Skip to content

Commit 35e6e20

Browse files
authored
refactor: vue-i18n use composition api (#632)
* refactor: vue-i18n use composition api Signed-off-by: Bob Du <i@bobdu.cc> * refactor: vue i18n use typescript typing Signed-off-by: Bob Du <i@bobdu.cc> * refactor: replace $t with t in vue-i18n usage Signed-off-by: Bob Du <i@bobdu.cc> --------- Signed-off-by: Bob Du <i@bobdu.cc>
1 parent 1d16e84 commit 35e6e20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1288
-1241
lines changed

auto-imports.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ declare global {
6969
const useCssModule: typeof import('vue')['useCssModule']
7070
const useCssVars: typeof import('vue')['useCssVars']
7171
const useDialog: typeof import('naive-ui')['useDialog']
72+
const useI18n: typeof import('vue-i18n')['useI18n']
7273
const useId: typeof import('vue')['useId']
7374
const useLink: typeof import('vue-router')['useLink']
7475
const useLoadingBar: typeof import('naive-ui')['useLoadingBar']

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"lint-staged": "^16.1.0",
5050
"markdown-it": "^14.1.0",
5151
"markdown-it-link-attributes": "^4.0.1",
52-
"naive-ui": "^2.41.1",
52+
"naive-ui": "^2.42.0",
5353
"pinia": "^3.0.2",
5454
"qrcode.vue": "^3.6.0",
5555
"rimraf": "^6.0.1",
@@ -60,7 +60,7 @@
6060
"vite": "6.3.4",
6161
"vue": "^3.5.16",
6262
"vue-chartjs": "^5.3.2",
63-
"vue-i18n": "11.1.2",
63+
"vue-i18n": "^11.1.6",
6464
"vue-router": "^4.5.1",
6565
"vue-tsc": "^2.2.10"
6666
},

pnpm-lock.yaml

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/common/PromptStore/index.vue

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import { NButton } from 'naive-ui'
44
import { fetchClearUserPrompt, fetchDeleteUserPrompt, fetchImportUserPrompt, fetchUpsertUserPrompt, fetchUserPromptList } from '@/api'
55
import { UserPrompt } from '@/components/common/Setting/model'
66
import { useBasicLayout } from '@/hooks/useBasicLayout'
7-
import { t } from '@/locales'
87
import { useAuthStoreWithout, usePromptStore } from '@/store'
98
import { SvgIcon } from '..'
109
import PromptRecommend from '../../../assets/recommend.json'
1110
11+
const props = defineProps<Props>()
12+
13+
const emit = defineEmits<Emit>()
14+
15+
const { t } = useI18n()
16+
1217
interface DataProps {
1318
_id?: string
1419
title: string
@@ -24,10 +29,6 @@ interface Emit {
2429
(e: 'update:visible', visible: boolean): void
2530
}
2631
27-
const props = defineProps<Props>()
28-
29-
const emit = defineEmits<Emit>()
30-
3132
const message = useMessage()
3233
3334
const show = computed({
@@ -399,7 +400,7 @@ async function handleGetUserPromptList() {
399400
<NModal v-model:show="show" style="width: 90%; max-width: 900px;" preset="card">
400401
<div class="space-y-4">
401402
<NTabs type="segment">
402-
<NTabPane name="local" :tab="$t('store.local')">
403+
<NTabPane name="local" :tab="t('store.local')">
403404
<div
404405
class="flex gap-3 mb-4"
405406
:class="[isMobile ? 'flex-col' : 'flex-row justify-between']"
@@ -410,28 +411,28 @@ async function handleGetUserPromptList() {
410411
size="small"
411412
@click="changeShowModal('add')"
412413
>
413-
{{ $t('common.add') }}
414+
{{ t('common.add') }}
414415
</NButton>
415416
<NButton
416417
size="small"
417418
@click="changeShowModal('local_import')"
418419
>
419-
{{ $t('common.import') }}
420+
{{ t('common.import') }}
420421
</NButton>
421422
<NButton
422423
size="small"
423424
:loading="exportLoading"
424425
@click="exportPromptTemplate()"
425426
>
426-
{{ $t('common.export') }}
427+
{{ t('common.export') }}
427428
</NButton>
428429
<NPopconfirm @positive-click="clearPromptTemplate">
429430
<template #trigger>
430431
<NButton size="small">
431-
{{ $t('common.clear') }}
432+
{{ t('common.clear') }}
432433
</NButton>
433434
</template>
434-
{{ $t('store.clearStoreConfirm') }}
435+
{{ t('store.clearStoreConfirm') }}
435436
</NPopconfirm>
436437
</div>
437438
<div class="flex items-center">
@@ -474,9 +475,9 @@ async function handleGetUserPromptList() {
474475
</NListItem>
475476
</NList>
476477
</NTabPane>
477-
<NTabPane name="download" :tab="$t('store.online')">
478+
<NTabPane name="download" :tab="t('store.online')">
478479
<p class="mb-4">
479-
{{ $t('store.onlineImportWarning') }}
480+
{{ t('store.onlineImportWarning') }}
480481
</p>
481482
<div class="flex items-center gap-4">
482483
<NInput v-model:value="downloadURL" placeholder="" />
@@ -487,7 +488,7 @@ async function handleGetUserPromptList() {
487488
:loading="importLoading"
488489
@click="downloadPromptTemplate()"
489490
>
490-
{{ $t('common.download') }}
491+
{{ t('common.download') }}
491492
</NButton>
492493
</div>
493494
<NDivider />

src/components/common/PromptTypeTag/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
2-
import { t } from '@/locales'
2+
defineProps<Props>()
3+
4+
const { t } = useI18n()
35
46
interface Props {
57
type: 'built-in' | 'user-defined'
68
}
7-
8-
defineProps<Props>()
99
</script>
1010

1111
<template>

src/components/common/Setting/About.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup lang='ts'>
22
import { fetchChatConfig, fetchUpdateBaseSetting } from '@/api'
3-
import { t } from '@/locales'
43
import { ConfigState } from './model'
54
5+
const { t } = useI18n()
6+
67
const ms = useMessage()
78
89
const loading = ref(false)
@@ -46,45 +47,45 @@ onMounted(() => {
4647
<div class="p-4 space-y-5 min-h-[200px]">
4748
<div class="space-y-6">
4849
<div class="flex items-center space-x-4">
49-
<span class="shrink-0 w-[100px]">{{ $t('setting.apiBaseUrl') }}</span>
50+
<span class="shrink-0 w-[100px]">{{ t('setting.apiBaseUrl') }}</span>
5051
<div class="flex-1">
5152
<NInput :value="config.apiBaseUrl" placeholder="https://api.openai.com, Only used by ChatGPTAPI" @input="(val) => { config.apiBaseUrl = val }" />
5253
</div>
5354
</div>
5455
<div class="flex items-center space-x-4">
55-
<span class="shrink-0 w-[100px]">{{ $t('setting.reverseProxy') }}</span>
56+
<span class="shrink-0 w-[100px]">{{ t('setting.reverseProxy') }}</span>
5657
<div class="flex-1">
5758
<NInput :value="config.reverseProxy" placeholder="Only used by ChatGPTUnofficialProxyAPI" @input="(val) => { config.reverseProxy = val }" />
5859
</div>
5960
</div>
6061
<div class="flex items-center space-x-4">
61-
<span class="shrink-0 w-[100px]">{{ $t('setting.timeout') }}</span>
62+
<span class="shrink-0 w-[100px]">{{ t('setting.timeout') }}</span>
6263
<div class="flex-1">
6364
<NInput :value="config.timeoutMs !== undefined ? String(config.timeoutMs) : undefined" placeholder="" @input="(val) => { config.timeoutMs = typeof val === 'string' ? Number(val) : undefined }" />
6465
</div>
6566
</div>
6667
<div class="flex items-center space-x-4">
67-
<span class="shrink-0 w-[100px]">{{ $t('setting.socks') }}</span>
68+
<span class="shrink-0 w-[100px]">{{ t('setting.socks') }}</span>
6869
<div class="flex-1">
6970
<NInput :value="config.socksProxy" placeholder="ip:port" @input="(val) => { config.socksProxy = val }" />
7071
</div>
7172
</div>
7273
<div class="flex items-center space-x-4">
73-
<span class="shrink-0 w-[100px]">{{ $t('setting.socksAuth') }}</span>
74+
<span class="shrink-0 w-[100px]">{{ t('setting.socksAuth') }}</span>
7475
<div class="flex-1">
7576
<NInput :value="config.socksAuth" placeholder="name:pasword" @input="(val) => { config.socksAuth = val }" />
7677
</div>
7778
</div>
7879
<div class="flex items-center space-x-4">
79-
<span class="shrink-0 w-[100px]">{{ $t('setting.httpsProxy') }}</span>
80+
<span class="shrink-0 w-[100px]">{{ t('setting.httpsProxy') }}</span>
8081
<div class="flex-1">
8182
<NInput :value="config.httpsProxy" placeholder="" @input="(val) => { config.httpsProxy = val }" />
8283
</div>
8384
</div>
8485
<div class="flex items-center space-x-4">
8586
<span class="shrink-0 w-[100px]" />
8687
<NButton :loading="saving" type="primary" @click="updateBaseSetting(config)">
87-
{{ $t('common.save') }}
88+
{{ t('common.save') }}
8889
</NButton>
8990
</div>
9091
</div>

src/components/common/Setting/Advanced.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script lang="ts" setup>
2-
import { t } from '@/locales'
32
import { useUserStore } from '@/store'
43
4+
const { t } = useI18n()
5+
56
const userStore = useUserStore()
67
78
const ms = useMessage()
@@ -22,20 +23,20 @@ function handleReset() {
2223
<div class="p-4 space-y-5 min-h-[200px]">
2324
<div class="space-y-6">
2425
<div class="flex items-center space-x-4">
25-
<span class="shrink-0 w-[120px]">{{ $t('setting.role') }}</span>
26+
<span class="shrink-0 w-[120px]">{{ t('setting.role') }}</span>
2627
<div class="flex-1">
2728
<NInput v-model:value="userStore.userInfo.advanced.systemMessage" type="textarea" :autosize="{ minRows: 1, maxRows: 4 }" />
2829
</div>
2930
</div>
3031
<div class="flex items-center space-x-4">
31-
<span class="shrink-0 w-[120px]">{{ $t('setting.temperature') }} </span>
32+
<span class="shrink-0 w-[120px]">{{ t('setting.temperature') }} </span>
3233
<div class="flex-1">
3334
<NSlider v-model:value="userStore.userInfo.advanced.temperature" :max="1" :min="0" :step="0.1" />
3435
</div>
3536
<span>{{ userStore.userInfo.advanced.temperature }}</span>
3637
</div>
3738
<div class="flex items-center space-x-4">
38-
<span class="shrink-0 w-[120px]">{{ $t('setting.top_p') }} </span>
39+
<span class="shrink-0 w-[120px]">{{ t('setting.top_p') }} </span>
3940
<div class="flex-1">
4041
<NSlider v-model:value="userStore.userInfo.advanced.top_p" :max="1" :min="0" :step="0.1" />
4142
</div>
@@ -44,13 +45,13 @@ function handleReset() {
4445
<div class="flex items-center space-x-4">
4546
<span class="shrink-0 w-[120px]">&nbsp;</span>
4647
<NButton type="primary" @click="updateSettings(false)">
47-
{{ $t('common.save') }}
48+
{{ t('common.save') }}
4849
</NButton>
4950
<NButton v-if="userStore.userInfo.root" type="info" @click="updateSettings(true)">
50-
{{ $t('common.sync') }}
51+
{{ t('common.sync') }}
5152
</NButton>
5253
<NButton type="warning" @click="handleReset">
53-
{{ $t('common.reset') }}
54+
{{ t('common.reset') }}
5455
</NButton>
5556
</div>
5657
</div>

src/components/common/Setting/Anonuncement.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang='ts'>
22
import type { AnnounceConfig, ConfigState } from './model'
33
import { fetchChatConfig, fetchUpdateAnnounce } from '@/api'
4-
import { t } from '@/locales'
4+
5+
const { t } = useI18n()
56
67
const ms = useMessage()
78
@@ -43,7 +44,7 @@ onMounted(() => {
4344
<NSpin :show="loading">
4445
<div class="space-y-6">
4546
<div class="flex items-center space-x-4">
46-
<span class="shrink-0 w-[100px]">{{ $t('setting.announceEnabled') }}</span>
47+
<span class="shrink-0 w-[100px]">{{ t('setting.announceEnabled') }}</span>
4748
<div class="flex-1">
4849
<NSwitch
4950
:round="false" :value="config && config.enabled"
@@ -52,7 +53,7 @@ onMounted(() => {
5253
</div>
5354
</div>
5455
<div class="flex items-center space-x-4">
55-
<span class="shrink-0 w-[100px]">{{ $t('setting.announceWords') }}</span>
56+
<span class="shrink-0 w-[100px]">{{ t('setting.announceWords') }}</span>
5657
<div class="flex-1">
5758
<NInput
5859
:value="config && config.announceWords"
@@ -66,7 +67,7 @@ onMounted(() => {
6667
<span class="shrink-0 w-[100px]" />
6768
<div class="flex flex-wrap items-center gap-4">
6869
<NButton :loading="saving" type="primary" @click="updateAnnouncement()">
69-
{{ $t('common.save') }}
70+
{{ t('common.save') }}
7071
</NButton>
7172
</div>
7273
</div>

0 commit comments

Comments
 (0)