saibo-kanban 0.4.0 → 0.4.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.1
4
+
5
+ - 导入改为页面操作:看板面板 → 「导入 xlsx」→ 选文件 → 预览数量 → 确认导入。
6
+ - 导入映射抽到 `lib/import-map.js`,页面与 CLI 共用;导入按「范围 + 标题」去重。
7
+
3
8
  ## 0.4.0
4
9
 
5
10
  - 新增 xlsx 导入:`node bin/import.mjs --xlsx <文件> [--dry-run]`。
package/README.md CHANGED
@@ -63,14 +63,18 @@ node bin/board.mjs show <id>
63
63
  node bin/board.mjs brief
64
64
  ```
65
65
 
66
- **导入 xlsx**
66
+ **页面导入(推荐)**
67
+
68
+ 看板面板 → 右上角「导入 xlsx」→ 选择文件 → 看预览(主表 / 滚动项 / 节点说明各多少条)→ 确认导入。
69
+
70
+ **命令行导入**
67
71
 
68
72
  ```bash
69
- node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" --dry-run # 先看映射
70
- node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" # 真正写入
73
+ node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" --dry-run
74
+ node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx"
71
75
  ```
72
76
 
73
- 主表进归档(历史台账),长期滚动项进活跃列,节点说明合成一条 design 资产。
77
+ 主表进归档(历史台账),长期滚动项进活跃列,节点说明合成一条 design 资产;重复条目按「范围 + 标题」跳过。
74
78
 
75
79
  ## 工具
76
80
 
package/bin/import.mjs CHANGED
@@ -1,19 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * 导入 xlsx 到看板。
3
+ * 命令行导入(页面导入之外的备用入口)。
4
4
  *
5
5
  * node bin/import.mjs --xlsx "C:\path\开发任务管理看板.xlsx" --dry-run
6
6
  * node bin/import.mjs --xlsx "..." --data-dir "C:\...\.dsh\saibo_kanban"
7
7
  *
8
- * 规则:
9
- * - 任务主表:全部导入为已归档(历史台账),状态 done
10
- * - 长期滚动项:导入为活跃条目,按状态映射
11
- * - 节点说明:整页文本合成一条 design 资产
8
+ * 页面操作是主路径:看板面板 → 导入 → 选择 xlsx。
12
9
  */
13
10
  import path from 'node:path';
14
11
  import { readXlsx } from '../lib/xlsx.js';
12
+ import { buildImport, describeImport } from '../lib/import-map.js';
15
13
  import { Store, defaultDataDir } from '../store.js';
16
- import { normalizeKinds, STATUSES } from '../core.js';
14
+ import { normalizeKinds } from '../core.js';
17
15
 
18
16
  const argv = process.argv.slice(2);
19
17
  const flags = {};
@@ -31,169 +29,38 @@ if (!file) {
31
29
  console.error('用法: node bin/import.mjs --xlsx <文件> [--dry-run] [--data-dir <目录>]');
32
30
  process.exit(1);
33
31
  }
34
- const dryRun = flags['dry-run'] === true;
35
- const dataDir = flags['data-dir'] || defaultDataDir();
36
-
37
- const STATUS_MAP = {
38
- DONE: 'done',
39
- 'DONE(描述修正)': 'done',
40
- 'DONE(已覆盖)': 'done',
41
- TODO: 'todo',
42
- PARTIAL: 'in_progress',
43
- FIX: 'in_progress',
44
- BLOCKED: 'blocked',
45
- 暂缓: 'backlog'
46
- };
47
-
48
- const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
49
-
50
- function headerIndex(rows, name) {
51
- for (let i = 0; i < Math.min(rows.length, 5); i += 1) {
52
- if ((rows[i] || []).some(v => String(v).trim() === name)) return i;
53
- }
54
- return 1;
55
- }
56
-
57
- function col(rows, headerRow, name) {
58
- const row = rows[headerRow] || [];
59
- for (let i = 0; i < row.length; i += 1) if (String(row[i]).trim() === name) return i;
60
- return -1;
61
- }
62
-
63
- function cell(row, idx) {
64
- if (idx < 0) return '';
65
- const v = row[idx];
66
- return v === undefined || v === null ? '' : String(v).trim();
67
- }
68
-
69
- function mapMain(rows) {
70
- const h = headerIndex(rows, '编号');
71
- const cId = col(rows, h, '编号');
72
- const cGroup = col(rows, h, '分组');
73
- const cTitle = col(rows, h, '名称');
74
- const cBody = col(rows, h, '详细说明');
75
- const cStatus = col(rows, h, '状态');
76
- const cType = col(rows, h, '类型');
77
- const out = [];
78
- for (let i = h + 1; i < rows.length; i += 1) {
79
- const title = cell(rows[i], cTitle);
80
- if (!title) continue;
81
- const status = STATUS_MAP[cell(rows[i], cStatus)] || 'done';
82
- out.push({
83
- title,
84
- body: [
85
- cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
86
- cell(rows[i], cType) ? `类型:${cell(rows[i], cType)}` : '',
87
- cell(rows[i], cBody)
88
- ].filter(Boolean).join('\n'),
89
- kind: 'task',
90
- scope: cell(rows[i], cGroup),
91
- status,
92
- archived: true,
93
- ext: cell(rows[i], cId)
94
- });
95
- }
96
- return out;
97
- }
98
-
99
- function mapRolling(rows) {
100
- const h = headerIndex(rows, '编号');
101
- const cId = col(rows, h, '编号');
102
- const cGroup = col(rows, h, '分组');
103
- const cTitle = col(rows, h, '名称');
104
- const cBody = col(rows, h, '详细说明');
105
- const cStatus = col(rows, h, '状态');
106
- const cPri = col(rows, h, '优先级');
107
- const cRoll = col(rows, h, '滚动次数');
108
- const cFirst = col(rows, h, '首次来源');
109
- const cLast = col(rows, h, '最近来源');
110
- const out = [];
111
- for (let i = h + 1; i < rows.length; i += 1) {
112
- const title = cell(rows[i], cTitle);
113
- if (!title) continue;
114
- const status = STATUS_MAP[cell(rows[i], cStatus)] || 'todo';
115
- out.push({
116
- title,
117
- body: [
118
- cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
119
- cell(rows[i], cBody),
120
- cell(rows[i], cPri) ? `优先级:${cell(rows[i], cPri)}` : '',
121
- cell(rows[i], cRoll) ? `滚动次数:${cell(rows[i], cRoll)}` : '',
122
- cell(rows[i], cFirst) ? `首次来源:${cell(rows[i], cFirst)}` : '',
123
- cell(rows[i], cLast) ? `最近来源:${cell(rows[i], cLast)}` : ''
124
- ].filter(Boolean).join('\n'),
125
- kind: 'task',
126
- scope: cell(rows[i], cGroup),
127
- status,
128
- archived: false,
129
- ext: cell(rows[i], cId)
130
- });
131
- }
132
- return out;
133
- }
134
-
135
- function mapNotes(rows) {
136
- const text = rows.map(r => cell(r, 0)).join('\n').trim();
137
- if (!text) return null;
138
- const firstLine = text.split('\n').find(l => l.trim()) || '节点说明';
139
- return {
140
- title: firstLine.replace(/^#+\s*/, '').slice(0, 120),
141
- body: text,
142
- kind: 'design',
143
- scope: '设计',
144
- status: 'done',
145
- archived: false,
146
- ext: 'nodes'
147
- };
148
- }
149
32
 
150
33
  const sheets = readXlsx(file);
151
- const byName = new Map(sheets.map(s => [s.name, s.rows]));
152
- const mainRows = byName.get('任务主表') || sheets[0]?.rows || [];
153
- const rollingRows = byName.get('长期滚动项') || sheets[1]?.rows || [];
154
- const notesRows = byName.get('节点说明') || sheets[2]?.rows || [];
155
-
156
- const main = mapMain(mainRows);
157
- const rolling = mapRolling(rollingRows);
158
- const notes = mapNotes(notesRows);
159
-
34
+ const plan = buildImport(sheets);
35
+ const desc = describeImport(plan);
160
36
  console.log(`文件:${file}`);
161
- console.log(`主表 ${main.length} 条(归档,done)`);
162
- console.log(`滚动项 ${rolling.length} 条(活跃)`);
163
- console.log(`节点说明:${notes ? '1 条' : '无'}`);
164
- console.log('状态分布:', Object.fromEntries([...new Set(rolling.map(r => r.status))].map(s => [statusLabel(s), rolling.filter(r => r.status === s).length])));
165
-
166
- const titles = new Map();
167
- for (const r of rolling) titles.set(r.title, (titles.get(r.title) || 0) + 1);
168
- const dup = [...titles.entries()].filter(([, n]) => n > 1);
169
- console.log(`滚动项重名:${dup.length} 组`);
37
+ console.log(`主表 ${desc.main} 条(归档,done)`);
38
+ console.log(`滚动项 ${desc.rolling} 条(活跃)`);
39
+ console.log(`节点说明:${desc.notes} 条`);
40
+ console.log('状态分布:', desc.byStatus);
170
41
  console.log('样例:');
171
- for (const r of rolling.slice(0, 2)) console.log(' -', r.status, '|', r.scope, '|', r.title);
172
- for (const r of main.slice(0, 1)) console.log(' -', r.status, '|', r.scope, '|', r.title, '(归档)');
42
+ for (const s of desc.samples) console.log(' -', s.status, '|', s.scope, '|', s.title);
173
43
 
174
- if (dryRun) {
175
- console.log('\n--dry-run:不写入。去掉 --dry-run 才导入。');
44
+ if (flags['dry-run'] === true) {
45
+ console.log('\n--dry-run:不写入。');
176
46
  process.exit(0);
177
47
  }
178
48
 
49
+ const dataDir = flags['data-dir'] || defaultDataDir();
179
50
  const store = new Store({ dataDir, kinds: normalizeKinds(null) }).load();
180
- let written = 0;
181
- for (const item of main) {
51
+ const existing = new Set([...store.items.values()].map(i => `${i.scope}|${i.title}`));
52
+ let imported = 0;
53
+ let skipped = 0;
54
+ const write = (item, note) => {
55
+ if (existing.has(`${item.scope}|${item.title}`)) { skipped += 1; return; }
182
56
  const created = store.record({
183
57
  title: item.title, kind: item.kind, scope: item.scope, body: item.body, status: item.status
184
- }, { by: 'human', note: '导入:任务主表' });
185
- store.archive(created.id, { by: 'human', note: '导入历史台账' });
186
- written += 1;
187
- }
188
- for (const item of rolling) {
189
- store.record({
190
- title: item.title, kind: item.kind, scope: item.scope, body: item.body, status: item.status
191
- }, { by: 'human', note: '导入:长期滚动项' });
192
- written += 1;
193
- }
194
- if (notes) {
195
- store.record({ title: notes.title, kind: notes.kind, scope: notes.scope, body: notes.body, status: notes.status },
196
- { by: 'human', note: '导入:节点说明' });
197
- written += 1;
198
- }
199
- console.log(`\n已导入 ${written} 条到 ${path.join(dataDir, 'records.jsonl')}`);
58
+ }, { by: 'human', note });
59
+ if (item.archived) store.archive(created.id, { by: 'human', note: '导入历史台账' });
60
+ existing.add(`${item.scope}|${item.title}`);
61
+ imported += 1;
62
+ };
63
+ for (const item of plan.main) write(item, '导入:任务主表');
64
+ for (const item of plan.rolling) write(item, '导入:长期滚动项');
65
+ if (plan.notes) write(plan.notes, '导入:节点说明');
66
+ console.log(`\n已导入 ${imported} 条,跳过重复 ${skipped} 条 → ${path.join(dataDir, 'records.jsonl')}`);
package/client.js CHANGED
@@ -23,8 +23,17 @@ window.__ModuleLoader__.load({
23
23
  const kindLabel = id => (KINDS.find(k => k.id === id) || { label: id }).label;
24
24
  const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
25
25
 
26
- async function api(method, args) {
27
- const res = await fetch('/saibo-kanban/api', {
26
+ function toBase64(buf) {
27
+ const bytes = new Uint8Array(buf);
28
+ let s = '';
29
+ const chunk = 0x8000;
30
+ for (let i = 0; i < bytes.length; i += chunk) {
31
+ s += String.fromCharCode.apply(null, bytes.subarray(i, i + chunk));
32
+ }
33
+ return btoa(s);
34
+ }
35
+
36
+ async function api(method, args) { const res = await fetch('/saibo-kanban/api', {
28
37
  method: 'POST',
29
38
  headers: { 'content-type': 'application/json' },
30
39
  body: JSON.stringify({ method, args: args || {} })
@@ -86,6 +95,14 @@ window.__ModuleLoader__.load({
86
95
  .sk-toast { position:absolute; left:50%; bottom:18px; transform:translateX(-50%); background:var(--dsw-alias-label-primary,#17181a); color:var(--dsw-alias-bg-base,#fff); padding:8px 14px; border-radius:9px; font-size:12.5px; z-index:9; }
87
96
  .sk-empty { padding:40px; text-align:center; color:var(--dsw-alias-label-secondary,#6b7280); }
88
97
  .sk-rail { display:flex; align-items:center; justify-content:center; }
98
+ .sk-modal { position:absolute; inset:0; background:rgba(15,18,25,.35); display:flex; align-items:center; justify-content:center; z-index:8; }
99
+ .sk-dialog { width:min(520px,92%); background:var(--dsw-alias-bg-layer-1,#fff); border:1px solid var(--dsw-alias-border-l1,#e6e7eb); border-radius:12px; box-shadow:0 18px 48px rgba(16,24,40,.22); padding:16px; display:flex; flex-direction:column; gap:10px; }
100
+ .sk-dialog h3 { margin:0; font-size:15px; }
101
+ .sk-dialog .hint { color:var(--dsw-alias-label-secondary,#6b7280); font-size:12px; line-height:1.6; }
102
+ .sk-dialog .row { display:flex; gap:8px; justify-content:flex-end; }
103
+ .sk-dialog input[type=file] { font:inherit; font-size:12.5px; }
104
+ .sk-kv { display:flex; gap:12px; flex-wrap:wrap; font-size:12.5px; }
105
+ .sk-kv b { font-weight:650; }
89
106
  `;
