2637 lines
106 KiB
HTML
2637 lines
106 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>标签管理</title>
|
||
<style>
|
||
:root{
|
||
--bg:#f4f5f7; --card:#ffffff; --line:#e3e6ec; --line-strong:#cfd4de;
|
||
--text:#1b1f27; --muted:#7a8291; --accent:#2563eb; --accent-soft:#eef3ff;
|
||
--danger:#dc2626; --radius:12px;
|
||
}
|
||
*{box-sizing:border-box;}
|
||
html,body{height:100%;}
|
||
body{
|
||
margin:0;background:var(--bg);color:var(--text);
|
||
font-family:"Microsoft YaHei","PingFang SC","Helvetica Neue",Arial,sans-serif;
|
||
font-size:14px;-webkit-font-smoothing:antialiased;
|
||
}
|
||
.app{display:flex;flex-direction:row;height:100vh;}
|
||
/* 选中文字统一高亮,方便确认"可复制" */
|
||
::selection{background:#cfe0ff;color:inherit;}
|
||
|
||
/* ---------- 左侧目录 ---------- */
|
||
.side{
|
||
--nav-w:330px;
|
||
flex:0 0 auto;position:relative;display:flex;background:var(--card);
|
||
border-right:1px solid var(--line);
|
||
transition:width .2s cubic-bezier(.4,0,.2,1);
|
||
}
|
||
.app.nav-collapsed .side{width:42px;}
|
||
/* 拖动调宽时不要动画,否则跟手会飘 */
|
||
.app.nav-resizing .side,
|
||
.app.nav-resizing .side-body{transition:none;}
|
||
.side-rail{
|
||
flex:0 0 42px;width:42px;display:flex;flex-direction:column;align-items:center;
|
||
padding:10px 0 8px;overflow:hidden;
|
||
}
|
||
.side-vtext{
|
||
writing-mode:vertical-rl;margin-top:10px;font-size:11.5px;letter-spacing:3px;
|
||
color:#b3bac6;opacity:0;transition:opacity .12s;
|
||
}
|
||
.app.nav-collapsed .side-vtext{opacity:1;transition:opacity .16s .06s;}
|
||
.side-body{
|
||
flex:0 0 var(--nav-w);width:var(--nav-w);display:flex;flex-direction:column;min-width:0;
|
||
overflow:hidden;opacity:1;transition:opacity .12s .05s;
|
||
}
|
||
.app.nav-collapsed .side-body{
|
||
flex-basis:0;width:0;opacity:0;pointer-events:none;transition:opacity .08s;
|
||
}
|
||
/* 右边线上的拖拽条:整条高度都能拖 */
|
||
.side-resizer{
|
||
position:absolute;top:0;bottom:0;right:-3px;width:8px;z-index:9;
|
||
cursor:col-resize;background:transparent;
|
||
}
|
||
.side-resizer::after{
|
||
content:"";position:absolute;top:0;bottom:0;left:3px;width:2px;
|
||
background:transparent;transition:background .12s;
|
||
}
|
||
.side-resizer:hover::after{background:#c7d7f7;}
|
||
.app.nav-resizing .side-resizer::after{background:var(--accent);}
|
||
.app.nav-collapsed .side-resizer{cursor:default;}
|
||
/* 折叠按钮:贴在目录右边线的正中 */
|
||
.side-fold{
|
||
position:absolute;top:50%;right:-12px;transform:translateY(-50%);z-index:11;
|
||
width:22px;height:52px;padding:0;border-radius:8px;font-family:inherit;
|
||
border:1px solid var(--line-strong);background:#fff;color:#6b7382;
|
||
font-size:14px;line-height:1;cursor:pointer;
|
||
display:inline-flex;align-items:center;justify-content:center;
|
||
box-shadow:0 1px 4px rgba(20,30,60,.10);
|
||
transition:background .14s,border-color .14s,color .14s;
|
||
}
|
||
.side-fold:hover{border-color:var(--accent);color:var(--accent);background:var(--accent-soft);}
|
||
.side-count{font-size:11.5px;color:#b3bac6;}
|
||
.side-list{
|
||
flex:1 1 auto;min-height:0;display:flex;flex-direction:column;
|
||
overflow-y:auto;overflow-x:hidden;padding:10px 8px 0;
|
||
}
|
||
.side-list::-webkit-scrollbar{width:7px;}
|
||
.side-list::-webkit-scrollbar-thumb{background:#dfe3ea;border-radius:4px;}
|
||
.side-item{
|
||
flex:0 0 auto;display:flex;align-items:center;gap:8px;width:100%;
|
||
padding:8px 42px 8px 10px;margin-bottom:3px;border-radius:8px;border:1px solid transparent;
|
||
background:transparent;color:#4b5462;font-size:13.5px;font-family:inherit;
|
||
text-align:left;cursor:pointer;white-space:nowrap;overflow:hidden;
|
||
transition:background .12s,color .12s,border-color .12s;
|
||
}
|
||
.side-item:hover{background:#f2f4f8;}
|
||
.side-item.active{
|
||
background:var(--accent-soft);border-color:#d5e2fb;color:var(--accent);font-weight:600;
|
||
}
|
||
.side-idx{flex:0 0 auto;min-width:15px;font-size:11.5px;color:#b0b8c5;text-align:right;}
|
||
.side-item.active .side-idx{color:#7ba3f0;}
|
||
.side-name{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;}
|
||
/* 目录项上的「上移 / 下移」,复用的就是「标签顺序」那套排序接口 */
|
||
.side-row{position:relative;flex:0 0 auto;}
|
||
.side-ops{
|
||
position:absolute;right:5px;top:50%;transform:translateY(-50%);
|
||
display:flex;gap:2px;opacity:0;pointer-events:none;transition:opacity .12s;
|
||
}
|
||
.side-row:hover .side-ops{opacity:1;pointer-events:auto;}
|
||
.side-op{
|
||
width:17px;height:17px;padding:0;border:none;border-radius:4px;background:rgba(255,255,255,.92);
|
||
color:#7c8598;font-size:11px;line-height:1;font-family:inherit;cursor:pointer;
|
||
display:inline-flex;align-items:center;justify-content:center;
|
||
}
|
||
.side-op:hover{background:#e4ecfb;color:var(--accent);}
|
||
.side-op:disabled{opacity:.35;cursor:default;background:rgba(255,255,255,.6);}
|
||
/* ---------- 目录树:层级缩进 + 加减把手 ---------- */
|
||
.side-row{
|
||
position:relative;flex:0 0 auto;display:flex;align-items:center;
|
||
padding-left:2px;border-radius:8px;
|
||
}
|
||
.side-row .side-item{flex:1 1 auto;min-width:0;width:auto;padding-left:5px;gap:6px;}
|
||
.side-guide{flex:0 0 9px;align-self:stretch;position:relative;}
|
||
.side-guide::before{
|
||
content:"";position:absolute;left:6px;top:0;bottom:0;border-left:1px dashed #e1e5ee;
|
||
}
|
||
.side-tog{
|
||
flex:0 0 15px;width:15px;height:15px;margin:0 1px 0 0;padding:0;
|
||
border:1px solid #d7dce6;border-radius:4px;background:#fff;color:#8d97a8;
|
||
font-size:11px;line-height:1;font-family:inherit;cursor:pointer;
|
||
display:inline-flex;align-items:center;justify-content:center;
|
||
}
|
||
.side-tog:hover{border-color:var(--accent);color:var(--accent);background:var(--accent-soft);}
|
||
.side-tog.leaf{border-color:transparent;background:transparent;cursor:default;pointer-events:none;}
|
||
.side-kids{
|
||
flex:0 0 auto;min-width:16px;font-size:10.5px;color:#a8b0bf;text-align:right;
|
||
font-variant-numeric:tabular-nums;
|
||
}
|
||
.side-row.k-project .side-name{font-weight:600;color:#233043;}
|
||
.side-row.k-cost .side-name,
|
||
.side-row.k-install .side-name{font-weight:600;color:#2b3a4f;}
|
||
.side-row.k-sectional .side-name,
|
||
.side-row.k-unit .side-name{font-weight:500;}
|
||
.side-row.k-record .side-name{font-weight:400;color:#4a5568;}
|
||
.side-row.k-record .side-idx{opacity:.65;}
|
||
.side-item.record{color:#4a5568;}
|
||
.side-item.record.active{background:var(--accent-soft);color:var(--accent);}
|
||
.side-foot{
|
||
flex:0 0 auto;position:sticky;bottom:0;margin-top:auto;
|
||
display:flex;gap:8px;padding:8px 4px 12px;background:var(--card);
|
||
border-top:1px solid #f0f2f6;
|
||
}
|
||
.side-add{
|
||
flex:1 1 auto;height:32px;padding:0 8px;border-radius:8px;
|
||
border:1px dashed var(--line-strong);background:var(--card);color:var(--accent);
|
||
font-size:13px;font-family:inherit;cursor:pointer;white-space:nowrap;
|
||
transition:border-color .15s,background .15s;
|
||
}
|
||
.side-add:hover{border-color:var(--accent);background:var(--accent-soft);}
|
||
.side-set{
|
||
flex:0 0 auto;height:32px;padding:0 11px;border-radius:8px;
|
||
border:1px solid var(--line-strong);background:var(--card);color:#4b5462;
|
||
font-size:13px;font-family:inherit;cursor:pointer;white-space:nowrap;
|
||
transition:border-color .15s,color .15s,background .15s;
|
||
}
|
||
.side-set:hover{border-color:var(--accent);color:var(--accent);background:var(--accent-soft);}
|
||
|
||
/* ---------- 内容区 ---------- */
|
||
.content{flex:1 1 auto;min-width:0;overflow:auto;padding:18px 20px 30px;}
|
||
.wrap{max-width:none;margin:0;display:flex;flex-direction:column;gap:14px;}
|
||
|
||
.card{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:15px 17px 16px;}
|
||
.card-head{display:flex;align-items:center;gap:10px;margin-bottom:13px;}
|
||
.card-head h2{
|
||
margin:0;font-size:14px;font-weight:600;letter-spacing:.2px;
|
||
padding-left:9px;border-left:3px solid var(--accent);
|
||
}
|
||
.card-head .hint{font-size:12px;color:var(--muted);}
|
||
.card-head .spacer{margin-left:auto;}
|
||
|
||
.input-row{display:flex;gap:10px;align-items:center;flex-wrap:wrap;}
|
||
.input-row input{
|
||
flex:1 1 150px;min-width:0;height:36px;padding:0 12px;
|
||
border:1px solid var(--line-strong);border-radius:8px;background:#fff;
|
||
color:var(--text);font-size:14px;font-family:inherit;outline:none;
|
||
transition:border-color .15s,box-shadow .15s;
|
||
}
|
||
.input-row input::placeholder{color:#a7aebb;}
|
||
.input-row input:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(37,99,235,.12);}
|
||
.input-row select{
|
||
flex:0 0 auto;height:36px;padding:0 8px;border:1px solid var(--line-strong);
|
||
border-radius:8px;background:#fff;color:var(--text);font-size:13.5px;
|
||
font-family:inherit;outline:none;cursor:pointer;
|
||
}
|
||
.input-row select:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(37,99,235,.12);}
|
||
|
||
.btn{
|
||
flex:0 0 auto;height:36px;padding:0 15px;border-radius:8px;
|
||
border:1px solid transparent;font-size:13.5px;font-family:inherit;cursor:pointer;
|
||
display:inline-flex;align-items:center;justify-content:center;white-space:nowrap;
|
||
transition:background .15s,border-color .15s,color .15s,opacity .15s;
|
||
}
|
||
.btn:disabled{opacity:.55;cursor:not-allowed;}
|
||
.btn.primary{background:var(--accent);color:#fff;}
|
||
.btn.primary:hover:not(:disabled){background:#1d4fd0;}
|
||
.btn.ghost{background:#fff;border-color:var(--line-strong);color:#3c4453;}
|
||
.btn.ghost:hover{background:#f2f4f8;}
|
||
.btn.small{height:30px;padding:0 11px;font-size:12.5px;}
|
||
|
||
/* ---------- 后缀分组 ---------- */
|
||
/* ---------- 后缀设置(Excel 表格) ---------- */
|
||
.xls-wrap{margin-top:13px;border:1px solid var(--line-strong);border-radius:10px;overflow-x:auto;background:#fff;}
|
||
.xls{width:100%;min-width:920px;border-collapse:separate;border-spacing:0;table-layout:auto;font-size:13px;}
|
||
.xls.auto-w{width:auto;max-width:100%;min-width:0;}
|
||
.xls thead th{
|
||
height:34px;padding:0 10px;text-align:center;font-weight:600;font-size:12.5px;
|
||
color:#3a4459;background:#f2f5fa;border-bottom:1px solid #e2e8f2;white-space:nowrap;
|
||
}
|
||
.xls th + th,.xls td + td{border-left:1px solid #eef1f7;}
|
||
.xls tbody td{
|
||
height:40px;padding:5px 10px;vertical-align:middle;
|
||
border-bottom:1px solid #eef1f7;background:#fff;
|
||
}
|
||
.xls tbody tr:last-child td{border-bottom:none;}
|
||
.xls tbody tr.srow:hover td{background:#fafcff;}
|
||
.xls tr.r-hidden{display:none;}
|
||
.xls .c-idx{width:58px;}
|
||
.xls .c-name{width:100px;}
|
||
.xls .c-files{width:auto;}
|
||
.xls .c-op{width:1px;white-space:nowrap;}
|
||
/* 窄屏:压缩次要列,操作列保证不换行 */
|
||
@media (max-width:1000px){
|
||
.xls .c-op{width:1px;}
|
||
}
|
||
.ridx{font-size:12.5px;color:#7b8496;}
|
||
.xname{font-size:13.5px;font-weight:600;color:#2b3446;word-break:break-all;}
|
||
.xname.pending{font-weight:500;color:#98a1b1;font-style:italic;}
|
||
.ridx.pending{color:#c3cad6;}
|
||
.xls tr.r-pending{background:#fbfcfe;}
|
||
.xls tr.r-pending .c-name{padding-left:2px;}
|
||
.fcells{display:flex;flex-wrap:nowrap;gap:5px;overflow:hidden;align-items:center;}
|
||
.ifmore{
|
||
display:none;flex:0 0 auto;height:26px;padding:0 8px;box-sizing:border-box;
|
||
border:1px solid #dfe6f2;border-radius:6px;background:#eef2f9;color:#5b6474;
|
||
font-size:12px;font-family:inherit;cursor:pointer;line-height:24px;letter-spacing:1px;
|
||
}
|
||
.ifmore:hover{background:#e2e9f5;border-color:#c6d3e8;}
|
||
.modal.files-modal{max-width:640px;}
|
||
.files-list{max-height:52vh;overflow:auto;border:1px solid var(--line);border-radius:8px;}
|
||
.fitem{display:flex;align-items:center;gap:10px;padding:7px 10px;font-size:12.5px;}
|
||
.fitem + .fitem{border-top:1px solid #f0f3f8;}
|
||
.fitem:hover{background:#f7f9fd;}
|
||
.fitem-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#2b3446;}
|
||
.fitem-size{flex:0 0 74px;text-align:right;color:#8b93a3;font-size:11.5px;}
|
||
.fitem-time{flex:0 0 132px;text-align:right;color:#9aa2b1;font-size:11.5px;}
|
||
.fitem-del{
|
||
flex:0 0 18px;width:18px;height:18px;padding:0;border:none;border-radius:4px;
|
||
background:transparent;color:#b6bdc9;font-size:12px;line-height:1;cursor:pointer;font-family:inherit;
|
||
}
|
||
.fitem-del:hover{background:#fde8e8;color:#d33;}
|
||
.fitem-empty{padding:18px;text-align:center;color:#a7aebb;font-size:12.5px;}
|
||
.ifchip{
|
||
display:inline-flex;align-items:center;gap:4px;flex:0 0 auto;
|
||
width:96px;height:26px;box-sizing:border-box;padding:0 3px 0 8px;
|
||
border:1px solid #dfe6f2;border-radius:6px;background:#f7f9fd;color:#3b465c;font-size:12px;
|
||
overflow:hidden;
|
||
}
|
||
.ifchip-name{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
|
||
.ifchip-del{
|
||
width:16px;height:16px;flex:0 0 16px;padding:0;border:none;border-radius:4px;background:transparent;
|
||
color:#a9b1c0;font-size:12px;line-height:1;cursor:pointer;font-family:inherit;
|
||
}
|
||
.ifchip-del:hover{background:#fde8e8;color:#d33;}
|
||
.fempty{font-size:12px;color:#b6bdc9;}
|
||
.op-cell{display:flex;flex-wrap:nowrap;gap:10px;align-items:center;justify-content:flex-start;}
|
||
.btn.xs{height:26px;padding:0 8px;font-size:12px;border-radius:6px;}
|
||
.btn.icon{
|
||
width:26px;height:26px;padding:0;display:inline-flex;align-items:center;justify-content:center;
|
||
font-size:13px;line-height:1;
|
||
}
|
||
.btn.danger{background:#fff5f5;border-color:#f3b4b4;color:var(--danger);}
|
||
.btn.danger:hover:not(:disabled){background:#ffe3e3;border-color:#e88b8b;}
|
||
.xls tr.grow td{background:#f7f9fd;padding:0;}
|
||
.xls tr.grow:hover td{background:#f1f5fc;}
|
||
.gbar{display:flex;align-items:center;gap:8px;padding:6px 10px;}
|
||
.gbar .spacer{margin-left:auto;}
|
||
.ghandle{
|
||
width:20px;height:20px;flex:0 0 auto;padding:0;border:1px solid var(--line-strong);background:#fff;
|
||
border-radius:5px;color:#3c4453;font-size:13px;line-height:1;cursor:pointer;
|
||
display:inline-flex;align-items:center;justify-content:center;font-family:inherit;
|
||
}
|
||
.ghandle:hover{border-color:var(--accent);color:var(--accent);}
|
||
.gname{font-size:13px;font-weight:600;color:#39404e;}
|
||
.gname[data-rename-group]{
|
||
cursor:pointer;padding:1px 6px;border-radius:5px;border:1px dashed transparent;
|
||
}
|
||
.gname[data-rename-group]:hover{background:#e8eefb;border-color:#b7cdf0;color:var(--accent);}
|
||
.gname[data-rename-group]:hover{color:var(--accent);}
|
||
.gcount{font-size:11.5px;color:var(--muted);}
|
||
.gcode{
|
||
flex:0 0 auto;min-width:26px;padding:0 6px;border-radius:6px;text-align:center;
|
||
background:#e8eefb;color:#3b5ea8;font-size:11.5px;font-weight:600;line-height:20px;
|
||
font-variant-numeric:tabular-nums;
|
||
}
|
||
.gdel{
|
||
width:20px;height:20px;padding:0;border:none;border-radius:5px;background:transparent;
|
||
color:#b3bac6;cursor:pointer;font-size:12px;line-height:1;font-family:inherit;
|
||
}
|
||
.gdel:hover{background:#fdecec;color:var(--danger);}
|
||
.xls tr.gempty td{height:34px;color:#aab2c0;font-size:12px;background:#fcfdff;}
|
||
|
||
/* ---------- 表格 ---------- */
|
||
/* 顶部工具区:5px 留白 → 小号「添加列」 → 蓝色分隔线 → 5px → 表格 */
|
||
.content.sheet-mode{padding-top:5px;}
|
||
.wrap.sheet-view{gap:0;}
|
||
.sheet-bar{display:flex;align-items:center;gap:12px;margin:0 0 6px;min-height:30px;}
|
||
.sheet-bar .spacer{margin-left:auto;}
|
||
.sheet-rule{height:2px;border-radius:1px;background:var(--accent);margin:0 0 5px;}
|
||
.save-flag{font-size:12px;color:#15803d;opacity:0;transition:opacity .25s;}
|
||
.save-flag.show{opacity:1;}
|
||
.sheet-wrap{
|
||
background:#fff;border:1px solid var(--line);border-radius:12px;
|
||
overflow:auto;max-height:calc(100vh - 132px);
|
||
}
|
||
table.sheet{border-collapse:separate;border-spacing:0;width:100%;font-size:13.5px;}
|
||
table.sheet.auto-w{width:auto;max-width:100%;table-layout:fixed;}
|
||
table.sheet.auto-w th,table.sheet.auto-w td{overflow:hidden;}
|
||
table.sheet.auto-w th:last-child,
|
||
table.sheet.auto-w td:last-child{padding-right:14px;}
|
||
table.sheet th, table.sheet td{
|
||
padding:0 10px;height:38px;white-space:nowrap;
|
||
border-bottom:1px solid #eef0f4;border-right:1px solid #f2f4f8;background:#fff;
|
||
}
|
||
table.sheet tbody td{text-align:left;}
|
||
table.sheet thead th{
|
||
position:sticky;top:0;z-index:3;height:40px;background:#f7f8fb;color:#4b5462;
|
||
font-weight:600;text-align:center;
|
||
}
|
||
.th-plain{display:block;overflow:hidden;text-overflow:ellipsis;}
|
||
.col-resizer{
|
||
position:absolute;top:0;right:0;width:6px;height:100%;cursor:col-resize;
|
||
z-index:7;background:transparent;
|
||
}
|
||
.col-resizer:hover,.col-resizer.dragging{background:rgba(37,99,235,.35);}
|
||
table.sheet td.c-action .btn{flex:0 0 auto;white-space:nowrap;}
|
||
table.sheet td.c-action .btn.on{
|
||
background:var(--accent) !important;border-color:var(--accent) !important;color:#fff !important;
|
||
}
|
||
table.sheet td.c-action .btn.on:hover{background:#1d4fd0 !important;}
|
||
table.sheet tbody tr.row-editing td.c-cell{background:#f2f7ff;}
|
||
table.sheet tbody tr.row-editing td.c-cell:hover{background:#e6efff;}
|
||
.efield input:disabled{background:#f4f6fa;color:#9aa2b1;cursor:not-allowed;}
|
||
table.sheet thead th[data-col]{cursor:pointer;}
|
||
table.sheet thead th[data-col]:hover{background:#eef3fb;}
|
||
table.sheet th.c-index, table.sheet td.c-index{
|
||
position:sticky;left:0;z-index:2;width:54px;min-width:54px;max-width:54px;
|
||
text-align:center;color:var(--muted);box-shadow:1px 0 0 #eceff4;
|
||
}
|
||
table.sheet td.c-index{background:#fbfcfe;}
|
||
table.sheet th.c-index{background:#f7f8fb;z-index:6;}
|
||
table.sheet th.c-suffix, table.sheet td.c-suffix{
|
||
position:sticky;left:54px;z-index:2;min-width:190px;max-width:190px;
|
||
overflow:hidden;text-overflow:ellipsis;box-shadow:1px 0 0 #eceff4;
|
||
}
|
||
table.sheet th.c-suffix{background:#f7f8fb;z-index:6;}
|
||
table.sheet td.c-suffix{font-weight:500;}
|
||
table.sheet th.c-anchorline, table.sheet td.c-anchorline{
|
||
width:78px;min-width:78px;max-width:78px;text-align:center;
|
||
}
|
||
table.sheet th.c-anchorline{background:#f7f8fb;}
|
||
table.sheet td.c-anchorline-cell{background:#fbfcfe;}
|
||
.al-dot{
|
||
width:16px;height:16px;border-radius:50%;border:2px solid #c8d2e2;background:#fff;
|
||
cursor:pointer;padding:0;vertical-align:middle;transition:background .15s,border-color .15s;
|
||
}
|
||
.al-dot:hover{border-color:var(--accent);}
|
||
.al-dot.on{background:var(--accent);border-color:var(--accent);box-shadow:inset 0 0 0 3px #fff;}
|
||
table.sheet th.c-action, table.sheet td.c-action{
|
||
width:84px;min-width:84px;max-width:84px;text-align:center;
|
||
}
|
||
table.sheet th.c-action{background:#f7f8fb;}
|
||
table.sheet td.c-action .btn{vertical-align:middle;}
|
||
.cell-text{display:block;line-height:38px;padding:0 10px;overflow:hidden;
|
||
text-overflow:ellipsis;white-space:nowrap;}
|
||
.cell-empty{display:block;line-height:38px;padding:0 10px;color:#c3cad6;}
|
||
.cv-anchor{
|
||
display:inline-block;max-width:46%;overflow:hidden;text-overflow:ellipsis;
|
||
vertical-align:middle;margin-right:6px;padding:0 6px;border-radius:4px;
|
||
background:#eef4ff;color:#3b6bb8;font-size:11.5px;line-height:18px;
|
||
}
|
||
.cv-value{
|
||
display:inline-block;max-width:calc(100% - 60px);overflow:hidden;
|
||
text-overflow:ellipsis;vertical-align:middle;color:#1f2937;
|
||
}
|
||
table.sheet td.c-cell{cursor:pointer;}
|
||
table.sheet td.c-cell:hover{background:var(--accent-soft);}
|
||
|
||
/* ---------- 行编辑弹框 ---------- */
|
||
.modal.edit-modal{max-width:520px;}
|
||
.edit-sub{margin:0 0 12px;font-size:12.5px;color:var(--muted);}
|
||
.edit-fields{max-height:52vh;overflow:auto;padding-right:2px;}
|
||
.efield{display:flex;align-items:center;gap:10px;margin-bottom:9px;}
|
||
.efield-name{
|
||
flex:0 0 104px;font-size:12.5px;color:#4b5462;text-align:right;
|
||
overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
||
}
|
||
.efield input{
|
||
flex:1;height:34px;padding:0 10px;border:1px solid var(--line-strong);border-radius:7px;
|
||
font-size:13px;font-family:inherit;color:var(--text);outline:none;background:#fff;
|
||
}
|
||
.efield input:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(37,99,235,.12);}
|
||
.edit-none{font-size:12.5px;color:#a7aebb;padding:10px 0;}
|
||
table.sheet tbody tr:hover td{background:#fafcff;}
|
||
table.sheet tbody tr:hover td.c-index{background:#f6f8fc;}
|
||
/* 标签页里的分组标题行 */
|
||
table.sheet tr.group-row td{
|
||
height:32px;padding:0 10px;background:#f4f7fb;border-bottom:1px solid #e4eaf3;
|
||
font-weight:600;font-size:12.5px;color:#3a4459;
|
||
}
|
||
table.sheet tbody tr.group-row:hover td{background:#eef3fb;}
|
||
.sg-bar{display:flex;align-items:center;gap:8px;}
|
||
.sg-handle{
|
||
width:18px;height:18px;flex:0 0 auto;border:1px solid var(--line-strong);background:#fff;
|
||
border-radius:4px;color:#3c4453;font-size:13px;line-height:1;cursor:pointer;
|
||
display:inline-flex;align-items:center;justify-content:center;padding:0;font-family:inherit;
|
||
}
|
||
.sg-handle:hover{border-color:var(--accent);color:var(--accent);}
|
||
.sg-count{font-weight:400;font-size:11.5px;color:var(--muted);}
|
||
table.sheet tr.group-empty td{height:34px;color:#a7aebb;font-size:12px;font-style:italic;}
|
||
table.sheet tr.r-hidden{display:none;}
|
||
table.sheet td.c-cell{padding:0;} table.sheet td.c-cell input{
|
||
width:100%;height:38px;padding:0 10px;border:none;background:transparent;
|
||
font:inherit;color:var(--text);outline:none;
|
||
}
|
||
table.sheet td.c-cell input:focus{background:var(--accent-soft);box-shadow:inset 0 0 0 2px rgba(37,99,235,.22);}
|
||
.th-inner{
|
||
display:flex;align-items:center;justify-content:center;gap:7px;
|
||
min-width:90px;width:100%;position:relative;
|
||
}
|
||
.th-inner .th-name{max-width:calc(100% - 26px);overflow:hidden;text-overflow:ellipsis;}
|
||
.col-del{
|
||
width:18px;height:18px;flex:0 0 auto;border:none;border-radius:4px;background:transparent;
|
||
position:absolute;right:2px;top:50%;margin-top:-9px;
|
||
color:#9aa2b1;cursor:pointer;font-size:14px;line-height:1;font-family:inherit;
|
||
opacity:.32;transition:opacity .12s,background .12s,color .12s;
|
||
}
|
||
table.sheet thead th:hover .col-del{opacity:1;}
|
||
.col-del:hover{background:#fdecec;color:var(--danger);}
|
||
.col-del.locked{color:#c6ccd8;}
|
||
.col-del.locked:hover{background:#f1f3f7;color:#8b93a3;}
|
||
.empty-row td{color:var(--muted);text-align:center;height:70px;font-size:13px;}
|
||
|
||
.placeholder{
|
||
display:flex;flex-direction:column;align-items:center;justify-content:center;
|
||
gap:8px;padding:60px 20px;text-align:center;background:var(--card);
|
||
border:1px dashed var(--line-strong);border-radius:var(--radius);color:var(--muted);
|
||
}
|
||
.placeholder strong{color:#4b5462;font-size:15px;font-weight:600;}
|
||
|
||
/* ---------- 弹框 ---------- */
|
||
.mask{position:fixed;inset:0;background:rgba(20,24,32,.38);display:flex;align-items:center;
|
||
justify-content:center;padding:20px;z-index:50;}
|
||
.mask[hidden]{display:none;}
|
||
.modal{width:100%;max-width:400px;background:#fff;border-radius:14px;padding:19px 21px 17px;
|
||
box-shadow:0 18px 48px rgba(16,24,40,.22);}
|
||
.modal h3{margin:0 0 13px;font-size:15px;font-weight:600;}
|
||
.modal input{width:100%;height:38px;padding:0 12px;border:1px solid var(--line-strong);
|
||
border-radius:8px;font-size:14px;font-family:inherit;color:var(--text);outline:none;
|
||
transition:border-color .15s,box-shadow .15s;}
|
||
.modal input:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(37,99,235,.12);}
|
||
.modal-chips{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:11px;}
|
||
.modal-chips[hidden]{display:none;}
|
||
/* 添加列:复选多选 */
|
||
.modal-check{
|
||
max-height:210px;overflow:auto;margin-bottom:10px;padding:8px 10px;
|
||
border:1px solid var(--line-strong);border-radius:8px;background:#fbfcfe;
|
||
}
|
||
.modal-check[hidden]{display:none;}
|
||
.colw-row{display:flex;align-items:center;gap:10px;margin-bottom:10px;}
|
||
.colw-row[hidden]{display:none;}
|
||
.colw-label{flex:0 0 34px;font-size:12.5px;color:#4b5462;text-align:right;}
|
||
.colw-row input{
|
||
flex:1;height:32px;padding:0 10px;border:1px solid var(--line-strong);border-radius:7px;
|
||
font-size:12.5px;font-family:inherit;color:var(--text);outline:none;background:#fff;
|
||
}
|
||
.colw-row input:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(37,99,235,.12);}
|
||
.modal-check .ck{
|
||
display:flex;align-items:center;gap:7px;padding:5px 4px;border-radius:6px;
|
||
font-size:13px;color:var(--text);cursor:pointer;line-height:1.4;
|
||
}
|
||
.modal-check .ck:hover{background:#eef3fb;}
|
||
.modal-check .ck input{
|
||
width:15px;height:15px;margin:0;flex:0 0 auto;cursor:pointer;accent-color:var(--accent);
|
||
}
|
||
.modal-check .ck.value > span{color:#15803d;font-weight:700;}
|
||
.modal-check .ck-vtag{
|
||
font-style:normal;font-size:10.5px;font-weight:600;line-height:1.4;
|
||
padding:0 4px;border-radius:4px;background:#dcfce7;color:#15803d;
|
||
}
|
||
.modal-check .ck-none{font-size:12.5px;color:#a7aebb;padding:6px 4px;}
|
||
.modal-check .ck-bar{
|
||
display:flex;align-items:center;gap:10px;padding:0 4px 6px;border-bottom:1px dashed #e6ebf3;
|
||
margin-bottom:4px;font-size:12px;color:var(--muted);
|
||
}
|
||
.ck-all{
|
||
border:none;background:transparent;color:var(--accent);font-size:12px;font-family:inherit;
|
||
cursor:pointer;padding:0;
|
||
}
|
||
.ck-all:hover{text-decoration:underline;}
|
||
.fchip{
|
||
padding:4px 10px;border:1px solid var(--line-strong);border-radius:14px;background:#fff;
|
||
font-size:12.5px;font-family:inherit;color:#4b5462;cursor:pointer;
|
||
}
|
||
.fchip:hover{border-color:var(--accent);color:var(--accent);background:var(--accent-soft);}
|
||
.modal-err{margin:7px 0 0;min-height:16px;font-size:12px;color:var(--danger);}
|
||
.modal-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:6px;}
|
||
.tab-order-modal{max-width:420px;}
|
||
.to-list{max-height:52vh;overflow:auto;border:1px solid var(--line);border-radius:8px;}
|
||
.to-row{display:flex;align-items:center;gap:8px;padding:7px 10px;font-size:13px;}
|
||
.to-row + .to-row{border-top:1px solid #f0f3f8;}
|
||
.to-idx{flex:0 0 20px;text-align:right;color:#9aa2b1;font-size:12px;}
|
||
.to-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#2b3446;}
|
||
.to-row .btn[disabled]{opacity:.4;cursor:not-allowed;}
|
||
.to-empty{padding:16px;text-align:center;color:#a7aebb;font-size:12.5px;}
|
||
.to-hint{padding:0 2px 9px;color:#8a94a6;font-size:12px;line-height:1.55;}
|
||
.confirm-msg{margin:0 0 4px;font-size:13px;line-height:1.75;color:#4b5462;white-space:pre-line;}
|
||
.btn.danger-strong{background:var(--danger);border-color:var(--danger);color:#fff;}
|
||
.btn.danger-strong:hover:not(:disabled){background:#c81e1e;border-color:#c81e1e;}
|
||
|
||
.toast{
|
||
position:fixed;left:50%;bottom:26px;transform:translate(-50%,14px);
|
||
padding:9px 16px;border-radius:8px;background:#1b1f27;color:#fff;font-size:13px;
|
||
opacity:0;pointer-events:none;transition:opacity .2s,transform .2s;z-index:80;max-width:80vw;
|
||
}
|
||
.toast.show{opacity:1;transform:translate(-50%,0);}
|
||
.toast.err{background:#b91c1c;}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="app" id="app">
|
||
<aside class="side" id="side">
|
||
<div class="side-rail">
|
||
<span class="side-vtext">目录</span>
|
||
</div>
|
||
<div class="side-resizer" id="sideResizer" title="左右拖动调整目录宽度,双击恢复默认"></div>
|
||
<button class="side-fold" id="navHandle" type="button" title="收起目录">‹</button>
|
||
<div class="side-body">
|
||
<div class="side-list" id="tabbar"></div>
|
||
</div>
|
||
</aside>
|
||
<main class="content" id="content"></main>
|
||
</div>
|
||
|
||
<div class="mask" id="mask" hidden>
|
||
<div class="modal">
|
||
<h3 id="modalTitle">新建标签</h3>
|
||
<div class="modal-chips" id="modalChips" hidden></div>
|
||
<div class="modal-check" id="modalCheck" hidden></div>
|
||
<div class="colw-row" id="colwRow" hidden>
|
||
<span class="colw-label">列宽</span>
|
||
<input id="colWidth" maxlength="8" placeholder="例如 200 或 200px,留空自适应" autocomplete="off">
|
||
</div>
|
||
<input id="modalInput" maxlength="30" placeholder="请输入名称" autocomplete="off">
|
||
<p class="modal-err" id="modalErr"></p>
|
||
<div class="modal-actions">
|
||
<button class="btn ghost" id="modalCancel" type="button">取消</button>
|
||
<button class="btn primary" id="modalOk" type="button">确定</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mask" id="editMask" hidden>
|
||
<div class="modal edit-modal">
|
||
<h3 id="editTitle">编辑</h3>
|
||
<div class="edit-fields" id="editFields"></div>
|
||
<p class="modal-err" id="editErr"></p>
|
||
<div class="modal-actions">
|
||
<button class="btn ghost" id="editCancel" type="button">取消</button>
|
||
<button class="btn primary" id="editOk" type="button">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mask" id="colMask" hidden>
|
||
<div class="modal">
|
||
<h3 id="colTitle">列设置</h3>
|
||
<div class="efield"><span class="efield-name">列宽(px)</span>
|
||
<input id="colW" maxlength="8" placeholder="例如 200,留空自适应" autocomplete="off"></div>
|
||
<p class="modal-err" id="colErr"></p>
|
||
<div class="modal-actions">
|
||
<button class="btn ghost" id="colCancel" type="button">取消</button>
|
||
<button class="btn primary" id="colOk" type="button">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mask" id="filesMask" hidden>
|
||
<div class="modal files-modal">
|
||
<h3 id="filesTitle">导入文件</h3>
|
||
<p class="edit-sub" id="filesSub"></p>
|
||
<div class="files-list" id="filesList"></div>
|
||
<div class="modal-actions">
|
||
<button class="btn ghost" id="filesClose" type="button">关闭</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mask" id="tabOrderMask" hidden>
|
||
<div class="modal tab-order-modal">
|
||
<h3>标签顺序</h3>
|
||
<div class="to-list" id="tabOrderList"></div>
|
||
<div class="modal-actions">
|
||
<button class="btn ghost" id="tabOrderClose" type="button">关闭</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mask" id="colOrderMask" hidden>
|
||
<div class="modal tab-order-modal">
|
||
<h3>列排序</h3>
|
||
<div class="to-hint">调整自建列的左右顺序,改完立即生效。序号、后缀、操作、锚定行是固定列,始终在最左边。</div>
|
||
<div class="to-list" id="colOrderList"></div>
|
||
<div class="modal-actions">
|
||
<button class="btn ghost" id="colOrderClose" type="button">关闭</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="mask" id="confirmMask" hidden>
|
||
<div class="modal confirm-modal">
|
||
<h3 id="confirmTitle">确认操作</h3>
|
||
<p class="confirm-msg" id="confirmMsg"></p>
|
||
<div class="modal-actions">
|
||
<button class="btn ghost" id="confirmCancel" type="button">取消</button>
|
||
<button class="btn primary" id="confirmOk" type="button">确定</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="toast" id="toast"></div>
|
||
<input type="file" id="upFile" hidden>
|
||
|
||
<script>
|
||
(function () {
|
||
"use strict";
|
||
|
||
var S = { tabs: [], fields: [], fieldGroups: [], ungrouped: [], groups: [], suffixTotal: 0, activeId: null, sheet: null };
|
||
var M = { mode: null, ctx: {} };
|
||
var busy = false;
|
||
|
||
var el = {
|
||
app: document.getElementById("app"),
|
||
side: document.getElementById("side"),
|
||
navHandle: document.getElementById("navHandle"),
|
||
navCount: document.getElementById("navCount"),
|
||
tabbar: document.getElementById("tabbar"),
|
||
content: document.getElementById("content"),
|
||
mask: document.getElementById("mask"),
|
||
modalTitle: document.getElementById("modalTitle"),
|
||
modalChips: document.getElementById("modalChips"),
|
||
modalCheck: document.getElementById("modalCheck"),
|
||
colwRow: document.getElementById("colwRow"),
|
||
colMask: document.getElementById("colMask"),
|
||
colTitle: document.getElementById("colTitle"),
|
||
colW: document.getElementById("colW"),
|
||
colErr: document.getElementById("colErr"),
|
||
colOk: document.getElementById("colOk"),
|
||
filesMask: document.getElementById("filesMask"),
|
||
filesTitle: document.getElementById("filesTitle"),
|
||
filesSub: document.getElementById("filesSub"),
|
||
filesList: document.getElementById("filesList"),
|
||
filesClose: document.getElementById("filesClose"),
|
||
tabOrderMask: document.getElementById("tabOrderMask"),
|
||
tabOrderList: document.getElementById("tabOrderList"),
|
||
tabOrderClose: document.getElementById("tabOrderClose"),
|
||
colOrderMask: document.getElementById("colOrderMask"),
|
||
colOrderList: document.getElementById("colOrderList"),
|
||
colOrderClose: document.getElementById("colOrderClose"),
|
||
confirmMask: document.getElementById("confirmMask"),
|
||
confirmTitle: document.getElementById("confirmTitle"),
|
||
confirmMsg: document.getElementById("confirmMsg"),
|
||
confirmOk: document.getElementById("confirmOk"),
|
||
confirmCancel: document.getElementById("confirmCancel"),
|
||
colCancel: document.getElementById("colCancel"),
|
||
colWidth: document.getElementById("colWidth"),
|
||
editMask: document.getElementById("editMask"),
|
||
editTitle: document.getElementById("editTitle"),
|
||
editFields: document.getElementById("editFields"),
|
||
editErr: document.getElementById("editErr"),
|
||
editOk: document.getElementById("editOk"),
|
||
editCancel: document.getElementById("editCancel"),
|
||
modalInput: document.getElementById("modalInput"),
|
||
modalErr: document.getElementById("modalErr"),
|
||
modalOk: document.getElementById("modalOk"),
|
||
modalCancel: document.getElementById("modalCancel"),
|
||
toast: document.getElementById("toast"),
|
||
upFile: document.getElementById("upFile")
|
||
};
|
||
|
||
/* ---------------- 工具 ---------------- */
|
||
|
||
function api(path, options) {
|
||
options = options || {};
|
||
var cfg = { method: options.method || "GET", headers: { "Content-Type": "application/json" } };
|
||
if (options.body !== undefined) cfg.body = JSON.stringify(options.body);
|
||
return fetch(path, cfg).then(function (res) {
|
||
return res.json().catch(function () { return {}; }).then(function (data) {
|
||
if (!res.ok) throw new Error(data.error || ("请求失败 (" + res.status + ")"));
|
||
return data;
|
||
});
|
||
});
|
||
}
|
||
|
||
var toastTimer = null;
|
||
function toast(msg, isErr) {
|
||
el.toast.textContent = msg;
|
||
el.toast.className = "toast show" + (isErr ? " err" : "");
|
||
clearTimeout(toastTimer);
|
||
toastTimer = setTimeout(function () { el.toast.className = "toast"; }, 2400);
|
||
}
|
||
|
||
function esc(s) {
|
||
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
|
||
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
|
||
});
|
||
}
|
||
|
||
function findTab(id) {
|
||
for (var i = 0; i < S.tabs.length; i++) if (S.tabs[i].id === id) return S.tabs[i];
|
||
return null;
|
||
}
|
||
|
||
function activeTab() { return findTab(S.activeId); }
|
||
|
||
/* ---------------- 加载 ---------------- */
|
||
|
||
function loadState() {
|
||
return api("/api/state").then(function (d) {
|
||
S.tabs = d.tabs || [];
|
||
S.fields = d.fields || [];
|
||
S.fieldGroups = d.fieldGroups || [];
|
||
S.rows = d.rows || [];
|
||
S.ungrouped = d.ungrouped || [];
|
||
S.groups = d.groups || [];
|
||
S.suffixTotal = d.suffixTotal || 0;
|
||
S.settings = d.settings || {};
|
||
if (!S.activeId || !findTab(S.activeId)) S.activeId = S.tabs.length ? S.tabs[0].id : null;
|
||
renderTabs();
|
||
}).catch(function (err) {
|
||
el.content.classList.remove("sheet-mode");
|
||
el.content.innerHTML = '<div class="wrap"><div class="placeholder"><strong>无法连接后端</strong>' +
|
||
'<span>请先运行 python app.py,再从 http://127.0.0.1:8765 打开本页</span></div></div>';
|
||
});
|
||
}
|
||
|
||
function loadSheet(tabId) {
|
||
return api("/api/tabs/" + tabId + "/sheet").then(function (d) {
|
||
S.sheet = d;
|
||
if (S.activeId === tabId) renderSheet();
|
||
}).catch(function (err) { toast(err.message, true); });
|
||
}
|
||
|
||
function refresh(opts) {
|
||
opts = opts || {};
|
||
var keepTab = S.activeId;
|
||
return loadState().then(function () {
|
||
var t = findTab(keepTab);
|
||
if (!t) { el.content.innerHTML = ""; return; }
|
||
S.activeId = t.id;
|
||
expandPathTo(t.id);
|
||
renderTabs();
|
||
if (t.fixed) { S.sheet = null; renderBasic(); }
|
||
else return loadSheet(t.id);
|
||
}).then(function () {
|
||
if (opts.focus) {
|
||
var target = el.content.querySelector(opts.focus);
|
||
if (target) target.focus();
|
||
}
|
||
});
|
||
}
|
||
|
||
/* ---------------- 目录(左侧) ---------------- */
|
||
|
||
var NAV_KEY = "adminCostNavCollapsed";
|
||
var navTrimTimer = null;
|
||
|
||
function setNavCollapsed(collapsed, persist) {
|
||
el.app.classList.toggle("nav-collapsed", !!collapsed);
|
||
el.navHandle.innerHTML = collapsed ? "›" : "‹";
|
||
el.navHandle.title = collapsed ? "展开目录" : "收起目录";
|
||
if (persist) {
|
||
try { localStorage.setItem(NAV_KEY, collapsed ? "1" : "0"); } catch (e) { /* 隐私模式忽略 */ }
|
||
}
|
||
// 收起/展开只改宽度,不重建内容;等动画结束再校一次文件 chip 的省略
|
||
clearTimeout(navTrimTimer);
|
||
navTrimTimer = setTimeout(function () {
|
||
requestAnimationFrame(trimFileCells);
|
||
}, 240);
|
||
}
|
||
|
||
/* 左右拖动调整目录宽度:拖右边线;双击恢复默认宽度 */
|
||
var NAV_W_KEY = "adminCostNavWidth";
|
||
var NAV_W_DEF = 330, NAV_W_MIN = 220, NAV_W_MAX = 720;
|
||
|
||
function applyNavWidth(px, persist) {
|
||
var max = Math.min(NAV_W_MAX, Math.max(NAV_W_MIN, Math.round(window.innerWidth * 0.62)));
|
||
var w = Math.max(NAV_W_MIN, Math.min(max, Math.round(px)));
|
||
el.side.style.setProperty("--nav-w", w + "px");
|
||
if (persist) {
|
||
try { localStorage.setItem(NAV_W_KEY, String(w)); } catch (e) { /* 忽略 */ }
|
||
}
|
||
return w;
|
||
}
|
||
|
||
(function initNavResize() {
|
||
var rz = document.getElementById("sideResizer");
|
||
if (!rz) return;
|
||
try {
|
||
var saved = parseInt(localStorage.getItem(NAV_W_KEY), 10);
|
||
if (saved > 0) applyNavWidth(saved, false);
|
||
} catch (e) { /* 忽略 */ }
|
||
|
||
var dragging = false;
|
||
rz.addEventListener("mousedown", function (e) {
|
||
if (e.button !== 0) return;
|
||
if (el.app.classList.contains("nav-collapsed")) return;
|
||
e.preventDefault();
|
||
dragging = true;
|
||
el.app.classList.add("nav-resizing");
|
||
document.body.style.userSelect = "none";
|
||
});
|
||
document.addEventListener("mousemove", function (e) {
|
||
if (!dragging) return;
|
||
// --nav-w 是右侧内容区宽度,左侧竖条固定 42px
|
||
applyNavWidth(e.clientX - el.side.getBoundingClientRect().left - 42, false);
|
||
});
|
||
document.addEventListener("mouseup", function () {
|
||
if (!dragging) return;
|
||
dragging = false;
|
||
el.app.classList.remove("nav-resizing");
|
||
document.body.style.userSelect = "";
|
||
var w = parseFloat(getComputedStyle(el.side).getPropertyValue("--nav-w"));
|
||
applyNavWidth(w, true);
|
||
requestAnimationFrame(trimFileCells);
|
||
});
|
||
rz.addEventListener("dblclick", function () {
|
||
applyNavWidth(NAV_W_DEF, true);
|
||
requestAnimationFrame(trimFileCells);
|
||
});
|
||
})();
|
||
|
||
/* 目录树:同一父节点下的子节点 */
|
||
function tabKids(pid) {
|
||
var key = pid || 0;
|
||
return S.tabs.filter(function (t) { return (t.parentId || 0) === key; });
|
||
}
|
||
|
||
/* 展开到某个节点:祖先链上有收起的,自动摊开并写库 */
|
||
function expandPathTo(id) {
|
||
var t = findTab(id);
|
||
var guard = 0;
|
||
while (t && t.parentId && guard++ < 40) {
|
||
var p = findTab(t.parentId);
|
||
if (!p) break;
|
||
if (p.collapsed) {
|
||
p.collapsed = false;
|
||
api("/api/tabs/" + p.id + "/collapse", { method: "POST", body: { collapsed: false } })
|
||
.catch(function () {});
|
||
}
|
||
t = p;
|
||
}
|
||
}
|
||
|
||
function toggleNode(id) {
|
||
var t = findTab(id);
|
||
if (!t) return;
|
||
t.collapsed = !t.collapsed;
|
||
renderTabs();
|
||
api("/api/tabs/" + id + "/collapse", { method: "POST", body: { collapsed: t.collapsed } })
|
||
.catch(function (err) { toast(err.message, true); t.collapsed = !t.collapsed; renderTabs(); });
|
||
}
|
||
|
||
function renderTabs() {
|
||
var kids = {};
|
||
S.tabs.forEach(function (t) {
|
||
var p = t.parentId || 0;
|
||
(kids[p] = kids[p] || []).push(t);
|
||
});
|
||
var fixed = kids[0].filter(function (t) { return t.fixed; }) || [];
|
||
var roots = kids[0].filter(function (t) { return !t.fixed; }) || [];
|
||
|
||
function rowHtml(t, depth, no, childCount) {
|
||
var active = t.id === S.activeId;
|
||
var isLeaf = childCount === 0;
|
||
var guides = "";
|
||
for (var i = 0; i < depth; i++) guides += '<span class="side-guide"></span>';
|
||
var kids = tabKids(t.id);
|
||
var pos = kids.map(function (x) { return x.id; }).indexOf(t.id);
|
||
var ops = t.fixed ? "" :
|
||
'<span class="side-ops">' +
|
||
'<button class="side-op" type="button" data-tab-move="' + t.id + '" data-dir="-1"' +
|
||
(pos <= 0 ? " disabled" : "") + ' title="上移">↑</button>' +
|
||
'<button class="side-op" type="button" data-tab-move="' + t.id + '" data-dir="1"' +
|
||
(pos < 0 || pos === kids.length - 1 ? " disabled" : "") + ' title="下移">↓</button>' +
|
||
"</span>";
|
||
return '<div class="side-row k-' + (t.nodeKind || "table") + '">' +
|
||
guides +
|
||
(isLeaf
|
||
? '<span class="side-tog leaf"></span>'
|
||
: '<button class="side-tog" type="button" data-tog="' + t.id + '" title="' +
|
||
(t.collapsed ? "展开" : "收起") + '">' + (t.collapsed ? "+" : "−") + "</button>") +
|
||
'<button class="side-item' + (active ? " active" : "") + '" type="button" ' +
|
||
'data-tab-id="' + t.id + '" title="' + esc(t.name) + (t.fixed ? "" : "(双击改名)") + '">' +
|
||
(no ? '<span class="side-idx">' + no + "</span>" : "") +
|
||
'<span class="side-name">' + esc(t.name) + "</span>" +
|
||
(isLeaf ? "" : '<span class="side-kids">' + childCount + "</span>") +
|
||
"</button>" +
|
||
ops +
|
||
"</div>";
|
||
}
|
||
|
||
var html = "";
|
||
fixed.forEach(function (t) { html += rowHtml(t, 0, "", 0); });
|
||
|
||
/* 锚定行就是目录里的一条记录行 */
|
||
function anchorHtml(t, depth, prefix, index) {
|
||
var list = (S.rows || []).filter(function (r) {
|
||
return r.tabId === t.id && r.anchor;
|
||
});
|
||
if (!list.length) return "";
|
||
var no = prefix ? prefix + "." + index : String(index);
|
||
return list.map(function (r, i) {
|
||
var guides = "";
|
||
for (var d = 0; d < depth; d++) guides += '<span class="side-guide"></span>';
|
||
return '<div class="side-row k-record">' + guides +
|
||
'<span class="side-tog leaf"></span>' +
|
||
'<button class="side-item record" type="button" data-row-go="' + r.id +
|
||
'" data-row-tab="' + t.id + '" title="' + esc(r.name) + '(锚定行)">' +
|
||
'<span class="side-idx">·</span>' +
|
||
'<span class="side-name">' + esc(r.name) + "</span>" +
|
||
"</button></div>";
|
||
}).join("");
|
||
}
|
||
|
||
(function walk(list, depth, prefix) {
|
||
list.forEach(function (t, i) {
|
||
var no = prefix ? prefix + "." + (i + 1) : String(i + 1);
|
||
var sub = kids[t.id] || [];
|
||
var anchors = (S.rows || []).filter(function (r) {
|
||
return r.tabId === t.id && r.anchor;
|
||
});
|
||
html += rowHtml(t, depth, no, sub.length);
|
||
if (t.collapsed) return;
|
||
html += anchorHtml(t, depth + 1, no, anchors.length ? 1 : 1);
|
||
if (sub.length) walk(sub, depth + 1, no);
|
||
});
|
||
})(roots, 0, "");
|
||
|
||
html += '<div class="side-foot">' +
|
||
'<button class="side-add" type="button" id="tabAdd" title="在选中节点下新建标签">+ 新建标签</button>' +
|
||
'<button class="side-set" type="button" data-act="tab-order" title="调整顺序 / 删除标签">设置</button>' +
|
||
"</div>";
|
||
el.tabbar.innerHTML = html;
|
||
if (el.navCount) el.navCount.textContent = S.tabs.length ? "共 " + S.tabs.length + " 项" : "";
|
||
}
|
||
|
||
/* 目录项上下移动:只在同级兄弟之间换位 */
|
||
function moveTab(id, dir) {
|
||
var t = findTab(id);
|
||
if (!t) return;
|
||
var ids = tabKids(t.parentId).map(function (x) { return x.id; });
|
||
var i = ids.indexOf(id);
|
||
if (i < 0) return;
|
||
var j = i + dir;
|
||
if (j < 0 || j >= ids.length) return;
|
||
var tmp = ids[i];
|
||
ids[i] = ids[j];
|
||
ids[j] = tmp;
|
||
api("/api/tabs/order", { method: "POST", body: { ids: ids } })
|
||
.then(function () { refresh(); })
|
||
.catch(function (err) { toast(err.message, true); refresh(); });
|
||
}
|
||
|
||
/* ---------------- 基本设置 ---------------- */
|
||
|
||
function fmtSize(b) {
|
||
b = parseInt(b, 10) || 0;
|
||
if (!b) return "";
|
||
if (b < 1024) return b + " B";
|
||
if (b < 1048576) return (b / 1024).toFixed(1) + " KB";
|
||
return (b / 1048576).toFixed(1) + " MB";
|
||
}
|
||
|
||
function fileChips(item) {
|
||
var logs = item.imports || [];
|
||
var total = item.importCount || 0;
|
||
if (!logs.length) return '<span class="fempty">未导入文件</span>';
|
||
var html = logs.map(function (l) {
|
||
var sz = fmtSize(l.size);
|
||
// 悬停显示完整文件名(含后缀)+ 大小 + 导入时间
|
||
var tip = esc(l.file) + " " + (sz ? sz + " · " : "") + esc(l.at) +
|
||
(l.path ? " " + esc(l.path) : "");
|
||
return '<span class="ifchip" title="' + tip + '">' +
|
||
'<span class="ifchip-name">' + esc(l.file) + "</span>" +
|
||
'<button class="ifchip-del" type="button" data-del-import="' + l.id +
|
||
'" title="删除这条导入记录">✕</button>' +
|
||
"</span>";
|
||
}).join("");
|
||
if (total > logs.length) {
|
||
html += '<span class="fempty">还有 ' + (total - logs.length) + " 条</span>";
|
||
}
|
||
html += '<button class="ifmore" type="button" data-show-files="' + item.id +
|
||
'" title="查看这一行的全部文件">⋯</button>';
|
||
return html;
|
||
}
|
||
|
||
function suffixTr(item, idx, gid, hidden, canDelete) {
|
||
var isPh = !!item.isPlaceholder;
|
||
var nameCell = isPh
|
||
? '<span class="xname pending" title="这一行还没有后缀,上传模板后自动命名">待上传</span>'
|
||
: '<span class="xname">' + esc(item.name) + "</span>";
|
||
var idxCell = isPh
|
||
? '<span class="ridx pending">—</span>'
|
||
: '<span class="ridx">' + idx + "</span>";
|
||
var files = item.importCount || 0;
|
||
var delBtn;
|
||
if (!canDelete) {
|
||
delBtn = '<button class="btn danger icon" type="button" disabled' +
|
||
' title="分组里至少要保留一行,不能删除">✕</button>';
|
||
} else if (files > 0) {
|
||
delBtn = '<button class="btn danger icon" type="button" disabled' +
|
||
' title="这一行还有 ' + files + ' 个上传文件,先在「导入文件」里删掉文件才能删除行">✕</button>';
|
||
} else {
|
||
delBtn = '<button class="btn danger icon" type="button" data-clear-suffix="' + item.id +
|
||
'" title="删除这个后缀">✕</button>';
|
||
}
|
||
return '<tr class="srow' + (hidden ? " r-hidden" : "") + (isPh ? " r-pending" : "") +
|
||
'" data-id="' + item.id + '" data-gid="' + gid + '">' +
|
||
'<td class="c-idx"' + xlsStyle("c-idx") + '>' +
|
||
idxCell + "</td>" +
|
||
'<td class="c-name"' + xlsStyle("c-name") + '>' + nameCell + "</td>" +
|
||
'<td class="c-files"' + xlsStyle("c-files") + '><div class="fcells">' + fileChips(item) + "</div></td>" +
|
||
'<td class="c-op"' + xlsStyle("c-op") + '><div class="op-cell">' +
|
||
'<button class="btn primary xs" type="button" data-upload="' + item.id + '" title="给这个后缀再传一个文件">上传模板</button>' +
|
||
'<button class="btn ghost xs" type="button" data-insert="' + item.id + '" title="在这一行下面插入一行">向下插入行</button>' +
|
||
'<button class="btn ghost icon" type="button" data-move="' + item.id + '" data-dir="-1" title="组内上移">↑</button>' +
|
||
'<button class="btn ghost icon" type="button" data-move="' + item.id + '" data-dir="1" title="组内下移">↓</button>' +
|
||
delBtn +
|
||
"</div></td>" +
|
||
"</tr>";
|
||
}
|
||
|
||
function groupHeadTr(gid, name, count, collapsed, editable, canCollapse, isDefault) {
|
||
var fold = canCollapse === undefined ? editable : canCollapse;
|
||
return '<tr class="grow' + (isDefault ? " g-default" : "") + '" data-group-id="' + gid + '"' +
|
||
">" +
|
||
'<td colspan="4"><div class="gbar">' +
|
||
(fold
|
||
? '<button class="ghandle" type="button" data-toggle-group="' + gid + '">' +
|
||
(collapsed ? "+" : "−") + "</button>"
|
||
: "") +
|
||
'<span class="gname' + (editable ? " editable" : "") + '"' +
|
||
(editable ? ' data-rename-group="' + gid + '" title="双击修改组名"' : "") +
|
||
">" + esc(name) + "</span>" +
|
||
'<span class="gcount">' + count + " 个</span>" +
|
||
(editable
|
||
? '<button class="btn ghost icon" type="button" data-gmove="' + gid + '" data-dir="-1" title="分组上移">↑</button>' +
|
||
'<button class="btn ghost icon" type="button" data-gmove="' + gid + '" data-dir="1" title="分组下移">↓</button>' +
|
||
'<button class="gdel" type="button" data-del-group="' + gid + '" title="删除分组(组里必须是空行)">✕</button>'
|
||
: "") +
|
||
"</div></td></tr>";
|
||
}
|
||
|
||
var XLS_DEF = { "c-idx": 58, "c-name": 100, "c-files": 0, "c-op": 0 };
|
||
|
||
function xlsWidths() {
|
||
var raw = (S.settings && S.settings.suffixWidths) || "";
|
||
if (!raw) return {};
|
||
try { return JSON.parse(raw) || {}; } catch (e) { return {}; }
|
||
}
|
||
|
||
function xlsW(cls) {
|
||
var v = parseInt(xlsWidths()[cls], 10) || 0;
|
||
return v || XLS_DEF[cls] || 0;
|
||
}
|
||
|
||
function xlsStyle(cls) {
|
||
var w = xlsW(cls);
|
||
if (!w) return "";
|
||
return ' style="width:' + w + 'px;min-width:' + w + 'px;max-width:' + w + 'px"';
|
||
}
|
||
|
||
function saveXlsWidths(obj) {
|
||
S.settings = S.settings || {};
|
||
S.settings.suffixWidths = JSON.stringify(obj);
|
||
api("/api/settings", {
|
||
method: "POST", body: { key: "suffixWidths", value: S.settings.suffixWidths }
|
||
}).catch(function (err) { toast(err.message, true); });
|
||
}
|
||
|
||
function trimFileCells() {
|
||
var cells = el.content.querySelectorAll(".fcells");
|
||
for (var i = 0; i < cells.length; i++) {
|
||
var cell = cells[i];
|
||
var chips = cell.querySelectorAll(".ifchip");
|
||
var more = cell.querySelector(".ifmore");
|
||
for (var k = 0; k < chips.length; k++) chips[k].style.display = "";
|
||
if (!more) continue;
|
||
more.style.display = "none";
|
||
if (cell.scrollWidth <= cell.clientWidth + 1) continue;
|
||
more.style.display = "inline-block";
|
||
for (var j = chips.length - 1; j >= 0; j--) {
|
||
chips[j].style.display = "none";
|
||
if (cell.scrollWidth <= cell.clientWidth + 1) break;
|
||
}
|
||
}
|
||
}
|
||
|
||
function suffixCard() {
|
||
var rows = "", idx = 0;
|
||
// 兜底:老库里若有游离行仍然显示(正常情况下后端已全部归入默认分组)
|
||
if (S.ungrouped.length) {
|
||
rows += groupHeadTr(0, "未分组", S.ungrouped.length, false, false, false);
|
||
S.ungrouped.forEach(function (it) { idx += 1; rows += suffixTr(it, idx, 0, false, true); });
|
||
}
|
||
S.groups.forEach(function (g) {
|
||
var editable = !g.isDefault;
|
||
rows += groupHeadTr(g.id, g.name, g.items.length, !!g.collapsed, editable, true, !!g.isDefault);
|
||
if (!g.items.length) {
|
||
rows += '<tr class="gempty"><td colspan="4">空分组</td></tr>';
|
||
} else {
|
||
// 组里只剩一行时不可删(后端也会拦)
|
||
var canDelete = g.items.length > 1;
|
||
g.items.forEach(function (it) {
|
||
if (!it.isPlaceholder) idx += 1;
|
||
rows += suffixTr(it, idx, g.id, !!g.collapsed, canDelete);
|
||
});
|
||
}
|
||
});
|
||
|
||
var xls = '<div class="xls-wrap"><table class="xls">' +
|
||
"<thead><tr>" +
|
||
'<th class="c-idx"' + xlsStyle("c-idx") + '>序号<span class="col-resizer" data-resize-x="c-idx"></span></th>' +
|
||
'<th class="c-name"' + xlsStyle("c-name") + '>后缀<span class="col-resizer" data-resize-x="c-name"></span></th>' +
|
||
'<th class="c-files"' + xlsStyle("c-files") + '>导入文件<span class="col-resizer" data-resize-x="c-files"></span></th>' +
|
||
'<th class="c-op"' + xlsStyle("c-op") + '>操作<span class="col-resizer" data-resize-x="c-op"></span></th>' +
|
||
"</tr></thead><tbody>" + rows + "</tbody></table></div>";
|
||
|
||
return '<section class="card">' +
|
||
'<div class="card-head">' +
|
||
"<h2>后缀设置</h2>" +
|
||
'<span class="spacer"></span>' +
|
||
'<button class="btn ghost small" type="button" data-act="add-group">+ 新建分组</button>' +
|
||
"</div>" +
|
||
xls +
|
||
"</section>";
|
||
}
|
||
|
||
function renderBasic() {
|
||
el.content.classList.remove("sheet-mode");
|
||
el.content.innerHTML = '<div class="wrap">' + suffixCard() + "</div>";
|
||
requestAnimationFrame(trimFileCells);
|
||
}
|
||
|
||
|
||
/* ---------------- 标签页表格 ---------------- */
|
||
|
||
var COL_DEFAULT_W = { index: 54, suffix: 190, action: 84, anchorline: 90 };
|
||
|
||
function colWidth(c) {
|
||
if (!c) return 0;
|
||
var w = parseInt(c.width, 10) || 0;
|
||
return w || COL_DEFAULT_W[c.kind] || 0;
|
||
}
|
||
|
||
function colStyle(c, idxW, fillGap) {
|
||
if (!c) return "";
|
||
var w = colWidth(c);
|
||
if (!w && fillGap) w = 150;
|
||
var parts = [];
|
||
if (w) {
|
||
parts.push("width:" + w + "px");
|
||
parts.push("min-width:" + w + "px");
|
||
parts.push("max-width:" + w + "px");
|
||
}
|
||
if (c.kind === "suffix") parts.push("left:" + (idxW || COL_DEFAULT_W.index) + "px");
|
||
return parts.length ? ' style="' + parts.join(";") + '"' : "";
|
||
}
|
||
|
||
function indexWidth(cols) {
|
||
var w = COL_DEFAULT_W.index;
|
||
(cols || []).forEach(function (c) {
|
||
if (c.kind === "index") w = colWidth(c);
|
||
});
|
||
return w;
|
||
}
|
||
|
||
function sheetGroupRow(g, count, colCount) {
|
||
return '<tr class="group-row" data-sheet-group="' + g.id + '">' +
|
||
'<td colspan="' + colCount + '"><div class="sg-bar">' +
|
||
'<button class="sg-handle" type="button" data-sheet-toggle="' + g.id + '" ' +
|
||
'title="' + (g.collapsed ? "展开分组" : "折叠分组") + '">' +
|
||
(g.collapsed ? "+" : "−") + "</button>" +
|
||
'<span class="sg-name">' + esc(g.name) + "</span>" +
|
||
'<span class="sg-count">' + count + " 个</span>" +
|
||
"</div></td></tr>";
|
||
}
|
||
|
||
/* ---------------- 标签顺序设置 ---------------- */
|
||
|
||
var TO = { ids: [] };
|
||
|
||
function openTabOrder() {
|
||
TO.ids = S.tabs.filter(function (t) { return !t.fixed; }).map(function (t) { return t.id; });
|
||
renderTabOrder();
|
||
el.tabOrderMask.hidden = false;
|
||
}
|
||
|
||
function closeTabOrder() {
|
||
el.tabOrderMask.hidden = true;
|
||
}
|
||
|
||
function renderTabOrder() {
|
||
var map = {};
|
||
S.tabs.forEach(function (t) { map[t.id] = t; });
|
||
if (!TO.ids.length) {
|
||
el.tabOrderList.innerHTML = '<div class="to-empty">除了「基本设置」,还没有别的标签。</div>';
|
||
return;
|
||
}
|
||
el.tabOrderList.innerHTML = TO.ids.map(function (id, i) {
|
||
return '<div class="to-row"><span class="to-idx">' + (i + 1) + '</span>' +
|
||
'<span class="to-name">' + esc((map[id] || {}).name || "") + '</span>' +
|
||
'<button class="btn ghost icon" type="button" data-to-move="' + id + '" data-dir="-1"' +
|
||
(i === 0 ? " disabled" : "") + ' title="上移">↑</button>' +
|
||
'<button class="btn ghost icon" type="button" data-to-move="' + id + '" data-dir="1"' +
|
||
(i === TO.ids.length - 1 ? " disabled" : "") + ' title="下移">↓</button>' +
|
||
'<button class="btn danger icon" type="button" data-to-del="' + id +
|
||
'" title="删除标签">✕</button>' +
|
||
'</div>';
|
||
}).join("");
|
||
}
|
||
|
||
function deleteTab(id) {
|
||
var t = findTab(id);
|
||
var name = t ? t.name : "";
|
||
confirmBox({
|
||
title: "删除标签",
|
||
message: "确定删除标签「" + name + "」?\n" +
|
||
"只有这个标签里一格数据都没有时才删得掉;有数据会提示先清空。",
|
||
okText: "删除",
|
||
danger: true
|
||
}).then(function (ok) {
|
||
if (!ok) return;
|
||
api("/api/tabs/" + id, { method: "DELETE" })
|
||
.then(function () {
|
||
var i = TO.ids.indexOf(id);
|
||
if (i >= 0) TO.ids.splice(i, 1);
|
||
if (S.activeId === id) S.activeId = null;
|
||
return refresh().then(function () {
|
||
renderTabOrder();
|
||
toast("已删除标签");
|
||
});
|
||
})
|
||
.catch(function (err) { toast(err.message, true); });
|
||
});
|
||
}
|
||
|
||
function moveTabOrder(id, dir) {
|
||
var i = TO.ids.indexOf(id);
|
||
if (i < 0) return;
|
||
var j = i + dir;
|
||
if (j < 0 || j >= TO.ids.length) return;
|
||
var tmp = TO.ids[i];
|
||
TO.ids[i] = TO.ids[j];
|
||
TO.ids[j] = tmp;
|
||
renderTabOrder();
|
||
api("/api/tabs/order", { method: "POST", body: { ids: TO.ids } })
|
||
.then(function () { refresh(); })
|
||
.catch(function (err) { toast(err.message, true); });
|
||
}
|
||
|
||
/* ---------------- 列排序(二次排序) ---------------- */
|
||
|
||
var CO = { ids: [], tabId: null };
|
||
|
||
function openColOrder() {
|
||
var sh = S.sheet;
|
||
if (!sh) { toast("先打开一个标签页", true); return; }
|
||
CO.tabId = sh.tabId || S.activeId;
|
||
CO.ids = sh.columns
|
||
.filter(function (c) { return c.kind === "custom"; })
|
||
.map(function (c) { return c.id; });
|
||
renderColOrder();
|
||
el.colOrderMask.hidden = false;
|
||
}
|
||
|
||
function closeColOrder() {
|
||
el.colOrderMask.hidden = true;
|
||
}
|
||
|
||
function renderColOrder() {
|
||
var map = {};
|
||
((S.sheet && S.sheet.columns) || []).forEach(function (c) { map[c.id] = c; });
|
||
if (!CO.ids.length) {
|
||
el.colOrderList.innerHTML = '<div class="to-empty">这个标签页还没有自建列。</div>';
|
||
return;
|
||
}
|
||
el.colOrderList.innerHTML = CO.ids.map(function (id, i) {
|
||
var c = map[id] || {};
|
||
return '<div class="to-row">' +
|
||
'<span class="to-idx">' + (i + 1) + '</span>' +
|
||
'<span class="to-name">' + esc(c.name || "") + '</span>' +
|
||
'<button class="btn ghost icon" type="button" data-co-move="' + id + '" data-dir="-1"' +
|
||
(i === 0 ? " disabled" : "") + ' title="左移">↑</button>' +
|
||
'<button class="btn ghost icon" type="button" data-co-move="' + id + '" data-dir="1"' +
|
||
(i === CO.ids.length - 1 ? " disabled" : "") + ' title="右移">↓</button>' +
|
||
'</div>';
|
||
}).join("");
|
||
}
|
||
|
||
function moveColOrder(id, dir) {
|
||
var i = CO.ids.indexOf(id);
|
||
if (i < 0) return;
|
||
var j = i + dir;
|
||
if (j < 0 || j >= CO.ids.length) return;
|
||
var tmp = CO.ids[i];
|
||
CO.ids[i] = CO.ids[j];
|
||
CO.ids[j] = tmp;
|
||
renderColOrder();
|
||
api("/api/tabs/" + CO.tabId + "/columns/order", { method: "POST", body: { ids: CO.ids } })
|
||
.then(function () {
|
||
return loadSheet(CO.tabId).then(renderColOrder);
|
||
})
|
||
.catch(function (err) { toast(err.message, true); });
|
||
}
|
||
|
||
/* ---------------- 统一确认弹框 ---------------- */
|
||
|
||
var CF = { resolve: null };
|
||
|
||
function confirmBox(opts) {
|
||
opts = opts || {};
|
||
return new Promise(function (resolve) {
|
||
if (CF.resolve) { CF.resolve(false); CF.resolve = null; }
|
||
CF.resolve = resolve;
|
||
el.confirmTitle.textContent = opts.title || "确认操作";
|
||
el.confirmMsg.textContent = opts.message || "";
|
||
el.confirmOk.textContent = opts.okText || "确定";
|
||
el.confirmCancel.textContent = opts.cancelText || "取消";
|
||
el.confirmOk.className = "btn " + (opts.danger ? "danger-strong" : "primary");
|
||
el.confirmMask.hidden = false;
|
||
setTimeout(function () { el.confirmOk.focus(); }, 20);
|
||
});
|
||
}
|
||
|
||
function closeConfirm(ok) {
|
||
if (el.confirmMask.hidden) return;
|
||
el.confirmMask.hidden = true;
|
||
var r = CF.resolve;
|
||
CF.resolve = null;
|
||
if (r) r(!!ok);
|
||
}
|
||
|
||
/* ---------------- 值字段(锚点 + 值) ---------------- */
|
||
|
||
function valueFieldSet() {
|
||
var m = {};
|
||
(S.fields || []).forEach(function (f) { if (f.isValue) m[f.name] = 1; });
|
||
return m;
|
||
}
|
||
|
||
function isValueCol(c) {
|
||
if (!c || c.kind !== "custom") return false;
|
||
return !!valueFieldSet()[c.name];
|
||
}
|
||
|
||
function parseValCell(raw) {
|
||
if (!raw) return { a: "", v: "" };
|
||
if (raw.charAt(0) === "{") {
|
||
try {
|
||
var o = JSON.parse(raw);
|
||
if (o && typeof o === "object") return { a: o.a || "", v: o.v || "" };
|
||
} catch (e) { /* 老数据是纯文本 */ }
|
||
}
|
||
return { a: "", v: raw };
|
||
}
|
||
|
||
function valueCellHtml(raw) {
|
||
var p = parseValCell(raw);
|
||
if (!p.a && !p.v) return '<span class="cell-empty">—</span>';
|
||
var h = "";
|
||
if (p.a) h += '<span class="cv-anchor" title="锚点:' + esc(p.a) + '">' + esc(p.a) + "</span>";
|
||
if (p.v) h += '<span class="cv-value" title="值:' + esc(p.v) + '">' + esc(p.v) + "</span>";
|
||
return h;
|
||
}
|
||
|
||
function sheetDataRow(r, idx, cols, hidden, s) {
|
||
var editing = ED.rowId === r.suffixId;
|
||
var tr = '<tr class="' + (hidden ? "r-hidden" : "") + (editing ? " row-editing" : "") + '">';
|
||
var iw = indexWidth(cols);
|
||
var fillGap = cols.some(function (c) { return (parseInt(c.width, 10) || 0) > 0; });
|
||
cols.forEach(function (c) {
|
||
var st = colStyle(c, iw, fillGap);
|
||
var cid = ' data-cid="' + c.id + '"';
|
||
if (c.kind === "index") {
|
||
tr += '<td class="c-index"' + cid + st + ">" + idx + "</td>";
|
||
} else if (c.kind === "suffix") {
|
||
tr += '<td class="c-suffix"' + cid + st + ' title="' + esc(r.name) + '">' + esc(r.name) + "</td>";
|
||
} else if (c.kind === "action") {
|
||
tr += '<td class="c-action"' + cid + st + '><button class="btn ghost xs' + (editing ? " on" : "") +
|
||
'" type="button" data-edit-row="' + r.suffixId + '" title="' +
|
||
(editing ? "再点一次退出编辑" : "点这里开始编辑,然后双击单元格") + '">编辑</button></td>';
|
||
} else {
|
||
var val = s.cells[c.id + ":" + r.suffixId] || "";
|
||
if (c.kind === "anchorline") val = r.anchor ? "1" : "";
|
||
var extra = c.kind === "anchorline" ? " c-anchorline-cell" : "";
|
||
var vcol = isValueCol(c);
|
||
var tip = vcol ? "双击编辑「" + esc(c.name) + "」(锚点 / 值)"
|
||
: "双击编辑「" + esc(c.name) + "」";
|
||
tr += '<td class="c-cell' + extra + (vcol ? " c-value-cell" : "") + '"' + cid + st +
|
||
' data-cell-col="' + c.id + '" data-cell-suffix="' + r.suffixId + '"' +
|
||
(c.kind === "anchorline"
|
||
? ' data-anchor-col="' + c.id + '" data-anchor-row="' + r.suffixId + '"'
|
||
: "") +
|
||
' title="' + tip + '">' +
|
||
(vcol ? valueCellHtml(val)
|
||
: (val ? '<span class="cell-text">' + esc(val) + "</span>"
|
||
: '<span class="cell-empty">—</span>')) + "</td>";
|
||
}
|
||
});
|
||
return tr + "</tr>";
|
||
}
|
||
|
||
function renderSheet() {
|
||
var tab = activeTab();
|
||
var s = S.sheet;
|
||
if (!tab || !s) { el.content.innerHTML = ""; return; }
|
||
var cols = s.columns;
|
||
var colCount = cols.length;
|
||
|
||
var head = "";
|
||
var idxW = indexWidth(s.columns);
|
||
var fillGap = s.columns.some(function (c) { return (parseInt(c.width, 10) || 0) > 0; });
|
||
var TH_CLASS = { index: "c-index", suffix: "c-suffix",
|
||
action: "c-action", anchorline: "c-anchorline" };
|
||
s.columns.forEach(function (c) {
|
||
var cls = TH_CLASS[c.kind];
|
||
var open = '<th' + (cls ? ' class="' + cls + '"' : "") +
|
||
' data-col="' + c.id + '" data-cid="' + c.id + '"' + colStyle(c, idxW, fillGap) +
|
||
' title="双击设置列宽"><span class="col-resizer" data-resize="' + c.id + '"></span>';
|
||
if (c.kind === "index") head += open + '<span class="th-plain">序号</span></th>';
|
||
else if (c.kind === "suffix") head += open + '<span class="th-plain">后缀</span></th>';
|
||
else if (c.kind === "anchorline") head += open + '<span class="th-plain">' + esc(c.name) + "</span></th>";
|
||
else if (c.kind === "action") head += open + '<span class="th-plain">' + esc(c.name) + "</span></th>";
|
||
else {
|
||
head += open + '<div class="th-inner"><span class="th-name">' + esc(c.name) + "</span>" +
|
||
'<button class="col-del' + (c.hasValues ? " locked" : "") + '" type="button" data-del-col="' + c.id + '" ' +
|
||
'title="' + (c.hasValues ? "该列已有数据,不能删除" : "删除该列") + '">✕</button></div></th>';
|
||
}
|
||
});
|
||
|
||
var body = "";
|
||
if (!s.rows.length) {
|
||
body = '<tr class="empty-row"><td colspan="' + colCount + '">' +
|
||
"这个节点还没有行:行的多少跟「后缀设置」一致,先去基本设置里加上后缀。</td></tr>";
|
||
} else {
|
||
var byGroup = {};
|
||
s.rows.forEach(function (r) {
|
||
var k = r.groupId == null ? "0" : String(r.groupId);
|
||
(byGroup[k] = byGroup[k] || []).push(r);
|
||
});
|
||
var idx = 0;
|
||
(s.groups || []).forEach(function (g) {
|
||
var list = byGroup[String(g.id)] || [];
|
||
body += sheetGroupRow(g, list.length, colCount);
|
||
if (!list.length) {
|
||
body += '<tr class="group-empty' + (g.collapsed ? " r-hidden" : "") + '"><td colspan="' +
|
||
colCount + '">(空分组)</td></tr>';
|
||
} else {
|
||
list.forEach(function (r) {
|
||
idx += 1;
|
||
body += sheetDataRow(r, idx, cols, !!g.collapsed, s);
|
||
});
|
||
}
|
||
});
|
||
var loose = byGroup["0"] || [];
|
||
loose.forEach(function (r) {
|
||
idx += 1;
|
||
body += sheetDataRow(r, idx, cols, false, s);
|
||
});
|
||
}
|
||
|
||
el.content.classList.add("sheet-mode");
|
||
el.content.innerHTML = '<div class="wrap sheet-view">' +
|
||
'<div class="sheet-bar">' +
|
||
'<span class="spacer"></span>' +
|
||
'<span class="save-flag" id="saveFlag">已保存</span>' +
|
||
'<button class="btn ghost small" type="button" data-act="add-col">+ 添加列</button>' +
|
||
'<button class="btn ghost small" type="button" data-act="col-order" ' +
|
||
'title="调整列的左右顺序">列排序</button>' +
|
||
"</div>" +
|
||
'<div class="sheet-rule"></div>' +
|
||
'<div class="sheet-wrap"><table class="sheet' + (fillGap ? " auto-w" : "") +
|
||
'"><thead><tr>' + head + "</tr></thead><tbody>" + body + "</tbody></table></div>" +
|
||
"</div>";
|
||
}
|
||
|
||
/* ---------------- 行编辑弹框 ---------------- */
|
||
|
||
var ED = { suffixId: null, rowId: null, busy: false };
|
||
|
||
function openEdit(suffixId, onlyColId) {
|
||
var sh = S.sheet;
|
||
if (!sh) return;
|
||
var row = null;
|
||
sh.rows.forEach(function (r) { if (r.suffixId === suffixId) row = r; });
|
||
if (!row) return;
|
||
ED.suffixId = suffixId;
|
||
ED.busy = false;
|
||
var cols = sh.columns.filter(function (c) {
|
||
return c.kind === "custom" || c.kind === "anchorline";
|
||
});
|
||
var single = null;
|
||
if (onlyColId) {
|
||
cols = cols.filter(function (c) { return c.id === onlyColId; });
|
||
single = cols[0] || null;
|
||
}
|
||
el.editTitle.textContent = single
|
||
? "编辑「" + row.name + "」· " + single.name
|
||
: "编辑「" + row.name + "」";
|
||
el.editErr.textContent = "";
|
||
if (!cols.length) {
|
||
el.editFields.innerHTML = '<div class="edit-none">这个标签还没有可填的列,先去「+ 添加列」加一列。</div>';
|
||
el.editOk.disabled = true;
|
||
} else {
|
||
el.editOk.disabled = false;
|
||
el.editFields.innerHTML = cols.map(function (c) {
|
||
var raw = sh.cells[c.id + ":" + suffixId] || "";
|
||
if (isValueCol(c)) {
|
||
var p = parseValCell(raw);
|
||
var sub = single ? "" : esc(c.name) + " · ";
|
||
return '<label class="efield"><span class="efield-name" title="锚点">' +
|
||
sub + "锚点</span>" +
|
||
'<input data-edit-col="' + c.id + '" data-part="a" value="' + esc(p.a) +
|
||
'" maxlength="500" autocomplete="off" placeholder="锚点"></label>' +
|
||
'<label class="efield"><span class="efield-name" title="值">' +
|
||
sub + "值</span>" +
|
||
'<input data-edit-col="' + c.id + '" data-part="v" value="' + esc(p.v) +
|
||
'" maxlength="500" autocomplete="off" placeholder="值"></label>';
|
||
}
|
||
return '<label class="efield"><span class="efield-name" title="' + esc(c.name) + '">' +
|
||
esc(c.name) + "</span>" +
|
||
'<input data-edit-col="' + c.id + '" value="' + esc(raw) +
|
||
'" maxlength="500" autocomplete="off"></label>';
|
||
}).join("");
|
||
}
|
||
el.editMask.hidden = false;
|
||
setTimeout(function () {
|
||
var f = el.editFields.querySelector("input");
|
||
if (f) { f.focus(); f.select(); }
|
||
}, 20);
|
||
}
|
||
|
||
function closeEdit() {
|
||
el.editMask.hidden = true;
|
||
ED.suffixId = null;
|
||
ED.busy = false;
|
||
}
|
||
|
||
function saveEdit() {
|
||
if (ED.busy || !ED.suffixId) return;
|
||
var values = {}, parts = {}, inputs = el.editFields.querySelectorAll("[data-edit-col]");
|
||
for (var i = 0; i < inputs.length; i++) {
|
||
var cid = inputs[i].getAttribute("data-edit-col");
|
||
var part = inputs[i].getAttribute("data-part");
|
||
if (part) {
|
||
parts[cid] = parts[cid] || {};
|
||
parts[cid][part] = inputs[i].value;
|
||
} else {
|
||
values[cid] = inputs[i].value;
|
||
}
|
||
}
|
||
Object.keys(parts).forEach(function (cid) {
|
||
var a = parts[cid].a || "", v = parts[cid].v || "";
|
||
values[cid] = (!a && !v) ? "" : JSON.stringify({ a: a, v: v });
|
||
});
|
||
if (!Object.keys(values).length) { closeEdit(); return; }
|
||
var sid = ED.suffixId;
|
||
ED.busy = true;
|
||
el.editOk.disabled = true;
|
||
api("/api/cells/batch", { method: "POST", body: { suffix_id: sid, values: values } })
|
||
.then(function () {
|
||
Object.keys(values).forEach(function (k) {
|
||
S.sheet.cells[k + ":" + sid] = values[k];
|
||
});
|
||
closeEdit();
|
||
renderSheet();
|
||
toast("已保存");
|
||
})
|
||
.catch(function (err) {
|
||
el.editErr.textContent = err.message;
|
||
ED.busy = false;
|
||
el.editOk.disabled = false;
|
||
});
|
||
}
|
||
|
||
/* ---------------- 拖动列宽 ---------------- */
|
||
|
||
var RS = { id: null, startX: 0, startW: 0, moved: false };
|
||
|
||
function freezeColWidths() {
|
||
// 拖动前先把每列当前实际宽度固定下来,再切到 auto 布局:
|
||
// 这样拖一列时其余列不会被表格 100% 宽度反推而变形
|
||
var table = document.querySelector("table.sheet");
|
||
if (!table) return;
|
||
if (!table.classList.contains("auto-w")) {
|
||
var ths = table.querySelectorAll("thead th");
|
||
for (var i = 0; i < ths.length; i++) {
|
||
var w = Math.round(ths[i].getBoundingClientRect().width);
|
||
if (w > 0) {
|
||
ths[i].style.width = w + "px";
|
||
ths[i].style.minWidth = w + "px";
|
||
ths[i].style.maxWidth = w + "px";
|
||
}
|
||
}
|
||
table.classList.add("auto-w");
|
||
}
|
||
}
|
||
|
||
function applyColWidth(colId, w) {
|
||
var nodes = document.querySelectorAll(
|
||
'table.sheet [data-cid="' + colId + '"]'
|
||
);
|
||
for (var i = 0; i < nodes.length; i++) {
|
||
nodes[i].style.width = w + "px";
|
||
nodes[i].style.minWidth = w + "px";
|
||
nodes[i].style.maxWidth = w + "px";
|
||
}
|
||
// 序号变宽/变窄时,「后缀」列的吸边位置要跟着走
|
||
var idxTh = document.querySelector('table.sheet thead th.c-index');
|
||
if (idxTh) {
|
||
var iw = Math.round(idxTh.getBoundingClientRect().width);
|
||
var sufs = document.querySelectorAll('table.sheet [data-cid].c-suffix');
|
||
for (var j = 0; j < sufs.length; j++) sufs[j].style.left = iw + "px";
|
||
}
|
||
}
|
||
|
||
el.content.addEventListener("mousedown", function (e) {
|
||
var rz = e.target.closest ? e.target.closest("[data-resize]") : null;
|
||
if (!rz) return;
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
RS.id = parseInt(rz.getAttribute("data-resize"), 10);
|
||
var th = rz.closest("th");
|
||
RS.startX = e.clientX;
|
||
RS.startW = th.getBoundingClientRect().width;
|
||
RS.moved = false;
|
||
freezeColWidths();
|
||
rz.classList.add("dragging");
|
||
|
||
function onMove(ev) {
|
||
var delta = ev.clientX - RS.startX;
|
||
if (Math.abs(delta) > 2) RS.moved = true;
|
||
var w = Math.max(40, Math.min(800, Math.round(RS.startW + delta)));
|
||
applyColWidth(RS.id, w);
|
||
}
|
||
|
||
function onUp() {
|
||
document.removeEventListener("mousemove", onMove);
|
||
document.removeEventListener("mouseup", onUp);
|
||
rz.classList.remove("dragging");
|
||
if (!RS.moved) { RS.id = null; return; }
|
||
var th2 = document.querySelector('table.sheet thead th[data-cid="' + RS.id + '"]');
|
||
var w2 = th2 ? Math.round(th2.getBoundingClientRect().width) : 0;
|
||
var id = RS.id;
|
||
RS.id = null;
|
||
if (!w2) return;
|
||
api("/api/columns/" + id, { method: "PATCH", body: { width: w2 } })
|
||
.then(function () { loadSheet(S.activeId); })
|
||
.catch(function (err) { toast(err.message, true); loadSheet(S.activeId); });
|
||
}
|
||
|
||
document.addEventListener("mousemove", onMove);
|
||
document.addEventListener("mouseup", onUp);
|
||
}, true);
|
||
|
||
/* ---------------- 基本设置:拖动列宽 ---------------- */
|
||
|
||
el.content.addEventListener("mousedown", function (e) {
|
||
var rz = e.target.closest ? e.target.closest("[data-resize-x]") : null;
|
||
if (!rz) return;
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
var cls = rz.getAttribute("data-resize-x");
|
||
var th = rz.closest("th");
|
||
var startX = e.clientX;
|
||
var startW = th.getBoundingClientRect().width;
|
||
var moved = false;
|
||
rz.classList.add("dragging");
|
||
|
||
function onMove(ev) {
|
||
if (Math.abs(ev.clientX - startX) > 2) moved = true;
|
||
var w = Math.max(48, Math.min(900, Math.round(startW + ev.clientX - startX)));
|
||
var nodes = document.querySelectorAll("table.xls ." + cls);
|
||
for (var i = 0; i < nodes.length; i++) {
|
||
nodes[i].style.width = w + "px";
|
||
nodes[i].style.minWidth = w + "px";
|
||
nodes[i].style.maxWidth = w + "px";
|
||
}
|
||
requestAnimationFrame(trimFileCells);
|
||
}
|
||
|
||
function onUp() {
|
||
document.removeEventListener("mousemove", onMove);
|
||
document.removeEventListener("mouseup", onUp);
|
||
rz.classList.remove("dragging");
|
||
if (!moved) return;
|
||
var th2 = document.querySelector("table.xls th." + cls);
|
||
var w2 = th2 ? Math.round(th2.getBoundingClientRect().width) : 0;
|
||
if (!w2) return;
|
||
var obj = xlsWidths();
|
||
obj[cls] = w2;
|
||
saveXlsWidths(obj);
|
||
requestAnimationFrame(trimFileCells);
|
||
}
|
||
|
||
document.addEventListener("mousemove", onMove);
|
||
document.addEventListener("mouseup", onUp);
|
||
}, true);
|
||
|
||
/* ---------------- 全部文件弹框 ---------------- */
|
||
|
||
function openFiles(suffixId) {
|
||
var w = findWrap(suffixId);
|
||
if (!w) return;
|
||
var item = w.item;
|
||
el.filesTitle.textContent = "导入文件 · " + displayName(item);
|
||
el.filesSub.textContent = "共 " + (item.importCount || 0) + " 个文件" +
|
||
((item.importCount || 0) > (item.imports || []).length
|
||
? "(只列出最近 " + (item.imports || []).length + " 条)" : "") +
|
||
" · 实体存放于 attachments 目录";
|
||
var logs = item.imports || [];
|
||
el.filesList.innerHTML = logs.length
|
||
? logs.map(function (l) {
|
||
return '<div class="fitem">' +
|
||
'<span class="fitem-name" title="' + esc(l.file) +
|
||
(l.path ? " " + esc(l.path) : "") + '">' + esc(l.file) + "</span>" +
|
||
'<span class="fitem-size">' + (fmtSize(l.size) || "—") + "</span>" +
|
||
'<span class="fitem-time">' + esc(l.at) + "</span>" +
|
||
'<button class="fitem-del" type="button" data-del-import="' + l.id +
|
||
'" title="删除这条记录">✕</button>' +
|
||
"</div>";
|
||
}).join("")
|
||
: '<div class="fitem-empty">这一行还没有文件</div>';
|
||
el.filesMask.hidden = false;
|
||
}
|
||
|
||
function closeFiles() {
|
||
el.filesMask.hidden = true;
|
||
}
|
||
|
||
/* ---------------- 列设置(双击表头) ---------------- */
|
||
|
||
var COL = { id: null, fixed: false };
|
||
|
||
function openColSet(colId) {
|
||
var c = null;
|
||
((S.sheet && S.sheet.columns) || []).forEach(function (x) { if (x.id === colId) c = x; });
|
||
if (!c) return;
|
||
COL.id = colId;
|
||
COL.kind = c.kind;
|
||
el.colTitle.textContent = "列宽 · " + c.name;
|
||
el.colW.value = c.width ? String(c.width) : "";
|
||
el.colW.placeholder = "默认 " + (COL_DEFAULT_W[c.kind] || 150) + "px,留空恢复";
|
||
el.colErr.textContent = "";
|
||
el.colOk.disabled = false;
|
||
el.colMask.hidden = false;
|
||
setTimeout(function () { el.colW.focus(); el.colW.select(); }, 20);
|
||
}
|
||
|
||
function closeColSet() {
|
||
el.colMask.hidden = true;
|
||
COL.id = null;
|
||
}
|
||
|
||
function saveColSet() {
|
||
if (!COL.id) return;
|
||
var body = { width: el.colW.value.trim() };
|
||
el.colOk.disabled = true;
|
||
api("/api/columns/" + COL.id, { method: "PATCH", body: body })
|
||
.then(function () {
|
||
closeColSet();
|
||
return loadSheet(S.activeId).then(function () { toast("列已更新"); });
|
||
})
|
||
.catch(function (err) {
|
||
el.colErr.textContent = err.message;
|
||
el.colOk.disabled = false;
|
||
});
|
||
}
|
||
|
||
/* ---------------- 单元格保存 ---------------- */
|
||
|
||
var saveTimers = {}, flagTimer = null;
|
||
|
||
function flashSaved() {
|
||
var flag = document.getElementById("saveFlag");
|
||
if (!flag) return;
|
||
flag.classList.add("show");
|
||
clearTimeout(flagTimer);
|
||
flagTimer = setTimeout(function () { flag.classList.remove("show"); }, 1200);
|
||
}
|
||
|
||
function queueSave(input) {
|
||
var key = input.getAttribute("data-col") + ":" + input.getAttribute("data-suffix");
|
||
clearTimeout(saveTimers[key]);
|
||
saveTimers[key] = setTimeout(function () { doSave(input); }, 420);
|
||
}
|
||
|
||
function doSave(input) {
|
||
var colId = parseInt(input.getAttribute("data-col"), 10);
|
||
var suffixId = parseInt(input.getAttribute("data-suffix"), 10);
|
||
var value = input.value;
|
||
var key = colId + ":" + suffixId;
|
||
if (S.sheet && (S.sheet.cells[key] || "") === value) { flashSaved(); return; }
|
||
api("/api/cells", { method: "PATCH", body: { col_id: colId, suffix_id: suffixId, value: value } })
|
||
.then(function () {
|
||
if (S.sheet) {
|
||
if (value) S.sheet.cells[key] = value; else delete S.sheet.cells[key];
|
||
var col = null;
|
||
(S.sheet.columns || []).forEach(function (c) { if (c.id === colId) col = c; });
|
||
if (col) {
|
||
col.hasValues = Object.keys(S.sheet.cells).some(function (k) { return k.indexOf(colId + ":") === 0; });
|
||
var btn = el.content.querySelector('[data-del-col="' + colId + '"]');
|
||
if (btn) {
|
||
btn.classList.toggle("locked", col.hasValues);
|
||
btn.title = col.hasValues ? "该列已有数据,不能删除" : "删除该列";
|
||
}
|
||
}
|
||
}
|
||
flashSaved();
|
||
})
|
||
.catch(function (err) { toast(err.message, true); });
|
||
}
|
||
|
||
/* ---------------- 弹框 ---------------- */
|
||
|
||
var TITLES = {
|
||
addTab: "新建标签", renameTab: "重命名标签",
|
||
addGroup: "新建分组", renameGroup: "重命名分组",
|
||
addFieldGroup: "新建字段分组", renameFieldGroup: "重命名字段分组",
|
||
addColumn: "添加列(可多选)", insertSuffix: "插入一行(新后缀)",
|
||
addRow: "新建一行(本节点的一条记录)",
|
||
renameField: "重命名字段"
|
||
};
|
||
|
||
function renderFieldChoices() {
|
||
var fields = S.fields || [];
|
||
if (!fields.length) {
|
||
return '<div class="ck-none">字段库还没有字段,可以直接在下面输入列名。</div>';
|
||
}
|
||
var html = '<div class="ck-bar"><span>勾选要添加的字段(可多选)</span>' +
|
||
'<button class="ck-all" type="button" data-ck="all">全选</button>' +
|
||
'<button class="ck-all" type="button" data-ck="none">清空</button></div>';
|
||
html += fields.map(function (f) {
|
||
return '<label class="ck' + (f.isValue ? " value" : "") +
|
||
'"><input type="checkbox" value="' + esc(f.name) + '">' +
|
||
"<span>" + esc(f.name) + (f.isValue ? ' <em class="ck-vtag">值</em>' : "") + "</span></label>";
|
||
}).join("");
|
||
return html;
|
||
}
|
||
|
||
function openModal(mode, ctx) {
|
||
M.mode = mode;
|
||
M.ctx = ctx || {};
|
||
el.modalTitle.textContent = TITLES[mode] || "";
|
||
el.modalInput.value = M.ctx.value || "";
|
||
el.modalErr.textContent = "";
|
||
el.modalChips.innerHTML = "";
|
||
el.modalChips.hidden = true;
|
||
|
||
if (mode === "addColumn") {
|
||
el.modalCheck.innerHTML = renderFieldChoices();
|
||
el.modalCheck.hidden = false;
|
||
el.colwRow.hidden = false;
|
||
el.colWidth.value = "";
|
||
el.modalInput.placeholder = "也可以直接输入列名(可留空)";
|
||
} else {
|
||
el.modalCheck.innerHTML = "";
|
||
el.modalCheck.hidden = true;
|
||
el.colwRow.hidden = true;
|
||
el.colWidth.value = "";
|
||
el.modalInput.placeholder = "请输入名称";
|
||
}
|
||
|
||
el.mask.hidden = false;
|
||
setTimeout(function () {
|
||
if (mode === "addColumn") {
|
||
var first = el.modalCheck.querySelector("input[type=checkbox]");
|
||
if (first) { first.focus(); return; }
|
||
}
|
||
el.modalInput.focus();
|
||
el.modalInput.select();
|
||
}, 20);
|
||
}
|
||
|
||
function closeModal() {
|
||
el.mask.hidden = true;
|
||
M.mode = null;
|
||
M.ctx = {};
|
||
el.modalInput.value = "";
|
||
el.modalErr.textContent = "";
|
||
el.modalOk.disabled = false;
|
||
busy = false;
|
||
}
|
||
|
||
function submitModal() {
|
||
if (busy || !M.mode) return;
|
||
|
||
if (M.mode === "addColumn") {
|
||
var names = [], boxes = el.modalCheck.querySelectorAll('input[type="checkbox"]');
|
||
for (var i = 0; i < boxes.length; i++) if (boxes[i].checked) names.push(boxes[i].value);
|
||
var manual = el.modalInput.value.trim();
|
||
if (manual) names.push(manual);
|
||
var seen = {}, uniq = [];
|
||
names.forEach(function (n) { if (n && !seen[n]) { seen[n] = 1; uniq.push(n); } });
|
||
if (!uniq.length) { el.modalErr.textContent = "请勾选字段,或输入一个列名"; return; }
|
||
|
||
busy = true;
|
||
el.modalOk.disabled = true;
|
||
var colw = el.colWidth.value.trim();
|
||
var added = [], failed = [], chain = Promise.resolve();
|
||
uniq.forEach(function (nm) {
|
||
chain = chain.then(function () {
|
||
return api("/api/tabs/" + S.activeId + "/columns", {
|
||
method: "POST", body: { name: nm, width: colw }
|
||
})
|
||
.then(function () { added.push(nm); })
|
||
.catch(function (err) { failed.push(nm + ":" + err.message); });
|
||
});
|
||
});
|
||
chain.then(function () {
|
||
closeModal();
|
||
loadSheet(S.activeId).then(function () {
|
||
if (added.length) toast("已添加 " + added.length + " 列");
|
||
if (failed.length) toast("有 " + failed.length + " 个没加成 —— " + failed.join(";"), true);
|
||
});
|
||
});
|
||
return;
|
||
}
|
||
|
||
var name = el.modalInput.value.trim();
|
||
if (!name) { el.modalErr.textContent = "名称不能为空"; el.modalInput.focus(); return; }
|
||
|
||
if (M.mode === "renameTab") {
|
||
var oldName = M.ctx.value || "";
|
||
if (name === oldName) { el.modalErr.textContent = "新名称和原名相同"; return; }
|
||
confirmBox({
|
||
title: "重命名确认",
|
||
message: "确定把标签「" + oldName + "」改名为「" + name + "」?",
|
||
okText: "确认改名"
|
||
}).then(function (ok) { if (ok) runSubmit(name); });
|
||
return;
|
||
}
|
||
runSubmit(name);
|
||
}
|
||
|
||
function runSubmit(name) {
|
||
var req;
|
||
if (M.mode === "addTab") {
|
||
var host = findTab(S.activeId);
|
||
req = api("/api/tabs", { method: "POST", body: {
|
||
name: name,
|
||
parent_id: host && !host.fixed ? host.id : null,
|
||
node_kind: "table"
|
||
} });
|
||
}
|
||
else if (M.mode === "renameTab") req = api("/api/tabs/" + M.ctx.id, { method: "PATCH", body: { name: name } });
|
||
else if (M.mode === "addGroup") req = api("/api/groups", { method: "POST", body: { name: name } });
|
||
else if (M.mode === "addFieldGroup") req = api("/api/field-groups", { method: "POST", body: { name: name } });
|
||
else if (M.mode === "renameFieldGroup") req = api("/api/field-groups/" + M.ctx.id, { method: "PATCH", body: { name: name } });
|
||
else if (M.mode === "renameGroup") req = api("/api/groups/" + M.ctx.id, { method: "PATCH", body: { name: name } });
|
||
else if (M.mode === "addColumn") req = api("/api/tabs/" + S.activeId + "/columns", { method: "POST", body: { name: name } });
|
||
else if (M.mode === "renameField") req = api("/api/fields/" + M.ctx.id, { method: "PATCH", body: { name: name } });
|
||
else if (M.mode === "addRow") {
|
||
req = api("/api/tabs/" + S.activeId + "/rows", { method: "POST", body: { name: name } });
|
||
}
|
||
else if (M.mode === "insertSuffix") {
|
||
req = api("/api/suffixes", { method: "POST", body: { name: name, group_id: M.ctx.gid || null } });
|
||
}
|
||
else return;
|
||
|
||
busy = true;
|
||
el.modalOk.disabled = true;
|
||
var mode = M.mode;
|
||
var ctx = M.ctx;
|
||
|
||
req.then(function (res) {
|
||
if (mode === "addTab") {
|
||
S.activeId = res.id;
|
||
closeModal();
|
||
refresh();
|
||
toast("已添加标签:" + res.name);
|
||
} else if (mode === "addColumn") {
|
||
closeModal();
|
||
loadSheet(S.activeId).then(function () { toast("已添加列:" + res.name); });
|
||
} else if (mode === "renameField") {
|
||
closeModal();
|
||
refresh();
|
||
toast("字段已改名" + (res.renamed ? ",「" + res.name + "」同步更新了 " + res.renamed + " 个列名" : ""));
|
||
} else if (mode === "addRow") {
|
||
closeModal();
|
||
loadSheet(S.activeId).then(function () { refresh(); toast("已新建行:" + res.name); });
|
||
} else if (mode === "insertSuffix") {
|
||
closeModal();
|
||
insertSuffixAfter(res.id, ctx.after, ctx.gid)
|
||
.then(function () { refresh(); toast("已插入后缀:" + res.name); })
|
||
.catch(function (err) { toast(err.message, true); refresh(); });
|
||
} else {
|
||
closeModal();
|
||
refresh();
|
||
}
|
||
}).catch(function (err) {
|
||
el.modalErr.textContent = err.message;
|
||
busy = false;
|
||
el.modalOk.disabled = false;
|
||
});
|
||
}
|
||
|
||
/* ---------------- 操作 ---------------- */
|
||
|
||
function deleteSuffix(id) {
|
||
api("/api/suffixes/" + id, { method: "DELETE" })
|
||
.then(function () { refresh(); })
|
||
.catch(function (err) { toast(err.message, true); });
|
||
}
|
||
|
||
function displayName(it) {
|
||
if (!it) return "";
|
||
return it.isPlaceholder ? "待上传" : it.name;
|
||
}
|
||
|
||
function findWrap(id) {
|
||
var i, j;
|
||
for (i = 0; i < S.ungrouped.length; i++) {
|
||
if (S.ungrouped[i].id === id) return { item: S.ungrouped[i], gid: 0 };
|
||
}
|
||
for (j = 0; j < S.groups.length; j++) {
|
||
var g = S.groups[j]; for (i = 0; i < g.items.length; i++) {
|
||
if (g.items[i].id === id) return { item: g.items[i], gid: g.id };
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
function orderSnapshot() {
|
||
var items = [];
|
||
S.ungrouped.forEach(function (it) { items.push({ id: it.id, group_id: null }); });
|
||
S.groups.forEach(function (g) {
|
||
g.items.forEach(function (it) { items.push({ id: it.id, group_id: g.id }); });
|
||
});
|
||
return items;
|
||
}
|
||
|
||
function insertSuffixAfter(newId, afterId, gid) {
|
||
var items = orderSnapshot();
|
||
var at = -1, i;
|
||
for (i = 0; i < items.length; i++) if (items[i].id === afterId) { at = i; break; }
|
||
items.splice(at + 1, 0, { id: newId, group_id: gid ? gid : null });
|
||
return api("/api/suffixes/order", { method: "POST", body: { items: items } });
|
||
}
|
||
|
||
function moveRow(id, dir) {
|
||
var tr = el.content.querySelector('tr.srow[data-id="' + id + '"]');
|
||
if (!tr) return;
|
||
var sib = dir < 0 ? tr.previousElementSibling : tr.nextElementSibling;
|
||
if (!sib || !sib.classList.contains("srow") ||
|
||
sib.getAttribute("data-gid") !== tr.getAttribute("data-gid")) {
|
||
toast("已经在本组" + (dir < 0 ? "最前" : "最后") + "了", true);
|
||
return;
|
||
}
|
||
var w = findWrap(id);
|
||
var o = findWrap(parseInt(sib.getAttribute("data-id"), 10));
|
||
var msg = "确定把「" + displayName(w && w.item) + "」" + (dir < 0 ? "上移" : "下移");
|
||
if (o) msg += "到「" + displayName(o.item) + "」" + (dir < 0 ? "前面" : "后面");
|
||
confirmBox({ title: "移动确认", message: msg + "?", okText: "移动" }).then(function (ok) {
|
||
if (!ok) return;
|
||
if (dir < 0) tr.parentNode.insertBefore(tr, sib);
|
||
else tr.parentNode.insertBefore(sib, tr);
|
||
collectSuffixOrder(true);
|
||
});
|
||
}
|
||
|
||
function moveGroup(id, dir) {
|
||
var idx = -1;
|
||
for (var i = 0; i < S.groups.length; i++) if (S.groups[i].id === id) idx = i;
|
||
if (idx < 0) return;
|
||
if (S.groups[idx].isDefault) { toast("「" + S.groups[idx].name + "」固定在最前,不能移动", true); return; }
|
||
var to = idx + dir;
|
||
if (to < 0) { toast("已经是第一个分组了", true); return; }
|
||
if (to >= S.groups.length) { toast("已经是最后一个分组了", true); return; }
|
||
if (S.groups[to].isDefault) { toast("「" + S.groups[to].name + "」固定在最前,不能越过", true); return; }
|
||
var a = S.groups[idx], b = S.groups[to];
|
||
var gmsg = "确定把分组「" + a.name + "」" + (dir < 0 ? "上移" : "下移") +
|
||
"到「" + b.name + "」" + (dir < 0 ? "前面" : "后面") + "?";
|
||
confirmBox({ title: "移动确认", message: gmsg, okText: "移动" }).then(function (ok) {
|
||
if (!ok) return;
|
||
var ids = S.groups.map(function (g) { return g.id; });
|
||
ids[idx] = b.id;
|
||
ids[to] = a.id;
|
||
api("/api/groups/order", { method: "POST", body: { ids: ids } })
|
||
.then(function () { refresh(); })
|
||
.catch(function (err) { toast(err.message, true); refresh(); });
|
||
});
|
||
}
|
||
|
||
function deleteImport(id) {
|
||
confirmBox({
|
||
title: "删除上传记录",
|
||
message: "确定删除这条上传记录?\n只删这条记录,后缀和它的其他记录都保留。",
|
||
okText: "删除",
|
||
danger: true
|
||
}).then(function (ok) {
|
||
if (!ok) return;
|
||
api("/api/suffixes/imports/" + id, { method: "DELETE" })
|
||
.then(function () { closeFiles(); refresh(); })
|
||
.catch(function (err) { toast(err.message, true); });
|
||
});
|
||
}
|
||
|
||
var UP = { suffixId: null };
|
||
|
||
function uploadFor(id) {
|
||
if (!findWrap(id)) return;
|
||
UP.suffixId = id;
|
||
el.upFile.value = "";
|
||
el.upFile.click();
|
||
}
|
||
|
||
function toggleGroup(id, collapsed) {
|
||
api("/api/groups/" + id, { method: "PATCH", body: { collapsed: collapsed } }).catch(function () {});
|
||
for (var i = 0; i < S.groups.length; i++) if (S.groups[i].id === id) S.groups[i].collapsed = collapsed;
|
||
}
|
||
|
||
function deleteGroup(id) {
|
||
var g = null;
|
||
S.groups.forEach(function (x) { if (x.id === id) g = x; });
|
||
if (g && g.isDefault) { toast("「" + g.name + "」是默认分组,不能删除", true); return; }
|
||
confirmBox({
|
||
title: "删除分组",
|
||
message: "确定删除分组「" + (g ? g.name : "") + "」?\n" +
|
||
"组里必须是空行(没上传模板、没填数据)才能删,删除时这些空行会一起删掉。",
|
||
okText: "删除",
|
||
danger: true
|
||
}).then(function (ok) {
|
||
if (!ok) return;
|
||
api("/api/groups/" + id, { method: "DELETE" })
|
||
.then(function () { refresh(); toast("已删除分组"); })
|
||
.catch(function (err) { toast(err.message, true); });
|
||
});
|
||
}
|
||
|
||
function deleteColumn(id) {
|
||
var c = null;
|
||
(S.sheet && S.sheet.columns ? S.sheet.columns : []).forEach(function (x) { if (x.id === id) c = x; });
|
||
confirmBox({
|
||
title: "删除列",
|
||
message: "确定删除列「" + (c ? c.name : "") + "」?\n这一列里的数据会一起删掉。",
|
||
okText: "删除",
|
||
danger: true
|
||
}).then(function (ok) {
|
||
if (!ok) return;
|
||
api("/api/columns/" + id, { method: "DELETE" })
|
||
.then(function () { loadSheet(S.activeId); })
|
||
.catch(function (err) { toast(err.message, true); });
|
||
});
|
||
}
|
||
|
||
/* ---------------- 后缀工具 ---------------- */
|
||
|
||
function extOf(name) {
|
||
var i = String(name || "").lastIndexOf(".");
|
||
if (i < 0 || i === name.length - 1) return "";
|
||
return name.slice(i + 1).trim().toLowerCase();
|
||
}
|
||
|
||
/* ---------------- 排序收集 ---------------- */
|
||
|
||
function tbody() { return el.content.querySelector(".xls tbody"); }
|
||
|
||
function sameOrder(a, b) {
|
||
if (a.length !== b.length) return false;
|
||
for (var i = 0; i < a.length; i++) {
|
||
if (a[i].id !== b[i].id) return false;
|
||
if ((a[i].group_id || 0) !== (b[i].group_id || 0)) return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
function collectSuffixOrder(skipConfirm) {
|
||
var body = tbody();
|
||
if (!body) return;
|
||
var items = [], gid = 0, rows = body.children;
|
||
for (var i = 0; i < rows.length; i++) {
|
||
var r = rows[i];
|
||
if (r.classList.contains("grow")) {
|
||
gid = parseInt(r.getAttribute("data-group-id"), 10) || 0;
|
||
continue;
|
||
}
|
||
if (!r.classList.contains("srow")) continue;
|
||
items.push({
|
||
id: parseInt(r.getAttribute("data-id"), 10),
|
||
group_id: gid === 0 ? null : gid,
|
||
});
|
||
}
|
||
if (!items.length) return;
|
||
if (sameOrder(items, orderSnapshot())) { refresh(); return; }
|
||
function sendSuffixOrder() {
|
||
api("/api/suffixes/order", { method: "POST", body: { items: items } })
|
||
.then(function () { refresh(); })
|
||
.catch(function (err) { toast(err.message, true); refresh(); });
|
||
}
|
||
if (skipConfirm) { sendSuffixOrder(); return; }
|
||
confirmBox({
|
||
title: "排序确认",
|
||
message: "确定按新位置调整后缀的顺序 / 所属分组?",
|
||
okText: "确认调整"
|
||
}).then(function (ok) { if (ok) sendSuffixOrder(); else refresh(); });
|
||
}
|
||
|
||
|
||
/* ---------------- 事件绑定 ---------------- */
|
||
|
||
el.navHandle.addEventListener("click", function () {
|
||
setNavCollapsed(!el.app.classList.contains("nav-collapsed"), true);
|
||
});
|
||
|
||
el.tabbar.addEventListener("click", function (e) {
|
||
if (e.target.closest("#tabAdd")) { openModal("addTab"); return; }
|
||
var tog = e.target.closest("[data-tog]");
|
||
if (tog) {
|
||
e.stopPropagation();
|
||
toggleNode(parseInt(tog.getAttribute("data-tog"), 10));
|
||
return;
|
||
}
|
||
if (e.target.closest('[data-act="tab-order"]')) {
|
||
openTabOrder();
|
||
return;
|
||
}
|
||
|
||
var mv = e.target.closest("[data-tab-move]");
|
||
if (mv) {
|
||
if (mv.disabled) return;
|
||
moveTab(parseInt(mv.getAttribute("data-tab-move"), 10), parseInt(mv.getAttribute("data-dir"), 10));
|
||
return;
|
||
}
|
||
|
||
var rg = e.target.closest("[data-row-go]");
|
||
if (rg) {
|
||
var rtid = parseInt(rg.getAttribute("data-row-tab"), 10);
|
||
S.focusRow = parseInt(rg.getAttribute("data-row-go"), 10);
|
||
S.activeId = rtid;
|
||
S.sheet = null;
|
||
ED.rowId = null;
|
||
renderTabs();
|
||
el.content.innerHTML = "";
|
||
loadSheet(rtid);
|
||
return;
|
||
}
|
||
|
||
var tb = e.target.closest("[data-tab-id]");
|
||
if (tb) {
|
||
var tid = parseInt(tb.getAttribute("data-tab-id"), 10);
|
||
if (tid === S.activeId) return;
|
||
S.activeId = tid;
|
||
S.sheet = null;
|
||
ED.rowId = null;
|
||
renderTabs();
|
||
var tab = findTab(tid);
|
||
if (tab.fixed) { renderBasic(); }
|
||
else { el.content.innerHTML = ""; loadSheet(tid); }
|
||
}
|
||
});
|
||
|
||
el.tabbar.addEventListener("dblclick", function (e) {
|
||
var tb = e.target.closest("[data-tab-id]");
|
||
if (!tb) return;
|
||
var t = findTab(parseInt(tb.getAttribute("data-tab-id"), 10));
|
||
if (t && !t.fixed) openModal("renameTab", { id: t.id, value: t.name });
|
||
});
|
||
|
||
el.content.addEventListener("click", function (e) {
|
||
// 标签页表格里的分组折叠
|
||
var sg = e.target.closest("[data-sheet-toggle]");
|
||
if (sg) {
|
||
var sgid = parseInt(sg.getAttribute("data-sheet-toggle"), 10);
|
||
var grp = null;
|
||
((S.sheet && S.sheet.groups) || []).forEach(function (x) { if (x.id === sgid) grp = x; });
|
||
if (grp) {
|
||
var next = !grp.collapsed;
|
||
api("/api/groups/" + sgid, { method: "PATCH", body: { collapsed: next } })
|
||
.then(function () { grp.collapsed = next; renderSheet(); })
|
||
.catch(function (err) { toast(err.message, true); });
|
||
}
|
||
return;
|
||
}
|
||
|
||
var edBtn = e.target.closest("[data-edit-row]");
|
||
if (edBtn) {
|
||
var rid = parseInt(edBtn.getAttribute("data-edit-row"), 10);
|
||
ED.rowId = (ED.rowId === rid) ? null : rid;
|
||
renderSheet();
|
||
if (ED.rowId) toast("已进入编辑:双击这一行的单元格修改");
|
||
return;
|
||
}
|
||
|
||
var act = e.target.closest("[data-act]");
|
||
|
||
if (e.target.closest("[data-toggle-group]")) {
|
||
var gid = parseInt(e.target.closest("[data-toggle-group]").getAttribute("data-toggle-group"), 10);
|
||
if (!gid) return;
|
||
var g2 = null;
|
||
S.groups.forEach(function (x) { if (x.id === gid) g2 = x; });
|
||
if (!g2) return;
|
||
g2.collapsed = !g2.collapsed;
|
||
toggleGroup(gid, g2.collapsed);
|
||
renderBasic();
|
||
return;
|
||
}
|
||
|
||
if (e.target.closest("[data-del-group]")) {
|
||
var dg = parseInt(e.target.closest("[data-del-group]").getAttribute("data-del-group"), 10);
|
||
deleteGroup(dg);
|
||
return;
|
||
}
|
||
|
||
if (act) {
|
||
var kind = act.getAttribute("data-act");
|
||
if (kind === "add-group") openModal("addGroup");
|
||
else if (kind === "add-col") openModal("addColumn");
|
||
else if (kind === "col-order") openColOrder();
|
||
return;
|
||
}
|
||
|
||
var an = e.target.closest ? e.target.closest("[data-anchor-row]") : null;
|
||
if (an) {
|
||
e.preventDefault();
|
||
var acol = parseInt(an.getAttribute("data-anchor-col"), 10);
|
||
var arow = parseInt(an.getAttribute("data-anchor-row"), 10);
|
||
api("/api/cells/anchor", { method: "POST", body: { col_id: acol, row_id: arow } })
|
||
.then(function () { return loadSheet(S.activeId); })
|
||
.then(function () { refresh(); })
|
||
.catch(function (err) { toast(err.message, true); });
|
||
return;
|
||
}
|
||
|
||
var cs = e.target.closest("[data-clear-suffix]");
|
||
if (cs) {
|
||
var cid = parseInt(cs.getAttribute("data-clear-suffix"), 10);
|
||
var wrap = findWrap(cid);
|
||
var name = wrap ? displayName(wrap.item) : "";
|
||
var isPh = !!(wrap && wrap.item.isPlaceholder);
|
||
var tip = isPh ? "确定删除这一行?" : "确定删除后缀「" + name + "」?";
|
||
if (wrap && wrap.item.importCount) {
|
||
tip += "\n它的 " + wrap.item.importCount + " 条导入记录会一并删除。";
|
||
}
|
||
confirmBox({
|
||
title: isPh ? "删除行" : "删除后缀",
|
||
message: tip,
|
||
okText: "删除",
|
||
danger: true
|
||
}).then(function (ok) { if (ok) deleteSuffix(cid); });
|
||
return;
|
||
}
|
||
|
||
if (e.target.closest("[data-del-import]")) {
|
||
deleteImport(parseInt(e.target.closest("[data-del-import]").getAttribute("data-del-import"), 10));
|
||
return;
|
||
}
|
||
|
||
if (e.target.closest("[data-upload]")) {
|
||
uploadFor(parseInt(e.target.closest("[data-upload]").getAttribute("data-upload"), 10));
|
||
return;
|
||
}
|
||
|
||
if (e.target.closest("[data-insert]")) {
|
||
var insId = parseInt(e.target.closest("[data-insert]").getAttribute("data-insert"), 10);
|
||
var iw = findWrap(insId);
|
||
openModal("insertSuffix", { after: insId, gid: iw ? iw.gid : 0 });
|
||
return;
|
||
}
|
||
|
||
if (e.target.closest("[data-move]")) {
|
||
var mv = e.target.closest("[data-move]");
|
||
moveRow(parseInt(mv.getAttribute("data-move"), 10), parseInt(mv.getAttribute("data-dir"), 10));
|
||
return;
|
||
}
|
||
|
||
var gmv = e.target.closest("[data-gmove]");
|
||
if (gmv) {
|
||
moveGroup(parseInt(gmv.getAttribute("data-gmove"), 10), parseInt(gmv.getAttribute("data-dir"), 10));
|
||
return;
|
||
}
|
||
|
||
var dc = e.target.closest("[data-del-col]");
|
||
if (dc) {
|
||
e.stopPropagation();
|
||
if (dc.classList.contains("locked")) { toast("该列已有数据,不能删除", true); return; }
|
||
deleteColumn(parseInt(dc.getAttribute("data-del-col"), 10));
|
||
return;
|
||
}
|
||
});
|
||
|
||
el.content.addEventListener("dblclick", function (e) {
|
||
if (e.target.closest && e.target.closest("[data-resize]")) return;
|
||
|
||
var rg = e.target.closest("[data-rename-group]");
|
||
if (rg) {
|
||
e.preventDefault();
|
||
var rid = parseInt(rg.getAttribute("data-rename-group"), 10);
|
||
var g = null;
|
||
S.groups.forEach(function (x) { if (x.id === rid) g = x; });
|
||
if (g) openModal("renameGroup", { id: rid, value: g.name });
|
||
return;
|
||
}
|
||
|
||
var th = e.target.closest ? e.target.closest("th[data-col]") : null;
|
||
if (th && !e.target.closest(".col-del") && !RS.moved) {
|
||
e.preventDefault();
|
||
openColSet(parseInt(th.getAttribute("data-col"), 10));
|
||
return;
|
||
}
|
||
var td = e.target.closest ? e.target.closest("td.c-cell[data-cell-col]") : null;
|
||
if (!td) return;
|
||
e.preventDefault();
|
||
var colId = parseInt(td.getAttribute("data-cell-col"), 10);
|
||
var sid = parseInt(td.getAttribute("data-cell-suffix"), 10);
|
||
if (!colId || !sid) return;
|
||
if (ED.rowId !== sid) {
|
||
toast("先点这一行右侧的「编辑」,再双击单元格", true);
|
||
return;
|
||
}
|
||
openEdit(sid, colId);
|
||
});
|
||
|
||
el.content.addEventListener("input", function (e) {
|
||
var input = e.target.closest("td.c-cell input");
|
||
if (input) queueSave(input);
|
||
});
|
||
|
||
el.content.addEventListener("blur", function (e) {
|
||
var input = e.target.closest ? e.target.closest("td.c-cell input") : null;
|
||
if (input) {
|
||
var key = input.getAttribute("data-col") + ":" + input.getAttribute("data-suffix");
|
||
clearTimeout(saveTimers[key]);
|
||
doSave(input);
|
||
}
|
||
}, true);
|
||
|
||
/* 一次读取同时拿到 sha256 与 base64:附件实体由后端写进 attachments 目录 */
|
||
function toBase64(buf) {
|
||
var bytes = new Uint8Array(buf), chunk = 0x8000, out = "";
|
||
for (var i = 0; i < bytes.length; i += chunk) {
|
||
out += String.fromCharCode.apply(null, bytes.subarray(i, i + chunk));
|
||
}
|
||
return btoa(out);
|
||
}
|
||
|
||
function readFileInfo(file) {
|
||
if (!file.arrayBuffer) return Promise.resolve({ hash: "", b64: "" });
|
||
return file.arrayBuffer().then(function (buf) {
|
||
var job = (window.crypto && crypto.subtle)
|
||
? crypto.subtle.digest("SHA-256", buf).then(function (d) {
|
||
var arr = new Uint8Array(d), out = "";
|
||
for (var i = 0; i < arr.length; i++) out += ("0" + arr[i].toString(16)).slice(-2);
|
||
return out;
|
||
}).catch(function () { return ""; })
|
||
: Promise.resolve("");
|
||
return job.then(function (hash) {
|
||
return { hash: hash, b64: toBase64(buf) };
|
||
});
|
||
}).catch(function () { return { hash: "", b64: "" }; });
|
||
}
|
||
|
||
var MAX_UPLOAD = 128 * 1024 * 1024;
|
||
|
||
/* 行内「上传模板」:把文件实体交给后端存进 attachments,库里只记路径 */
|
||
el.upFile.addEventListener("change", function () {
|
||
var f = el.upFile.files[0];
|
||
var id = UP.suffixId;
|
||
el.upFile.value = "";
|
||
if (!f || !id) return;
|
||
var w = findWrap(id);
|
||
if (!w) return;
|
||
var ext = extOf(f.name);
|
||
if (!ext) { toast("文件名里没有后缀(应形如 清单.cos)", true); return; }
|
||
if (f.size > MAX_UPLOAD) { toast("文件太大,单个文件上限 128 MB", true); return; }
|
||
var isPh = !!w.item.isPlaceholder;
|
||
var curName = String(w.item.name).toLowerCase();
|
||
var baseName = curName.replace(/-\d+$/, "");
|
||
if (!isPh && ext !== curName && ext !== baseName) {
|
||
toast("这个文件是 ." + ext + ",本行是 " + w.item.name + ",后缀不一致", true);
|
||
return;
|
||
}
|
||
readFileInfo(f)
|
||
.then(function (info) {
|
||
return api("/api/suffixes/import-file", {
|
||
method: "POST",
|
||
body: {
|
||
name: f.name, size: f.size, suffix_id: id,
|
||
hash: info.hash, content: info.b64
|
||
}
|
||
});
|
||
})
|
||
.then(function (res) {
|
||
refresh();
|
||
if (!res.path) {
|
||
// 老服务端(还没重启)只会记一条记录、不落盘,这里直接点出来
|
||
toast("只记了记录,附件没进 attachments —— 请关掉服务窗口后用 启动.bat 重启一次", true);
|
||
return;
|
||
}
|
||
if (res.merged) {
|
||
toast("后缀 " + res.suffix + " 已存在,文件已并入那一行", true);
|
||
} else if (isPh) {
|
||
toast("已上传 " + f.name + ",这一行命名为 " + res.suffix);
|
||
} else {
|
||
toast("已上传 " + f.name + "," + displayName(w.item) + " 共 " + res.count + " 次导入");
|
||
}
|
||
})
|
||
.catch(function (err) { toast(err.message, true); });
|
||
});
|
||
|
||
/* 备注列:失去焦点且有变化才保存 */
|
||
el.content.addEventListener("change", function (e) {
|
||
var inp = e.target.closest ? e.target.closest("[data-note]") : null;
|
||
if (!inp) return;
|
||
var id = parseInt(inp.getAttribute("data-note"), 10);
|
||
var val = inp.value.trim();
|
||
var w = findWrap(id);
|
||
if (w && (w.item.note || "") === val) return;
|
||
api("/api/suffixes/" + id, { method: "PATCH", body: { note: val } })
|
||
.then(function () { if (w) w.item.note = val; })
|
||
.catch(function (err) { toast(err.message, true); refresh(); });
|
||
});
|
||
|
||
el.tabOrderClose.addEventListener("click", closeTabOrder);
|
||
el.tabOrderMask.addEventListener("mousedown", function (e) {
|
||
if (e.target === el.tabOrderMask) closeTabOrder();
|
||
});
|
||
el.tabOrderList.addEventListener("click", function (e) {
|
||
var del = e.target.closest("[data-to-del]");
|
||
if (del) {
|
||
deleteTab(parseInt(del.getAttribute("data-to-del"), 10));
|
||
return;
|
||
}
|
||
var mv = e.target.closest("[data-to-move]");
|
||
if (!mv || mv.disabled) return;
|
||
moveTabOrder(parseInt(mv.getAttribute("data-to-move"), 10),
|
||
parseInt(mv.getAttribute("data-dir"), 10));
|
||
});
|
||
|
||
el.colOrderClose.addEventListener("click", closeColOrder);
|
||
el.colOrderMask.addEventListener("mousedown", function (e) {
|
||
if (e.target === el.colOrderMask) closeColOrder();
|
||
});
|
||
el.colOrderList.addEventListener("click", function (e) {
|
||
var mv = e.target.closest("[data-co-move]");
|
||
if (!mv || mv.disabled) return;
|
||
moveColOrder(parseInt(mv.getAttribute("data-co-move"), 10),
|
||
parseInt(mv.getAttribute("data-dir"), 10));
|
||
});
|
||
|
||
el.confirmOk.addEventListener("click", function () { closeConfirm(true); });
|
||
el.confirmCancel.addEventListener("click", function () { closeConfirm(false); }); el.confirmMask.addEventListener("mousedown", function (e) {
|
||
if (e.target === el.confirmMask) closeConfirm(false);
|
||
});
|
||
el.confirmMask.addEventListener("keydown", function (e) {
|
||
if (e.key === "Enter") { e.preventDefault(); closeConfirm(true); }
|
||
});
|
||
|
||
el.filesClose.addEventListener("click", closeFiles);
|
||
el.filesMask.addEventListener("mousedown", function (e) {
|
||
if (e.target === el.filesMask) closeFiles();
|
||
});
|
||
|
||
el.colOk.addEventListener("click", saveColSet);
|
||
el.colCancel.addEventListener("click", closeColSet);
|
||
el.colMask.addEventListener("mousedown", function (e) {
|
||
if (e.target === el.colMask) closeColSet();
|
||
});
|
||
el.colW.addEventListener("keydown", function (e) {
|
||
if (e.key === "Enter") { e.preventDefault(); saveColSet(); }
|
||
});
|
||
|
||
el.editOk.addEventListener("click", saveEdit);
|
||
el.editCancel.addEventListener("click", closeEdit);
|
||
el.editMask.addEventListener("mousedown", function (e) {
|
||
if (e.target === el.editMask) closeEdit();
|
||
});
|
||
el.editFields.addEventListener("keydown", function (e) {
|
||
if (e.key === "Enter") { e.preventDefault(); saveEdit(); }
|
||
});
|
||
|
||
el.modalOk.addEventListener("click", submitModal);
|
||
el.modalCancel.addEventListener("click", closeModal);
|
||
el.mask.addEventListener("mousedown", function (e) { if (e.target === el.mask) closeModal(); });
|
||
el.modalCheck.addEventListener("click", function (e) {
|
||
var btn = e.target.closest("[data-ck]");
|
||
if (!btn) return;
|
||
var boxes = el.modalCheck.querySelectorAll('input[type="checkbox"]');
|
||
var on = btn.getAttribute("data-ck") === "all";
|
||
for (var i = 0; i < boxes.length; i++) boxes[i].checked = on;
|
||
});
|
||
el.modalChips.addEventListener("click", function (e) {
|
||
var b = e.target.closest("[data-fill]");
|
||
if (b) { el.modalInput.value = b.getAttribute("data-fill"); el.modalInput.focus(); }
|
||
});
|
||
el.modalInput.addEventListener("keydown", function (e) {
|
||
if (e.key === "Enter") { e.preventDefault(); submitModal(); }
|
||
if (e.key !== "Escape") return;
|
||
if (!el.tabOrderMask.hidden) { closeTabOrder(); return; }
|
||
if (!el.confirmMask.hidden) { closeConfirm(false); return; }
|
||
if (!el.filesMask.hidden) { closeFiles(); return; }
|
||
if (!el.colMask.hidden) { closeColSet(); return; }
|
||
if (!el.editMask.hidden) { closeEdit(); return; }
|
||
if (!el.mask.hidden) closeModal();
|
||
});
|
||
|
||
/* ---------------- 启动 ---------------- */
|
||
|
||
(function restoreNav() {
|
||
var saved = "";
|
||
try { saved = localStorage.getItem(NAV_KEY) || ""; } catch (e) { saved = ""; }
|
||
setNavCollapsed(saved === "1", false);
|
||
})();
|
||
|
||
loadState().then(function () {
|
||
var t = activeTab();
|
||
if (!t) return;
|
||
if (t.fixed) renderBasic(); else loadSheet(t.id);
|
||
});
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|