whychdw
2019-07-05 7ab97c4ada45550abc7f440d60549b249726a9ff
修改路由bug
8个文件已修改
41 ■■■■ 已修改文件
src/App.vue 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main.js 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/index.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/home/DataControl.vue 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/home/DataHistory.vue 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/home/data.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/home/index.vue 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/login.vue 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/App.vue
@@ -11,7 +11,12 @@
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("store") ) {
        this.$store.replaceState(Object.assign({}, this.$store.state,JSON.parse(sessionStorage.getItem("store"))))
    }
    }
    // 判断是否已经登录
    if(!this.$store.state.login) {
      this.$router.push('/');
    }
    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload",()=>{
src/main.js
@@ -21,13 +21,9 @@
router.beforeEach((to, from, next) => {
    iView.LoadingBar.start();
    if(store.state.login || to.path=='/') {     // 判断是否登录
        // console.log(to.meta);
        Util.title(to.meta.title);
        next();
    }else{
        next('/');
    }
    // console.log(to.meta);
    Util.title(to.meta.title);
    next();
    
});
src/store/index.js
@@ -5,7 +5,7 @@
const store = new Vuex.Store({
    state: {
        login: true,
        login: false,
        userName: '',
        topNav: {
            actionName: '/'
src/views/home/DataControl.vue
@@ -133,6 +133,12 @@
            tbl:[] 
        }
    },
    created: function() {
        // 设置主导航
        this.$store.commit('setActiveName', 'control');
        this.$bus.$emit('changePageState', 'control');
    },
    methods: {
        setAutoComplete: function() {
            this.autocomplete.data = [];  // 初始化可搜索内容
src/views/home/DataHistory.vue
@@ -198,6 +198,12 @@
            deep: true
        }
    },
    created: function() {
        // 设置主导航
        this.$store.commit('setActiveName', 'history');
        this.$bus.$emit('changePageState', 'history');
    },
    methods: {
        showAlarmsSetting: function() {
            this.alarmsModal = true;
src/views/home/data.vue
@@ -273,7 +273,7 @@
                    county: item.county.trim(),
                    device_name: item.device_name.trim()
                });
                //console.log(url);
                // console.log(url);
                _self.$router.replace ('/index/data/'+url+pageState+'/');
            }
        }
src/views/home/index.vue
@@ -16,6 +16,10 @@
            imgs: mapImgSrc
        }
    },
    created: function() {
        // 设置主导航
        this.$store.commit('setActiveName', 'home');
    },
    methods: {
        // 查询地图中的坐标点
        searchMapDot: function() {
src/views/login.vue
@@ -46,12 +46,16 @@
            }
        }
    },
    created: function() {
        sessionStorage.removeItem('store');
    },
    methods: {
        handleSubmit(name) {
            this.$refs[name].validate((valid) => {
                if (valid) {
                    this.$store.commit('setLogin', true);
                    this.$store.commit('setUserName', this.user.name);
                    sessionStorage.setItem("store",JSON.stringify(this.$store.state))
                    this.$router.push('/index');
                } else {
                    this.$Message.error('登录失败!用户名/密码错误');