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