From a7d8d8560c9e9b880e52b54fd3479759296d31f1 Mon Sep 17 00:00:00 2001 From: liyanshuang <123.com> Date: Mon, 16 Mar 2026 10:35:54 +0800 Subject: [PATCH] =?UTF-8?q?Token=E6=89=93=E9=80=9A=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/AIxiaocaishen.js | 2 +- src/store/chat.js | 4 +- src/views/homePage.vue | 457 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 452 insertions(+), 11 deletions(-) diff --git a/src/api/AIxiaocaishen.js b/src/api/AIxiaocaishen.js index 36d701f..2d670a9 100644 --- a/src/api/AIxiaocaishen.js +++ b/src/api/AIxiaocaishen.js @@ -102,7 +102,7 @@ export const getAnnouncementAPI = function () { export const getUserCountAPI = function (params) { return request({ // 'http://39.101.133.168:8828/link/api/aiEmotion/client/getRemainNum', - url: `${APIurl}/api/aiEmotion/client/getRemainNum`, + url: `${APIurl}/api/aiEmotion/client/getRemainTokenNum`, method: "POST", data: params, // headers: { diff --git a/src/store/chat.js b/src/store/chat.js index 376129c..9d0e336 100644 --- a/src/store/chat.js +++ b/src/store/chat.js @@ -32,7 +32,9 @@ export const useChatStore = defineStore("chat", { token: localStorage.getItem("localToken"), source: activeTab == 'deepNine' ? '2' : '1', }); - this.UserCount = result.data; + this.UserCount = result.data.remain_num; + this.FreeCount = result.data.remain_free_num; + this.PaidCount = result.data.remain_pay_num; }, setLoading(status) { this.isLoading = status; diff --git a/src/views/homePage.vue b/src/views/homePage.vue index 32d2715..e1b03a9 100644 --- a/src/views/homePage.vue +++ b/src/views/homePage.vue @@ -50,6 +50,13 @@ import VConsole from "vconsole"; const vConsole = new VConsole(); const isMobile = ref(null); +//免费的Token的到期时间 +const freeTokenExpireTime = ref("2026-06-30"); +// Token清除时间范围 +const tokenClearTimeRange = ref({ + startTime: '2025-07-01', + endTime: '2025-12-31' +}); // 获取 AiEmotion 组件的 ref const aiEmotionRef = ref(null); @@ -66,6 +73,125 @@ const deepNineStore = useDeepNineStore(); // 音频管理 const emotionAudioStore = useEmotionAudioStore(); const audioStore = useAudioStore(); +// 控制Token变动记录弹窗显示 +const tokenRecordVisible = ref(false); + +const tokenRecordList = ref([ +]); +import axios from 'axios' + +// 获取Token变动记录接口 +const getTokenChangeLogs = async () => { + try { + const APIurl = import.meta.env.VITE_APP_API_BASE_URL + const res = await axios.post( + `${APIurl}/api/aiEmotion/client/viewTokenChangeLogs`, + { + token: localStorage.getItem('localToken') + } + ) + if (res.data.code === 200) { + // 接口字段映射到前端表格格式 + const records = res.data.data.map((item, index) => ({ + id: index + 1, + change: item.count, + type: item.token_type === 1 ? '付费' : '免费', + time: item.created_at, + remark: item.reason + })) + tokenRecordList.value = records + } else { + ElMessage.error(res.data.msg || '获取Token流水失败') + } + } catch (error) { + ElMessage.error(error.message || '网络异常') + } +} + +// 获取免费Token过期时间和清除时间范围接口 +const getTokenExpireInfo = async () => { + try { + const APIurl = import.meta.env.VITE_APP_API_BASE_URL + const res = await axios.post( + `${APIurl}/api/aiEmotion/client/getCleanUpFreeTokenTime`, + { + token: localStorage.getItem('localToken') + } + ) + if (res.data.code === 200) { + // 更新过期时间(只取年月日) + if (res.data.data.expiredTime) { + freeTokenExpireTime.value = res.data.data.expiredTime.split(' ')[0] + } + // 更新清除时间范围 + if (res.data.data.startTime && res.data.data.endTime) { + tokenClearTimeRange.value = { + startTime: res.data.data.startTime, + endTime: res.data.data.endTime + } + } + } + } catch (error) { + console.error('获取Token过期信息失败', error) + } +} +// Token清除提示 +const showTokenClearDialog = ref(false) +// 当前要显示的清除文案 +const currentClearText = ref('') +// 点击查看Token变动记录 +const showTokenRecord = async () => { + await getTokenChangeLogs() + tokenRecordVisible.value = true +}; +const APIurl = import.meta.env.VITE_APP_API_BASE_URL +// 清除弹窗提醒接口 +const clearPopupReminder = async () => { + try { + const res = await axios.post( + `${APIurl}/api/aiEmotion/client/clearPopupReminder`, + { + token: localStorage.getItem('localToken') + } + ) + console.log('clearPopupReminder 接口返回:', res.data) + if (res.data.code === 200) { + // 接口返回 data 为 true 时,显示清除提示弹窗 + if (res.data.data === true) { + console.log('设置 showTokenClearDialog = true') + showTokenClearDialog.value = true + } + } else { + ElMessage.error(res.data.msg || '获取清除提醒状态失败') + } + } catch (error) { + ElMessage.error(error.message || '网络异常') + } +} +//判断是否需要显示Token清除提示 +const checkTokenClearTip = () => { + // 1. 先判断是否已经提示过(本地缓存标记) + const hasShowClearTip = localStorage.getItem('hasShowTokenClearTip') + if (hasShowClearTip === '1') return + + // 格式化时间显示 + const formatDate = (dateStr) => { + const date = new Date(dateStr) + return `${date.getFullYear()} 年 ${String(date.getMonth() + 1).padStart(2, '0')} 月 ${String(date.getDate()).padStart(2, '0')} 日` + } + + const startTime = formatDate(tokenClearTimeRange.value.startTime) + const endTime = formatDate(tokenClearTimeRange.value.endTime) + + currentClearText.value = `【通知】${startTime} - ${endTime} 期间获得的免费 Token 已统一清除,过期未使用额度不予保留、不累计、不顺延。` + showTokenClearDialog.value = true +} + +// 关闭Token清除弹窗,并标记已提示 +const closeTokenClearDialog = () => { + showTokenClearDialog.value = false + localStorage.setItem('hasShowTokenClearTip', '1') +} // 根据当前页面类型获取对应的音频store const getCurrentAudioStore = () => { return activeTab.value === "AiEmotion" ? emotionAudioStore : audioStore; @@ -166,13 +292,19 @@ const getSelectedOptionImage = () => { }; // 点击外部关闭下拉菜单 -onMounted(() => { +onMounted(async () => { document.addEventListener("click", (e) => { const container = document.querySelector(".custom-select-container"); if (container && !container.contains(e.target) && isDropdownOpen.value) { isDropdownOpen.value = false; } }); + // 获取Token过期信息 + getTokenExpireInfo() + // 调用清除弹窗提醒接口 + await clearPopupReminder() + // 检查是否需要显示Token清除提示 + checkTokenClearTip() }); // 手机端选择器变化处理(保留原函数以兼容其他地方可能的调用) @@ -271,6 +403,12 @@ const ensureAIchat = () => { // 获取次数 const UserCount = computed(() => chatStore.UserCount); +//总的Token +const totalToken = computed(() => chatStore.UserCount); +//付费的Token +const paidToken = computed(() => chatStore.PaidCount); +//免费的Token +const freeToken = computed(() => chatStore.FreeCount); const getCount = () => { console.log("点击了获取次数的按钮"); @@ -868,8 +1006,8 @@ watch( activeTab.value == "AIchat" ? 1 : activeTab.value == "AiEmotion" - ? 2 - : 3; + ? 2 + : 3; const result = historyRecordRef.value.getHistoryList({ model: model, token: localStorage.getItem("localToken"), @@ -1838,6 +1976,20 @@ onUnmounted(() => {
| 序号 | +数量变化 | +Token类型 | +操作时间 | +备注 | +
|---|---|---|---|---|
| {{ index + 1 }} | ++ {{ item.change > 0 ? '+' : '' }}{{ item.change }} + | +{{ item.type }} | +{{ item.time }} | +{{ item.remark }} | +