-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
59 lines (54 loc) · 1.86 KB
/
utils.js
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
// 通用的错误提示函数
function showToast(message, type = 'info') {
const toast = document.createElement('div');
toast.className = 'toast toast-top toast-center z-50';
toast.style.position = 'fixed';
toast.innerHTML = `
<div class="alert alert-${type}">
<span>${message}</span>
</div>
`;
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 3000);
}
// 通用的加载提示
function showLoading(message = '加载中...') {
const loading = document.createElement('div');
loading.className = 'fixed inset-0 flex items-center justify-center bg-base-200/50 z-50';
loading.id = 'loadingOverlay';
loading.innerHTML = `
<div class="loading loading-spinner loading-lg text-primary"></div>
<span class="ml-4">${message}</span>
`;
document.body.appendChild(loading);
}
function hideLoading() {
const loading = document.getElementById('loadingOverlay');
if (loading) {
loading.remove();
}
}
// 通用的确认对话框
function showConfirm(message, onConfirm, onCancel) {
const dialog = document.createElement('div');
dialog.className = 'modal modal-open';
dialog.innerHTML = `
<div class="modal-box">
<h3 class="font-bold text-lg">确认</h3>
<p class="py-4">${message}</p>
<div class="modal-action">
<button class="btn btn-primary" id="confirmBtn">确定</button>
<button class="btn" id="cancelBtn">取消</button>
</div>
</div>
`;
document.body.appendChild(dialog);
document.getElementById('confirmBtn').onclick = () => {
dialog.remove();
onConfirm?.();
};
document.getElementById('cancelBtn').onclick = () => {
dialog.remove();
onCancel?.();
};
}