11<template >
22 <Modal v-model:show =" isVisible" title =" 设置" size =" 4xl" :close-on-backdrop =" false" :close-on-esc =" false" @close =" closeSettings" >
3- <!-- 日志设置 -->
4- <div class =" mb-6" >
5- <h3 class =" text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center" >
6- <FileText class =" w-5 h-5 mr-2" />
7- 日志设置
8- </h3 >
9-
10- <div class =" space-y-4" >
11- <!-- 当前日志目录 -->
12- <div >
13- <label class =" block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" >
14- 当前日志目录
15- </label >
16- <div class =" bg-gray-50 dark:bg-gray-700 rounded-lg p-3 text-sm text-gray-600 dark:text-gray-400 font-mono" >
17- {{ currentLogDir || '加载中...' }}
18- </div >
19- </div >
20-
21- <!-- 修改日志目录 -->
22- <div >
23- <label class =" block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" >
24- 选择新的日志目录
25- </label >
26- <div class =" flex gap-2" >
27- <input v-model =" newLogDir"
28- type =" text"
29- placeholder =" 选择或输入日志目录路径"
30- class =" flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm"
31- readonly />
32-
33- <Button type =" primary"
34- :icon-only =" true"
35- :icon =" Folder"
36- @click =" selectLogDirectory" >
37- </Button >
38- </div >
39- </div >
40-
41- <!-- 操作按钮 -->
42- <div class =" flex gap-3 pt-0.5" >
43- <Button @click =" applyLogDirChange"
44- :disabled =" !newLogDir || newLogDir === currentLogDir"
45- type =" secondary" >
46- 应用更改
47- </Button >
48- <Button @click =" openLogDirectory" type =" secondary" >
49- 打开日志目录
50- </Button >
51- <Button @click =" resetLogDirectory"
52- class =" cursor-pointer px-4 py-2 bg-orange-500 hover:bg-orange-600 text-white text-sm font-medium rounded-md transition-colors" >
53- 重置为默认
54- </Button >
55- </div >
56-
57- <!-- 日志文件列表 -->
58- <div v-if =" logFiles.length > 0" >
59- <label class =" block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" >
60- 最近的日志文件
61- </label >
62- <div class =" bg-gray-50 dark:bg-gray-700 rounded-lg p-3 max-h-32 overflow-y-auto" >
63- <div v-for =" file in logFiles.slice(0, 5)" :key =" file"
64- class =" text-sm text-gray-600 dark:text-gray-400 font-mono py-1 hover:text-blue-600 dark:hover:text-blue-400 cursor-pointer"
65- @click =" openLogFile(file)" >
66- {{ file }}
67- </div >
68- </div >
69- </div >
70- </div >
71- </div >
72-
73- <!-- 日志管理 -->
74- <div class =" mb-6" >
75- <h3 class =" text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center" >
76- <Settings2 class =" w-5 h-5 mr-2" />
77- 日志管理
78- </h3 >
79-
80- <div class =" space-y-4" >
81- <!-- 清理旧日志 -->
82- <div >
83- <label class =" block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" >
84- 自动清理日志
85- </label >
86- <div class =" flex items-center gap-3" >
87- <Select v-model =" keepDays"
88- class =" w-36"
89- :options =" keepDaysOptions"
90- placeholder =" 选择保留天数" >
91- </Select >
92- <Button type =" danger" @click =" clearLogs" >
93- 立即清理
94- </Button >
95- </div >
96- </div >
97- </div >
98- </div >
3+ <Tabs v-model =" activeTab" type =" card" size =" md" :tabs =" tabsData" >
4+ <template #general >
5+ <General />
6+ </template >
7+ </Tabs >
998 </Modal >
1009</template >
10110
10211<script setup lang="ts">
10312import { nextTick , onMounted , ref } from ' vue'
104- import { invoke } from ' @tauri-apps/api/core'
105- import { open as openDialog } from ' @tauri-apps/plugin-dialog'
106- import { openPath } from ' @tauri-apps/plugin-opener'
107- import { FileText , Folder , Settings2 } from ' lucide-vue-next'
108- import Select from ' ../ui/Select.vue'
109- import { useToast } from ' ../plugins/toast'
110- import Button from ' ../ui/Button.vue'
13+ import { ShieldIcon } from ' lucide-vue-next'
11114import Modal from ' ../ui/Modal.vue'
15+ import Tabs from ' ../ui/Tabs.vue'
16+ import General from ' ./setting/General.vue'
11217
113- const toast = useToast ()
11418const isVisible = ref (false )
115- const currentLogDir = ref (' ' )
116- const newLogDir = ref (' ' )
117- const logFiles = ref <string []>([])
118- const keepDays = ref (30 )
119- const keepDaysOptions = [
120- { label: ' 保留 7 天' , value: 7 },
121- { label: ' 保留 14 天' , value: 14 },
122- { label: ' 保留 30 天' , value: 30 },
123- { label: ' 保留 90 天' , value: 90 }
19+ const activeTab = ref (' general' )
20+ const tabsData = [
21+ { key: ' general' , label: ' 通用' , icon: ShieldIcon }
12422]
12523
12624const emit = defineEmits <{
@@ -134,105 +32,7 @@ const closeSettings = () => {
13432 }, 300 )
13533}
13634
137- const loadLogDirectory = async () => {
138- try {
139- const logDir = await invoke <string >(' get_log_directory' )
140- currentLogDir .value = logDir
141- newLogDir .value = logDir
142- }
143- catch (error ) {
144- console .error (' Failed to get current log directory:' , error )
145- }
146- }
147-
148- const loadLogFiles = async () => {
149- try {
150- const files = await invoke <string []>(' get_log_files' )
151- logFiles .value = files
152- }
153- catch (error ) {
154- console .error (' Failed to get log files:' , error )
155- }
156- }
157-
158- const selectLogDirectory = async () => {
159- try {
160- const selected = await openDialog ({
161- directory: true ,
162- multiple: false ,
163- title: ' 选择日志目录'
164- })
165-
166- if (selected ) {
167- newLogDir .value = selected as string
168- }
169- }
170- catch (error ) {
171- console .error (' Failed to select directory:' , error )
172- }
173- }
174-
175- const applyLogDirChange = async () => {
176- try {
177- await invoke (' set_log_directory' , { path: newLogDir .value })
178- currentLogDir .value = newLogDir .value
179- await loadLogFiles ()
180- toast .success (' 日志目录已更新' )
181- }
182- catch (error ) {
183- console .error (' Failed to set log directory:' , error )
184- toast .error (' 日志目录更新失败, 错误信息: ' + error )
185- }
186- }
187-
188- const openLogDirectory = async () => {
189- try {
190- await openPath (currentLogDir .value )
191- }
192- catch (error ) {
193- console .error (' Failed to open log directory:' , error )
194- }
195- }
196-
197- const resetLogDirectory = async () => {
198- try {
199- await invoke (' reset_log_directory' )
200- await loadLogDirectory ()
201- await loadLogFiles ()
202- toast .success (' 日志目录已重置为默认' )
203- }
204- catch (error ) {
205- console .error (' Failed to reset log directory:' , error )
206- toast .error (' 日志目录重置失败, 错误信息: ' + error )
207- }
208- }
209-
210- const openLogFile = async (filename : string ) => {
211- try {
212- const logPath = ` ${ currentLogDir .value }/${ filename } `
213- await openPath (logPath )
214- }
215- catch (error ) {
216- console .error (' Failed to open log file:' , error )
217- }
218- }
219-
220- const clearLogs = async () => {
221- try {
222- await invoke (' clear_logs' , { keepDays: parseInt (keepDays .value .toString ()) })
223- await loadLogFiles ()
224- toast .success (` 已清理 ${ keepDays .value } 天前的日志 ` )
225- }
226- catch (error ) {
227- console .error (' Failed to clear old logs:' , error )
228- toast .error (' 清理日志失败, 错误信息: ' + error )
229- }
230- }
231-
23235onMounted (async () => {
233- await loadLogDirectory ()
234- await loadLogFiles ()
235-
23636 // 延迟显示动画
23737 await nextTick ()
23838 setTimeout (() => {
0 commit comments