AdaKing88
2023-08-23 9cad48db6c56c3e2796a9d6da881817ef13b6eca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Element Plus
import { ElMessageBox } from 'element-plus';
// 命名空间
const globalFunction = {}
/**
 * @param { message } String 内容,可选 
 * @param { title } String 标题,可选 
 * @param { thenFun } Function 回调函数,可选 
 * @description 确认弹窗
 */
globalFunction.deleteConfirm = (params) => {
    ElMessageBox.confirm(params.message || '确认删除当前数据吗?删除后将无法恢复', params.title || '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        showClose: false,            // 取消右上角关闭按钮
        closeOnClickModal: false,    // 取消点击遮罩关闭 MessageBox
        closeOnPressEscape: false,   // 取消按下ESC键关闭MessageBox
        type: 'warning',
        beforeClose: (action, instance, done) => {
            globalFunction.deleteConfirmObj = { instance, done };
            if(action === "confirm") {
                // 按钮加载状态
                globalFunction.confirmButtonLoading(true);
                // 判断thenFun存在并且是Function类型,是则自动执行函数
                params.thenFun && Object.prototype.toString.call(params.thenFun) === "[object Function]" && params.thenFun();
            }else{
                globalFunction.deleteConfirmClose();
            }
        }
    }).then(()=>{}).catch(()=>{})
 
}
/**
 * @param { bool } Boolean 加载状态,可选 
 * @description 弹窗确认按钮加载状态
 */
globalFunction.confirmButtonLoading = (bool) => {
    globalFunction.deleteConfirmObj.instance.confirmButtonLoading = bool;
}
 /**
  * @param {*} params 
  */
globalFunction.deleteConfirmClose = () => {
    globalFunction.deleteConfirmObj.done();
    globalFunction.deleteConfirmObj = null;
}
/** 函数2 */
globalFunction.message = (params) => {
    console.log(params)
}
 
export default {
    install(app){
        app.config.globalProperties["deleteConfirm"] = globalFunction.deleteConfirm;
        app.config.globalProperties["deleteConfirmClose"] = globalFunction.deleteConfirmClose;
        app.config.globalProperties["confirmButtonLoading"] = globalFunction.confirmButtonLoading;
        app.config.globalProperties["message"] = globalFunction.message;
    }
}