90 lines
2.1 KiB
JavaScript
90 lines
2.1 KiB
JavaScript
/**
|
|
* Web唐明明
|
|
* 匆匆数载恍如梦,岁月迢迢华发增。
|
|
* 碌碌无为枉半生,一朝惊醒万事空。
|
|
* moduleName: router
|
|
*/
|
|
|
|
import { RouterMount, createRouter } from 'uni-simple-router';
|
|
import store from '../store/index'
|
|
|
|
import { jsdkInfo } from '@/apis/interfaces/user.js'
|
|
import { authFollow } from '@/apis/interfaces/authUrl'
|
|
|
|
const wx = require('jweixin-module')
|
|
|
|
const router = createRouter({
|
|
h5: {
|
|
paramsToQuery: true
|
|
},
|
|
platform: process.env.VUE_APP_PLATFORM,
|
|
routes: [...ROUTES, {
|
|
path: '*',
|
|
name:'404',
|
|
component: ()=> import('@/pages/404/404')
|
|
}]
|
|
})
|
|
|
|
// 全局路由前置守卫
|
|
router.beforeEach((to, from, next) => {
|
|
const token = store.getters.getToken || uni.getStorageSync('token')
|
|
const openId = store.getters.getOpenId || uni.getStorageSync('openId')
|
|
// 检查是否需要微信授权
|
|
// if(to.name != 'weChatIndex' && openId === ''){
|
|
// authFollow({
|
|
// url: '/wechat?pageName=' + to.name
|
|
// }).then(res => {
|
|
// window.location.href = res
|
|
// }).catch(err => {
|
|
// uni.showToast({
|
|
// title: err.message,
|
|
// icon: "none"
|
|
// })
|
|
// })
|
|
// return
|
|
// }
|
|
|
|
// 检查是否需要登录
|
|
if(to.auth && token === ''){
|
|
next({
|
|
name: 'Login',
|
|
NAVTYPE: 'push',
|
|
params: {
|
|
toName: to.name
|
|
}
|
|
})
|
|
return
|
|
}
|
|
next();
|
|
// 微信鉴权
|
|
jsdkInfo(window.location.href).then(res => {
|
|
let wxConfig = JSON.parse(res)
|
|
wx.config({
|
|
debug: false,
|
|
appId: wxConfig.appId,
|
|
timestamp: wxConfig.timestamp,
|
|
nonceStr: wxConfig.nonceStr,
|
|
signature: wxConfig.signature,
|
|
jsApiList: ['updateAppMessageShareData']
|
|
})
|
|
wx.ready(() => {
|
|
wx.updateAppMessageShareData({
|
|
title: '助力修缮庙宇,分享功德无量',
|
|
desc: '和我一起为西安禅经寺修缮添砖加瓦',
|
|
link: 'http://web.temple.siyuankunlun.cn/' + '?invite=' + store.getters.getIntive,
|
|
imgUrl: 'http://web.temple.siyuankunlun.cn/photo.png'
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
// 全局路由后置守卫
|
|
router.afterEach((to, from) => {
|
|
// console.log('跳转结束--暂无应用场景')
|
|
})
|
|
|
|
export {
|
|
router,
|
|
RouterMount
|
|
}
|