Files
SupplierSystem/scripts/fix-nav-remove-fulfillment-ops.cjs
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

125 lines
3.8 KiB
JavaScript

/**
* 去掉 nav_menu_layout 中的「履约作业」分组,并将验收照片复核放入「业务流程」。
* Usage (from server dir): node ../scripts/fix-nav-remove-fulfillment-ops.cjs [--execute]
*/
const path = require('path');
const fs = require('fs');
function loadDotenv() {
const candidates = [
path.join(process.cwd(), '.env'),
path.join(process.cwd(), 'server', '.env'),
path.join(__dirname, '../server/.env'),
];
for (const file of candidates) {
if (!fs.existsSync(file)) continue;
try {
require('dotenv').config({ path: file });
return;
} catch (_) {
/* try next */
}
}
}
loadDotenv();
const { Pool } = require('pg');
const execute = process.argv.includes('--execute');
function patchLayout(raw) {
const layout = typeof raw === 'string' ? JSON.parse(raw) : JSON.parse(JSON.stringify(raw));
if (!layout || !Array.isArray(layout.groups)) return { layout, changed: false };
let changed = false;
let flow =
layout.groups.find((g) => String(g.label || '').trim() === '业务流程') ||
layout.groups.find((g) => String(g.label || '').trim() === '验收管理') ||
layout.groups.find((g) => g.id === 'grp-inspection' || g.id === 'grp-business');
if (!flow) {
flow = {
id: 'grp-business',
label: '业务流程',
icon: 'CheckCircle',
visible: true,
items: [],
};
layout.groups.push(flow);
if (
Array.isArray(layout.order) &&
!layout.order.some((e) => e.kind === 'group' && e.groupId === flow.id)
) {
const financeIdx = layout.order.findIndex(
(e) => e.kind === 'group' && e.groupId === 'grp-finance'
);
if (financeIdx >= 0) layout.order.splice(financeIdx, 0, { kind: 'group', groupId: flow.id });
else layout.order.push({ kind: 'group', groupId: flow.id });
}
changed = true;
}
const assigned = new Set();
for (const g of layout.groups) {
for (const item of g.items || []) assigned.add(item.menuKey);
}
const legacyIds = [];
layout.groups = layout.groups.filter((g) => {
if (String(g.label || '').trim() !== '履约作业') return true;
legacyIds.push(g.id);
for (const item of g.items || []) {
if (assigned.has(item.menuKey)) continue;
flow.items.push({ ...item });
assigned.add(item.menuKey);
changed = true;
}
changed = true;
return false;
});
if (legacyIds.length && Array.isArray(layout.order)) {
layout.order = layout.order.filter(
(e) => !(e.kind === 'group' && legacyIds.includes(e.groupId))
);
}
if (!flow.items.some((i) => i.menuKey === 'inspection-review')) {
flow.items.push({ menuKey: 'inspection-review', visible: true });
changed = true;
}
return { layout, changed };
}
(async () => {
if (!process.env.DATABASE_URL) {
console.error('DATABASE_URL missing');
process.exit(1);
}
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const rows = await pool.query(
`SELECT id, branch_code, config_value FROM system_configs WHERE config_key = 'nav_menu_layout'`
);
for (const row of rows.rows) {
const { layout, changed } = patchLayout(row.config_value);
const groups = (layout.groups || []).map((g) => ({
id: g.id,
label: g.label,
items: (g.items || []).map((i) => i.menuKey),
}));
console.log(`branch=${row.branch_code ?? 'platform'} changed=${changed}`);
console.log(JSON.stringify(groups, null, 2));
if (changed && execute) {
await pool.query(`UPDATE system_configs SET config_value = $1::jsonb WHERE id = $2`, [
JSON.stringify(layout),
row.id,
]);
console.log(' -> updated');
}
}
if (!execute) console.log('\nDry run. Re-run with --execute to write.');
await pool.end();
})().catch((e) => {
console.error(e);
process.exit(1);
});