dsh-data-dashboard 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@ import { createV10Overview } from './v10-overview.mjs';
12
12
  export { createV10Model } from './v10-model.mjs';
13
13
  export const V10_TEMPLATE_SHA256 = 'b58e609411d0b9ab2d77d7079ea580e8210d11946999a8c11cea1fc34bf9b886';
14
14
  export const V10_SCRIPT_SHA256 = 'd11a689940d80a4010c5f45786ac2da7d3106cb8309216b4df2d55c8dac4599c';
15
- export const V10_RENDERER_VERSION = 19;
15
+ export const V10_RENDERER_VERSION = 22;
16
16
  export const V10_SHELL_SHA256 = 'd5118e6e2ec447cc22992c348e18ae719bfbda959a2b694352843c120522a5f1';
17
17
  const APPLICATION_MARKER = '/*__V10_APPLICATION__*/';
18
18
  const IDS = ['invoice', 'movement', 'opening', 'terminal', 'inventory', 'banquet'];
@@ -21,8 +21,9 @@ const NUMERIC = {
21
21
  invoice: ['amount'], movement: ['amount', 'bottles', 'boxes', 'cases'], opening: ['bottles', 'amount'],
22
22
  terminal: [], inventory: ['counted', 'system', 'countAmount', 'systemAmount', 'absoluteVariance', 'signedVariance', 'sourceVariance'], banquet: ['events', 'bottles'],
23
23
  };
24
- const TEXT = { invoice: ['brand', 'category', 'dealerCode', 'dealerName', 'productCode', 'productName'], movement: ['brand', 'category', 'quantityUnit', 'terminalCode', 'terminalName', 'channel', 'movementType', 'productCode', 'productName', 'variety', 'dealerCode', 'dealerName'], opening: ['city'], terminal: ['terminalCode', 'terminalName', 'star', 'agreementId', 'type', 'series', 'signLevel', 'signVariety'], inventory: ['brand', 'category', 'safety', 'dealerCode', 'dealerName', 'productCode', 'productName'], banquet: [] };
25
- const OPTIONAL_DISPLAY_TEXT = new Set(['productCode', 'productName', 'variety', 'terminalName', 'channel', 'movementType', 'agreementId', 'type', 'series', 'signLevel', 'signVariety']);
24
+ const TEXT = { invoice: ['brand', 'category', 'dealerCode', 'dealerName', 'productCode', 'productName', 'platform'], movement: ['brand', 'category', 'quantityUnit', 'terminalCode', 'terminalName', 'channel', 'movementType', 'productCode', 'productName', 'variety', 'dealerCode', 'dealerName'], opening: ['city'], terminal: ['terminalCode', 'terminalName', 'star', 'agreementId', 'type', 'series', 'signLevel', 'signVariety'], inventory: ['brand', 'category', 'safety', 'dealerCode', 'dealerName', 'productCode', 'productName'], banquet: [] };
25
+ const OPTIONAL_DISPLAY_TEXT = new Set(['productCode', 'productName', 'variety', 'terminalName', 'channel', 'movementType', 'agreementId', 'type', 'series', 'signLevel', 'signVariety', 'platform']);
26
+ const PLATFORMS = ['zang10', 'tunzhihu'];
26
27
  const hash = text => createHash('sha256').update(text).digest('hex');
27
28
  const isObject = value => value && typeof value === 'object' && !Array.isArray(value);
28
29
  const fail = message => { throw new Error(`v10 看板校验失败:${message}`); };
@@ -50,7 +51,9 @@ export function sanitizeV10Payload(input) {
50
51
  for (const key of ['organizationMapping', 'terminalIdentity', 'crossTableMetrics', 'banquetOpeningSubset', 'banquetReward', 'inventoryValuationBasis']) {
51
52
  const rule = contract[key];
52
53
  if (!rule) continue;
53
- if (!isObject(rule) || !['confirmed', 'pending', 'not-guaranteed'].includes(rule.status)) fail(`规则 ${key} 状态无效`);
54
+ // Organization mapping v2 reports its own path-verified status (v10 业务确认 2026-11-26).
55
+ const statuses = key === 'organizationMapping' ? ['applied', 'partial', 'invalid', 'not-configured', 'confirmed', 'pending'] : ['confirmed', 'pending', 'not-guaranteed'];
56
+ if (!isObject(rule) || !statuses.includes(rule.status)) fail(`规则 ${key} 状态无效`);
54
57
  const clean = { status: rule.status };
55
58
  for (const field of ['sources', 'appliedSources']) if (rule[field]) {
56
59
  if (!isObject(rule[field])) fail(`规则 ${key} 来源绑定无效`);
@@ -96,7 +99,7 @@ export function sanitizeV10Payload(input) {
96
99
  return [key, value];
97
100
  }));
98
101
  if (row.date !== null && !validDate(row.date)) fail(`${where}.date 无效`);
99
- if (id === 'banquet' && row.date !== null) fail('宴席必须保持来源固定期间');
102
+ if (id === 'invoice' && row.platform && !PLATFORMS.includes(row.platform)) fail(`${where}.platform 无效`);
100
103
  const clean = { org, orgPath, date: row.date };
101
104
  for (const key of NUMERIC[id]) {
102
105
  if (!(key in row)) fail(`${where}.${key} 缺失,不能静默补零`);
@@ -175,6 +178,34 @@ export function sanitizeV10Payload(input) {
175
178
  return { month: row.month, metric: row.metric, value: row.value, region: string(row.org.region ?? '', `${where}.region`), office: string(row.org.office ?? '', `${where}.office`), unit: string(row.org.unit ?? '', `${where}.unit`) };
176
179
  }) : [] };
177
180
  }
