forked from mx-space/mx-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
121 lines (110 loc) · 2.71 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
darkTheme,
dateZhCN,
lightTheme,
NConfigProvider,
NDialogProvider,
NElement,
NMessageProvider,
NNotificationProvider,
useDialog,
useMessage,
useNotification,
useThemeVars,
zhCN,
} from 'naive-ui'
import { defineComponent, onMounted } from 'vue'
import { RouterView } from 'vue-router'
import type { VNode } from 'vue'
import { PortalInjectKey } from '~/hooks/use-portal-element'
import { ThemeColorConfig } from '../theme.config'
import { useUIStore } from './stores/ui'
import { colorRef } from './utils/color'
const Root = defineComponent({
name: 'RootView',
setup() {
onMounted(() => {
const message = useMessage()
const _error = message.error
Object.assign(message, {
error: (...rest: any[]) => {
// @ts-ignore
_error.apply(this, rest)
throw rest[0]
},
})
window.message = message
window.notification = useNotification()
window.dialog = useDialog()
})
const $portalElement = ref<VNode | null>(null)
provide(PortalInjectKey, {
setElement(el) {
$portalElement.value = el
return () => {
$portalElement.value = null
}
},
})
return () => {
return (
<>
<RouterView />
{$portalElement.value}
</>
)
}
},
})
const App = defineComponent({
setup() {
const uiStore = useUIStore()
return () => {
const { isDark, naiveUIDark } = uiStore
return (
<NConfigProvider
locale={zhCN}
dateLocale={dateZhCN}
themeOverrides={{
common: colorRef.value,
}}
theme={naiveUIDark ? darkTheme : isDark ? darkTheme : lightTheme}
>
<NNotificationProvider>
<NMessageProvider>
<NDialogProvider>
<AccentColorInjector />
<NElement>
<Root />
</NElement>
</NDialogProvider>
</NMessageProvider>
</NNotificationProvider>
</NConfigProvider>
)
}
},
})
const AccentColorInjector = defineComponent({
setup() {
const vars = useThemeVars()
watchEffect(() => {
const { primaryColor, primaryColorHover, primaryColorSuppl } = vars.value
document.documentElement.style.setProperty(
'--color-primary',
primaryColor,
)
document.documentElement.style.setProperty(
'--color-primary-shallow',
primaryColorHover,
)
document.documentElement.style.setProperty(
'--color-primary-deep',
primaryColorSuppl,
)
})
return () => null
},
})
// eslint-disable-next-line import/no-default-export
export default App