From c333b907e682a3935fc87754eff246b43f4a3518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Wed, 23 Jul 2025 18:22:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E8=AF=A2=E5=8D=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/adminApi.ts | 63 +++++ src/store/modules/user.ts | 51 ++-- src/typings/api.d.ts | 21 +- src/views/admin/inquiry_system/index.vue | 306 ++++++++++++++++------- src/views/crmpc/highseas/index.vue | 4 +- 5 files changed, 332 insertions(+), 113 deletions(-) create mode 100644 src/api/adminApi.ts diff --git a/src/api/adminApi.ts b/src/api/adminApi.ts new file mode 100644 index 0000000..12c338b --- /dev/null +++ b/src/api/adminApi.ts @@ -0,0 +1,63 @@ +import request from '@/utils/http' + +export class manageService { + //询单列表 + static getinquiryList(params: Api.Common.PaginatingParams) { + return request.get({ + url: '/admin/inquiry/list', + params + }) + } + // 获取详情 + static inquirydetail(params: any) { + return request.get({ + url: '/admin/inquiry/show', + params + }) + } + //添加询单 + static inquiryAdd(params: any) { + return request.post({ + url: '/admin/inquiry/store', + params + // showErrorMessage: false // 不显示错误消息 + }) + } + //修改询单 + static inquiryedit(params: any) { + return request.post({ + url: '/admin/inquiry/update', + params + // showErrorMessage: false // 不显示错误消息 + }) + } + //删除询单 + static inquirydelete(params: any) { + return request.get({ + url: '/admin/inquiry/destroy', + params + }) + } + //分配询单 + static inquiryallocation(params: any) { + return request.post({ + url: '/admin/inquiry/allocation', + params + // showErrorMessage: false // 不显示错误消息 + }) + } + //发布询单 + static inquiryrelease(params: any) { + return request.post({ + url: '/admin/inquiry/release', + params + // showErrorMessage: false // 不显示错误消息 + }) + } + //获取用户下拉框 + static presetusers() { + return request.get({ + url: '/common/preset/users' + }) + } +} diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index e33247f..0ee0289 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -67,52 +67,77 @@ export const useUserStore = defineStore( refreshToken.value = newRefreshToken } if (expiresIn) { - // 记录绝对过期时间 const expireAt = Date.now() + expiresIn * 1000 tokenExpireAt.value = expireAt localStorage.setItem('token_expire_at', String(expireAt)) - scheduleTokenRefresh(expiresIn) + // 检查是否需要重新设置定时器 + const currentLeftSeconds = Math.floor((expireAt - Date.now()) / 1000) + if (currentLeftSeconds > 0) { + scheduleTokenRefresh(currentLeftSeconds) + } } } - const setCompany= (id: string, abbr: string) => { + const setCompany = (id: string, abbr: string) => { companyid.value = id companyabbr.value = abbr } - const setSystems= (id: string, abbr: string) => { + const setSystems = (id: string, abbr: string) => { systemsid.value = id systemsabbr.value = abbr } - function restoreTokenTimer() { const expireAt = Number(localStorage.getItem('token_expire_at') || '0') if (accessToken.value && expireAt > Date.now()) { const leftSeconds = Math.floor((expireAt - Date.now()) / 1000) - scheduleTokenRefresh(leftSeconds) + scheduleTokenRefresh(leftSeconds); } } + let isScheduled = false + function scheduleTokenRefresh(expiresIn: number) { - if (refreshTimeout) clearTimeout(refreshTimeout) + if (refreshTimeout) { + clearTimeout(refreshTimeout) + refreshTimeout = null + } + // 提前1分钟刷新 const refreshTime = (expiresIn - 100) * 1000 + if (refreshTime > 0) { - refreshTimeout = setTimeout(refreshTokenAction, refreshTime) + if (!isScheduled) { + isScheduled = true + refreshTimeout = setTimeout(() => { + refreshTokenAction().finally(() => { + isScheduled = false // 重置标志位 + }) + }, refreshTime) + } else { + console.log('scheduleTokenRefresh is already scheduled, skipping...') + } + } else { + console.error('Invalid refreshTime:', refreshTime) } } async function refreshTokenAction() { try { const { data } = await UserService.refreshToken({ refresh_token: refreshToken.value }) - setToken(data.access_token, data.refresh_token, data.expires_in) + // 动态计算剩余时间 + const currentTime = Date.now() + const expireAt = currentTime + data.expires_in * 1000 + const leftSeconds = Math.floor((expireAt - currentTime) / 1000) + setToken(data.access_token, data.refresh_token, leftSeconds) } catch (e) { + console.error('Token refresh failed:', e) logOut() } } const logOut = () => { // 清空所有本地缓存 - localStorage.clear(); - sessionStorage.clear(); + localStorage.clear() + sessionStorage.clear() companyabbr.value = '' companyid.value = '' @@ -123,17 +148,13 @@ export const useUserStore = defineStore( accessToken.value = '' refreshToken.value = '' if (refreshTimeout) clearTimeout(refreshTimeout) // 清理定时器 - // 清理工作台标签页 useWorktabStore().clearAll() - // 清理sessionStorage中的用户信息缓存 sessionStorage.removeItem('lastUserInfo') sessionStorage.removeItem('iframeRoutes') - // 重置路由状态 resetRouterState(router) - // 跳转到登录页 router.push(RoutesAlias.Login) } diff --git a/src/typings/api.d.ts b/src/typings/api.d.ts index ca12d49..25d1677 100644 --- a/src/typings/api.d.ts +++ b/src/typings/api.d.ts @@ -29,6 +29,23 @@ declare namespace Api { /** 启用状态 */ type EnableStatus = '1' | '2' + + interface CommonInfo { + data: never[] + } + + /** 列表数据 */ + interface CommonListData { + records: CommonInfo[] + current: number + size: number + total: number + } + + interface AddResponse { + code: string + message: string + } } /** 认证类型 */ @@ -116,7 +133,7 @@ declare namespace Api { interface AddParams { categorie_id: any content: any - attachment:any + attachment: any } interface AddResponse { code: string @@ -126,7 +143,7 @@ declare namespace Api { interface StatusParams { id: any msg: any - status:any + status: any } //分类 interface CategorieInfo { diff --git a/src/views/admin/inquiry_system/index.vue b/src/views/admin/inquiry_system/index.vue index 54b6900..9174f98 100644 --- a/src/views/admin/inquiry_system/index.vue +++ b/src/views/admin/inquiry_system/index.vue @@ -10,15 +10,15 @@ - - - + + + - + @@ -80,23 +80,61 @@ >