From e38b25c98910308e6ef8cd3bbfd4ffb19f5eed89 Mon Sep 17 00:00:00 2001 From: YM <479443481@qq.com> Date: 星期四, 10 四月 2025 17:21:33 +0800 Subject: [PATCH] Merge branch 'master' of http://182.92.203.7:2001/r/LibraryAgent --- src/plugin/axios/index.ts | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 56 insertions(+), 0 deletions(-) diff --git a/src/plugin/axios/index.ts b/src/plugin/axios/index.ts new file mode 100644 index 0000000..e0c1d14 --- /dev/null +++ b/src/plugin/axios/index.ts @@ -0,0 +1,56 @@ +import axios from 'axios' +import myConfig from '@/assets/js/config.js' +// 鍒涘缓 axios 瀹炰緥 +const service = axios.create({ + baseURL: myConfig.requestCtx, + timeout: myConfig.requestTimeOut // 璇锋眰瓒呮椂鏃堕棿 +}) + +// 璇锋眰鎷︽埅鍣� +// app-6MPX5Fr97eK6BWHpy8g7vddd + +service.interceptors.request.use( + (config) => { + const token = "app-6MPX5Fr97eK6BWHpy8g7vddd" + if (token) config.headers['Authorization'] = `Bearer ${token}` + return config + }, + (error) => { + // 鍙戦�佸け璐� + Promise.reject(error) + } +) + +// 鍝嶅簲鎷︽埅鍣� +service.interceptors.response.use( + (response) => { + // dataAxios 鏄� axios 杩斿洖鏁版嵁涓殑 data + const dataAxios = response.data + if (typeof dataAxios.data === 'boolean') { + return dataAxios.data + } + if (response.config.responseType == 'blob') { + return dataAxios + } + const { success } = dataAxios + if (dataAxios.currentDate) { + sessionStorage.currentDate = new Date(dataAxios.currentDate).getTime() + } + // 鏍规嵁 code 杩涜鍒ゆ柇 + if (success) { + return dataAxios.data ? dataAxios.data : dataAxios + } else { + // 鎻愮ず閿欒 + } + }, + (error) => { + if (error.response && error.response.data && error.response.data.error) { + console.error(error.response.data.error.msg) + } else { + console.error('璇锋眰鍙戠敓閿欒') + } + return Promise.reject(error) + } +) + +export default service -- Gitblit v1.9.1