79 lines
3.2 KiB
JavaScript
79 lines
3.2 KiB
JavaScript
/* 霜曜 / 黑金主题:仅记忆主题偏好,不写任何业务数据。 */
|
|
(function (global) {
|
|
var KEY = "jinniu-theme";
|
|
|
|
function read() {
|
|
try {
|
|
return localStorage.getItem(KEY) === "night" ? "night" : "day";
|
|
} catch (err) {
|
|
return "day";
|
|
}
|
|
}
|
|
|
|
function syncButtons(theme) {
|
|
document.querySelectorAll("[data-theme-set]").forEach(function (btn) {
|
|
var on = btn.getAttribute("data-theme-set") === theme;
|
|
btn.classList.toggle("is-active", on);
|
|
btn.setAttribute("aria-pressed", on ? "true" : "false");
|
|
});
|
|
}
|
|
|
|
function apply(theme, animate) {
|
|
var next = theme === "night" ? "night" : "day";
|
|
var root = document.documentElement;
|
|
root.classList.add("v-fusion");
|
|
if (animate) {
|
|
root.setAttribute("data-theme-anim", "");
|
|
window.setTimeout(function () {
|
|
root.removeAttribute("data-theme-anim");
|
|
}, 220);
|
|
}
|
|
root.setAttribute("data-theme", next);
|
|
if (document.body) document.body.setAttribute("data-theme", next);
|
|
syncButtons(next);
|
|
}
|
|
|
|
function set(theme) {
|
|
var next = theme === "night" ? "night" : "day";
|
|
try {
|
|
localStorage.setItem(KEY, next);
|
|
} catch (err) {
|
|
/* 无本地存储时仍切换当次会话 */
|
|
}
|
|
apply(next, true);
|
|
}
|
|
|
|
var incoming = new URLSearchParams(location.search).get("theme");
|
|
if (incoming === "day" || incoming === "night") {
|
|
try { localStorage.setItem(KEY, incoming); } catch (e) {}
|
|
}
|
|
apply(incoming === "day" || incoming === "night" ? incoming : read(), false);
|
|
document.addEventListener("click", function(event) {
|
|
var link = event.target.closest("[data-return-portal]");
|
|
if (link) { var url = new URL(link.href); url.searchParams.set("theme", read()); link.href = url.toString(); }
|
|
});
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
if (!global.PORTAL_HOME) return;
|
|
var checkbox = document.querySelector('[name="createUser"]');
|
|
if (checkbox) { checkbox.checked = false; checkbox.disabled = true; checkbox.parentElement.classList.add("portal-native-account"); }
|
|
var login = document.querySelector('[name="loginName"]');
|
|
if (login) { login.required = false; login.closest(".field").classList.add("portal-native-account"); }
|
|
var reset = document.querySelector('#btn-reset-pwd');
|
|
if (reset) reset.classList.add("portal-native-account");
|
|
var sub = document.querySelector('#companyDialog .modal-sub');
|
|
if (sub) sub.textContent = "选择已获财务公司端权限的员工。保存后生效;移除员工会收回其对本公司的操作权限,历史记录保留。";
|
|
var hint = document.querySelector('#companyForm .hint');
|
|
if (hint) hint.textContent = "可选择多名出纳,也可暂不分配。员工可操作的公司由这里的分配决定。";
|
|
var submit = document.querySelector('#companyForm button[type="submit"]');
|
|
if (submit) submit.textContent = "保存公司与分配";
|
|
});
|
|
document.addEventListener("click", function (event) {
|
|
var btn = event.target.closest("[data-theme-set]");
|
|
if (!btn) return;
|
|
event.preventDefault();
|
|
set(btn.getAttribute("data-theme-set"));
|
|
});
|
|
|
|
global.JinniuTheme = { apply: apply, set: set, read: read };
|
|
})(window);
|