08-12-周三_14-20-35
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/* ==================== Shared Utilities ==================== */
|
||||
|
||||
/* URL parameter helper */
|
||||
function getUrlParam(name) {
|
||||
const url = new URL(window.location.href);
|
||||
return url.searchParams.get(name);
|
||||
}
|
||||
|
||||
/* Toast notification */
|
||||
function showToast(msg, type) {
|
||||
type = type || 'info';
|
||||
var icons = { success: '✅', error: '❌', info: 'ℹ️' };
|
||||
var container = document.getElementById('toastContainer');
|
||||
if (!container) { container = document.createElement('div'); container.id = 'toastContainer'; container.className = 'toast-container'; document.body.appendChild(container); }
|
||||
var t = document.createElement('div');
|
||||
t.className = 'toast toast-' + type;
|
||||
t.innerHTML = '<span>' + (icons[type] || '') + '</span> ' + msg;
|
||||
container.appendChild(t);
|
||||
setTimeout(function () { t.remove(); }, 3000);
|
||||
}
|
||||
|
||||
/* Render shared navbar */
|
||||
function renderNavbar() {
|
||||
var nav = document.getElementById('navbarActions');
|
||||
if (!nav) return;
|
||||
nav.innerHTML =
|
||||
'<a href="index.html" class="btn btn-ghost">🏠 首页</a>' +
|
||||
'<a href="admin.html" class="btn btn-outline btn-sm">⚙️ 后台管理</a>' +
|
||||
'<a href="register.html" class="btn btn-ghost btn-sm">✍️ 注册</a>' +
|
||||
'<a href="login.html" class="btn btn-primary btn-sm">🔑 登录</a>';
|
||||
}
|
||||
|
||||
/* Category badge helper */
|
||||
function categoryBadge(cat) {
|
||||
if (!cat) return '';
|
||||
return '<span class="note-category" style="background:' + cat.color + '15;color:' + cat.color + '">' + cat.icon + ' ' + cat.name + '</span>';
|
||||
}
|
||||
|
||||
/* Empty state helper */
|
||||
function emptyState(icon, text) {
|
||||
return '<div class="empty-state"><div class="empty-icon">' + icon + '</div><p>' + text + '</p></div>';
|
||||
}
|
||||
|
||||
/* Modal helpers */
|
||||
function renderModal(title, content) {
|
||||
var div = document.createElement('div');
|
||||
div.className = 'modal-overlay';
|
||||
div.onclick = function (e) { if (e.target === div) closeModal(); };
|
||||
div.innerHTML = '<div class="form-modal" onclick="event.stopPropagation()"><h3>' + title + '</h3>' + content + '</div>';
|
||||
document.body.appendChild(div);
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
var o = document.querySelector('.modal-overlay');
|
||||
if (o) o.remove();
|
||||
}
|
||||
|
||||
/* ==================== Bootstrap on every page ==================== */
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
renderNavbar();
|
||||
});
|
||||
Reference in New Issue
Block a user