diff --git a/ui/dasadmin/src/api/common.ts b/ui/dasadmin/src/api/common.ts index 3e35a5bc..a558cb5e 100644 --- a/ui/dasadmin/src/api/common.ts +++ b/ui/dasadmin/src/api/common.ts @@ -2,7 +2,6 @@ import createAxios from '/@/utils/axios' import { isAdminApp, checkFileMimetype } from '/@/utils/common' import { getUrl } from '/@/utils/axios' import { useAdminInfo } from '/@/stores/adminInfo' -import { useUserInfo } from '/@/stores/userInfo' import { ElNotification, type UploadRawFile } from 'element-plus' import { useSiteConfig } from '/@/stores/siteConfig' import { state as uploadExpandState, fileUpload as uploadExpand } from '/@/components/mixins/baUpload' @@ -27,10 +26,10 @@ export const changeTerminalConfigUrl = '/admin/ajax/changeTerminalConfig' export const clearCacheUrl = '/admin/ajax/clearCache' // 公共 -export const captchaUrl = '/api/captchaImage' -export const clickCaptchaUrl = '/api/captchaImage' +export const captchaUrl = '/api/auth/captchaImage' +export const clickCaptchaUrl = '/api/auth/captchaImage' export const checkClickCaptchaUrl = '/api/common/checkClickCaptcha' -export const refreshTokenUrl = '/api/common/refreshToken' +export const refreshTokenUrl = '/api/auth/refreshToken' // api模块(前台) export const apiUploadUrl = '/api/ajax/upload' diff --git a/ui/dasadmin/src/utils/axios.ts b/ui/dasadmin/src/utils/axios.ts index 9a204ea8..7d557f16 100644 --- a/ui/dasadmin/src/utils/axios.ts +++ b/ui/dasadmin/src/utils/axios.ts @@ -8,6 +8,7 @@ import adminBaseRoute from '/@/router/static/adminBase' import { useAdminInfo } from '/@/stores/adminInfo' import { useConfig } from '/@/stores/config' import { encrypt_aes, decrypt_aes, generateRandomNumber } from './crypto' +import { json } from 'stream/consumers' window.requests = [] window.tokenRefreshing = false @@ -48,6 +49,7 @@ function createAxios>(axiosConfig: AxiosRequest headers: { 'think-lang': config.lang.defaultLang, server: true, + 'Content-Type': 'application/json', }, responseType: 'json', }) @@ -88,14 +90,14 @@ function createAxios>(axiosConfig: AxiosRequest if (config.method === 'post' && config.data) { // 对data进行加密 - const formData = new FormData() - formData.append('param', encrypt_aes(config.data, v)) - config.data = formData + // const formData = new FormData() + // formData.append('param') + config.data = encrypt_aes(config.data, v) } else if (config.method === 'get' && config.params) { // 对params进行加密 - const formData = new FormData() - formData.append('param', encrypt_aes(config.params, v)) - config.params = formData + // const formData = new FormData() + // formData.append('param') + config.params = encrypt_aes(config.params, v) } // 自动携带token @@ -120,35 +122,36 @@ function createAxios>(axiosConfig: AxiosRequest if (response.config.responseType == 'json') { if (response.data && response.data.code == 401) { - // if (response.data.code == 409) { - // if (!window.tokenRefreshing) { - // window.tokenRefreshing = true - // return refreshToken() - // .then((res) => { - // adminInfo.setToken(res.data.token, 'auth') - // response.headers.token = `${res.data.token}` - // window.requests.forEach((cb) => cb(res.data.token, 'admin-refresh')) - // window.requests = [] - // return Axios(response.config) - // }) - // .catch((err) => { - // adminInfo.removeToken() - // router.push({ name: 'adminLogin' }) - // return Promise.reject(err) - // }) - // .finally(() => { - // window.tokenRefreshing = false - // }) - // } else { - // return new Promise((resolve) => { - // // 用函数形式将 resolve 存入,等待刷新后再执行 - // window.requests.push((token: string, type: string) => { - // response.headers.token = `${token}` - // resolve(Axios(response.config)) - // }) - // }) - // } - // } + if (response.data.code == 409) { + if (!window.tokenRefreshing) { + window.tokenRefreshing = true + return refreshToken() + .then((res) => { + adminInfo.setToken(res.data.token, 'auth') + response.headers.token = `${res.data.accessToken}` + window.requests.forEach((cb) => cb(res.data.accessToken, 'admin-refresh')) + window.requests = [] + return Axios(response.config) + }) + .catch((err) => { + adminInfo.removeToken() + router.push({ name: 'adminLogin' }) + return Promise.reject(err) + }) + .finally(() => { + window.tokenRefreshing = false + }) + } else { + return new Promise((resolve) => { + // 用函数形式将 resolve 存入,等待刷新后再执行 + window.requests.push((token: string, type: string) => { + const v = response.headers.v + response.headers.token = encrypt_aes(token, v) + resolve(Axios(response.config)) + }) + }) + } + } // if (options.showCodeMessage) { // ElNotification({ // type: 'error', diff --git a/ui/dasadmin/src/views/backend/login.vue b/ui/dasadmin/src/views/backend/login.vue index efb15144..efa20464 100644 --- a/ui/dasadmin/src/views/backend/login.vue +++ b/ui/dasadmin/src/views/backend/login.vue @@ -117,7 +117,7 @@ const form = reactive({ username: '', password: '', keep: false, - uuid: '', + key: '', code: '', }) @@ -174,7 +174,7 @@ const onSubmitPre = () => { const load = () => { getCaptchaData().then((res) => { - form.uuid = res.data.key + form.key = res.data.key state.captcha = 'data:image\/png;base64,' + res.data.img }) }