build / build-and-test (push) Successful in 3m19s
1) 工作台速录 - 手机尾号输入框下方新增 3×4 触摸小键盘(1-9、0、⌫、✓),点 ✓ 直接提交;实体键盘仍可输入 - 抽屉顶部新增秒级时钟(HH:MM:SS),位于日期标题上方 2) 日历格子 - 移除排单缩略信息(客户名/套餐色签/“x/y 单”小字) - 保留左侧打手颜色竖条,中间改为大字「待完成 / 总数」,例如 1/2 = 还剩 1 单、共 2 单 - 大屏格子按此前约定保持原样 3) 客户停用 / 恢复 / 彻底删除 - customers 新增 archived 列(0/1);停用后默认从客户列表、日历、待办、大屏、到期提醒、徽标中隐藏,订阅与打卡记录原样保留 - 恢复后立即回到日历;列表右上角可切换「显示已停用」,已停用行带标记 - 彻底删除为二次确认操作,依赖外键级联清理订阅、打卡、暂停、追加记录与加急标记 - 停用/恢复/删除都会写入操作日志 4) 按钮收纳 - 任务行只露出「完成」,跳过 / 加急(取消加急)/ 追加收进「⋯」菜单;已完成行只露「撤销打卡」等,点空白处自动收起 - 加急、跳过等原有能力不变,仅入口折叠 5) 顶栏 - 在「今日到期」「3 天内到期」右侧新增「7 天内到期」徽标,固定统计未来 7 天 6) 视觉 - 移除管理端背景的横线装饰,改为纯底色;大屏网格背景保留 数据库兼容性: - 只新增 customers.archived 一列,老库启动时自动 ALTER,可重复迁移;原有表结构与接口不变 测试: - 新增单测 TestCustomerArchiveFilters:停用后日历/到期/徽标/搜索/列表全部过滤、恢复回日历、彻底删除级联清理订阅与打卡 - 功能验证 20 项(键盘、格子计数、折叠菜单、7 天徽标、时钟、停用/恢复/删除、背景)全部通过 - 原有 119 项验收回归全绿;go vet / go test ./... 通过;版本号 1.5.0
179 lines
6.8 KiB
JavaScript
179 lines
6.8 KiB
JavaScript
/* 代打台 · 交互增强(无框架,全部渐进增强) */
|
|
(function () {
|
|
'use strict';
|
|
|
|
/* 提示条自动淡出 */
|
|
document.querySelectorAll('[data-flash]').forEach(function (el) {
|
|
setTimeout(function () {
|
|
el.classList.add('hide');
|
|
setTimeout(function () { el.remove(); }, 450);
|
|
}, 4200);
|
|
});
|
|
|
|
/* 按 / 聚焦搜索框 */
|
|
document.addEventListener('keydown', function (e) {
|
|
if (e.key !== '/' || e.metaKey || e.ctrlKey || e.altKey) return;
|
|
var tag = (document.activeElement && document.activeElement.tagName) || '';
|
|
if (/^(INPUT|TEXTAREA|SELECT)$/.test(tag)) return;
|
|
var s = document.querySelector('[data-search]');
|
|
if (s) { e.preventDefault(); s.focus(); s.select(); }
|
|
});
|
|
|
|
/* 危险操作确认 */
|
|
document.querySelectorAll('form[data-confirm]').forEach(function (f) {
|
|
f.addEventListener('submit', function (e) {
|
|
if (!window.confirm(f.getAttribute('data-confirm'))) e.preventDefault();
|
|
});
|
|
});
|
|
|
|
/* 追加时长面板:点日历挑终止日 + 实时反算 */
|
|
function parseDay(s) { return new Date(s + 'T00:00:00'); }
|
|
function diffDays(a, b) { return Math.round((b.getTime() - a.getTime()) / 86400000); }
|
|
|
|
document.querySelectorAll('form[data-extend]').forEach(function (form) {
|
|
var base = parseDay(form.getAttribute('data-base'));
|
|
var today = parseDay(form.getAttribute('data-today'));
|
|
var input = form.querySelector('[data-end-input]');
|
|
var endLabel = form.querySelector('[data-end-label]');
|
|
var daysEl = form.querySelector('[data-days]');
|
|
var remainEl = form.querySelector('[data-remain]');
|
|
var buttons = form.querySelectorAll('.miniday');
|
|
if (!input) return;
|
|
|
|
function paint(date) {
|
|
if (!date) return;
|
|
var d = parseDay(date);
|
|
input.value = date;
|
|
if (endLabel) endLabel.textContent = date;
|
|
var days = diffDays(base, d) + 1;
|
|
if (daysEl) daysEl.textContent = days > 0 ? days : 0;
|
|
var remain = diffDays(today, d) + 1;
|
|
if (remainEl) remainEl.textContent = remain > 0 ? remain : 0;
|
|
buttons.forEach(function (b) {
|
|
b.classList.toggle('picked', b.getAttribute('data-date') === date);
|
|
});
|
|
}
|
|
|
|
buttons.forEach(function (b) {
|
|
b.addEventListener('click', function () {
|
|
if (!b.disabled) paint(b.getAttribute('data-date'));
|
|
});
|
|
});
|
|
input.addEventListener('change', function () { paint(input.value); });
|
|
if (input.value) paint(input.value);
|
|
});
|
|
|
|
/* 新订阅表单:按套餐类型切换「天数 / 次数 / 终止日」 */
|
|
document.querySelectorAll('form[data-sub-form]').forEach(function (form) {
|
|
var sel = form.querySelector('[data-pkg-select]');
|
|
var daysWrap = form.querySelector('[data-days-wrap]');
|
|
var countWrap = form.querySelector('[data-count-wrap]');
|
|
var endWrap = form.querySelector('[data-end-wrap]');
|
|
if (!sel) return;
|
|
|
|
function sync() {
|
|
var opt = sel.options[sel.selectedIndex];
|
|
var unit = opt && opt.getAttribute('data-unit');
|
|
var amount = opt && opt.getAttribute('data-amount');
|
|
if (unit === 'count') {
|
|
if (daysWrap) daysWrap.hidden = true;
|
|
if (countWrap) { countWrap.hidden = false; if (amount) countWrap.querySelector('input').value = amount; }
|
|
if (endWrap) endWrap.hidden = true;
|
|
} else if (unit === 'day') {
|
|
if (daysWrap) { daysWrap.hidden = false; if (amount) daysWrap.querySelector('input').value = amount; }
|
|
if (countWrap) countWrap.hidden = true;
|
|
if (endWrap) endWrap.hidden = false;
|
|
} else {
|
|
if (daysWrap) daysWrap.hidden = false;
|
|
if (countWrap) countWrap.hidden = true;
|
|
if (endWrap) endWrap.hidden = true;
|
|
}
|
|
}
|
|
sel.addEventListener('change', sync);
|
|
sync();
|
|
});
|
|
|
|
/* 套餐表单:切换默认量单位文案 */
|
|
document.querySelectorAll('form[data-package-form]').forEach(function (form) {
|
|
var label = form.querySelector('[data-unit-label]');
|
|
var radios = form.querySelectorAll('input[name="unit"]');
|
|
function sync() {
|
|
var v = 'day';
|
|
radios.forEach(function (r) { if (r.checked) v = r.value; });
|
|
if (label) label.textContent = v === 'count' ? '次' : '天';
|
|
}
|
|
radios.forEach(function (r) { r.addEventListener('change', sync); });
|
|
sync();
|
|
});
|
|
})();
|
|
|
|
/* ---------- 亮色 / 暗色切换 ----------
|
|
偏好写 cookie,服务端首屏直接带 data-theme,不闪。
|
|
没有 cookie 时跟随系统(由 CSS 的 prefers-color-scheme 决定)。 */
|
|
(function () {
|
|
'use strict';
|
|
var KEY = 'daili_theme';
|
|
var btns = document.querySelectorAll('[data-theme-toggle]');
|
|
if (!btns.length) return;
|
|
|
|
function effective() {
|
|
var attr = document.documentElement.getAttribute('data-theme');
|
|
if (attr === 'light' || attr === 'dark') return attr;
|
|
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
}
|
|
|
|
Array.prototype.forEach.call(btns, function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
var next = effective() === 'dark' ? 'light' : 'dark';
|
|
document.documentElement.setAttribute('data-theme', next);
|
|
document.cookie = KEY + '=' + next + '; path=/; max-age=31536000; SameSite=Lax';
|
|
});
|
|
});
|
|
})();
|
|
|
|
/* ---------- 触摸小键盘 + 抽屉时钟 + 更多菜单 ---------- */
|
|
(function () {
|
|
'use strict';
|
|
|
|
/* 时钟:精确到秒 */
|
|
var clocks = document.querySelectorAll('[data-clock]');
|
|
function tick() {
|
|
var d = new Date();
|
|
var pad = function (n) { return n < 10 ? '0' + n : '' + n; };
|
|
var t = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
|
|
Array.prototype.forEach.call(clocks, function (el) { el.textContent = t; });
|
|
}
|
|
if (clocks.length) { tick(); setInterval(tick, 1000); }
|
|
|
|
/* 小键盘:输入手机尾号 */
|
|
Array.prototype.forEach.call(document.querySelectorAll('[data-keypad]'), function (pad) {
|
|
var form = pad.closest('form');
|
|
if (!form) return;
|
|
var input = form.querySelector('input[name="tail"]');
|
|
if (!input) return;
|
|
pad.addEventListener('click', function (e) {
|
|
var btn = e.target.closest('button[data-key]');
|
|
if (!btn) return;
|
|
var key = btn.getAttribute('data-key');
|
|
if (key === 'back') {
|
|
input.value = input.value.slice(0, -1);
|
|
} else if (key === 'ok') {
|
|
if (input.value) {
|
|
if (form.requestSubmit) { form.requestSubmit(); } else { form.submit(); }
|
|
}
|
|
} else {
|
|
if (input.value.length < 8) { input.value += key; }
|
|
}
|
|
input.focus();
|
|
});
|
|
});
|
|
|
|
/* 更多菜单:点开一个时收起其它,点空白处关闭 */
|
|
document.addEventListener('click', function (e) {
|
|
var opened = document.querySelectorAll('.more-actions[open]');
|
|
Array.prototype.forEach.call(opened, function (d) {
|
|
if (!d.contains(e.target)) { d.removeAttribute('open'); }
|
|
});
|
|
});
|
|
})();
|