Skip to content

Commit bbf93eb

Browse files
committed
feat(core): 拆分 Settings 为 Composition 方式
1 parent 54818d0 commit bbf93eb

2 files changed

Lines changed: 70 additions & 33 deletions

File tree

src/components/Settings.vue

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,30 @@
2525
</template>
2626

2727
<script setup lang="ts">
28-
import { nextTick, onMounted, ref } from 'vue'
29-
import { BracesIcon, CodeIcon, ShieldIcon } from 'lucide-vue-next'
28+
import { onMounted } from 'vue'
3029
import Modal from '../ui/Modal.vue'
3130
import Tabs from '../ui/Tabs.vue'
3231
import General from './setting/General.vue'
3332
import Language from './setting/Language.vue'
3433
import Editor from './setting/Editor.vue'
35-
36-
const isVisible = ref(false)
37-
const activeTab = ref('general')
38-
const tabsData = [
39-
{ key: 'general', label: '通用', icon: ShieldIcon },
40-
{ key: 'editor', label: '编辑器', icon: CodeIcon },
41-
{ key: 'language', label: '语言', icon: BracesIcon }
42-
]
34+
import { useSettings } from '../composables/useSettings.ts'
4335
4436
const emit = defineEmits<{
4537
close: []
4638
'settings-changed': [config: any]
4739
}>()
4840
49-
// 处理编辑器设置变更
50-
const handleEditorSettingsChanged = (config: any) => {
51-
console.log('设置模态框接收到编辑器配置变更:', config)
52-
// 向上传递事件到主组件
53-
emit('settings-changed', config)
54-
}
55-
56-
// 处理编辑器错误
57-
const handleEditorError = (message: string) => {
58-
console.error('编辑器设置错误:', message)
59-
}
60-
61-
const closeSettings = () => {
62-
isVisible.value = false
63-
setTimeout(() => {
64-
emit('close')
65-
}, 300)
66-
}
41+
const {
42+
isVisible,
43+
activeTab,
44+
tabsData,
45+
handleEditorSettingsChanged,
46+
handleEditorError,
47+
closeSettings,
48+
initialize
49+
} = useSettings(emit)
6750
6851
onMounted(async () => {
69-
// 延迟显示动画
70-
await nextTick()
71-
setTimeout(() => {
72-
isVisible.value = true
73-
}, 50)
52+
await initialize()
7453
})
7554
</script>

src/composables/useSettings.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { nextTick, ref } from 'vue'
2+
import { BracesIcon, CodeIcon, ShieldIcon } from 'lucide-vue-next'
3+
4+
export function useSettings(emit: any)
5+
{
6+
// 状态管理
7+
const isVisible = ref(false)
8+
const activeTab = ref('general')
9+
10+
// 标签页配置
11+
const tabsData = [
12+
{ key: 'general', label: '通用', icon: ShieldIcon },
13+
{ key: 'editor', label: '编辑器', icon: CodeIcon },
14+
{ key: 'language', label: '语言', icon: BracesIcon }
15+
]
16+
17+
// 处理编辑器设置变更
18+
const handleEditorSettingsChanged = (config: any) => {
19+
console.log('设置模态框接收到编辑器配置变更:', config)
20+
// 向上传递事件到主组件
21+
emit('settings-changed', config)
22+
}
23+
24+
// 处理编辑器错误
25+
const handleEditorError = (message: string) => {
26+
console.error('编辑器设置错误:', message)
27+
}
28+
29+
// 关闭设置
30+
const closeSettings = () => {
31+
isVisible.value = false
32+
setTimeout(() => {
33+
emit('close')
34+
}, 300)
35+
}
36+
37+
// 初始化模态框
38+
const initialize = async () => {
39+
// 延迟显示动画
40+
await nextTick()
41+
setTimeout(() => {
42+
isVisible.value = true
43+
}, 50)
44+
}
45+
46+
return {
47+
// 状态
48+
isVisible,
49+
activeTab,
50+
tabsData,
51+
52+
// 方法
53+
handleEditorSettingsChanged,
54+
handleEditorError,
55+
closeSettings,
56+
initialize
57+
}
58+
}

0 commit comments

Comments
 (0)