tor-univer-sheet 1.1.13 → 1.1.14

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,64 +1,64 @@
1
1
  import l from "dayjs";
2
- import { CellValueType as U } from "@univerjs/presets";
3
- import z from "decimal.js";
4
- const ft = (t, r) => {
5
- for (const o of r)
6
- t[o] = null;
7
- }, K = () => {
2
+ import { CellValueType as R } from "@univerjs/presets";
3
+ import Z from "decimal.js";
4
+ const mt = (t, o) => {
5
+ for (const r of o)
6
+ t[r] = null;
7
+ }, L = () => {
8
8
  if (typeof crypto == "object") {
9
9
  if (typeof crypto.randomUUID == "function")
10
10
  return crypto.randomUUID();
11
11
  if (typeof crypto.getRandomValues == "function" && typeof Uint8Array == "function") {
12
- const o = (e) => {
13
- const c = Number(e);
14
- return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16);
12
+ const r = (e) => {
13
+ const u = Number(e);
14
+ return (u ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> u / 4).toString(16);
15
15
  };
16
- return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, o);
16
+ return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, r);
17
17
  }
18
18
  }
19
- let t = (/* @__PURE__ */ new Date()).getTime(), r = typeof performance < "u" && performance.now && performance.now() * 1e3 || 0;
20
- 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, (r) => {
21
21
  let e = Math.random() * 16;
22
- return t > 0 ? (e = (t + e) % 16 | 0, t = Math.floor(t / 16)) : (e = (r + e) % 16 | 0, r = Math.floor(r / 16)), (o === "x" ? e : e & 3 | 8).toString(16);
22
+ return t > 0 ? (e = (t + e) % 16 | 0, t = Math.floor(t / 16)) : (e = (o + e) % 16 | 0, o = Math.floor(o / 16)), (r === "x" ? e : e & 3 | 8).toString(16);
23
23
  });
24
24
  };
