From 9f16b5c553b479ea12fe368a7ecc748872ea8b98 Mon Sep 17 00:00:00 2001 From: zxl <763096477@qq.com> Date: 星期四, 12 六月 2025 11:11:27 +0800 Subject: [PATCH] 修改配置文件 --- web_src/src/main.js | 70 ++++++++++++++++++++++------------- 1 files changed, 44 insertions(+), 26 deletions(-) diff --git a/web_src/src/main.js b/web_src/src/main.js old mode 100644 new mode 100755 index 20ad485..328bb25 --- a/web_src/src/main.js +++ b/web_src/src/main.js @@ -1,22 +1,24 @@ import Vue from 'vue'; import App from './App.vue'; -Vue.config.productionTip = false; -import ElementUI from 'element-ui'; +import ElementUI, {Notification} from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; import router from './router/index.js'; import axios from 'axios'; import VueCookies from 'vue-cookies'; -import echarts from 'echarts'; +import VCharts from 'v-charts'; import VueClipboard from 'vue-clipboard2'; -import { Notification } from 'element-ui'; import Fingerprint2 from 'fingerprintjs2'; import VueClipboards from 'vue-clipboards'; +import Contextmenu from "vue-contextmenujs" +import userService from "./components/service/UserService" + +Vue.config.productionTip = false; // 鐢熸垚鍞竴ID -Fingerprint2.get(function(components) { - const values = components.map(function(component,index) { +Fingerprint2.get(function (components) { + const values = components.map(function (component, index) { if (index === 0) { //鎶婂井淇℃祻瑙堝櫒閲孶A鐨剋ifi鎴�4G绛夌綉缁滄浛鎹㈡垚绌�,涓嶇劧鍒囨崲缃戠粶浼欼D涓嶄竴鏍� return component.value.replace(/\bNetType\/\w+\b/, ''); } @@ -25,38 +27,54 @@ //console.log(values) //浣跨敤鐨勬祻瑙堝櫒淇℃伅npm // 鐢熸垚鏈�缁坕d let port = window.location.port; - console.log(port); const fingerPrint = Fingerprint2.x64hash128(values.join(port), 31) Vue.prototype.$browserId = fingerPrint; - console.log("鍞竴鏍囪瘑鐮侊細" + fingerPrint); + console.log("娴忚鍣� ID: " + fingerPrint); }); Vue.use(VueClipboard); Vue.use(ElementUI); Vue.use(VueCookies); Vue.use(VueClipboards); -Vue.prototype.$axios = axios; + Vue.prototype.$notify = Notification; +Vue.use(Contextmenu); +Vue.use(VCharts); -axios.defaults.baseURL = (process.env.NODE_ENV === 'development') ? process.env.BASE_API : ""; - +axios.defaults.baseURL = (process.env.NODE_ENV === 'development') ? process.env.BASE_API : (window.baseUrl ? window.baseUrl : ""); +axios.defaults.withCredentials = true; // api 杩斿洖401鑷姩鍥炵櫥闄嗛〉闈� -// axios.interceptors.response.use(function (response) { -// // 瀵瑰搷搴旀暟鎹仛鐐逛粈涔� -// return response; -// }, function (error) { -// // 瀵瑰搷搴旈敊璇仛鐐逛粈涔� -// if (error.response.status === 401) { -// console.log((1111)) -// router.push('/login'); -// } -// return Promise.reject(error); -// }); +axios.interceptors.response.use((response) => { + // 瀵瑰搷搴旀暟鎹仛鐐逛粈涔� + let token = response.headers["access-token"]; + if (token) { + userService.setToken(token) + } + return response; +}, (error) => { + // 瀵瑰搷搴旈敊璇仛鐐逛粈涔� + if (error.response.status === 401) { + console.log("Received 401 Response") + router.push('/login'); + } + return Promise.reject(error); +}); +axios.interceptors.request.use( + config => { + if (userService.getToken() != null && config.url !== "/api/user/login") { + config.headers['access-token'] = `${userService.getToken()}`; + } + return config; + }, + error => { + return Promise.reject(error); + } +); -Vue.prototype.$cookies.config(60*30); - +Vue.prototype.$axios = axios; +Vue.prototype.$cookies.config(60 * 30); new Vue({ - router: router, - render: h => h(App), + router: router, + render: h => h(App), }).$mount('#app') -- Gitblit v1.8.0