tor-univer-sheet 1.0.14 → 1.0.16

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.
@@ -1,29 +1,28 @@
1
1
  import h from "dayjs";
2
- import { CellValueType as P } from "@univerjs/presets";
3
- import A from "decimal.js";
4
- import { read as V, utils as F } from "xlsx";
5
- const et = (t, e) => {
6
- for (const o of e)
7
- t[o] = null;
2
+ import { CellValueType as O } from "@univerjs/presets";
3
+ import G from "decimal.js";
4
+ const X = (t, o) => {
5
+ for (const e of o)
6
+ t[e] = null;
8
7
  }, q = () => {
9
8
  if (typeof crypto == "object") {
10
9
  if (typeof crypto.randomUUID == "function")
11
10
  return crypto.randomUUID();
12
11
  if (typeof crypto.getRandomValues == "function" && typeof Uint8Array == "function") {
13
- const o = (r) => {
14
- const s = Number(r);
15
- return (s ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> s / 4).toString(16);
12
+ const e = (r) => {
13
+ const i = Number(r);
14
+ return (i ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> i / 4).toString(16);
16
15
  };
17
- return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, o);
16
+ return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, e);
18
17
  }
19
18
  }
20
- let t = (/* @__PURE__ */ new Date()).getTime(), e = typeof performance < "u" && performance.now && performance.now() * 1e3 || 0;
21
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (o) => {
19
+ let t = (/* @__PURE__ */ new Date()).getTime(), o = typeof performance < "u" && performance.now && performance.now() * 1e3 || 0;
20
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
22
21
  let r = Math.random() * 16;
23
- return t > 0 ? (r = (t + r) % 16 | 0, t = Math.floor(t / 16)) : (r = (e + r) % 16 | 0, e = Math.floor(e / 16)), (o === "x" ? r : r & 3 | 8).toString(16);
22
+ return t > 0 ? (r = (t + r) % 16 | 0, t = Math.floor(t / 16)) : (r = (o + r) % 16 | 0, o = Math.floor(o / 16)), (e === "x" ? r : r & 3 | 8).toString(16);
24
23
  });
25
24
  };
