zhaoke 3 жил өмнө
parent
commit
a484bb0dd2

+ 1 - 0
public/config.js

@@ -1,5 +1,6 @@
 var PLATFROM_CONFIG = {};
 PLATFROM_CONFIG.baseUrl = "https://authgateway.fsjtkj.cn/" // http请求地址
+PLATFROM_CONFIG.socketUrl = "ws://192.168.3.239:8998/websocket" // websocket请求地址
 PLATFROM_CONFIG.appSecret = "40t7vcbi5bc1twyihd2dum82yn1mt1kj" //appSecret
 PLATFROM_CONFIG.appId = "unsk1w37910olf8j" //appid
 // does job show yes/no 显示/不显示职务

+ 3 - 0
src/App.vue

@@ -44,6 +44,7 @@ import { mapGetters } from "vuex";
 import { SsoLogin } from "@/api/apiHome";
 import { GetSSOCheckCode } from "@/api/login";
 import { getCodeToken } from "@/utils/auth";
+import { wsSocketClose, wsSocket } from "@/utils/socket"
 export default {
   name: "App",
   components: {
@@ -158,6 +159,8 @@ export default {
       if (oldViews) {
         this.handleInit();
       }
+      wsSocketClose()
+      wsSocket()
     },
     /**
      * @description: 定时器方法

+ 9 - 2
src/store/modules/app.js

@@ -20,6 +20,7 @@ const state = {
   outcheck: false,
   systemSet: Cookies.get('systemSet') != null ? Cookies.get('systemSet') : null,
   errorNum: Cookies.get('errorNum') ? Cookies.get('errorNum') : 0,
+  wsData: []
 }
 const mutations = {
   TOGGLE_SIDEBAR: state => {
@@ -59,7 +60,10 @@ const mutations = {
   ERROR_NUM: (state, systemSet) => {
     state.errorNum = systemSet
     Cookies.set('errorNum', systemSet)
-  }
+  },
+  WS_DATA: (state, data) => {
+    state.wsData = data
+  },
 }
 
 const actions = {
@@ -89,7 +93,10 @@ const actions = {
   },
   getErrorNum ({ commit }, systemSet) {
     commit('ERROR_NUM', systemSet)
-  }
+  },
+  getWsData ({ commit }, data) {
+    commit('WS_DATA', data)
+  },
 }
 
 export default {

+ 2 - 0
src/store/modules/user.js

@@ -1,6 +1,7 @@
 import { login, loginUp, getInfo } from '@/api/login'
 import { getToken, setToken, removeToken, setUserId, TokenKey } from '@/utils/auth'
 import { resetRouter } from '@/router'
+import { wsSocketClose } from '@/utils/socket'
 const getDefaultState = () => {
   return {
     token: getToken(),
@@ -120,6 +121,7 @@ const actions = {
         resetRouter();
         commit('RESET_STATE');
         commit('SET_ROLES', []);
+        wsSocketClose();
         resolve();
       })
 

+ 3 - 3
src/utils/request.js

@@ -15,7 +15,7 @@ import { Loading } from 'element-ui'
 // create an axios instance
 const service = axios.create({
   //baseURL: baseURL, // url = base url + request url
-  //baseURL: 'http://106.14.243.117:9002',
+  // baseURL: 'http://192.168.3.239:8998',
   baseURL: `${PLATFROM_CONFIG.baseUrl}`,
   // withCredentials: true, // send cookies when cross-domain requests
   timeout: 30000, // request timeout
@@ -109,7 +109,7 @@ service.interceptors.response.use(
           type: 'error',
           duration: 5 * 1000,
           onClose: () => {
-            store.dispatch('tagsView/delAllViews').then(() => {})
+            store.dispatch('tagsView/delAllViews').then(() => { })
             store.dispatch('user/resetToken').then(() => {
               location.reload()
             })
@@ -159,7 +159,7 @@ service.interceptors.response.use(
         duration: 5 * 1000,
         onClose: () => {
           store.dispatch('app/toggleDialog', false)
-          store.dispatch('tagsView/delAllViews').then(() => {})
+          store.dispatch('tagsView/delAllViews').then(() => { })
           store.dispatch('user/resetToken').then(() => {
             location.reload()
           })

+ 37 - 0
src/utils/socket.js

@@ -0,0 +1,37 @@
+import store from '@/store'
+let ws = null
+
+export function wsSocket () {
+
+  ws = new WebSocket(`${PLATFROM_CONFIG.socketUrl}`)
+
+  ws.onopen = function () {
+    console.log('ws打开')
+  }
+
+  ws.onmessage = function (res) {
+    const datas = JSON.parse(res.data)
+    store.dispatch('app/getWsData', datas)
+    console.log('ws数据', datas)
+  }
+
+  ws.onerror = function (err) {
+    console.log('ws错误', err)
+  }
+
+  ws.onclose = function () {
+    console.log('ws关闭')
+  }
+}
+
+export function wsSendData (msg) {
+  if (ws) {
+    ws.send(msg)
+  }
+}
+
+export function wsSocketClose () {
+  if (ws) {
+    ws.close()
+  }
+}

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

@@ -61,6 +61,7 @@ import { GetCheckCode, getToken } from '@/api/login';
 import { GetSystemSet } from "@/api/systemConfiguration";
 import { setCodeToken, getCodeToken } from '@/utils/auth';
 import { getAuthListByUser } from '@/api/Account';
+import { wsSocket } from '@/utils/socket';
 export default {
   name: 'Login',
   components: { Identify, Dialog },
@@ -166,6 +167,7 @@ export default {
                       this.$store.dispatch('user/setPowerList', []);
                       this.$router.push('/');
                     }
+                    wsSocket();
                   } else {
                     this.loading = false;
                     this.$store.dispatch("user/logout");