68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
let hintModalResolve = null;
|
|
|
|
const hintModal = document.querySelector("#hint-modal")
|
|
// const hintContainer = document.querySelector('#hint-container');
|
|
const hintContent = document.querySelector('#hint-content');
|
|
const hintTitle = document.querySelector('#hint-title');
|
|
|
|
const cancelHintBtn = document.querySelector('#cancel-hint-btn');
|
|
const confirmHintBtn = document.querySelector('#confirm-hint-btn');
|
|
|
|
|
|
// 显示提示弹窗并返回Promise
|
|
async function showHintModal(
|
|
message, title , confirmBtnText, cancelBtnText, showConfirm = true,
|
|
showCancel = true
|
|
) {
|
|
// 设置内容
|
|
hintContent.innerHTML = message;
|
|
|
|
// 显示弹窗
|
|
hintModal.style.display = 'flex';
|
|
|
|
// 设置标题
|
|
if(!title) {
|
|
title = await getPopupText("hintDefaultTitleText")
|
|
}
|
|
if(!confirmBtnText && showConfirm) {
|
|
confirmBtnText = await getPopupText("hintDefaultConfirmText")
|
|
}
|
|
if(!cancelBtnText && showCancel) {
|
|
cancelBtnText = await getPopupText("hintDefaultCancelText")
|
|
}
|
|
|
|
hintTitle.innerHTML = title;
|
|
|
|
// 设置确认按钮文字
|
|
confirmHintBtn.innerHTML = confirmBtnText ? confirmBtnText : '';
|
|
confirmHintBtn.style.display = showConfirm ? 'flex' : 'none';
|
|
|
|
// 设置取消按钮文字
|
|
cancelHintBtn.innerHTML = cancelBtnText ? cancelBtnText : '';
|
|
cancelHintBtn.style.display = showCancel ? 'flex' : 'none';
|
|
|
|
// 返回Promise
|
|
return new Promise((resolve) => {
|
|
hintModalResolve = resolve;
|
|
});
|
|
}
|
|
|
|
confirmHintBtn?.addEventListener('click', () => {
|
|
if (hintModal) hintModal.style.display = 'none';
|
|
|
|
if (hintModalResolve) {
|
|
hintModalResolve(true);
|
|
hintModalResolve = null;
|
|
}
|
|
});
|
|
|
|
cancelHintBtn?.addEventListener('click', () => {
|
|
if (hintModal) hintModal.style.display = 'none';
|
|
|
|
if (hintModalResolve) {
|
|
hintModalResolve(false);
|
|
hintModalResolve = null;
|
|
}
|
|
});
|
|
|