26
- function rt(t) {
25
+ function E(t) {
27
26
  return {
28
27
  ...t?.workbookData,
29
28
  id: t?.id || q(),
@@ -31,35 +30,35 @@ function rt(t) {
31
30
  appVersion: t?.appVersion || "1.0.0"
32
31
  };
33
32
  }
34
- const B = Object.prototype.toString, G = (t, e) => B.call(t) === `[object ${e}]`, $ = (t) => t !== null && G(t, "Object"), _ = (t) => t == null || typeof t > "u" ? !0 : R(t) || z(t) ? t.length === 0 : t instanceof Map || t instanceof Set ? t.size === 0 : $(t) ? Object.keys(t).length === 0 : !1, z = (t) => G(t, "String"), R = (t) => t && Array.isArray(t);
35
- class E {
33
+ const F = Object.prototype.toString, V = (t, o) => F.call(t) === `[object ${o}]`, $ = (t) => t !== null && V(t, "Object"), J = (t) => t == null || typeof t > "u" ? !0 : R(t) || z(t) ? t.length === 0 : t instanceof Map || t instanceof Set ? t.size === 0 : $(t) ? Object.keys(t).length === 0 : !1, z = (t) => V(t, "String"), R = (t) => t && Array.isArray(t);
34
+ class Z {
36
35
  value;
37
- constructor(e) {
38
- this.value = new A(e);
36
+ constructor(o) {
37
+ this.value = new G(o);
39
38
  }
40
39
  /**
41
40
  * 加法运算
42
41
  * @param num 要加的数
43
42
  * @returns DecimalChain 实例,支持链式调用
44
43
  */
45
- add(e) {
46
- return this.value = this.value.add(e || 0), this;
44
+ add(o) {
45
+ return this.value = this.value.add(o || 0), this;
47
46
  }
48
47
  /**
49
48
  * 减法运算
50
49
  * @param num 要减的数
51
50
  * @returns DecimalChain 实例,支持链式调用
52
51
  */
53
- subtract(e) {
54
- return this.value = this.value.sub(e || 0), this;
52
+ subtract(o) {
53
+ return this.value = this.value.sub(o || 0), this;
55
54
  }
56
55
  /**
57
56
  * 乘法运算
58
57
  * @param num 要乘的数
59
58
  * @returns DecimalChain 实例,支持链式调用
60
59
  */
61
- multiply(e) {
62
- return this.value = this.value.mul(e || 0), this;
60
+ multiply(o) {
61
+ return this.value = this.value.mul(o || 0), this;
63
62
  }
64
63
  /**
65
64
  * 除法运算
@@ -67,11 +66,11 @@ class E {
67
66
  * @returns DecimalChain 实例,支持链式调用
68
67
  * @throws 当除数为0时抛出错误
69
68
  */
70
- divide(e) {
71
- const o = new A(e);
72
- if (o.isZero())
69
+ divide(o) {
70
+ const e = new G(o);
71
+ if (e.isZero())
73
72
  throw new Error("除数是0");
74
- return this.value = this.value.div(o), this;
73
+ return this.value = this.value.div(e), this;
75
74
  }
76
75
  /**
77
76
  * 保留小数位数
@@ -79,8 +78,8 @@ class E {
79
78
  * @param rounding 舍入模式,默认为四舍五入
80
79
  * @returns DecimalChain 实例,支持链式调用
81
80
  */
82
- toFixed(e, o) {
83
- return this.value = new A(this.value.toFixed(e, o)), this;
81
+ toFixed(o, e) {
82
+ return this.value = new G(this.value.toFixed(o, e)), this;
84
83
  }
85
84
  /**
86
85
  * 返回当前值
@@ -104,356 +103,356 @@ class E {
104
103
  return this.value.toNumber();
105
104
  }
106
105
  }
107
- function O(t = 0) {
108
- return new E(t);
106
+ function I(t = 0) {
107
+ return new Z(t);
109
108
  }
110
- var X = /* @__PURE__ */ ((t) => (t.无 = "no", t.年 = "year", t.月 = "month", t.周 = "week", t.天 = "day", t.班组 = "shift", t.小时 = "hour", t.半小时 = "half_hour", t))(X || {}), Z = /* @__PURE__ */ ((t) => (t.view = "view", t.edit = "edit", t))(Z || {});
111
- async function ot(t, e) {
112
- if (!e) return Promise.reject("日期不能为空");
109
+ var _ = /* @__PURE__ */ ((t) => (t.无 = "no", t.年 = "year", t.月 = "month", t.周 = "week", t.天 = "day", t.班组 = "shift", t.小时 = "hour", t.半小时 = "half_hour", t))(_ || {}), B = /* @__PURE__ */ ((t) => (t.view = "view", t.edit = "edit", t))(B || {});
110
+ async function tt(t, o) {
111
+ if (!o) return Promise.reject("日期不能为空");
113
112
  switch (t) {
114
113
  case "year":
115
- if (R(e))
116
- return Promise.resolve(e);
117
- const o = h(e);
118
- if (!o.isValid())
114
+ if (R(o))
115
+ return Promise.resolve(o);
116
+ const e = h(o);
117
+ if (!e.isValid())
119
118
  return Promise.reject("无效的日期格式");
120
- const r = o.year(), s = `${r}-01`, a = `${r}-12`;
121
- return Promise.resolve([s, a]);
119
+ const r = e.year(), i = `${r}-01`, n = `${r}-12`;
120
+ return Promise.resolve([i, n]);
122
121
  case "month":
123
- if (R(e))
124
- return Promise.resolve(e);
125
- const v = h(e);
122
+ if (R(o))
123
+ return Promise.resolve(o);
124
+ const v = h(o);
126
125
  if (!v.isValid())
127
126
  return Promise.reject("无效的日期格式");
128
- const m = v.startOf("month").format("YYYY-MM-DD"), p = v.endOf("month").format("YYYY-MM-DD");
129
- return Promise.resolve([m, p]);
127
+ const l = v.startOf("month").format("YYYY-MM-DD"), Y = v.endOf("month").format("YYYY-MM-DD");
128
+ return Promise.resolve([l, Y]);
130
129
  case "day":
131
- if (R(e))
132
- return Promise.resolve(e);
133
- const f = h(e);
130
+ if (R(o))
131
+ return Promise.resolve(o);
132
+ const f = h(o);
134
133
  if (!f.isValid())
135
134
  return Promise.reject("无效的日期格式");
136
- const k = f.startOf("day").format("YYYY-MM-DD HH:mm:ss"), u = f.endOf("day").format("YYYY-MM-DD HH:mm:ss");
137
- return Promise.resolve([k, u]);
135
+ const N = f.startOf("day").format("YYYY-MM-DD HH:mm:ss"), c = f.endOf("day").format("YYYY-MM-DD HH:mm:ss");
136
+ return Promise.resolve([N, c]);
138
137
  default:
139
138
  return Promise.reject("不支持的周期类型");
140
139
  }
141
140
  }
142
- function N(t, e, o) {
143
- if (!o) return 0;
141
+ function j(t, o, e) {
142
+ if (!e) return 0;
144
143
  const r = {
145
144
  year: "YYYY",
146
145
  month: "YYYY-MM",
147
146
  day: "YYYY-MM-DD",
148
147
  hour: "HH:mm:ss"
149
- }[o];
150
- return ["day", "hour"].includes(o) ? h(e, r).diff(h(t, r), o) + 1 : h(e, r).diff(h(t, r), o);
148
+ }[e];
149
+ return ["day", "hour"].includes(e) ? h(o, r).diff(h(t, r), e) + 1 : h(o, r).diff(h(t, r), e);
151
150
  }
152
- function L(t, e, o) {
151
+ function A(t, o, e) {
153
152
  const r = {
154
153
  year: "YYYY",
155
154
  month: "YYYY-MM",
156
155
  day: "YYYY-MM-DD",
157
156
  hour: "HH:mm:ss"
158
- }[o];
159
- return h(t).subtract(e, o).format(r);
157
+ }[e];
158
+ return h(t).subtract(o, e).format(r);
160
159
  }
161
- function H(t, e, o, r) {
162
- const s = {
160
+ function H(t, o, e, r) {
161
+ const i = {
163
162
  year: "YYYY",
164
163
  month: "YYYY-MM",
165
164
  day: "YYYY-MM-DD",
166
165
  hour: "YYYY-MM-DD HH:mm:ss"
167
- }[e];
168
- return h(t, s).add(o * r, e).format(s);
166
+ }[o];
167
+ return h(t, i).add(e * r, o).format(i);
169
168
  }
170
- function D(t, e, o) {
171
- return t[e] || (t[e] = {}), t[e][o] || (t[e][o] = {}), t[e][o];
169
+ function D(t, o, e) {
170
+ return t[o] || (t[o] = {}), t[o][e] || (t[o][e] = {}), t[o][e];
172
171
  }
173
- async function nt(t) {
172
+ async function et(t) {
174
173
  if (!t)
175
174
  throw new Error("cellData is required");
176
- const e = Object.entries(t).reduce((o, r) => {
177
- const [s, a] = r;
178
- for (const [v, m] of Object.entries(a)) {
179
- const { custom: p, v: f } = m;
180
- if (!p) continue;
181
- const { cellType: k } = p;
182
- if (k === "indicator") {
183
- const u = D(o, s, v);
184
- u.custom = p, u.v = f;
175
+ const o = Object.entries(t).reduce((e, r) => {
176
+ const [i, n] = r;
177
+ for (const [v, l] of Object.entries(n)) {
178
+ const { custom: Y, v: f } = l;
179
+ if (!Y) continue;
180
+ const { cellType: N } = Y;
181
+ if (N === "indicator") {
182
+ const c = D(e, i, v);
183
+ c.custom = Y, c.v = f;
185
184
  }
186
185
  }
187
- return o;
186
+ return e;
188
187
  }, {});
189
- return !e || _(e) ? Promise.reject(new Error("No data found")) : Promise.resolve(e);
188
+ return !o || J(o) ? Promise.reject(new Error("No data found")) : Promise.resolve(o);
190
189
  }
191
- function J({
190
+ function K({
192
191
  acc: t,
193
- params: e,
194
- initRowNum: o,
192
+ params: o,
193
+ initRowNum: e,
195
194
  initColNum: r,
196
- cellData: s
195
+ cellData: i
197
196
  }) {
198
- const { rangeData: a, currentDay: v, extraArgs: m } = e, p = m?.teamData || {}, { cycleType: f, timeIncrement: k, forwardPush: u, copyType: g, copyInterval: M, defaultShift: C } = s.custom;
199
- let Y = 0;
197
+ const { rangeData: n, currentDay: v, extraArgs: l } = o, Y = l?.teamData || {}, { cycleType: f, timeIncrement: N, forwardPush: c, copyType: M, copyInterval: x, defaultShift: P } = i.custom;
198
+ let b = 0;
200
199
  switch (f) {
201
200
  case "day": {
202
- let n = "";
203
- if (u && (n = L(
204
- a[0],
201
+ let s = "";
202
+ if (c && (s = A(
203
+ n[0],
205
204
  6,
206
205
  "day"
207
206
  /* day */
208
- )), !g) {
209
- let l = "";
210
- u ? l = n : l = a[0];
211
- const c = D(t, o, r);
212
- c.v = l, c.t = P.STRING;
207
+ )), !M) {
208
+ let m = "";
209
+ c ? m = s : m = n[0];
210
+ const u = D(t, e, r);
211
+ u.v = m, u.t = O.STRING;
213
212
  break;
214
213
  }
215
- u ? Y = N(
216
- n,
217
- a[0],
214
+ c ? b = j(
215
+ s,
216
+ n[0],
218
217
  "day"
219
218
  /* day */
220
- ) : Y = N(
221
- a[0],
222
- a[1],
219
+ ) : b = j(
220
+ n[0],
221
+ n[1],
223
222
  "day"
224
223
  /* day */
225
224
  );
226
- for (let l = 0; l <= Math.abs(Y === 0 ? 1 : Y); l++) {
227
- const c = l * (M + 1);
225
+ for (let m = 0; m <= Math.abs(b === 0 ? 1 : b); m++) {
226
+ const u = m * (x + 1);
228
227
  let w = "";
229
- u ? w = H(n, "day", l, k) : w = H(a[0], "day", l, k);
230
- const y = g === "right" ? o : o + c, x = g === "right" ? r + c : r, b = D(t, y, x);
231
- b.v = w, b.t = P.STRING;
228
+ c ? w = H(s, "day", m, N) : w = H(n[0], "day", m, N);
229
+ const y = M === "right" ? e : e + u, p = M === "right" ? r + u : r, g = D(t, y, p);
230
+ g.v = w, g.t = O.STRING;
232
231
  }
233
232
  break;
234
233
  }
235
234
  case "month": {
236
- if (!g) {
237
- const n = D(t, o, r);
238
- n.v = a[0], n.t = P.STRING;
235
+ if (!M) {
236
+ const s = D(t, e, r);
237
+ s.v = n[0], s.t = O.STRING;
239
238
  break;
240
239
  }
241
- Y = N(
242
- a[0],
243
- a[1],
240
+ b = j(
241
+ n[0],
242
+ n[1],
244
243
  "month"
245
244
  /* month */
246
245
  );
247
- for (let n = 0; n <= Math.abs(Y === 0 ? 1 : Y); n++) {
248
- const l = n * (M + 1), c = g === "right" ? o : o + l, w = g === "right" ? r + l : r, y = D(t, c, w);
249
- y.v = H(a[0], "month", n, k), y.t = P.STRING;
246
+ for (let s = 0; s <= Math.abs(b === 0 ? 1 : b); s++) {
247
+ const m = s * (x + 1), u = M === "right" ? e : e + m, w = M === "right" ? r + m : r, y = D(t, u, w);
248
+ y.v = H(n[0], "month", s, N), y.t = O.STRING;
250
249
  }
251
250
  break;
252
251
  }
253
252
  case "year": {
254
- if (!g) {
255
- const n = D(t, o, r);
256
- n.v = a[0], n.t = P.STRING;
253
+ if (!M) {
254
+ const s = D(t, e, r);
255
+ s.v = n[0], s.t = O.STRING;
257
256
  break;
258
257
  }
259
- Y = N(
260
- a[0],
261
- a[1],
258
+ b = j(
259
+ n[0],
260
+ n[1],
262
261
  "year"
263
262
  /* year */
264
263
  );
265
- for (let n = 0; n <= Math.abs(Y === 0 ? 1 : Y); n++) {
266
- const l = n * (M + 1), c = g === "right" ? o : o + l, w = g === "right" ? r + l : r, y = D(t, c, w);
267
- y.v = H(a[0], "year", n, k), y.t = P.STRING;
264
+ for (let s = 0; s <= Math.abs(b === 0 ? 1 : b); s++) {
265
+ const m = s * (x + 1), u = M === "right" ? e : e + m, w = M === "right" ? r + m : r, y = D(t, u, w);
266
+ y.v = H(n[0], "year", s, N), y.t = O.STRING;
268
267
  }
269
268
  break;
270
269
  }
271
270
  case "hour": {
272
- if (!g) {
273
- const n = D(t, o, r);
274
- if (n.t = P.STRING, C) {
275
- n.v = h(p?.startDatetime).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
271
+ if (!M) {
272
+ const s = D(t, e, r);
273
+ if (s.t = O.STRING, P) {
274
+ s.v = h(Y?.startDatetime).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
276
275
  break;
277
276
  }
278
- n.v = h(v).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
277
+ s.v = h(v).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
279
278
  break;
280
279
  }
281
- Y = N(
282
- p?.startDatetime,
283
- p?.endDatetime,
280
+ b = j(
281
+ Y?.startDatetime,
282
+ Y?.endDatetime,
284
283
  "hour"
285
284
  /* hour */
286
285
  );
287
- for (let n = 0; n < Math.abs(Y === 0 ? 1 : Y); n++) {
288
- const l = n * (M + 1), c = g === "right" ? o : o + l, w = g === "right" ? r + l : r, y = D(t, c, w);
289
- if (y.t = P.STRING, C) {
290
- const x = h(p?.startDatetime).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
291
- y.v = H(x, "hour", n, k);
286
+ for (let s = 0; s < Math.abs(b === 0 ? 1 : b); s++) {
287
+ const m = s * (x + 1), u = M === "right" ? e : e + m, w = M === "right" ? r + m : r, y = D(t, u, w);
288
+ if (y.t = O.STRING, P) {
289
+ const p = h(Y?.startDatetime).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
290
+ y.v = H(p, "hour", s, N);
292
291
  continue;
293
292
  }
294
- y.v = H(h(v).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), "hour", n, k);
293
+ y.v = H(h(v).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), "hour", s, N);
295
294
  }
296
295
  }
297
296
  }
298
297
  }
299
- async function st(t, e) {
298
+ async function rt(t, o) {
300
299
  if (!t)
301
300
  return Promise.reject("没有可用的单元格数据");
302
- const { extraArgs: o, rangeData: r } = e;
301
+ const { extraArgs: e, rangeData: r } = o;
303
302
  if (!r.length)
304
303
  return Promise.reject("处理时间范围失败, rangeData不能为空");
305
- const s = o?.teamData || {}, a = e?.currentDay || h().format("YYYY-MM-DD"), v = Object.entries(t).reduce((m, p) => {
306
- const [f, k] = p;
307
- for (const [u, g] of Object.entries(k)) {
308
- const { custom: M } = g;
309
- if (!M) continue;
310
- const { cellType: C, cycleType: Y, timeIncrement: n, forwardPush: l, copyType: c, copyInterval: w, defaultShift: y } = M;
311
- if (C === "time") {
312
- J({ acc: m, params: e, initRowNum: Number(f), initColNum: Number(u), cellData: g });
304
+ const i = e?.teamData || {}, n = o?.currentDay || h().format("YYYY-MM-DD"), v = Object.entries(t).reduce((l, Y) => {
305
+ const [f, N] = Y;
306
+ for (const [c, M] of Object.entries(N)) {
307
+ const { custom: x } = M;
308
+ if (!x) continue;
309
+ const { cellType: P, cycleType: b, timeIncrement: s, forwardPush: m, copyType: u, copyInterval: w, defaultShift: y } = x;
310
+ if (P === "time") {
311
+ K({ acc: l, params: o, initRowNum: Number(f), initColNum: Number(c), cellData: M });
313
312
  continue;
314
313
  }
315
- const x = {
316
- cycleType: Y,
317
- indicatorName: M.indicatorName,
318
- indicatorCode: M.indicatorCode,
319
- indicatorId: M.indicatorId,
320
- indicatorDimensionName: M.indicatorDimensionName,
321
- indicatorDimensionConfig: M.indicatorDimensionConfig,
322
- required: M.required,
323
- cellType: M.cellType,
324
- defaultShift: M.defaultShift
314
+ const p = {
315
+ cycleType: b,
316
+ indicatorName: x.indicatorName,
317
+ indicatorCode: x.indicatorCode,
318
+ indicatorId: x.indicatorId,
319
+ indicatorDimensionName: x.indicatorDimensionName,
320
+ indicatorDimensionConfig: x.indicatorDimensionConfig,
321
+ required: x.required,
322
+ cellType: x.cellType,
323
+ defaultShift: x.defaultShift
325
324
  };
326
- let b = 0;
327
- switch (Y) {
325
+ let g = 0;
326
+ switch (b) {
328
327
  case "day": {
329
- let i = "";
330
- if (l && (i = L(
328
+ let a = "";
329
+ if (m && (a = A(
331
330
  r[0],
332
331
  6,
333
332
  "day"
334
333
  /* day */
335
- )), !c) {
334
+ )), !u) {
336
335
  let d = "";
337
- l ? d = i : d = r[0];
338
- const S = D(m, f, u);
336
+ m ? d = a : d = r[0];
337
+ const S = D(l, f, c);
339
338
  S.custom = {
340
- ...x,
339
+ ...p,
341
340
  businessDate: d
342
- }, y && (S.custom.teamData = s);
341
+ }, y && (S.custom.teamData = i);
343
342
  break;
344
343
  }
345
- l ? b = N(
346
- i,
344
+ m ? g = j(
345
+ a,
347
346
  r[0],
348
347
  "day"
349
348
  /* day */
350
- ) : b = N(
349
+ ) : g = j(
351
350
  r[0],
352
351
  r[1],
353
352
  "day"
354
353
  /* day */
355
354
  );
356
- for (let d = 0; d < Math.abs(b === 0 ? 1 : b); d++) {
355
+ for (let d = 0; d < Math.abs(g === 0 ? 1 : g); d++) {
357
356
  const S = d * (w + 1);
358
- let j = "";
359
- l ? j = H(i, "day", d, n) : j = H(r[0], "day", d, n);
360
- const I = c === "right" ? f : O(f).add(S).toNumber(), U = c === "right" ? O(u).add(S).toNumber() : u, T = D(m, I, U);
361
- T.custom = {
362
- ...x,
363
- businessDate: j
364
- }, y && (T.custom.teamData = s);
357
+ let k = "";
358
+ m ? k = H(a, "day", d, s) : k = H(r[0], "day", d, s);
359
+ const C = u === "right" ? f : I(f).add(S).toNumber(), T = u === "right" ? I(c).add(S).toNumber() : c, U = D(l, C, T);
360
+ U.custom = {
361
+ ...p,
362
+ businessDate: k
363
+ }, y && (U.custom.teamData = i);
365
364
  }
366
365
  break;
367
366
  }
368
367
  case "month": {
369
- if (!c) {
370
- const i = D(m, f, u);
371
- i.custom = {
372
- ...x,
368
+ if (!u) {
369
+ const a = D(l, f, c);
370
+ a.custom = {
371
+ ...p,
373
372
  businessDate: r[0]
374
373
  };
375
374
  break;
376
375
  }
377
- b = N(
376
+ g = j(
378
377
  r[0],
379
378
  r[1],
380
379
  "month"
381
380
  /* month */
382
381
  );
383
- for (let i = 0; i <= Math.abs(b === 0 ? 1 : b); i++) {
384
- const d = i * (w + 1), S = c === "right" ? f : O(f).add(d).toNumber(), j = c === "right" ? O(u).add(d).toNumber() : u, I = D(m, S, j);
385
- I.custom = {
386
- ...x,
387
- businessDate: H(r[0], "month", i, n)
382
+ for (let a = 0; a <= Math.abs(g === 0 ? 1 : g); a++) {
383
+ const d = a * (w + 1), S = u === "right" ? f : I(f).add(d).toNumber(), k = u === "right" ? I(c).add(d).toNumber() : c, C = D(l, S, k);
384
+ C.custom = {
385
+ ...p,
386
+ businessDate: H(r[0], "month", a, s)
388
387
  };
389
388
  }
390
389
  break;
391
390
  }
392
391
  case "year": {
393
- if (!c) {
394
- const i = D(m, f, u);
395
- i.custom = {
396
- ...x,
392
+ if (!u) {
393
+ const a = D(l, f, c);
394
+ a.custom = {
395
+ ...p,
397
396
  businessDate: r[0]
398
397
  };
399
398
  break;
400
399
  }
401
- b = N(
400
+ g = j(
402
401
  r[0],
403
402
  r[1],
404
403
  "year"
405
404
  /* year */
406
405
  );
407
- for (let i = 0; i < Math.abs(b === 0 ? 1 : b); i++) {
408
- const d = i * (w + 1), S = c === "right" ? f : O(f).add(d).toNumber(), j = c === "right" ? O(u).add(d).toNumber() : u, I = D(m, S, j);
409
- I.custom = {
410
- ...x,
411
- businessDate: H(r[0], "year", i, n)
406
+ for (let a = 0; a < Math.abs(g === 0 ? 1 : g); a++) {
407
+ const d = a * (w + 1), S = u === "right" ? f : I(f).add(d).toNumber(), k = u === "right" ? I(c).add(d).toNumber() : c, C = D(l, S, k);
408
+ C.custom = {
409
+ ...p,
410
+ businessDate: H(r[0], "year", a, s)
412
411
  };
413
412
  }
414
413
  break;
415
414
  }
416
415
  case "hour": {
417
- if (!c) {
418
- const i = D(m, f, u);
416
+ if (!u) {
417
+ const a = D(l, f, c);
419
418
  if (y) {
420
- i.custom = {
421
- ...x,
422
- teamData: s,
423
- businessDate: h(s?.startDatetime).add(1, "hour").format("YYYY-MM-DD HH:mm:ss")
419
+ a.custom = {
420
+ ...p,
421
+ teamData: i,
422
+ businessDate: h(i?.startDatetime).add(1, "hour").format("YYYY-MM-DD HH:mm:ss")
424
423
  };
425
424
  break;
426
425
  }
427
- i.custom = {
428
- ...x,
429
- businessDate: h(a).add(1, "hour").format("YYYY-MM-DD HH:mm:ss")
426
+ a.custom = {
427
+ ...p,
428
+ businessDate: h(n).add(1, "hour").format("YYYY-MM-DD HH:mm:ss")
430
429
  };
431
430
  break;
432
431
  }
433
- b = N(
434
- s?.startDatetime,
435
- s?.endDatetime,
432
+ g = j(
433
+ i?.startDatetime,
434
+ i?.endDatetime,
436
435
  "hour"
437
436
  /* hour */
438
437
  );
439
- for (let i = 0; i < Math.abs(b === 0 ? 1 : b); i++) {
440
- const d = i * (w + 1), S = c === "right" ? f : O(f).add(d).toNumber(), j = c === "right" ? O(u).add(d).toNumber() : u, I = D(m, S, j);
438
+ for (let a = 0; a < Math.abs(g === 0 ? 1 : g); a++) {
439
+ const d = a * (w + 1), S = u === "right" ? f : I(f).add(d).toNumber(), k = u === "right" ? I(c).add(d).toNumber() : c, C = D(l, S, k);
441
440
  if (y) {
442
- const U = h(s?.startDatetime).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
443
- I.custom = {
444
- ...x,
445
- teamData: s,
446
- businessDate: H(U, "hour", i, n)
441
+ const T = h(i?.startDatetime).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
442
+ C.custom = {
443
+ ...p,
444
+ teamData: i,
445
+ businessDate: H(T, "hour", a, s)
447
446
  };
448
447
  continue;
449
448
  }
450
- I.custom = {
451
- ...x,
449
+ C.custom = {
450
+ ...p,
452
451
  businessDate: H(
453
- h(a).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"),
452
+ h(n).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"),
454
453
  "hour",
455
- i,
456
- n
454
+ a,
455
+ s
457
456
  )
458
457
  };
459
458
  }
@@ -461,66 +460,46 @@ async function st(t, e) {
461
460
  }
462
461
  }
463
462
  }
464
- return m;
463
+ return l;
465
464
  }, {});
466
465
  return Promise.resolve(v);
467
466
  }
468
- async function at(t = "*", e = !1) {
469
- const o = document.createElement("input");
470
- return o.type = "file", o.accept = t, o.multiple = e, o.click(), new Promise((r, s) => {
471
- o.onchange = function() {
472
- const a = Array.from(o?.files ?? []);
473
- a.length > 0 ? r(a) : s();
474
- };
475
- });
467
+ function ot(t) {
468
+ return Object.entries(t).reduce((e, [r, i]) => {
469
+ const n = Math.max(...Object.keys(i).map(Number));
470
+ return n > e ? e = Number(n) : e = Number(e) || 0, e;
471
+ }, 0);
476
472
  }
477
- function it(t) {
478
- return new Promise((e, o) => {
479
- const r = new FileReader();
480
- r.onload = (s) => {
481
- try {
482
- const a = s.target?.result;
483
- if (!a) {
484
- o("读取文件失败");
485
- return;
473
+ function st(t, o) {
474
+ const e = JSON.parse(JSON.stringify(t || {}));
475
+ for (const [r, i] of Object.entries(o)) {
476
+ e[r] || (e[r] = {});
477
+ for (const [n, v] of Object.entries(i)) {
478
+ const l = v, Y = e[r]?.[n];
479
+ Y ? e[r][n] = {
480
+ ...Y,
481
+ ...l,
482
+ custom: {
483
+ ...Y.custom,
484
+ ...l.custom || {}
486
485
  }
487
- const v = V(a, {
488
- type: "binary"
489
- }), m = [];
490
- v.SheetNames.forEach((p) => {
491
- m.push(F.sheet_to_json(v.Sheets[p]));
492
- }), e(m);
493
- } catch {
494
- o("读取错误!");
495
- }
496
- }, r.readAsBinaryString(t);
497
- });
498
- }
499
- const ct = (t, e = void 0) => {
500
- const o = t.data;
501
- if (o instanceof Blob) {
502
- let r = t.headers.get("content-disposition")?.split("filename=")?.[1] ?? "未知文件";
503
- if (r = decodeURIComponent(r), e && (r = e), typeof window.chrome < "u") {
504
- const s = document.createElement("a"), a = URL.createObjectURL(o);
505
- s.href = a, s.download = r, s.click(), URL.revokeObjectURL(a);
506
- } else {
507
- const s = URL.createObjectURL(o);
508
- window.open(s), URL.revokeObjectURL(s);
486
+ } : e[r][n] = l;
509
487
  }
510
488
  }
511
- }, ut = "./style.css";
489
+ return e;
490
+ }
491
+ const nt = "./style.css";
512
492
  export {
513
- X as CycleTypeEnum,
514
- Z as ModeEnum,
515
- O as decimal,
516
- ct as downloadBlobRes,
517
- nt as filterIndicatorsCell,
518
- st as generateIndicatorsCells,
493
+ _ as CycleTypeEnum,
494
+ B as ModeEnum,
495
+ I as decimal,
496
+ et as filterIndicatorsCell,
497
+ rt as generateIndicatorsCells,
519
498
  q as generateUUID,
520
- it as getXlsxData,
521
- et as handleClearInput,
522
- ot as initDateRange,
523
- at as openMultipleFileSelector,
524
- ut as stylePath,
525
- rt as useData
499
+ ot as getNumColumns,
500
+ X as handleClearInput,
501
+ tt as initDateRange,
502
+ st as mergeCellData,
503
+ nt as stylePath,
504
+ E as useData
526
505
  };
@@ -1 +1 @@
1
- (function(f,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("dayjs"),require("@univerjs/presets"),require("decimal.js"),require("xlsx")):typeof define=="function"&&define.amd?define(["exports","dayjs","@univerjs/presets","decimal.js","xlsx"],m):(f=typeof globalThis<"u"?globalThis:f||self,m(f.TorUniverSheet={},f.dayjs,f.presets,f.Decimal,f.xlsx))})(this,(function(f,m,O,V,A){"use strict";const $=(e,t)=>{for(const n of t)e[n]=null},G=()=>{if(typeof crypto=="object"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"&&typeof Uint8Array=="function"){const n=r=>{const s=Number(r);return(s^crypto.getRandomValues(new Uint8Array(1))[0]&15>>s/4).toString(16)};return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,n)}}let e=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let r=Math.random()*16;return e>0?(r=(e+r)%16|0,e=Math.floor(e/16)):(r=(t+r)%16|0,t=Math.floor(t/16)),(n==="x"?r:r&3|8).toString(16)})};function X(e){return{...e?.workbookData,id:e?.id||G(),name:e?.name||"未命名",appVersion:e?.appVersion||"1.0.0"}}const _=Object.prototype.toString,L=(e,t)=>_.call(e)===`[object ${t}]`,z=e=>e!==null&&L(e,"Object"),Z=e=>e==null||typeof e>"u"?!0:T(e)||J(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:z(e)?Object.keys(e).length===0:!1,J=e=>L(e,"String"),T=e=>e&&Array.isArray(e);class K{value;constructor(t){this.value=new V(t)}add(t){return this.value=this.value.add(t||0),this}subtract(t){return this.value=this.value.sub(t||0),this}multiply(t){return this.value=this.value.mul(t||0),this}divide(t){const n=new V(t);if(n.isZero())throw new Error("除数是0");return this.value=this.value.div(n),this}toFixed(t,n){return this.value=new V(this.value.toFixed(t,n)),this}valueOf(){return this.value}toString(){return this.value.toString()}toNumber(){return this.value.toNumber()}}function N(e=0){return new K(e)}var q=(e=>(e.无="no",e.年="year",e.月="month",e.周="week",e.天="day",e.班组="shift",e.小时="hour",e.半小时="half_hour",e))(q||{}),F=(e=>(e.view="view",e.edit="edit",e))(F||{});async function Q(e,t){if(!t)return Promise.reject("日期不能为空");switch(e){case"year":if(T(t))return Promise.resolve(t);const n=m(t);if(!n.isValid())return Promise.reject("无效的日期格式");const r=n.year(),s=`${r}-01`,a=`${r}-12`;return Promise.resolve([s,a]);case"month":if(T(t))return Promise.resolve(t);const S=m(t);if(!S.isValid())return Promise.reject("无效的日期格式");const h=S.startOf("month").format("YYYY-MM-DD"),p=S.endOf("month").format("YYYY-MM-DD");return Promise.resolve([h,p]);case"day":if(T(t))return Promise.resolve(t);const d=m(t);if(!d.isValid())return Promise.reject("无效的日期格式");const k=d.startOf("day").format("YYYY-MM-DD HH:mm:ss"),c=d.endOf("day").format("YYYY-MM-DD HH:mm:ss");return Promise.resolve([k,c]);default:return Promise.reject("不支持的周期类型")}}function I(e,t,n){if(!n)return 0;const r={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[n];return["day","hour"].includes(n)?m(t,r).diff(m(e,r),n)+1:m(t,r).diff(m(e,r),n)}function B(e,t,n){const r={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[n];return m(e).subtract(t,n).format(r)}function C(e,t,n,r){const s={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"YYYY-MM-DD HH:mm:ss"}[t];return m(e,s).add(n*r,t).format(s)}function Y(e,t,n){return e[t]||(e[t]={}),e[t][n]||(e[t][n]={}),e[t][n]}async function W(e){if(!e)throw new Error("cellData is required");const t=Object.entries(e).reduce((n,r)=>{const[s,a]=r;for(const[S,h]of Object.entries(a)){const{custom:p,v:d}=h;if(!p)continue;const{cellType:k}=p;if(k==="indicator"){const c=Y(n,s,S);c.custom=p,c.v=d}}return n},{});return!t||Z(t)?Promise.reject(new Error("No data found")):Promise.resolve(t)}function ee({acc:e,params:t,initRowNum:n,initColNum:r,cellData:s}){const{rangeData:a,currentDay:S,extraArgs:h}=t,p=h?.teamData||{},{cycleType:d,timeIncrement:k,forwardPush:c,copyType:M,copyInterval:w,defaultShift:U}=s.custom;let b=0;switch(d){case"day":{let o="";if(c&&(o=B(a[0],6,"day")),!M){let l="";c?l=o:l=a[0];const u=Y(e,n,r);u.v=l,u.t=O.CellValueType.STRING;break}c?b=I(o,a[0],"day"):b=I(a[0],a[1],"day");for(let l=0;l<=Math.abs(b===0?1:b);l++){const u=l*(w+1);let v="";c?v=C(o,"day",l,k):v=C(a[0],"day",l,k);const y=M==="right"?n:n+u,x=M==="right"?r+u:r,g=Y(e,y,x);g.v=v,g.t=O.CellValueType.STRING}break}case"month":{if(!M){const o=Y(e,n,r);o.v=a[0],o.t=O.CellValueType.STRING;break}b=I(a[0],a[1],"month");for(let o=0;o<=Math.abs(b===0?1:b);o++){const l=o*(w+1),u=M==="right"?n:n+l,v=M==="right"?r+l:r,y=Y(e,u,v);y.v=C(a[0],"month",o,k),y.t=O.CellValueType.STRING}break}case"year":{if(!M){const o=Y(e,n,r);o.v=a[0],o.t=O.CellValueType.STRING;break}b=I(a[0],a[1],"year");for(let o=0;o<=Math.abs(b===0?1:b);o++){const l=o*(w+1),u=M==="right"?n:n+l,v=M==="right"?r+l:r,y=Y(e,u,v);y.v=C(a[0],"year",o,k),y.t=O.CellValueType.STRING}break}case"hour":{if(!M){const o=Y(e,n,r);if(o.t=O.CellValueType.STRING,U){o.v=m(p?.startDatetime).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}o.v=m(S).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}b=I(p?.startDatetime,p?.endDatetime,"hour");for(let o=0;o<Math.abs(b===0?1:b);o++){const l=o*(w+1),u=M==="right"?n:n+l,v=M==="right"?r+l:r,y=Y(e,u,v);if(y.t=O.CellValueType.STRING,U){const x=m(p?.startDatetime).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");y.v=C(x,"hour",o,k);continue}y.v=C(m(S).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",o,k)}}}}async function te(e,t){if(!e)return Promise.reject("没有可用的单元格数据");const{extraArgs:n,rangeData:r}=t;if(!r.length)return Promise.reject("处理时间范围失败, rangeData不能为空");const s=n?.teamData||{},a=t?.currentDay||m().format("YYYY-MM-DD"),S=Object.entries(e).reduce((h,p)=>{const[d,k]=p;for(const[c,M]of Object.entries(k)){const{custom:w}=M;if(!w)continue;const{cellType:U,cycleType:b,timeIncrement:o,forwardPush:l,copyType:u,copyInterval:v,defaultShift:y}=w;if(U==="time"){ee({acc:h,params:t,initRowNum:Number(d),initColNum:Number(c),cellData:M});continue}const x={cycleType:b,indicatorName:w.indicatorName,indicatorCode:w.indicatorCode,indicatorId:w.indicatorId,indicatorDimensionName:w.indicatorDimensionName,indicatorDimensionConfig:w.indicatorDimensionConfig,required:w.required,cellType:w.cellType,defaultShift:w.defaultShift};let g=0;switch(b){case"day":{let i="";if(l&&(i=B(r[0],6,"day")),!u){let D="";l?D=i:D=r[0];const H=Y(h,d,c);H.custom={...x,businessDate:D},y&&(H.custom.teamData=s);break}l?g=I(i,r[0],"day"):g=I(r[0],r[1],"day");for(let D=0;D<Math.abs(g===0?1:g);D++){const H=D*(v+1);let P="";l?P=C(i,"day",D,o):P=C(r[0],"day",D,o);const R=u==="right"?d:N(d).add(H).toNumber(),j=u==="right"?N(c).add(H).toNumber():c,E=Y(h,R,j);E.custom={...x,businessDate:P},y&&(E.custom.teamData=s)}break}case"month":{if(!u){const i=Y(h,d,c);i.custom={...x,businessDate:r[0]};break}g=I(r[0],r[1],"month");for(let i=0;i<=Math.abs(g===0?1:g);i++){const D=i*(v+1),H=u==="right"?d:N(d).add(D).toNumber(),P=u==="right"?N(c).add(D).toNumber():c,R=Y(h,H,P);R.custom={...x,businessDate:C(r[0],"month",i,o)}}break}case"year":{if(!u){const i=Y(h,d,c);i.custom={...x,businessDate:r[0]};break}g=I(r[0],r[1],"year");for(let i=0;i<Math.abs(g===0?1:g);i++){const D=i*(v+1),H=u==="right"?d:N(d).add(D).toNumber(),P=u==="right"?N(c).add(D).toNumber():c,R=Y(h,H,P);R.custom={...x,businessDate:C(r[0],"year",i,o)}}break}case"hour":{if(!u){const i=Y(h,d,c);if(y){i.custom={...x,teamData:s,businessDate:m(s?.startDatetime).add(1,"hour").format("YYYY-MM-DD HH:mm:ss")};break}i.custom={...x,businessDate:m(a).add(1,"hour").format("YYYY-MM-DD HH:mm:ss")};break}g=I(s?.startDatetime,s?.endDatetime,"hour");for(let i=0;i<Math.abs(g===0?1:g);i++){const D=i*(v+1),H=u==="right"?d:N(d).add(D).toNumber(),P=u==="right"?N(c).add(D).toNumber():c,R=Y(h,H,P);if(y){const j=m(s?.startDatetime).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");R.custom={...x,teamData:s,businessDate:C(j,"hour",i,o)};continue}R.custom={...x,businessDate:C(m(a).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",i,o)}}break}}}return h},{});return Promise.resolve(S)}async function re(e="*",t=!1){const n=document.createElement("input");return n.type="file",n.accept=e,n.multiple=t,n.click(),new Promise((r,s)=>{n.onchange=function(){const a=Array.from(n?.files??[]);a.length>0?r(a):s()}})}function ne(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=s=>{try{const a=s.target?.result;if(!a){n("读取文件失败");return}const S=A.read(a,{type:"binary"}),h=[];S.SheetNames.forEach(p=>{h.push(A.utils.sheet_to_json(S.Sheets[p]))}),t(h)}catch{n("读取错误!")}},r.readAsBinaryString(e)})}const oe=(e,t=void 0)=>{const n=e.data;if(n instanceof Blob){let r=e.headers.get("content-disposition")?.split("filename=")?.[1]??"未知文件";if(r=decodeURIComponent(r),t&&(r=t),typeof window.chrome<"u"){const s=document.createElement("a"),a=URL.createObjectURL(n);s.href=a,s.download=r,s.click(),URL.revokeObjectURL(a)}else{const s=URL.createObjectURL(n);window.open(s),URL.revokeObjectURL(s)}}},se="./style.css";f.CycleTypeEnum=q,f.ModeEnum=F,f.decimal=N,f.downloadBlobRes=oe,f.filterIndicatorsCell=W,f.generateIndicatorsCells=te,f.generateUUID=G,f.getXlsxData=ne,f.handleClearInput=$,f.initDateRange=Q,f.openMultipleFileSelector=re,f.stylePath=se,f.useData=X,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(d,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("dayjs"),require("@univerjs/presets"),require("decimal.js")):typeof define=="function"&&define.amd?define(["exports","dayjs","@univerjs/presets","decimal.js"],m):(d=typeof globalThis<"u"?globalThis:d||self,m(d.TorUniverSheet={},d.dayjs,d.presets,d.Decimal))})(this,(function(d,m,P,U){"use strict";const z=(e,n)=>{for(const t of n)e[t]=null},G=()=>{if(typeof crypto=="object"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"&&typeof Uint8Array=="function"){const t=r=>{const i=Number(r);return(i^crypto.getRandomValues(new Uint8Array(1))[0]&15>>i/4).toString(16)};return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t)}}let e=new Date().getTime(),n=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16;return e>0?(r=(e+r)%16|0,e=Math.floor(e/16)):(r=(n+r)%16|0,n=Math.floor(n/16)),(t==="x"?r:r&3|8).toString(16)})};function Z(e){return{...e?.workbookData,id:e?.id||G(),name:e?.name||"未命名",appVersion:e?.appVersion||"1.0.0"}}const _=Object.prototype.toString,A=(e,n)=>_.call(e)===`[object ${n}]`,B=e=>e!==null&&A(e,"Object"),E=e=>e==null||typeof e>"u"?!0:V(e)||K(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:B(e)?Object.keys(e).length===0:!1,K=e=>A(e,"String"),V=e=>e&&Array.isArray(e);class L{value;constructor(n){this.value=new U(n)}add(n){return this.value=this.value.add(n||0),this}subtract(n){return this.value=this.value.sub(n||0),this}multiply(n){return this.value=this.value.mul(n||0),this}divide(n){const t=new U(n);if(t.isZero())throw new Error("除数是0");return this.value=this.value.div(t),this}toFixed(n,t){return this.value=new U(this.value.toFixed(n,t)),this}valueOf(){return this.value}toString(){return this.value.toString()}toNumber(){return this.value.toNumber()}}function O(e=0){return new L(e)}var q=(e=>(e.无="no",e.年="year",e.月="month",e.周="week",e.天="day",e.班组="shift",e.小时="hour",e.半小时="half_hour",e))(q||{}),F=(e=>(e.view="view",e.edit="edit",e))(F||{});async function Q(e,n){if(!n)return Promise.reject("日期不能为空");switch(e){case"year":if(V(n))return Promise.resolve(n);const t=m(n);if(!t.isValid())return Promise.reject("无效的日期格式");const r=t.year(),i=`${r}-01`,s=`${r}-12`;return Promise.resolve([i,s]);case"month":if(V(n))return Promise.resolve(n);const p=m(n);if(!p.isValid())return Promise.reject("无效的日期格式");const h=p.startOf("month").format("YYYY-MM-DD"),b=p.endOf("month").format("YYYY-MM-DD");return Promise.resolve([h,b]);case"day":if(V(n))return Promise.resolve(n);const f=m(n);if(!f.isValid())return Promise.reject("无效的日期格式");const S=f.startOf("day").format("YYYY-MM-DD HH:mm:ss"),c=f.endOf("day").format("YYYY-MM-DD HH:mm:ss");return Promise.resolve([S,c]);default:return Promise.reject("不支持的周期类型")}}function I(e,n,t){if(!t)return 0;const r={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[t];return["day","hour"].includes(t)?m(n,r).diff(m(e,r),t)+1:m(n,r).diff(m(e,r),t)}function $(e,n,t){const r={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[t];return m(e).subtract(n,t).format(r)}function N(e,n,t,r){const i={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"YYYY-MM-DD HH:mm:ss"}[n];return m(e,i).add(t*r,n).format(i)}function Y(e,n,t){return e[n]||(e[n]={}),e[n][t]||(e[n][t]={}),e[n][t]}async function W(e){if(!e)throw new Error("cellData is required");const n=Object.entries(e).reduce((t,r)=>{const[i,s]=r;for(const[p,h]of Object.entries(s)){const{custom:b,v:f}=h;if(!b)continue;const{cellType:S}=b;if(S==="indicator"){const c=Y(t,i,p);c.custom=b,c.v=f}}return t},{});return!n||E(n)?Promise.reject(new Error("No data found")):Promise.resolve(n)}function X({acc:e,params:n,initRowNum:t,initColNum:r,cellData:i}){const{rangeData:s,currentDay:p,extraArgs:h}=n,b=h?.teamData||{},{cycleType:f,timeIncrement:S,forwardPush:c,copyType:w,copyInterval:v,defaultShift:j}=i.custom;let g=0;switch(f){case"day":{let o="";if(c&&(o=$(s[0],6,"day")),!w){let l="";c?l=o:l=s[0];const u=Y(e,t,r);u.v=l,u.t=P.CellValueType.STRING;break}c?g=I(o,s[0],"day"):g=I(s[0],s[1],"day");for(let l=0;l<=Math.abs(g===0?1:g);l++){const u=l*(v+1);let x="";c?x=N(o,"day",l,S):x=N(s[0],"day",l,S);const y=w==="right"?t:t+u,C=w==="right"?r+u:r,M=Y(e,y,C);M.v=x,M.t=P.CellValueType.STRING}break}case"month":{if(!w){const o=Y(e,t,r);o.v=s[0],o.t=P.CellValueType.STRING;break}g=I(s[0],s[1],"month");for(let o=0;o<=Math.abs(g===0?1:g);o++){const l=o*(v+1),u=w==="right"?t:t+l,x=w==="right"?r+l:r,y=Y(e,u,x);y.v=N(s[0],"month",o,S),y.t=P.CellValueType.STRING}break}case"year":{if(!w){const o=Y(e,t,r);o.v=s[0],o.t=P.CellValueType.STRING;break}g=I(s[0],s[1],"year");for(let o=0;o<=Math.abs(g===0?1:g);o++){const l=o*(v+1),u=w==="right"?t:t+l,x=w==="right"?r+l:r,y=Y(e,u,x);y.v=N(s[0],"year",o,S),y.t=P.CellValueType.STRING}break}case"hour":{if(!w){const o=Y(e,t,r);if(o.t=P.CellValueType.STRING,j){o.v=m(b?.startDatetime).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}o.v=m(p).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}g=I(b?.startDatetime,b?.endDatetime,"hour");for(let o=0;o<Math.abs(g===0?1:g);o++){const l=o*(v+1),u=w==="right"?t:t+l,x=w==="right"?r+l:r,y=Y(e,u,x);if(y.t=P.CellValueType.STRING,j){const C=m(b?.startDatetime).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");y.v=N(C,"hour",o,S);continue}y.v=N(m(p).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",o,S)}}}}async function ee(e,n){if(!e)return Promise.reject("没有可用的单元格数据");const{extraArgs:t,rangeData:r}=n;if(!r.length)return Promise.reject("处理时间范围失败, rangeData不能为空");const i=t?.teamData||{},s=n?.currentDay||m().format("YYYY-MM-DD"),p=Object.entries(e).reduce((h,b)=>{const[f,S]=b;for(const[c,w]of Object.entries(S)){const{custom:v}=w;if(!v)continue;const{cellType:j,cycleType:g,timeIncrement:o,forwardPush:l,copyType:u,copyInterval:x,defaultShift:y}=v;if(j==="time"){X({acc:h,params:n,initRowNum:Number(f),initColNum:Number(c),cellData:w});continue}const C={cycleType:g,indicatorName:v.indicatorName,indicatorCode:v.indicatorCode,indicatorId:v.indicatorId,indicatorDimensionName:v.indicatorDimensionName,indicatorDimensionConfig:v.indicatorDimensionConfig,required:v.required,cellType:v.cellType,defaultShift:v.defaultShift};let M=0;switch(g){case"day":{let a="";if(l&&(a=$(r[0],6,"day")),!u){let D="";l?D=a:D=r[0];const H=Y(h,f,c);H.custom={...C,businessDate:D},y&&(H.custom.teamData=i);break}l?M=I(a,r[0],"day"):M=I(r[0],r[1],"day");for(let D=0;D<Math.abs(M===0?1:M);D++){const H=D*(x+1);let k="";l?k=N(a,"day",D,o):k=N(r[0],"day",D,o);const T=u==="right"?f:O(f).add(H).toNumber(),R=u==="right"?O(c).add(H).toNumber():c,J=Y(h,T,R);J.custom={...C,businessDate:k},y&&(J.custom.teamData=i)}break}case"month":{if(!u){const a=Y(h,f,c);a.custom={...C,businessDate:r[0]};break}M=I(r[0],r[1],"month");for(let a=0;a<=Math.abs(M===0?1:M);a++){const D=a*(x+1),H=u==="right"?f:O(f).add(D).toNumber(),k=u==="right"?O(c).add(D).toNumber():c,T=Y(h,H,k);T.custom={...C,businessDate:N(r[0],"month",a,o)}}break}case"year":{if(!u){const a=Y(h,f,c);a.custom={...C,businessDate:r[0]};break}M=I(r[0],r[1],"year");for(let a=0;a<Math.abs(M===0?1:M);a++){const D=a*(x+1),H=u==="right"?f:O(f).add(D).toNumber(),k=u==="right"?O(c).add(D).toNumber():c,T=Y(h,H,k);T.custom={...C,businessDate:N(r[0],"year",a,o)}}break}case"hour":{if(!u){const a=Y(h,f,c);if(y){a.custom={...C,teamData:i,businessDate:m(i?.startDatetime).add(1,"hour").format("YYYY-MM-DD HH:mm:ss")};break}a.custom={...C,businessDate:m(s).add(1,"hour").format("YYYY-MM-DD HH:mm:ss")};break}M=I(i?.startDatetime,i?.endDatetime,"hour");for(let a=0;a<Math.abs(M===0?1:M);a++){const D=a*(x+1),H=u==="right"?f:O(f).add(D).toNumber(),k=u==="right"?O(c).add(D).toNumber():c,T=Y(h,H,k);if(y){const R=m(i?.startDatetime).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");T.custom={...C,teamData:i,businessDate:N(R,"hour",a,o)};continue}T.custom={...C,businessDate:N(m(s).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",a,o)}}break}}}return h},{});return Promise.resolve(p)}function te(e){return Object.entries(e).reduce((t,[r,i])=>{const s=Math.max(...Object.keys(i).map(Number));return s>t?t=Number(s):t=Number(t)||0,t},0)}function re(e,n){const t=JSON.parse(JSON.stringify(e||{}));for(const[r,i]of Object.entries(n)){t[r]||(t[r]={});for(const[s,p]of Object.entries(i)){const h=p,b=t[r]?.[s];b?t[r][s]={...b,...h,custom:{...b.custom,...h.custom||{}}}:t[r][s]=h}}return t}const ne="./style.css";d.CycleTypeEnum=q,d.ModeEnum=F,d.decimal=O,d.filterIndicatorsCell=W,d.generateIndicatorsCells=ee,d.generateUUID=G,d.getNumColumns=te,d.handleClearInput=z,d.initDateRange=Q,d.mergeCellData=re,d.stylePath=ne,d.useData=Z,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
@@ -73,20 +73,13 @@ declare class DecimalChain {
73
73
  toNumber(): number;
74
74
  }
75
75
 
76
- /**
77
- * 下载axios导出的文件
78
- * @param res
79
- * @param _filename
80
- */
81
- export declare const downloadBlobRes: (res: any, _filename?: string | undefined) => void;
82
-
83
76
  export declare function filterIndicatorsCell(cellData: IObjectMatrixPrimitiveType<ICellData>): Promise<{}>;
84
77
 
85
78
  export declare function generateIndicatorsCells(cells: IObjectMatrixPrimitiveType<ICellData>, params: IGenerateIndicatorsCellsParams): Promise<ICellData>;
86
79
 
87
80
  export declare const generateUUID: () => string;
88
81
 
89
- export declare function getXlsxData(file: File): Promise<unknown>;
82
+ export declare function getNumColumns(cells: IObjectMatrixPrimitiveType<ICellData>): number;
90
83
 
91
84
  export declare const handleClearInput: (model: any, strList: string[]) => void;
92
85
 
@@ -98,13 +91,20 @@ export declare interface IGenerateIndicatorsCellsParams {
98
91
 
99
92
  export declare function initDateRange(cycleType: CycleTypeEnum, date: string[] | string): Promise<string[]>;
100
93
 
94
+ /**
95
+ * 智能合并单元格数据
96
+ * 保留原有单元格的属性(如公式、值等),用新数据进行更新
97
+ * @param originalCellData - 原始单元格数据(来自 sheetSnapshot.cellData)
98
+ * @param newCells - 新的单元格数据(来自后端或自生成)
99
+ * @returns 合并后的单元格数据
100
+ */
101
+ export declare function mergeCellData(originalCellData: IObjectMatrixPrimitiveType<ICellData> | undefined, newCells: IObjectMatrixPrimitiveType<ICellData>): IObjectMatrixPrimitiveType<ICellData>;
102
+
101
103
  export declare enum ModeEnum {
102
104
  view = "view",
103
105
  edit = "edit"
104
106
  }
105
107
 
106
- export declare function openMultipleFileSelector(acceptTypes?: string, multiple?: boolean): Promise<unknown>;
107
-
108
108
  export declare const stylePath = "./style.css";
109
109
 
110
110
  export declare type TeamDataType = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tor-univer-sheet",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "style": "./dist/style.css",
5
5
  "description": "基于 Univer 的 Vue3 电子表格组件",
6
6
  "author": "tortormore",
@@ -36,18 +36,17 @@
36
36
  "peerDependencies": {
37
37
  "dayjs": "^1.11.20",
38
38
  "decimal.js": "^10.6.0",
39
- "vue": "^3.5.0",
40
- "xlsx": "^0.18.5"
39
+ "vue": "^3.5.0"
41
40
  },
42
41
  "dependencies": {
43
- "@univerjs/core": "^0.15.5",
44
- "@univerjs/preset-sheets-advanced": "^0.15.5",
45
- "@univerjs/preset-sheets-core": "^0.15.5",
46
- "@univerjs/preset-sheets-drawing": "^0.15.5",
47
- "@univerjs/preset-sheets-note": "^0.15.5",
48
- "@univerjs/presets": "^0.15.5",
49
- "@univerjs/ui": "^0.15.5",
50
- "@univerjs/ui-adapter-vue3": "^0.15.5",
42
+ "@univerjs/core": "^0.18.0",
43
+ "@univerjs/preset-sheets-advanced": "^0.18.0",
44
+ "@univerjs/preset-sheets-core": "^0.18.0",
45
+ "@univerjs/preset-sheets-drawing": "^0.18.0",
46
+ "@univerjs/preset-sheets-note": "^0.18.0",
47
+ "@univerjs/presets": "^0.18.0",
48
+ "@univerjs/ui": "^0.18.0",
49
+ "@univerjs/ui-adapter-vue3": "^0.18.0",
51
50
  "vite-plugin-dts": "^4.5.4"
52
51
  },
53
52
  "devDependencies": {
@@ -0,0 +1,59 @@
1
+ import {
2
+ ICellData,
3
+ IObjectMatrixPrimitiveType,
4
+ } from '@univerjs/presets'
5
+
6
+
7
+ export function getNumColumns(cells: IObjectMatrixPrimitiveType<ICellData>) {
8
+ const result = Object.entries(cells).reduce((acc, [rowNum, cols]) => {
9
+ const colsNum = Math.max(...Object.keys(cols).map(Number))
10
+ if (colsNum > acc) {
11
+ acc = Number(colsNum)
12
+ } else {
13
+ acc = Number(acc) || 0
14
+ }
15
+ return acc
16
+ }, 0)
17
+ return result
18
+ }
19
+ /**
20
+ * 智能合并单元格数据
21
+ * 保留原有单元格的属性(如公式、值等),用新数据进行更新
22
+ * @param originalCellData - 原始单元格数据(来自 sheetSnapshot.cellData)
23
+ * @param newCells - 新的单元格数据(来自后端或自生成)
24
+ * @returns 合并后的单元格数据
25
+ */
26
+ export function mergeCellData(
27
+ originalCellData: IObjectMatrixPrimitiveType<ICellData> | undefined,
28
+ newCells: IObjectMatrixPrimitiveType<ICellData>
29
+ ): IObjectMatrixPrimitiveType<ICellData> {
30
+ const result = JSON.parse(JSON.stringify(originalCellData || {})) as IObjectMatrixPrimitiveType<ICellData>
31
+
32
+ for (const [rowNum, cols] of Object.entries(newCells)) {
33
+ if (!result[rowNum]) {
34
+ result[rowNum] = {}
35
+ }
36
+
37
+ for (const [colNum, newCellData] of Object.entries(cols)) {
38
+ const cellData = newCellData as ICellData
39
+ const originalCell = result[rowNum]?.[colNum]
40
+
41
+ if (originalCell) {
42
+ result[rowNum][colNum] = {
43
+ ...originalCell,
44
+ ...cellData,
45
+ custom: {
46
+ ...originalCell.custom,
47
+ ...(cellData.custom || {})
48
+ }
49
+ }
50
+ } else {
51
+ result[rowNum][colNum] = cellData
52
+ }
53
+ }
54
+ }
55
+
56
+ return result
57
+ }
58
+
59
+
@@ -16,3 +16,7 @@ export type {
16
16
  TeamDataType,
17
17
  } from './UniverSheet.data'
18
18
 
19
+ export {
20
+ getNumColumns,
21
+ mergeCellData
22
+ } from './Methods.data'
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export {
7
7
  CycleTypeEnum,
8
8
  } from './components/UniverSheet'
9
9
 
10
+
10
11
  export type {
11
12
  UniverSheetsProps,
12
13
  IGenerateIndicatorsCellsParams,
@@ -17,17 +18,14 @@ export {
17
18
  initDateRange,
18
19
  filterIndicatorsCell,
19
20
  generateIndicatorsCells,
21
+ mergeCellData,
22
+ getNumColumns
20
23
  } from './components/UniverSheet'
21
24
 
22
25
  export { decimal } from './utils/decimal'
23
26
 
24
27
  export { handleClearInput, generateUUID } from './utils'
25
28
 
26
- export {
27
- openMultipleFileSelector,
28
- getXlsxData,
29
- downloadBlobRes,
30
- } from './utils/fileHelp'
31
29
 
32
30
  // 导出样式文件路径(不导入,让使用者自己导入)
33
31
  export const stylePath = './style.css'
@@ -1,69 +0,0 @@
1
- import { read, utils } from 'xlsx'
2
-
3
- export async function openMultipleFileSelector(acceptTypes = '*', multiple = false) {
4
- const fileInput = document.createElement('input')
5
- fileInput.type = 'file'
6
- fileInput.accept = acceptTypes
7
- fileInput.multiple = multiple // 允许多选
8
- fileInput.click()
9
- return new Promise((resolve, reject) => {
10
- fileInput.onchange = function () {
11
- const files = Array.from(fileInput?.files ?? [])
12
- if (files.length > 0) {
13
- resolve(files)
14
- } else {
15
- reject()
16
- }
17
- }
18
- })
19
- }
20
- export function getXlsxData(file: File) {
21
- return new Promise((resolve, reject) => {
22
- const reader = new FileReader()
23
- reader.onload = (ev) => {
24
- try {
25
- const data = ev.target?.result
26
- if (!data) {
27
- reject('读取文件失败')
28
- return
29
- }
30
- const workbook = read(data, {
31
- type: 'binary'
32
- })
33
- const sheetData: any[] = []
34
- workbook.SheetNames.forEach((name) => {
35
- sheetData.push(utils.sheet_to_json(workbook.Sheets[name]))
36
- })
37
- resolve(sheetData)
38
- } catch (e) {
39
- reject('读取错误!')
40
- }
41
- }
42
- reader.readAsBinaryString(file)
43
- })
44
- }
45
- /**
46
- * 下载axios导出的文件
47
- * @param res
48
- * @param _filename
49
- */
50
- export const downloadBlobRes = (res: any, _filename: string | undefined = undefined) => {
51
- const data = res.data
52
- if (data instanceof Blob) {
53
- let filename = res.headers.get('content-disposition')?.split('filename=')?.[1] ?? '未知文件'
54
- filename = decodeURIComponent(filename)
55
- if (_filename) filename = _filename
56
- if (typeof (window as any).chrome !== 'undefined') {
57
- const link = document.createElement('a')
58
- const url = URL.createObjectURL(data)
59
- link.href = url
60
- link.download = filename
61
- link.click()
62
- URL.revokeObjectURL(url)
63
- } else {
64
- const url = URL.createObjectURL(data)
65
- window.open(url)
66
- URL.revokeObjectURL(url)
67
- }
68
- }
69
- }