zhaomiao 3 năm trước cách đây
mục cha
commit
1f9f4d8d7c

+ 2 - 1
src/api/axios.js

@@ -2,7 +2,7 @@
 import BASE from '@tools/base'
 import store from '@store/index'
 import axios from 'axios'
-
+import {getToken} from '@/utils/auth'
 import { Message } from 'element-ui';
 
 // 创建axios实例
@@ -43,6 +43,7 @@ const httpService_L = axios.create({
 // http request 拦截器
 httpService.interceptors.request.use(
   config => {
+    config.headers.authToken = getToken;
     return config;
   },
   err => {

+ 26 - 20
src/router/index.js

@@ -14,6 +14,7 @@ VueRouter.prototype.replace = function replace(location) {
 // 公共页面
 import main from '@views/main'
 import error404 from '@views/404'
+import login from '@views/login'
 
 // 子路由
 import yRouter from '@router/ylf';
@@ -47,6 +48,14 @@ const routes = [
     name: 'error404',
     component: error404,
   },
+  {
+    path: '/login', // 页面不存在的情况下会跳到404页面
+    meta: {
+      requireAuth: true, // 添加该字段,表示进入这个路由是需要登录的  /进路由勾子函数beforeEach
+    },
+    name: 'login',
+    component: login,
+  }
   // { // 健康评价报告 - 临时  /部署单页面
   //   path:'/healthAssessmentDetailed2',
   //   component: r => require.ensure([], () => r(require('@views/healthManagement/healthAssessmentDetailed')), 'healthManagement')
@@ -63,30 +72,27 @@ const router = new VueRouter({
  * 路由的钩子函数,处理是否登录的判断
  * **/
  router.beforeEach((to, from, next) => {
-  // 路由地址不存在的处理办法
+    // 路由地址不存在的处理办法
+  
+  if (to.matched.some(m => m.meta.requireAuth)) {    // 需要登录
+    // if(window.localStorage.token && window.localStorage.isLogin === '1'){
+    //   next()
+    // } else 
+    if (to.path !== '/login') {
+      let token = window.localStorage.token;
+      if (token === 'null' || token === '' || token === undefined){
+          next()
+      }
+    } else {
+      next()
+    }
+  } else {   // 不需要登录
+    next()
+  }
   if (to.matched.length === 0) { // 如果未匹配到路由
     // sessionStorage.removeItem("btrh_sxsd_locationHref");
     next('/404')   // 如果上级也未匹配到路由则跳转登录页面,如果上级能匹配到则转上级路由
   }
-
-  if (to.matched.some(r => r.meta.requireAuth)) {
-
-    let userinfo = JSON.parse(sessionStorage.getItem("btrh_sxsd_userinfo"));
-    userinfo = "";
-    if(userinfo !== null){
-      // if(to.path !== "/"){
-      //   // 判断当前菜单是否有权限打开,如果无权限,自动退出
-      //   routerCheck(userinfo.roleId, to.path, next);
-      // }else{
-      //   next();
-      // }
-      next();
-      return;
-    }
-    next("/login");
-  } else {
-    next();
-  }
 })
 
 export default router

+ 1 - 1
src/router/zm.js

@@ -90,5 +90,5 @@ export default [
   { // 区间曲线偏差
     path:'/curveDeviation',
     component: r => require.ensure([], () => r(require('@views/healthManagement/curveDeviation')), 'healthManagement')
-  }
+  },
 ]

+ 3 - 2
src/store/getters.js

@@ -1,7 +1,8 @@
 const getters = {
-  token: state => state.user.token,  //建立token的快捷访问   user 是因为index.js中导入的时候名称定义为user
+  authToken: state => state.user.authToken,  //建立token的快捷访问   user 是因为index.js中导入的时候名称定义为user
   submitDDTag: state => state.submitDDTag,
-  loading: state => state.loading,
+  loading:state =>state.loading,
+  username: state => state.user.username,
   themeName: state => state.themeName,
 }
 export default getters

+ 7 - 7
src/store/index.js

@@ -5,24 +5,24 @@ import user from './modules/user'
 Vue.use(Vuex)
 
 const state = {
-  submitDDTag: false, // 提交 - 防抖动 - 针对快速请求问题的拦截机制
-  loading: false, // 全局 - 加载中....
-  themeName: 'light' // 默认主题
+  submitDDTag: false,   //提交 - 防抖动 - 针对快速请求问题的拦截机制
+  loading: false,   //全局 - 加载中....
+  themeName:"light",
 };
 //改变状态的方法
 const mutations = {
-  openSubmitDDTag (state, tag) {
+  openSubmitDDTag(state, tag) {
     state.submitDDTag = tag;
   },
-  loadingStore (state, tag) {
+  loadingStore(state, tag) {
     state.loading = tag;
   },
-  changeTheme (state, tag) {
+changeTheme (state, tag) {
     state.themeName = tag;
   },
 };
 var vuexStore = new Vuex.Store({
-  module: {
+  module:{
     user//调用this['user/login']()  引用 ...mapActions(['user/login']),
   },
   getters,

+ 10 - 15
src/store/modules/user.js

@@ -1,35 +1,30 @@
-import { getToken, setToken, removeToken } from '@/utils/auth'
+// import {getToken,setToken,removeToken} from '@/utils/auth'
 const state = {
-  token: getToken //设置token为共享状态   初始化vuex的时候 就先从缓存中读取
+  authToken:localStorage.getItem('authToken') ? localStorage.getItem('authToken'):'', //设置token为共享状态   初始化vuex的时候 就先从缓存中读取
+  username:"",
 }
 const mutations = {
-  REMOVE_TOKEN (state) {
-    state.token = null//将vuex的数据置空
-    removeToken()//同步到缓存
+  REMOVE_TOKEN(state){
+    localStorage.removeItem('authToken');
   },
   SET_TOKEN: (state, token) => {
-    state.token = token//将数据设置给vuex
-    //同步缓存
-    setToken(token)
-  },
-  SET_INTRODUCTION: (state, introduction) => {
-    state.introduction = introduction
+    state.authToken = value;
+	  localStorage.setItem('authToken', token);
   },
   SET_NAME: (state, name) => {
     state.name = name
   },
 }
 const actions = {
-  async login (context, data) {
+  async login(context,data){
     const result = await login(data)
-    if (result.data.sucess) {
+    if(result.data.sucess){
       //调用vuex中setToken方法
-      context.commit('setToken', result.data.data)
+      context.commit('setToken',result.data.data)
     }
   }
 }
 export default {
-  namespaced: true,
   state,
   mutations,
   actions,

+ 1 - 0
src/views/healthManagement/curveDeviation.vue

@@ -26,6 +26,7 @@
           <template slot-scope="scope">
             <el-button @click="renderCharts('zxt', scope.row.wtId)" type="text" size="small">曲线趋势</el-button>
             <el-button @click="renderCharts('sdt', scope.row.wtId)" type="text" size="small">散点趋势</el-button>
+            
           </template>
         </el-table-column>
       </el-table>

+ 1 - 0
src/views/healthManagement/healthManagement.vue

@@ -191,6 +191,7 @@
                   <div class="recommendItem" v-for="domain in Confirmed" :key="domain.key">
                     <div class="inline" style="background:rgb(84, 92, 100);color:#fff;">
                       <div class="l">风机编号</div>
+                      
                         <p class="to" style="width:50%;text-align:center;">{{domain.wtid}}</p>
                       <div class="r">跟踪</div>
                     </div>