tor-univer-sheet 1.1.19 → 1.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tor-univer-sheet.es.js +124 -119
- package/dist/tor-univer-sheet.umd.js +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import d from "dayjs";
|
|
2
2
|
import { CellValueType as E } from "@univerjs/presets";
|
|
3
|
-
import
|
|
3
|
+
import z from "decimal.js";
|
|
4
4
|
const dt = (t, r) => {
|
|
5
5
|
for (const o of r)
|
|
6
6
|
t[o] = null;
|
|
7
|
-
},
|
|
7
|
+
}, Q = () => {
|
|
8
8
|
if (typeof crypto == "object") {
|
|
9
9
|
if (typeof crypto.randomUUID == "function")
|
|
10
10
|
return crypto.randomUUID();
|
|
@@ -25,16 +25,16 @@ const dt = (t, r) => {
|
|
|
25
25
|
function ht(t) {
|
|
26
26
|
return {
|
|
27
27
|
...t?.workbookData,
|
|
28
|
-
id: t?.id ||
|
|
28
|
+
id: t?.id || Q(),
|
|
29
29
|
name: t?.name || "未命名",
|
|
30
30
|
appVersion: t?.appVersion || "1.0.0"
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
const X = Object.prototype.toString,
|
|
33
|
+
const X = Object.prototype.toString, Z = (t, r) => X.call(t) === `[object ${r}]`, tt = (t) => typeof t < "u", et = (t) => !tt(t), rt = (t) => t !== null && Z(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) => Z(t, "String"), K = (t) => t && Array.isArray(t);
|
|
34
34
|
class at {
|
|
35
35
|
value;
|
|
36
36
|
constructor(r) {
|
|
37
|
-
this.value = new
|
|
37
|
+
this.value = new z(r);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* 加法运算
|
|
@@ -67,7 +67,7 @@ class at {
|
|
|
67
67
|
* @throws 当除数为0时抛出错误
|
|
68
68
|
*/
|
|
69
69
|
divide(r) {
|
|
70
|
-
const o = new
|
|
70
|
+
const o = new z(r);
|
|
71
71
|
if (o.isZero())
|
|
72
72
|
throw new Error("除数是0");
|
|
73
73
|
return this.value = this.value.div(o), this;
|
|
@@ -79,7 +79,7 @@ class at {
|
|
|
79
79
|
* @returns DecimalChain 实例,支持链式调用
|
|
80
80
|
*/
|
|
81
81
|
toFixed(r, o) {
|
|
82
|
-
return this.value = new
|
|
82
|
+
return this.value = new z(this.value.toFixed(r, o)), this;
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* 返回当前值
|
|
@@ -103,7 +103,7 @@ class at {
|
|
|
103
103
|
return this.value.toNumber();
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
function
|
|
106
|
+
function I(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 || {});
|
|
@@ -124,8 +124,8 @@ async function yt(t, r) {
|
|
|
124
124
|
const h = d(r);
|
|
125
125
|
if (!h.isValid())
|
|
126
126
|
return Promise.reject("无效的日期格式");
|
|
127
|
-
const
|
|
128
|
-
return Promise.resolve([
|
|
127
|
+
const x = h.startOf("month").format("YYYY-MM-DD"), a = h.endOf("month").format("YYYY-MM-DD");
|
|
128
|
+
return Promise.resolve([x, a]);
|
|
129
129
|
case "day":
|
|
130
130
|
if (K(r))
|
|
131
131
|
return Promise.resolve(r);
|
|
@@ -138,7 +138,7 @@ async function yt(t, r) {
|
|
|
138
138
|
return Promise.reject("不支持的周期类型");
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function H(t, r, o) {
|
|
142
142
|
return o ? d(r).diff(d(t), o) : 0;
|
|
143
143
|
}
|
|
144
144
|
function L(t, r, o) {
|
|
@@ -152,14 +152,14 @@ function L(t, r, o) {
|
|
|
152
152
|
}[o];
|
|
153
153
|
return d(t).subtract(r, o).format(e);
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function O(t, r, o, e) {
|
|
156
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
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
|
|
162
|
-
return [h.startOf(
|
|
161
|
+
const x = { year: "year", day: "day", hour: "hour" };
|
|
162
|
+
return [h.startOf(x[r]).format(c), h.endOf(x[r]).format(c)];
|
|
163
163
|
}
|
|
164
164
|
function A(t, r, o, e) {
|
|
165
165
|
const c = {
|
|
@@ -178,10 +178,10 @@ async function Yt(t) {
|
|
|
178
178
|
throw new Error("cellData is required");
|
|
179
179
|
const r = Object.entries(t).reduce((o, e) => {
|
|
180
180
|
const [c, n] = e;
|
|
181
|
-
for (const [h,
|
|
182
|
-
const { custom: a, v: y, t: Y, s: f } =
|
|
181
|
+
for (const [h, x] of Object.entries(n)) {
|
|
182
|
+
const { custom: a, v: y, t: Y, s: f } = x;
|
|
183
183
|
if (!a) continue;
|
|
184
|
-
const { cellType: q } = a,
|
|
184
|
+
const { cellType: q } = a, u = !a.hasOwnProperty("writeBack") || G(a?.writeBack) ? !0 : a.writeBack;
|
|
185
185
|
if (q === "indicator") {
|
|
186
186
|
const P = T(o, c, h);
|
|
187
187
|
P.custom = {
|
|
@@ -192,7 +192,7 @@ async function Yt(t) {
|
|
|
192
192
|
forwardPushTimes: G(a?.useDefaultEndDate) ? 0 : a?.forwardPushTimes,
|
|
193
193
|
useDefaultEndDate: G(a?.useDefaultEndDate) ? !1 : a?.useDefaultEndDate,
|
|
194
194
|
copyType: G(a?.copyType) ? "" : a?.copyType,
|
|
195
|
-
writeBack:
|
|
195
|
+
writeBack: u
|
|
196
196
|
}, P.s = f, P.t = Y, P.v = y || "";
|
|
197
197
|
}
|
|
198
198
|
}
|
|
@@ -210,14 +210,14 @@ function F(t, r) {
|
|
|
210
210
|
}
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function ut({
|
|
214
214
|
acc: t,
|
|
215
215
|
params: r,
|
|
216
216
|
initRowNum: o,
|
|
217
217
|
initColNum: e,
|
|
218
218
|
cellData: c
|
|
219
219
|
}) {
|
|
220
|
-
const { rangeData: n, currentDay: h, extraArgs:
|
|
220
|
+
const { rangeData: n, currentDay: h, extraArgs: x } = r, a = x?.teamData || {}, { cycleType: y, timeIncrement: Y, forwardPush: f, forwardPushTimes: q, copyType: u, copyInterval: P, defaultShift: p, templateStr: C, useDefaultEndDate: W } = c.custom;
|
|
221
221
|
let w = 0;
|
|
222
222
|
switch (y) {
|
|
223
223
|
case "day": {
|
|
@@ -227,47 +227,47 @@ function lt({
|
|
|
227
227
|
q,
|
|
228
228
|
"day"
|
|
229
229
|
/* day */
|
|
230
|
-
)), !
|
|
231
|
-
let
|
|
232
|
-
f ?
|
|
230
|
+
)), !u) {
|
|
231
|
+
let l = "";
|
|
232
|
+
f ? l = s : l = n[0];
|
|
233
233
|
const i = T(t, o, e);
|
|
234
|
-
i.v = C ? F(C, { businessDate:
|
|
234
|
+
i.v = C ? F(C, { businessDate: l, dayjs: d }) : d(l).format("YYYY-MM-DD"), i.t = E.STRING, i.s = "tor-time-cell-style";
|
|
235
235
|
break;
|
|
236
236
|
}
|
|
237
|
-
f ? w =
|
|
237
|
+
f ? w = H(
|
|
238
238
|
s,
|
|
239
239
|
n[0],
|
|
240
240
|
"day"
|
|
241
241
|
/* day */
|
|
242
|
-
) : (w =
|
|
242
|
+
) : (w = H(
|
|
243
243
|
n[0],
|
|
244
244
|
n[1],
|
|
245
245
|
"day"
|
|
246
246
|
/* day */
|
|
247
247
|
), console.log("copyNum", w));
|
|
248
|
-
for (let
|
|
249
|
-
const i =
|
|
250
|
-
let
|
|
251
|
-
f ?
|
|
252
|
-
const g =
|
|
253
|
-
$.v = C ? F(C, { businessDate:
|
|
248
|
+
for (let l = 0; l <= Math.abs(w === 0 ? 1 : w); l++) {
|
|
249
|
+
const i = l * (P + 1);
|
|
250
|
+
let N = "";
|
|
251
|
+
f ? N = A(s, "day", l, Y) : N = A(n[0], "day", l, Y);
|
|
252
|
+
const g = u === "right" ? o : o + i, B = u === "right" ? e + i : e, $ = T(t, g, B);
|
|
253
|
+
$.v = C ? F(C, { businessDate: N, dayjs: d }) : d(N).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 (!
|
|
259
|
-
const [s,
|
|
260
|
-
i.v = d(
|
|
258
|
+
if (!u) {
|
|
259
|
+
const [s, l] = O(n[1], "month", 0, 1), i = T(t, o, e);
|
|
260
|
+
i.v = d(l).format("YYYY-MM"), i.t = E.STRING, i.s = "tor-time-cell-style";
|
|
261
261
|
break;
|
|
262
262
|
}
|
|
263
|
-
w =
|
|
263
|
+
w = H(
|
|
264
264
|
n[0],
|
|
265
265
|
n[1],
|
|
266
266
|
"month"
|
|
267
267
|
/* month */
|
|
268
268
|
);
|
|
269
269
|
for (let s = 0; s <= Math.abs(w === 0 ? 1 : w); s++) {
|
|
270
|
-
const
|
|
270
|
+
const l = s * (P + 1), i = u === "right" ? o : o + l, N = u === "right" ? e + l : e, g = T(t, i, N);
|
|
271
271
|
g.v = A(n[0], "month", s, Y), g.t = E.STRING, g.s = "tor-time-cell-style";
|
|
272
272
|
}
|
|
273
273
|
break;
|
|
@@ -279,57 +279,57 @@ function lt({
|
|
|
279
279
|
q || 0,
|
|
280
280
|
"year"
|
|
281
281
|
/* year */
|
|
282
|
-
)), !
|
|
283
|
-
const
|
|
282
|
+
)), !u) {
|
|
283
|
+
const l = f ? s : n[0], [i, N] = O(l, "year", 0, 1), g = T(t, o, e), [, B] = O(n[1], "month", 0, 1);
|
|
284
284
|
g.v = C ? F(C, {
|
|
285
285
|
startTime: i,
|
|
286
|
-
endTime:
|
|
286
|
+
endTime: N,
|
|
287
287
|
rangeData: n,
|
|
288
288
|
dayjs: d
|
|
289
|
-
}) :
|
|
289
|
+
}) : l, g.t = E.STRING, g.s = "tor-time-cell-style";
|
|
290
290
|
break;
|
|
291
291
|
}
|
|
292
|
-
f ? w =
|
|
292
|
+
f ? w = H(
|
|
293
293
|
s,
|
|
294
294
|
n[0],
|
|
295
295
|
"year"
|
|
296
296
|
/* year */
|
|
297
|
-
) : w =
|
|
297
|
+
) : w = H(
|
|
298
298
|
n[0],
|
|
299
299
|
n[1],
|
|
300
300
|
"year"
|
|
301
301
|
/* year */
|
|
302
302
|
);
|
|
303
|
-
for (let
|
|
304
|
-
const i =
|
|
305
|
-
|
|
303
|
+
for (let l = 0; l <= Math.abs(w === 0 ? 1 : w); l++) {
|
|
304
|
+
const i = l * (P + 1), N = u === "right" ? o : o + i, g = u === "right" ? e + i : e, [B, $] = O(n[0], "year", l, Y), S = T(t, N, g), k = A(n[0], "year", l, Y);
|
|
305
|
+
S.v = C ? F(C, {
|
|
306
306
|
startTime: B,
|
|
307
307
|
endTime: $,
|
|
308
308
|
rangeData: n,
|
|
309
309
|
dayjs: d
|
|
310
|
-
}) : k,
|
|
310
|
+
}) : k, S.t = E.STRING, S.s = "tor-time-cell-style";
|
|
311
311
|
}
|
|
312
312
|
break;
|
|
313
313
|
}
|
|
314
314
|
case "hour": {
|
|
315
|
-
if (!
|
|
315
|
+
if (!u) {
|
|
316
316
|
const s = T(t, o, e);
|
|
317
|
-
if (s.t = E.STRING, s.s = "tor-time-cell-style",
|
|
317
|
+
if (s.t = E.STRING, s.s = "tor-time-cell-style", p) {
|
|
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
|
-
w =
|
|
324
|
+
w = H(
|
|
325
325
|
n[0],
|
|
326
326
|
n[1],
|
|
327
327
|
"hour"
|
|
328
328
|
/* hour */
|
|
329
329
|
);
|
|
330
330
|
for (let s = 0; s <= Math.abs(w === 0 ? 1 : w); s++) {
|
|
331
|
-
const
|
|
332
|
-
if (g.t = E.STRING, g.s = "tor-time-cell-style",
|
|
331
|
+
const l = s * (P + 1), i = u === "right" ? o : o + l, N = u === "right" ? e + l : e, g = T(t, i, N);
|
|
332
|
+
if (g.t = E.STRING, g.s = "tor-time-cell-style", p) {
|
|
333
333
|
const B = d(n[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
|
|
334
334
|
g.v = A(B, "hour", s, Y);
|
|
335
335
|
continue;
|
|
@@ -339,7 +339,7 @@ function lt({
|
|
|
339
339
|
break;
|
|
340
340
|
}
|
|
341
341
|
case "shift": {
|
|
342
|
-
if (!
|
|
342
|
+
if (!u) {
|
|
343
343
|
const s = T(t, o, e);
|
|
344
344
|
s.t = E.STRING, s.s = "tor-time-cell-style", s.v = C ? F(C, {
|
|
345
345
|
rangeData: n,
|
|
@@ -350,9 +350,9 @@ function lt({
|
|
|
350
350
|
if (!a.length)
|
|
351
351
|
throw new Error("没有获取到当班数据");
|
|
352
352
|
for (let s = 0; s < a.length; s++) {
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
team:
|
|
353
|
+
const l = a[s], { startDatetime: i, endDatetime: N } = l, g = s * (P + 1), B = u === "right" ? o : I(o).add(g).toNumber(), $ = u === "right" ? I(e).add(g).toNumber() : e, S = T(t, B, $);
|
|
354
|
+
S.s = "tor-time-cell-style", S.v = C ? F(C, {
|
|
355
|
+
team: l
|
|
356
356
|
}) : i;
|
|
357
357
|
}
|
|
358
358
|
break;
|
|
@@ -365,72 +365,77 @@ async function Dt(t, r) {
|
|
|
365
365
|
const { extraArgs: o, rangeData: e } = r;
|
|
366
366
|
if (!e.length)
|
|
367
367
|
return Promise.reject("处理时间范围失败, rangeData不能为空");
|
|
368
|
-
const c = o?.teamData || [], { periodicityTime: n } = r, h = r?.currentDay || d().format("YYYY-MM-DD"),
|
|
368
|
+
const c = o?.teamData || [], { periodicityTime: n } = r, h = r?.currentDay || d().format("YYYY-MM-DD"), x = (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
369
|
const [f, q] = Y;
|
|
370
|
-
for (const [
|
|
371
|
-
const { custom:
|
|
372
|
-
if (!
|
|
370
|
+
for (const [u, P] of Object.entries(q)) {
|
|
371
|
+
const { custom: p } = P;
|
|
372
|
+
if (!p) continue;
|
|
373
373
|
const {
|
|
374
374
|
cellType: C,
|
|
375
|
-
cycleType:
|
|
375
|
+
cycleType: W,
|
|
376
376
|
timeIncrement: w,
|
|
377
377
|
forwardPush: s,
|
|
378
|
-
forwardPushTimes:
|
|
378
|
+
forwardPushTimes: l,
|
|
379
379
|
copyType: i,
|
|
380
|
-
copyInterval:
|
|
380
|
+
copyInterval: N,
|
|
381
381
|
defaultShift: g,
|
|
382
382
|
useDefaultStartDate: B,
|
|
383
383
|
useDefaultEndDate: $
|
|
384
|
-
} =
|
|
384
|
+
} = p;
|
|
385
385
|
if (C === "time") {
|
|
386
|
-
|
|
386
|
+
ut({ acc: y, params: r, initRowNum: Number(f), initColNum: Number(u), cellData: P });
|
|
387
387
|
continue;
|
|
388
388
|
}
|
|
389
|
-
const
|
|
390
|
-
cycleType:
|
|
391
|
-
indicatorName:
|
|
392
|
-
indicatorCode:
|
|
393
|
-
indicatorId:
|
|
394
|
-
indicatorDimensionName:
|
|
395
|
-
indicatorDimensionConfig:
|
|
396
|
-
required: nt(
|
|
397
|
-
cellType:
|
|
398
|
-
defaultShift:
|
|
399
|
-
writeBack: G(
|
|
389
|
+
const S = {
|
|
390
|
+
cycleType: W,
|
|
391
|
+
indicatorName: p.indicatorName,
|
|
392
|
+
indicatorCode: p.indicatorCode,
|
|
393
|
+
indicatorId: p.indicatorId,
|
|
394
|
+
indicatorDimensionName: p.indicatorDimensionName,
|
|
395
|
+
indicatorDimensionConfig: p.indicatorDimensionConfig,
|
|
396
|
+
required: nt(p?.required) ?? !1,
|
|
397
|
+
cellType: p.cellType,
|
|
398
|
+
defaultShift: p?.defaultShift || !1,
|
|
399
|
+
writeBack: G(p?.writeBack) ? !0 : p.writeBack,
|
|
400
|
+
dimensionJson: p?.dimensionJson || "",
|
|
401
|
+
unit: p?.unit || "",
|
|
402
|
+
innerSyncWay: p?.innerSyncWay || "",
|
|
403
|
+
outSyncConfigId: p?.outSyncConfigId || "",
|
|
404
|
+
innerSyncStatus: p?.innerSyncStatus || ""
|
|
400
405
|
};
|
|
401
406
|
let k = 0;
|
|
402
|
-
switch (
|
|
407
|
+
switch (W) {
|
|
403
408
|
case "day": {
|
|
404
409
|
let m = "";
|
|
405
410
|
if (s && (m = L(
|
|
406
411
|
e[0],
|
|
407
|
-
|
|
412
|
+
l || 0,
|
|
408
413
|
"day"
|
|
409
414
|
/* day */
|
|
410
415
|
)), !i) {
|
|
411
|
-
const D = s ? m : e[0], [M, b] =
|
|
416
|
+
const D = s ? m : e[0], [M, b] = x(...O(D, "day", 0, 1)), v = T(y, f, u);
|
|
412
417
|
v.s = "tor-indicator-cell-style", v.custom = {
|
|
413
|
-
...
|
|
418
|
+
...S,
|
|
414
419
|
startTime: M,
|
|
415
420
|
endTime: b
|
|
416
421
|
};
|
|
417
422
|
break;
|
|
418
423
|
}
|
|
419
|
-
s ? k =
|
|
424
|
+
s ? k = H(
|
|
420
425
|
m,
|
|
421
426
|
e[0],
|
|
422
427
|
"day"
|
|
423
428
|
/* day */
|
|
424
|
-
) : k =
|
|
429
|
+
) : k = H(
|
|
425
430
|
e[0],
|
|
426
431
|
e[1],
|
|
427
432
|
"day"
|
|
428
433
|
/* day */
|
|
429
434
|
);
|
|
430
435
|
for (let D = 0; D <= Math.abs(k === 0 ? 1 : k); D++) {
|
|
431
|
-
const M = D * (
|
|
436
|
+
const M = D * (N + 1), b = s ? m : e[0], [v, R] = x(...O(b, "day", D, w)), j = i === "right" ? f : I(f).add(M).toNumber(), U = i === "right" ? I(u).add(M).toNumber() : u, V = T(y, j, U);
|
|
432
437
|
V.s = "tor-indicator-cell-style", V.custom = {
|
|
433
|
-
...
|
|
438
|
+
...S,
|
|
434
439
|
startTime: v,
|
|
435
440
|
endTime: R
|
|
436
441
|
};
|
|
@@ -439,24 +444,24 @@ async function Dt(t, r) {
|
|
|
439
444
|
}
|
|
440
445
|
case "month": {
|
|
441
446
|
if (!i) {
|
|
442
|
-
const [m, D] =
|
|
447
|
+
const [m, D] = O(e[1], "month", 0, 1), M = T(y, f, u);
|
|
443
448
|
M.s = "tor-indicator-cell-style", M.custom = {
|
|
444
|
-
...
|
|
449
|
+
...S,
|
|
445
450
|
startTime: m,
|
|
446
451
|
endTime: D
|
|
447
452
|
};
|
|
448
453
|
break;
|
|
449
454
|
}
|
|
450
|
-
k =
|
|
455
|
+
k = H(
|
|
451
456
|
e[0],
|
|
452
457
|
e[1],
|
|
453
458
|
"month"
|
|
454
459
|
/* month */
|
|
455
460
|
);
|
|
456
461
|
for (let m = 0; m <= Math.abs(k === 0 ? 1 : k); m++) {
|
|
457
|
-
const D = m * (
|
|
462
|
+
const D = m * (N + 1), M = i === "right" ? f : I(f).add(D).toNumber(), b = i === "right" ? I(u).add(D).toNumber() : u, [v, R] = O(e[0], "month", m, w), j = T(y, M, b);
|
|
458
463
|
j.s = "tor-indicator-cell-style", j.custom = {
|
|
459
|
-
...
|
|
464
|
+
...S,
|
|
460
465
|
startTime: v,
|
|
461
466
|
endTime: R
|
|
462
467
|
};
|
|
@@ -468,7 +473,7 @@ async function Dt(t, r) {
|
|
|
468
473
|
if (s) {
|
|
469
474
|
m = L(
|
|
470
475
|
e[0],
|
|
471
|
-
|
|
476
|
+
l || 0,
|
|
472
477
|
"year"
|
|
473
478
|
/* year */
|
|
474
479
|
);
|
|
@@ -476,31 +481,31 @@ async function Dt(t, r) {
|
|
|
476
481
|
D = d(`${m}-${b + 1}`).format("YYYY-MM"), M = d(`${m}-${b + 2}`).format("YYYY-MM");
|
|
477
482
|
}
|
|
478
483
|
if (!i) {
|
|
479
|
-
const b = s ? m : e[0], [v, R] =
|
|
484
|
+
const b = s ? m : e[0], [v, R] = O(b, "year", 0, 1), j = T(y, f, u);
|
|
480
485
|
j.s = "tor-indicator-cell-style";
|
|
481
|
-
const [, U] =
|
|
486
|
+
const [, U] = O(D, "month", 0, 1), [V] = O(M, "month", 0, 1);
|
|
482
487
|
j.custom = {
|
|
483
|
-
...
|
|
488
|
+
...S,
|
|
484
489
|
startTime: B ? V : v,
|
|
485
490
|
endTime: $ ? U : R
|
|
486
491
|
};
|
|
487
492
|
break;
|
|
488
493
|
}
|
|
489
|
-
s ? k =
|
|
494
|
+
s ? k = H(
|
|
490
495
|
m,
|
|
491
496
|
e[0],
|
|
492
497
|
"year"
|
|
493
498
|
/* year */
|
|
494
|
-
) : k =
|
|
499
|
+
) : k = H(
|
|
495
500
|
e[0],
|
|
496
501
|
e[1],
|
|
497
502
|
"year"
|
|
498
503
|
/* year */
|
|
499
504
|
);
|
|
500
505
|
for (let b = 0; b <= Math.abs(k === 0 ? 1 : k); b++) {
|
|
501
|
-
const v = b * (
|
|
506
|
+
const v = b * (N + 1), R = i === "right" ? f : I(f).add(v).toNumber(), j = i === "right" ? I(u).add(v).toNumber() : u, [U, V] = O(e[0], "year", b, w), J = T(y, R, j);
|
|
502
507
|
J.s = "tor-indicator-cell-style", J.custom = {
|
|
503
|
-
...
|
|
508
|
+
...S,
|
|
504
509
|
startTime: U,
|
|
505
510
|
endTime: V
|
|
506
511
|
};
|
|
@@ -509,34 +514,34 @@ async function Dt(t, r) {
|
|
|
509
514
|
}
|
|
510
515
|
case "hour": {
|
|
511
516
|
if (!i) {
|
|
512
|
-
const m = g ? e[0] : e[0] ?? h, [D, M] =
|
|
517
|
+
const m = g ? e[0] : e[0] ?? h, [D, M] = O(m, "hour", 1, 1), b = T(y, f, u);
|
|
513
518
|
b.s = "tor-indicator-cell-style", b.custom = {
|
|
514
|
-
...
|
|
519
|
+
...S,
|
|
515
520
|
startTime: D,
|
|
516
521
|
endTime: M
|
|
517
522
|
};
|
|
518
523
|
break;
|
|
519
524
|
}
|
|
520
|
-
k =
|
|
525
|
+
k = H(
|
|
521
526
|
e[0],
|
|
522
527
|
e[1],
|
|
523
528
|
"hour"
|
|
524
529
|
/* hour */
|
|
525
530
|
);
|
|
526
531
|
for (let m = 0; m <= Math.abs(k === 0 ? 1 : k); m++) {
|
|
527
|
-
const D = m * (
|
|
532
|
+
const D = m * (N + 1), M = i === "right" ? f : I(f).add(D).toNumber(), b = i === "right" ? I(u).add(D).toNumber() : u, v = T(y, M, b);
|
|
528
533
|
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,
|
|
534
|
+
const V = d(e[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [J, _] = O(V, "hour", m, w);
|
|
530
535
|
v.custom = {
|
|
531
|
-
...
|
|
536
|
+
...S,
|
|
532
537
|
startTime: J,
|
|
533
|
-
endTime:
|
|
538
|
+
endTime: _
|
|
534
539
|
};
|
|
535
540
|
continue;
|
|
536
541
|
}
|
|
537
|
-
const R = d(h).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [j, U] =
|
|
542
|
+
const R = d(h).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [j, U] = O(R, "hour", m, w);
|
|
538
543
|
v.custom = {
|
|
539
|
-
...
|
|
544
|
+
...S,
|
|
540
545
|
startTime: j,
|
|
541
546
|
endTime: U
|
|
542
547
|
};
|
|
@@ -545,9 +550,9 @@ async function Dt(t, r) {
|
|
|
545
550
|
}
|
|
546
551
|
case "shift": {
|
|
547
552
|
if (!i) {
|
|
548
|
-
const [m, D] = e, M = T(y, f,
|
|
553
|
+
const [m, D] = e, M = T(y, f, u);
|
|
549
554
|
M.s = "tor-indicator-cell-style", M.custom = {
|
|
550
|
-
...
|
|
555
|
+
...S,
|
|
551
556
|
startTime: m,
|
|
552
557
|
endTime: D
|
|
553
558
|
};
|
|
@@ -556,9 +561,9 @@ async function Dt(t, r) {
|
|
|
556
561
|
if (!c.length)
|
|
557
562
|
throw new Error("没有获取到当班数据");
|
|
558
563
|
for (let m = 0; m < c.length; m++) {
|
|
559
|
-
const D = c[m], { startDatetime: M, endDatetime: b } = D, v = m * (
|
|
564
|
+
const D = c[m], { startDatetime: M, endDatetime: b } = D, v = m * (N + 1), R = i === "right" ? f : I(f).add(v).toNumber(), j = i === "right" ? I(u).add(v).toNumber() : u, U = T(y, R, j);
|
|
560
565
|
U.s = "tor-indicator-cell-style", U.custom = {
|
|
561
|
-
...
|
|
566
|
+
...S,
|
|
562
567
|
startTime: M,
|
|
563
568
|
endTime: b
|
|
564
569
|
};
|
|
@@ -582,15 +587,15 @@ function bt(t, r) {
|
|
|
582
587
|
for (const [e, c] of Object.entries(r)) {
|
|
583
588
|
o[e] || (o[e] = {});
|
|
584
589
|
for (const [n, h] of Object.entries(c)) {
|
|
585
|
-
const
|
|
590
|
+
const x = h, a = o[e]?.[n];
|
|
586
591
|
a ? o[e][n] = {
|
|
587
592
|
...a,
|
|
588
|
-
...
|
|
593
|
+
...x,
|
|
589
594
|
custom: {
|
|
590
595
|
...a.custom,
|
|
591
|
-
...
|
|
596
|
+
...x.custom
|
|
592
597
|
}
|
|
593
|
-
} : o[e][n] =
|
|
598
|
+
} : o[e][n] = x;
|
|
594
599
|
}
|
|
595
600
|
}
|
|
596
601
|
return o;
|
|
@@ -603,11 +608,11 @@ function wt(t, r) {
|
|
|
603
608
|
for (const n in c) {
|
|
604
609
|
const h = c[n];
|
|
605
610
|
if (h?.custom?.cellType === "indicator") {
|
|
606
|
-
const
|
|
611
|
+
const x = Number(e), a = Number(n);
|
|
607
612
|
if (r.some(
|
|
608
|
-
(Y) =>
|
|
613
|
+
(Y) => x >= Y.startRow && x <= Y.endRow && a >= Y.startColumn && a <= Y.endColumn
|
|
609
614
|
) && !r.some(
|
|
610
|
-
(f) =>
|
|
615
|
+
(f) => x === f.startRow && a === f.startColumn
|
|
611
616
|
))
|
|
612
617
|
continue;
|
|
613
618
|
}
|
|
@@ -620,11 +625,11 @@ const Mt = "./style.css";
|
|
|
620
625
|
export {
|
|
621
626
|
it as CycleTypeEnum,
|
|
622
627
|
ct as ModeEnum,
|
|
623
|
-
|
|
628
|
+
I as decimal,
|
|
624
629
|
Yt as filterIndicatorsCell,
|
|
625
630
|
wt as filterMergedIndicatorCells,
|
|
626
631
|
Dt as generateIndicatorsCells,
|
|
627
|
-
|
|
632
|
+
Q as generateUUID,
|
|
628
633
|
gt as getNumColumns,
|
|
629
634
|
dt as handleClearInput,
|
|
630
635
|
yt as initDateRange,
|
|
@@ -1 +1 @@
|
|
|
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"})}));
|
|
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 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 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,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||_(),name:e?.name||"未命名",appVersion:e?.appVersion||"1.0.0"}}const ne=Object.prototype.toString,Q=(e,r)=>ne.call(e)===`[object ${r}]`,oe=e=>typeof e<"u",se=e=>!oe(e),ae=e=>e!==null&&Q(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=>Q(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 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 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 n=l(r);if(!n.isValid())return Promise.reject("无效的日期格式");const t=n.year(),c=`${t}-01`,o=`${t}-12`;return Promise.resolve([c,o]);case"month":if(K(r))return Promise.resolve(r);const h=l(r);if(!h.isValid())return Promise.reject("无效的日期格式");const N=h.startOf("month").format("YYYY-MM-DD"),a=h.endOf("month").format("YYYY-MM-DD");return Promise.resolve([N,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,n){return n?l(r).diff(l(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 l(e).subtract(r,n).format(t)}function O(e,r,n,t){const c="YYYY-MM-DD HH:mm:ss",o=j(e,r,n,t),h=l(o);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 N={year:"year",day:"day",hour:"hour"};return[h.startOf(N[r]).format(c),h.endOf(N[r]).format(c)]}function j(e,r,n,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(n*t,r).format(c)}function w(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[c,o]=t;for(const[h,N]of Object.entries(o)){const{custom:a,v:y,t:Y,s:m}=N;if(!a)continue;const{cellType:J}=a,u=!a.hasOwnProperty("writeBack")||q(a?.writeBack)?!0:a.writeBack;if(J==="indicator"){const H=w(n,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 n},{});return!r||q(r)?Promise.reject(new Error("No data found")):Promise.resolve(r)}function F(e,r){return e.replace(/\$\{([^}]+)\}/g,(n,t)=>{try{const c=Object.keys(r),o=Object.values(r);return new Function(...c,`return ${t};`)(...o)}catch(c){return console.error(`表达式执行失败: ${t}`,c),n}})}function de({acc:e,params:r,initRowNum:n,initColNum:t,cellData:c}){const{rangeData:o,currentDay:h,extraArgs:N}=r,a=N?.teamData||{},{cycleType:y,timeIncrement:Y,forwardPush:m,forwardPushTimes:J,copyType:u,copyInterval:H,defaultShift:C,templateStr:P,useDefaultEndDate:Z}=c.custom;let T=0;switch(y){case"day":{let s="";if(m&&(s=L(o[0],J,"day")),!u){let f="";m?f=s:f=o[0];const i=w(e,n,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,o[0],"day"):(T=V(o[0],o[1],"day"),console.log("copyNum",T));for(let f=0;f<=Math.abs(T===0?1:T);f++){const i=f*(H+1);let S="";m?S=j(s,"day",f,Y):S=j(o[0],"day",f,Y);const g=u==="right"?n:n+i,U=u==="right"?t+i:t,G=w(e,g,U);G.v=P?F(P,{businessDate:S,dayjs:l}):l(S).format("YYYY-MM-DD"),G.t=$.CellValueType.STRING,G.s="tor-time-cell-style"}break}case"month":{if(!u){const[s,f]=O(o[1],"month",0,1),i=w(e,n,t);i.v=l(f).format("YYYY-MM"),i.t=$.CellValueType.STRING,i.s="tor-time-cell-style";break}T=V(o[0],o[1],"month");for(let s=0;s<=Math.abs(T===0?1:T);s++){const f=s*(H+1),i=u==="right"?n:n+f,S=u==="right"?t+f:t,g=w(e,i,S);g.v=j(o[0],"month",s,Y),g.t=$.CellValueType.STRING,g.s="tor-time-cell-style"}break}case"year":{let s="";if(m&&(s=L(o[0],J||0,"year")),!u){const f=m?s:o[0],[i,S]=O(f,"year",0,1),g=w(e,n,t),[,U]=O(o[1],"month",0,1);g.v=P?F(P,{startTime:i,endTime:S,rangeData:o,dayjs:l}):f,g.t=$.CellValueType.STRING,g.s="tor-time-cell-style";break}m?T=V(s,o[0],"year"):T=V(o[0],o[1],"year");for(let f=0;f<=Math.abs(T===0?1:T);f++){const i=f*(H+1),S=u==="right"?n:n+i,g=u==="right"?t+i:t,[U,G]=O(o[0],"year",f,Y),v=w(e,S,g),k=j(o[0],"year",f,Y);v.v=P?F(P,{startTime:U,endTime:G,rangeData:o,dayjs:l}):k,v.t=$.CellValueType.STRING,v.s="tor-time-cell-style"}break}case"hour":{if(!u){const s=w(e,n,t);if(s.t=$.CellValueType.STRING,s.s="tor-time-cell-style",C){s.v=l(o[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(o[0],o[1],"hour");for(let s=0;s<=Math.abs(T===0?1:T);s++){const f=s*(H+1),i=u==="right"?n:n+f,S=u==="right"?t+f:t,g=w(e,i,S);if(g.t=$.CellValueType.STRING,g.s="tor-time-cell-style",C){const U=l(o[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,n,t);s.t=$.CellValueType.STRING,s.s="tor-time-cell-style",s.v=P?F(P,{rangeData:o,dayjs:l}):o[0];break}if(!a.length)throw new Error("没有获取到当班数据");for(let s=0;s<a.length;s++){const f=a[s],{startDatetime:i,endDatetime:S}=f,g=s*(H+1),U=u==="right"?n:I(n).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:n,rangeData:t}=r;if(!t.length)return Promise.reject("处理时间范围失败, rangeData不能为空");const c=n?.teamData||[],{periodicityTime:o}=r,h=r?.currentDay||l().format("YYYY-MM-DD"),N=(y,Y)=>o?parseInt(o.split(":")[0],10)<12?[l(y).format("YYYY-MM-DD")+" "+o,l(Y).add(1,"day").format("YYYY-MM-DD")+" "+o]:[l(y).subtract(1,"day").format("YYYY-MM-DD")+" "+o,l(Y).format("YYYY-MM-DD")+" "+o]:[y,Y],a=Object.entries(e).reduce((y,Y)=>{const[m,J]=Y;for(const[u,H]of Object.entries(J)){const{custom:C}=H;if(!C)continue;const{cellType:P,cycleType:Z,timeIncrement:T,forwardPush:s,forwardPushTimes:f,copyType:i,copyInterval:S,defaultShift:g,useDefaultStartDate:U,useDefaultEndDate:G}=C;if(P==="time"){de({acc:y,params:r,initRowNum:Number(m),initColNum:Number(u),cellData:H});continue}const v={cycleType:Z,indicatorName:C.indicatorName,indicatorCode:C.indicatorCode,indicatorId:C.indicatorId,indicatorDimensionName:C.indicatorDimensionName,indicatorDimensionConfig:C.indicatorDimensionConfig,required:ce(C?.required)??!1,cellType:C.cellType,defaultShift:C?.defaultShift||!1,writeBack:q(C?.writeBack)?!0:C.writeBack,dimensionJson:C?.dimensionJson||"",unit:C?.unit||"",innerSyncWay:C?.innerSyncWay||"",outSyncConfigId:C?.outSyncConfigId||"",innerSyncStatus:C?.innerSyncStatus||""};let k=0;switch(Z){case"day":{let d="";if(s&&(d=L(t[0],f||0,"day")),!i){const D=s?d:t[0],[p,b]=N(...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*(S+1),b=s?d:t[0],[x,B]=N(...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*(S+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*(S+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),W=w(y,B,R);W.s="tor-indicator-cell-style",W.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*(S+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"),[W,be]=O(A,"hour",d,T);x.custom={...v,startTime:W,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*(S+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((n,[t,c])=>{const o=Math.max(...Object.keys(c).map(Number));return o>n?n=Number(o):n=Number(n)||0,n},0)}function Ye(e,r){const n=JSON.parse(JSON.stringify(e||{}));for(const[t,c]of Object.entries(r)){n[t]||(n[t]={});for(const[o,h]of Object.entries(c)){const N=h,a=n[t]?.[o];a?n[t][o]={...a,...N,custom:{...a.custom,...N.custom}}:n[t][o]=N}}return n}function De(e,r){if(!r?.length||!e)return e;const n={};for(const t in e){const c=e[t];for(const o in c){const h=c[o];if(h?.custom?.cellType==="indicator"){const N=Number(t),a=Number(o);if(r.some(Y=>N>=Y.startRow&&N<=Y.endRow&&a>=Y.startColumn&&a<=Y.endColumn)&&!r.some(m=>N===m.startRow&&a===m.startColumn))continue}n[t]||(n[t]={}),n[t][o]=h}}return n}const ge="./style.css";M.CycleTypeEnum=X,M.ModeEnum=ee,M.decimal=I,M.filterIndicatorsCell=me,M.filterMergedIndicatorCells=De,M.generateIndicatorsCells=he,M.generateUUID=_,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"})}));
|