90
107
 
91
108
  function Panel() {
@@ -99,6 +116,10 @@ window.__ModuleLoader__.load({
99
116
  const [overCol, setOverCol] = useState(null);
100
117
  const [toast, setToast] = useState('');
101
118
  const [busy, setBusy] = useState(false);
119
+ const [imp, setImp] = useState(null);
120
+ const [impBusy, setImpBusy] = useState(false);
121
+ const [impError, setImpError] = useState('');
122
+ const fileRef = useRef(null);
102
123
  const toastTimer = useRef(null);
103
124
 
104
125
  const say = useCallback(msg => {
@@ -168,6 +189,24 @@ window.__ModuleLoader__.load({
168
189
  h('input', {
169
190
  className: 'sk-search', placeholder: '搜索标题 / 编号 / 范围',
170
191
  value: query, onChange: e => setQuery(e.target.value)
192
+ }),
193
+ h('button', { className: 'sk-btn', onClick: () => fileRef.current && fileRef.current.click() }, '导入 xlsx'),
194
+ h('input', {
195
+ ref: fileRef, type: 'file', accept: '.xlsx', style: { display: 'none' },
196
+ onChange: async e => {
197
+ const file = e.target.files && e.target.files[0];
198
+ e.target.value = '';
199
+ if (!file) return;
200
+ setImpBusy(true); setImpError('');
201
+ try {
202
+ const buf = await file.arrayBuffer();
203
+ const data = toBase64(buf);
204
+ const r = await api('import.preview', { data });
205
+ setImp({ name: file.name, data, summary: r.summary });
206
+ } catch (err) {
207
+ setImp({ name: file.name, data: null, summary: null, error: err.message });
208
+ } finally { setImpBusy(false); }
209
+ }
171
210
  })
172
211
  );
173
212
 
@@ -331,10 +370,40 @@ window.__ModuleLoader__.load({
331
370
  )
332
371
  ) : null;
333
372
 
373
+ const importDialog = imp ? h('div', { className: 'sk-modal' },
374
+ h('div', { className: 'sk-dialog' },
375
+ h('h3', null, '导入 ' + (imp.name || 'xlsx')),
376
+ imp.error ? h('div', { className: 'hint', style: { color: 'var(--dsw-alias-state-error-primary,#dc2626)' } }, imp.error) : null,
377
+ imp.summary ? h('div', { className: 'sk-kv' },
378
+ h('span', null, '主表 ', h('b', null, String(imp.summary.main)), ' 条(归档)'),
379
+ h('span', null, '滚动项 ', h('b', null, String(imp.summary.rolling)), ' 条(活跃)'),
380
+ h('span', null, '节点说明 ', h('b', null, String(imp.summary.notes)), ' 条')
381
+ ) : h('div', { className: 'hint' }, impBusy ? '解析中…' : ''),
382
+ imp.summary ? h('div', { className: 'hint' },
383
+ Object.entries(imp.summary.byStatus || {}).map(([k, v]) => k + ' ' + v).join(' · ')) : null,
384
+ h('div', { className: 'row' },
385
+ h('button', { className: 'sk-btn', onClick: () => { setImp(null); setImpError(''); } }, '取消'),
386
+ imp.summary ? h('button', {
387
+ className: 'sk-btn primary',
388
+ onClick: async () => {
389
+ setImpBusy(true); setImpError('');
390
+ try {
391
+ const r = await api('import.apply', { data: imp.data });
392
+ setImp(null); await load();
393
+ say('已导入 ' + r.imported + ' 条,跳过重复 ' + r.skipped + ' 条');
394
+ } catch (err) { setImpError(err.message); }
395
+ finally { setImpBusy(false); }
396
+ }
397
+ }, impBusy ? '导入中…' : '确认导入') : null
398
+ )
399
+ )
400
+ ) : null;
401
+
334
402
  return h('div', { className: 'sk', style: { position: 'relative' } },
335
403
  h('style', null, CSS),
336
404
  head,
337
405
  h('div', { className: 'sk-body' }, error ? h('div', { className: 'sk-empty', style: { color: 'var(--dsw-alias-state-error-primary,#dc2626)' } }, error) : content),
406
+ importDialog,
338
407
  drawer,
339
408
  toast ? h('div', { className: 'sk-toast' }, toast) : null
340
409
  );
package/index.js CHANGED
@@ -8,6 +8,8 @@
8
8
  import { Store, defaultDataDir } from './store.js';
9
9
  import { createTools } from './tools.js';
10
10
  import { normalizeKinds } from './core.js';
11
+ import { readXlsxBuffer } from './lib/xlsx.js';
12
+ import { buildImport, describeImport } from './lib/import-map.js';
11
13
 
12
14
  export const inject = ['tools', 'webServer'];
13
15
 
@@ -96,6 +98,14 @@ function dispatch(store, method, args) {
96
98
  case 'brief': {
97
99
  return { markdown: store.brief({}) };
98
100
  }
101
+ case 'import.preview': {
102
+ const plan = buildImport(readXlsxBuffer(decodeData(args.data)));
103
+ return { summary: describeImport(plan) };
104
+ }
105
+ case 'import.apply': {
106
+ const plan = buildImport(readXlsxBuffer(decodeData(args.data)));
107
+ return applyPlan(store, plan);
108
+ }
99
109
  default:
100
110
  throw new Error(`未知方法: ${method}`);
101
111
  }
@@ -117,6 +127,30 @@ function publicItem(item) {
117
127
  };
118
128
  }
119
129
 
130
+ function decodeData(data) {
131
+ if (typeof data !== 'string' || data.length < 16) throw new Error('没有收到文件内容');
132
+ return Buffer.from(data, 'base64');
133
+ }
134
+
135
+ function applyPlan(store, plan) {
136
+ const existing = new Set([...store.items.values()].map(i => `${i.scope}|${i.title}`));
137
+ let imported = 0;
138
+ let skipped = 0;
139
+ const write = (item, note) => {
140
+ if (existing.has(`${item.scope}|${item.title}`)) { skipped += 1; return; }
141
+ const created = store.record({
142
+ title: item.title, kind: item.kind, scope: item.scope, body: item.body, status: item.status
143
+ }, { by: 'human', note });
144
+ if (item.archived) store.archive(created.id, { by: 'human', note: '导入历史台账' });
145
+ existing.add(`${item.scope}|${item.title}`);
146
+ imported += 1;
147
+ };
148
+ for (const item of plan.main) write(item, '导入:任务主表');
149
+ for (const item of plan.rolling) write(item, '导入:长期滚动项');
150
+ if (plan.notes) write(plan.notes, '导入:节点说明');
151
+ return { imported, skipped, summary: describeImport(plan) };
152
+ }
153
+
120
154
  function readJsonBody(req) {
121
155
  return new Promise((resolve, reject) => {
122
156
  let body = '';
@@ -0,0 +1,145 @@
1
+ /**
2
+ * import-map.js — xlsx 工作表 → 看板条目的映射规则。
3
+ *
4
+ * CLI 和页面共用这一份,避免两边规则漂移。
5
+ */
6
+ import { STATUSES } from '../core.js';
7
+
8
+ export const STATUS_MAP = {
9
+ DONE: 'done',
10
+ 'DONE(描述修正)': 'done',
11
+ 'DONE(已覆盖)': 'done',
12
+ TODO: 'todo',
13
+ PARTIAL: 'in_progress',
14
+ FIX: 'in_progress',
15
+ BLOCKED: 'blocked',
16
+ 暂缓: 'backlog'
17
+ };
18
+
19
+ const statusLabel = id => (STATUSES.find(s => s.id === id) || { label: id }).label;
20
+
21
+ function headerIndex(rows, name) {
22
+ for (let i = 0; i < Math.min(rows.length, 5); i += 1) {
23
+ if ((rows[i] || []).some(v => String(v).trim() === name)) return i;
24
+ }
25
+ return 1;
26
+ }
27
+
28
+ function col(rows, headerRow, name) {
29
+ const row = rows[headerRow] || [];
30
+ for (let i = 0; i < row.length; i += 1) if (String(row[i]).trim() === name) return i;
31
+ return -1;
32
+ }
33
+
34
+ function cell(row, idx) {
35
+ if (idx < 0) return '';
36
+ const v = row[idx];
37
+ return v === undefined || v === null ? '' : String(v).trim();
38
+ }
39
+
40
+ export function mapMain(rows) {
41
+ const h = headerIndex(rows, '编号');
42
+ const cId = col(rows, h, '编号');
43
+ const cGroup = col(rows, h, '分组');
44
+ const cTitle = col(rows, h, '名称');
45
+ const cBody = col(rows, h, '详细说明');
46
+ const cStatus = col(rows, h, '状态');
47
+ const cType = col(rows, h, '类型');
48
+ const out = [];
49
+ for (let i = h + 1; i < rows.length; i += 1) {
50
+ const title = cell(rows[i], cTitle);
51
+ if (!title) continue;
52
+ out.push({
53
+ title,
54
+ body: [
55
+ cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
56
+ cell(rows[i], cType) ? `类型:${cell(rows[i], cType)}` : '',
57
+ cell(rows[i], cBody)
58
+ ].filter(Boolean).join('\n'),
59
+ kind: 'task',
60
+ scope: cell(rows[i], cGroup),
61
+ status: STATUS_MAP[cell(rows[i], cStatus)] || 'done',
62
+ archived: true,
63
+ ext: cell(rows[i], cId)
64
+ });
65
+ }
66
+ return out;
67
+ }
68
+
69
+ export function mapRolling(rows) {
70
+ const h = headerIndex(rows, '编号');
71
+ const cId = col(rows, h, '编号');
72
+ const cGroup = col(rows, h, '分组');
73
+ const cTitle = col(rows, h, '名称');
74
+ const cBody = col(rows, h, '详细说明');
75
+ const cStatus = col(rows, h, '状态');
76
+ const cPri = col(rows, h, '优先级');
77
+ const cRoll = col(rows, h, '滚动次数');
78
+ const cFirst = col(rows, h, '首次来源');
79
+ const cLast = col(rows, h, '最近来源');
80
+ const out = [];
81
+ for (let i = h + 1; i < rows.length; i += 1) {
82
+ const title = cell(rows[i], cTitle);
83
+ if (!title) continue;
84
+ out.push({
85
+ title,
86
+ body: [
87
+ cell(rows[i], cId) ? `编号:${cell(rows[i], cId)}` : '',
88
+ cell(rows[i], cBody),
89
+ cell(rows[i], cPri) ? `优先级:${cell(rows[i], cPri)}` : '',
90
+ cell(rows[i], cRoll) ? `滚动次数:${cell(rows[i], cRoll)}` : '',
91
+ cell(rows[i], cFirst) ? `首次来源:${cell(rows[i], cFirst)}` : '',
92
+ cell(rows[i], cLast) ? `最近来源:${cell(rows[i], cLast)}` : ''
93
+ ].filter(Boolean).join('\n'),
94
+ kind: 'task',
95
+ scope: cell(rows[i], cGroup),
96
+ status: STATUS_MAP[cell(rows[i], cStatus)] || 'todo',
97
+ archived: false,
98
+ ext: cell(rows[i], cId)
99
+ });
100
+ }
101
+ return out;
102
+ }
103
+
104
+ export function mapNotes(rows) {
105
+ const text = rows.map(r => cell(r, 0)).join('\n').trim();
106
+ if (!text) return null;
107
+ const firstLine = text.split('\n').find(l => l.trim()) || '节点说明';
108
+ return {
109
+ title: firstLine.replace(/^#+\s*/, '').slice(0, 120),
110
+ body: text,
111
+ kind: 'design',
112
+ scope: '设计',
113
+ status: 'done',
114
+ archived: false,
115
+ ext: 'nodes'
116
+ };
117
+ }
118
+
119
+ /** 把工作簿整理成待导入集合。 */
120
+ export function buildImport(sheets) {
121
+ const byName = new Map(sheets.map(s => [s.name, s.rows]));
122
+ const mainRows = byName.get('任务主表') || sheets[0]?.rows || [];
123
+ const rollingRows = byName.get('长期滚动项') || sheets[1]?.rows || [];
124
+ const notesRows = byName.get('节点说明') || sheets[2]?.rows || [];
125
+ return {
126
+ main: mapMain(mainRows),
127
+ rolling: mapRolling(rollingRows),
128
+ notes: mapNotes(notesRows)
129
+ };
130
+ }
131
+
132
+ export function describeImport({ main, rolling, notes }) {
133
+ const byStatus = {};
134
+ for (const item of rolling) {
135
+ const label = statusLabel(item.status);
136
+ byStatus[label] = (byStatus[label] || 0) + 1;
137
+ }
138
+ return {
139
+ main: main.length,
140
+ rolling: rolling.length,
141
+ notes: notes ? 1 : 0,
142
+ byStatus,
143
+ samples: rolling.slice(0, 5).map(r => ({ title: r.title, scope: r.scope, status: r.status }))
144
+ };
145
+ }
package/lib/xlsx.js CHANGED
@@ -124,7 +124,11 @@ function readSheet(xml, shared) {
124
124
 
125
125
  /** 读取工作簿,返回 [{ name, rows }],rows 为二维字符串数组。 */
126
126
  export function readXlsx(file) {
127
- const buf = fs.readFileSync(file);
127
+ return readXlsxBuffer(fs.readFileSync(file));
128
+ }
129
+
130
+ /** 从内存读取工作簿(页面导入用)。 */
131
+ export function readXlsxBuffer(buf) {
128
132
  const entries = readEntries(buf);
129
133
  const shared = readSharedStrings(readFile(buf, entries, 'xl/sharedStrings.xml'));
130
134
  const workbook = readFile(buf, entries, 'xl/workbook.xml');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saibo-kanban",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "AI 与人共用的活看板:草稿进收件箱、人做分拣、字段级修订可回滚,零 token 纠错。",
5
5
  "keywords": [
6
6
  "dsh",