Skip to content

Commit e379802

Browse files
committed
feat: 默认配置和类型工具提取到独立子包中
1 parent 71a094f commit e379802

24 files changed

Lines changed: 448 additions & 666 deletions

File tree

apps/core/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@fantastic-mobile/components": "workspace:*",
20+
"@fantastic-mobile/settings": "workspace:*",
2021
"@fantastic-mobile/themes": "workspace:*",
2122
"@vant/touch-emulator": "catalog:",
2223
"@vee-validate/zod": "catalog:",
@@ -57,12 +58,10 @@
5758
"@iconify/vue": "catalog:",
5859
"@types/nprogress": "catalog:",
5960
"@types/qs": "catalog:",
60-
"@unocss/reset": "catalog:",
6161
"@vitejs/plugin-legacy": "catalog:",
6262
"@vitejs/plugin-vue": "catalog:",
6363
"@vitejs/plugin-vue-jsx": "catalog:",
6464
"@vue/tsconfig": "catalog:",
65-
"@yeungkc/unocss-preset-safe-area": "catalog:",
6665
"autoprefixer": "catalog:",
6766
"boxen": "catalog:",
6867
"http-server": "catalog:",
@@ -73,8 +72,6 @@
7372
"postcss-nested": "catalog:",
7473
"sass-embedded": "catalog:",
7574
"svgo": "catalog:",
76-
"unocss": "catalog:",
77-
"unocss-preset-animations": "catalog:",
7875
"unplugin-auto-import": "catalog:",
7976
"unplugin-turbo-console": "catalog:",
8077
"unplugin-vue-components": "catalog:",

