parent
5aa4d3d5ae
commit
dcab55055c
@ -6,33 +6,14 @@
|
|||||||
:theme="appStore.isDark ? darkTheme : undefined"
|
:theme="appStore.isDark ? darkTheme : undefined"
|
||||||
:theme-overrides="naiveThemeOverrides"
|
:theme-overrides="naiveThemeOverrides"
|
||||||
>
|
>
|
||||||
<n-loading-bar-provider>
|
<slot />
|
||||||
<n-dialog-provider>
|
|
||||||
<n-notification-provider>
|
|
||||||
<n-message-provider>
|
|
||||||
<slot></slot>
|
|
||||||
<NaiveProviderContent />
|
|
||||||
</n-message-provider>
|
|
||||||
</n-notification-provider>
|
|
||||||
</n-dialog-provider>
|
|
||||||
</n-loading-bar-provider>
|
|
||||||
</n-config-provider>
|
</n-config-provider>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { defineComponent, h } from 'vue'
|
import { zhCN, dateZhCN, darkTheme } from 'naive-ui'
|
||||||
import {
|
|
||||||
zhCN,
|
|
||||||
dateZhCN,
|
|
||||||
darkTheme,
|
|
||||||
useLoadingBar,
|
|
||||||
useDialog,
|
|
||||||
useMessage,
|
|
||||||
useNotification,
|
|
||||||
} from 'naive-ui'
|
|
||||||
import { useCssVar } from '@vueuse/core'
|
import { useCssVar } from '@vueuse/core'
|
||||||
import { kebabCase } from 'lodash-es'
|
import { kebabCase } from 'lodash-es'
|
||||||
import { setupMessage, setupDialog } from '@/utils'
|
|
||||||
import { naiveThemeOverrides } from '~/settings'
|
import { naiveThemeOverrides } from '~/settings'
|
||||||
import { useAppStore } from '@/store'
|
import { useAppStore } from '@/store'
|
||||||
|
|
||||||
@ -45,23 +26,5 @@ function setupCssVar() {
|
|||||||
if (key === 'primaryColor') window.localStorage.setItem('__THEME_COLOR__', common[key] || '')
|
if (key === 'primaryColor') window.localStorage.setItem('__THEME_COLOR__', common[key] || '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 挂载naive组件的方法至window, 以便在全局使用
|
|
||||||
function setupNaiveTools() {
|
|
||||||
window.$loadingBar = useLoadingBar()
|
|
||||||
window.$notification = useNotification()
|
|
||||||
|
|
||||||
window.$message = setupMessage(useMessage())
|
|
||||||
window.$dialog = setupDialog(useDialog())
|
|
||||||
}
|
|
||||||
|
|
||||||
const NaiveProviderContent = defineComponent({
|
|
||||||
setup() {
|
|
||||||
setupCssVar()
|
setupCssVar()
|
||||||
setupNaiveTools()
|
|
||||||
},
|
|
||||||
render() {
|
|
||||||
return h('div')
|
|
||||||
},
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -9,11 +9,13 @@ import { setupRouter } from '@/router'
|
|||||||
import { setupStore } from '@/store'
|
import { setupStore } from '@/store'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import { useResize } from '@zclzone/utils'
|
import { useResize } from '@zclzone/utils'
|
||||||
|
import { setupNaiveDiscreteApi } from './utils'
|
||||||
|
|
||||||
async function setupApp() {
|
async function setupApp() {
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
|
||||||
setupStore(app)
|
setupStore(app)
|
||||||
|
setupNaiveDiscreteApi()
|
||||||
|
|
||||||
await setupRouter(app)
|
await setupRouter(app)
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
import * as NaiveUI from 'naive-ui'
|
||||||
import { isNullOrUndef } from '@/utils'
|
import { isNullOrUndef } from '@/utils'
|
||||||
|
import { naiveThemeOverrides as themeOverrides } from '~/settings'
|
||||||
|
import { useAppStore } from '@/store/modules/app'
|
||||||
|
|
||||||
export function setupMessage(NMessage) {
|
export function setupMessage(NMessage) {
|
||||||
let loadingMessage = null
|
let loadingMessage = null
|
||||||
@ -77,3 +80,20 @@ export function setupDialog(NDialog) {
|
|||||||
|
|
||||||
return NDialog
|
return NDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setupNaiveDiscreteApi() {
|
||||||
|
const appStore = useAppStore()
|
||||||
|
const configProviderProps = computed(() => ({
|
||||||
|
theme: appStore.isDark ? NaiveUI.darkTheme : undefined,
|
||||||
|
themeOverrides,
|
||||||
|
}))
|
||||||
|
const { message, dialog, notification, loadingBar } = NaiveUI.createDiscreteApi(
|
||||||
|
['message', 'dialog', 'notification', 'loadingBar'],
|
||||||
|
{ configProviderProps }
|
||||||
|
)
|
||||||
|
|
||||||
|
window.$loadingBar = loadingBar
|
||||||
|
window.$notification = notification
|
||||||
|
window.$message = setupMessage(message)
|
||||||
|
window.$dialog = setupDialog(dialog)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user