|
@@ -1,10 +1,5 @@
|
|
|
-import {
|
|
|
- getUrlParam,
|
|
|
- getWeixinRedirectURI,
|
|
|
- isWeiXin
|
|
|
-} from '@/utils'
|
|
|
-import * as API_WeiXin from '@/apis/weixin.js'
|
|
|
-import carhelp from '@/utils/mixin.js'
|
|
|
+
|
|
|
+// import carhelp from '@/utils/mixin.js'
|
|
|
|
|
|
import Vue from 'vue'
|
|
|
import uniCrazyRouter from "uni-crazy-router";
|
|
@@ -15,25 +10,9 @@ Vue.use(uniCrazyRouter)
|
|
|
|
|
|
uniCrazyRouter.beforeEach(async (to, from, next) => {
|
|
|
|
|
|
- // 逻辑代码
|
|
|
- console.log("beforeEach")
|
|
|
- if(to.url==from.url){
|
|
|
-
|
|
|
- var url="pages/index/index";
|
|
|
- if(to.url.indexOf("pages/my")==0){
|
|
|
- url="pages/my/index";
|
|
|
- }
|
|
|
- if(to.url.indexOf("pages/news")==0){
|
|
|
- url="pages/news/index";
|
|
|
- }
|
|
|
- if(to.url.indexOf("pages/remind")==0){
|
|
|
- url="pages/remind/index";
|
|
|
- }
|
|
|
-
|
|
|
- window.location.href=window.location.href.split('#')[0]+"#/"+url
|
|
|
- }else{
|
|
|
- routerBeforeEach(to, from, next);
|
|
|
- }
|
|
|
+
|
|
|
+ routerBeforeEach(to, from, next);
|
|
|
+
|
|
|
})
|
|
|
|
|
|
uniCrazyRouter.afterEach((to, from) => {
|
|
@@ -63,52 +42,11 @@ const router = new Router()
|
|
|
// 路由全局拦截器 在这里处理登录、授权等相关操作
|
|
|
router.beforeEach(function(to, from, next) {
|
|
|
|
|
|
- console.log('前置守卫')
|
|
|
- if (process.car.SIMPLE_RUN) {
|
|
|
- if (!carhelp.getOpenId()) {
|
|
|
- carhelp.setOpenId("test")
|
|
|
- }
|
|
|
- routerBeforeEach(to, from, next);
|
|
|
- } else {
|
|
|
-
|
|
|
- if (!carhelp.getOpenId()) {
|
|
|
- if (isWeiXin()) {
|
|
|
- getOpenId();
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- routerBeforeEach(to, from, next);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ console.log('前置守卫')
|
|
|
+ routerBeforeEach(to, from, next);
|
|
|
|
|
|
})
|
|
|
-
|
|
|
-function getOpenId() {
|
|
|
- const code = getUrlParam('code');
|
|
|
-
|
|
|
- if (!code) {
|
|
|
- var url = document.URL;
|
|
|
-
|
|
|
- window.location.href = getWeixinRedirectURI(process.car.VUE_APP_WXAPPID, url);
|
|
|
- } else {
|
|
|
|
|
|
-
|
|
|
- API_WeiXin.getDataByCode(code).then(response => {
|
|
|
-
|
|
|
- carhelp.setOpenId(response.data.openid)
|
|
|
- //var linkUrl = document.URL.replace(/\?code=(.*?)&state=STATE/g, '');
|
|
|
- //window.location = linkUrl; //隐藏参数
|
|
|
- //return Promise.resolve(response.openid);
|
|
|
- }).catch(error => {
|
|
|
- console.log(error);
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
|
|
|
function routerBeforeEach(to, from, next) {
|
|
|
next();
|