naive.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import type { App } from 'vue'
  2. import * as NaiveUI from 'naive-ui'
  3. import { computed } from 'vue'
  4. import { useDesignSettingStore } from '@/store/modules/designSetting'
  5. import { store } from '@/store'
  6. import { lighten } from '@/utils/index'
  7. import { MessageProviderProps } from 'naive-ui'
  8. // NaiveUI 全局方法注册
  9. const designStore = useDesignSettingStore(store)
  10. const configProviderPropsRef = computed(() => ({
  11. theme: designStore.darkTheme ? NaiveUI.darkTheme : undefined,
  12. themeOverrides: {
  13. common: {
  14. primaryColor: designStore.appTheme,
  15. primaryColorHover: lighten(designStore.appTheme, 6),
  16. primaryColorPressed: lighten(designStore.appTheme, 6)
  17. },
  18. LoadingBar: {
  19. colorLoading: designStore.appTheme
  20. }
  21. }
  22. }))
  23. const messageProviderPropsRef = computed(
  24. () =>
  25. ({
  26. closable: false,
  27. containerStyle: 'undefined',
  28. duration: 3,
  29. keepAliveOnHover: false,
  30. max: 1,
  31. placement: 'top',
  32. to: 'body'
  33. } as MessageProviderProps)
  34. )
  35. // const { message, dialog, notification, loadingBar } = NaiveUI.createDiscreteApi(
  36. // ['message', 'dialog', 'notification', 'loadingBar'],
  37. // {
  38. // configProviderProps: configProviderPropsRef
  39. // }
  40. // )
  41. // const w = window as any
  42. // window['$message'] = message
  43. // window['$dialog'] = dialog
  44. // window['$notification'] = notification
  45. // window['$loading'] = loadingBar
  46. const naive = NaiveUI.create({
  47. components: [
  48. NaiveUI.NMessageProvider,
  49. NaiveUI.NDialogProvider,
  50. NaiveUI.NConfigProvider,
  51. NaiveUI.NInput,
  52. NaiveUI.NButton,
  53. NaiveUI.NForm,
  54. NaiveUI.NFormItem,
  55. NaiveUI.NCheckboxGroup,
  56. NaiveUI.NCheckbox,
  57. NaiveUI.NIcon,
  58. NaiveUI.NLayout,
  59. NaiveUI.NLayoutHeader,
  60. NaiveUI.NLayoutContent,
  61. NaiveUI.NLayoutFooter,
  62. NaiveUI.NLayoutSider,
  63. NaiveUI.NMenu,
  64. NaiveUI.NBreadcrumb,
  65. NaiveUI.NBreadcrumbItem,
  66. NaiveUI.NDropdown,
  67. NaiveUI.NSpace,
  68. NaiveUI.NTooltip,
  69. NaiveUI.NAvatar,
  70. NaiveUI.NTabs,
  71. NaiveUI.NTabPane,
  72. NaiveUI.NCard,
  73. NaiveUI.NRow,
  74. NaiveUI.NCol,
  75. NaiveUI.NDrawer,
  76. NaiveUI.NDrawerContent,
  77. NaiveUI.NDivider,
  78. NaiveUI.NSwitch,
  79. NaiveUI.NBadge,
  80. NaiveUI.NAlert,
  81. NaiveUI.NElement,
  82. NaiveUI.NTag,
  83. NaiveUI.NNotificationProvider,
  84. NaiveUI.NProgress,
  85. NaiveUI.NDatePicker,
  86. NaiveUI.NGrid,
  87. NaiveUI.NGridItem,
  88. NaiveUI.NList,
  89. NaiveUI.NListItem,
  90. NaiveUI.NThing,
  91. NaiveUI.NDataTable,
  92. NaiveUI.NPopover,
  93. NaiveUI.NPagination,
  94. NaiveUI.NSelect,
  95. NaiveUI.NRadioGroup,
  96. NaiveUI.NRadio,
  97. NaiveUI.NSteps,
  98. NaiveUI.NStep,
  99. NaiveUI.NInputGroup,
  100. NaiveUI.NResult,
  101. NaiveUI.NDescriptions,
  102. NaiveUI.NDescriptionsItem,
  103. NaiveUI.NTable,
  104. NaiveUI.NInputNumber,
  105. NaiveUI.NLoadingBarProvider,
  106. NaiveUI.NModal,
  107. NaiveUI.NUpload,
  108. NaiveUI.NTree,
  109. NaiveUI.NSpin,
  110. NaiveUI.NTimePicker,
  111. NaiveUI.NBackTop,
  112. NaiveUI.NSkeleton
  113. ]
  114. })
  115. const { message, dialog, notification, loadingBar } = NaiveUI.createDiscreteApi(
  116. ['message', 'dialog', 'notification', 'loadingBar'],
  117. {
  118. configProviderProps: configProviderPropsRef
  119. // messageProviderProps: messageProviderPropsRef
  120. }
  121. )
  122. ;(window as any)['$message'] = message
  123. // const w = window as any
  124. // window['$message'] = message
  125. // window['$dialog'] = dialog
  126. // window['$notification'] = notification
  127. // window['$loading'] = loadingBar
  128. export function setupNaive(app: App<Element>) {
  129. app.use(naive)
  130. }