181
+ // 平台来源只保留文件名与期间(订单本身已并入发票记录)。
182
+ if (isObject(input.platforms)) {
183
+ result.platforms = {};
184
+ for (const id of PLATFORMS) {
185
+ const item = input.platforms[id];
186
+ if (!isObject(item)) continue;
187
+ const cover = isObject(item.coverage) ? item.coverage : {};
188
+ for (const key of ['start', 'end']) if (cover[key] != null && !validDate(cover[key])) fail(`${id} 期间 ${key} 无效`);
189
+ result.platforms[id] = { rows: Number.isSafeInteger(item.rows) ? item.rows : 0, coverage: { start: cover.start ?? null, end: cover.end ?? null },
190
+ originalName: item.source?.originalName ? string(item.source.originalName, `${id}.originalName`).replaceAll('\\', '/').split('/').at(-1) : null };
191
+ }
192
+ }
193
+ // 分销商动销:只作动销参考,不进入六个板块的记录。
194
+ const distributor = input.modules.distributor;
195
+ if (isObject(distributor) && distributor.state !== 'unavailable' && Array.isArray(distributor.records) && distributor.records.length) {
196
+ const cover = input.coverage.distributor || {};
197
+ result.distributor = { state: distributor.state, coverage: { start: validDate(cover.start) ? cover.start : null, end: validDate(cover.end) ? cover.end : null },
198
+ records: distributor.records.map((row, index) => {
199
+ const where = `distributor[${index}]`;
200
+ if (!Array.isArray(row.orgPath) || row.orgPath.length !== 6) fail(`${where} 缺少完整六级组织路径`);
201
+ if (row.date !== null && !validDate(row.date)) fail(`${where}.date 无效`);
202
+ for (const key of ['amount', 'quantity']) if (row[key] !== null && (typeof row[key] !== 'number' || !Number.isFinite(row[key]))) fail(`${where}.${key} 必须为有限数或 null`);
203
+ const orgPath = row.orgPath.map((value, i) => string(value, `${where}.orgPath[${i}]`));
204
+ return { org: Object.fromEntries(ORG.map((key, i) => [key, orgPath[i]])), orgPath, date: row.date, amount: row.amount, quantity: row.quantity,
205
+ distributorName: string(row.distributorName ?? '', `${where}.distributorName`), productName: string(row.productName ?? '', `${where}.productName`),
206
+ brand: string(row.brand ?? null, `${where}.brand`, true), category: string(row.category ?? null, `${where}.category`, true) };
207
+ }) };
208
+ }
178
209
  if (!IDS.some(id => result.modules[id].state !== 'unavailable' && result.modules[id].records.length) && !IDS.some(id => result.modules[id].reviewPending)) fail('零有效来源不能生成真实数据看板');
179
210
  return result;
180
211
  }
@@ -214,7 +245,13 @@ export function packV10Payload(payload) {
214
245
  }
215
246
  return [id, { ...module, records }];
216
247
  }));
217
- return { ...payload, organizationPaths: paths, modules };
248
+ const packed = { ...payload, organizationPaths: paths, modules };
249
+ if (payload.distributor) packed.distributor = { ...payload.distributor, records: payload.distributor.records.map(({ org, orgPath, ...row }) => {
250
+ const key = JSON.stringify(orgPath);
251
+ if (!keys.has(key)) { keys.set(key, paths.length); paths.push(orgPath); }
252
+ return { ...row, orgIndex: keys.get(key) };
253
+ }) };
254
+ return packed;
218
255
  }
219
256
  // Shared objects are restored in memory, so the offline file does not repeat a
220
257
  // full six-level organization hundreds of thousands of times. Keep this function
@@ -236,6 +273,7 @@ export function unpackV10Payload(payload) {
236
273
  return [id, { ...module, records: records.map(({ orgIndex, ...row }) => ({ ...row, org: orgs[orgIndex], orgPath: payload.organizationPaths[orgIndex] })) }];
237
274
  }));
238
275
  const { organizationPaths, ...rest } = payload;
276
+ if (payload.distributor) rest.distributor = { ...payload.distributor, records: payload.distributor.records.map(({ orgIndex, ...row }) => ({ ...row, org: orgs[orgIndex], orgPath: payload.organizationPaths[orgIndex] })) };
239
277
  return { ...rest, modules };
240
278
  }
241
279
  function once(source, search, replacement) {
@@ -102,14 +102,25 @@ function organization(moduleId, row, sourceFormat) {
102
102
  invoice: ['销售大区', '办事处', '客户主任单元'], movement: ['大区名称', '办事处名称', '主任单元名称'],
103
103
  opening: ['产品所属-大区', '产品所属-办事处', '产品所属-主任单元'], terminal: ['大区', '办事处', '主任单元'],
104
104
  inventory: ['大区名称', '办事处名称', '单元名称'], banquet: ['大区', '办事处', '主任单元'], target: ['大区', '办事处', '主任单元'],
105
+ zang10: ['大区', '办事处', '客户主任单元'], tunzhihu: ['大区', '办事处', '主任单元'], distributor: ['大区', '办事处', '客户主任单元'],
105
106
  }[moduleId];
106
- return [text(row.get('营销公司名称')), text(row.get('事业部名称', '事业部')), text(row.get('战区名称')), ...headers.map(header => text(row.get(header)))];
107
+ return [text(row.get('营销公司名称')), text(row.get('事业部名称', '事业部')), text(row.get('战区名称', '战区')), ...headers.map(header => text(row.get(header)))];
107
108
  }
108
109
 
