12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const api_login = require("../../api/login.js");
- const common_assets = require("../../common/assets.js");
- const isWechat = () => {
- return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
- };
- const _sfc_main = {
- data() {
- return {
- code: null
- };
- },
- onLoad(option) {
- this.getWechatCode();
- },
- onUnload() {
- },
- mounted() {
- },
- methods: {
- loginByMp() {
- if (this.code == null) {
- return;
- }
- common_vendor.index.showLoading({
- title: "处理中..."
- });
- let that = this;
- var data = { code: this.code };
- api_login.loginByWeChat(data).then(
- (res) => {
- common_vendor.index.hideLoading();
- if (res.code == 200) {
- common_vendor.index.setStorageSync("AppToken", res.token);
- common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
- common_vendor.index.$emit("refreshIM");
- that.goToLanch();
- } else {
- common_vendor.index.showToast({ title: res.msg, icon: "none" });
- }
- },
- (err) => {
- }
- );
- },
- getWechatCode() {
- if (isWechat) {
- let appid = "wx9ea36eecd281bcd3";
- let code = this.getUrlCode().code;
- let local = window.location.href;
- if (code == null || code === "") {
- window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + encodeURIComponent(local) + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
- } else {
- this.code = code;
- }
- }
- },
- getUrlCode() {
- var url = location.search;
- var theRequest = new Object();
- if (url.indexOf("?") != -1) {
- var str = url.substr(1);
- var strs = str.split("&");
- for (var i = 0; i < strs.length; i++) {
- theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
- }
- }
- console.log(theRequest);
- return theRequest;
- },
- goToLanch() {
- let beforLoginUrl = common_vendor.index.getStorageSync("beforLoginPage");
- console.log("beforLoginUrl:" + beforLoginUrl);
- common_vendor.index.reLaunch({
- url: beforLoginUrl
- });
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return {
- a: common_assets._imports_0$6,
- b: common_vendor.o(($event) => $options.loginByMp())
- };
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
|