baseline: 小军 WMS 二开代码原始快照(含 SynOABusiness.cs Debugger.Break)
This commit is contained in:
commit
c2b0e7be0d
6522 files changed
+3530643
No files matched your search
@@ -0,0 +1,31 @@
|
||||
/* ============================================
|
||||
* GX-WMS 通用列表(Grid)组件样式
|
||||
* 与 grid.js 配套使用
|
||||
* ============================================ */
|
||||
|
||||
.gx-grid { background: #fff; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); overflow-x: auto; max-height: calc(100vh - 220px); overflow-y: auto; }
|
||||
.gx-grid table { width: 100%; border-collapse: collapse; min-width: 2400px; table-layout: fixed; }
|
||||
.gx-grid thead { background: #f7f9fc; }
|
||||
.gx-grid thead th { position: sticky; top: 0; background: #f7f9fc; z-index: 5; text-align: left; padding: 9px 8px; font-size: 12px; color: #606266; font-weight: 600; border-bottom: 2px solid #ebeef5; white-space: nowrap; border-right: 1px solid #ebeef5; position: relative; user-select: none; }
|
||||
.gx-grid thead th .gx-resizer { position: absolute; right: 0; top: 0; height: 100%; width: 6px; cursor: col-resize; user-select: none; }
|
||||
.gx-grid thead th .gx-resizer:hover { background: #409eff; }
|
||||
.gx-grid thead th .gx-resizer.active { background: #409eff; }
|
||||
.gx-grid tbody td { padding: 8px; font-size: 12px; color: #303133; border-bottom: 1px solid #f0f2f5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid #f5f7fa; }
|
||||
.gx-grid tbody tr:hover { background: #f5f7fa; }
|
||||
.gx-grid tbody tr:nth-child(even) { background: #fafbfc; }
|
||||
.gx-grid tbody tr:nth-child(even):hover { background: #f5f7fa; }
|
||||
|
||||
/* 风险标签 */
|
||||
.gx-grid .tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
|
||||
.gx-grid .tag.broken { background: #fef0f0; color: #f56c6c; }
|
||||
.gx-grid .tag.warn { background: #fdf6ec; color: #e6a23c; }
|
||||
.gx-grid .tag.safe { background: #f0f9eb; color: #67c23a; }
|
||||
.gx-grid .tag.empty { background: #f4f4f5; color: #909399; }
|
||||
|
||||
/* 数字 */
|
||||
.gx-grid .num { font-family: 'Consolas','Monaco',monospace; }
|
||||
.gx-grid .num.zero { color: #c0c4cc; }
|
||||
.gx-grid .num.neg { color: #f56c6c; font-weight: 600; }
|
||||
|
||||
/* 占位符 */
|
||||
.gx-grid .muted { color: #909399; }
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* ============================================
|
||||
* GX-WMS 通用列表(Grid)组件
|
||||
*
|
||||
* 功能:
|
||||
* 1. 表头固定(上下滚动时不消失)
|
||||
* 2. 列宽可拖动(拖动表头右边调整,列与列之间互不影响)
|
||||
* 3. 行 hover 高亮
|
||||
* 4. 风险标签自动着色(断线/预警/安全)
|
||||
* 5. 数字自动格式化(0 灰色、负数红色)
|
||||
* 6. 横向滚动自然
|
||||
* 7. 自动重新绑定(数据刷新后)
|
||||
*
|
||||
* 用法:
|
||||
* 1. 引入 CSS:<link rel="stylesheet" href="../common/grid.css">
|
||||
* 2. 引入 JS:<script src="../common/grid.js"></script>
|
||||
* 3. HTML 结构:
|
||||
* <div id="myGrid" class="gx-grid">
|
||||
* <table>
|
||||
* <thead><tr><th style="width:80px">列名</th>...</tr></thead>
|
||||
* <tbody id="myTbody"></tbody>
|
||||
* </table>
|
||||
* </div>
|
||||
* 4. JS 渲染后调用:Grid.bind('myGrid');
|
||||
* 5. 工具函数:
|
||||
* Grid.riskTag('断线') => <span class="tag broken">断线</span>
|
||||
* Grid.num(120) => <span class="num">120</span>
|
||||
* Grid.num(0) => <span class="num zero">0</span>
|
||||
* Grid.num(-5) => <span class="num neg">-5</span>
|
||||
* Grid.muted('未填写') => <span class="muted">未填写</span>
|
||||
* ============================================
|
||||
*/
|
||||
|
||||
const Grid = (function() {
|
||||
/**
|
||||
* 绑定列宽拖动 + 重新绑定的工具
|
||||
* @param {string} containerId - 容器元素的 id(含 class="gx-grid")
|
||||
*/
|
||||
function bind(containerId) {
|
||||
const wrap = document.getElementById(containerId);
|
||||
if (!wrap) return;
|
||||
const table = wrap.querySelector('table');
|
||||
if (!table) return;
|
||||
|
||||
// 确保有 <colgroup>,按列设置宽度(改 col 宽度,浏览器自动应用到整列,无需遍历 td,性能好)
|
||||
let colgroup = table.querySelector('colgroup');
|
||||
if (!colgroup) {
|
||||
colgroup = document.createElement('colgroup');
|
||||
table.insertBefore(colgroup, table.firstChild);
|
||||
}
|
||||
const theadRow = table.querySelector('thead tr');
|
||||
const colCount = theadRow ? theadRow.children.length : 0;
|
||||
const cols = [];
|
||||
for (let i = 0; i < colCount; i++) {
|
||||
let col = colgroup.children[i];
|
||||
if (!col) {
|
||||
col = document.createElement('col');
|
||||
colgroup.appendChild(col);
|
||||
}
|
||||
cols.push(col);
|
||||
}
|
||||
|
||||
const ths = wrap.querySelectorAll('thead th');
|
||||
ths.forEach((th, idx) => {
|
||||
if (th.querySelector('.gx-resizer')) return;
|
||||
// 用 th 当前宽度初始化 col 宽度(保持原列宽不被 colgroup 覆盖)
|
||||
if (cols[idx]) {
|
||||
const w = th.style.width || th.getBoundingClientRect().width + 'px';
|
||||
cols[idx].style.width = w;
|
||||
}
|
||||
const r = document.createElement('div');
|
||||
r.className = 'gx-resizer';
|
||||
th.appendChild(r);
|
||||
|
||||
r.addEventListener('mousedown', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const startX = e.pageX;
|
||||
const startW = th.getBoundingClientRect().width;
|
||||
let raf = null;
|
||||
let pendingW = startW;
|
||||
r.classList.add('active');
|
||||
|
||||
const onMove = function(ev) {
|
||||
const dx = ev.pageX - startX;
|
||||
pendingW = Math.max(8, startW + dx); // 最小 8px,允许一直收缩到很小
|
||||
if (raf) return; // 已有待处理的帧,跳过(该帧会用最新 pendingW)
|
||||
raf = requestAnimationFrame(function() {
|
||||
raf = null;
|
||||
if (cols[idx]) cols[idx].style.width = pendingW + 'px';
|
||||
th.style.width = pendingW + 'px'; // 同步 th,保证表头与列内容对齐
|
||||
});
|
||||
};
|
||||
const onUp = function() {
|
||||
if (raf) { cancelAnimationFrame(raf); raf = null; }
|
||||
// 最终确保应用一次
|
||||
if (cols[idx]) cols[idx].style.width = pendingW + 'px';
|
||||
th.style.width = pendingW + 'px';
|
||||
r.classList.remove('active');
|
||||
document.removeEventListener('mousemove', onMove);
|
||||
document.removeEventListener('mouseup', onUp);
|
||||
};
|
||||
document.addEventListener('mousemove', onMove);
|
||||
document.addEventListener('mouseup', onUp);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 风险标签
|
||||
*/
|
||||
function riskTag(risk) {
|
||||
if (!risk) return '<span class="tag empty">未判定</span>';
|
||||
const cls = ({'断线':'broken','预警':'warn','安全':'safe'})[risk] || 'empty';
|
||||
return '<span class="tag ' + cls + '">' + risk + '</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字格式化
|
||||
*/
|
||||
function num(v) {
|
||||
if (v === null || v === undefined || v === '' || v === '-') return '<span class="muted">-</span>';
|
||||
const n = Number(v);
|
||||
if (isNaN(n)) return v;
|
||||
if (n === 0) return '<span class="num zero">0</span>';
|
||||
if (n < 0) return '<span class="num neg">' + n + '</span>';
|
||||
return '<span class="num">' + n + '</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 占位符
|
||||
*/
|
||||
function muted(v, placeholder) {
|
||||
if (!v) return '<span class="muted">' + (placeholder || '-') + '</span>';
|
||||
return v;
|
||||
}
|
||||
|
||||
return { bind: bind, riskTag: riskTag, num: num, muted: muted };
|
||||
})();
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
/* GX-WMS 左侧侧边栏导航样式 */
|
||||
:root { --sidebar-width: 240px; --sidebar-collapsed: 60px; }
|
||||
|
||||
body.with-sidebar { padding-left: var(--sidebar-width); transition: padding-left .25s ease; }
|
||||
body.sidebar-collapsed.with-sidebar { padding-left: var(--sidebar-collapsed); }
|
||||
|
||||
#sidebar {
|
||||
position: fixed;
|
||||
top: 0; left: 0; bottom: 0;
|
||||
width: var(--sidebar-width);
|
||||
background: #1e293b;
|
||||
color: #cbd5e1;
|
||||
overflow-y: auto;
|
||||
box-shadow: 2px 0 8px rgba(0,0,0,.08);
|
||||
z-index: 1000;
|
||||
font-family: 'Microsoft YaHei','PingFang SC',sans-serif;
|
||||
transition: width .25s ease;
|
||||
}
|
||||
body.sidebar-collapsed #sidebar { width: var(--sidebar-collapsed); }
|
||||
|
||||
#sidebar::-webkit-scrollbar { width: 6px; }
|
||||
#sidebar::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
|
||||
#sidebar::-webkit-scrollbar-track { background: transparent; }
|
||||
|
||||
/* 收缩按钮 */
|
||||
.sidebar-toggle {
|
||||
position: absolute;
|
||||
top: 16px; right: 10px;
|
||||
width: 26px; height: 26px;
|
||||
border: none; border-radius: 4px;
|
||||
background: transparent;
|
||||
color: #94a3b8;
|
||||
font-size: 15px;
|
||||
cursor: pointer;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all .15s;
|
||||
}
|
||||
.sidebar-toggle:hover { background: #334155; color: #fff; }
|
||||
body.sidebar-collapsed .sidebar-toggle { right: 17px; }
|
||||
|
||||
/* 用户信息区 */
|
||||
.sidebar-user {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 16px 14px;
|
||||
border-bottom: 1px solid #334155;
|
||||
background: #0f172a;
|
||||
}
|
||||
.sidebar-user .avatar {
|
||||
width: 38px; height: 38px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg,#3b82f6,#1d4ed8);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.sidebar-user .user-text { flex: 1; min-width: 0; }
|
||||
.sidebar-user .user-name { font-size: 14px; color: #e2e8f0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.sidebar-user .user-action { font-size: 12px; margin-top: 2px; }
|
||||
.sidebar-user .user-action a { color: #94a3b8; text-decoration: none; }
|
||||
.sidebar-user .user-action a:hover { color: #60a5fa; }
|
||||
|
||||
/* 菜单容器 */
|
||||
.sidebar-menu { padding: 8px 0; }
|
||||
|
||||
/* 分组标题(可折叠) */
|
||||
.menu-group-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 11px 16px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: #cbd5e1;
|
||||
user-select: none;
|
||||
transition: background .15s;
|
||||
}
|
||||
.menu-group-title:hover { background: #334155; color: #fff; }
|
||||
.menu-group-title .menu-icon {
|
||||
width: 22px;
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
text-align: center;
|
||||
}
|
||||
.menu-group-title .menu-label { flex: 1; margin-left: 10px; }
|
||||
.menu-group-title .menu-arrow {
|
||||
font-size: 11px;
|
||||
color: #64748b;
|
||||
transition: transform .2s;
|
||||
}
|
||||
.menu-arrow.rotate { transform: rotate(-180deg); color: #94a3b8; }
|
||||
.menu-group.expanded > .menu-group-title {
|
||||
background: #334155;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* 子菜单容器 */
|
||||
.menu-children {
|
||||
max-height: 0;
|
||||
overflow: hidden;
|
||||
transition: max-height .25s ease;
|
||||
background: #0f172a;
|
||||
}
|
||||
.menu-group.expanded > .menu-children {
|
||||
max-height: 1200px;
|
||||
}
|
||||
|
||||
/* 子菜单项 */
|
||||
.menu-child {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 9px 16px 9px 44px;
|
||||
color: #94a3b8;
|
||||
text-decoration: none;
|
||||
font-size: 13px;
|
||||
transition: all .15s;
|
||||
border-left: 3px solid transparent;
|
||||
}
|
||||
.menu-child:hover { background: #1e293b; color: #e2e8f0; }
|
||||
.menu-child.active {
|
||||
background: #1e3a8a;
|
||||
color: #fff;
|
||||
border-left-color: #3b82f6;
|
||||
font-weight: 500;
|
||||
}
|
||||
.menu-child-dot {
|
||||
width: 14px;
|
||||
color: #475569;
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.menu-child.active .menu-child-dot { color: #60a5fa; }
|
||||
|
||||
/* ===== 子分组(多级菜单,支持任意层级) ===== */
|
||||
.menu-subgroup-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px 16px 10px 22px;
|
||||
color: #94a3b8;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
transition: all .15s;
|
||||
}
|
||||
.menu-subgroup-title:hover { background: #334155; color: #fff; }
|
||||
.menu-subgroup-title .menu-icon { width: 20px; font-size: 14px; text-align: center; }
|
||||
.menu-subgroup-title .menu-label { flex: 1; margin-left: 8px; }
|
||||
.menu-subgroup-title .menu-arrow { font-size: 10px; color: #64748b; margin-right: 10px; transition: transform .2s; }
|
||||
.menu-subgroup-children {
|
||||
max-height: 0;
|
||||
overflow: hidden;
|
||||
transition: max-height .25s ease;
|
||||
}
|
||||
.menu-subgroup.expanded > .menu-subgroup-children { max-height: 1000px; }
|
||||
|
||||
/* 多级缩进:按层级加深 */
|
||||
.menu-child[data-depth="2"] { padding-left: 58px; }
|
||||
.menu-child[data-depth="3"] { padding-left: 72px; }
|
||||
.menu-child[data-depth="4"] { padding-left: 86px; }
|
||||
.menu-subgroup-title[data-depth="2"] { padding-left: 34px; }
|
||||
.menu-subgroup-title[data-depth="3"] { padding-left: 48px; }
|
||||
.menu-subgroup-title[data-depth="4"] { padding-left: 62px; }
|
||||
|
||||
/* 单项菜单(无子项) */
|
||||
.menu-single {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 11px 16px;
|
||||
color: #cbd5e1;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
transition: background .15s;
|
||||
border-left: 3px solid transparent;
|
||||
}
|
||||
.menu-single:hover { background: #334155; color: #fff; }
|
||||
.menu-single.active {
|
||||
background: #1e3a8a;
|
||||
color: #fff;
|
||||
border-left-color: #3b82f6;
|
||||
font-weight: 500;
|
||||
}
|
||||
.menu-single .menu-icon {
|
||||
width: 22px;
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
text-align: center;
|
||||
}
|
||||
.menu-single .menu-label { margin-left: 10px; }
|
||||
|
||||
/* ===== 折叠状态(只显示图标) ===== */
|
||||
body.sidebar-collapsed .sidebar-user { justify-content: center; padding: 16px 0; }
|
||||
body.sidebar-collapsed .sidebar-user .avatar { width: 34px; height: 34px; font-size: 14px; }
|
||||
body.sidebar-collapsed .sidebar-user .user-text { display: none; }
|
||||
|
||||
body.sidebar-collapsed .menu-group-title { justify-content: center; padding: 13px 0; }
|
||||
body.sidebar-collapsed .menu-group-title .menu-label { display: none; }
|
||||
body.sidebar-collapsed .menu-group-title .menu-arrow { display: none; }
|
||||
body.sidebar-collapsed .menu-group-title .menu-icon { width: auto; }
|
||||
|
||||
body.sidebar-collapsed .menu-children { display: none; }
|
||||
|
||||
body.sidebar-collapsed .menu-single { justify-content: center; padding: 13px 0; }
|
||||
body.sidebar-collapsed .menu-single .menu-label { display: none; }
|
||||
body.sidebar-collapsed .menu-single .menu-icon { width: auto; }
|
||||
|
||||
/* 折叠时菜单项 hover 提示 */
|
||||
body.sidebar-collapsed .menu-group-title { position: relative; }
|
||||
body.sidebar-collapsed .menu-group-title:hover::after {
|
||||
content: attr(data-title);
|
||||
position: absolute;
|
||||
left: calc(var(--sidebar-collapsed) + 8px);
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background: #0f172a;
|
||||
color: #e2e8f0;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
z-index: 1001;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,.3);
|
||||
pointer-events: none;
|
||||
}
|
||||
body.sidebar-collapsed .menu-single { position: relative; }
|
||||
body.sidebar-collapsed .menu-single:hover::after {
|
||||
content: attr(data-title);
|
||||
position: absolute;
|
||||
left: calc(var(--sidebar-collapsed) + 8px);
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background: #0f172a;
|
||||
color: #e2e8f0;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
z-index: 1001;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,.3);
|
||||
pointer-events: none;
|
||||
}
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
/**
|
||||
* ============================================
|
||||
* GX-WMS 左侧侧边栏导航组件
|
||||
* 用法:
|
||||
* 1. 页面 <head> 引入 nav.css:<link rel="stylesheet" href=".../common/nav.css">
|
||||
* 2. <body> 顶部加一个容器:<div id="sidebar"></div>
|
||||
* 3. 主内容区域包裹在 <div class="main-content"> 中
|
||||
* 4. 页面底部引入本JS,自动初始化
|
||||
*
|
||||
* 维护点:仅修改本文件的 MENU_GROUPS 配置
|
||||
* ============================================
|
||||
*/
|
||||
|
||||
// ---------- 应用根路径自动探测 ----------
|
||||
// 支持 IIS 子目录部署(如 /WebApi,名称可变)和 VS 调试(网站根目录)两种场景。
|
||||
// 原理:根据本脚本自身 URL(<应用根>/View/common/nav.js)反推出应用根前缀。
|
||||
// - 部署在子目录时自动得到 '/WebApi' 之类前缀
|
||||
// - VS 调试 / 根目录部署时为空字符串,不影响原行为
|
||||
var APP_BASE = '';
|
||||
(function () {
|
||||
try {
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
for (var i = scripts.length - 1; i >= 0; i--) {
|
||||
var src = scripts[i].getAttribute('src') || '';
|
||||
if (src.indexOf('nav.js') >= 0) {
|
||||
var a = document.createElement('a');
|
||||
a.href = src;
|
||||
var p = a.pathname.replace(/\\/g, '/');
|
||||
var idx = p.indexOf('/View/common/nav.js');
|
||||
if (idx >= 0) APP_BASE = p.substring(0, idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) { APP_BASE = ''; }
|
||||
window.APP_BASE = APP_BASE;
|
||||
})();
|
||||
|
||||
// ---------- 菜单配置(唯一维护点) ----------
|
||||
// 顶级项:{ title, icon, role, children? } 有 children = 分组
|
||||
// 子项:{ title, href, role }
|
||||
// href 使用绝对路径(以 / 开头),渲染时会自动加上应用根前缀 APP_BASE
|
||||
var MENU_GROUPS = [
|
||||
{ title: '首页', icon: '🏠', href: '/home.html', hideOnHome: true },
|
||||
{
|
||||
title: '生产管理', icon: '🏭', role: 'Purchase01',
|
||||
children: [
|
||||
{ title: 'BOM主数据', href: '/View/Delivery/bom_master.html', icon: '🧩', role: 'Purchase01' },
|
||||
{ title: '生产排程计划', href: '/View/Delivery/schedule.html', icon: '📅', role: 'Purchase01' },
|
||||
{ title: '生产排程看板', href: '/View/Delivery/schedule_board.html', icon: '📊', role: 'Purchase01' },
|
||||
{ title: '线边仓库存', href: '/View/Delivery/production_delivery.html', icon: '🏬', role: 'Purchase01' },
|
||||
{ title: 'MES追溯看板', href: '/View/MES/mes_dashboard.html', icon: '🔍', role: 'Produce02' }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '采购管理', icon: '📋', role: ['YF01', 'Purchase01'],
|
||||
children: [
|
||||
{
|
||||
title: '采购申请管理', icon: '📦', role: ['YF01', 'Purchase01'],
|
||||
children: [
|
||||
{ title: '采购申请管理', href: '/procurement.html', icon: '📋', role: 'Purchase01' },
|
||||
{ title: '研发采购全链路看板', href: '/procurement_board_list.html', icon: '📈', role: ['YF01', 'Purchase01'] },
|
||||
{ title: '研发订单考核时效看板', href: '/procurement_audit_leadtime.html', icon: '⏱️', role: ['YF01', 'Purchase01'] }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '采购物料交付', icon: '🚚', role: 'Purchase01',
|
||||
children: [
|
||||
{ title: '采购物料交付', href: '/View/Delivery/material_delivery.html', icon: '🚚', role: 'Purchase01' },
|
||||
{ title: '采购物料交付计划看板', href: '/View/Delivery/delivery_dashboard.html', icon: '📊', role: 'Purchase01' }
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'CRM', icon: '📊', role: 'CRM01',
|
||||
children: [
|
||||
{ title: '金蝶-CRM产品同步', href: '/index.html', icon: '🔄', role: 'CRM01' },
|
||||
{ title: '金蝶-CRM销售订单新变更单同步', href: '/crm_sale_order_sync.html', icon: '📄', role: 'CRM01' }
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// ============================================
|
||||
// 通用逻辑,一般无需修改
|
||||
// ============================================
|
||||
|
||||
function getLoginUser() {
|
||||
try {
|
||||
var raw = sessionStorage.getItem('gx_user');
|
||||
if (!raw) return null;
|
||||
return JSON.parse(raw);
|
||||
} catch (e) { return null; }
|
||||
}
|
||||
|
||||
function hasRole(role) {
|
||||
if (!role) return true;
|
||||
// 支持 role 为数组:任一角色命中即通过(一个功能可分给多个角色)
|
||||
if (Array.isArray(role)) {
|
||||
for (var i = 0; i < role.length; i++) {
|
||||
if (hasRole(role[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
var user = getLoginUser();
|
||||
if (!user) return false;
|
||||
var rn = user.roleNumbers;
|
||||
if (Array.isArray(rn)) {
|
||||
if (rn.indexOf(role) >= 0) return true;
|
||||
for (var i = 0; i < rn.length; i++) {
|
||||
if (String(rn[i]).toUpperCase() === String(role).toUpperCase()) return true;
|
||||
}
|
||||
}
|
||||
var rs = user.roles;
|
||||
if (Array.isArray(rs)) {
|
||||
for (var j = 0; j < rs.length; j++) {
|
||||
var item = rs[j] || {};
|
||||
if (String(item.roleNumber || '').toUpperCase() === String(role).toUpperCase()) return true;
|
||||
if (String(item.roleName || '').toUpperCase() === String(role).toUpperCase()) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isActive(href) {
|
||||
try {
|
||||
var u = new URL(APP_BASE + href, window.location.origin);
|
||||
return window.location.pathname.replace(/\\/g, '/').indexOf(u.pathname) >= 0;
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
|
||||
function getLoginPath() {
|
||||
// 用 APP_BASE(自动探测的应用根前缀)拼接登录页地址:
|
||||
// - VS 调试/根目录部署:APP_BASE 为空,返回 '/login.html'
|
||||
// - 子目录部署(如 /WebApi):返回 '/WebApi/login.html'
|
||||
return APP_BASE + '/login.html';
|
||||
}
|
||||
|
||||
function logout() {
|
||||
sessionStorage.removeItem('gx_user');
|
||||
window.location.href = getLoginPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归判断菜单项(含子孙)是否有激活项
|
||||
*/
|
||||
function isItemActive(item) {
|
||||
if (item.href && isActive(item.href)) return true;
|
||||
if (item.children) {
|
||||
for (var i = 0; i < item.children.length; i++) {
|
||||
if (isItemActive(item.children[i])) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归判断菜单项是否有可见(有权限)的子孙
|
||||
*/
|
||||
function hasVisibleItem(item) {
|
||||
if (!hasRole(item.role)) return false;
|
||||
if (!item.children || !item.children.length) return true;
|
||||
for (var i = 0; i < item.children.length; i++) {
|
||||
if (hasVisibleItem(item.children[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归渲染子菜单项(支持任意层级)
|
||||
* items: 菜单配置数组;depth: 当前层级(从1开始)
|
||||
*/
|
||||
function renderSubItems(items, depth) {
|
||||
var html = '';
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var it = items[i];
|
||||
if (!hasVisibleItem(it)) continue;
|
||||
if (it.children && it.children.length) {
|
||||
// 子分组(可继续递归)
|
||||
var subActive = isItemActive(it) ? ' expanded' : '';
|
||||
var subRotate = isItemActive(it) ? ' rotate' : '';
|
||||
html += '<div class="menu-subgroup' + subActive + '" data-depth="' + depth + '">'
|
||||
+ ' <div class="menu-subgroup-title" onclick="toggleSubGroup(this)" data-title="' + it.title + '">'
|
||||
+ ' <span class="menu-icon">' + (it.icon || '') + '</span>'
|
||||
+ ' <span class="menu-label">' + it.title + '</span>'
|
||||
+ ' <span class="menu-arrow' + subRotate + '">▾</span>'
|
||||
+ ' </div>'
|
||||
+ ' <div class="menu-subgroup-children">'
|
||||
+ renderSubItems(it.children, depth + 1)
|
||||
+ ' </div>'
|
||||
+ '</div>';
|
||||
} else {
|
||||
// 叶子项
|
||||
var activeCls = isActive(it.href) ? ' active' : '';
|
||||
html += '<a class="menu-child" data-depth="' + depth + '" href="' + APP_BASE + it.href + '" data-title="' + it.title + '">'
|
||||
+ ' <span class="menu-child-dot">•</span>'
|
||||
+ ' <span class="menu-label">' + it.title + '</span>'
|
||||
+ '</a>';
|
||||
}
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换子分组展开/收起
|
||||
*/
|
||||
function toggleSubGroup(titleEl) {
|
||||
var sub = titleEl.parentNode;
|
||||
if (!sub) return;
|
||||
sub.classList.toggle('expanded');
|
||||
var arrow = titleEl.querySelector('.menu-arrow');
|
||||
if (arrow) arrow.classList.toggle('rotate');
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染侧边栏
|
||||
*/
|
||||
function renderSidebar() {
|
||||
var user = getLoginUser();
|
||||
if (!user) {
|
||||
if (window.location.href.indexOf('login.html') < 0) {
|
||||
window.location.href = getLoginPath();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var html = '';
|
||||
// 收缩按钮
|
||||
html += '<button class="sidebar-toggle" title="收起/展开菜单" onclick="toggleSidebar()">☰</button>';
|
||||
// 用户信息区
|
||||
var name = user.userName || user.userId || user.name || '用户';
|
||||
html += '<div class="sidebar-user">'
|
||||
+ '<div class="avatar">' + (name || '?').charAt(0) + '</div>'
|
||||
+ '<div class="user-text">'
|
||||
+ ' <div class="user-name">' + name + '</div>'
|
||||
+ ' <div class="user-action"><a href="javascript:void(0)" onclick="logout()">退出登录</a></div>'
|
||||
+ '</div>'
|
||||
+ '</div>';
|
||||
|
||||
// 找出当前页面所在分组(用于默认展开)
|
||||
var activeGroupIdx = -1;
|
||||
var activeChildIdx = -1;
|
||||
|
||||
// 渲染菜单
|
||||
html += '<div class="sidebar-menu">';
|
||||
for (var i = 0; i < MENU_GROUPS.length; i++) {
|
||||
var g = MENU_GROUPS[i];
|
||||
|
||||
if (g.children && g.children.length) {
|
||||
// 分组自身有角色限制时先过滤(未配置 role 则不限制)
|
||||
if (g.role && !hasRole(g.role)) continue;
|
||||
// 递归检查组内是否有激活项(任意层级)
|
||||
var hasActiveChild = isItemActive(g);
|
||||
// 组内没有任何有权限的可见项则跳过
|
||||
if (!hasVisibleItem(g)) continue;
|
||||
if (hasActiveChild && activeGroupIdx < 0) activeGroupIdx = i;
|
||||
|
||||
var expanded = hasActiveChild ? ' expanded' : '';
|
||||
var rotate = hasActiveChild ? ' rotate' : '';
|
||||
html += '<div class="menu-group' + expanded + '" data-group="' + i + '">'
|
||||
+ ' <div class="menu-group-title" data-title="' + g.title + '" onclick="toggleGroup(' + i + ')">'
|
||||
+ ' <span class="menu-icon">' + (g.icon || '') + '</span>'
|
||||
+ ' <span class="menu-label">' + g.title + '</span>'
|
||||
+ ' <span class="menu-arrow' + rotate + '">▾</span>'
|
||||
+ ' </div>'
|
||||
+ ' <div class="menu-children">'
|
||||
+ renderSubItems(g.children, 1)
|
||||
+ ' </div>'
|
||||
+ '</div>';
|
||||
} else {
|
||||
// 单项菜单:按 g.role 判断(分组由子项权限决定,不看 g.role)
|
||||
if (!hasRole(g.role)) continue;
|
||||
// 在首页本身不显示"首页"入口
|
||||
if (g.href === '/home.html' && isActive(g.href)) continue;
|
||||
var activeSingle = isActive(g.href) ? ' active' : '';
|
||||
if (activeSingle) activeGroupIdx = i;
|
||||
html += '<a class="menu-single' + activeSingle + '" href="' + APP_BASE + g.href + '" data-title="' + g.title + '">'
|
||||
+ ' <span class="menu-icon">' + (g.icon || '') + '</span>'
|
||||
+ ' <span class="menu-label">' + g.title + '</span>'
|
||||
+ '</a>';
|
||||
}
|
||||
}
|
||||
html += '</div>';
|
||||
|
||||
var el = document.getElementById('sidebar');
|
||||
if (el) el.innerHTML = html;
|
||||
|
||||
// 主体内容左边距
|
||||
document.body.classList.add('with-sidebar');
|
||||
|
||||
// 恢复折叠状态
|
||||
if (localStorage.getItem('gx_sidebar_collapsed') === '1') {
|
||||
document.body.classList.add('sidebar-collapsed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换侧边栏折叠/展开
|
||||
*/
|
||||
function toggleSidebar() {
|
||||
document.body.classList.toggle('sidebar-collapsed');
|
||||
var collapsed = document.body.classList.contains('sidebar-collapsed');
|
||||
if (collapsed) localStorage.setItem('gx_sidebar_collapsed', '1');
|
||||
else localStorage.removeItem('gx_sidebar_collapsed');
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换分组展开/折叠
|
||||
*/
|
||||
function toggleGroup(idx) {
|
||||
// 折叠状态下点击分组:先展开侧边栏,再展开该分组
|
||||
if (document.body.classList.contains('sidebar-collapsed')) {
|
||||
toggleSidebar();
|
||||
// 展开侧边栏后延迟让 CSS 过渡完成,再展开分组
|
||||
var el = document.querySelector('.menu-group[data-group="' + idx + '"]');
|
||||
if (el) el.classList.add('expanded');
|
||||
return;
|
||||
}
|
||||
var el = document.querySelector('.menu-group[data-group="' + idx + '"]');
|
||||
if (!el) return;
|
||||
el.classList.toggle('expanded');
|
||||
var arrow = el.querySelector('.menu-arrow');
|
||||
if (arrow) arrow.classList.toggle('rotate');
|
||||
}
|
||||
|
||||
function initNav() {
|
||||
renderSidebar();
|
||||
}
|
||||
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener('DOMContentLoaded', function () { initNav(); });
|
||||
} else {
|
||||
window.onload = function () { initNav(); };
|
||||
}
|
||||
Reference in new issue
Block a user