109
110
  function recordDate(moduleId, row, date1904) {
110
- const header = { invoice: '业务日期', movement: '扫码日期', opening: '抽奖日期', terminal: '签约日期', inventory: '提交时间' }[moduleId];
111
+ if (moduleId === 'zang10' || moduleId === 'banquet') return monthDay(moduleId === 'zang10' ? row.get('订单归属年月') : row.get('执行时间(月)'), date1904);
112
+ const header = { invoice: '业务日期', movement: '扫码日期', opening: '抽奖日期', terminal: '签约日期', inventory: '提交时间', tunzhihu: '业务日期', distributor: '动销日期 (日)' }[moduleId];
111
113
  return header ? sourceDate(row.get(header), date1904) : null;
112
114
  }
115
+ /** Month-only source values (202307, 2023-07, 2023/7, 2023年7月, Excel date) → first day of that month. */
116
+ export function monthDay(value, date1904 = false) {
117
+ if (value === null || value === undefined) return null;
118
+ if (value instanceof Date || (typeof value === 'number' && value > 0 && value < 100000)) { const day = sourceDate(value, date1904); return day ? `${day.slice(0, 7)}-01` : null; }
119
+ const raw = text(value), match = raw.match(/^(\d{4})(?:[-/年.]?)(\d{1,2})(?:月)?(?:[-/]\d{1,2})?(?:[ T].*)?$/);
120
+ if (!match) return null;
121
+ const month = Number(match[2]);
122
+ return month >= 1 && month <= 12 ? `${match[1]}-${String(month).padStart(2, '0')}-01` : null;
123
+ }
113
124
 
