Skip to content

Commit

Permalink
feat: config global loading and useLoading default value is false
Browse files Browse the repository at this point in the history
  • Loading branch information
flingyp committed Jun 30, 2023
1 parent 3b9013e commit 5bfd2d3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/components/common/SingleApp.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script setup lang="ts">
import { darkTheme, zhCN, dateZhCN } from 'naive-ui'
import { useVAdmireConfigStore } from '~/store'
import BaseSpin from '~/components/common/BaseSpin.vue'
defineOptions({
name: 'SingleApp',
})
const { naiveThemeOverrides, themeMode } = storeToRefs(useVAdmireConfigStore())
const { isLoading, loadingText } = inject('loading') as { isLoading: boolean, loadingText: string }
</script>

<template>
Expand All @@ -22,7 +24,12 @@ const { naiveThemeOverrides, themeMode } = storeToRefs(useVAdmireConfigStore())
<NNotificationProvider placement="bottom-right">
<NDialogProvider>
<NMessageProvider>
<slot />
<BaseSpin
:is-loading="isLoading"
:loading-text="loadingText"
>
<slot />
</BaseSpin>
</NMessageProvider>
</NDialogProvider>
</NNotificationProvider>
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useLoading/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Can configure the loading property of the BaseSpin component or the Button component to implement the Loading effect
* @returns
*/
export const useLoading = () => {
const isLoading = ref(false)
export const useLoading = (defaultValue = false) => {
const isLoading = ref(defaultValue)

const setLoading = async (value: boolean) => {
isLoading.value = value
Expand Down
2 changes: 2 additions & 0 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { usePinia } from './pinia'
import { useVueRouter } from './vue-router'
import { useI18n } from './i18n'
import { useClipboard } from './clipboard'
import { useAppProvide } from './provide'

export default async (app: App) => {
useVueRouter(app)
usePinia(app)
useI18n(app)
useClipboard(app)
useAppProvide(app)
}
14 changes: 14 additions & 0 deletions src/modules/provide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App } from 'vue'

/**
* Config app provide global property
* @param app
*/
export const useAppProvide = (app: App) => {
const { isLoading, setLoading } = useLoading(false)
app.provide('loading', {
isLoading,
setLoading,
loadingText: '加载中...',
})
}

0 comments on commit 5bfd2d3

Please sign in to comment.