/**
* 数字人直播系统 - Dialog 对话框组件
*/
(function() {
'use strict';
const Dialog = {
show(options = {}) {
const { title = '提示', content = '', confirmText = '确定', cancelText = '取消', showCancel = true, onConfirm, onCancel } = options;
const overlay = document.createElement('div');
overlay.className = 'dh-dialog-overlay';
overlay.style.cssText = `
position: fixed; top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.4);
display: flex; align-items: center; justify-content: center;
z-index: 99995;
animation: dhFadeIn 0.2s ease;
`;
overlay.innerHTML = `
${title}
${content}
${showCancel ? `` : ''}
`;
document.body.appendChild(overlay);
overlay.querySelector('.dh-dialog-confirm').onclick = () => {
overlay.remove();
if (onConfirm) onConfirm();
};
if (showCancel) {
overlay.querySelector('.dh-dialog-cancel').onclick = () => {
overlay.remove();
if (onCancel) onCancel();
};
}
overlay.addEventListener('click', (e) => {
if (e.target === overlay) { overlay.remove(); if (onCancel) onCancel(); }
});
},
confirm(message, options = {}) {
return new Promise((resolve) => {
this.show({
title: options.title || '确认',
content: message,
confirmText: options.confirmText || '确定',
cancelText: options.cancelText || '取消',
onConfirm: () => resolve(true),
onCancel: () => resolve(false)
});
});
},
alert(message, options = {}) {
return new Promise((resolve) => {
this.show({
title: options.title || '提示',
content: message,
confirmText: '确定',
showCancel: false,
onConfirm: () => resolve(true)
});
});
}
};
// 动画样式
const style = document.createElement('style');
style.textContent = `
@keyframes dhFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dhScaleIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
`;
document.head.appendChild(style);
window.DigitalHumanDialog = Dialog;
console.log('[数字人直播] Dialog组件已加载');
})();