|
1 | 1 | <script lang="ts" setup> |
2 | 2 | import { computed, ref } from 'vue' |
3 | | -import { NButton, NInput, NPopconfirm, NSelect, useMessage } from 'naive-ui' |
| 3 | +import { NButton, NDivider, NInput, NPopconfirm, NSelect, useMessage } from 'naive-ui' |
| 4 | +import { UserConfig } from '@/components/common/Setting/model' |
4 | 5 | import type { Language, Theme } from '@/store/modules/app/helper' |
5 | 6 | import { SvgIcon } from '@/components/common' |
6 | | -import { useAppStore, useUserStore } from '@/store' |
| 7 | +import { useAppStore, useAuthStore, useUserStore } from '@/store' |
7 | 8 | import type { UserInfo } from '@/store/modules/user/helper' |
8 | 9 | import { getCurrentDate } from '@/utils/functions' |
9 | 10 | import { useBasicLayout } from '@/hooks/useBasicLayout' |
10 | 11 | import { t } from '@/locales' |
11 | | -import { fetchClearAllChat } from '@/api' |
| 12 | +import { fetchClearAllChat, fetchUpdateUserChatModel } from '@/api' |
12 | 13 |
|
13 | 14 | const appStore = useAppStore() |
14 | 15 | const userStore = useUserStore() |
| 16 | +const authStore = useAuthStore() |
15 | 17 |
|
16 | 18 | const { isMobile } = useBasicLayout() |
17 | 19 |
|
@@ -66,6 +68,14 @@ async function updateUserInfo(options: Partial<UserInfo>) { |
66 | 68 | ms.success(t('common.success')) |
67 | 69 | } |
68 | 70 |
|
| 71 | +async function updateUserChatModel(chatModel: string) { |
| 72 | + if (!userStore.userInfo.config) |
| 73 | + userStore.userInfo.config = new UserConfig() |
| 74 | + userStore.userInfo.config.chatModel = chatModel |
| 75 | + userStore.recordState() |
| 76 | + await fetchUpdateUserChatModel(chatModel) |
| 77 | +} |
| 78 | +
|
69 | 79 | function exportData(): void { |
70 | 80 | const date = getCurrentDate() |
71 | 81 | const data: string = localStorage.getItem('chatStorage') || '{}' |
@@ -138,6 +148,25 @@ function handleImportButtonClick(): void { |
138 | 148 | <NInput v-model:value="avatar" placeholder="" /> |
139 | 149 | </div> |
140 | 150 | </div> |
| 151 | + <div class="flex items-center space-x-4"> |
| 152 | + <span class="flex-shrink-0 w-[100px]">{{ $t('setting.saveUserInfo') }}</span> |
| 153 | + <NButton type="primary" @click="updateUserInfo({ avatar, name, description })"> |
| 154 | + {{ $t('common.save') }} |
| 155 | + </NButton> |
| 156 | + </div> |
| 157 | + <NDivider /> |
| 158 | + <div class="flex items-center space-x-4"> |
| 159 | + <span class="flex-shrink-0 w-[100px]">{{ $t('setting.defaultChatModel') }}</span> |
| 160 | + <div class="w-[200px]"> |
| 161 | + <NSelect |
| 162 | + style="width: 200px" |
| 163 | + :value="userInfo.config.chatModel" |
| 164 | + :options="authStore.session?.chatModels" |
| 165 | + :disabled="!!authStore.session?.auth && !authStore.token" |
| 166 | + @update-value="(val) => updateUserChatModel(val)" |
| 167 | + /> |
| 168 | + </div> |
| 169 | + </div> |
141 | 170 | <div |
142 | 171 | class="flex items-center space-x-4" |
143 | 172 | :class="isMobile && 'items-start'" |
@@ -200,12 +229,6 @@ function handleImportButtonClick(): void { |
200 | 229 | /> |
201 | 230 | </div> |
202 | 231 | </div> |
203 | | - <div class="flex items-center space-x-4"> |
204 | | - <span class="flex-shrink-0 w-[100px]">{{ $t('setting.saveUserInfo') }}</span> |
205 | | - <NButton type="primary" @click="updateUserInfo({ avatar, name, description })"> |
206 | | - {{ $t('common.save') }} |
207 | | - </NButton> |
208 | | - </div> |
209 | 232 | </div> |
210 | 233 | </div> |
211 | 234 | </template> |
0 commit comments