diff --git a/src/components/primevue/fns.tsx b/src/components/primevue/fns.tsx
index 3198388..1e7a21d 100644
--- a/src/components/primevue/fns.tsx
+++ b/src/components/primevue/fns.tsx
@@ -1,4 +1,3 @@
-import { ConfirmationService, DialogService, ToastService, useDialogRef } from '@/plugins/primevue';
import dialogContent from './__dialog-content.vue';
const dynamicComponent = defineComponent({
@@ -9,7 +8,7 @@ const dynamicComponent = defineComponent({
},
},
setup(props, ctx) {
- const dialogRef = useDialogRef();
+ const dialogRef = usePrimevueDialogRef();
return () => (
diff --git a/src/plugins/primevue.ts b/src/plugins/primevue.ts
index 90a147e..9ebd106 100644
--- a/src/plugins/primevue.ts
+++ b/src/plugins/primevue.ts
@@ -8,81 +8,7 @@ import Aura from '@primevue/themes/aura';
import zhCN from 'primelocale/zh-CN.json';
import PrimeVue from 'primevue/config';
-// ========================================================================
-// ========================== ConfirmationService =========================
-// ========================================================================
-// @ts-expect-error - Ignore missing types
-import ConfirmationEventBus from 'primevue/confirmationeventbus';
-
-import type { ConfirmationOptions } from 'primevue/confirmationoptions';
-interface HConfirmationOptions extends ConfirmationOptions {
- rejectProps?: import('primevue/button').ButtonProps;
- acceptProps?: import('primevue/button').ButtonProps;
-}
-const ConfirmationService = {
- require: (options: HConfirmationOptions) => {
- ConfirmationEventBus.emit('confirm', options);
- },
- close: () => {
- ConfirmationEventBus.emit('close');
- },
-};
-
-// ========================================================================
-// ============================= ToastService =============================
-// ========================================================================
-// @ts-expect-error - Ignore missing types
-import ToastEventBus from 'primevue/toasteventbus';
-
-import type { ToastServiceMethods } from 'primevue/toastservice';
-// https://github.com/primefaces/primevue/blob/61929eae7526015af0362fc5889f2af7527403d1/packages/primevue/src/toastservice/ToastService.js
-const ToastService: ToastServiceMethods = {
- add: (message) => {
- ToastEventBus.emit('add', message);
- },
- remove: (message) => {
- ToastEventBus.emit('remove', message);
- },
- removeGroup: (group) => {
- ToastEventBus.emit('remove-group', group);
- },
- removeAllGroups: () => {
- ToastEventBus.emit('remove-all-groups');
- },
-};
-
-// ========================================================================
-// ============================= DialogService ============================
-// ========================================================================
-// @ts-expect-error - Ignore missing types
-import DynamicDialogEventBus from 'primevue/dynamicdialogeventbus';
-
-import type { DialogServiceMethods } from 'primevue/dialogservice';
-
-// https://github.com/primefaces/primevue/blob/18367429f624285ff32d0ef775c1825a43a02fb1/packages/primevue/src/dialogservice/DialogService.js#L7
-const DialogService: DialogServiceMethods = {
- open: (content, options) => {
- const instance = {
- content: content && markRaw(content),
- options: options || {},
- data: options && options.data,
- close: (params: unknown) => {
- DynamicDialogEventBus.emit('close', { instance, params });
- },
- };
-
- DynamicDialogEventBus.emit('open', { instance });
-
- return instance;
- },
-};
-
-function useDialogRef() {
- type DialogRef = ComputedRef;
- return inject('dialogRef');
-}
-
-function setupPrimeVue(app: import('vue').App) {
+export function setupPrimeVue(app: import('vue').App) {
app.use(PrimeVue, {
locale: {
...zhCN['zh-CN'],
@@ -98,5 +24,3 @@ function setupPrimeVue(app: import('vue').App) {
},
});
}
-
-export { ConfirmationService, DialogService, setupPrimeVue, ToastService, useDialogRef };
diff --git a/src/plugins/router.ts b/src/plugins/router.ts
index fdd36aa..974b7de 100644
--- a/src/plugins/router.ts
+++ b/src/plugins/router.ts
@@ -1,5 +1,4 @@
import { DataLoaderPlugin } from 'unplugin-vue-router/data-loaders';
-import { createLogGuard, createProgressGuard, createStackGuard } from 'utils4u/vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import { handleHotUpdate, routes } from 'vue-router/auto-routes';
@@ -17,15 +16,16 @@ if ($__DEV__) Object.assign(window, { router });
function setupRouter(app: import('vue').App) {
app
- // Register the plugin before the router
- .use(DataLoaderPlugin, { router })
- // adding the router will trigger the initial navigation
- .use(router);
-
+ .use(DataLoaderPlugin, { router }) // Register the plugin before the router
+ .use(router); // adding the router will trigger the initial navigation
+}
+export { router, setupRouter };
+// ========================================================================
+// =========================== Router Guards ==============================
+// ========================================================================
+{
// 警告:路由守卫的创建顺序会影响执行流程,请勿调整
- createProgressGuard(router);
+ createNProgressGuard(router);
createLogGuard(router);
Object.assign(window, { stack: createStackGuard(router) });
}
-
-export { router, setupRouter };
diff --git a/vite.config.plugins.ts b/vite.config.plugins.ts
index 641faa2..312f540 100644
--- a/vite.config.plugins.ts
+++ b/vite.config.plugins.ts
@@ -53,7 +53,7 @@ export function Plugins() {
'@vueuse/core',
VueRouterAutoImports,
unheadVueComposablesImports,
- createUtils4uAutoImports(),
+ createUtils4uAutoImports(['primevue']),
'vue-i18n',
],
}),