使用El-MessageBox,创建一个弹窗 点击“确定”、“取消”,实现消息提醒,点击“确定”后并执行API调用的公共方法

一、使用El-MessageBox。

二、创建一个方法 function MessageBoxConfirm(message:string,title:string)

message 是消息内容,title是标题,

/**
* message 消息内容
* title  标题
* 点击“确定” 返回true,点击“取消”返回false;
*/
function MessageBoxConfirm(message: string, title: string) {  
    return new Promise((resolve, reject) => {  
        ElMessageBox.confirm(  
            message,  
            title,  
            {  
                confirmButtonText: '确定',  
                cancelButtonText: '取消',  
                type: "warning",  
                dangerouslyUseHTMLString: true,  
                customClass: 'messageBox',   
                center: true,  
            }  
        ).then(() => {  
            // 点击“确定”时解析 Promise 并返回 true  
            resolve(true);  
        }).catch(() => {  
            // 点击“取消”时拒绝 Promise, 并返回 false  
            reject(false); 
        });  
    })  
}

方法使用:

MessageBoxConfirm('你确定要执行此操作吗?', '确认提示')  
    .then(confirmed => {  
        if (confirmed) {  
            // 用户点击了“确定”  
            console.log('用户已确认');  
        }  
    })  
    .catch(cancelled => {  
        // 用户点击了“取消”,
        console.log('用户已取消');  
    });

实现MessageBox弹出的弹窗点击下一页更新弹窗内容,可以使用自定义的MessageBox。下面是一个简单的例子: ```c++ #include <windows.h> int customMessageBox(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType) { int result = 0; int currentPage = 1; const int totalPages = 3; const WCHAR* page1Text = L"这是第一页内容"; const WCHAR* page2Text = L"这是第二页内容"; const WCHAR* page3Text = L"这是第三页内容"; WCHAR buttonText[16] = L"下一页"; while (currentPage <= totalPages) { WCHAR messageText[256]; swprintf_s(messageText, L"第%d页:%s", currentPage, currentPage == 1 ? page1Text : currentPage == 2 ? page2Text : page3Text); if (currentPage < totalPages) { int result = MessageBox(hWnd, messageText, lpCaption, uType | MB_OKCANCEL); if (result == IDCANCEL) return result; } else { wcscpy_s(buttonText, L"完成"); int result = MessageBox(hWnd, messageText, lpCaption, uType | MB_OK); if (result == IDOK) return result; } ++currentPage; if (currentPage <= totalPages) { int buttonResult = MessageBox(hWnd, L"", lpCaption, uType | MB_OKCANCEL); if (buttonResult == IDCANCEL) return buttonResult; } } return result; } ``` 这个自定义的MessageBox可以显示多页内容,且在最后一页显示“完成”按钮。每当点击“下一页”按钮时,它会弹出一个空的MessageBox,等待用户点击OK,然后更新内容显示下一页。当显示最后一页时,它会显示“完成”按钮,等待用户点击OK。 你可以根据自己的需要修改这个例子来实现你的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值