|
|
@ -1,18 +1,13 @@
|
|
|
|
<script lang="ts" setup>
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, ref } from 'vue'
|
|
|
|
import { computed, ref } from 'vue'
|
|
|
|
import { NButton, NInput, useMessage } from 'naive-ui'
|
|
|
|
import { NButton, NInput, NPopconfirm, useMessage } from 'naive-ui'
|
|
|
|
import type { Language, Theme } from '@/store/modules/app/helper'
|
|
|
|
import type { Language, Theme } from '@/store/modules/app/helper'
|
|
|
|
import { SvgIcon } from '@/components/common'
|
|
|
|
import { SvgIcon } from '@/components/common'
|
|
|
|
import { useAppStore, useUserStore } from '@/store'
|
|
|
|
import { useAppStore, useUserStore } from '@/store'
|
|
|
|
import type { UserInfo } from '@/store/modules/user/helper'
|
|
|
|
import type { UserInfo } from '@/store/modules/user/helper'
|
|
|
|
|
|
|
|
import { getCurrentDate } from '@/utils/functions'
|
|
|
|
import { t } from '@/locales'
|
|
|
|
import { t } from '@/locales'
|
|
|
|
|
|
|
|
|
|
|
|
interface Emit {
|
|
|
|
|
|
|
|
(event: 'update'): void
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<Emit>()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const appStore = useAppStore()
|
|
|
|
const appStore = useAppStore()
|
|
|
|
const userStore = useUserStore()
|
|
|
|
const userStore = useUserStore()
|
|
|
|
|
|
|
|
|
|
|
@ -68,7 +63,56 @@ function updateUserInfo(options: Partial<UserInfo>) {
|
|
|
|
function handleReset() {
|
|
|
|
function handleReset() {
|
|
|
|
userStore.resetUserInfo()
|
|
|
|
userStore.resetUserInfo()
|
|
|
|
ms.success(t('common.success'))
|
|
|
|
ms.success(t('common.success'))
|
|
|
|
emit('update')
|
|
|
|
window.location.reload()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function exportData(): void {
|
|
|
|
|
|
|
|
const date = getCurrentDate()
|
|
|
|
|
|
|
|
const data: string = localStorage.getItem('chatStorage') || '{}'
|
|
|
|
|
|
|
|
const jsonString: string = JSON.stringify(JSON.parse(data), null, 2)
|
|
|
|
|
|
|
|
const blob: Blob = new Blob([jsonString], { type: 'application/json' })
|
|
|
|
|
|
|
|
const url: string = URL.createObjectURL(blob)
|
|
|
|
|
|
|
|
const link: HTMLAnchorElement = document.createElement('a')
|
|
|
|
|
|
|
|
link.href = url
|
|
|
|
|
|
|
|
link.download = `chat-store_${date}.json`
|
|
|
|
|
|
|
|
document.body.appendChild(link)
|
|
|
|
|
|
|
|
link.click()
|
|
|
|
|
|
|
|
document.body.removeChild(link)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function importData(event: Event): void {
|
|
|
|
|
|
|
|
const target = event.target as HTMLInputElement
|
|
|
|
|
|
|
|
if (!target || !target.files)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const file: File = target.files[0]
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const reader: FileReader = new FileReader()
|
|
|
|
|
|
|
|
reader.onload = () => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const data = JSON.parse(reader.result as string)
|
|
|
|
|
|
|
|
localStorage.setItem('chatStorage', JSON.stringify(data))
|
|
|
|
|
|
|
|
ms.success(t('common.success'))
|
|
|
|
|
|
|
|
location.reload()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (error) {
|
|
|
|
|
|
|
|
ms.error(t('common.invalidFileFormat'))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reader.readAsText(file)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clearData(): void {
|
|
|
|
|
|
|
|
localStorage.removeItem('chatStorage')
|
|
|
|
|
|
|
|
location.reload()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleImportButtonClick(): void {
|
|
|
|
|
|
|
|
const fileInput = document.getElementById('fileInput') as HTMLElement
|
|
|
|
|
|
|
|
if (fileInput)
|
|
|
|
|
|
|
|
fileInput.click()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
@ -102,25 +146,49 @@ function handleReset() {
|
|
|
|
{{ $t('common.save') }}
|
|
|
|
{{ $t('common.save') }}
|
|
|
|
</NButton>
|
|
|
|
</NButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.resetUserInfo') }}</span>
|
|
|
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.chatHistory') }}</span>
|
|
|
|
<NButton text type="primary" @click="handleReset">
|
|
|
|
|
|
|
|
{{ $t('common.reset') }}
|
|
|
|
<NButton @click="exportData">
|
|
|
|
|
|
|
|
<template #icon>
|
|
|
|
|
|
|
|
<SvgIcon icon="ri:download-2-fill" />
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
{{ $t('common.export') }}
|
|
|
|
|
|
|
|
</NButton>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<input id="fileInput" type="file" style="display:none" @change="importData">
|
|
|
|
|
|
|
|
<NButton @click="handleImportButtonClick">
|
|
|
|
|
|
|
|
<template #icon>
|
|
|
|
|
|
|
|
<SvgIcon icon="ri:upload-2-fill" />
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
{{ $t('common.import') }}
|
|
|
|
|
|
|
|
</NButton>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<NPopconfirm placement="bottom" @positive-click="clearData">
|
|
|
|
|
|
|
|
<template #trigger>
|
|
|
|
|
|
|
|
<NButton>
|
|
|
|
|
|
|
|
<template #icon>
|
|
|
|
|
|
|
|
<SvgIcon icon="ri:close-circle-line" />
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
{{ $t('common.clear') }}
|
|
|
|
</NButton>
|
|
|
|
</NButton>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
{{ $t('chat.clearHistoryConfirm') }}
|
|
|
|
|
|
|
|
</NPopconfirm>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.theme') }}</span>
|
|
|
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.theme') }}</span>
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
<template v-for="item of themeOptions" :key="item.key">
|
|
|
|
<template v-for="item of themeOptions" :key="item.key">
|
|
|
|
<a
|
|
|
|
<NButton
|
|
|
|
class="flex items-center justify-center h-8 px-4 border rounded-md cursor-pointer dark:border-neutral-700"
|
|
|
|
:type="item.key === theme ? 'primary' : undefined"
|
|
|
|
:class="item.key === theme && ['bg-[#4ca85e]', 'border-[#4ca85e]', 'text-white']"
|
|
|
|
|
|
|
|
@click="appStore.setTheme(item.key)"
|
|
|
|
@click="appStore.setTheme(item.key)"
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<span class="text-xl">
|
|
|
|
<template #icon>
|
|
|
|
<SvgIcon :icon="item.icon" />
|
|
|
|
<SvgIcon :icon="item.icon" />
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
</a>
|
|
|
|
</NButton>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -128,18 +196,21 @@ function handleReset() {
|
|
|
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.language') }}</span>
|
|
|
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.language') }}</span>
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
<template v-for="item of languageOptions" :key="item.key">
|
|
|
|
<template v-for="item of languageOptions" :key="item.key">
|
|
|
|
<a
|
|
|
|
<NButton
|
|
|
|
class="flex items-center justify-center h-8 px-4 border rounded-md cursor-pointer dark:border-neutral-700"
|
|
|
|
:type="item.key === language ? 'primary' : undefined"
|
|
|
|
:class="item.key === language && ['bg-[#4ca85e]', 'border-[#4ca85e]', 'text-white']"
|
|
|
|
|
|
|
|
@click="appStore.setLanguage(item.key)"
|
|
|
|
@click="appStore.setLanguage(item.key)"
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<span class="text-sm">
|
|
|
|
|
|
|
|
{{ item.label }}
|
|
|
|
{{ item.label }}
|
|
|
|
</span>
|
|
|
|
</NButton>
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex items-center space-x-4">
|
|
|
|
|
|
|
|
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.resetUserInfo') }}</span>
|
|
|
|
|
|
|
|
<NButton @click="handleReset">
|
|
|
|
|
|
|
|
{{ $t('common.reset') }}
|
|
|
|
|
|
|
|
</NButton>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|