114
125
  export async function inspectWorkbook({ file, moduleId, sha256, validation }) {
115
126
  if (!moduleById.has(moduleId)) throw new Error('没有这个资料入口。');
@@ -25,9 +25,9 @@ const MAX_BYTES = uploadLimits.fileBytes;
25
25
  const knownModules = new Set(moduleDefinitions.map(m => m.id));
26
26
  // How often each board is expected to be refreshed. Only used for reminders.
27
27
  const CYCLES = ['daily', 'weekly', 'monthly', 'irregular'];
28
- export const DEFAULT_CYCLES = { invoice: 'daily', movement: 'daily', opening: 'daily', terminal: 'weekly', inventory: 'monthly', banquet: 'irregular', target: 'monthly' };
28
+ export const DEFAULT_CYCLES = { invoice: 'daily', movement: 'daily', opening: 'daily', terminal: 'weekly', inventory: 'monthly', banquet: 'monthly', target: 'monthly', zang10: 'monthly', tunzhihu: 'monthly', distributor: 'weekly' };
29
29
  const publicFiles = new Map([['/', ['board.html', 'text/html; charset=utf-8']], ['/board', ['board.html', 'text/html; charset=utf-8']], ['/admin', ['index.html', 'text/html; charset=utf-8']], ['/board.js', ['board.js', 'text/javascript; charset=utf-8']], ['/board.css', ['board.css', 'text/css; charset=utf-8']], ['/admin.js', ['admin.js', 'text/javascript; charset=utf-8']], ['/admin.css', ['admin.css', 'text/css; charset=utf-8']]]);
30
- for (const [file, type] of [['review.js', 'text/javascript'], ['review.css', 'text/css']]) publicFiles.set(`/${file}`, [file, `${type}; charset=utf-8`]);
30
+ for (const [file, type] of [['review.js', 'text/javascript'], ['review.css', 'text/css'], ['org-mapping.js', 'text/javascript']]) publicFiles.set(`/${file}`, [file, `${type}; charset=utf-8`]);
31
31
 
32
32
  class RequestError extends Error {
33
33
  constructor(status, message, extra = {}) { super(message); this.status = status; this.extra = extra; }
@@ -144,11 +144,34 @@ export async function createAdminServer({ port = 4180, dataDir = DEFAULT_DATA_DI
144
144
  } catch {}
145
145
  try {
146
146
  const result = await workerJob({ kind: 'coverage', file: resolve(directory, 'source.xlsx'), validation: upload.validation, moduleId: upload.moduleId }, () => {}, log);
147
- coverageCache.set(upload.id, { start: result.start, end: result.end });
147
+ // Write the cache file before publishing the range, so a reader that sees it can also find the file.
148
148
  await atomicJson(resolve(directory, 'coverage.json'), { sha256: upload.sha256, start: result.start, end: result.end }).catch(log);
149
+ coverageCache.set(upload.id, { start: result.start, end: result.end });
149
150
  } catch (error) { log(error.stack); coverageCache.set(upload.id, { start: null, end: null }); }
150
151
  }
151
152
  }
153
+ // Generations made before the mapping summary was recorded (2026-11-26) show
154
+ // the old rule's status from their own diagnostics.json, read once, kept in
155
+ // memory only; state.json and the files are not rewritten.
156
+ const legacyMapping = new Map();
157
+ const LEGACY_PATTERN = /"organizationMapping":\{"version":1,"status":"([a-z-]{1,20})"/;
158
+ async function legacyMappingStatus(id) {
159
+ let tail = '';
160
+ for await (const chunk of createReadStream(resolve(dataDir, 'generations', id, 'diagnostics.json'), { encoding: 'utf8', highWaterMark: 1 << 20 })) {
161
+ const match = LEGACY_PATTERN.exec(tail + chunk);
162
+ if (match) return match[1];
163
+ tail = chunk.slice(-200);
164
+ }
165
+ return null;
166
+ }
167
+ async function fillLegacyMapping() {
168
+ for (const job of [...store.state.generations].reverse()) {
169
+ if (closing) return;
170
+ if (job.status !== 'completed' || job.organizationMapping || legacyMapping.has(job.id) || !/^[a-f0-9-]{36}$/.test(job.id)) continue;
171
+ legacyMapping.set(job.id, await legacyMappingStatus(job.id).catch(() => null));
172
+ }
173
+ }
174
+ const withLegacyMapping = job => job.status !== 'completed' || job.organizationMapping || !legacyMapping.get(job.id) ? job : { ...job, legacyOrganizationMappingStatus: legacyMapping.get(job.id) };
152
175
  const refreshCoverage = () => { if (coverageRun || closing) return; coverageRun = track(fillCoverage().catch(log).finally(() => { coverageRun = null; })); };
153
176
  function view() {
154
177
  return {
@@ -160,7 +183,7 @@ export async function createAdminServer({ port = 4180, dataDir = DEFAULT_DATA_DI
160
183
  reviewStatus: store.state.uploads.find(u => u.id === (store.state.candidates?.[m.id] || store.state.active[m.id]))?.reviewStatus ?? 'unchecked' })),
161
184
  reviewRevision: store.state.review?.revision ?? 0,
162
185
  uploads: [...store.state.uploads].reverse().map(withCoverage),
163
- generations: [...store.state.generations].reverse().map(job => ({ ...job, ...(job.status === 'completed' ? { viewUrl: `/api/generations/${job.id}/view`, downloadUrl: `/api/generations/${job.id}/download` } : {}) })),
186
+ generations: [...store.state.generations].reverse().map(withLegacyMapping).map(job => ({ ...job, ...(job.status === 'completed' ? { viewUrl: `/api/generations/${job.id}/view`, downloadUrl: `/api/generations/${job.id}/download` } : {}) })),
164
187
  busy,
165
188
  settings: { cycles: { ...DEFAULT_CYCLES, ...(store.state.settings?.cycles || {}) } },
166
189
  };
@@ -531,6 +554,7 @@ export async function createAdminServer({ port = 4180, dataDir = DEFAULT_DATA_DI
531
554
  actualPort = server.address().port;
532
555
  } catch (error) { await store.release(); throw error; }
533
556
  refreshCoverage();
557
+ track(fillLegacyMapping().catch(log));
534
558
  return {
535
559
  server, port: actualPort, url: `http://127.0.0.1:${actualPort}/`, dataDir,
536
560
  async close() {
@@ -1,59 +1,63 @@
1
1
  {
2
2
  "name": "dsh-data-dashboard",
3
- "version": "0.1.4",
4
- "builtAt": "2026-11-25T06:12:45.367Z",
5
- "sourceCommit": "de16d0bc750c1652a44d80ef3e5978de0e9c235f",
6
- "sourceDirty": true,
3
+ "version": "0.1.6",
4
+ "builtAt": "2026-11-27T13:22:43.012Z",
5
+ "sourceCommit": "624416c1a8a73b7b24e9cdc64e6e81a0857e55cc",
6
+ "sourceDirty": false,
7
7
  "files": {
8
8
  "README.md": "ae7f24665cd16f9d729d719ef2335c328d14e0c8b791e40c5c39c8a61d8783d6",
9
9
  "assets/theater-board.svg": "896b0573d86494e4c31b11bde56cecd517b509bd3bf940a24742ac565f164afc",
10
- "backend/incremental/flow.mjs": "d4fc15a45380b548cfec74fb46025eaee0373d2faf3b7f4ad2db9d9a4486d100",
10
+ "backend/incremental/flow.mjs": "2aa3abfce940990d17bf5f4bd466afd269aa56cb1999d9ea55fe5706b03c0b75",
11
11
  "backend/incremental/jobs.mjs": "3c706c735f5acd357f9578bc014fc4598024ba631c954d51a0f11ff06b8fd780",
12
12
  "backend/incremental/xlsx-rows.mjs": "4d840c2401bb0e6157d36f3a0df4e7750bee3209ea6ddb40b70fd9d7cd4e2447",
13
13
  "backend/job-worker.mjs": "a9cfa26a77d72926e8485f274a441ae2f919555aee31288776d4e0abc5de9c50",
14
- "backend/modules.mjs": "0aee556332a186fb7a728858d4643a07da8570e4d155c57204996b01692ffe69",
15
- "backend/modules/banquet/index.mjs": "66747cfdf75ceb16fc2d00c56b78e629d7b7aebe935e3c9415f1ce955b691fa9",
14
+ "backend/modules.mjs": "80f0d3f0639ab15a6745d5be275f22d42d364173f4216f49e94d8e2cf1862919",
15
+ "backend/modules/banquet/index.mjs": "44d8f4994256d3d735df132e239288bd82631b09799ea6815d63f4f36966197d",
16
+ "backend/modules/distributor/index.mjs": "4d08a4d165e23b955a57fede552c61a95be426a02a9313324cece3ec32fea9e4",
16
17
  "backend/modules/inventory/index.mjs": "621937531da92a607f9a54b622f599aeff36cbd7c7814140f202c0e9cc2727f7",
17
18
  "backend/modules/inventory/legacy-fields.mjs": "0de131399a9f5399bf7959ae57af8c52e5c8ab53170910bac3e4bdd21f3be057",
18
19
  "backend/modules/invoice/index.mjs": "4d4f0bce05d3a0e385d5a301365d056bd7954427b5038c69393c77724cdd6473",
19
20
  "backend/modules/movement/index.mjs": "9179dd5726cd698a521bfaaa6e1a1452912dc1b34ceb3b7395d8e8d75c802abb",
20
- "backend/modules/opening/index.mjs": "e6f11fc58689848251511ac332cdc3ffc419d7907adcabd3b7440985bcf410fc",
21
+ "backend/modules/opening/index.mjs": "84f6b2a85150aff9ca76633675304c260ba40b8ef6bb1c4c0d196887fa43bc39",
21
22
  "backend/modules/target/index.mjs": "d644e882b3b7476c6b8b8985f23aa714b15b0ac902a880137bbf951ac407ee6d",
22
23
  "backend/modules/terminal/index.mjs": "cd65735c7dd277e7bc137e9d49c5e15f5b5d99da7c91e93480711351a6f016ea",
23
- "backend/public/admin.css": "2a43416bed62c0c29b43125fd4151530a9b7370daf9d51187abc2d8f64f614e7",
24
- "backend/public/admin.js": "acc62dbd69c179702cf925883967de88cbf4220fba3d218e702b72f676bab6e9",
25
- "backend/public/board.css": "b6dbff8c6d2f21ee70ddb06d90504c8e583722d027567057dc86053ae2b390a4",
26
- "backend/public/board.html": "b81c90c9d64f67894ca3b0cd295f7710fa08095c32b05e93928be2f77343d684",
27
- "backend/public/board.js": "e5302d9fcb8784bef3581142314937674ac17778e6fd9b4844445a2db44dd018",
28
- "backend/public/index.html": "5224461c906395cb7be2a8762c4ec42623fd77ded5bd907daf53686cec80e950",
24
+ "backend/modules/tunzhihu/index.mjs": "ae90f4b6c412a5b7b16da57f9d4f0d2ce94355b3192b6099e0d24a50c3297c54",
25
+ "backend/modules/zang10/index.mjs": "4e777ad06f080bf1294b1286f1cd429f2bdc1fa5821f42031751d1022d65d8e0",
26
+ "backend/public/admin.css": "085ef21c7dee63aedb4b7b4eefe99b7d913581d23085933edfc270abf9720897",
27
+ "backend/public/admin.js": "c9eada31a46485d6193e2fedf02f3a8054dd085145163ff47d4ba74b58748f88",
28
+ "backend/public/board.css": "c7a03188cfbb9f174f0375d48f511a454b60eb58dc4bf0a7e469633e43f12a91",
29
+ "backend/public/board.html": "e731c85e60aa1acd8ae3fca73094754b3d6b8254313e359b3d93a85a2b82d264",
30
+ "backend/public/board.js": "a48c3ea374a7f3e2595f4202432968bf4445f240eaf3654071a32218ad0dbadb",
31
+ "backend/public/index.html": "ee6513a26671f374696cd3b4d6dc6ffcbb9f4935ee6fca36adb1ec56279768ec",
32
+ "backend/public/org-mapping.js": "66ac67a2efa3405d1cb705e4d61ec20307e54142818bac6993e7585a8d5ead5b",
29
33
  "backend/public/review.css": "6fd7366dccd877335f0897577f8cb56a30a2232fe0e779bef84d75757b78b56f",
30
34
  "backend/public/review.js": "cd6bd9ad50e458bc13d7a6b41c6c2ad800cf297a05279a7908b02518bc4ae53c",
31
- "backend/real-data/generate-dashboard.mjs": "6ab0745248f0dddb45237a589c25c2d91459483b06980d79bd1c6c93e2ca7478",
35
+ "backend/real-data/generate-dashboard.mjs": "e9d88b345ef35651f22b713c9ec88687df24e794f5ee85870cb76c7ece642766",
32
36
  "backend/real-data/inventory-history.mjs": "863345fc46ef2c66e1f5279823f408a7ee2b78a421574176c7221b79d44d5a50",
33
- "backend/real-data/organization-mapping.mjs": "963414c4ee317e41a29064dc66a5b8a8241dbe6246d8ae76d930da8c2cbfd867",
34
- "backend/real-data/source-payload.mjs": "f2f04697dac7ee7d62f5bb1f3304b552118ff8854c8dae7fb4e0575d4fdb3679",
37
+ "backend/real-data/organization-mapping.mjs": "4e64d9a1930f774f24a3d8d544a9aad4877bc1f1c5010a69fbde1b022348f1c4",
38
+ "backend/real-data/source-payload.mjs": "87a489c4423d15ddfeda4aaba173c7e1eee6e0b57e666776b7ce4d7b70886b87",
35
39
  "backend/real-data/terminal-components.mjs": "e7c7399e9459964d25cee0c0f7d72834e6480603d6c64b9f41c581319db9c12a",
36
40
  "backend/real-data/terminal-structure.css": "17ca1107abff93b48e5d129a3943b01b2f6ff7113eeede589f51634861069e26",
37
41
  "backend/real-data/terminal-structure.mjs": "a06b4f0eb91e0c2aea6c8f75ff898017787a4269d4e1630866fb31796ead462e",
38
- "backend/real-data/v10-components.mjs": "a2ec25b59a6f2a7ada61081ac3de4dc63e09693d9c12eaa82bce1efed1cc65e0",
42
+ "backend/real-data/v10-components.mjs": "fdcbb1418c4331d5615512c06167e2ffe7539e4edf3f970e7cb0d86a2ff7f285",
39
43
  "backend/real-data/v10-details.css": "a0c12a87ea7fd2974051f0e7b6c00a6057fe8e60515abd6c53aa52b93e8cf924",
40
- "backend/real-data/v10-details.mjs": "740c3246fbf5fbbd8ae806dc3e042f4a8d5ce9cea31553fe45a1ea77a6514195",
44
+ "backend/real-data/v10-details.mjs": "e21f8742823cd21f628d158527a6eac613b2f1ac14e2672248f143e487068f6b",
41
45
  "backend/real-data/v10-layout.css": "2efc29f10d984a8629ef87aae1c72cbdc09658a3553407732c2359931a66cdbd",
42
- "backend/real-data/v10-model.mjs": "19ce10b2a8d520bbcf14a496681a0f42b2bd38eb53f88634404e3fc26a8b2699",
43
- "backend/real-data/v10-overview-data.mjs": "da365789e08cd089d7b10bb1236d2891ccf5d0bc4f9b9e91187e233264ec03f0",
44
- "backend/real-data/v10-overview.css": "6c906cb737fd86be5278febd6449b97fbb02892dc2b0314dd1200930b4b341a7",
45
- "backend/real-data/v10-overview.mjs": "b7dcad8691f7264fd76d6e6e193016c41bdf31c5d7cbd1fe434e1358a59c189b",
46
- "backend/real-data/v10-presentation.mjs": "aadeffbb27499f6353eb52533d1eb2f87493d617da80ab8afeb851e97bdffe09",
46
+ "backend/real-data/v10-model.mjs": "30837c7bb4f5d2370d99ac88fa972a42a3cf4f237667e94126d378b4f98f4d75",
47
+ "backend/real-data/v10-overview-data.mjs": "1f4f1bcca8206228757e3510eeba334607976e9762db3d882717e674b958c333",
48
+ "backend/real-data/v10-overview.css": "3416e27dc73ab261d4ccf11e9cfd97e7b64541ab12fe977b7e397dc4adbe60e5",
49
+ "backend/real-data/v10-overview.mjs": "98d0093d5824b9928e9fc876a9ea0bdc3a4caa76dbadf61f74bbdbcaea4a58b1",
50
+ "backend/real-data/v10-presentation.mjs": "b54f0b766c0e6ff38cd2625db2a8443f066b075ceda934d45280a3bf5ceecf5f",
47
51
  "backend/real-data/v10-shell.html": "d5118e6e2ec447cc22992c348e18ae719bfbda959a2b694352843c120522a5f1",
48
- "backend/real-data/v10-template.mjs": "62802e21574312eb27f0f7e1631170b5457dbf4f32b1e3e3e6b4fe9dc73f0fd0",
52
+ "backend/real-data/v10-template.mjs": "0523c50cde4db93952c9353a72720f4eb8c7d9bb503dcaed48c3fa473f386026",
49
53
  "backend/recognition/fingerprint.mjs": "652340bf7b1f1617c03d53e5c5724154ffabc262c0a522e498ba015671420528",
50
54
  "backend/recognition/headers.mjs": "1cadc4fb39b8a1d7decddae666c827b00903b7f14cfd9e7f4974f2042f07fc02",
51
55
  "backend/recognition/module-definition.mjs": "2aaea663fcc2a52c193637135ad762c7c2af35da96aa12d89742ab6606ed7801",
52
56
  "backend/recognition/result.mjs": "4afe8df9046258424091e556de8337bf283837bd07a1c8c14f765bd11eaa98b5",
53
57
  "backend/recognition/upload-limits.mjs": "8fde2d6c62ab7f0bfa1a945d34efc462087b895fd25e92cf5d5c34c97d738ace",
54
- "backend/review-engine.mjs": "9c13e5684b4697f09b5bda808266095ae3acd40474124d4dd021ff067b547e1d",
58
+ "backend/review-engine.mjs": "852373424d48d7d35d75e35c0baaecc9fea7484565a58be96f366db517395309",
55
59
  "backend/review-service.mjs": "c9d4526b952e07c7c9a5d9c5ef9ccaf6bd108527057dd605e24107312d1bb02f",
56
- "backend/server.mjs": "f9a1a61c69fa7658ca687f7f1b1d0d40cc639bc169131edf3b9d3c8bc621ac41",
60
+ "backend/server.mjs": "21ed2f05a4821a3832ebf2ee69841f19b8117079ff78aa1b08151fce45835e12",
57
61
  "backend/store.mjs": "1e74edc99a577fa9a72a43722a35b6cee7c0c5582b49a5786bbc676412602f0b",
58
62
  "backend/target-template.mjs": "fa33f13b8ee56da7a2bc44c1c474d879817e270bddad03350799143f7fe78b43",
59
63
  "backend/validate-workbook.mjs": "2f86c034e4af578b7971486e81e86912f69a086c877c516223350b52931cc377",
@@ -62,18 +66,18 @@
62
66
  "backend/web-sync/exporter.mjs": "b74a1bef8f072242b12d8a683f6cf42744da925c478558c2c7306fd2ab282130",
63
67
  "backend/web-sync/local.html": "baa1606eac3438fcbab366fd0336a210126ff0a924e5c369b529784a6ade2609",
64
68
  "backend/web-sync/server.mjs": "2b0dd216db6cccf1f641e372394109654fea018780825a6a7bd52d126636043e",
65
- "client.js": "3a3222a2b6573efdf1c6d472d3ece340fddf5db4c279c508ea24d82bb2b42511",
69
+ "client.js": "a849fe79c38810c963b42a21232889a53e033bdf72ce2b0568dfaac9caa4755b",
66
70
  "cordis.patch.yml": "9c21f648e3a89752d07d2db65b1236330b8489b584ddfc63f98be9d9e3116133",
67
71
  "index.js": "b851c33fb87bc02aa3c95d9c236a21865501fcda0576ffa568ae2eabdb73954e",
68
72
  "lib/dist-manifest.mjs": "92ea95c04d108b62e9c513eb7330914a24fbc46b5a4a0869ee0fca1cfb7418fe",
69
73
  "lib/market-index.mjs": "c016b827c730bdd8717a643ae1e8a1b32d845ac7b9f4f80914571acf34fbe21a",
70
74
  "lib/package-audit.mjs": "fcddbf4e8a6eec68bf1c2cbd01a6569fcd6301b50677f367a08fc0476f44561b",
71
75
  "lib/settings.mjs": "b05040be7d56020b33b1c7e4e8208830360a0935e191960d8e13038fce6f16e0",
72
- "lib/tool-definitions.mjs": "a3fa67c261627e140025d200f624885510f8857bf77c3f219efc53cbc4ea1300",
73
- "lib/tools.mjs": "78cf680319cc2e5868b01c76c55a369ee034e9a5be2dc6a3865462dd1ed2c172",
76
+ "lib/tool-definitions.mjs": "1ca9009007cbaabcaab63b5f098611d92d5fd3729312870eea903d0860be3c18",
77
+ "lib/tools.mjs": "dd920e4b586e726081b2e4e268223f708c2dd202b3f5217fcd7053405f75861b",
74
78
  "locale/en.json": "e7a5b39324d6162e7d29957fbc7a0f4bde9c588de2000c874f058df5520f472c",
75
79
  "locale/zh.json": "dd29dcecb35aa6e95a295af228fd39f833c1f492cc5ca41567bb6945ab134510",
76
- "package-lock.json": "7ff8aebb33a076262532e4ab48e9b755b0efb2893d56f70d2f9d5b94659030c5",
77
- "package.json": "95c4df01ce5aab9ea0c4d4ffa1168c9d27dad2f77076c46f5dd3b828e24d6a00"
80
+ "package-lock.json": "223158ebd62936a35db2b9e8086251b4d11adb63d07c381dae4353aa3c39179c",
81
+ "package.json": "da73ccc999a8e1f0e9a0e28f2fd5f41fd71368dc001e188ad5a74b52a0723d7b"
78
82
  }
79
83
  }
package/client.js CHANGED
@@ -10,15 +10,45 @@ const LOOPBACK=['127.0.0.1','localhost'];
10
10
  function BoardIcon({size}){const s=size||20;return h('svg',{width:s,height:s,viewBox:'0 0 24 24',fill:'none',stroke:'currentColor',strokeWidth:1.8,strokeLinejoin:'round','aria-hidden':true},h('rect',{x:3.5,y:3.5,width:7,height:9,rx:1.5}),h('rect',{x:13.5,y:3.5,width:7,height:5,rx:1.5}),h('rect',{x:13.5,y:11.5,width:7,height:9,rx:1.5}),h('rect',{x:3.5,y:15.5,width:7,height:5,rx:1.5}))}
11
11
  // DSH Web on loopback keeps its own hostname (same-site with the backend);
12
12
  // the DSH desktop window (dsh-app://app) uses 127.0.0.1.
13
- function boardUrl(port,where){const loc=where||location;if(LOOPBACK.includes(loc.hostname)&&(loc.protocol==='http:'||loc.protocol==='https:'))return`http://${loc.hostname}:${port}/`;if(loc.protocol==='dsh-app:'&&loc.hostname==='app')return`http://127.0.0.1:${port}/`;return null}
13
+ const isDesktop=loc=>loc.protocol==='dsh-app:'&&loc.hostname==='app';
14
+ // The ?host=dsh-desktop marker only asks the board page to report its top-bar
15
+ // geometry; the backend's iframe admission checks the pathname, not the query.
16
+ function boardUrl(port,where){const loc=where||location;if(LOOPBACK.includes(loc.hostname)&&(loc.protocol==='http:'||loc.protocol==='https:'))return`http://${loc.hostname}:${port}/`;if(isDesktop(loc))return`http://127.0.0.1:${port}/?host=dsh-desktop`;return null}
17
+ // DSH desktop (DSH插件 4.1): Electron ignores -webkit-app-region inside the
18
+ // cross-origin board iframe, so the host lays a transparent drag layer over the
19
+ // board's top bar. The layer has pointer-events:none and holes (no-drag) over
20
+ // the bar's controls: the window drag is decided by geometry, every other
21
+ // click falls through to the iframe. Geometry comes only from the board frame
22
+ // itself (origin http://127.0.0.1:<port> and source === that frame's window);
23
+ // without a valid message there is no layer, so nothing can block clicks.
24
+ const MAX_HOLES=32;
25
+ function box(v,limit){if(!Array.isArray(v)||v.length!==4||!v.every(n=>typeof n==='number'&&Number.isFinite(n)))return null;const[x,y,w,hh]=v;if(w<=0||hh<=0||w>limit||hh>limit||Math.abs(x)>limit||Math.abs(y)>limit)return null;return{left:x,top:y,width:w,height:hh}}
26
+ function readDragRegion(event,expectedOrigin,frameWindow){
27
+ if(event.origin!==expectedOrigin||!frameWindow||event.source!==frameWindow)return null;
28
+ const d=event.data;if(!d||typeof d!=='object'||d.type!=='theater-board:drag-region'||d.version!==1)return null;
29
+ const bar=box(d.bar,20000);if(!bar||bar.height>200)return null;
30
+ if(!Array.isArray(d.holes)||d.holes.length>MAX_HOLES)return null;
31
+ const holes=d.holes.map(v=>box(v,20000));if(holes.some(v=>!v))return null;
32
+ return{bar,holes}}
33
+ const abs=r=>({position:'absolute',left:r.left,top:r.top,width:r.width,height:r.height,pointerEvents:'none'});
34
+ function DragLayer({region}){
35
+ return h(React.Fragment,null,h('div',{'data-theater-drag':'bar',style:{...abs(region.bar),WebkitAppRegion:'drag'}}),
36
+ ...region.holes.map((r,i)=>h('div',{key:i,'data-theater-drag':'hole',style:{...abs(r),WebkitAppRegion:'no-drag'}})))}
14
37
  function makePage(readPort){return function TheaterBoardPage(){
15
38
  const port=readPort();const src=boardUrl(port);
39
+ const desktop=!!src&&isDesktop(location);
40
+ const frame=React.useRef(null);const[region,setRegion]=React.useState(null);
41
+ React.useEffect(()=>{if(!desktop)return;const origin=`http://127.0.0.1:${port}`;
42
+ const onMessage=event=>{const next=readDragRegion(event,origin,frame.current&&frame.current.contentWindow);if(next)setRegion(next)};
43
+ window.addEventListener('message',onMessage);return()=>window.removeEventListener('message',onMessage)},[desktop,port]);
16
44
  if(!src)return h('div',{style:{padding:32,lineHeight:1.7}},'战区看板只能在本机的 DeepSeek Harness 中使用(桌面版,或地址为 127.0.0.1 / localhost 的网页版)。');
17
- return h('iframe',{src,title:'战区经营看板',style:{display:'block',width:'100%',height:'100%',border:0,background:'#fff'}})}}
45
+ const iframe=h('iframe',{ref:frame,src,title:'战区经营看板',style:{display:'block',width:'100%',height:'100%',border:0,background:'#fff'}});
46
+ if(!desktop)return iframe;
47
+ return h('div',{style:{position:'relative',width:'100%',height:'100%'}},iframe,region?h(DragLayer,{region}):null)}}
18
48
  const inject=['slots'];
19
49
  function apply(ctx,config){
20
50
  const readPort=()=>{try{const v=config&&config.port&&config.port.get();return Number.isInteger(v)?v:DEFAULT_PORT}catch{return DEFAULT_PORT}};
21
51
  ctx.slots.inject('main',()=>ctx.slots.register({name:'main',key:PANEL_ID},makePage(readPort)));
22
52
  ctx.slots.inject('sidebar.panellist',()=>ctx.slots.register({name:'sidebar.panellist',id:PANEL_ID,order:50,label:'战区看板'},BoardIcon));
23
53
  }
24
- exports.apply=apply;exports.inject=inject;exports.boardUrl=boardUrl;return module.exports}});
54
+ exports.apply=apply;exports.inject=inject;exports.boardUrl=boardUrl;exports.readDragRegion=readDragRegion;return module.exports}});
@@ -17,7 +17,7 @@ export function toolDefinitions(queries, { HarnessError } = {}) {
17
17
  return [
18
18
  {
19
19
  name: 'theater_board_status',
20
- description: `战区经营看板:查看七类资料(发票、动销、开瓶、签约、库存、宴席、经营目标)的当前文件、上传时间、数据起止日、是否超期待更新,以及最近一次生成的看板时间和打开链接。${shared}`,
20
+ description: `战区经营看板:查看各类资料(发票、藏10与吞之乎平台销售、动销、分销商动销、开瓶、签约、库存、宴席、经营目标)的当前文件、上传时间、数据起止日、是否超期待更新,以及最近一次生成的看板时间和打开链接。${shared}`,
21
21
  parameters: {},
22
22
  output: { schema: json, render },
23
23
  isConcurrencySafe: () => true,
@@ -26,7 +26,7 @@ export function toolDefinitions(queries, { HarnessError } = {}) {
26
26
  },
27
27
  {
28
28
  name: 'theater_board_summary',
29
- description: `战区经营看板:按月份或日期区间、大区/办事处/主任单元,返回发票销售、终端动销、消费者开瓶的主指标、当年累计和经营目标达成率(与看板同一口径)。三个板块分别统计,不要自行计算它们之间的比例。组织名称请先用 theater_board_organizations 确认。${shared}`,
29
+ description: `战区经营看板:按月份或日期区间、大区/办事处/主任单元,返回发票销售(含藏10、吞之乎平台)、终端动销、消费者开瓶的主指标、季度与财年累计和经营目标达成率(与看板同一口径)。三个板块分别统计,不要自行计算它们之间的比例。组织名称请先用 theater_board_organizations 确认。${shared}`,
30
30
  parameters: {
31
31
  month: { type: 'string', description: '月份 YYYY-MM;与 start/end 二选一;都不填为看板默认最近月份' },
32
32
  start: { type: 'string', description: '区间开始 YYYY-MM-DD(需与 end 同时给出)' },
package/lib/tools.mjs CHANGED
@@ -231,7 +231,11 @@ export function createBoardQueries({ dataDir, backendDir, port, problem = () =>
231
231
  modules[id] = {
232
232
  title: m.title, state: m.state, main: shape(m.main, model),
233
233
  ...(id === 'opening' ? {} : { ytd: shape(m.extra.find(item => item.label === '当年截至所选月来源金额'), model) }),
234
- targets: { attainment: shape(t.attainment, model), ytdAttainment: shape(t.ytdAttainment, model), target: shape(t.month, model), ytdTarget: shape(t.ytd, model) },
234
+ targets: { attainment: shape(t.attainment, model), ytdAttainment: shape(t.ytdAttainment, model), target: shape(t.month, model), ytdTarget: shape(t.ytd, model),
235
+ // 2026-11-27:公司按季度考核,季度与财年(7 月起)累计达成与看板首屏同一口径。
236
+ ...Object.fromEntries(['quarter', 'fiscal'].filter(kind => t[kind]).map(kind => [kind, { label: t[kind].label, start: t[kind].start, end: t[kind].periodEnd,
237
+ actual: shape(t[kind].actual, model), target: shape(t[kind].target, model), attainment: shape(t[kind].attainment, model) }])) },
238
+ ...(id === 'invoice' && m.platformSources ? { sources: m.platformSources.map(item => ({ key: item.key, label: item.label, records: item.records, value: shape(item, model) })) } : {}),
235
239
  records: m.recordCount, notes: [...m.pending],
236
240
  };
237
241
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-data-dashboard",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "license": "UNLICENSED",
5
5
  "description": "战区经营看板 DSH 插件:在 DeepSeek Harness 左侧栏打开本机战区看板(看板 / 更新数据 / 历史版本)",
6
6
  "type": "module",