Skip to content

Commit 83edce4

Browse files
committed
feat(localization): add 'insufficientCredits' message in multiple languages; remove unused credit modal logic from user store and dashboard view for cleaner code
1 parent 68cfa14 commit 83edce4

3 files changed

Lines changed: 18 additions & 174 deletions

File tree

src/locales/messages.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const messages = {
5353
cancelSwitch: '取消',
5454
ccStatus: '本地Curso状态',
5555
registerTime: '本地Cursor账户注册时间',
56+
insufficientCredits: '剩余额度不足, 请先充值',
5657
email: '本地Cursor邮箱',
5758
cpUsage: 'Cursor Pool额度使用量',
5859
advancedModelUsage: '高级模型使用量',
@@ -234,6 +235,7 @@ export const messages = {
234235
cancelSwitch: 'Cancel',
235236
ccStatus: 'CC Status',
236237
registerTime: 'Register Time',
238+
insufficientCredits: 'Insufficient credits, please recharge first',
237239
email: 'Email',
238240
cpUsage: 'CP Credits Usage',
239241
advancedModelUsage: 'Advanced Model Usage',
@@ -424,6 +426,7 @@ export const messages = {
424426
cancelSwitch: 'キャンセル',
425427
ccStatus: 'CC状態',
426428
registerTime: '登録時間',
429+
insufficientCredits: 'クレジット不足、最初に再チャージする必要があります',
427430
email: 'メールアドレス',
428431
cpUsage: 'CP积分使用量',
429432
advancedModelUsage: '高级模型使用量',
@@ -541,14 +544,7 @@ export const messages = {
541544
cursorRunningMessage: 'Detected Cursor is running, please save the project that has not been changed before continuing!',
542545
closingCursor: 'Cursor を閉じています...',
543546
forgotPassword: 'パスワードを忘れた場合',
544-
unknown: '不明',
545-
notBound: '未绑定',
546-
verified: '検証済み',
547-
unverified: '未検証',
548-
success: '成功',
549-
failed: '失敗',
550-
loading: '読み込み中...',
551-
confirmRestart: '今すぐ再起動'
547+
confirmRestart: 'Redémarrer maintenant'
552548
},
553549
inbound: {
554550
title: '线路',
@@ -613,6 +609,7 @@ export const messages = {
613609
cancelSwitch: 'Annuler',
614610
ccStatus: 'État CC',
615611
registerTime: 'Heure d\'inscription',
612+
insufficientCredits: 'Crédits insuffisants, veuillez recharger d\'abord',
616613
email: 'Email',
617614
cpUsage: 'CP积分使用量',
618615
advancedModelUsage: '高级模型使用量',
@@ -791,6 +788,7 @@ export const messages = {
791788
downloadNow: 'Jetzt herunterladen',
792789
ccStatus: 'CC Status',
793790
registerTime: 'Registrierungszeit',
791+
insufficientCredits: 'Unzureichende Guthaben, bitte zuerst aufladen',
794792
email: 'Email',
795793
cpUsage: 'CP积分使用量',
796794
advancedModelUsage: '高级模型使用量',
@@ -969,6 +967,7 @@ export const messages = {
969967
downloadNow: '지금 다운로드',
970968
ccStatus: 'CC 상태',
971969
registerTime: '등록 시간',
970+
insufficientCredits: '크레딧 부족, 먼저 재충전하세요',
972971
email: '이메일',
973972
cpUsage: 'CP积分使用量',
974973
advancedModelUsage: '高级模型使用量',
@@ -1147,6 +1146,7 @@ export const messages = {
11471146
downloadNow: 'Скачать сейчас',
11481147
ccStatus: 'Статус CC',
11491148
registerTime: 'Время регистрации',
1149+
insufficientCredits: 'Недостаточно кредитов, пожалуйста, пополните сначала',
11501150
email: 'Email',
11511151
cpUsage: 'CP积分使用量',
11521152
advancedModelUsage: '高级模型使用量',
@@ -1325,6 +1325,7 @@ export const messages = {
13251325
downloadNow: 'Descargar ahora',
13261326
ccStatus: 'Estado CC',
13271327
registerTime: 'Hora de registro',
1328+
insufficientCredits: 'Créditos insuficientes, por favor recargue primero',
13281329
email: 'Email',
13291330
cpUsage: 'CP积分使用量',
13301331
advancedModelUsage: '高级模型使用量',

src/stores/user.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ export const useUserStore = defineStore('user', () => {
2424
const isAdmin = ref<boolean | null>(null)
2525
const isCheckingAdmin = ref(false)
2626

27-
// 积分相关状态
28-
const showInsufficientCreditsModal = ref(false)
2927
const activationCode = ref('')
3028
const activationLoading = ref(false)
3129
const activationError = ref('')
32-
const pendingCreditAction = ref<'account' | 'quick' | null>(null)
3330

3431
// Getters
3532
const username = computed(() => userInfo.value?.username || '')
@@ -165,7 +162,6 @@ export const useUserStore = defineStore('user', () => {
165162

166163
// 重置激活码状态
167164
activationCode.value = ''
168-
showInsufficientCreditsModal.value = false
169165

170166
return true
171167
} catch (error) {
@@ -211,24 +207,6 @@ export const useUserStore = defineStore('user', () => {
211207
function checkCredits(requiredCredits: number = 50) {
212208
return userCredits.value >= requiredCredits
213209
}
214-
215-
/**
216-
* 显示积分不足模态框
217-
*/
218-
function showInsufficientCredits(action: 'account' | 'quick') {
219-
pendingCreditAction.value = action
220-
showInsufficientCreditsModal.value = true
221-
}
222-
223-
/**
224-
* 关闭积分不足模态框
225-
*/
226-
function closeInsufficientCredits() {
227-
showInsufficientCreditsModal.value = false
228-
pendingCreditAction.value = null
229-
activationCode.value = ''
230-
activationError.value = ''
231-
}
232210

233211
// 返回 store 对象
234212
return {
@@ -239,11 +217,9 @@ export const useUserStore = defineStore('user', () => {
239217
loginError,
240218
isAdmin,
241219
isCheckingAdmin,
242-
showInsufficientCreditsModal,
243220
activationCode,
244221
activationLoading,
245222
activationError,
246-
pendingCreditAction,
247223

248224
// Getters
249225
username,
@@ -260,8 +236,6 @@ export const useUserStore = defineStore('user', () => {
260236
changePassword,
261237
resetPassword,
262238
checkCredits,
263-
showInsufficientCredits,
264-
closeInsufficientCredits,
265239
checkIsAdmin,
266240
}
267241
})

src/views/DashboardView.vue

Lines changed: 9 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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'
33
import { ref, onMounted, computed, watch } from 'vue'
44
import { useI18n } from '../locales'
55
import { 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
// 添加统一的自动注入函数,并增加日志
211206
const 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
// 修改账户切换执行函数
369336
const executeAccountSwitch = async (force_kill: boolean = false) => {
370337
try {
@@ -607,10 +574,6 @@ onMounted(async () => {
607574
// 添加引导相关状态
608575
const shouldShowTour = ref(false)
609576
610-
// 添加积分不足模态框状态
611-
const activationCode = ref('')
612-
const activationError = ref('')
613-
614577
// 添加加载状态
615578
const machineCodeLoading = ref(false)
616579
const 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 的状态到本地视图状态
664611
watch(
665612
[() => cursorStore.machineCode, () => cursorStore.currentAccount, () => cursorStore.hookStatus,
@@ -673,11 +620,10 @@ watch(
673620
watch([
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

Comments
 (0)