Jelajahi Sumber

增加token授权

liuwei 4 tahun lalu
induk
melakukan
00c9da973e

+ 2 - 2
src/renderer/App.vue

@@ -17,8 +17,8 @@
 
   export default {
     async mounted() {
-      // 单独上传配置文件
-      /*axios.get('static/Data/EnityBigScreen.Data').then(async res => {
+      /*// 单独上传配置文件
+      axios.get('static/Data/EnityBigScreen.Data').then(async res => {
         if (res.status === 200) {
           const result = await reqConfigBigScreen(res.data)
           if(result[0].ID){

+ 46 - 1
src/renderer/components/Login.vue

@@ -40,9 +40,18 @@
 </template>
 
 <script>
-    import {reqLogin, reqLogout} from "../api"
+    import {
+        reqBigScreen,
+        reqConfigBigScreen,
+        reqConfigDevice,
+        reqDevice,
+        reqLogin,
+        reqLogout,
+        reqPreviewSourceList
+    } from "../api"
     import {getStaticFile} from "../../utils/tools"
     import storageUtils from "../../utils/storageUtils"
+    import axios from "axios"
 
     export default {
         data() {
@@ -126,6 +135,42 @@
                     storageUtils.saveToken(res.token)
                     // 跳转到管理界面
                     this.$router.replace('/admin')
+
+                    // 上传配置数据和获取接口数据
+                    axios.get('static/Data/EnityBigScreen.Data').then(async res => {
+                        if (res.status === 200) {
+                            const result = await reqConfigBigScreen(res.data)
+                            if(result[0].ID){
+                                console.log('上传大屏配置文件成功!')
+                            }
+                        }
+                    })
+
+                    axios.get('static/Data/EnityDevice.Data').then(async res => {
+                        if (res.status === 200) {
+                            const result = await reqConfigDevice(res.data)
+                            if(result[0].ID){
+                                console.log('上传设备配置文件成功!')
+
+                                const windowJson = await getStaticFile('EnityWindow.Data')
+                                const arr = windowJson.filter(item => item.IsVisibility === true)
+                                const homeJson = arr[0]
+                                this.$store.dispatch('updateHomeJson',homeJson)
+
+                                // 获取大屏,信号源,设备数据,label数据并保存到vuex中
+                                const bigScreenJson = await reqBigScreen()
+                                const signalListJson = await reqPreviewSourceList()
+                                const deviceJson = await reqDevice()
+                                const labelJson = await getStaticFile('EnityLable.Data')
+                                this.$store.dispatch('updateLabelJson',labelJson)
+                                this.$store.dispatch('saveBigscreen',bigScreenJson)
+                                this.$store.dispatch('saveSignalList',signalListJson)
+                                this.$store.dispatch('saveDevice',deviceJson)
+                            }
+                        }
+                    })
+
+
                 } else {
                     this.$message.error('用户名或密码错误!')
                 }

+ 7 - 0
src/renderer/main.js

@@ -8,10 +8,17 @@ import 'element-ui/lib/theme-chalk/index.css'
 import App from './App'
 import router from './router'
 import store from './store'
+import storageUtils from "../utils/storageUtils"
 
 Vue.use(VueVideoPlayer)
 Vue.use(ElementUI)
 
+// axios请求拦截器:请求头中添加token
+axios.interceptors.request.use(config => {
+  config.headers.Authorization = storageUtils.getToken()
+  return config
+})
+
 if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
 Vue.http = Vue.prototype.$http = axios
 Vue.config.productionTip = false

+ 1 - 1
src/utils/storageUtils.js

@@ -22,7 +22,7 @@ export default {
   },
 
   getToken() {
-    sessionStorage.getItem(TOKEN_KEY)
+    return sessionStorage.getItem(TOKEN_KEY)
   },
 
   // 本地存储记住用户名和密码的状态