旅游教育出版社-数字教材移动端
QYF-GitLab1
12 小时以前 8e3ee81b6ed824866734b7034604121f370f4201
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import service from "@/plugin/axios";
import webApi from "./assets/js/webApi";
 
import "./registerServiceWorker";
 
import Vant from "vant";
import "vant/lib/index.css";
// 基础css
import "@/assets/css/base.css";
// 公共css
import "@/assets/css/common.css";
// 配置项
import config from "@/assets/js/config";
// 工具类
import toolClass from "@/assets/js/toolClass";
import wx from "weixin-js-sdk";
import MG from "@/assets/js/middleGround/WebMiddleGroundApi";
// 时间处理
import moment from "moment";
 
import WeChat from "@/assets/js/weChat/weChat";
// import vConsole from "@/assets/js/vConsole"
Vue.prototype.webApi = webApi;
Vue.config.productionTip = false;
Vue.prototype.config = config;
Vue.prototype.tool = toolClass;
Vue.prototype.request = service;
Vue.use(Vant);
 
// Vue.use(vConsole);
// 微信
Vue.use(wx);
Vue.prototype.MG = MG;
Vue.prototype.moment = moment;
Vue.prototype.WeChat = WeChat;
 
// 路由拦截处理
router.beforeEach((to, from, next) => {
  console.log(to.meta, "tometa");
  console.log(to.meta.requiresAuth, "requiresAuth");
  if (to.meta && to.meta && to.meta.requiresAuth) {
    // const shareVal = getSharekey(location.href);
    // if (shareVal && shareVal.key) {
    //   shareNewJobWithApiNewEvent(config.appRefCode, shareVal.productId);
    // }
    // 判断当前的token是否存在
    if (toolClass.getCookie(config.tokenKey)) {
      // 拦截如果是绑定code,静默绑定微信
      let bindingCode = WeChat.getUrlInfo("bindingWeChat");
      if (bindingCode.code) {
        let query = {
          code: bindingCode.code,
          isSocial: true, // 公众号和开放平台是不同的主体,公众号绑定微信使用isSocial=true,开放平台(扫码绑定)使用isSocial=false;
        };
        MG.identity
          .bindWeChat(query)
          .then((res) => {
            const url = window.location.href;
            const redirectUrl = url.split("?")[0];
            window.location.href = redirectUrl;
          })
          .catch((res) => {
            console.log(res);
          });
      } else {
        next();
      }
    } else {
      // 拦截如果是登录code
      let loginCode = WeChat.getUrlInfo("weChatLogin");
      if (loginCode.code) {
        WeChat.login(loginCode.code, (data) => {
          toolClass.setCookie(config.tokenKey, data);
          const url = window.location.href;
          const domian = url.split("?")[0];
          console.log(domian, "domian");
          const routeCode = url.split("#")[1];
          const redirectUrl = domian + "#" + routeCode;
          window.location.href = redirectUrl;
        });
        return false;
      }
      // 检查是否拥有微信账户
      let checkCode = WeChat.getUrlInfo("checkWeChat");
      if (checkCode.code) {
        /**
         * identity/checkWeChatAccount
         * 通过code 判断是否是新用户
         *   新用户
         *      选择登录方式
         *        微信登录
         *          个人中心 提示绑定手机号
         *        手机号登录
         *          登录成功后 调用wechat.login 静默绑定用户
         *   已有账户
         *     微信登录即可, 此时两个账户已经打通
         *
         */
        let query = {
          code: checkCode.code,
          appCode: config.appRefCode,
        };
        MG.identity
          .chechWechatAccount(query)
          .then((res) => {
            if (res == true) {
              const url = window.location.href;
              const domian = url.split("?")[0];
              const redirectUrl = domian + "#" + "/weChatLogin";
              window.location.href = redirectUrl;
            } else {
              if (to.meta.title != "选择登录方式") {
                const url = window.location.href;
                const domian = url.split("?")[0];
                const redirectUrl = domian + "#" + "/index";
                window.location.href = redirectUrl;
              } else {
                const url = window.location.href;
                const domian = url.split("?")[0];
                const redirectUrl = domian + "#" + "/selectLoginMethod";
                window.location.href = redirectUrl;
              }
            }
          })
          .catch((res) => {
            console.log(res);
          });
      } else {
        //判断是否是移动端
        // if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        //如在是微信中打开
        var ua = navigator.userAgent.toLowerCase(); //获取判断用的对象
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
          toolClass.delCookie(config.tokenKey);
          localStorage.fullPath = to.fullPath;
          window.location.href =
            config.requestCtx + "/mobile/textbooks/#" + to.fullPath;
          WeChat.getCode("checkWeChat");
        } else {
          WeChat.getCode("weChatLogin");
        }
      }
    }
  } else {
    console.log("不拦截");
    next();
  }
});
new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");