Browse Source

增加用户信息

wangb 3 months ago
parent
commit
6857c4ae40

+ 3 - 3
.env.development

@@ -11,7 +11,7 @@ VUE_APP_TITLE = '页面标题'
 # 马力军
 # VUE_APP_LOGIN_URL = 'http://192.168.2.45:48080'
 # 王波
-VUE_APP_LOGIN_URL = 'http://172.16.12.101:48080'
+VUE_APP_LOGIN_URL = 'http://172.16.12.102:48080'
 # VUE_APP_LOGIN_URL = 'http://172.16.12.102:8190'
 
 # 发电能力分析
@@ -31,11 +31,11 @@ VUE_APP_REPORT_URL = 'http://172.16.12.101:9001'
 
 # 功率预测
 # 徐世利
-VUE_APP_BASE_URL = 'http://192.168.2.150:8086'
+# VUE_APP_BASE_URL = 'http://192.168.2.150:8086'
 # 马力军
 # VUE_APP_BASE_URL = 'http://192.168.2.45:8086'
 # 王波
-# VUE_APP_BASE_URL = 'http://172.16.12.101:8086'
+VUE_APP_BASE_URL = 'http://172.16.12.101:8086'
 
 # 综合报警
 # VUE_APP_ALARM = 'http://10.127.7.241:6015'

+ 9 - 1
src/api/gengra.js

@@ -4,12 +4,20 @@ import httpRequest from '@/utils/request.js'
 export function apiProjectLogin(params) {
     return httpRequest({
         baseURL: process.env.VUE_APP_LOGIN_URL,
-        url: 'admin-api/system/auth/login',
+        // url: 'admin-api/system/auth/login',
         url: 'login',
         data: params,
         method: "post"
     })
 }
