123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import {
- RouterMount,
- createRouter,
- runtimeQuit
- } from './js_sdk/uni-simple-router';
- import {
- BACK_URL
- } from './config/cachekey'
- import store from './store'
- import {
- silentLogin
- } from '@/api/app'
- import {
- getWxCode
- } from './utils/login'
- import Cache from './utils/cache'
- import wechath5 from './utils/wechath5'
- import {
- isWeixinClient
- } from './utils/tools'
- const scrollInfo = {};
- let first = null;
- const whiteList = ['register', 'login', 'forget_pwd']
- const router = createRouter({
- platform: process.env.VUE_APP_PLATFORM,
- APP: {
- animation: {}
- },
- h5: {
- scrollBehavior: (to, from, savedPosition) => {
- const XY = scrollInfo[to.name];
- if (XY) return XY;
- return {
- x: 0,
- y: 0
- };
- }
- },
- routerErrorEach: ({
- type,
- msg
- }) => {
- router.$lockStatus = false;
- // #ifdef APP-PLUS
- if (type === 3) {
- runtimeQuit();
- }
- // #endif
- },
- debugger: false,
- routes: [
- ...ROUTES,
- {
- path: '*',
- redirect: (to) => {
- return {
- name: '404'
- }
- }
- },
- ]
- });
- console.log(router)
- let count = 0;
- router.beforeEach((to, from, next) => {
- // #ifdef H5
- // tab页面的滚动缓存
- if (from.meta.keepScroll === true) {
- scrollInfo[from.name] = {
- x: window.scrollX,
- y: window.scrollY
- }
- }
- // #endif
- console.log(to, from, 'beforeEach---开始跳转')
- let index = whiteList.findIndex((item) => from.path.includes(item))
- if (index == -1 && !store.getters.token) {
- Cache.set(BACK_URL, from.fullPath)
- }
- if (to.meta.auth && !store.getters.token) {
- next('/pages/login/login');
- return
- } else {
- next()
- }
- });
- router.afterEach((to, from, next) => {
- // #ifdef H5
- // 添加定时器防止拿到的域名是上一个域名
- setTimeout(async () => {
- if (isWeixinClient()) {
- // jssdk配置
- await wechath5.config()
- // 分享配置
- if (to.path.includes('goods_details')) return
- store.dispatch('wxShare')
- }
- })
- // #endif
- console.log('跳转完成');
- });
- export {
- router,
- RouterMount
- }
|