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