+// 获取用户信息
+export function apigetUserInfo() {
+    return httpRequest({
+        baseURL: process.env.VUE_APP_LOGIN_URL,
+        url: 'getInfo',
+        method: "get"
+    })
+}
 
 // 风电数据准备页面
 export function apiGetbaseStation() {

+ 58 - 30
src/components/commonHeaders.vue

@@ -74,7 +74,7 @@ import moon_W from "@/assets/images/headerCom/moon_W.png";
 import headerMenuImg from "@/assets/images/headerCom/headerMenu.png";
 import { Sunny, Moon } from "@element-plus/icons-vue";
 import { apiGetpersonalInformation } from "@/api/api";
-import { removeToken } from "@/utils/auth";
+import { removeToken, removeUserKey, getUserKey } from "../utils/auth";
 export default {
   name: "headerCom",
   data() {
@@ -92,7 +92,34 @@ export default {
       leftIndex: "1",
       currentTime: "",
       showRole: true,
-      menuData: [],
+      menuData: [
+          {
+            index: "/home",
+            icon: "Menu",
+            name: "首页",
+            showBac: true,
+          },
+          {
+            index: "/generatingCap/dataFilter/prepare",
+            icon: "Histogram",
+            name: "发电能力分析",
+          },
+          {
+            index: "/integratedAlarm/realwarning",
+            icon: "Histogram",
+            name: "综合报警",
+          },
+          {
+            index: "/intelligentReport/gkjlb?name=xinzhuang",
+            icon: "PictureFilled",
+            name: "智能报表",
+          },
+          {
+            index: "/powerPrediction/index",
+            icon: "TrendCharts",
+            name: "功率预测",
+          },
+      ],
       rainW: false,
       userName: "",
       switchTheme: false,
@@ -101,34 +128,33 @@ export default {
   },
   created() {
     this.headerReportUrl = this.baseReportUrl;
-    this.menuData = [
-      {
-        index: "/home",
-        icon: "Menu",
-        name: "首页",
-        showBac: true,
-      },
-      {
-        index: "/generatingCap/dataFilter/prepare",
-        icon: "Histogram",
-        name: "发电能力分析",
-      },
-      {
-        index: "/integratedAlarm/realwarning",
-        icon: "Histogram",
-        name: "综合报警",
-      },
-      {
-        index: "/intelligentReport/gkjlb?name=xinzhuang",
-        icon: "PictureFilled",
-        name: "智能报表",
-      },
-      {
-        index: "/powerPrediction/index",
-        icon: "TrendCharts",
-        name: "功率预测",
-      },
-    ];
+    console.log("userkey==>>>", this.$store.state.userKey)
+    const userKey = getUserKey()
+    this.$store.commit("changeUserkey", userKey);
+    let menuData = []
+    if (userKey === "zz") {
+      menuData = [
+          {
+            index: "/home",
+            icon: "Menu",
+            name: "首页",
+            showBac: true,
+          },
+          {
+            index: "/intelligentReport/gkjlb?name=xinzhuang",
+            icon: "PictureFilled",
+            name: "智能报表",
+          },
+          {
+            index: "/powerPrediction/index",
+            icon: "TrendCharts",
+            name: "功率预测",
+          }
+      ]
+    } else {
+      menuData = this.menuData
+    }
+    this.menuData = menuData
   },
   mounted() {
     let that = this;
@@ -238,6 +264,8 @@ export default {
     // },
     backLogin() {
       window.sessionStorage.clear();
+      removeToken();
+      removeUserKey();
     //   this.getThemeClass(true);
     //   this.$emit("swichFn", true);
       this.$router.push({

+ 8 - 8
src/permission.js

@@ -15,7 +15,7 @@ import { isRelogin } from "./utils/request";
 
 NProgress.configure({ showSpinner: false }) // 关闭加载微调器
 
-const whiteList = ['/login','/404','/layout', '/home'] // 设置白名单,用于任何人可访问
+const whiteList = ['/login','/404','/layout'] // 设置白名单,用于任何人可访问
 
 // 钩子函数
 router.beforeEach((to, from, next) => {
@@ -37,14 +37,14 @@ router.beforeEach((to, from, next) => {
         }
   } else {
     // 没有token
-    // if (whiteList.indexOf(to.path) !== -1) {
-    //   // 在免登录白名单,直接进入
-    //   next()
-    // } else {
-    //   next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
-    //   NProgress.done()
-      // }
+    if (whiteList.indexOf(to.path) !== -1) {
+      // 在免登录白名单,直接进入
       next()
+    } else {
+      next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
+      NProgress.done()
+      }
+      // next()
   }
 })
 

+ 8 - 0
src/store/index.js

@@ -7,12 +7,14 @@
  */
 import { createStore } from 'vuex'
 import user from './modules/user'
+import { getUserKey } from "../utils/auth";
 
 export default createStore({
   state: {
     theme: false,
     themeName: "dark",
     moreSty: "blueSty",
+    userKey: getUserKey() || "gly",
     readyProgress: 0,
     alarmList: (localStorage.getItem("alarmList") ? JSON.parse(localStorage.getItem("alarmList")) : []),
     warnList: [], //弹窗报警列表
@@ -28,6 +30,9 @@ export default createStore({
     changeTheme(state, tag) {
       state.theme = tag;
     },
+    changeUserkey(state, value) {
+      state.userKey = value;
+    },
     setReadyProgress(state, value) {
       state.readyProgress = value;
     },
@@ -52,6 +57,9 @@ export default createStore({
     changeTheme(context, bool) {
       context.commit("changeTheme", bool);
     },
+    changeUserkey(context, value) {
+      context.commit("changeUserkey", value);
+    },
     setReadyProgress(context, value) {
       context.commit("setReadyProgress", value);
     },

+ 13 - 0
src/utils/auth.js

@@ -8,6 +8,7 @@
 import Cookies from 'js-cookie'
 
 const TokenKey = 'Admin-Token'
+const UserIdKey = "userkey";
 
 export function getToken() {
   return Cookies.get(TokenKey)
@@ -20,3 +21,15 @@ export function setToken(token) {
 export function removeToken() {
   return Cookies.remove(TokenKey)
 }
+
+export function getUserKey() {
+  return Cookies.get(UserIdKey)
+}
+
+export function setUserKey(userKey) {
+  return Cookies.set(UserIdKey, userKey)
+}
+
+export function removeUserKey() {
+  return Cookies.remove(UserIdKey)
+}

+ 4 - 1
src/utils/request.js

@@ -31,7 +31,10 @@ const service = axios.create({
 // request拦截器
 service.interceptors.request.use(config => {
   // 是否需要设置 token (默认是存在的,只有传值 false 的时候是不需要token)
-  config.headers.token = getToken()
+//   config.headers.token = getToken()
+if (getToken()) {
+    config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
+  }
   return config
 }, error => {
     console.log(error)

+ 1 - 1
src/views/IntegratedAlarm/alarmConfig/customConfig/index.vue

@@ -175,7 +175,7 @@
           </template>
         </el-table-column>
 
-        <el-table-column label="操作" align="center" width="100">
+        <el-table-column label="操作" align="center" width="100" v-if="$store.state.userKey !== 'ld'">
           <template #default="scope">
             <el-button
               type="text"

+ 1 - 1
src/views/IntegratedAlarm/alarmConfig/historyConfig/index.vue

@@ -132,7 +132,7 @@
             </span>
           </template>
         </el-table-column>
-        <el-table-column label="操作" align="center" width="100">
+        <el-table-column label="操作" align="center" width="100" v-if="$store.state.userKey !== 'ld'">
           <template #default="scope">
             <el-button
               type="text"

+ 1 - 1
src/views/IntegratedAlarm/deviceConfig/components/custom.vue

@@ -183,7 +183,7 @@
         prop="relatedPartsName"
         min-width="30"
       /> -->
-      <el-table-column label="操作" align="center" width="80">
+      <el-table-column label="操作" align="center" width="80" v-if="$store.state.userKey !== 'ld'">
         <template #default="scope">
           <el-button
             :style="`color: ${

+ 1 - 0
src/views/IntegratedAlarm/deviceConfig/components/message.vue

@@ -50,6 +50,7 @@
     </el-form>
     <el-button
       style="float: right; border: none"
+       v-if="$store.state.userKey !== 'ld'"
       :style="`color:#fff;${
         $store.state.moreSty === 'greenSty'
           ? 'background: #05bb4c;'

+ 1 - 1
src/views/IntegratedAlarm/deviceConfig/components/windturbine.vue

@@ -116,7 +116,7 @@
           </template>
         </el-table-column>
 
-        <el-table-column label="操作" align="center" width="100">
+        <el-table-column label="操作" align="center" width="100" v-if="$store.state.userKey !== 'ld'">
           <template #default="scope">
             <el-button
               type="text"

+ 1 - 1
src/views/IntegratedAlarm/deviceConfig/components/ycpoint.vue

@@ -130,7 +130,7 @@
         </template>
       </el-table-column>
 
-      <el-table-column label="操作" width="180" align="center">
+      <el-table-column label="操作" width="180" align="center" v-if="$store.state.userKey !== 'ld'">
         <template #default="scope">
           <el-button
             type="text"

+ 1 - 1
src/views/IntegratedAlarm/deviceConfig/components/yxpoint.vue

@@ -102,7 +102,7 @@
           {{ row[item.code] ? row[item.code] : "--" }}
         </template>
       </el-table-column>
-      <el-table-column label="操作" width="180" align="center">
+      <el-table-column label="操作" width="180" align="center" v-if="$store.state.userKey !== 'ld'">
         <template #default="scope">
           <el-button
             type="text"

+ 1 - 1
src/views/IntegratedAlarm/earlyWarning/index.vue

@@ -164,7 +164,7 @@
             </p>
           </template>
         </el-table-column>
-        <el-table-column label="操作" width="80px" align="center">
+        <el-table-column label="操作" width="80px" align="center" v-if="$store.state.userKey !== 'ld'">
           <template #default="scope">
             <el-button type="primary" size="small" @click="editItem(scope.row)">
               <span style="color: #fff">编辑</span>

+ 19 - 9
src/views/login/index.vue

@@ -87,7 +87,8 @@
 
 <script>
     import {
-        setToken
+        setToken,
+        setUserKey
     } from '@/utils/auth'
     import {
         ElMessage
@@ -98,14 +99,15 @@
         apiGetWeather
     } from '@/api/api'
     import {
-        apiProjectLogin
+        apiProjectLogin,
+        apigetUserInfo
     } from '@/api/gengra'
     export default {
         data() {
             return {
                 // administrator qweABC123
-                inputUser: 'admin',
-                inputMima: 'admin123',
+                inputUser: 'Admin',
+                inputMima: 'admin@123456',
                 // inputUser: 'testdb',
                 // inputMima: '123456',
                 inputYanzhengma: '',
@@ -240,25 +242,33 @@
                 }
                 apiProjectLogin(params).then(datas => {
                     if (datas && datas.code === 200) {
-                        // setToken(datas.data.accessToken)
                         setToken(datas.token)
                         let userObj = {
                             role: '',
                             userId: datas.userId
                         }
-                        if (datas.userId === 1) {
+                        if (datas.userId === 1 || datas.userId === 6) {
                             userObj.role = 'administrators'
                             window.sessionStorage.setItem('userMessage', JSON.stringify(userObj))
                         } else {
                             userObj.role = 'ordinaryUser'
                             window.sessionStorage.setItem('userMessage', JSON.stringify(userObj))
                         }
+                        that.getUserInfo()
+                    } else {
+                        ElMessage.error(datas.msg);
+                    }
+                })
+            },
+            getUserInfo() {
+                let that = this
+                apigetUserInfo().then(res =>{
+                    if (res && res.user) {
+                        let userkey = res.roles[0] || ""
+                        setUserKey(userkey)
                         that.$router.push({
                             path: "/home"
-                            // path: "/generatingCap/dataFilter/prepare"
                         })
-                    } else {
-                        ElMessage.error(datas.msg);
                     }
                 })
             }