diff --git a/ruoyi-ui/src/views/JiHeExpressway/components/Buttons/Button.vue b/ruoyi-ui/src/views/JiHeExpressway/components/Buttons/Button.vue index fd383c28..06b7bb5d 100644 --- a/ruoyi-ui/src/views/JiHeExpressway/components/Buttons/Button.vue +++ b/ruoyi-ui/src/views/JiHeExpressway/components/Buttons/Button.vue @@ -19,7 +19,7 @@ export default { diff --git a/ruoyi-ui/src/views/JiHeExpressway/pages/service/PublishingChannelManagement/components/Switcher.vue b/ruoyi-ui/src/views/JiHeExpressway/pages/service/PublishingChannelManagement/components/Switcher.vue new file mode 100644 index 00000000..ba3232a1 --- /dev/null +++ b/ruoyi-ui/src/views/JiHeExpressway/pages/service/PublishingChannelManagement/components/Switcher.vue @@ -0,0 +1,94 @@ + + + + + diff --git a/ruoyi-ui/src/views/JiHeExpressway/pages/service/PublishingChannelManagement/index.vue b/ruoyi-ui/src/views/JiHeExpressway/pages/service/PublishingChannelManagement/index.vue index af4468ac..07aba29e 100644 --- a/ruoyi-ui/src/views/JiHeExpressway/pages/service/PublishingChannelManagement/index.vue +++ b/ruoyi-ui/src/views/JiHeExpressway/pages/service/PublishingChannelManagement/index.vue @@ -1,15 +1,71 @@ diff --git a/ruoyi-ui/src/views/JiHeExpressway/utils/axios/auth.js b/ruoyi-ui/src/views/JiHeExpressway/utils/axios/auth.js index bce63156..757ffb27 100644 --- a/ruoyi-ui/src/views/JiHeExpressway/utils/axios/auth.js +++ b/ruoyi-ui/src/views/JiHeExpressway/utils/axios/auth.js @@ -1,22 +1,45 @@ import axios from "axios"; -const RequestURL = `http://10.168.65.211:3000`; +// 摄像头 +// const RequestURL = `http://10.168.65.211:3000`; -const UN = "jhgskj", - PD = "jhgskj@2023", +// 后台 +const RequestURL = `http://10.168.77.209:1024/dev-api`; + +// const UN = "jhgskj", +// PD = "jhgskj@2023", +const UN = "admin", + PD = "admin123", tokeKey = "LOCAL_TOKEN"; +let continueRefreshToken = true; + function getToken() { - return axios - .post(`${RequestURL}/apiLogin`, { - username: UN, - password: PD, - }) - .then((res) => { - localStorage.setItem(tokeKey, res.data.token); - - return res.data.token; - }); + const token = localStorage.getItem(tokeKey); + + if (token) return Promise.resolve(token); + + return new Promise((resolve, reject) => { + axios + .post(`${RequestURL}/login`, { + username: UN, + password: PD, + }) + .then((res) => { + if (res.data.code === 200) { + localStorage.setItem(tokeKey, `Bearer ${res.data.token}`); + console.log("get token success"); + resolve(res.data.token); + } else { + console.log("get token failed"); + reject(void 0); + } + }) + .catch((e) => { + console.log("get token failed", error); + reject(e); + }); + }); } const axiosIns = axios.create({ @@ -28,11 +51,9 @@ axiosIns.defaults.baseURL = RequestURL; // request拦截器 axiosIns.interceptors.request.use( async (config) => { - // let token = localStorage.getItem(tokeKey); - - // if (!token) token = await getToken(); + const token = await getToken(); - // config.headers["Authorization"] = token; + config.headers["Authorization"] = token; return config; }, @@ -44,7 +65,18 @@ axiosIns.interceptors.request.use( // response拦截器 axiosIns.interceptors.response.use( async (response) => { - // if (response.data.code === 401) {} + if (response.data.code === 401 && continueRefreshToken) { + localStorage.removeItem(tokeKey); + + return getToken() + .then(async () => { + return await axiosIns.request(response.config); + }) + .catch((e) => { + continueRefreshToken = false; + return null; + }); + } return response.data; }, diff --git a/ruoyi-ui/vue.config.js b/ruoyi-ui/vue.config.js index bdb6139f..c65bee06 100644 --- a/ruoyi-ui/vue.config.js +++ b/ruoyi-ui/vue.config.js @@ -41,7 +41,7 @@ module.exports = { // target: `http://192.168.0.194:8080`, // target: `http://10.0.81.201:8080`, // target: `http://10.168.73.36:8080`, // 周乐 - target: `http://10.168.77.209:8080`,// 刘朋 + target: `http://10.168.77.209:8080`, // 刘朋 // target: `http://10.168.66.196:8080`, changeOrigin: true, pathRewrite: {