11<script setup lang="ts">
2- import { NCard , NSpace , NButton , NProgress , NNumberAnimation , NGrid , NGridItem , NTag , NDivider , NModal , NIcon , NForm , NFormItem , NInput , NScrollbar } from ' naive-ui'
2+ import { NCard , NSpace , NButton , NProgress , NNumberAnimation , NGrid , NGridItem , NTag , NDivider , NModal , NIcon , NScrollbar } from ' naive-ui'
33import { ref , onMounted , computed , watch } from ' vue'
44import { useI18n } from ' ../locales'
55import { useMessage } from ' naive-ui'
@@ -202,11 +202,6 @@ const handleMachineCodeChange = async (force_kill: boolean = false) => {
202202 }
203203}
204204
205- // 添加新的 ref
206- const showUnusedCreditsModal = ref (false )
207- const unusedCredits = ref (0 )
208- const pendingAction = ref <' account' | ' quick' | null >(null )
209-
210205// 添加统一的自动注入函数,并增加日志
211206const autoApplyHook = async (): Promise <boolean > => {
212207 try {
@@ -251,7 +246,8 @@ const handleAccountSwitch = async () => {
251246
252247 // 检查积分是否足够
253248 if (! userStore .checkCredits (50 )) {
254- userStore .showInsufficientCredits (' account' )
249+ message .error (i18n .value .dashboard .insufficientCredits )
250+ router .push (' /settings' )
255251 return
256252 }
257253
@@ -303,7 +299,8 @@ const handleQuickChange = async () => {
303299
304300 // 检查积分是否足够
305301 if (! userStore .checkCredits (50 )) {
306- userStore .showInsufficientCredits (' quick' )
302+ message .error (i18n .value .dashboard .insufficientCredits )
303+ router .push (' /settings' )
307304 return
308305 }
309306
@@ -335,36 +332,6 @@ const handleQuickChange = async () => {
335332 }
336333}
337334
338- // 修改确认切换函数
339- const handleConfirmSwitch = async () => {
340- showUnusedCreditsModal .value = false
341- if (pendingAction .value === ' account' ) {
342- // 检查 Cursor 是否在运行
343- const isRunning = await checkCursorRunning ()
344- if (isRunning ) {
345- showCursorRunningModal .value = true
346- pendingForceKillAction .value = { type: ' account' }
347- return
348- }
349- await executeAccountSwitch ()
350- } else if (pendingAction .value === ' quick' ) {
351- // 检查 Cursor 是否在运行
352- const isRunning = await checkCursorRunning ()
353- if (isRunning ) {
354- showCursorRunningModal .value = true
355- pendingForceKillAction .value = { type: ' quick' }
356- return
357- }
358- await executeQuickChange ()
359- }
360- pendingAction .value = null
361- }
362-
363- const handleCancelSwitch = () => {
364- showUnusedCreditsModal .value = false
365- pendingAction .value = null
366- }
367-
368335// 修改账户切换执行函数
369336const executeAccountSwitch = async (force_kill : boolean = false ) => {
370337 try {
@@ -607,10 +574,6 @@ onMounted(async () => {
607574// 添加引导相关状态
608575const shouldShowTour = ref (false )
609576
610- // 添加积分不足模态框状态
611- const activationCode = ref (' ' )
612- const activationError = ref (' ' )
613-
614577// 添加加载状态
615578const machineCodeLoading = ref (false )
616579const accountSwitchLoading = ref (false )
@@ -644,22 +607,6 @@ const handleTourComplete = () => {
644607 shouldShowTour .value = false
645608}
646609
647- // 激活码处理
648- const handleActivate = async () => {
649- if (! activationCode .value ) {
650- activationError .value = ' 请输入激活码'
651- return
652- }
653-
654- try {
655- await userStore .activateCode (activationCode .value )
656- message .success (' 激活成功' )
657- updateLocalViewState ()
658- } catch (error ) {
659- // 错误处理在 store 中已完成
660- }
661- }
662-
663610// 同步 store 的状态到本地视图状态
664611watch (
665612 [() => cursorStore .machineCode , () => cursorStore .currentAccount , () => cursorStore .hookStatus ,
@@ -673,11 +620,10 @@ watch(
673620watch ([
674621 () => showAdminPrivilegeModal ,
675622 () => showCursorRunningModal ,
676- () => appStore .showDisclaimerModal ,
677- () => userStore .showInsufficientCreditsModal
623+ () => appStore .showDisclaimerModal
678624],
679- ([adminModal , cursorModal , disclaimerModal , creditsModal ]) => {
680- if (adminModal || cursorModal || disclaimerModal || creditsModal ) {
625+ ([adminModal , cursorModal , disclaimerModal ]) => {
626+ if (adminModal || cursorModal || disclaimerModal ) {
681627 shouldShowTour .value = false
682628 }
683629 }
@@ -715,15 +661,11 @@ const handleMachineCodeClick = async () => {
715661 }
716662}
717663
718- // 添加表单数据
719- const formValue = ref ({
720- activationCode: ' '
721- })
722664 </script >
723665
724666<template >
725667 <n-space vertical size =" large" >
726- <article-list v-if =" userStore.userInfo && !appStore.showDisclaimerModal && !userStore.showInsufficientCreditsModal " />
668+ <article-list v-if =" userStore.userInfo && !appStore.showDisclaimerModal" />
727669
728670 <n-grid :cols =" 2" :x-gap =" 24" style =" display : grid ; grid-template-columns : repeat (2 , 1fr );" >
729671 <!-- 用户信息卡片 -->
@@ -891,31 +833,6 @@ const formValue = ref({
891833 </n-space >
892834 </n-card >
893835
894- <n-modal
895- v-model:show =" showUnusedCreditsModal"
896- preset =" dialog"
897- title =" 使用提醒"
898- :closable =" true"
899- :mask-closable =" false"
900- >
901- <template #default >
902- <p >您还有 {{ unusedCredits }} 次高级模型使用次数未使用</p >
903- <p style =" margin-top : 12px ; color : #666 ;" >
904- {{ pendingAction === 'quick' ? '一键切换将扣除50积分' : '切换账号将扣除50积分' }},确定要继续吗?
905- </p >
906- </template >
907- <template #action >
908- <n-space justify =" end" >
909- <n-button @click =" handleCancelSwitch" >
910- 取消
911- </n-button >
912- <n-button type =" primary" @click =" handleConfirmSwitch" >
913- 确认切换
914- </n-button >
915- </n-space >
916- </template >
917- </n-modal >
918-
919836 <!-- 添加 Cursor 运行提醒模态框 -->
920837 <cursor-running-modal
921838 v-model:show =" showCursorRunningModal"
@@ -976,54 +893,6 @@ const formValue = ref({
976893 </template >
977894 </n-modal >
978895
979- <!-- 修改积分不足模态框 -->
980- <n-modal
981- v-model:show =" userStore.showInsufficientCreditsModal"
982- preset =" dialog"
983- title =" 额度不足"
984- :closable =" true"
985- :mask-closable =" false"
986- style =" width : 500px "
987- >
988- <n-form
989- :model =" formValue"
990- label-placement =" left"
991- label-width =" auto"
992- require-mark-placement =" right-hanging"
993- >
994- <div style =" margin-bottom : 16px " >
995- <p >您当前对话额度不足,账户切换需要消耗50额度。</p >
996- <p style =" margin-top : 12px ; color : #ff4d4f ;" >
997- 当前额度: {{ userStore.userCredits }},还需要: {{ Math.max(0, 50 - userStore.userCredits) }} 额度
998- </p >
999- </div >
1000-
1001- <n-form-item label =" 激活码" >
1002- <n-input
1003- v-model:value =" userStore.activationCode"
1004- type =" text"
1005- placeholder =" 请输入卡密"
1006- :disabled =" userStore.activationLoading"
1007- />
1008- </n-form-item >
1009-
1010- <p v-if =" userStore.activationError" style =" color : #ff4d4f ; margin-top : 8px ;" >
1011- {{ userStore.activationError }}
1012- </p >
1013- </n-form >
1014-
1015- <template #action >
1016- <n-space justify =" end" >
1017- <n-button @click =" userStore.closeInsufficientCredits()" :disabled =" userStore.activationLoading" >
1018- 取消
1019- </n-button >
1020- <n-button type =" primary" @click =" handleActivate" :loading =" userStore.activationLoading" >
1021- 激活卡密
1022- </n-button >
1023- </n-space >
1024- </template >
1025- </n-modal >
1026-
1027896 <!-- 添加引导组件 -->
1028897 <DashboardTour :show =" shouldShowTour" :onComplete =" handleTourComplete" />
1029898 </n-space >
0 commit comments