diff --git a/src/api/http.js b/src/api/http.js index 8d3234d..feedc32 100644 --- a/src/api/http.js +++ b/src/api/http.js @@ -1,112 +1,120 @@ import axios from 'axios'; import { - Message + Message } from 'element-ui' import router from '../router/index' import Cookie from 'js-cookie' import config from '@/config' const service = axios.create({ - baseURL: config.host, - timeout: 10000000 + baseURL: config.host, + timeout: 10000000 }) // post请求头 service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; // 请求拦截器 service.interceptors.request.use(config => { - const token = Cookie.get('admin-token') - if (token) { - config.headers.token = token + const token = Cookie.get('admin-token') + if (token) { + config.headers.token = token + } + return config; +}, err => { + Message.error({ + message: '退出登陆', + onClose: function () { + router.push({ name: 'login' }); } - return config; - }, err => { - Message.error({ - message: '退出登陆', - onClose: function () { - router.push({name: 'login'}); - } - }) - return Promise.reject(err); + }) + return Promise.reject(err); }) let logouted = 0; // 响应拦截器 service.interceptors.response.use( - response => { - const res = response.data; - if (res.status == 200 || res.status == 10000 || res.status == 30001) { - return Promise.resolve(res).catch(e => {}); - } else if (!res.status) { - return Promise.resolve(res).catch(e => {}); - } else { - Message.error(res.message) - return Promise.reject(res) - } - }, - // 服务器状态码不是200的情况 - error => { - if (error.response.status) { - switch (error.response.status) { - // 401: 未登录 - case 401: - if (!logouted) { - Message.error('登录过期,请重新登录') - setTimeout(() => { - history.back() - }, 1500) - logouted = 1 - } - break; - default: - // Message.error(error.response.data.message) - Promise.reject(error.response); - } - return Promise.reject(error.response); - } + response => { + const res = response.data; + if (res.status == 200 || res.status == 10000 || res.status == 30001) { + return Promise.resolve(res).catch(e => { }); + } else if (res.code === 401) { + // 账号互踢 + if (!logouted) { + Message.error(res.msg.includes('顶') ? '您的账号已在其他设备登录,您已被迫下线!' : '登录过期,请重新登录!') + setTimeout(() => { + history.back() + }, 1500) + logouted = 1 + } + } else if (!res.status) { + return Promise.resolve(res).catch(e => { }); + } else { + Message.error(res.message) + return Promise.reject(res) + } + }, + // 服务器状态码不是200的情况 + error => { + if (error.response.status) { + switch (error.response.status) { + // 401: 未登录 + case 401: + if (!logouted) { + Message.error('登录过期,请重新登录') + setTimeout(() => { + history.back() + }, 1500) + logouted = 1 + } + break; + default: + Promise.reject(error.response); + } + return Promise.reject(error.response); } + } ); -function get(url, params) { - return new Promise((resolve, reject) => { - service.get(url, { params: params }).then(res => { - resolve(res); - }).catch(err => { - reject(err); - }); +function get (url, params) { + return new Promise((resolve, reject) => { + service.get(url, { params: params }).then(res => { + resolve(res); + }).catch(err => { + reject(err); }); + }); } -function post(url, params) { - return new Promise((resolve, reject) => { - service.post(url, params).then(res => { - resolve(res); - }).catch(err => { - reject(err.data); - }); +function post (url, params) { + return new Promise((resolve, reject) => { + service.post(url, params).then(res => { + resolve(res); + }).catch(err => { + reject(err.data); }); + }); } -function del(url, params) { - return new Promise((resolve, reject) => { - service.delete(url, { - params - }).then(res => { - resolve(res); - }).catch(err => { - reject(err.data); - }); +function del (url, params) { + return new Promise((resolve, reject) => { + service.delete(url, { + params + }).then(res => { + resolve(res); + }).catch(err => { + reject(err.data); }); + }); } -function put(url, params) { - return new Promise((resolve, reject) => { - service.put(url, params).then(res => { - resolve(res); - }).catch(err => { - reject(err.data); - }); +function put (url, params) { + return new Promise((resolve, reject) => { + service.put(url, params).then(res => { + resolve(res); + }).catch(err => { + reject(err.data); }); + }); } export { get, post, del, put } \ No newline at end of file diff --git a/src/components/TestPanel.vue b/src/components/TestPanel.vue index ee6c3e9..02962ad 100644 --- a/src/components/TestPanel.vue +++ b/src/components/TestPanel.vue @@ -214,8 +214,10 @@ import "codemirror/theme/base16-light.css"; import { mavonEditor } from 'mavon-editor' import 'mavon-editor/dist/css/index.css' import Stomp from 'stompjs' -export const MQTT_USERNAME = 'huoran' // 连接用户名, todo: read from database -export const MQTT_PASSWORD = 'huoran2024' // 连接密码, todo: read from database +// export const MQTT_USERNAME = 'huoran' // 连接用户名, todo: read from database +// export const MQTT_PASSWORD = 'huoran2024' // 连接密码, todo: read from database +export const MQTT_USERNAME = 'huorantest' // 连接用户名, todo: read from database +export const MQTT_PASSWORD = 'huorantest2024' // 连接密码, todo: read from database export default { data () { @@ -1090,8 +1092,8 @@ export default { // 消息队列获取 connect () { - // let ws = new WebSocket(`ws://124.71.74.9:15674/ws`); - let ws = new WebSocket(`wss://python.occupationlab.com/ws`); + let ws = new WebSocket(`ws://139.159.153.48:15674/ws`); + // let ws = new WebSocket(`wss://python.occupationlab.com/ws`); this.client = Stomp.over(ws); this.client.heartbeat.outgoing = 0 this.client.heartbeat.incoming = 0 diff --git a/src/config/index.js b/src/config/index.js index b584acd..2416b53 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -13,8 +13,8 @@ let host = location.origin + '/' let bankPath = `${location.origin}/banksystem` // 银行系统 // 121.37.12.51 | 192.168.31.151 if (isDev) { - // host = 'http://192.168.31.217:9000/' - host = 'http://121.37.12.51:9000/' + host = 'http://192.168.31.51:9000/' + // host = 'http://121.37.12.51:9000/' // host = 'https://occupationlab.com/' bankPath = `http://${location.hostname}:8093` } else if (isPro) { diff --git a/src/views/Home.vue b/src/views/Home.vue index bb3cb0c..09995ed 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -5,43 +5,47 @@
{{ curriculumName }}
{{ $config.title }}
-编程语言
-{{ $config.title }}
+编程语言
+