25
- function mt(t) {
25
+ function lt(t) {
26
26
  return {
27
27
  ...t?.workbookData,
28
- id: t?.id || K(),
28
+ id: t?.id || L(),
29
29
  name: t?.name || "未命名",
30
30
  appVersion: t?.appVersion || "1.0.0"
31
31
  };
32
32
  }
33
- const L = Object.prototype.toString, Z = (t, r) => L.call(t) === `[object ${r}]`, Q = (t) => typeof t < "u", W = (t) => !Q(t), X = (t) => t !== null && Z(t, "Object"), I = (t) => t == null || typeof t > "u" ? !0 : q(t) || rt(t) ? t.length === 0 : t instanceof Map || t instanceof Set ? t.size === 0 : X(t) ? Object.keys(t).length === 0 : !1, tt = (t) => t === null, et = (t) => W(t) || tt(t), rt = (t) => Z(t, "String"), q = (t) => t && Array.isArray(t);
34
- class ot {
33
+ const Q = Object.prototype.toString, _ = (t, o) => Q.call(t) === `[object ${o}]`, W = (t) => typeof t < "u", X = (t) => !W(t), tt = (t) => t !== null && _(t, "Object"), U = (t) => t == null || typeof t > "u" ? !0 : F(t) || ot(t) ? t.length === 0 : t instanceof Map || t instanceof Set ? t.size === 0 : tt(t) ? Object.keys(t).length === 0 : !1, et = (t) => t === null, rt = (t) => X(t) || et(t), ot = (t) => _(t, "String"), F = (t) => t && Array.isArray(t);
34
+ class nt {
35
35
  value;
36
- constructor(r) {
37
- this.value = new z(r);
36
+ constructor(o) {
37
+ this.value = new Z(o);
38
38
  }
39
39
  /**
40
40
  * 加法运算
41
41
  * @param num 要加的数
42
42
  * @returns DecimalChain 实例,支持链式调用
43
43
  */
44
- add(r) {
45
- return this.value = this.value.add(r || 0), this;
44
+ add(o) {
45
+ return this.value = this.value.add(o || 0), this;
46
46
  }
47
47
  /**
48
48
  * 减法运算
49
49
  * @param num 要减的数
50
50
  * @returns DecimalChain 实例,支持链式调用
51
51
  */
52
- subtract(r) {
53
- return this.value = this.value.sub(r || 0), this;
52
+ subtract(o) {
53
+ return this.value = this.value.sub(o || 0), this;
54
54
  }
55
55
  /**
56
56
  * 乘法运算
57
57
  * @param num 要乘的数
58
58
  * @returns DecimalChain 实例,支持链式调用
59
59
  */
60
- multiply(r) {
61
- return this.value = this.value.mul(r || 0), this;
60
+ multiply(o) {
61
+ return this.value = this.value.mul(o || 0), this;
62
62
  }
63
63
  /**
64
64
  * 除法运算
@@ -66,11 +66,11 @@ class ot {
66
66
  * @returns DecimalChain 实例,支持链式调用
67
67
  * @throws 当除数为0时抛出错误
68
68
  */
69
- divide(r) {
70
- const o = new z(r);
71
- if (o.isZero())
69
+ divide(o) {
70
+ const r = new Z(o);
71
+ if (r.isZero())
72
72
  throw new Error("除数是0");
73
- return this.value = this.value.div(o), this;
73
+ return this.value = this.value.div(r), this;
74
74
  }
75
75
  /**
76
76
  * 保留小数位数
@@ -78,8 +78,8 @@ class ot {
78
78
  * @param rounding 舍入模式,默认为四舍五入
79
79
  * @returns DecimalChain 实例,支持链式调用
80
80
  */
81
- toFixed(r, o) {
82
- return this.value = new z(this.value.toFixed(r, o)), this;
81
+ toFixed(o, r) {
82
+ return this.value = new Z(this.value.toFixed(o, r)), this;
83
83
  }
84
84
  /**
85
85
  * 返回当前值
@@ -103,476 +103,515 @@ class ot {
103
103
  return this.value.toNumber();
104
104
  }
105
105
  }
106
- function $(t = 0) {
107
- return new ot(t);
106
+ function C(t = 0) {
107
+ return new nt(t);
108
108
  }
109
- var nt = /* @__PURE__ */ ((t) => (t.无 = "no", t.年 = "year", t.月 = "month", t.周 = "week", t.天 = "day", t.班组 = "shift", t.小时 = "hour", t.半小时 = "half_hour", t))(nt || {}), st = /* @__PURE__ */ ((t) => (t.view = "view", t.edit = "edit", t))(st || {});
110
- async function lt(t, r) {
111
- if (!r) return Promise.reject("日期不能为空");
109
+ var st = /* @__PURE__ */ ((t) => (t.无 = "no", t.年 = "year", t.月 = "month", t.周 = "week", t.天 = "day", t.班组 = "shift", t.小时 = "hour", t.半小时 = "half_hour", t))(st || {}), at = /* @__PURE__ */ ((t) => (t.view = "view", t.edit = "edit", t))(at || {});
110
+ async function dt(t, o) {
111
+ if (!o) return Promise.reject("日期不能为空");
112
112
  switch (t) {
113
113
  case "year":
114
- if (q(r))
115
- return Promise.resolve(r);
116
- const o = l(r);
117
- if (!o.isValid())
114
+ if (F(o))
115
+ return Promise.resolve(o);
116
+ const r = l(o);
117
+ if (!r.isValid())
118
118
  return Promise.reject("无效的日期格式");
119
- const e = o.year(), c = `${e}-01`, s = `${e}-12`;
120
- return Promise.resolve([c, s]);
119
+ const e = r.year(), u = `${e}-01`, s = `${e}-12`;
120
+ return Promise.resolve([u, s]);
121
121
  case "month":
122
- if (q(r))
123
- return Promise.resolve(r);
124
- const i = l(r);
125
- if (!i.isValid())
122
+ if (F(o))
123
+ return Promise.resolve(o);
124
+ const D = l(o);
125
+ if (!D.isValid())
126
126
  return Promise.reject("无效的日期格式");
127
- const N = i.startOf("month").format("YYYY-MM-DD"), n = i.endOf("month").format("YYYY-MM-DD");
128
- return Promise.resolve([N, n]);
127
+ const d = D.startOf("month").format("YYYY-MM-DD"), c = D.endOf("month").format("YYYY-MM-DD");
128
+ return Promise.resolve([d, c]);
129
129
  case "day":
130
- if (q(r))
131
- return Promise.resolve(r);
132
- const w = l(r);
133
- if (!w.isValid())
130
+ if (F(o))
131
+ return Promise.resolve(o);
132
+ const Y = l(o);
133
+ if (!Y.isValid())
134
134
  return Promise.reject("无效的日期格式");
135
- const d = w.startOf("day").format("YYYY-MM-DD HH:mm:ss"), H = w.endOf("day").format("YYYY-MM-DD HH:mm:ss");
136
- return Promise.resolve([d, H]);
135
+ const S = Y.startOf("day").format("YYYY-MM-DD HH:mm:ss"), m = Y.endOf("day").format("YYYY-MM-DD HH:mm:ss");
136
+ return Promise.resolve([S, m]);
137
137
  default:
138
138
  return Promise.reject("不支持的周期类型");
139
139
  }
140
140
  }
141
- function S(t, r, o) {
142
- if (!o) return 0;
141
+ function H(t, o, r) {
142
+ if (!r) return 0;
143
143
  const e = {
144
144
  year: "YYYY",
145
145
  month: "YYYY-MM",
146
146
  day: "YYYY-MM-DD",
147
147
  hour: "HH:mm:ss"
148
- }[o];
149
- return ["day", "hour"].includes(o) ? l(r, e).diff(l(t, e), o) : l(r, e).diff(l(t, e), o);
148
+ }[r];
149
+ return ["day", "hour"].includes(r) ? l(o, e).diff(l(t, e), r) : l(o, e).diff(l(t, e), r);
150
150
  }
151
- function F(t, r, o) {
152
- if (!o)
151
+ function J(t, o, r) {
152
+ if (!r)
153
153
  throw new Error("日期类型不能为空");
154
154
  const e = {
155
155
  year: "YYYY",
156
156
  month: "YYYY-MM",
157
157
  day: "YYYY-MM-DD",
158
158
  hour: "HH:mm:ss"
159
- }[o];
160
- return l(t).subtract(r, o).format(e);
159
+ }[r];
160
+ return l(t).subtract(o, r).format(e);
161
161
  }
162
- function x(t, r, o, e) {
163
- const c = "YYYY-MM-DD HH:mm:ss", s = A(t, r, o, e), i = l(s);
164
- if (r === "month") {
165
- const n = i.month();
166
- return n === 0 ? [i.startOf("month").format(c), i.date(25).endOf("day").format(c)] : n === 11 ? [i.subtract(1, "month").date(26).startOf("day").format(c), i.endOf("month").format(c)] : [i.subtract(1, "month").date(26).startOf("day").format(c), i.date(25).endOf("day").format(c)];
162
+ function O(t, o, r, e) {
163
+ const u = "YYYY-MM-DD HH:mm:ss", s = V(t, o, r, e), D = l(s);
164
+ if (o === "month") {
165
+ const c = D.month();
166
+ return c === 0 ? [D.startOf("month").format(u), D.date(25).endOf("day").format(u)] : c === 11 ? [D.subtract(1, "month").date(26).startOf("day").format(u), D.endOf("month").format(u)] : [D.subtract(1, "month").date(26).startOf("day").format(u), D.date(25).endOf("day").format(u)];
167
167
  }
168
- const N = { year: "year", day: "day", hour: "hour" };
169
- return [i.startOf(N[r]).format(c), i.endOf(N[r]).format(c)];
168
+ const d = { year: "year", day: "day", hour: "hour" };
169
+ return [D.startOf(d[o]).format(u), D.endOf(d[o]).format(u)];
170
170
  }
171
- function A(t, r, o, e) {
172
- const c = {
171
+ function V(t, o, r, e) {
172
+ const u = {
173
173
  year: "YYYY",
174
174
  month: "YYYY-MM",
175
175
  day: "YYYY-MM-DD",
176
176
  hour: "YYYY-MM-DD HH:mm:ss"
177
- }[r];
178
- return l(t, c).add(o * e, r).format(c);
177
+ }[o];
178
+ return l(t, u).add(r * e, o).format(u);
179
179
  }
180
- function g(t, r, o) {
181
- return t[r] || (t[r] = {}), t[r][o] || (t[r][o] = {}), t[r][o];
180
+ function w(t, o, r) {
181
+ return t[o] || (t[o] = {}), t[o][r] || (t[o][r] = {}), t[o][r];
182
182
  }
183
- async function dt(t) {
183
+ async function ht(t) {
184
184
  if (!t)
185
185
  throw new Error("cellData is required");
186
- const r = Object.entries(t).reduce((o, e) => {
187
- const [c, s] = e;
188
- for (const [i, N] of Object.entries(s)) {
189
- const { custom: n, v: w, t: d, s: H } = N;
190
- if (!n) continue;
191
- const { cellType: m } = n, B = !n.hasOwnProperty("writeBack") || I(n?.writeBack) ? !0 : n.writeBack;
192
- if (m === "indicator") {
193
- const P = g(o, c, i);
186
+ const o = Object.entries(t).reduce((r, e) => {
187
+ const [u, s] = e;
188
+ for (const [D, d] of Object.entries(s)) {
189
+ const { custom: c, v: Y, t: S, s: m } = d;
190
+ if (!c) continue;
191
+ const { cellType: E } = c, f = !c.hasOwnProperty("writeBack") || U(c?.writeBack) ? !0 : c.writeBack;
192
+ if (E === "indicator") {
193
+ const P = w(r, u, D);
194
194
  P.custom = {
195
- ...n,
196
- required: I(n?.required) ? !1 : n?.required,
197
- defaultShift: I(n?.defaultShift) ? !1 : n?.defaultShift,
198
- forwardPush: I(n?.forwardPush) ? !1 : n?.forwardPush,
199
- forwardPushTimes: I(n?.useDefaultEndDate) ? 0 : n?.forwardPushTimes,
200
- useDefaultEndDate: I(n?.useDefaultEndDate) ? !1 : n?.useDefaultEndDate,
201
- copyType: I(n?.copyType) ? "" : n?.copyType,
202
- writeBack: B
203
- }, P.s = H, P.t = d, P.v = w;
195
+ ...c,
196
+ required: U(c?.required) ? !1 : c?.required,
197
+ defaultShift: U(c?.defaultShift) ? !1 : c?.defaultShift,
198
+ forwardPush: U(c?.forwardPush) ? !1 : c?.forwardPush,
199
+ forwardPushTimes: U(c?.useDefaultEndDate) ? 0 : c?.forwardPushTimes,
200
+ useDefaultEndDate: U(c?.useDefaultEndDate) ? !1 : c?.useDefaultEndDate,
201
+ copyType: U(c?.copyType) ? "" : c?.copyType,
202
+ writeBack: f
203
+ }, P.s = m, P.t = S, P.v = Y;
204
204
  }
205
205
  }
206
- return o;
206
+ return r;
207
207
  }, {});
208
- return !r || I(r) ? Promise.reject(new Error("No data found")) : Promise.resolve(r);
208
+ return !o || U(o) ? Promise.reject(new Error("No data found")) : Promise.resolve(o);
209
209
  }
210
- function E(t, r) {
211
- return t.replace(/\$\{([^}]+)\}/g, (o, e) => {
210
+ function A(t, o) {
211
+ return t.replace(/\$\{([^}]+)\}/g, (r, e) => {
212
212
  try {
213
- const c = Object.keys(r), s = Object.values(r);
214
- return new Function(...c, `return ${e};`)(...s);
215
- } catch (c) {
216
- return console.error(`表达式执行失败: ${e}`, c), o;
213
+ const u = Object.keys(o), s = Object.values(o);
214
+ return new Function(...u, `return ${e};`)(...s);
215
+ } catch (u) {
216
+ return console.error(`表达式执行失败: ${e}`, u), r;
217
217
  }
218
218
  });
219
219
  }
220
- function at({
220
+ function it({
221
221
  acc: t,
222
- params: r,
223
- initRowNum: o,
222
+ params: o,
223
+ initRowNum: r,
224
224
  initColNum: e,
225
- cellData: c
225
+ cellData: u
226
226
  }) {
227
- const { rangeData: s, currentDay: i, extraArgs: N } = r;
228
- N?.teamData;
229
- const { cycleType: n, timeIncrement: w, forwardPush: d, forwardPushTimes: H, copyType: m, copyInterval: B, defaultShift: P, templateStr: v, useDefaultEndDate: R } = c.custom;
230
- let b = 0;
231
- switch (n) {
227
+ const { rangeData: s, currentDay: D, extraArgs: d } = o, c = d?.teamData || {}, { cycleType: Y, timeIncrement: S, forwardPush: m, forwardPushTimes: E, copyType: f, copyInterval: P, defaultShift: q, templateStr: x, useDefaultEndDate: $ } = u.custom;
228
+ let p = 0;
229
+ switch (Y) {
232
230
  case "day": {
233
- let a = "";
234
- if (d && (a = F(
231
+ let n = "";
232
+ if (m && (n = J(
235
233
  s[0],
236
- H,
234
+ E,
237
235
  "day"
238
236
  /* day */
239
- )), !m) {
240
- let u = "";
241
- d ? u = a : u = s[0];
242
- const Y = g(t, o, e);
243
- Y.v = v ? E(v, { businessDate: u, dayjs: l }) : l(u).format("YYYY-MM-DD"), Y.t = U.STRING;
237
+ )), !f) {
238
+ let i = "";
239
+ m ? i = n : i = s[0];
240
+ const y = w(t, r, e);
241
+ y.v = x ? A(x, { businessDate: i, dayjs: l }) : l(i).format("YYYY-MM-DD"), y.t = R.STRING;
244
242
  break;
245
243
  }
246
- d ? b = S(
247
- a,
244
+ m ? p = H(
245
+ n,
248
246
  s[0],
249
247
  "day"
250
248
  /* day */
251
- ) : (b = S(
249
+ ) : (p = H(
252
250
  s[0],
253
251
  s[1],
254
252
  "day"
255
253
  /* day */
256
- ), console.log("copyNum", b));
257
- for (let u = 0; u <= Math.abs(b === 0 ? 1 : b); u++) {
258
- const Y = u * (B + 1);
259
- let O = "";
260
- d ? O = A(a, "day", u, w) : O = A(s[0], "day", u, w);
261
- const T = m === "right" ? o : o + Y, M = m === "right" ? e + Y : e, D = g(t, T, M);
262
- D.v = v ? E(v, { businessDate: O, dayjs: l }) : l(O).format("YYYY-MM-DD"), D.t = U.STRING;
254
+ ), console.log("copyNum", p));
255
+ for (let i = 0; i <= Math.abs(p === 0 ? 1 : p); i++) {
256
+ const y = i * (P + 1);
257
+ let k = "";
258
+ m ? k = V(n, "day", i, S) : k = V(s[0], "day", i, S);
259
+ const N = f === "right" ? r : r + y, M = f === "right" ? e + y : e, b = w(t, N, M);
260
+ b.v = x ? A(x, { businessDate: k, dayjs: l }) : l(k).format("YYYY-MM-DD"), b.t = R.STRING;
263
261
  }
264
262
  break;
265
263
  }
266
264
  case "month": {
267
- if (!m) {
268
- const [a, u] = x(s[1], "month", 0, 1), Y = g(t, o, e);
269
- Y.v = l(u).format("YYYY-MM"), Y.t = U.STRING;
265
+ if (!f) {
266
+ const [n, i] = O(s[1], "month", 0, 1), y = w(t, r, e);
267
+ y.v = l(i).format("YYYY-MM"), y.t = R.STRING;
270
268
  break;
271
269
  }
272
- b = S(
270
+ p = H(
273
271
  s[0],
274
272
  s[1],
275
273
  "month"
276
274
  /* month */
277
275
  );
278
- for (let a = 0; a <= Math.abs(b === 0 ? 1 : b); a++) {
279
- const u = a * (B + 1), Y = m === "right" ? o : o + u, O = m === "right" ? e + u : e, T = g(t, Y, O);
280
- T.v = A(s[0], "month", a, w), T.t = U.STRING;
276
+ for (let n = 0; n <= Math.abs(p === 0 ? 1 : p); n++) {
277
+ const i = n * (P + 1), y = f === "right" ? r : r + i, k = f === "right" ? e + i : e, N = w(t, y, k);
278
+ N.v = V(s[0], "month", n, S), N.t = R.STRING;
281
279
  }
282
280
  break;
283
281
  }
284
282
  case "year": {
285
- let a = "";
286
- if (d && (a = F(
283
+ let n = "";
284
+ if (m && (n = J(
287
285
  s[0],
288
- H || 0,
286
+ E || 0,
289
287
  "year"
290
288
  /* year */
291
- )), !m) {
292
- const u = d ? a : s[0], [Y, O] = x(u, "year", 0, 1), T = g(t, o, e), [, M] = x(s[1], "month", 0, 1);
293
- T.v = v ? E(v, {
294
- startTime: Y,
295
- endTime: O,
289
+ )), !f) {
290
+ const i = m ? n : s[0], [y, k] = O(i, "year", 0, 1), N = w(t, r, e), [, M] = O(s[1], "month", 0, 1);
291
+ N.v = x ? A(x, {
292
+ startTime: y,
293
+ endTime: k,
296
294
  rangeData: s,
297
295
  dayjs: l
298
- }) : u, T.t = U.STRING;
296
+ }) : i, N.t = R.STRING;
299
297
  break;
300
298
  }
301
- d ? b = S(
302
- a,
299
+ m ? p = H(
300
+ n,
303
301
  s[0],
304
302
  "year"
305
303
  /* year */
306
- ) : b = S(
304
+ ) : p = H(
307
305
  s[0],
308
306
  s[1],
309
307
  "year"
310
308
  /* year */
311
309
  );
312
- for (let u = 0; u <= Math.abs(b === 0 ? 1 : b); u++) {
313
- const Y = u * (B + 1), O = m === "right" ? o : o + Y, T = m === "right" ? e + Y : e, [M, D] = x(s[0], "year", u, w), f = g(t, O, T), h = A(s[0], "year", u, w);
314
- f.v = v ? E(v, {
310
+ for (let i = 0; i <= Math.abs(p === 0 ? 1 : p); i++) {
311
+ const y = i * (P + 1), k = f === "right" ? r : r + y, N = f === "right" ? e + y : e, [M, b] = O(s[0], "year", i, S), a = w(t, k, N), h = V(s[0], "year", i, S);
312
+ a.v = x ? A(x, {
315
313
  startTime: M,
316
- endTime: D,
314
+ endTime: b,
317
315
  rangeData: s,
318
316
  dayjs: l
319
- }) : h, f.t = U.STRING;
317
+ }) : h, a.t = R.STRING;
320
318
  }
321
319
  break;
322
320
  }
323
321
  case "hour": {
324
- if (!m) {
325
- const a = g(t, o, e);
326
- if (a.t = U.STRING, P) {
327
- a.v = l(s[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
322
+ if (!f) {
323
+ const n = w(t, r, e);
324
+ if (n.t = R.STRING, q) {
325
+ n.v = l(s[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
328
326
  break;
329
327
  }
330
- a.v = l(i).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
328
+ n.v = l(D).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
331
329
  break;
332
330
  }
333
- b = S(
331
+ p = H(
334
332
  s[0],
335
333
  s[1],
336
334
  "hour"
337
335
  /* hour */
338
336
  );
339
- for (let a = 0; a <= Math.abs(b === 0 ? 1 : b); a++) {
340
- const u = a * (B + 1), Y = m === "right" ? o : o + u, O = m === "right" ? e + u : e, T = g(t, Y, O);
341
- if (T.t = U.STRING, P) {
337
+ for (let n = 0; n <= Math.abs(p === 0 ? 1 : p); n++) {
338
+ const i = n * (P + 1), y = f === "right" ? r : r + i, k = f === "right" ? e + i : e, N = w(t, y, k);
339
+ if (N.t = R.STRING, q) {
342
340
  const M = l(s[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
343
- T.v = A(M, "hour", a, w);
341
+ N.v = V(M, "hour", n, S);
344
342
  continue;
345
343
  }
346
- T.v = A(l(i).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), "hour", a, w);
344
+ N.v = V(l(D).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), "hour", n, S);
345
+ }
346
+ break;
347
+ }
348
+ case "shift": {
349
+ if (!f) {
350
+ const n = w(t, r, e);
351
+ n.t = R.STRING, n.v = x ? A(x, {
352
+ rangeData: s,
353
+ dayjs: l
354
+ }) : s[0];
355
+ break;
356
+ }
357
+ if (!c.length)
358
+ throw new Error("没有获取到当班数据");
359
+ for (let n = 0; n < c.length; n++) {
360
+ const i = c[n], { startDatetime: y, endDatetime: k } = i, N = n * (P + 1), M = f === "right" ? r : C(r).add(N).toNumber(), b = f === "right" ? C(e).add(N).toNumber() : e, a = w(t, M, b);
361
+ a.v = x ? A(x, {
362
+ team: i
363
+ }) : y;
347
364
  }
365
+ break;
348
366
  }
349
367
  }
350
368
  }
351
- async function ht(t, r) {
369
+ async function Yt(t, o) {
352
370
  if (!t)
353
371
  return Promise.reject("没有可用的单元格数据");
354
- const { extraArgs: o, rangeData: e } = r;
372
+ const { extraArgs: r, rangeData: e } = o;
355
373
  if (!e.length)
356
374
  return Promise.reject("处理时间范围失败, rangeData不能为空");
357
- o?.teamData;
358
- const c = r?.currentDay || l().format("YYYY-MM-DD"), s = Object.entries(t).reduce((i, N) => {
359
- const [n, w] = N;
360
- for (const [d, H] of Object.entries(w)) {
361
- const { custom: m } = H;
362
- if (!m) continue;
375
+ const u = r?.teamData || [], s = o?.currentDay || l().format("YYYY-MM-DD"), D = Object.entries(t).reduce((d, c) => {
376
+ const [Y, S] = c;
377
+ for (const [m, E] of Object.entries(S)) {
378
+ const { custom: f } = E;
379
+ if (!f) continue;
363
380
  const {
364
- cellType: B,
365
- cycleType: P,
366
- timeIncrement: v,
367
- forwardPush: R,
368
- forwardPushTimes: b,
369
- copyType: a,
370
- copyInterval: u,
371
- defaultShift: Y,
372
- useDefaultStartDate: O,
373
- useDefaultEndDate: T
374
- } = m;
375
- if (B === "time") {
376
- at({ acc: i, params: r, initRowNum: Number(n), initColNum: Number(d), cellData: H });
381
+ cellType: P,
382
+ cycleType: q,
383
+ timeIncrement: x,
384
+ forwardPush: $,
385
+ forwardPushTimes: p,
386
+ copyType: n,
387
+ copyInterval: i,
388
+ defaultShift: y,
389
+ useDefaultStartDate: k,
390
+ useDefaultEndDate: N
391
+ } = f;
392
+ if (P === "time") {
393
+ it({ acc: d, params: o, initRowNum: Number(Y), initColNum: Number(m), cellData: E });
377
394
  continue;
378
395
  }
379
396
  const M = {
380
- cycleType: P,
381
- indicatorName: m.indicatorName,
382
- indicatorCode: m.indicatorCode,
383
- indicatorId: m.indicatorId,
384
- indicatorDimensionName: m.indicatorDimensionName,
385
- indicatorDimensionConfig: m.indicatorDimensionConfig,
386
- required: et(m?.required) ?? !1,
387
- cellType: m.cellType,
388
- defaultShift: m?.defaultShift || !1,
389
- writeBack: I(m?.writeBack) ? !0 : m.writeBack
397
+ cycleType: q,
398
+ indicatorName: f.indicatorName,
399
+ indicatorCode: f.indicatorCode,
400
+ indicatorId: f.indicatorId,
401
+ indicatorDimensionName: f.indicatorDimensionName,
402
+ indicatorDimensionConfig: f.indicatorDimensionConfig,
403
+ required: rt(f?.required) ?? !1,
404
+ cellType: f.cellType,
405
+ defaultShift: f?.defaultShift || !1,
406
+ writeBack: U(f?.writeBack) ? !0 : f.writeBack
390
407
  };
391
- let D = 0;
392
- switch (P) {
408
+ let b = 0;
409
+ switch (q) {
393
410
  case "day": {
394
- let f = "";
395
- if (R && (f = F(
411
+ let a = "";
412
+ if ($ && (a = J(
396
413
  e[0],
397
- b || 0,
414
+ p || 0,
398
415
  "day"
399
416
  /* day */
400
- )), !a) {
401
- const h = R ? f : e[0], [p, y] = x(h, "day", 0, 1), k = g(i, n, d);
402
- k.custom = {
417
+ )), !n) {
418
+ const h = $ ? a : e[0], [T, g] = O(h, "day", 0, 1), v = w(d, Y, m);
419
+ v.custom = {
403
420
  ...M,
404
- startTime: p,
405
- endTime: y
421
+ startTime: T,
422
+ endTime: g
406
423
  };
407
424
  break;
408
425
  }
409
- R ? D = S(
410
- f,
426
+ $ ? b = H(
427
+ a,
411
428
  e[0],
412
429
  "day"
413
430
  /* day */
414
- ) : D = S(
431
+ ) : b = H(
415
432
  e[0],
416
433
  e[1],
417
434
  "day"
418
435
  /* day */
419
436
  );
420
- for (let h = 0; h <= Math.abs(D === 0 ? 1 : D); h++) {
421
- const p = h * (u + 1), y = R ? f : e[0], [k, j] = x(y, "day", h, v), C = a === "right" ? n : $(n).add(p).toNumber(), G = a === "right" ? $(d).add(p).toNumber() : d, V = g(i, C, G);
422
- V.custom = {
437
+ for (let h = 0; h <= Math.abs(b === 0 ? 1 : b); h++) {
438
+ const T = h * (i + 1), g = $ ? a : e[0], [v, j] = O(g, "day", h, x), I = n === "right" ? Y : C(Y).add(T).toNumber(), B = n === "right" ? C(m).add(T).toNumber() : m, G = w(d, I, B);
439
+ G.custom = {
423
440
  ...M,
424
- startTime: k,
441
+ startTime: v,
425
442
  endTime: j
426
443
  };
427
444
  }
428
445
  break;
429
446
  }
430
447
  case "month": {
431
- if (!a) {
432
- const [f, h] = x(e[1], "month", 0, 1), p = g(i, n, d);
433
- p.custom = {
448
+ if (!n) {
449
+ const [a, h] = O(e[1], "month", 0, 1), T = w(d, Y, m);
450
+ T.custom = {
434
451
  ...M,
435
- startTime: f,
452
+ startTime: a,
436
453
  endTime: h
437
454
  };
438
455
  break;
439
456
  }
440
- D = S(
457
+ b = H(
441
458
  e[0],
442
459
  e[1],
443
460
  "month"
444
461
  /* month */
445
462
  );
446
- for (let f = 0; f <= Math.abs(D === 0 ? 1 : D); f++) {
447
- const h = f * (u + 1), p = a === "right" ? n : $(n).add(h).toNumber(), y = a === "right" ? $(d).add(h).toNumber() : d, [k, j] = x(e[0], "month", f, v), C = g(i, p, y);
448
- C.custom = {
463
+ for (let a = 0; a <= Math.abs(b === 0 ? 1 : b); a++) {
464
+ const h = a * (i + 1), T = n === "right" ? Y : C(Y).add(h).toNumber(), g = n === "right" ? C(m).add(h).toNumber() : m, [v, j] = O(e[0], "month", a, x), I = w(d, T, g);
465
+ I.custom = {
449
466
  ...M,
450
- startTime: k,
467
+ startTime: v,
451
468
  endTime: j
452
469
  };
453
470
  }
454
471
  break;
455
472
  }
456
473
  case "year": {
457
- let f = "", h = "", p = "";
458
- if (R) {
459
- f = F(
474
+ let a = "", h = "", T = "";
475
+ if ($) {
476
+ a = J(
460
477
  e[0],
461
- b || 0,
478
+ p || 0,
462
479
  "year"
463
480
  /* year */
464
481
  );
465
- const y = l(e[1]).format("MM");
466
- h = l(`${f}-${y + 1}`).format("YYYY-MM"), p = l(`${f}-${y + 2}`).format("YYYY-MM");
482
+ const g = l(e[1]).format("MM");
483
+ h = l(`${a}-${g + 1}`).format("YYYY-MM"), T = l(`${a}-${g + 2}`).format("YYYY-MM");
467
484
  }
468
- if (!a) {
469
- const y = R ? f : e[0], [k, j] = x(y, "year", 0, 1), C = g(i, n, d), [, G] = x(h, "month", 0, 1), [V] = x(p, "month", 0, 1);
470
- C.custom = {
485
+ if (!n) {
486
+ const g = $ ? a : e[0], [v, j] = O(g, "year", 0, 1), I = w(d, Y, m), [, B] = O(h, "month", 0, 1), [G] = O(T, "month", 0, 1);
487
+ I.custom = {
471
488
  ...M,
472
- startTime: O ? V : k,
473
- endTime: T ? G : j
489
+ startTime: k ? G : v,
490
+ endTime: N ? B : j
474
491
  };
475
492
  break;
476
493
  }
477
- R ? D = S(
478
- f,
494
+ $ ? b = H(
495
+ a,
479
496
  e[0],
480
497
  "year"
481
498
  /* year */
482
- ) : D = S(
499
+ ) : b = H(
483
500
  e[0],
484
501
  e[1],
485
502
  "year"
486
503
  /* year */
487
504
  );
488
- for (let y = 0; y <= Math.abs(D === 0 ? 1 : D); y++) {
489
- const k = y * (u + 1), j = a === "right" ? n : $(n).add(k).toNumber(), C = a === "right" ? $(d).add(k).toNumber() : d, [G, V] = x(e[0], "year", y, v), J = g(i, j, C);
490
- J.custom = {
505
+ for (let g = 0; g <= Math.abs(b === 0 ? 1 : b); g++) {
506
+ const v = g * (i + 1), j = n === "right" ? Y : C(Y).add(v).toNumber(), I = n === "right" ? C(m).add(v).toNumber() : m, [B, G] = O(e[0], "year", g, x), z = w(d, j, I);
507
+ z.custom = {
491
508
  ...M,
492
- startTime: G,
493
- endTime: V
509
+ startTime: B,
510
+ endTime: G
494
511
  };
495
512
  }
496
513
  break;
497
514
  }
498
515
  case "hour": {
499
- if (!a) {
500
- const f = Y ? e[0] : e[0] ?? c, [h, p] = x(f, "hour", 1, 1), y = g(i, n, d);
501
- y.custom = {
516
+ if (!n) {
517
+ const a = y ? e[0] : e[0] ?? s, [h, T] = O(a, "hour", 1, 1), g = w(d, Y, m);
518
+ g.custom = {
502
519
  ...M,
503
520
  startTime: h,
504
- endTime: p
521
+ endTime: T
505
522
  };
506
523
  break;
507
524
  }
508
- D = S(
525
+ b = H(
509
526
  e[0],
510
527
  e[1],
511
528
  "hour"
512
529
  /* hour */
513
530
  );
514
- for (let f = 0; f <= Math.abs(D === 0 ? 1 : D); f++) {
515
- const h = f * (u + 1), p = a === "right" ? n : $(n).add(h).toNumber(), y = a === "right" ? $(d).add(h).toNumber() : d, k = g(i, p, y);
516
- if (Y) {
517
- const V = l(e[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [J, _] = x(V, "hour", f, v);
518
- k.custom = {
531
+ for (let a = 0; a <= Math.abs(b === 0 ? 1 : b); a++) {
532
+ const h = a * (i + 1), T = n === "right" ? Y : C(Y).add(h).toNumber(), g = n === "right" ? C(m).add(h).toNumber() : m, v = w(d, T, g);
533
+ if (y) {
534
+ const G = l(e[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [z, K] = O(G, "hour", a, x);
535
+ v.custom = {
519
536
  ...M,
520
- startTime: J,
521
- endTime: _
537
+ startTime: z,
538
+ endTime: K
522
539
  };
523
540
  continue;
524
541
  }
525
- const j = l(c).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [C, G] = x(j, "hour", f, v);
526
- k.custom = {
542
+ const j = l(s).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [I, B] = O(j, "hour", a, x);
543
+ v.custom = {
527
544
  ...M,
528
- startTime: C,
529
- endTime: G
545
+ startTime: I,
546
+ endTime: B
547
+ };
548
+ }
549
+ break;
550
+ }
551
+ case "shift": {
552
+ if (!n) {
553
+ const [a, h] = e, T = w(d, Y, m);
554
+ T.custom = {
555
+ ...M,
556
+ startTime: a,
557
+ endTime: h
558
+ };
559
+ break;
560
+ }
561
+ if (!u.length)
562
+ throw new Error("没有获取到当班数据");
563
+ for (let a = 0; a < u.length; a++) {
564
+ const h = u[a], { startDatetime: T, endDatetime: g } = h, v = a * (i + 1), j = n === "right" ? Y : C(Y).add(v).toNumber(), I = n === "right" ? C(m).add(v).toNumber() : m, B = w(d, j, I);
565
+ B.custom = {
566
+ ...M,
567
+ startTime: T,
568
+ endTime: g
530
569
  };
531
570
  }
532
571
  break;
533
572
  }
534
573
  }
535
574
  }
536
- return i;
575
+ return d;
537
576
  }, {});
538
- return Promise.resolve(s);
577
+ return Promise.resolve(D);
539
578
  }
540
- function Yt(t) {
541
- return Object.entries(t).reduce((o, [e, c]) => {
542
- const s = Math.max(...Object.keys(c).map(Number));
543
- return s > o ? o = Number(s) : o = Number(o) || 0, o;
579
+ function Dt(t) {
580
+ return Object.entries(t).reduce((r, [e, u]) => {
581
+ const s = Math.max(...Object.keys(u).map(Number));
582
+ return s > r ? r = Number(s) : r = Number(r) || 0, r;
544
583
  }, 0);
545
584
  }
546
- function Dt(t, r) {
547
- const o = JSON.parse(JSON.stringify(t || {}));
548
- for (const [e, c] of Object.entries(r)) {
549
- o[e] || (o[e] = {});
550
- for (const [s, i] of Object.entries(c)) {
551
- const N = i, n = o[e]?.[s];
552
- n ? o[e][s] = {
553
- ...n,
554
- ...N,
585
+ function yt(t, o) {
586
+ const r = JSON.parse(JSON.stringify(t || {}));
587
+ for (const [e, u] of Object.entries(o)) {
588
+ r[e] || (r[e] = {});
589
+ for (const [s, D] of Object.entries(u)) {
590
+ const d = D, c = r[e]?.[s];
591
+ c ? r[e][s] = {
592
+ ...c,
593
+ ...d,
555
594
  custom: {
556
- ...n.custom,
557
- ...N.custom
595
+ ...c.custom,
596
+ ...d.custom
558
597
  }
559
- } : o[e][s] = N;
598
+ } : r[e][s] = d;
560
599
  }
561
600
  }
562
- return o;
601
+ return r;
563
602
  }
564
- const yt = "./style.css";
603
+ const bt = "./style.css";
565
604
  export {
566
- nt as CycleTypeEnum,
567
- st as ModeEnum,
568
- $ as decimal,
569
- dt as filterIndicatorsCell,
570
- ht as generateIndicatorsCells,
571
- K as generateUUID,
572
- Yt as getNumColumns,
573
- ft as handleClearInput,
574
- lt as initDateRange,
575
- Dt as mergeCellData,
576
- yt as stylePath,
577
- mt as useData
605
+ st as CycleTypeEnum,
606
+ at as ModeEnum,
607
+ C as decimal,
608
+ ht as filterIndicatorsCell,
609
+ Yt as generateIndicatorsCells,
610
+ L as generateUUID,
611
+ Dt as getNumColumns,
612
+ mt as handleClearInput,
613
+ dt as initDateRange,
614
+ yt as mergeCellData,
615
+ bt as stylePath,
616
+ lt as useData
578
617
  };
@@ -1 +1 @@
1
- (function(Y,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("dayjs"),require("@univerjs/presets"),require("decimal.js")):typeof define=="function"&&define.amd?define(["exports","dayjs","@univerjs/presets","decimal.js"],c):(Y=typeof globalThis<"u"?globalThis:Y||self,c(Y.TorUniverSheet={},Y.dayjs,Y.presets,Y.Decimal))})(this,(function(Y,c,R,z){"use strict";const W=(e,r)=>{for(const n of r)e[n]=null},_=()=>{if(typeof crypto=="object"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"&&typeof Uint8Array=="function"){const n=t=>{const f=Number(t);return(f^crypto.getRandomValues(new Uint8Array(1))[0]&15>>f/4).toString(16)};return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,n)}}let e=new Date().getTime(),r=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let t=Math.random()*16;return e>0?(t=(e+t)%16|0,e=Math.floor(e/16)):(t=(r+t)%16|0,r=Math.floor(r/16)),(n==="x"?t:t&3|8).toString(16)})};function X(e){return{...e?.workbookData,id:e?.id||_(),name:e?.name||"未命名",appVersion:e?.appVersion||"1.0.0"}}const ee=Object.prototype.toString,K=(e,r)=>ee.call(e)===`[object ${r}]`,te=e=>typeof e<"u",re=e=>!te(e),ne=e=>e!==null&&K(e,"Object"),H=e=>e==null||typeof e>"u"?!0:A(e)||ae(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:ne(e)?Object.keys(e).length===0:!1,oe=e=>e===null,se=e=>re(e)||oe(e),ae=e=>K(e,"String"),A=e=>e&&Array.isArray(e);class ie{value;constructor(r){this.value=new z(r)}add(r){return this.value=this.value.add(r||0),this}subtract(r){return this.value=this.value.sub(r||0),this}multiply(r){return this.value=this.value.mul(r||0),this}divide(r){const n=new z(r);if(n.isZero())throw new Error("除数是0");return this.value=this.value.div(n),this}toFixed(r,n){return this.value=new z(this.value.toFixed(r,n)),this}valueOf(){return this.value}toString(){return this.value.toString()}toNumber(){return this.value.toNumber()}}function I(e=0){return new ie(e)}var L=(e=>(e.无="no",e.年="year",e.月="month",e.周="week",e.天="day",e.班组="shift",e.小时="hour",e.半小时="half_hour",e))(L||{}),Q=(e=>(e.view="view",e.edit="edit",e))(Q||{});async function ue(e,r){if(!r)return Promise.reject("日期不能为空");switch(e){case"year":if(A(r))return Promise.resolve(r);const n=c(r);if(!n.isValid())return Promise.reject("无效的日期格式");const t=n.year(),f=`${t}-01`,s=`${t}-12`;return Promise.resolve([f,s]);case"month":if(A(r))return Promise.resolve(r);const i=c(r);if(!i.isValid())return Promise.reject("无效的日期格式");const x=i.startOf("month").format("YYYY-MM-DD"),o=i.endOf("month").format("YYYY-MM-DD");return Promise.resolve([x,o]);case"day":if(A(r))return Promise.resolve(r);const p=c(r);if(!p.isValid())return Promise.reject("无效的日期格式");const d=p.startOf("day").format("YYYY-MM-DD HH:mm:ss"),V=p.endOf("day").format("YYYY-MM-DD HH:mm:ss");return Promise.resolve([d,V]);default:return Promise.reject("不支持的周期类型")}}function k(e,r,n){if(!n)return 0;const t={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[n];return["day","hour"].includes(n),c(r,t).diff(c(e,t),n)}function F(e,r,n){if(!n)throw new Error("日期类型不能为空");const t={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[n];return c(e).subtract(r,n).format(t)}function T(e,r,n,t){const f="YYYY-MM-DD HH:mm:ss",s=E(e,r,n,t),i=c(s);if(r==="month"){const o=i.month();return o===0?[i.startOf("month").format(f),i.date(25).endOf("day").format(f)]:o===11?[i.subtract(1,"month").date(26).startOf("day").format(f),i.endOf("month").format(f)]:[i.subtract(1,"month").date(26).startOf("day").format(f),i.date(25).endOf("day").format(f)]}const x={year:"year",day:"day",hour:"hour"};return[i.startOf(x[r]).format(f),i.endOf(x[r]).format(f)]}function E(e,r,n,t){const f={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"YYYY-MM-DD HH:mm:ss"}[r];return c(e,f).add(n*t,r).format(f)}function M(e,r,n){return e[r]||(e[r]={}),e[r][n]||(e[r][n]={}),e[r][n]}async function ce(e){if(!e)throw new Error("cellData is required");const r=Object.entries(e).reduce((n,t)=>{const[f,s]=t;for(const[i,x]of Object.entries(s)){const{custom:o,v:p,t:d,s:V}=x;if(!o)continue;const{cellType:m}=o,$=!o.hasOwnProperty("writeBack")||H(o?.writeBack)?!0:o.writeBack;if(m==="indicator"){const P=M(n,f,i);P.custom={...o,required:H(o?.required)?!1:o?.required,defaultShift:H(o?.defaultShift)?!1:o?.defaultShift,forwardPush:H(o?.forwardPush)?!1:o?.forwardPush,forwardPushTimes:H(o?.useDefaultEndDate)?0:o?.forwardPushTimes,useDefaultEndDate:H(o?.useDefaultEndDate)?!1:o?.useDefaultEndDate,copyType:H(o?.copyType)?"":o?.copyType,writeBack:$},P.s=V,P.t=d,P.v=p}}return n},{});return!r||H(r)?Promise.reject(new Error("No data found")):Promise.resolve(r)}function J(e,r){return e.replace(/\$\{([^}]+)\}/g,(n,t)=>{try{const f=Object.keys(r),s=Object.values(r);return new Function(...f,`return ${t};`)(...s)}catch(f){return console.error(`表达式执行失败: ${t}`,f),n}})}function fe({acc:e,params:r,initRowNum:n,initColNum:t,cellData:f}){const{rangeData:s,currentDay:i,extraArgs:x}=r;x?.teamData;const{cycleType:o,timeIncrement:p,forwardPush:d,forwardPushTimes:V,copyType:m,copyInterval:$,defaultShift:P,templateStr:C,useDefaultEndDate:q}=f.custom;let b=0;switch(o){case"day":{let a="";if(d&&(a=F(s[0],V,"day")),!m){let u="";d?u=a:u=s[0];const D=M(e,n,t);D.v=C?J(C,{businessDate:u,dayjs:c}):c(u).format("YYYY-MM-DD"),D.t=R.CellValueType.STRING;break}d?b=k(a,s[0],"day"):(b=k(s[0],s[1],"day"),console.log("copyNum",b));for(let u=0;u<=Math.abs(b===0?1:b);u++){const D=u*($+1);let O="";d?O=E(a,"day",u,p):O=E(s[0],"day",u,p);const v=m==="right"?n:n+D,w=m==="right"?t+D:t,y=M(e,v,w);y.v=C?J(C,{businessDate:O,dayjs:c}):c(O).format("YYYY-MM-DD"),y.t=R.CellValueType.STRING}break}case"month":{if(!m){const[a,u]=T(s[1],"month",0,1),D=M(e,n,t);D.v=c(u).format("YYYY-MM"),D.t=R.CellValueType.STRING;break}b=k(s[0],s[1],"month");for(let a=0;a<=Math.abs(b===0?1:b);a++){const u=a*($+1),D=m==="right"?n:n+u,O=m==="right"?t+u:t,v=M(e,D,O);v.v=E(s[0],"month",a,p),v.t=R.CellValueType.STRING}break}case"year":{let a="";if(d&&(a=F(s[0],V||0,"year")),!m){const u=d?a:s[0],[D,O]=T(u,"year",0,1),v=M(e,n,t),[,w]=T(s[1],"month",0,1);v.v=C?J(C,{startTime:D,endTime:O,rangeData:s,dayjs:c}):u,v.t=R.CellValueType.STRING;break}d?b=k(a,s[0],"year"):b=k(s[0],s[1],"year");for(let u=0;u<=Math.abs(b===0?1:b);u++){const D=u*($+1),O=m==="right"?n:n+D,v=m==="right"?t+D:t,[w,y]=T(s[0],"year",u,p),l=M(e,O,v),h=E(s[0],"year",u,p);l.v=C?J(C,{startTime:w,endTime:y,rangeData:s,dayjs:c}):h,l.t=R.CellValueType.STRING}break}case"hour":{if(!m){const a=M(e,n,t);if(a.t=R.CellValueType.STRING,P){a.v=c(s[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}a.v=c(i).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}b=k(s[0],s[1],"hour");for(let a=0;a<=Math.abs(b===0?1:b);a++){const u=a*($+1),D=m==="right"?n:n+u,O=m==="right"?t+u:t,v=M(e,D,O);if(v.t=R.CellValueType.STRING,P){const w=c(s[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");v.v=E(w,"hour",a,p);continue}v.v=E(c(i).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",a,p)}}}}async function le(e,r){if(!e)return Promise.reject("没有可用的单元格数据");const{extraArgs:n,rangeData:t}=r;if(!t.length)return Promise.reject("处理时间范围失败, rangeData不能为空");n?.teamData;const f=r?.currentDay||c().format("YYYY-MM-DD"),s=Object.entries(e).reduce((i,x)=>{const[o,p]=x;for(const[d,V]of Object.entries(p)){const{custom:m}=V;if(!m)continue;const{cellType:$,cycleType:P,timeIncrement:C,forwardPush:q,forwardPushTimes:b,copyType:a,copyInterval:u,defaultShift:D,useDefaultStartDate:O,useDefaultEndDate:v}=m;if($==="time"){fe({acc:i,params:r,initRowNum:Number(o),initColNum:Number(d),cellData:V});continue}const w={cycleType:P,indicatorName:m.indicatorName,indicatorCode:m.indicatorCode,indicatorId:m.indicatorId,indicatorDimensionName:m.indicatorDimensionName,indicatorDimensionConfig:m.indicatorDimensionConfig,required:se(m?.required)??!1,cellType:m.cellType,defaultShift:m?.defaultShift||!1,writeBack:H(m?.writeBack)?!0:m.writeBack};let y=0;switch(P){case"day":{let l="";if(q&&(l=F(t[0],b||0,"day")),!a){const h=q?l:t[0],[N,g]=T(h,"day",0,1),S=M(i,o,d);S.custom={...w,startTime:N,endTime:g};break}q?y=k(l,t[0],"day"):y=k(t[0],t[1],"day");for(let h=0;h<=Math.abs(y===0?1:y);h++){const N=h*(u+1),g=q?l:t[0],[S,B]=T(g,"day",h,C),U=a==="right"?o:I(o).add(N).toNumber(),G=a==="right"?I(d).add(N).toNumber():d,j=M(i,U,G);j.custom={...w,startTime:S,endTime:B}}break}case"month":{if(!a){const[l,h]=T(t[1],"month",0,1),N=M(i,o,d);N.custom={...w,startTime:l,endTime:h};break}y=k(t[0],t[1],"month");for(let l=0;l<=Math.abs(y===0?1:y);l++){const h=l*(u+1),N=a==="right"?o:I(o).add(h).toNumber(),g=a==="right"?I(d).add(h).toNumber():d,[S,B]=T(t[0],"month",l,C),U=M(i,N,g);U.custom={...w,startTime:S,endTime:B}}break}case"year":{let l="",h="",N="";if(q){l=F(t[0],b||0,"year");const g=c(t[1]).format("MM");h=c(`${l}-${g+1}`).format("YYYY-MM"),N=c(`${l}-${g+2}`).format("YYYY-MM")}if(!a){const g=q?l:t[0],[S,B]=T(g,"year",0,1),U=M(i,o,d),[,G]=T(h,"month",0,1),[j]=T(N,"month",0,1);U.custom={...w,startTime:O?j:S,endTime:v?G:B};break}q?y=k(l,t[0],"year"):y=k(t[0],t[1],"year");for(let g=0;g<=Math.abs(y===0?1:y);g++){const S=g*(u+1),B=a==="right"?o:I(o).add(S).toNumber(),U=a==="right"?I(d).add(S).toNumber():d,[G,j]=T(t[0],"year",g,C),Z=M(i,B,U);Z.custom={...w,startTime:G,endTime:j}}break}case"hour":{if(!a){const l=D?t[0]:t[0]??f,[h,N]=T(l,"hour",1,1),g=M(i,o,d);g.custom={...w,startTime:h,endTime:N};break}y=k(t[0],t[1],"hour");for(let l=0;l<=Math.abs(y===0?1:y);l++){const h=l*(u+1),N=a==="right"?o:I(o).add(h).toNumber(),g=a==="right"?I(d).add(h).toNumber():d,S=M(i,N,g);if(D){const j=c(t[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),[Z,Ye]=T(j,"hour",l,C);S.custom={...w,startTime:Z,endTime:Ye};continue}const B=c(f).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),[U,G]=T(B,"hour",l,C);S.custom={...w,startTime:U,endTime:G}}break}}}return i},{});return Promise.resolve(s)}function me(e){return Object.entries(e).reduce((n,[t,f])=>{const s=Math.max(...Object.keys(f).map(Number));return s>n?n=Number(s):n=Number(n)||0,n},0)}function de(e,r){const n=JSON.parse(JSON.stringify(e||{}));for(const[t,f]of Object.entries(r)){n[t]||(n[t]={});for(const[s,i]of Object.entries(f)){const x=i,o=n[t]?.[s];o?n[t][s]={...o,...x,custom:{...o.custom,...x.custom}}:n[t][s]=x}}return n}const he="./style.css";Y.CycleTypeEnum=L,Y.ModeEnum=Q,Y.decimal=I,Y.filterIndicatorsCell=ce,Y.generateIndicatorsCells=le,Y.generateUUID=_,Y.getNumColumns=me,Y.handleClearInput=W,Y.initDateRange=ue,Y.mergeCellData=de,Y.stylePath=he,Y.useData=X,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(M,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("dayjs"),require("@univerjs/presets"),require("decimal.js")):typeof define=="function"&&define.amd?define(["exports","dayjs","@univerjs/presets","decimal.js"],c):(M=typeof globalThis<"u"?globalThis:M||self,c(M.TorUniverSheet={},M.dayjs,M.presets,M.Decimal))})(this,(function(M,c,U,Z){"use strict";const X=(e,n)=>{for(const r of n)e[r]=null},K=()=>{if(typeof crypto=="object"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"&&typeof Uint8Array=="function"){const r=t=>{const f=Number(t);return(f^crypto.getRandomValues(new Uint8Array(1))[0]&15>>f/4).toString(16)};return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,r)}}let e=new Date().getTime(),n=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let t=Math.random()*16;return e>0?(t=(e+t)%16|0,e=Math.floor(e/16)):(t=(n+t)%16|0,n=Math.floor(n/16)),(r==="x"?t:t&3|8).toString(16)})};function ee(e){return{...e?.workbookData,id:e?.id||K(),name:e?.name||"未命名",appVersion:e?.appVersion||"1.0.0"}}const te=Object.prototype.toString,L=(e,n)=>te.call(e)===`[object ${n}]`,re=e=>typeof e<"u",ne=e=>!re(e),oe=e=>e!==null&&L(e,"Object"),E=e=>e==null||typeof e>"u"?!0:J(e)||ie(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:oe(e)?Object.keys(e).length===0:!1,se=e=>e===null,ae=e=>ne(e)||se(e),ie=e=>L(e,"String"),J=e=>e&&Array.isArray(e);class ue{value;constructor(n){this.value=new Z(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 r=new Z(n);if(r.isZero())throw new Error("除数是0");return this.value=this.value.div(r),this}toFixed(n,r){return this.value=new Z(this.value.toFixed(n,r)),this}valueOf(){return this.value}toString(){return this.value.toString()}toNumber(){return this.value.toNumber()}}function S(e=0){return new ue(e)}var Q=(e=>(e.无="no",e.年="year",e.月="month",e.周="week",e.天="day",e.班组="shift",e.小时="hour",e.半小时="half_hour",e))(Q||{}),W=(e=>(e.view="view",e.edit="edit",e))(W||{});async function ce(e,n){if(!n)return Promise.reject("日期不能为空");switch(e){case"year":if(J(n))return Promise.resolve(n);const r=c(n);if(!r.isValid())return Promise.reject("无效的日期格式");const t=r.year(),f=`${t}-01`,s=`${t}-12`;return Promise.resolve([f,s]);case"month":if(J(n))return Promise.resolve(n);const D=c(n);if(!D.isValid())return Promise.reject("无效的日期格式");const d=D.startOf("month").format("YYYY-MM-DD"),u=D.endOf("month").format("YYYY-MM-DD");return Promise.resolve([d,u]);case"day":if(J(n))return Promise.resolve(n);const Y=c(n);if(!Y.isValid())return Promise.reject("无效的日期格式");const P=Y.startOf("day").format("YYYY-MM-DD HH:mm:ss"),m=Y.endOf("day").format("YYYY-MM-DD HH:mm:ss");return Promise.resolve([P,m]);default:return Promise.reject("不支持的周期类型")}}function H(e,n,r){if(!r)return 0;const t={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[r];return["day","hour"].includes(r),c(n,t).diff(c(e,t),r)}function z(e,n,r){if(!r)throw new Error("日期类型不能为空");const t={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[r];return c(e).subtract(n,r).format(t)}function k(e,n,r,t){const f="YYYY-MM-DD HH:mm:ss",s=q(e,n,r,t),D=c(s);if(n==="month"){const u=D.month();return u===0?[D.startOf("month").format(f),D.date(25).endOf("day").format(f)]:u===11?[D.subtract(1,"month").date(26).startOf("day").format(f),D.endOf("month").format(f)]:[D.subtract(1,"month").date(26).startOf("day").format(f),D.date(25).endOf("day").format(f)]}const d={year:"year",day:"day",hour:"hour"};return[D.startOf(d[n]).format(f),D.endOf(d[n]).format(f)]}function q(e,n,r,t){const f={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"YYYY-MM-DD HH:mm:ss"}[n];return c(e,f).add(r*t,n).format(f)}function b(e,n,r){return e[n]||(e[n]={}),e[n][r]||(e[n][r]={}),e[n][r]}async function fe(e){if(!e)throw new Error("cellData is required");const n=Object.entries(e).reduce((r,t)=>{const[f,s]=t;for(const[D,d]of Object.entries(s)){const{custom:u,v:Y,t:P,s:m}=d;if(!u)continue;const{cellType:G}=u,l=!u.hasOwnProperty("writeBack")||E(u?.writeBack)?!0:u.writeBack;if(G==="indicator"){const I=b(r,f,D);I.custom={...u,required:E(u?.required)?!1:u?.required,defaultShift:E(u?.defaultShift)?!1:u?.defaultShift,forwardPush:E(u?.forwardPush)?!1:u?.forwardPush,forwardPushTimes:E(u?.useDefaultEndDate)?0:u?.forwardPushTimes,useDefaultEndDate:E(u?.useDefaultEndDate)?!1:u?.useDefaultEndDate,copyType:E(u?.copyType)?"":u?.copyType,writeBack:l},I.s=m,I.t=P,I.v=Y}}return r},{});return!n||E(n)?Promise.reject(new Error("No data found")):Promise.resolve(n)}function j(e,n){return e.replace(/\$\{([^}]+)\}/g,(r,t)=>{try{const f=Object.keys(n),s=Object.values(n);return new Function(...f,`return ${t};`)(...s)}catch(f){return console.error(`表达式执行失败: ${t}`,f),r}})}function le({acc:e,params:n,initRowNum:r,initColNum:t,cellData:f}){const{rangeData:s,currentDay:D,extraArgs:d}=n,u=d?.teamData||{},{cycleType:Y,timeIncrement:P,forwardPush:m,forwardPushTimes:G,copyType:l,copyInterval:I,defaultShift:F,templateStr:N,useDefaultEndDate:$}=f.custom;let v=0;switch(Y){case"day":{let o="";if(m&&(o=z(s[0],G,"day")),!l){let i="";m?i=o:i=s[0];const g=b(e,r,t);g.v=N?j(N,{businessDate:i,dayjs:c}):c(i).format("YYYY-MM-DD"),g.t=U.CellValueType.STRING;break}m?v=H(o,s[0],"day"):(v=H(s[0],s[1],"day"),console.log("copyNum",v));for(let i=0;i<=Math.abs(v===0?1:v);i++){const g=i*(I+1);let O="";m?O=q(o,"day",i,P):O=q(s[0],"day",i,P);const C=l==="right"?r:r+g,T=l==="right"?t+g:t,y=b(e,C,T);y.v=N?j(N,{businessDate:O,dayjs:c}):c(O).format("YYYY-MM-DD"),y.t=U.CellValueType.STRING}break}case"month":{if(!l){const[o,i]=k(s[1],"month",0,1),g=b(e,r,t);g.v=c(i).format("YYYY-MM"),g.t=U.CellValueType.STRING;break}v=H(s[0],s[1],"month");for(let o=0;o<=Math.abs(v===0?1:v);o++){const i=o*(I+1),g=l==="right"?r:r+i,O=l==="right"?t+i:t,C=b(e,g,O);C.v=q(s[0],"month",o,P),C.t=U.CellValueType.STRING}break}case"year":{let o="";if(m&&(o=z(s[0],G||0,"year")),!l){const i=m?o:s[0],[g,O]=k(i,"year",0,1),C=b(e,r,t),[,T]=k(s[1],"month",0,1);C.v=N?j(N,{startTime:g,endTime:O,rangeData:s,dayjs:c}):i,C.t=U.CellValueType.STRING;break}m?v=H(o,s[0],"year"):v=H(s[0],s[1],"year");for(let i=0;i<=Math.abs(v===0?1:v);i++){const g=i*(I+1),O=l==="right"?r:r+g,C=l==="right"?t+g:t,[T,y]=k(s[0],"year",i,P),a=b(e,O,C),h=q(s[0],"year",i,P);a.v=N?j(N,{startTime:T,endTime:y,rangeData:s,dayjs:c}):h,a.t=U.CellValueType.STRING}break}case"hour":{if(!l){const o=b(e,r,t);if(o.t=U.CellValueType.STRING,F){o.v=c(s[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}o.v=c(D).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}v=H(s[0],s[1],"hour");for(let o=0;o<=Math.abs(v===0?1:v);o++){const i=o*(I+1),g=l==="right"?r:r+i,O=l==="right"?t+i:t,C=b(e,g,O);if(C.t=U.CellValueType.STRING,F){const T=c(s[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");C.v=q(T,"hour",o,P);continue}C.v=q(c(D).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",o,P)}break}case"shift":{if(!l){const o=b(e,r,t);o.t=U.CellValueType.STRING,o.v=N?j(N,{rangeData:s,dayjs:c}):s[0];break}if(!u.length)throw new Error("没有获取到当班数据");for(let o=0;o<u.length;o++){const i=u[o],{startDatetime:g,endDatetime:O}=i,C=o*(I+1),T=l==="right"?r:S(r).add(C).toNumber(),y=l==="right"?S(t).add(C).toNumber():t,a=b(e,T,y);a.v=N?j(N,{team:i}):g}break}}}async function me(e,n){if(!e)return Promise.reject("没有可用的单元格数据");const{extraArgs:r,rangeData:t}=n;if(!t.length)return Promise.reject("处理时间范围失败, rangeData不能为空");const f=r?.teamData||[],s=n?.currentDay||c().format("YYYY-MM-DD"),D=Object.entries(e).reduce((d,u)=>{const[Y,P]=u;for(const[m,G]of Object.entries(P)){const{custom:l}=G;if(!l)continue;const{cellType:I,cycleType:F,timeIncrement:N,forwardPush:$,forwardPushTimes:v,copyType:o,copyInterval:i,defaultShift:g,useDefaultStartDate:O,useDefaultEndDate:C}=l;if(I==="time"){le({acc:d,params:n,initRowNum:Number(Y),initColNum:Number(m),cellData:G});continue}const T={cycleType:F,indicatorName:l.indicatorName,indicatorCode:l.indicatorCode,indicatorId:l.indicatorId,indicatorDimensionName:l.indicatorDimensionName,indicatorDimensionConfig:l.indicatorDimensionConfig,required:ae(l?.required)??!1,cellType:l.cellType,defaultShift:l?.defaultShift||!1,writeBack:E(l?.writeBack)?!0:l.writeBack};let y=0;switch(F){case"day":{let a="";if($&&(a=z(t[0],v||0,"day")),!o){const h=$?a:t[0],[p,w]=k(h,"day",0,1),x=b(d,Y,m);x.custom={...T,startTime:p,endTime:w};break}$?y=H(a,t[0],"day"):y=H(t[0],t[1],"day");for(let h=0;h<=Math.abs(y===0?1:y);h++){const p=h*(i+1),w=$?a:t[0],[x,V]=k(w,"day",h,N),B=o==="right"?Y:S(Y).add(p).toNumber(),R=o==="right"?S(m).add(p).toNumber():m,A=b(d,B,R);A.custom={...T,startTime:x,endTime:V}}break}case"month":{if(!o){const[a,h]=k(t[1],"month",0,1),p=b(d,Y,m);p.custom={...T,startTime:a,endTime:h};break}y=H(t[0],t[1],"month");for(let a=0;a<=Math.abs(y===0?1:y);a++){const h=a*(i+1),p=o==="right"?Y:S(Y).add(h).toNumber(),w=o==="right"?S(m).add(h).toNumber():m,[x,V]=k(t[0],"month",a,N),B=b(d,p,w);B.custom={...T,startTime:x,endTime:V}}break}case"year":{let a="",h="",p="";if($){a=z(t[0],v||0,"year");const w=c(t[1]).format("MM");h=c(`${a}-${w+1}`).format("YYYY-MM"),p=c(`${a}-${w+2}`).format("YYYY-MM")}if(!o){const w=$?a:t[0],[x,V]=k(w,"year",0,1),B=b(d,Y,m),[,R]=k(h,"month",0,1),[A]=k(p,"month",0,1);B.custom={...T,startTime:O?A:x,endTime:C?R:V};break}$?y=H(a,t[0],"year"):y=H(t[0],t[1],"year");for(let w=0;w<=Math.abs(y===0?1:y);w++){const x=w*(i+1),V=o==="right"?Y:S(Y).add(x).toNumber(),B=o==="right"?S(m).add(x).toNumber():m,[R,A]=k(t[0],"year",w,N),_=b(d,V,B);_.custom={...T,startTime:R,endTime:A}}break}case"hour":{if(!o){const a=g?t[0]:t[0]??s,[h,p]=k(a,"hour",1,1),w=b(d,Y,m);w.custom={...T,startTime:h,endTime:p};break}y=H(t[0],t[1],"hour");for(let a=0;a<=Math.abs(y===0?1:y);a++){const h=a*(i+1),p=o==="right"?Y:S(Y).add(h).toNumber(),w=o==="right"?S(m).add(h).toNumber():m,x=b(d,p,w);if(g){const A=c(t[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),[_,De]=k(A,"hour",a,N);x.custom={...T,startTime:_,endTime:De};continue}const V=c(s).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),[B,R]=k(V,"hour",a,N);x.custom={...T,startTime:B,endTime:R}}break}case"shift":{if(!o){const[a,h]=t,p=b(d,Y,m);p.custom={...T,startTime:a,endTime:h};break}if(!f.length)throw new Error("没有获取到当班数据");for(let a=0;a<f.length;a++){const h=f[a],{startDatetime:p,endDatetime:w}=h,x=a*(i+1),V=o==="right"?Y:S(Y).add(x).toNumber(),B=o==="right"?S(m).add(x).toNumber():m,R=b(d,V,B);R.custom={...T,startTime:p,endTime:w}}break}}}return d},{});return Promise.resolve(D)}function de(e){return Object.entries(e).reduce((r,[t,f])=>{const s=Math.max(...Object.keys(f).map(Number));return s>r?r=Number(s):r=Number(r)||0,r},0)}function he(e,n){const r=JSON.parse(JSON.stringify(e||{}));for(const[t,f]of Object.entries(n)){r[t]||(r[t]={});for(const[s,D]of Object.entries(f)){const d=D,u=r[t]?.[s];u?r[t][s]={...u,...d,custom:{...u.custom,...d.custom}}:r[t][s]=d}}return r}const Ye="./style.css";M.CycleTypeEnum=Q,M.ModeEnum=W,M.decimal=S,M.filterIndicatorsCell=fe,M.generateIndicatorsCells=me,M.generateUUID=K,M.getNumColumns=de,M.handleClearInput=X,M.initDateRange=ce,M.mergeCellData=he,M.stylePath=Ye,M.useData=ee,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tor-univer-sheet",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "style": "./dist/style.css",
5
5
  "description": "基于 Univer 的 Vue3 电子表格组件",
6
6
  "author": "tortormore",