ann0707
2018-08-16 c9bc8ec61cff4076132f6396d99d383a2cdf5a03
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
/**
 * Created by c.y on 2018/3/16.
 * 全局的router的配置, 以及其跳转的控制
 */
 
import Vue from 'vue';
import VueRouter from 'vue-router';
import store from '../store/index';
import {setClientInfo, setProductConfig} from '../config/config'; // 配置信息
import projectRouter from './router';
import judgmentUrl from '../tool/judgmentUrl';
 
 
setClientInfo(); // 将设备信息写入本地存储
setProductConfig(); // 获取项目配置信息
 
Vue.use(VueRouter);
 
// 路由的动态加载,最先开始加载项目路由
// 如果是app的话,需要动态加载路由配置
let router = new VueRouter(projectRouter);
 
// 路由的跳转的控制
router.beforeEach((to, from, next) => {
 
    // 如果微信分享的话,微信会在地址栏添加额外参数
    if (judgmentUrl.getUrlQuestionMark()) {
        window.location.href = judgmentUrl.getRightProjectUrl();
    }
    // arr里存放需要登录状态下才能访问的页面的name
    // 过滤  实名认证,申请记录,修改密码
    // 收入贷界面
    let arr = ['f-auth', 'f-apply-record', 'f-update-password'
        , 'incoPersonalInfo', 'incoHouseAndJobInfo', 'incoBindCard', 'incoPhotoInfo', 'incoAuditResults'];
    let loginFalse = ['f-login', 'f-register', 'f-forget-password'];  // 登录后不能进入 登录、注册、忘记密码界面
    //判断是否登录,如果没有登录则判断是否往arr里的页面进行跳转,如果是,则跳转到登录页
    let sid = window.sessionStorage.getItem('newSid');
    if (sid) {   // 已经登录
        if (loginFalse.indexOf(to.name) !== -1) {
            window.history.go(-1);
        }
    } else {  // 未登录
        if (arr.indexOf(to.name) !== -1) {
            next('f-login');
        }
    }
    next();
});
 
router.afterEach((to, from) => {
 
    if (to.name == '/f-main') {
// 微信预加载 分享功能
 
    }
 
    // 记录访问页面地址
    store.commit('UPDATE_PAGE_ACCESS_RECORD', {pageName: {name: to.name, fullPath: to.fullPath}});
    // 跳转到顶部,解决ios空白问题,不要问为什么这么写,删掉一个就会出错,谨慎操作
    window.scrollTo(0, 2);
    setTimeout(function () {
        store.commit('UPDATE_APP_STYLE', {
            height: document.documentElement.clientHeight + 1
        });
        window.scrollTo(0, 0);
        store.commit('UPDATE_APP_STYLE', {
            height: '100%',
            overflow: 'auto',
            '-webkit-overflow-scrolling': 'touch'
        });
    }, 5);
 
});
 
export default router;