Skip to content

Commit

Permalink
feat: extract variables for history
Browse files Browse the repository at this point in the history
  • Loading branch information
DongHuiTiao authored and ayangweb committed Apr 9, 2023
1 parent eed086e commit 30c5c8c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
24 changes: 14 additions & 10 deletions src/components/Function/components/HistoryDrawer.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import type { SessionPayload } from '@/types'
const { t } = useI18n()
const props = defineProps<{ visible: boolean; setVisible: () => void }>()
const sessionStore = useSessionStore()
Expand All @@ -22,7 +22,7 @@ const renderList = computed(() =>
const isEdit = computed(() => sessionList.value.some((item) => item.isEdit))
const handleClick = (item: SessionPayload) => {
if (isEdit.value) return Message.info('请先完成当前编辑')
if (isEdit.value) return Message.info(t('message.pleaseFinishEdit'))
switchSession(item)
Expand All @@ -46,21 +46,21 @@ const handleOpen = () => {
}
const handleClose = () => {
if (isEdit.value) return Message.info('请先完成当前编辑')
if (isEdit.value) return Message.info(t('message.pleaseFinishEdit'))
search.value = ''
props.setVisible()
}
const handleEdit = (item: SessionPayload) => {
if (isEdit.value) return Message.info(`请先完成当前编辑`)
if (isEdit.value) return Message.info(t('message.pleaseFinishEdit'))
item.isEdit = true
}
const handleUpdate = (item: SessionPayload) => {
if (!item.title.trim()) return Message.info('标题不能为空')
if (!item.title.trim()) return Message.info(t('message.titleRequire'))
item.isEdit = false
Expand All @@ -80,7 +80,7 @@ const handleUpdate = (item: SessionPayload) => {
unmountOnClose
>
<!-- TODO:加入全部清除的按钮 -->
<template #title> 会话历史 </template>
<template #title> {{ $t('history.title') }} </template>

<ul class="flex flex-col gap-2" v-if="renderList.length">
<li
Expand Down Expand Up @@ -112,7 +112,11 @@ const handleUpdate = (item: SessionPayload) => {
{{ item.title }}
</div>
<div class="truncate">与 {{ item.name }} 的会话</div>
<div class="truncate">
<i18n-t keypath="history.historyWith" tag="label">
<span>{{ ` ${item.name} ` }}</span>
</i18n-t>
</div>
</div>
<div
Expand All @@ -123,7 +127,7 @@ const handleUpdate = (item: SessionPayload) => {
<icon-edit @click="handleEdit(item)" />
<a-popconfirm
type="error"
content="确定删除该会话吗?"
:content="t('history.confirmDelete')"
@ok="deleteSession(item)"
>
<icon-delete />
Expand All @@ -139,14 +143,14 @@ const handleUpdate = (item: SessionPayload) => {
</ul>
<div class="flex h-full items-center" v-else>
<a-empty description="暂无历史会话" />
<a-empty :description="t('history.empty')" />
</div>
<template #footer>
<a-input-search
ref="searchRef"
v-model="search"
placeholder="搜索对话"
:placeholder="t('history.searchPlaceholder')"
allow-clear
/>
</template>
Expand Down
18 changes: 9 additions & 9 deletions src/components/Function/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { emit } from '@tauri-apps/api/event'
const { t } = useI18n()
const { currentRole } = storeToRefs(useRoleStore())
const { isThinking } = storeToRefs(useSessionStore())
Expand All @@ -23,13 +23,13 @@ const triggerScroll = () => {

<!-- 当前聊天角色对象 -->
<div>
正在与
<a-tooltip content="点我回到底部">
<span class="mark cursor-pointer" @click="triggerScroll">
{{ currentRole?.name }}
</span>
</a-tooltip>
对话
<i18n-t keypath="session.sessionWith" tag="label">
<a-tooltip content="点我回到底部">
<span class="mark cursor-pointer" @click="triggerScroll">
{{ currentRole?.name }}
</span>
</a-tooltip>
</i18n-t>
</div>

<!-- 功能按钮 -->
Expand All @@ -41,7 +41,7 @@ const triggerScroll = () => {
<!-- 导出 -->
<Export />
<!-- 历史记录 -->
<a-tooltip content="历史记录">
<a-tooltip :content="`${t('history.title')}`">
<a-button
type="text"
:disabled="isThinking"
Expand Down
17 changes: 14 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"history": {},
"session": {},
"history": {
"confirmDelete": "Are you sure you want to delete this conversation?",
"empty": "No history session yet",
"historyWith": "Session with {0}",
"searchPlaceholder": "search session",
"title": "session history"
},
"session": {
"sessionWith": "Talking to {0}"
},
"setting": {
"tab": {
"common": "Common",
Expand Down Expand Up @@ -44,7 +52,10 @@
"checkUpdate": "Check for updates"
}
},
"message": {},
"message": {
"pleaseFinishEdit": "Please complete the current edit first",
"titleRequire": "The title can not be blank"
},
"errors": {},
"tips": {
"input": {
Expand Down
17 changes: 14 additions & 3 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"history": {},
"session": {},
"history": {
"title": "会话记录",
"historyWith": "与{0}的会话",
"confirmDelete": "确定删除该会话吗?",
"empty": "暂无历史会话",
"searchPlaceholder": "搜索对话"
},
"session": {
"sessionWith": "正在与{0}对话"
},
"setting": {
"tab": {
"common": "通用",
Expand Down Expand Up @@ -44,7 +52,10 @@
"checkUpdate": "检查更新"
}
},
"message": {},
"message": {
"pleaseFinishEdit": "请先完成当前编辑",
"titleRequire": "标题不能为空"
},
"errors": {},
"tips": {
"input": {
Expand Down

0 comments on commit 30c5c8c

Please sign in to comment.