From aed250da13d3ca3a1004647cfca81aaa01252296 Mon Sep 17 00:00:00 2001 From: xuhongjie <1943105267@qq.com> Date: Fri, 18 Apr 2025 09:05:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=90=84=E4=B8=AA=E5=9B=BE=E8=A1=A8=E6=9C=80=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=AE=B0=E5=BD=95=EF=BC=8C=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=BE=85=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +- src/api/axios.ts | 50 +++++--- src/api/path/project.api.ts | 2 +- src/api/refresh.js | 37 ++++++ src/views/AI/chat/index.vue | 30 ++++- src/views/AI/components/history/index.vue | 113 +++++++++++++++++- src/views/AI/index.vue | 44 +++++-- .../components/CanvasPage/index.vue | 8 +- .../ChartDataMatchingAndShow/index.vue | 7 +- .../ContentHeader/headerRightBtn/index.vue | 14 +-- 10 files changed, 261 insertions(+), 48 deletions(-) create mode 100644 src/api/refresh.js diff --git a/.env b/.env index ada25fe..de01cb3 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ VITE_DEV_PORT = '8080' # development path -VITE_DEV_PATH = 'https://demo.mtruning.club' +VITE_DEV_PATH = 'http://192.168.0.128' # production path -VITE_PRO_PATH = 'https://demo.mtruning.club' \ No newline at end of file +VITE_PRO_PATH = 'http://192.168.0.128:8083' \ No newline at end of file diff --git a/src/api/axios.ts b/src/api/axios.ts index f799f28..5146007 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -7,6 +7,7 @@ import { SystemStoreEnum, SystemStoreUserInfoEnum } from '@/store/modules/system import { redirectErrorPage, getLocalStorage, routerTurnByName, isPreview } from '@/utils' import { fetchAllowList } from './axios.config' import includes from 'lodash/includes' +import { refreshToken, isRefreshRequest } from '@/api/refresh.js' export interface MyResponseType { code: ResultEnum @@ -19,10 +20,12 @@ export interface MyRequestInstance extends Axios { } const axiosInstance = axios.create({ - baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}${axiosPre}`, + // baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}${axiosPre}`, + baseURL:`${import.meta.env.VITE_PRO_PATH}${axiosPre}`, timeout: ResultEnum.TIMEOUT }) as unknown as MyRequestInstance +console.log(`${import.meta.env.PROD }`,'sssss'), axiosInstance.interceptors.request.use( (config: InternalAxiosRequestConfig) => { // 白名单校验 @@ -35,7 +38,8 @@ axiosInstance.interceptors.request.use( return config } const userInfo = info[SystemStoreEnum.USER_INFO] - config.headers[userInfo[SystemStoreUserInfoEnum.TOKEN_NAME] || 'token'] = userInfo[SystemStoreUserInfoEnum.USER_TOKEN] || '' + config.headers[userInfo[SystemStoreUserInfoEnum.TOKEN_NAME] || 'token'] = + userInfo[SystemStoreUserInfoEnum.USER_TOKEN] || '' return config }, (err: AxiosError) => { @@ -45,7 +49,7 @@ axiosInstance.interceptors.request.use( // 响应拦截器 axiosInstance.interceptors.response.use( - (res: AxiosResponse) => { + async (res: AxiosResponse) => { // 预览页面错误不进行处理 if (isPreview()) { return Promise.resolve(res.data) @@ -60,21 +64,37 @@ axiosInstance.interceptors.response.use( } // 登录过期 - if (code === ResultEnum.TOKEN_OVERDUE) { - window['$message'].error(window['$t']('http.token_overdue_message')) - routerTurnByName(PageEnum.BASE_LOGIN_NAME) - return Promise.resolve(res.data) - } + // if (code === ResultEnum.TOKEN_OVERDUE ) { + // console.log('token过期') + // window['$message'].error(window['$t']('http.token_overdue_message')) + // routerTurnByName(PageEnum.BASE_LOGIN_NAME) + // return Promise.resolve(res.data) + // } - // 固定错误码重定向 - if (ErrorPageNameMap.get(code)) { - redirectErrorPage(code) - return Promise.resolve(res.data) + + + //重新获取token + if (code === ResultEnum.TOKEN_OVERDUE && !isRefreshRequest(res.config)) { + const isSucceed = await refreshToken() + if (isSucceed) { + const info = getLocalStorage(StorageEnum.GO_SYSTEM_STORE) + const userInfo = info[SystemStoreEnum.USER_INFO] + res.config.headers[userInfo[SystemStoreUserInfoEnum.TOKEN_NAME] || 'token'] = + userInfo[SystemStoreUserInfoEnum.USER_TOKEN] || '' + let result = await axiosInstance.request(res.config) //重新请求 + return result + } } - // 提示错误 - window['$message'].error(window['$t']((res.data as any).msg)) - return Promise.resolve(res.data) + // 固定错误码重定向 + // if (ErrorPageNameMap.get(code)) { + // // redirectErrorPage(code) + // return Promise.resolve(res.data) + // } + + // // 提示错误 + // window['$message'].error(window['$t']((res.data as any).msg)) + // return Promise.resolve(res.data) }, (err: AxiosError) => { const status = err.response?.status diff --git a/src/api/path/project.api.ts b/src/api/path/project.api.ts index ee0001b..6d9029d 100644 --- a/src/api/path/project.api.ts +++ b/src/api/path/project.api.ts @@ -4,7 +4,7 @@ import { ContentTypeEnum, RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEn import { ProjectItem, ProjectDetail } from './project' // * 项目列表 -export const projectListApi = async (data: object) => { +export const projectListApi = async (data?: object) => { try { const res = await http(RequestHttpEnum.GET)(`${ModuleTypeEnum.PROJECT}/list`, data) return res diff --git a/src/api/refresh.js b/src/api/refresh.js new file mode 100644 index 0000000..4b3b4bb --- /dev/null +++ b/src/api/refresh.js @@ -0,0 +1,37 @@ +import { loginApi } from '@/api/path' +import { useSystemStore } from '@/store/modules/systemStore/systemStore' +import { SystemStoreUserInfoEnum, SystemStoreEnum } from '@/store/modules/systemStore/systemStore.d' + +let promise; + +export async function refreshToken() { + if (promise) { + return promise; + } + const systemStore = useSystemStore() + promise = new Promise(async (resolve) => { + const res = await loginApi({username:'admin',password:'123456',__isRefreshToken: true}) + if(res && res.data) { + const { tokenValue, tokenName } = res.data.token + const { nickname, username, id } = res.data.userinfo + // 存储到 pinia + systemStore.setItem(SystemStoreEnum.USER_INFO, { + [SystemStoreUserInfoEnum.USER_TOKEN]: tokenValue, + [SystemStoreUserInfoEnum.TOKEN_NAME]: tokenName, + [SystemStoreUserInfoEnum.USER_ID]: id, + [SystemStoreUserInfoEnum.USER_NAME]: username, + [SystemStoreUserInfoEnum.NICK_NAME]: nickname, + }) + resolve(res.code == 200); + } + + }); + promise.finally(() => { + promise = null; + }); + return promise; +} + +export function isRefreshRequest(config) { + return !!config.__isRefreshToken; //两个取反,变成boolean +} diff --git a/src/views/AI/chat/index.vue b/src/views/AI/chat/index.vue index 1dfbf7c..87a3fed 100644 --- a/src/views/AI/chat/index.vue +++ b/src/views/AI/chat/index.vue @@ -81,7 +81,9 @@ import { ref, reactive, onMounted, onUnmounted, watch, nextTick } from 'vue' import userIcon from '@/assets/images/ai/user-icon.png' import aiIcon from '@/assets/images/ai/ai-icon.png' import { useMessage } from 'naive-ui' +import { useRoute } from 'vue-router' +const route = useRoute() const messageDialog = useMessage() const scrollContainer = ref(null) // const chartContainer = ref(null) @@ -172,9 +174,35 @@ const hanlderStyleColor = (type: string, fatherIndex: number, childIndex: number messagesItem.chartInstanceItem?.changeColorStyle(childIndex) } onMounted(() => { - // chartInstance = new LineChart('test', chartData) + // route.path + // const result = checkLastPartIsTimestamp(route.path); + // if(result){ + // //时间戳 + // }else{ + + // } + // console.log(result ) }) +const checkLastPartIsTimestamp = (str:string)=> { + // 找到最后一个 / 的位置 + const lastSlashIndex = str.lastIndexOf('/'); + if (lastSlashIndex === -1) { + return false; + } + // 截取最后一个 / 后面的值 + const lastPart = str.slice(lastSlashIndex + 1); + // 尝试将其转换为数字 + const num = Number(lastPart); + // 检查是否为有效数字 + if (isNaN(num)) { + return false; + } + // 检查是否在合理的时间戳范围内(这里简单假设从 2000 年到 2100 年) + const minTimestamp = new Date('2024-01-01').getTime(); + const maxTimestamp = new Date('2124-01-01').getTime(); + return num >= minTimestamp && num <= maxTimestamp; +} // 监听messages变化,自动滚动到底部 watch( messages, diff --git a/src/views/AI/components/history/index.vue b/src/views/AI/components/history/index.vue index a02436a..5dce0ac 100644 --- a/src/views/AI/components/history/index.vue +++ b/src/views/AI/components/history/index.vue @@ -1,12 +1,115 @@ - - \ No newline at end of file + border-radius: 4px; + display: flex; + align-items: center; + gap: 3px; + .history-row-title { + flex: 1; + font-size: 14px; + color: #cfd5e5; + font-weight: 400; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + .del-icon { + display: none; + } + } + .history-item:hover { + background-color: #3d424d; + .del-icon { + display: block; + } + } +} + diff --git a/src/views/AI/index.vue b/src/views/AI/index.vue index 0cc72bd..d787f08 100644 --- a/src/views/AI/index.vue +++ b/src/views/AI/index.vue @@ -9,7 +9,7 @@ :to="item.path" v-for="(item, index) in menuList" :key="index" - @click="handlerPath(item.path)" + @click="handlerPath(item.path, index)" > @@ -20,7 +20,7 @@ >新建{{ item.name }} - +
@@ -29,14 +29,17 @@ diff --git a/src/views/chart/ContentConfigurations/components/CanvasPage/index.vue b/src/views/chart/ContentConfigurations/components/CanvasPage/index.vue index 3f8d94f..9cf7050 100644 --- a/src/views/chart/ContentConfigurations/components/CanvasPage/index.vue +++ b/src/views/chart/ContentConfigurations/components/CanvasPage/index.vue @@ -22,7 +22,7 @@ -
+ 背景颜色 @@ -54,7 +54,7 @@ >
- + 背景控制 diff --git a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMatchingAndShow/index.vue b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMatchingAndShow/index.vue index c8635d0..69138a8 100644 --- a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMatchingAndShow/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataMatchingAndShow/index.vue @@ -241,9 +241,8 @@ watch( ) => { if(newData){ messagesList = [] - if(targetData.value.lastMessagesItem) messagesList.push(targetData.value.lastMessagesItem) } - // console.log(newData,'图表变化',targetData.value.lastMessagesItem) + }, ) @@ -257,7 +256,9 @@ watch( dimensions: any } | null ) => { - // console.log(targetData.value.option.messages,'sss') + if(targetData.value.lastMessagesItem && messagesList.length === 0){ + messagesList.push(targetData.value.lastMessagesItem) + } noData.value = false if (newData && targetData?.value?.chartConfig?.chartFrame === ChartFrameEnum.ECHARTS) { // 只有 DataSet 数据才有对应的格式 diff --git a/src/views/chart/ContentHeader/headerRightBtn/index.vue b/src/views/chart/ContentHeader/headerRightBtn/index.vue index ad4ed96..367733d 100644 --- a/src/views/chart/ContentHeader/headerRightBtn/index.vue +++ b/src/views/chart/ContentHeader/headerRightBtn/index.vue @@ -171,13 +171,13 @@ const btnList = [ icon: renderIcon(BrowsersOutlineIcon), event: previewHandle }, - { - key: 'release', - title: () => (release.value ? '已发布' : '发布'), - icon: renderIcon(SendIcon), - type: () => (release.value ? 'primary' : 'default'), - event: modelShowHandle - } + // { + // key: 'release', + // title: () => (release.value ? '已发布' : '发布'), + // icon: renderIcon(SendIcon), + // type: () => (release.value ? 'primary' : 'default'), + // event: modelShowHandle + // } ] const comBtnList = computed(() => {