Skip to content

Commit

Permalink
feat: language use radio selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Apr 9, 2023
1 parent bb7adcf commit 540d9da
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/components/Session/components/SessionAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ const calcToken = (data: SessionData) => {
/>
</a-tooltip>
<span class="text-gray text-xs" v-if="isTokenUsage">
<span
class="text-gray w-13! whitespace-nowrap text-center text-xs"
v-if="isTokenUsage"
>
{{ calcToken(data) }}
</span>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Session/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ watch([currentSession, sessionDataList], () => {
{{ getLocalTime(item.time!) }}
</span>

<div class="blink-block" v-if="!item.message.content" />
<div
class="blink-block"
:class="[showTime ? 'p0' : 'py-4']"
v-if="!item.message.content"
/>

<SessionContent :data="item" v-else />
</div>
Expand Down
30 changes: 20 additions & 10 deletions src/components/Settings/components/General.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
const settingsStore = useSettingsStore()
const { toggleTheme, setLanguage } = settingsStore
const { themeMode, autoStart, isRememberPosition, proxy, showTime } =
const { themeMode, autoStart, isRememberPosition, proxy, currentLang } =
storeToRefs(settingsStore)
const relaunch = () => {
Expand All @@ -11,11 +11,21 @@ const relaunch = () => {

<template>
<ul class="general flex flex-col gap-4">
<button @click="setLanguage('zh')">zh</button>
<button @click="setLanguage('en')">en</button>
<li>
<i>唤醒窗口:</i>
<ShortcutKey />
<i>语言:</i>
<a-radio-group
v-model="currentLang"
type="button"
size="large"
@change="(value: any) => setLanguage(value)"
>
<a-radio value="zh">
<icon-chinese-fill />
</a-radio>
<a-radio value="en">
<icon-english-fill />
</a-radio>
</a-radio-group>
</li>

<li>
Expand All @@ -38,6 +48,11 @@ const relaunch = () => {
</a-radio-group>
</li>

<li>
<i>唤醒窗口:</i>
<ShortcutKey />
</li>

<li>
<i>开机自启动:</i>
<a-switch v-model="autoStart" type="round" size="medium" />
Expand All @@ -48,11 +63,6 @@ const relaunch = () => {
<a-switch v-model="isRememberPosition" type="round" />
</li>

<li>
<i>显示对话时间:</i>
<a-switch v-model="showTime" type="round" />
</li>

<li>
<i>开启代理:</i>
<a-switch v-model="proxy.bypass" type="round"></a-switch>
Expand Down
10 changes: 7 additions & 3 deletions src/components/Settings/components/Modal.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script setup lang="ts">
const { apiKey, isMemory, modalParams, isTokenUsage, tokenUnit } = storeToRefs(
useSettingsStore()
)
const { apiKey, isMemory, modalParams, isTokenUsage, tokenUnit, showTime } =
storeToRefs(useSettingsStore())
const totalCredit = ref(0)
const usedCredit = ref(0)
Expand Down Expand Up @@ -35,6 +34,11 @@ watch(
<a-input-password v-model="apiKey" placeholder="OpenAI API KEY" />
</li>

<li>
<i>显示对话时间:</i>
<a-switch v-model="showTime" type="round" />
</li>

<li>
<i>记忆模式:</i>
<a-switch v-model="isMemory" type="round" />
Expand Down
8 changes: 4 additions & 4 deletions src/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export const useSettingsStore = defineStore(
// 显示对话时间
const showTime = ref(false)

// 当前显示语言
const currentLang = ref<string | undefined>()
const { locale } = useI18n({ useScope: 'global' })

// 绑定快捷键
const registerKey = async () => {
await unregisterAll()
Expand Down Expand Up @@ -80,10 +84,6 @@ export const useSettingsStore = defineStore(
document.body.setAttribute('arco-theme', theme)
}

// 当前显示语言
const currentLang = ref<string | undefined>()
const { locale } = useI18n({ useScope: 'global' })

// 语言切换
const setLanguage = async (lang?: Locales) => {
const systemLang = ((await invoke('get_user_language')) as string).split(
Expand Down

0 comments on commit 540d9da

Please sign in to comment.