Browse Source

页面切换问题

luyanan 6 years ago
parent
commit
7d7a9c1361

+ 11 - 17
src/components/Breadcrumb/index.vue

@ -3,14 +3,14 @@
3 3
    <transition-group name="breadcrumb">
4 4
      <el-breadcrumb-item v-for="(item,index)  in levelList" :key="item.path" v-if="item.meta.title">
5 5
        <span v-if="item.redirect==='noredirect'||index==levelList.length-1" class="no-redirect">{{item.meta.title}}</span>
6
        <router-link v-else :to="item.redirect||item.path">{{item.meta.title}}</router-link>
6
        <router-link v-else :to="item.redirect||item.path" replace>{{item.meta.title}}</router-link>
7 7
      </el-breadcrumb-item>
8 8
    </transition-group>
9 9
  </el-breadcrumb>
10 10
</template>
11 11
12 12
<script>
13
import { mapGetters } from 'vuex'
13
import Cookies from 'js-cookie'
14 14
export default {
15 15
  created() {
16 16
    this.getBreadcrumb()
@ -20,11 +20,6 @@ export default {
20 20
      levelList: null
21 21
    }
22 22
  },
23
  computed: {
24
    ...mapGetters([
25
      'roles'
26
    ])
27
  },
28 23
  watch: {
29 24
    $route() {
30 25
      this.getBreadcrumb()
@ -32,17 +27,16 @@ export default {
32 27
  },
33 28
  methods: {
34 29
    getBreadcrumb() {
35
      let matched = this.$route.matched.filter(item => item.name)
36
      if (this.roles.indexOf('1') >= 0) {
37
        const first = matched[0]
38
        if (first && first.name !== 'dashboard') {
39
          matched = [{ path: '/dashboard', meta: { title: '主页' }}].concat(matched)
40
        }
41
      } else {
42
        const firstF = matched[1]
43
        if (firstF && firstF.name !== 'bridgeHome') {
44
          matched = [{ path: 'bridgeHome', meta: { title: '主页' }}].concat(matched)
30
      const bridgeName = Cookies.get('bridgeName')
31
      let matched = this.$route.matched.filter(item => {
32
        if (bridgeName && item.path === '/bridgeHome') {
33
          item.meta.title = bridgeName
45 34
        }
35
        return item.name
36
      })
37
      const first = matched[0]
38
      if (first && first.name !== 'dashboard') {
39
        matched = [{ path: '/dashboard', meta: { title: '主页' }}].concat(matched)
46 40
      }
47 41
      this.levelList = matched
48 42
    }

+ 4 - 2
src/permission.js

@ -4,6 +4,7 @@ import NProgress from 'nprogress' // Progress 进度条
4 4
import 'nprogress/nprogress.css'// Progress 进度条样式
5 5
import { Message } from 'element-ui'
6 6
import { getCookiesName } from '@/utils/auth' // 验权
7
import queryInfo from '@/utils/queryInfo'
7 8
8 9
NProgress.configure({ showSpinner: false })// NProgress Configuration
9 10
@ -23,7 +24,7 @@ router.beforeEach((to, from, next) => {
23 24
      NProgress.done()
24 25
    } else {
25 26
      if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
26
        // console.log(5555)
27
        console.log(5555)
27 28
        store.dispatch('GetUserInfo').then(res => { // 拉取user_info
28 29
          const roles = [res.data.type.toString()]
29 30
          store.dispatch('GenerateRoutes', { roles }).then(() => { // 根据roles权限生成可访问的路由表
@ -37,11 +38,12 @@ router.beforeEach((to, from, next) => {
37 38
          })
38 39
        })
39 40
      } else {
40
        // console.log(4444)
41
        console.log(4444)
41 42
        if (hasPermission(store.getters.roles, to.meta.roles)) {
42 43
          next()
43 44
        }
44 45
      }
46
      queryInfo.queryAllInfo()
45 47
    }
46 48
  } else {
47 49
    if (whiteList.indexOf(to.path) !== -1) {

+ 13 - 19
src/router/index.js

@ -41,12 +41,11 @@ export const constantRouterMap = [
41 41
    component: Layout,
42 42
    redirect: '/dashboard',
43 43
    hidden: true,
44
    meta: { noCache: true },
45 44
    children: [{
46 45
      path: 'dashboard',
47 46
      component: () => import('@/views/dashboard'),
48 47
      name: 'dashboard',
49
      meta: { title: '主页', noCache: true }
48
      meta: { title: '主页' }
50 49
    }]
51 50
  },
52 51
  {
@ -55,7 +54,6 @@ export const constantRouterMap = [
55 54
    component: Layout,
56 55
    name: 'bridgesConsole',
57 56
    meta: {
58
      noCache: true,
59 57
      roles: ['0']
60 58
    },
61 59
    children: [
@ -64,7 +62,7 @@ export const constantRouterMap = [
64 62
        name: 'bridgeHome',
65 63
        component: () => import('@/views/bridgesConsole/index'),
66 64
        redirect: '/bridgeHome/bridgeDetail',
67
        meta: { title: '主页', noCache: true },
65
        meta: { title: '桥梁简称' },
68 66
        children: [
69 67
          {
70 68
            path: 'bridgeDetail',
@ -75,20 +73,19 @@ export const constantRouterMap = [
75 73
            path: 'danger',
76 74
            name: 'danger',
77 75
            redirect: 'dangerList',
78
            meta: { title: '历史报警信息查询', noCache: true },
76
            meta: { title: '历史报警信息查询' },
79 77
            component: () => import('@/views/bridgesConsole/bridgeDanger/index'),
80 78
            children: [
81 79
              {
82 80
                path: 'dangerList',
83 81
                name: 'dangerList',
84
                component: () => import('@/views/bridgesConsole/bridgeDanger/dangerList'),
85
                meta: { noCache: true }
82
                component: () => import('@/views/bridgesConsole/bridgeDanger/dangerList')
86 83
              },
87 84
              {
88 85
                path: 'dangerDetail',
89 86
                name: 'dangerDetail',
90 87
                component: () => import('@/views/bridgesConsole/bridgeDanger/dangerDetail'),
91
                meta: { title: '报警信息浏览', noCache: true }
88
                meta: { title: '报警信息浏览' }
92 89
              }
93 90
            ]
94 91
          },
@ -98,8 +95,7 @@ export const constantRouterMap = [
98 95
            component: () => import('@/views/bridgesConsole/bridgeMonitor/index'),
99 96
            meta: {
100 97
              title: '历史监测信息查询',
101
              roles: ['0'],
102
              noCache: true
98
              roles: ['0']
103 99
            }
104 100
          }
105 101
        ]
@ -114,8 +110,7 @@ export const constantRouterMap = [
114 110
    meta: {
115 111
      title: '用户系统管理',
116 112
      icon: 'peoples',
117
      roles: ['1'],
118
      noCache: true
113
      roles: ['1']
119 114
    },
120 115
    alwaysShow: true,
121 116
    children: [
@ -123,7 +118,7 @@ export const constantRouterMap = [
123 118
        path: 'infoManage',
124 119
        name: 'infoManage',
125 120
        component: () => import('@/views/peoplesManage/infoManage/index'),
126
        meta: { title: '用户信息管理', noCache: true }
121
        meta: { title: '用户信息管理' }
127 122
      }
128 123
    ]
129 124
  },
@ -134,33 +129,32 @@ export const constantRouterMap = [
134 129
    meta: {
135 130
      title: '基础信息管理',
136 131
      icon: 'list',
137
      roles: ['1'],
138
      noCache: true
132
      roles: ['1']
139 133
    },
140 134
    children: [
141 135
      {
142 136
        path: 'bridgesInfo',
143 137
        name: 'BridgesInfo',
144 138
        component: () => import('@/views/baseInfoManage/bridgesInfo/index'),
145
        meta: { title: '桥梁信息管理', noCache: true }
139
        meta: { title: '桥梁信息管理' }
146 140
      },
147 141
      {
148 142
        path: 'serversConfig',
149 143
        name: 'ServersConfig',
150 144
        component: () => import('@/views/baseInfoManage/serversConfig/index'),
151
        meta: { title: '采集服务器配置', noCache: true }
145
        meta: { title: '采集服务器配置' }
152 146
      },
153 147
      {
154 148
        path: 'boxesConfig',
155 149
        name: 'BoxesConfig',
156 150
        component: () => import('@/views/baseInfoManage/boxesConfig/index'),
157
        meta: { title: '采集盒配置', noCache: true }
151
        meta: { title: '采集盒配置' }
158 152
      },
159 153
      {
160 154
        path: 'sensorsConfig',
161 155
        name: 'SensorsConfig',
162 156
        component: () => import('@/views/baseInfoManage/sensorsConfig/index'),
163
        meta: { title: '传感器配置', noCache: true }
157
        meta: { title: '传感器配置' }
164 158
      }
165 159
    ]
166 160
  },

+ 23 - 16
src/utils/queryInfo.js

@ -1,27 +1,34 @@
1
/**
2
 * Created by luyanan on 18/8/23.
3
 */
4
/* eslint-disable one-var */
1 5
import request from '@/utils/request'
6
import store from '@/store'
2 7
3
/*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/
4
var serverList = [],
8
var bridgeObj = {},
9
  serverList = [],
5 10
  deviceList = [],
6 11
  transducerList = [],
7 12
  queryAllInfo = function() {
8
    request({
9
      url: '/ajax/all/byUser',
10
      method: 'get',
11
      params: {
12
        active: 1
13
      }
14
    }).then(res => {
15
      if (res.success) {
16
        serverList = res.data.server
17
        deviceList = res.data.device
18
        transducerList = res.data.transducer
19
      }
20
    })
13
    if (!bridgeObj.server && store.getters.roles.indexOf('1') === -1) {
14
      request({
15
        url: '/ajax/all/byUser',
16
        method: 'get',
17
        params: {
18
          active: 1
19
        }
20
      }).then(res => {
21
        if (res.success) {
22
          bridgeObj = res.data
23
          serverList = res.data.server
24
          deviceList = res.data.device
25
          transducerList = res.data.transducer
26
        }
27
      })
28
    }
21 29
  },
22 30
  queryServers = function(bid, flag) {
23 31
    const obj = serverList
24
    /*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/
25 32
    var servers = [], serverSeqArr = []
26 33
    for (let i = 0; i < obj.length; ++i) {
27 34
      if (bid === obj[i].bridgeId) {

+ 1 - 1
src/views/bridgesConsole/bridgeDanger/dangerList.vue

@ -85,7 +85,7 @@ export default {
85 85
      })
86 86
    },
87 87
    alarmShow(id, msg) {
88
      this.$router.push({
88
      this.$router.replace({
89 89
        name: 'dangerDetail',
90 90
        query: { aid: id, msg: msg }
91 91
      })

+ 1 - 1
src/views/bridgesConsole/bridgeDetail/components/BInfoDialog02.vue

@ -1,6 +1,6 @@
1 1
<template>
2 2
  <el-dialog title="采集服务器信息" :visible.sync="dialogTableVisible" :width="dialogW">
3
    <el-form class="form-main">
3
    <el-form class="form-main" style="padding:0 15px">
4 4
      <el-row :gutter="16" v-if="serverList.length">
5 5
        <el-col :xs="12" :sm="12" :lg="12" v-for="item in serverShowList" :key="item.index">
6 6
          <div class="list-item">

+ 3 - 3
src/views/bridgesConsole/bridgeDetail/index.vue

@ -244,16 +244,16 @@ export default {
244 244
      this.currentNo = val
245 245
    },
246 246
    alarmShow(id, msg) {
247
      this.$router.push({
247
      this.$router.replace({
248 248
        name: 'dangerDetail',
249 249
        query: { aid: id, msg: msg }
250 250
      })
251 251
    },
252 252
    queryDangerInfo() {
253
      this.$router.push({ name: 'dangerList' })
253
      this.$router.replace({ name: 'dangerList' })
254 254
    },
255 255
    queryMonitorInfo() {
256
      this.$router.push({ name: 'bridgeMonitor' })
256
      this.$router.replace({ name: 'bridgeMonitor' })
257 257
    },
258 258
    queryBirdgeInfo() {
259 259
      this.$refs.BInfoDialog01.dialogTableVisible = true

+ 0 - 13
src/views/bridgesConsole/index.vue

@ -1,18 +1,5 @@
1 1
<template>
2 2
  <div>
3
    <el-menu class="navbar" mode="horizontal">
4
      <breadcrumb></breadcrumb>
5
    </el-menu>
6 3
    <router-view></router-view>
7 4
  </div>
8 5
</template>
9
<script>
10
import Breadcrumb from '@/components/Breadcrumb'
11
12
export default {
13
  name: 'bridgeHome',
14
  components: {
15
    Breadcrumb
16
  }
17
}
18
</script>

+ 1 - 1
src/views/dashboard/admin/index.vue

@ -28,7 +28,7 @@ export default {
28 28
  text-align: center;
29 29
  margin: 20px;
30 30
  height: 100%;
31
  padding: 15% 0;
31
  padding: 12% 0;
32 32
  background: #fff;
33 33
  .plat-pic{
34 34
    margin: 40px auto 0;

+ 1 - 2
src/views/dashboard/other/index.vue

@ -45,7 +45,6 @@ export default {
45 45
    }
46 46
  },
47 47
  created() {
48
    queryInfo.queryAllInfo()
49 48
    this.getBridgeLists()
50 49
  },
51 50
  methods: {
@ -87,9 +86,9 @@ export default {
87 86
      }
88 87
    },
89 88
    goToDashboardC(id, name) {
90
      this.$router.push({ name: 'bridgeHome' })
91 89
      Cookies.set('bridgeId', id)
92 90
      Cookies.set('bridgeName', name)
91
      this.$router.replace({ name: 'bridgeHome' })
93 92
    },
94 93
    handleCurrentChange(val) {
95 94
      this.pageNo = val

+ 2 - 2
src/views/findPwd/index.vue

@ -213,7 +213,7 @@
213 213
                  center: true,
214 214
                  callback: action => {
215 215
                    if (action === 'confirm') {
216
                      this.$router.push({ path: '/login' })
216
                      this.$router.replace({ path: '/login' })
217 217
                    }
218 218
                  }
219 219
                })
@ -239,7 +239,7 @@
239 239
        })
240 240
      },
241 241
      goLogin() {
242
        this.$router.push({ path: '/login' })
242
        this.$router.replace({ path: '/login' })
243 243
      }
244 244
    }
245 245
  }

+ 2 - 2
src/views/layout/components/Navbar.vue

@ -1,8 +1,8 @@
1 1
<template>
2 2
  <div>
3 3
    <marqueebox :isShow="roles.indexOf('1')>=0"></marqueebox>
4
    <el-menu v-if="roles.indexOf('1')>=0" class="navbar" mode="horizontal">
5
      <hamburger class="hamburger-container" :toggleClick="toggleSideBar" :isActive="sidebar.opened"></hamburger>
4
    <el-menu class="navbar" mode="horizontal">
5
      <hamburger v-if="roles.indexOf('1')>=0" class="hamburger-container" :toggleClick="toggleSideBar" :isActive="sidebar.opened"></hamburger>
6 6
      <breadcrumb></breadcrumb>
7 7
    </el-menu>
8 8
  </div>

+ 1 - 1
src/views/layout/components/Sidebar/SidebarItem.vue

@ -17,7 +17,7 @@
17 17
        <template v-for="child in item.children" v-if="!child.hidden">
18 18
          <sidebar-item :is-nest="true" class="nest-menu" v-if="child.children&&child.children.length>0" :item="child" :key="child.path" :base-path="resolvePath(child.path)"></sidebar-item>
19 19
20
          <router-link v-else :to="resolvePath(child.path)" :key="child.name">
20
          <router-link v-else :to="resolvePath(child.path)" :key="child.name" replace>
21 21
            <el-menu-item :index="resolvePath(child.path)">
22 22
              <svg-icon v-if="child.meta&&child.meta.icon" :icon-class="child.meta.icon"></svg-icon>
23 23
              <span v-if="child.meta&&child.meta.title" slot="title">{{child.meta.title}}</span>

+ 34 - 25
src/views/layout/components/TopNavbar.vue

@ -1,5 +1,5 @@
1 1
<template>
2
  <el-menu class="topnavbar" mode="horizontal">
2
  <div class="topnavbar">
3 3
    <div class="logo-container">
4 4
      <div class="logo-wrapper" @click="toHome"><div class="logo-img"></div></div>
5 5
      <el-dropdown v-if="roles.indexOf('1')<0" trigger="click" class="drop-menu">
@ -13,28 +13,16 @@
13 13
        </el-dropdown-menu>
14 14
      </el-dropdown>
15 15
    </div>
16
    <el-dropdown class="avatar-container" trigger="click">
17
      <div class="avatar-wrapper">
18
      	<div>您好,{{ name }}</div>
19
        <i class="el-icon-caret-bottom"></i>
20
      </div>
21
      <el-dropdown-menu class="user-dropdown" slot="dropdown">
22
        <router-link v-if="roles.indexOf('1')>=0" class="inlineBlock" to="/">
23
          <el-dropdown-item>主页</el-dropdown-item>
24
        </router-link>
25
        <router-link v-if="roles.indexOf('1')<0" class="inlineBlock" to="/bridgeHome">
26
          <el-dropdown-item>主页</el-dropdown-item>
27
        </router-link>
28
        <el-dropdown-item divided>
29
          <span @click="logout" style="display:block;">退出</span>
30
        </el-dropdown-item>
31
      </el-dropdown-menu>
32
    </el-dropdown>
33
  </el-menu>
16
    <div class="name-box">
17
      <span>您好,{{ name }}</span>
18
      <span class="exit-btn" @click="logout">退出登录</span>
19
    </div>
20
  </div>
34 21
</template>
35 22
36 23
<script>
37 24
import { mapGetters } from 'vuex'
25
import { MessageBox } from 'element-ui'
38 26
import { getBridgeList } from '@/api/bridgeInfo'
39 27
import Cookies from 'js-cookie'
40 28
@ -70,7 +58,7 @@ export default {
70 58
  },
71 59
  methods: {
72 60
    toHome() {
73
      this.$router.push({ path: '/' })
61
      this.$router.replace({ path: '/' })
74 62
      Cookies.remove('bridgeId')
75 63
      Cookies.remove('bridgeName')
76 64
    },
@ -78,10 +66,19 @@ export default {
78 66
      this.$store.dispatch('ToggleSideBar')
79 67
    },
80 68
    logout() {
81
      this.$store.dispatch('LogOut').then(() => {
82
        Cookies.remove('bridgeId')
83
        Cookies.remove('bridgeName')
84
        location.reload() // 为了重新实例化vue-router对象 避免bug
69
      MessageBox.confirm('您确认要退出登录吗?', '提示', {
70
        confirmButtonText: '确定',
71
        cancelButtonText: '取消',
72
        type: 'warning',
73
        center: true
74
      }).then(() => {
75
        this.$store.dispatch('LogOut').then(() => {
76
          Cookies.remove('bridgeId')
77
          Cookies.remove('bridgeName')
78
          location.reload() // 为了重新实例化vue-router对象 避免bug
79
        })
80
      }).catch(() => {
81
        console.log('已取消退出')
85 82
      })
86 83
    },
87 84
    getBridgeLists() {
@ -107,7 +104,7 @@ export default {
107 104
      this.showName = name
108 105
      Cookies.set('bridgeId', id)
109 106
      Cookies.set('bridgeName', name)
110
      this.$router.push({
107
      this.$router.replace({
111 108
        name: 'bridgeDetail',
112 109
        query: { id: id, name: name }
113 110
      })
@ -148,6 +145,18 @@ export default {
148 145
      color: #fff;
149 146
    }
150 147
  }
148
  .name-box{
149
    display: inline-block;
150
    position: absolute;
151
    right: 20px;
152
    font-size:14px;
153
    overflow: hidden;
154
    color:#fff;
155
    .exit-btn {
156
      margin-left:30px;
157
      cursor: pointer;
158
    }
159
  }
151 160
  .avatar-container {
152 161
    height: 50px;
153 162
    display: inline-block;

+ 2 - 2
src/views/login/index.vue

@ -94,7 +94,7 @@ export default {
94 94
              if (response.data) {
95 95
                this.$store.dispatch('GetUserInfo').then(res => {
96 96
                })
97
                this.$router.push({ path: '/' })
97
                this.$router.replace({ path: '/' })
98 98
              } else {
99 99
                Message.error('登录账号与密码不匹配,请检查后重试')
100 100
                this.changeImgVc()
@ -132,7 +132,7 @@ export default {
132 132
      })
133 133
    },
134 134
    goBackPwd() {
135
      this.$router.push({ path: '/findPwd' })
135
      this.$router.replace({ path: '/findPwd' })
136 136
    },
137 137
    changeImgVc() {
138 138
      this.imgVcUrl = getPictureVC('PIC_LOGIN')