fix: 修改全局 dialog 提示

This commit is contained in:
奔跑的面条 2022-05-02 17:33:51 +08:00
parent 621a302451
commit 8ca08a5600

View File

@ -27,7 +27,7 @@ export const loadingError = () => {
/** /**
* * render * * render
* @param { Object} params * @param { Object} params , https://www.naiveui.com/zh-CN/light/components/dialog
* @param { Function } dialogFn * @param { Function } dialogFn
* ``` * ```
* demo * demo
@ -40,6 +40,8 @@ export const goDialog = (
params: { params: {
// 基本 // 基本
type?: DialogEnum type?: DialogEnum
// 标题
title?: string | (() => any)
// 提示 // 提示
message?: string message?: string
// 取消提示词 // 取消提示词
@ -64,6 +66,7 @@ export const goDialog = (
) => { ) => {
const { const {
type, type,
title,
message, message,
negativeText, negativeText,
negativeButtonProps, negativeButtonProps,
@ -98,33 +101,33 @@ export const goDialog = (
} }
} }
const d: DialogReactive = typeObj[type || DialogEnum.warning]['fn']({ const dialog: DialogReactive = typeObj[type || DialogEnum.warning]['fn']({
title: '提示', // 导入其余 NaiveUI 支持参数
...params,
title: title || '提示',
icon: renderIcon(InformationCircleIcon, { size: dialogIconSize }), icon: renderIcon(InformationCircleIcon, { size: dialogIconSize }),
content: typeObj[type || DialogEnum.warning]['message'], content: typeObj[type || DialogEnum.warning]['message'],
positiveText: positiveText || '确定', positiveText: positiveText || '确定',
positiveButtonProps: positiveButtonProps,
negativeText: negativeText || '取消', negativeText: negativeText || '取消',
negativeButtonProps: negativeButtonProps,
// 是否通过遮罩关闭 // 是否通过遮罩关闭
maskClosable: isMaskClosable || maskClosable, maskClosable: isMaskClosable || maskClosable,
onPositiveClick: async () => { onPositiveClick: async () => {
// 执行异步 // 执行异步
if (promise && onPositiveCallback) { if (promise && onPositiveCallback) {
d.loading = true dialog.loading = true
try { try {
const res = await onPositiveCallback() const res = await onPositiveCallback()
promiseResCallback && promiseResCallback(res) promiseResCallback && promiseResCallback(res)
} catch (err) { } catch (err) {
promiseRejCallback && promiseRejCallback(err) promiseRejCallback && promiseRejCallback(err)
} }
d.loading = false dialog.loading = false
return return
} }
onPositiveCallback && onPositiveCallback(d) onPositiveCallback && onPositiveCallback(dialog)
}, },
onNegativeClick: async () => { onNegativeClick: async () => {
onNegativeCallback && onNegativeCallback(d) onNegativeCallback && onNegativeCallback(dialog)
} }
}) })
} }