tor-univer-sheet 1.1.18 → 1.1.19

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