mirror of
https://gitee.com/dromara/go-view.git
synced 2026-04-23 00:00:12 +08:00
feat: 完成dialog动态封装
This commit is contained in:
+61
-19
@@ -1,43 +1,85 @@
|
||||
import { icon } from '@/plugins'
|
||||
import { DialogEnum } from '@/enums/pluginEnum'
|
||||
import { dialogIconSize, maskClosable } from '@/settings/designSetting'
|
||||
import { DialogReactive } from 'naive-ui'
|
||||
const { InformationCircleIcon } = icon.ionicons5
|
||||
import { renderIcon } from '@/utils'
|
||||
|
||||
/**
|
||||
* * render 弹出确认框
|
||||
* * render 对话框
|
||||
* @param { Function } dialogFn dialog函数,暂时必须从页面传过来
|
||||
* @param { Object} params 配置参数
|
||||
*/
|
||||
export const goDialog = (
|
||||
dialogFn: Function,
|
||||
export const goDialog = (
|
||||
params: {
|
||||
// 基本
|
||||
type: 'delete'
|
||||
type: DialogEnum
|
||||
message?: string
|
||||
// 回调
|
||||
onPositiveCallback?: Function
|
||||
onNegativeCallback?: Function
|
||||
// 渲染函数
|
||||
render?: boolean
|
||||
contentFn?: Function
|
||||
actionFn?: Function
|
||||
}
|
||||
// 异步
|
||||
promise?: boolean
|
||||
promiseResCallback?: Function
|
||||
promiseRejCallback?: Function
|
||||
},
|
||||
dialogFn?: Function
|
||||
) => {
|
||||
const { type, message, onPositiveCallback, onNegativeCallback } = params
|
||||
const tip = {
|
||||
delete: '是否删除此数据'
|
||||
const {
|
||||
type,
|
||||
message,
|
||||
onPositiveCallback,
|
||||
onNegativeCallback,
|
||||
promise,
|
||||
promiseResCallback,
|
||||
promiseRejCallback
|
||||
} = params
|
||||
|
||||
const typeObj = {
|
||||
// 自定义
|
||||
delete: {
|
||||
fn: dialogFn || window['$dialog'].warning,
|
||||
message: message || '是否删除此数据?'
|
||||
},
|
||||
// 原有
|
||||
warning: {
|
||||
fn: window['$dialog'].warning,
|
||||
message: message || '是否执行此操作?'
|
||||
},
|
||||
error: {
|
||||
fn: window['$dialog'].error,
|
||||
message: message || '是否执行此操作?'
|
||||
},
|
||||
success: {
|
||||
fn: window['$dialog'].success,
|
||||
message: message || '是否执行此操作?'
|
||||
}
|
||||
}
|
||||
const instance = dialogFn({
|
||||
|
||||
const d: DialogReactive = (typeObj as any)[type]['fn']({
|
||||
title: '提示',
|
||||
icon: renderIcon(InformationCircleIcon, { size: dialogIconSize }),
|
||||
content: message || tip[type] || '',
|
||||
content: (typeObj as any)[type]['message'],
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
maskClosable: maskClosable,
|
||||
onPositiveClick: () => {
|
||||
onPositiveCallback && onPositiveCallback(instance)
|
||||
onPositiveClick: async () => {
|
||||
// 执行异步
|
||||
if (promise && onPositiveCallback) {
|
||||
d.loading = true
|
||||
try {
|
||||
const res = await onPositiveCallback()
|
||||
promiseResCallback && promiseResCallback(res)
|
||||
} catch (err) {
|
||||
promiseRejCallback && promiseRejCallback(err)
|
||||
}
|
||||
d.loading = false
|
||||
return
|
||||
}
|
||||
onPositiveCallback && onPositiveCallback(d)
|
||||
},
|
||||
onNegativeClick: () => {
|
||||
onNegativeCallback && onNegativeCallback(instance)
|
||||
onNegativeClick: async () => {
|
||||
onNegativeCallback && onNegativeCallback(d)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user