apps/core/src/components/AppSetting/index.vue

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script setup lang="ts">
22
import { useClipboard } from '@vueuse/core'
33
import { toast } from 'vue-sonner'
4-
import settingsDefault from '@/settings/default'
5-
import { diffTwoObj } from '@/settings/utils'
4+
import { setSettings } from '@fantastic-mobile/settings'
65
import eventBus from '@/utils/eventBus'
76
87
defineOptions({
98
name: 'AppSetting',
109
})
1110
1211
const appSettingsStore = useAppSettingsStore()
12+
const settingsDefault = setSettings({})
1313
1414
const isShow = ref(false)
1515
@@ -41,6 +41,33 @@ watch(copied, (val) => {
4141
function handleCopy() {
4242
copy(JSON.stringify(diffTwoObj(settingsDefault, appSettingsStore.settings), null, 2))
4343
}
44+
45+
function isObject(value: unknown): value is Record<string, any> {
46+
return typeof value === 'object' && value !== null && !Array.isArray(value)
47+
}
48+
49+
function diffTwoObj(originalObj: Record<string, any>, diffObj: Record<string, any>) {
50+
if (!isObject(originalObj) || !isObject(diffObj)) {
51+
return diffObj
52+
}
53+
const diff: Record<string, any> = {}
54+
for (const key in diffObj) {
55+
const originalValue = originalObj[key]
56+
const diffValue = diffObj[key]
57+
if (JSON.stringify(originalValue) !== JSON.stringify(diffValue)) {
58+
if (isObject(originalValue) && isObject(diffValue)) {
59+
const nestedDiff = diffTwoObj(originalValue, diffValue)
60+
if (Object.keys(nestedDiff).length > 0) {
61+
diff[key] = nestedDiff
62+
}
63+
}
64+
else {
65+
diff[key] = diffValue
66+
}
67+
}
68+
}
69+
return diff
70+
}
4471
</script>
4572

4673
<template>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setSettings } from './utils'
1+
import { setSettings } from '@fantastic-mobile/settings'
22

33
export default setSettings({
44
// 请在此处编写或粘贴配置代码

apps/core/src/settings/utils.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

apps/core/src/store/modules/app/settings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Settings } from '#/global'
1+
import type { ThemeSettings } from '@fantastic-mobile/settings'
22
import settingsDefault from '@/settings'
33

44
export const useAppSettingsStore = defineStore(
@@ -24,7 +24,7 @@ export const useAppSettingsStore = defineStore(
2424
immediate: true,
2525
})
2626

27-
const currentColorScheme = ref<Exclude<Settings.theme['colorScheme'], ''>>()
27+
const currentColorScheme = ref<Exclude<Required<ThemeSettings>['colorScheme'], ''>>()
2828
watch(() => settings.value.theme.colorScheme, updateTheme, {
2929
immediate: true,
3030
})

apps/core/src/types/global.d.ts

Lines changed: 0 additions & 112 deletions
This file was deleted.

apps/example/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@fantastic-mobile/components": "workspace:*",
20+
"@fantastic-mobile/settings": "workspace:*",
2021
"@fantastic-mobile/themes": "workspace:*",
2122
"@vant/touch-emulator": "catalog:",
2223
"@vee-validate/zod": "catalog:",
@@ -59,12 +60,10 @@
5960
"@iconify/vue": "catalog:",
6061
"@types/nprogress": "catalog:",
6162
"@types/qs": "catalog:",
62-
"@unocss/reset": "catalog:",
6363
"@vitejs/plugin-legacy": "catalog:",
6464
"@vitejs/plugin-vue": "catalog:",
6565
"@vitejs/plugin-vue-jsx": "catalog:",
6666
"@vue/tsconfig": "catalog:",
67-
"@yeungkc/unocss-preset-safe-area": "catalog:",
6867
"autoprefixer": "catalog:",
6968
"boxen": "catalog:",
7069
"http-server": "catalog:",
@@ -75,8 +74,6 @@
7574
"postcss-nested": "catalog:",
7675
"sass-embedded": "catalog:",
7776
"svgo": "catalog:",
78-
"unocss": "catalog:",
79-
"unocss-preset-animations": "catalog:",
8077
"unplugin-auto-import": "catalog:",
8178
"unplugin-turbo-console": "catalog:",
8279
"unplugin-vue-components": "catalog:",

apps/example/src/components/AppSetting/index.vue

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script setup lang="ts">
22
import { useClipboard } from '@vueuse/core'
33
import { toast } from 'vue-sonner'
4-
import settingsDefault from '@/settings/default'
5-
import { diffTwoObj } from '@/settings/utils'
4+
import { setSettings } from '@fantastic-mobile/settings'
65
import eventBus from '@/utils/eventBus'
76
87
defineOptions({
98
name: 'AppSetting',
109
})
1110
1211
const appSettingsStore = useAppSettingsStore()
12+
const settingsDefault = setSettings({})
1313
1414
const isShow = ref(false)
1515
@@ -41,6 +41,33 @@ watch(copied, (val) => {
4141
function handleCopy() {
4242
copy(JSON.stringify(diffTwoObj(settingsDefault, appSettingsStore.settings), null, 2))
4343
}
44+
45+
function isObject(value: unknown): value is Record<string, any> {
46+
return typeof value === 'object' && value !== null && !Array.isArray(value)
47+
}
48+
49+
function diffTwoObj(originalObj: Record<string, any>, diffObj: Record<string, any>) {
50+
if (!isObject(originalObj) || !isObject(diffObj)) {
51+
return diffObj
52+
}
53+
const diff: Record<string, any> = {}
54+
for (const key in diffObj) {
55+
const originalValue = originalObj[key]
56+
const diffValue = diffObj[key]
57+
if (JSON.stringify(originalValue) !== JSON.stringify(diffValue)) {
58+
if (isObject(originalValue) && isObject(diffValue)) {
59+
const nestedDiff = diffTwoObj(originalValue, diffValue)
60+
if (Object.keys(nestedDiff).length > 0) {
61+
diff[key] = nestedDiff
62+
}
63+
}
64+
else {
65+
diff[key] = diffValue
66+
}
67+
}
68+
}
69+
return diff
70+
}
4471
</script>
4572

4673
<template>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setSettings } from './utils'
1+
import { setSettings } from '@fantastic-mobile/settings'
22

33
export default setSettings({
44
app: {

0 commit comments

Comments
 (0)