feat: 更新 utils4u 依赖至 2.18.1,并添加 PrimeVue 服务的全局类型声明
This commit is contained in:
@ -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<import('primevue/dynamicdialogoptions').DynamicDialogInstance>;
|
||||
return inject<DialogRef>('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 };
|
||||
|
Reference in New Issue
Block a user