@idooel/components 0.0.2-beta.5 → 0.0.2-beta.6
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/@idooel/components.esm.js +781 -333
- package/dist/@idooel/components.umd.js +781 -333
- package/package.json +1 -1
- package/packages/upload/src/index.vue +14 -5
|
@@ -9,411 +9,853 @@
|
|
|
9
9
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
10
10
|
var FileUpload__default = /*#__PURE__*/_interopDefaultLegacy(FileUpload);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
var __defProp$2 = Object.defineProperty;
|
|
13
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value
|
|
18
|
+
}) : obj[key] = value;
|
|
19
|
+
var __publicField$2 = (obj, key, value) => {
|
|
20
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
return value;
|
|
18
22
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"%": (data, a, b) => a(data) % b(data),
|
|
31
|
-
"===": (data, a, b) => a(data) === b(data),
|
|
32
|
-
"!==": (data, a, b) => a(data) !== b(data),
|
|
33
|
-
"==": (data, a, b) => a(data) == b(data),
|
|
34
|
-
"!=": (data, a, b) => a(data) != b(data),
|
|
35
|
-
"<": (data, a, b) => a(data) < b(data),
|
|
36
|
-
">": (data, a, b) => a(data) > b(data),
|
|
37
|
-
"<=": (data, a, b) => a(data) <= b(data),
|
|
38
|
-
">=": (data, a, b) => a(data) >= b(data),
|
|
39
|
-
"&&": (data, a, b) => a(data) && b(data),
|
|
40
|
-
"||": (data, a, b) => a(data) || b(data),
|
|
41
|
-
"!": (data, a) => !a(data)
|
|
42
|
-
};
|
|
43
|
-
function isNumber$1(char) {
|
|
44
|
-
return char >= "0" && char <= "9" && typeof char === "string";
|
|
23
|
+
class LexerError extends Error {
|
|
24
|
+
constructor(message, index, line, column) {
|
|
25
|
+
super(message);
|
|
26
|
+
__publicField$2(this, "index");
|
|
27
|
+
__publicField$2(this, "line");
|
|
28
|
+
__publicField$2(this, "column");
|
|
29
|
+
this.name = "LexerError";
|
|
30
|
+
this.index = index;
|
|
31
|
+
this.line = line;
|
|
32
|
+
this.column = column;
|
|
33
|
+
}
|
|
45
34
|
}
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
class ParseError extends Error {
|
|
36
|
+
constructor(message, index, line, column) {
|
|
37
|
+
super(message);
|
|
38
|
+
__publicField$2(this, "index");
|
|
39
|
+
__publicField$2(this, "line");
|
|
40
|
+
__publicField$2(this, "column");
|
|
41
|
+
this.name = "ParseError";
|
|
42
|
+
this.index = index;
|
|
43
|
+
this.line = line;
|
|
44
|
+
this.column = column;
|
|
45
|
+
}
|
|
48
46
|
}
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
class EvalError extends Error {
|
|
48
|
+
constructor(message) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = "EvalError";
|
|
51
|
+
}
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
53
|
+
var TokenKind = /* @__PURE__ */(TokenKind2 => {
|
|
54
|
+
TokenKind2["Identifier"] = "Identifier";
|
|
55
|
+
TokenKind2["Number"] = "Number";
|
|
56
|
+
TokenKind2["String"] = "String";
|
|
57
|
+
TokenKind2["Punctuator"] = "Punctuator";
|
|
58
|
+
TokenKind2["Operator"] = "Operator";
|
|
59
|
+
TokenKind2["EOF"] = "EOF";
|
|
60
|
+
return TokenKind2;
|
|
61
|
+
})(TokenKind || {});
|
|
62
|
+
const PUNCTUATORS = /* @__PURE__ */new Set(["(", ")", "{", "}", "[", "]", ".", ",", ":", "?"]);
|
|
63
|
+
const MULTI_OPERATORS = ["?.", "??", "===", "!==", "==", "!=", "<=", ">=", "&&", "||"];
|
|
64
|
+
const SINGLE_OPERATORS = /* @__PURE__ */new Set(["+", "-", "*", "/", "%", "<", ">", "!"]);
|
|
65
|
+
function isDigit(ch) {
|
|
66
|
+
return ch >= "0" && ch <= "9";
|
|
67
|
+
}
|
|
68
|
+
function isIdentStart(ch) {
|
|
69
|
+
return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch === "_" || ch === "$";
|
|
70
|
+
}
|
|
71
|
+
function isIdentPart(ch) {
|
|
72
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
73
|
+
}
|
|
74
|
+
function lex(input) {
|
|
75
|
+
if (!input && input !== "") throw new LexerError("invalid input", 0, 1, 1);
|
|
76
|
+
const tokens = [];
|
|
77
|
+
let index = 0;
|
|
78
|
+
let line = 1;
|
|
79
|
+
let column = 1;
|
|
80
|
+
function current() {
|
|
81
|
+
return input.charAt(index);
|
|
82
|
+
}
|
|
83
|
+
function advance(n = 1) {
|
|
84
|
+
for (let i = 0; i < n; i++) {
|
|
85
|
+
const ch = input.charAt(index++);
|
|
86
|
+
if (ch === "\n") {
|
|
87
|
+
line++;
|
|
88
|
+
column = 1;
|
|
89
|
+
} else {
|
|
90
|
+
column++;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function make(kind, text, value, startIndex, startLine, startColumn) {
|
|
95
|
+
return {
|
|
96
|
+
kind,
|
|
97
|
+
text,
|
|
98
|
+
value,
|
|
99
|
+
index: startIndex ?? index,
|
|
100
|
+
line: startLine ?? line,
|
|
101
|
+
column: startColumn ?? column
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
while (index < input.length) {
|
|
105
|
+
const ch = current();
|
|
106
|
+
if (ch === " " || ch === " " || ch === "\r" || ch === "\n" || ch === "\v" || ch === "\xA0") {
|
|
107
|
+
advance();
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (ch === "'" || ch === '"') {
|
|
111
|
+
const quote = ch;
|
|
112
|
+
const startIndex = index;
|
|
113
|
+
const startLine = line;
|
|
114
|
+
const startColumn = column;
|
|
115
|
+
advance();
|
|
116
|
+
let value = "";
|
|
117
|
+
let escaped = false;
|
|
118
|
+
while (index < input.length) {
|
|
119
|
+
const c = current();
|
|
120
|
+
if (escaped) {
|
|
121
|
+
if (c === "u") {
|
|
122
|
+
const hex = input.substring(index + 1, index + 5);
|
|
123
|
+
if (!/^[\da-f]{4}$/i.test(hex)) {
|
|
124
|
+
throw new LexerError(`invalid unicode escape \\u${hex}`, index, line, column);
|
|
82
125
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
escape = true;
|
|
86
|
-
} else if (c === char) {
|
|
87
|
-
index++;
|
|
88
|
-
token = {
|
|
89
|
-
index: start,
|
|
90
|
-
constant: true,
|
|
91
|
-
text: char + value + char,
|
|
92
|
-
value
|
|
93
|
-
};
|
|
94
|
-
break;
|
|
126
|
+
value += String.fromCharCode(parseInt(hex, 16));
|
|
127
|
+
advance(5);
|
|
95
128
|
} else {
|
|
96
|
-
|
|
129
|
+
const ESCAPE = {
|
|
130
|
+
n: "\n",
|
|
131
|
+
f: "\f",
|
|
132
|
+
r: "\r",
|
|
133
|
+
t: " ",
|
|
134
|
+
v: "\v"
|
|
135
|
+
};
|
|
136
|
+
value += ESCAPE[c] ?? c;
|
|
137
|
+
advance();
|
|
97
138
|
}
|
|
98
|
-
|
|
139
|
+
escaped = false;
|
|
140
|
+
continue;
|
|
99
141
|
}
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
142
|
+
if (c === "\\") {
|
|
143
|
+
escaped = true;
|
|
144
|
+
advance();
|
|
145
|
+
continue;
|
|
104
146
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (c === "." || isNumber$1(c)) {
|
|
111
|
-
value += c;
|
|
112
|
-
} else {
|
|
113
|
-
let c2 = content.charAt(index + 1);
|
|
114
|
-
if (c === "e" && isExpOperator(c2)) {
|
|
115
|
-
value += c;
|
|
116
|
-
} else if (isExpOperator(c) && c2 && isNumber$1(c2) && value.charAt(value.length - 1) === "e") {
|
|
117
|
-
value += c;
|
|
118
|
-
} else if (isExpOperator(c) && (!c2 || !isNumber$1(c2)) && value.charAt(value.length - 1) == "e") {
|
|
119
|
-
throw new Error(`invalid expression: ${content}`);
|
|
120
|
-
} else {
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
index++;
|
|
147
|
+
if (c === quote) {
|
|
148
|
+
advance();
|
|
149
|
+
tokens.push(make("String" /* String */, input.slice(startIndex, index), value, startIndex, startLine, startColumn));
|
|
150
|
+
value = "";
|
|
151
|
+
break;
|
|
125
152
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
let start = index;
|
|
134
|
-
while (index < length) {
|
|
135
|
-
let c = content.charAt(index);
|
|
136
|
-
if (!(isIdent(c) || isNumber$1(c))) {
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
index++;
|
|
153
|
+
value += c;
|
|
154
|
+
advance();
|
|
155
|
+
}
|
|
156
|
+
if (value !== "") {
|
|
157
|
+
const last = tokens[tokens.length - 1];
|
|
158
|
+
if (!last || last.index !== startIndex) {
|
|
159
|
+
throw new LexerError("unterminated string", startIndex, startLine, startColumn);
|
|
140
160
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
index++;
|
|
154
|
-
} else {
|
|
155
|
-
let char2 = char + content.charAt(index + 1);
|
|
156
|
-
let char3 = char2 + content.charAt(index + 2);
|
|
157
|
-
let op1 = OPERATORS[char];
|
|
158
|
-
let op2 = OPERATORS[char2];
|
|
159
|
-
let op3 = OPERATORS[char3];
|
|
160
|
-
if (op1 || op2 || op3) {
|
|
161
|
-
let text = op3 ? char3 : op2 ? char2 : char;
|
|
162
|
-
tokens.push({
|
|
163
|
-
index,
|
|
164
|
-
text,
|
|
165
|
-
operator: true
|
|
166
|
-
});
|
|
167
|
-
index += text.length;
|
|
161
|
+
}
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (isDigit(ch) || ch === "." && isDigit(input.charAt(index + 1))) {
|
|
165
|
+
const startIndex = index;
|
|
166
|
+
const startLine = line;
|
|
167
|
+
const startColumn = column;
|
|
168
|
+
let text = "";
|
|
169
|
+
while (index < input.length) {
|
|
170
|
+
let c = input.charAt(index).toLowerCase();
|
|
171
|
+
if (c === "." || isDigit(c)) {
|
|
172
|
+
text += c;
|
|
168
173
|
} else {
|
|
169
|
-
|
|
174
|
+
const c2 = input.charAt(index + 1);
|
|
175
|
+
if (c === "e" && (c2 === "+" || c2 === "-" || isDigit(c2))) {
|
|
176
|
+
text += c;
|
|
177
|
+
} else if ((c === "+" || c === "-") && isDigit(c2) && text.charAt(text.length - 1) === "e") {
|
|
178
|
+
text += c;
|
|
179
|
+
} else if ((c === "+" || c === "-") && (!c2 || !isDigit(c2)) && text.charAt(text.length - 1) === "e") {
|
|
180
|
+
throw new LexerError("dangling exponent", index, line, column);
|
|
181
|
+
} else {
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
170
184
|
}
|
|
185
|
+
advance();
|
|
186
|
+
}
|
|
187
|
+
tokens.push(make("Number" /* Number */, text, Number(text), startIndex, startLine, startColumn));
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (isIdentStart(ch)) {
|
|
191
|
+
const startIndex = index;
|
|
192
|
+
const startLine = line;
|
|
193
|
+
const startColumn = column;
|
|
194
|
+
advance();
|
|
195
|
+
while (index < input.length && isIdentPart(current())) advance();
|
|
196
|
+
const text = input.slice(startIndex, index);
|
|
197
|
+
tokens.push(make("Identifier" /* Identifier */, text, void 0, startIndex, startLine, startColumn));
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const three = input.substring(index, index + 3);
|
|
201
|
+
const two = input.substring(index, index + 2);
|
|
202
|
+
const one = input.substring(index, index + 1);
|
|
203
|
+
const multi = MULTI_OPERATORS.find(op => input.startsWith(op, index));
|
|
204
|
+
if (multi) {
|
|
205
|
+
tokens.push(make("Operator" /* Operator */, multi, void 0, index, line, column));
|
|
206
|
+
advance(multi.length);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (PUNCTUATORS.has(one)) {
|
|
210
|
+
tokens.push(make("Punctuator" /* Punctuator */, one, void 0, index, line, column));
|
|
211
|
+
advance();
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (SINGLE_OPERATORS.has(one)) {
|
|
215
|
+
tokens.push(make("Operator" /* Operator */, one, void 0, index, line, column));
|
|
216
|
+
advance();
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
throw new LexerError(`invalid token '${three || two || one}'`, index, line, column);
|
|
220
|
+
}
|
|
221
|
+
tokens.push({
|
|
222
|
+
kind: "EOF" /* EOF */,
|
|
223
|
+
text: "<eof>",
|
|
224
|
+
index,
|
|
225
|
+
line,
|
|
226
|
+
column
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
tokens
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
var __defProp$1 = Object.defineProperty;
|
|
233
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
234
|
+
enumerable: true,
|
|
235
|
+
configurable: true,
|
|
236
|
+
writable: true,
|
|
237
|
+
value
|
|
238
|
+
}) : obj[key] = value;
|
|
239
|
+
var __publicField$1 = (obj, key, value) => {
|
|
240
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
241
|
+
return value;
|
|
242
|
+
};
|
|
243
|
+
class LRUCache {
|
|
244
|
+
constructor(maxSize = 100) {
|
|
245
|
+
__publicField$1(this, "cache", /* @__PURE__ */new Map());
|
|
246
|
+
__publicField$1(this, "maxSize");
|
|
247
|
+
this.maxSize = maxSize;
|
|
248
|
+
}
|
|
249
|
+
get(key) {
|
|
250
|
+
const value = this.cache.get(key);
|
|
251
|
+
if (value !== void 0) {
|
|
252
|
+
this.cache.delete(key);
|
|
253
|
+
this.cache.set(key, value);
|
|
254
|
+
}
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
set(key, value) {
|
|
258
|
+
if (this.cache.has(key)) {
|
|
259
|
+
this.cache.delete(key);
|
|
260
|
+
}
|
|
261
|
+
if (this.cache.size >= this.maxSize) {
|
|
262
|
+
const firstKey = this.cache.keys().next().value;
|
|
263
|
+
if (firstKey !== void 0) {
|
|
264
|
+
this.cache.delete(firstKey);
|
|
171
265
|
}
|
|
172
266
|
}
|
|
267
|
+
this.cache.set(key, value);
|
|
268
|
+
}
|
|
269
|
+
clear() {
|
|
270
|
+
this.cache.clear();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const astCache = new LRUCache(100);
|
|
274
|
+
function parseToAst(input) {
|
|
275
|
+
const cached = astCache.get(input);
|
|
276
|
+
if (cached !== void 0) {
|
|
277
|
+
return cached;
|
|
278
|
+
}
|
|
279
|
+
const {
|
|
280
|
+
tokens
|
|
281
|
+
} = lex(input);
|
|
282
|
+
const state = new Parser(tokens, input);
|
|
283
|
+
const result = state.parse();
|
|
284
|
+
astCache.set(input, result);
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
class Parser {
|
|
288
|
+
constructor(tokens, input) {
|
|
289
|
+
__publicField$1(this, "tokens");
|
|
290
|
+
__publicField$1(this, "input");
|
|
291
|
+
__publicField$1(this, "i", 0);
|
|
173
292
|
this.tokens = tokens;
|
|
174
|
-
|
|
293
|
+
this.input = input;
|
|
175
294
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return data => func && func(data);
|
|
295
|
+
current() {
|
|
296
|
+
return this.tokens[this.i];
|
|
297
|
+
}
|
|
298
|
+
next() {
|
|
299
|
+
return this.tokens[this.i + 1];
|
|
300
|
+
}
|
|
301
|
+
eat() {
|
|
302
|
+
return this.tokens[this.i++];
|
|
185
303
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
304
|
+
matchText(text) {
|
|
305
|
+
return this.current()?.text === text;
|
|
306
|
+
}
|
|
307
|
+
expectText(text) {
|
|
308
|
+
const t = this.current();
|
|
309
|
+
if (!text || t?.text === text) {
|
|
310
|
+
this.i++;
|
|
311
|
+
return t;
|
|
191
312
|
}
|
|
313
|
+
return void 0;
|
|
314
|
+
}
|
|
315
|
+
consumeText(text) {
|
|
316
|
+
const t = this.expectText(text);
|
|
317
|
+
if (!t) this.error(this.current(), `unexpected token, expect '${text ?? "<any>"}'`);
|
|
318
|
+
return t;
|
|
319
|
+
}
|
|
320
|
+
error(t, message) {
|
|
321
|
+
throw new ParseError(`${message} at ${t.line}:${t.column}`, t.index, t.line, t.column);
|
|
192
322
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
323
|
+
parse() {
|
|
324
|
+
const t = this.current();
|
|
325
|
+
if (t && t.kind !== TokenKind.EOF && t.text !== "}" && t.text !== ")" && t.text !== "]") {
|
|
326
|
+
const expr = this.expression();
|
|
327
|
+
return expr;
|
|
328
|
+
}
|
|
329
|
+
return void 0;
|
|
198
330
|
}
|
|
199
331
|
expression() {
|
|
200
332
|
return this.ternary();
|
|
201
333
|
}
|
|
202
334
|
ternary() {
|
|
203
|
-
|
|
204
|
-
if (this.
|
|
205
|
-
|
|
206
|
-
this.
|
|
207
|
-
|
|
208
|
-
|
|
335
|
+
const test = this.nullish();
|
|
336
|
+
if (this.expectText("?")) {
|
|
337
|
+
const consequent = this.expression();
|
|
338
|
+
this.consumeText(":");
|
|
339
|
+
const alternate = this.expression();
|
|
340
|
+
const node = {
|
|
341
|
+
type: "ConditionalExpression",
|
|
342
|
+
test,
|
|
343
|
+
consequent,
|
|
344
|
+
alternate
|
|
345
|
+
};
|
|
346
|
+
return node;
|
|
209
347
|
}
|
|
210
|
-
return
|
|
211
|
-
}
|
|
212
|
-
binary(left, op, right) {
|
|
213
|
-
let fn = OPERATORS[op];
|
|
214
|
-
return data => fn(data, left, right);
|
|
348
|
+
return test;
|
|
215
349
|
}
|
|
216
|
-
|
|
217
|
-
let
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
350
|
+
nullish() {
|
|
351
|
+
let left = this.logicalOR();
|
|
352
|
+
while (this.expectText("??")) {
|
|
353
|
+
if (isLogicalAndOr(left)) {
|
|
354
|
+
this.error(this.current(), "Cannot mix ?? with && or || without parentheses");
|
|
355
|
+
}
|
|
356
|
+
const rightStart = this.current();
|
|
357
|
+
const right = this.logicalOR();
|
|
358
|
+
if (isLogicalAndOr(right)) {
|
|
359
|
+
this.error(rightStart, "Cannot mix ?? with && or || without parentheses");
|
|
360
|
+
}
|
|
361
|
+
const node = {
|
|
362
|
+
type: "LogicalExpression",
|
|
363
|
+
operator: "??",
|
|
364
|
+
left,
|
|
365
|
+
right
|
|
366
|
+
};
|
|
367
|
+
left = node;
|
|
228
368
|
}
|
|
369
|
+
return left;
|
|
229
370
|
}
|
|
230
371
|
logicalOR() {
|
|
231
372
|
let left = this.logicalAND();
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
373
|
+
while (this.expectText("||")) {
|
|
374
|
+
const right = this.logicalAND();
|
|
375
|
+
const node = {
|
|
376
|
+
type: "LogicalExpression",
|
|
377
|
+
operator: "||",
|
|
378
|
+
left,
|
|
379
|
+
right
|
|
380
|
+
};
|
|
381
|
+
left = node;
|
|
235
382
|
}
|
|
236
383
|
return left;
|
|
237
384
|
}
|
|
238
385
|
logicalAND() {
|
|
239
386
|
let left = this.equality();
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
387
|
+
while (this.expectText("&&")) {
|
|
388
|
+
const right = this.equality();
|
|
389
|
+
const node = {
|
|
390
|
+
type: "LogicalExpression",
|
|
391
|
+
operator: "&&",
|
|
392
|
+
left,
|
|
393
|
+
right
|
|
394
|
+
};
|
|
395
|
+
left = node;
|
|
243
396
|
}
|
|
244
397
|
return left;
|
|
245
398
|
}
|
|
246
399
|
equality() {
|
|
247
400
|
let left = this.relational();
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
401
|
+
while (true) {
|
|
402
|
+
if (this.expectText("===")) {
|
|
403
|
+
left = this.binary(left, "===", this.relational());
|
|
404
|
+
} else if (this.expectText("!==")) {
|
|
405
|
+
left = this.binary(left, "!==", this.relational());
|
|
406
|
+
} else if (this.expectText("==")) {
|
|
407
|
+
left = this.binary(left, "==", this.relational());
|
|
408
|
+
} else if (this.expectText("!=")) {
|
|
409
|
+
left = this.binary(left, "!=", this.relational());
|
|
410
|
+
} else break;
|
|
251
411
|
}
|
|
252
412
|
return left;
|
|
253
413
|
}
|
|
254
414
|
relational() {
|
|
255
415
|
let left = this.additive();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
416
|
+
while (true) {
|
|
417
|
+
if (this.expectText("<=")) {
|
|
418
|
+
left = this.binary(left, "<=", this.additive());
|
|
419
|
+
} else if (this.expectText(">=")) {
|
|
420
|
+
left = this.binary(left, ">=", this.additive());
|
|
421
|
+
} else if (this.expectText("<")) {
|
|
422
|
+
left = this.binary(left, "<", this.additive());
|
|
423
|
+
} else if (this.expectText(">")) {
|
|
424
|
+
left = this.binary(left, ">", this.additive());
|
|
425
|
+
} else break;
|
|
259
426
|
}
|
|
260
427
|
return left;
|
|
261
428
|
}
|
|
262
429
|
additive() {
|
|
263
430
|
let left = this.multiplicative();
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
431
|
+
while (true) {
|
|
432
|
+
if (this.expectText("+")) {
|
|
433
|
+
left = this.binary(left, "+", this.multiplicative());
|
|
434
|
+
} else if (this.expectText("-")) {
|
|
435
|
+
left = this.binary(left, "-", this.multiplicative());
|
|
436
|
+
} else break;
|
|
267
437
|
}
|
|
268
438
|
return left;
|
|
269
439
|
}
|
|
270
440
|
multiplicative() {
|
|
271
441
|
let left = this.unary();
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
442
|
+
while (true) {
|
|
443
|
+
if (this.expectText("*")) {
|
|
444
|
+
left = this.binary(left, "*", this.unary());
|
|
445
|
+
} else if (this.expectText("/")) {
|
|
446
|
+
left = this.binary(left, "/", this.unary());
|
|
447
|
+
} else if (this.expectText("%")) {
|
|
448
|
+
left = this.binary(left, "%", this.unary());
|
|
449
|
+
} else break;
|
|
275
450
|
}
|
|
276
451
|
return left;
|
|
277
452
|
}
|
|
453
|
+
unary() {
|
|
454
|
+
if (this.expectText("+")) {
|
|
455
|
+
return this.primary();
|
|
456
|
+
}
|
|
457
|
+
if (this.expectText("-")) {
|
|
458
|
+
const arg = this.unary();
|
|
459
|
+
const node = {
|
|
460
|
+
type: "UnaryExpression",
|
|
461
|
+
operator: "-",
|
|
462
|
+
argument: arg
|
|
463
|
+
};
|
|
464
|
+
return node;
|
|
465
|
+
}
|
|
466
|
+
if (this.expectText("!")) {
|
|
467
|
+
const arg = this.unary();
|
|
468
|
+
const node = {
|
|
469
|
+
type: "UnaryExpression",
|
|
470
|
+
operator: "!",
|
|
471
|
+
argument: arg
|
|
472
|
+
};
|
|
473
|
+
return node;
|
|
474
|
+
}
|
|
475
|
+
return this.primary();
|
|
476
|
+
}
|
|
278
477
|
primary() {
|
|
279
|
-
|
|
280
|
-
let
|
|
281
|
-
if (this.
|
|
282
|
-
|
|
283
|
-
this.
|
|
284
|
-
} else if (this.
|
|
285
|
-
|
|
286
|
-
} else if (this.
|
|
287
|
-
|
|
288
|
-
} else if (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
478
|
+
const t = this.current();
|
|
479
|
+
let expr;
|
|
480
|
+
if (this.expectText("(")) {
|
|
481
|
+
expr = this.expression();
|
|
482
|
+
this.consumeText(")");
|
|
483
|
+
} else if (this.expectText("[")) {
|
|
484
|
+
expr = this.array();
|
|
485
|
+
} else if (this.expectText("{")) {
|
|
486
|
+
expr = this.object();
|
|
487
|
+
} else if (t.kind === TokenKind.Identifier && (t.text === "true" || t.text === "false" || t.text === "null" || t.text === "undefined")) {
|
|
488
|
+
const tok = this.eat();
|
|
489
|
+
const map = {
|
|
490
|
+
true: true,
|
|
491
|
+
false: false,
|
|
492
|
+
null: null,
|
|
493
|
+
undefined: void 0
|
|
494
|
+
};
|
|
495
|
+
const node = {
|
|
496
|
+
type: "Literal",
|
|
497
|
+
value: map[tok.text]
|
|
498
|
+
};
|
|
499
|
+
expr = node;
|
|
500
|
+
} else if (t.kind === TokenKind.Identifier) {
|
|
501
|
+
expr = this.identifier();
|
|
502
|
+
} else if (t.kind === TokenKind.Number || t.kind === TokenKind.String) {
|
|
503
|
+
const tok = this.eat();
|
|
504
|
+
const node = {
|
|
505
|
+
type: "Literal",
|
|
506
|
+
value: tok.kind === TokenKind.Number ? Number(tok.text) : String(tok.value)
|
|
507
|
+
};
|
|
508
|
+
expr = node;
|
|
294
509
|
} else {
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
510
|
+
this.error(t, "unexpected token in primary");
|
|
511
|
+
}
|
|
512
|
+
while (true) {
|
|
513
|
+
if (this.expectText("(")) {
|
|
514
|
+
const args = [];
|
|
515
|
+
if (!this.matchText(")")) {
|
|
516
|
+
do {
|
|
517
|
+
args.push(this.expression());
|
|
518
|
+
} while (this.expectText(","));
|
|
519
|
+
}
|
|
520
|
+
this.consumeText(")");
|
|
521
|
+
const call = {
|
|
522
|
+
type: "CallExpression",
|
|
523
|
+
callee: expr,
|
|
524
|
+
arguments: args,
|
|
525
|
+
optional: false
|
|
526
|
+
};
|
|
527
|
+
expr = call;
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
if (this.expectText("?.(")) ;
|
|
531
|
+
if (this.expectText(".")) {
|
|
532
|
+
const id = this.consumeIdentifier();
|
|
533
|
+
const prop = {
|
|
534
|
+
type: "Identifier",
|
|
535
|
+
name: id
|
|
536
|
+
};
|
|
537
|
+
const mem = {
|
|
538
|
+
type: "MemberExpression",
|
|
539
|
+
object: expr,
|
|
540
|
+
property: prop,
|
|
541
|
+
computed: false,
|
|
542
|
+
optional: false
|
|
543
|
+
};
|
|
544
|
+
expr = mem;
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
if (this.expectText("[")) {
|
|
548
|
+
const prop = this.expression();
|
|
549
|
+
this.consumeText("]");
|
|
550
|
+
const mem = {
|
|
551
|
+
type: "MemberExpression",
|
|
552
|
+
object: expr,
|
|
553
|
+
property: prop,
|
|
554
|
+
computed: true,
|
|
555
|
+
optional: false
|
|
556
|
+
};
|
|
557
|
+
expr = mem;
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
if (this.matchText("?.")) {
|
|
561
|
+
this.eat();
|
|
562
|
+
if (this.expectText("(")) {
|
|
563
|
+
const args = [];
|
|
564
|
+
if (!this.matchText(")")) {
|
|
565
|
+
do {
|
|
566
|
+
args.push(this.expression());
|
|
567
|
+
} while (this.expectText(","));
|
|
568
|
+
}
|
|
569
|
+
this.consumeText(")");
|
|
570
|
+
const call = {
|
|
571
|
+
type: "CallExpression",
|
|
572
|
+
callee: expr,
|
|
573
|
+
arguments: args,
|
|
574
|
+
optional: true
|
|
575
|
+
};
|
|
576
|
+
expr = call;
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (this.expectText("[")) {
|
|
580
|
+
const prop2 = this.expression();
|
|
581
|
+
this.consumeText("]");
|
|
582
|
+
const mem2 = {
|
|
583
|
+
type: "MemberExpression",
|
|
584
|
+
object: expr,
|
|
585
|
+
property: prop2,
|
|
586
|
+
computed: true,
|
|
587
|
+
optional: true
|
|
588
|
+
};
|
|
589
|
+
expr = mem2;
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
const id = this.consumeIdentifier();
|
|
593
|
+
const prop = {
|
|
594
|
+
type: "Identifier",
|
|
595
|
+
name: id
|
|
596
|
+
};
|
|
597
|
+
const mem = {
|
|
598
|
+
type: "MemberExpression",
|
|
599
|
+
object: expr,
|
|
600
|
+
property: prop,
|
|
601
|
+
computed: false,
|
|
602
|
+
optional: true
|
|
603
|
+
};
|
|
604
|
+
expr = mem;
|
|
605
|
+
continue;
|
|
309
606
|
}
|
|
607
|
+
break;
|
|
310
608
|
}
|
|
311
|
-
return
|
|
609
|
+
return expr;
|
|
312
610
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
objectIndex(object) {
|
|
321
|
-
let indexFn = this.expression();
|
|
322
|
-
this.consume("]");
|
|
323
|
-
return data => {
|
|
324
|
-
let o = object(data);
|
|
325
|
-
let key = indexFn(data) + "";
|
|
326
|
-
return o && o[key];
|
|
611
|
+
identifier() {
|
|
612
|
+
const name = this.consumeIdentifier();
|
|
613
|
+
const node = {
|
|
614
|
+
type: "Identifier",
|
|
615
|
+
name
|
|
327
616
|
};
|
|
617
|
+
return node;
|
|
328
618
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
} while (this.expect(","));
|
|
335
|
-
}
|
|
336
|
-
this.consume(")");
|
|
337
|
-
return data => {
|
|
338
|
-
let callContext = context && context(data);
|
|
339
|
-
let fn = func(data, callContext);
|
|
340
|
-
return fn && fn.apply(callContext, args.length ? args.map(arg => arg(data)) : null);
|
|
341
|
-
};
|
|
619
|
+
consumeIdentifier() {
|
|
620
|
+
const t = this.current();
|
|
621
|
+
if (t.kind !== TokenKind.Identifier) this.error(t, "identifier expected");
|
|
622
|
+
this.eat();
|
|
623
|
+
return t.text;
|
|
342
624
|
}
|
|
343
625
|
array() {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (token.text !== "]") {
|
|
626
|
+
const elements = [];
|
|
627
|
+
if (!this.matchText("]")) {
|
|
347
628
|
do {
|
|
348
|
-
if (this.
|
|
629
|
+
if (this.matchText("]")) break;
|
|
349
630
|
elements.push(this.expression());
|
|
350
|
-
} while (this.
|
|
631
|
+
} while (this.expectText(","));
|
|
351
632
|
}
|
|
352
|
-
this.
|
|
353
|
-
return
|
|
633
|
+
this.consumeText("]");
|
|
634
|
+
return {
|
|
635
|
+
type: "ArrayExpression",
|
|
636
|
+
elements
|
|
637
|
+
};
|
|
354
638
|
}
|
|
355
639
|
object() {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
let token = this.tokens[0];
|
|
359
|
-
if (token.text !== "}") {
|
|
640
|
+
const properties = [];
|
|
641
|
+
if (!this.matchText("}")) {
|
|
360
642
|
do {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
values.push(this.expression());
|
|
373
|
-
} while (this.expect(","));
|
|
643
|
+
if (this.matchText("}")) break;
|
|
644
|
+
const keyTok = this.eat();
|
|
645
|
+
let key;
|
|
646
|
+
if (keyTok.kind === TokenKind.String) key = String(keyTok.value);else if (keyTok.kind === TokenKind.Identifier) key = keyTok.text;else this.error(keyTok, "invalid object key");
|
|
647
|
+
this.consumeText(":");
|
|
648
|
+
const value = this.expression();
|
|
649
|
+
properties.push({
|
|
650
|
+
key,
|
|
651
|
+
value
|
|
652
|
+
});
|
|
653
|
+
} while (this.expectText(","));
|
|
374
654
|
}
|
|
375
|
-
this.
|
|
376
|
-
return
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
object[keys[i]] = values[i](data);
|
|
380
|
-
}
|
|
381
|
-
return object;
|
|
655
|
+
this.consumeText("}");
|
|
656
|
+
return {
|
|
657
|
+
type: "ObjectExpression",
|
|
658
|
+
properties
|
|
382
659
|
};
|
|
383
660
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
id += this.consume().text + this.consume().text;
|
|
391
|
-
token = this.tokens[0];
|
|
392
|
-
token2 = this.tokens[1];
|
|
393
|
-
token3 = this.tokens[2];
|
|
394
|
-
}
|
|
395
|
-
return data => {
|
|
396
|
-
let elements = id.split(".");
|
|
397
|
-
let key;
|
|
398
|
-
for (let i = 0; elements.length > 1; i++) {
|
|
399
|
-
key = elements.shift();
|
|
400
|
-
data = data[key];
|
|
401
|
-
if (!data) break;
|
|
402
|
-
}
|
|
403
|
-
key = elements.shift();
|
|
404
|
-
return data && data[key];
|
|
661
|
+
binary(left, op, right) {
|
|
662
|
+
return {
|
|
663
|
+
type: "BinaryExpression",
|
|
664
|
+
operator: op,
|
|
665
|
+
left,
|
|
666
|
+
right
|
|
405
667
|
};
|
|
406
668
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
669
|
+
}
|
|
670
|
+
function isLogicalAndOr(node) {
|
|
671
|
+
return node.type === "LogicalExpression" && (node.operator === "&&" || node.operator === "||");
|
|
672
|
+
}
|
|
673
|
+
const DENY_KEYS = /* @__PURE__ */new Set(["__proto__", "prototype", "constructor"]);
|
|
674
|
+
let evalOptions = {};
|
|
675
|
+
let currentDepth = 0;
|
|
676
|
+
function evaluate(ast, scope, options) {
|
|
677
|
+
if (!ast) return void 0;
|
|
678
|
+
evalOptions = options || {};
|
|
679
|
+
currentDepth = 0;
|
|
680
|
+
return exec(ast, scope);
|
|
681
|
+
}
|
|
682
|
+
function exec(node, scope) {
|
|
683
|
+
const maxDepth = evalOptions.maxDepth || 100;
|
|
684
|
+
if (++currentDepth > maxDepth) {
|
|
685
|
+
currentDepth--;
|
|
686
|
+
if (evalOptions.strict) {
|
|
687
|
+
throw new EvalError(`Maximum recursion depth (${maxDepth}) exceeded`);
|
|
688
|
+
}
|
|
689
|
+
return void 0;
|
|
410
690
|
}
|
|
691
|
+
try {
|
|
692
|
+
switch (node.type) {
|
|
693
|
+
case "Literal":
|
|
694
|
+
return node.value;
|
|
695
|
+
case "Identifier":
|
|
696
|
+
return readIdentifier(node, scope);
|
|
697
|
+
case "MemberExpression":
|
|
698
|
+
return readMember(node, scope);
|
|
699
|
+
case "CallExpression":
|
|
700
|
+
return callExpression(node, scope);
|
|
701
|
+
case "UnaryExpression":
|
|
702
|
+
return unaryExpression(node, scope);
|
|
703
|
+
case "BinaryExpression":
|
|
704
|
+
return binaryExpression(node, scope);
|
|
705
|
+
case "LogicalExpression":
|
|
706
|
+
return logicalExpression(node, scope);
|
|
707
|
+
case "ConditionalExpression":
|
|
708
|
+
return conditionalExpression(node, scope);
|
|
709
|
+
case "ArrayExpression":
|
|
710
|
+
return arrayExpression(node, scope);
|
|
711
|
+
case "ObjectExpression":
|
|
712
|
+
return objectExpression(node, scope);
|
|
713
|
+
default:
|
|
714
|
+
return void 0;
|
|
715
|
+
}
|
|
716
|
+
} finally {
|
|
717
|
+
currentDepth--;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
function readIdentifier(node, scope) {
|
|
721
|
+
if (!scope) return void 0;
|
|
722
|
+
return scope[node.name];
|
|
411
723
|
}
|
|
412
|
-
|
|
724
|
+
function readMember(node, scope) {
|
|
725
|
+
const object = exec(node.object, scope);
|
|
726
|
+
if (object == null) {
|
|
727
|
+
return void 0;
|
|
728
|
+
}
|
|
729
|
+
const key = node.computed ? String(exec(node.property, scope)) : node.property.name;
|
|
730
|
+
if (DENY_KEYS.has(key)) {
|
|
731
|
+
if (evalOptions.strict) {
|
|
732
|
+
throw new EvalError(`Access to property "${key}" is not allowed`);
|
|
733
|
+
}
|
|
734
|
+
return void 0;
|
|
735
|
+
}
|
|
736
|
+
try {
|
|
737
|
+
return object[key];
|
|
738
|
+
} catch (err) {
|
|
739
|
+
if (evalOptions.strict) {
|
|
740
|
+
throw new EvalError(`Failed to access property "${key}": ${err}`);
|
|
741
|
+
}
|
|
742
|
+
return void 0;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
function callExpression(node, scope) {
|
|
746
|
+
let fn;
|
|
747
|
+
let thisArg = void 0;
|
|
748
|
+
const calleeNode = node.callee;
|
|
749
|
+
if (calleeNode.type === "MemberExpression") {
|
|
750
|
+
const mem = calleeNode;
|
|
751
|
+
thisArg = exec(mem.object, scope);
|
|
752
|
+
if (thisArg == null) return void 0;
|
|
753
|
+
const key = mem.computed ? String(exec(mem.property, scope)) : mem.property.name;
|
|
754
|
+
if (DENY_KEYS.has(key)) {
|
|
755
|
+
if (evalOptions.strict) {
|
|
756
|
+
throw new EvalError(`Call to method "${key}" is not allowed`);
|
|
757
|
+
}
|
|
758
|
+
return void 0;
|
|
759
|
+
}
|
|
760
|
+
fn = thisArg[key];
|
|
761
|
+
} else {
|
|
762
|
+
fn = exec(node.callee, scope);
|
|
763
|
+
}
|
|
764
|
+
if (fn == null) return void 0;
|
|
765
|
+
if (typeof fn !== "function") {
|
|
766
|
+
if (evalOptions.strict) {
|
|
767
|
+
throw new EvalError(`Cannot call non-function value`);
|
|
768
|
+
}
|
|
769
|
+
return void 0;
|
|
770
|
+
}
|
|
771
|
+
const args = node.arguments.map(a => exec(a, scope));
|
|
772
|
+
try {
|
|
773
|
+
return fn.apply(thisArg, args);
|
|
774
|
+
} catch (err) {
|
|
775
|
+
if (evalOptions.strict) {
|
|
776
|
+
throw new EvalError(`Function call failed: ${err}`);
|
|
777
|
+
}
|
|
778
|
+
return void 0;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function unaryExpression(node, scope) {
|
|
782
|
+
const v = exec(node.argument, scope);
|
|
783
|
+
switch (node.operator) {
|
|
784
|
+
case "-":
|
|
785
|
+
return 0 - Number(v);
|
|
786
|
+
case "!":
|
|
787
|
+
return !v;
|
|
788
|
+
case "+":
|
|
789
|
+
return v;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
function binaryExpression(node, scope) {
|
|
793
|
+
const a = exec(node.left, scope);
|
|
794
|
+
const b = exec(node.right, scope);
|
|
795
|
+
switch (node.operator) {
|
|
796
|
+
case "+":
|
|
797
|
+
return a + b;
|
|
798
|
+
case "-":
|
|
799
|
+
return a - b;
|
|
800
|
+
case "*":
|
|
801
|
+
return a * b;
|
|
802
|
+
case "/":
|
|
803
|
+
return a / b;
|
|
804
|
+
case "%":
|
|
805
|
+
return a % b;
|
|
806
|
+
case "==":
|
|
807
|
+
return a == b;
|
|
808
|
+
case "!=":
|
|
809
|
+
return a != b;
|
|
810
|
+
case "===":
|
|
811
|
+
return a === b;
|
|
812
|
+
case "!==":
|
|
813
|
+
return a !== b;
|
|
814
|
+
case "<":
|
|
815
|
+
return a < b;
|
|
816
|
+
case ">":
|
|
817
|
+
return a > b;
|
|
818
|
+
case "<=":
|
|
819
|
+
return a <= b;
|
|
820
|
+
case ">=":
|
|
821
|
+
return a >= b;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function logicalExpression(node, scope) {
|
|
825
|
+
if (node.operator === "&&") {
|
|
826
|
+
const left2 = exec(node.left, scope);
|
|
827
|
+
return left2 ? exec(node.right, scope) : left2;
|
|
828
|
+
}
|
|
829
|
+
if (node.operator === "||") {
|
|
830
|
+
const left2 = exec(node.left, scope);
|
|
831
|
+
return left2 ? left2 : exec(node.right, scope);
|
|
832
|
+
}
|
|
833
|
+
const left = exec(node.left, scope);
|
|
834
|
+
return left ?? exec(node.right, scope);
|
|
835
|
+
}
|
|
836
|
+
function conditionalExpression(node, scope) {
|
|
837
|
+
const test = exec(node.test, scope);
|
|
838
|
+
return test ? exec(node.consequent, scope) : exec(node.alternate, scope);
|
|
839
|
+
}
|
|
840
|
+
function arrayExpression(node, scope) {
|
|
841
|
+
return node.elements.map(e => exec(e, scope));
|
|
842
|
+
}
|
|
843
|
+
function objectExpression(node, scope) {
|
|
844
|
+
const out = {};
|
|
845
|
+
for (const p of node.properties) {
|
|
846
|
+
if (DENY_KEYS.has(p.key)) continue;
|
|
847
|
+
out[p.key] = exec(p.value, scope);
|
|
848
|
+
}
|
|
849
|
+
return out;
|
|
850
|
+
}
|
|
851
|
+
function compile(expression, options) {
|
|
413
852
|
if (!expression) throw new Error("expression is required");
|
|
414
|
-
const
|
|
415
|
-
return
|
|
416
|
-
}
|
|
853
|
+
const ast = parseToAst(expression);
|
|
854
|
+
return scope => evaluate(ast, scope, options);
|
|
855
|
+
}
|
|
856
|
+
function parse$1(expression, scope = {}, options) {
|
|
857
|
+
return compile(expression, options)(scope);
|
|
858
|
+
}
|
|
417
859
|
|
|
418
860
|
const CONTEXT = '__idooel__ele__context__';
|
|
419
861
|
const AREA_NAMES = {
|
|
@@ -5395,7 +5837,8 @@
|
|
|
5395
5837
|
// 上传状态管理
|
|
5396
5838
|
saveToServerAsyncPageTimer: null,
|
|
5397
5839
|
uploadRefId: null,
|
|
5398
|
-
groupId
|
|
5840
|
+
// 多选且外部无值时,预先生成 groupId,确保首次上传参数完整
|
|
5841
|
+
groupId: this.multiple && !this.value ? v4() : null
|
|
5399
5842
|
};
|
|
5400
5843
|
},
|
|
5401
5844
|
created() {
|
|
@@ -5408,11 +5851,6 @@
|
|
|
5408
5851
|
watch: {
|
|
5409
5852
|
value: {
|
|
5410
5853
|
async handler(value) {
|
|
5411
|
-
console.log('watch.value triggered:', {
|
|
5412
|
-
value,
|
|
5413
|
-
multiple: this.multiple,
|
|
5414
|
-
currentGroupId: this.groupId
|
|
5415
|
-
});
|
|
5416
5854
|
if (shared.type.isEmpty(value)) {
|
|
5417
5855
|
this.resetFiles();
|
|
5418
5856
|
} else if (this.multiple) {
|
|
@@ -5891,8 +6329,18 @@
|
|
|
5891
6329
|
resetFiles() {
|
|
5892
6330
|
this.files = [];
|
|
5893
6331
|
this.buildedFiles = [];
|
|
5894
|
-
|
|
5895
|
-
|
|
6332
|
+
// 多选模式下保留或生成 groupId,避免首次上传为空
|
|
6333
|
+
if (this.multiple) {
|
|
6334
|
+
if (!this.groupId) {
|
|
6335
|
+
this.groupId = v4();
|
|
6336
|
+
console.log('Generated groupId in resetFiles:', this.groupId);
|
|
6337
|
+
} else {
|
|
6338
|
+
console.log('Preserve existing groupId in resetFiles:', this.groupId);
|
|
6339
|
+
}
|
|
6340
|
+
} else {
|
|
6341
|
+
this.groupId = null;
|
|
6342
|
+
console.log('Reset groupId to null (single mode)');
|
|
6343
|
+
}
|
|
5896
6344
|
},
|
|
5897
6345
|
/**
|
|
5898
6346
|
* 处理多文件模式的值变化
|
|
@@ -6147,11 +6595,11 @@
|
|
|
6147
6595
|
/* style */
|
|
6148
6596
|
const __vue_inject_styles__$t = function (inject) {
|
|
6149
6597
|
if (!inject) return
|
|
6150
|
-
inject("data-v-4772bfd1_0", { source: "[data-v-4772bfd1] .ele-upload__inner {\n opacity: 1 !important;\n cursor: pointer;\n border: 1px dashed var(--idooel-form-title-border-color);\n background: var(--idooel-form-upload-bg-color) !important;\n border-radius: var(--idooel-form-border-radius);\n}\n[data-v-4772bfd1] .ele-upload__inner:hover {\n border-color: var(--idooel-form-upload-border-hover-color);\n}\n.ele-upload__wrapper[data-v-4772bfd1] {\n width: 100%;\n}\n.ele-upload__wrapper .ele-upload__area[data-v-4772bfd1] {\n padding: 16px;\n width: 100%;\n height: 80px;\n display: flex;\n flex-direction: row;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon[data-v-4772bfd1] {\n color: var(--idooel-primary-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n font-size: 16x;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon .anticon-cloud-upload[data-v-4772bfd1] {\n font-size: 48px;\n color: var(--idooel-primary-color);\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon .anticon[data-v-4772bfd1] {\n font-size: 48px;\n color: var(--idooel-primary-color);\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text[data-v-4772bfd1] {\n margin-left: 16px;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text .ele-upload__message[data-v-4772bfd1] {\n font-size: 16px;\n color: var(--idoole-black-088);\n text-align: left;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text .ele-upload__ext[data-v-4772bfd1] {\n text-align: left;\n font-size: 14px;\n color: var(--idoole-black-06);\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item[data-v-4772bfd1] {\n width: 100%;\n margin-top: 8px;\n padding: 8px 12px;\n border-radius: var(--idooel-form-border-radius);\n background: var(--idooel-form-upload-bg-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__suffix--icon[data-v-4772bfd1] {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__name[data-v-4772bfd1] {\n flex: 1;\n text-align: left;\n white-space: nowrap;\n overflow: hidden;\n font-size: 14px;\n margin-left: 8px;\n cursor: pointer;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__name .ele-file__inner[data-v-4772bfd1] {\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__delete[data-v-4772bfd1] {\n margin-left: 8px;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__delete .ele-file__delete--icon[data-v-4772bfd1] {\n margin-left: 8px;\n cursor: pointer;\n}\n\n/*# sourceMappingURL=index.vue.map */", map: {"version":3,"sources":["/Users/huangshan/Goldgov/GanJiao/base-elearning-frontend-model/packages/components/packages/upload/src/index.vue","index.vue"],"names":[],"mappings":"AA0tBA;EACA,qBAAA;EACA,eAAA;EACA,wDAAA;EACA,yDAAA;EAIA,+CAAA;AC5tBA;ADytBA;EACA,0DAAA;ACvtBA;AD2tBA;EACA,WAAA;ACxtBA;ADytBA;EACA,aAAA;EACA,WAAA;EACA,YAAA;EACA,aAAA;EACA,mBAAA;ACvtBA;ADwtBA;EACA,kCAAA;EACA,aAAA;EACA,mBAAA;EACA,mBAAA;EACA,cAAA;ACttBA;ADutBA;EACA,eAAA;EACA,kCAAA;ACrtBA;ADutBA;EACA,eAAA;EACA,kCAAA;ACrtBA;ADwtBA;EACA,iBAAA;ACttBA;ADutBA;EACA,eAAA;EACA,8BAAA;EACA,gBAAA;ACrtBA;ADutBA;EACA,gBAAA;EACA,eAAA;EACA,6BAAA;ACrtBA;AD0tBA;EACA,WAAA;EACA,eAAA;EACA,iBAAA;EACA,+CAAA;EACA,8CAAA;EACA,aAAA;EACA,mBAAA;EACA,mBAAA;ACxtBA;ADytBA;EACA,aAAA;EACA,mBAAA;EACA,uBAAA;EACA,WAAA;EACA,YAAA;ACvtBA;ADytBA;EACA,OAAA;EACA,gBAAA;EACA,mBAAA;EACA,gBAAA;EACA,eAAA;EACA,gBAAA;EACA,eAAA;ACvtBA;ADwtBA;EACA,gBAAA;EACA,uBAAA;ACttBA;ADytBA;EACA,gBAAA;ACvtBA;ADwtBA;EACA,gBAAA;EACA,eAAA;ACttBA;;AAEA,oCAAoC","file":"index.vue","sourcesContent":["<template>\n <div class=\"ele-upload__wrapper\">\n <FileUpload\n class=\"ele-upload__inner\"\n v-show=\"isShowUploadContainer\"\n v-model=\"files\"\n :ref=\"uploadRef\"\n :drop=\"drop\"\n :chunk-enabled=\"chunkEnabled\"\n :chunk=\"chunkConfig\"\n :accept=\"accept\"\n :size=\"fileSizeLimit\"\n :post-action=\"postAction\"\n :multiple=\"multiple\"\n :headers=\"headers\"\n :maximum=\"getMaximum\"\n :data=\"uploadParams\"\n @input-file=\"onWatchInputFiles\"\n @input=\"onWatchFiles\"\n style=\"width: 100%;\">\n <section class=\"ele-upload__area\">\n <div class=\"ele-upload__area--icon\">\n <template v-if=\"iconIsZhWrod\">\n {{ icon }}\n </template>\n <template v-else>\n <ele-icon :type=\"icon\"></ele-icon>\n </template>\n </div>\n <div class=\"ele-upload__area--text\">\n <div class=\"ele-upload__message\" v-if=\"message\" v-html=\"message\"></div>\n <div class=\"ele-upload__message\" v-else>单击或拖动文件到该区域以上传</div>\n <div class=\"ele-upload__ext\" v-if=\"ext\" v-html=\"ext\"></div>\n <div class=\"ele-upload__ext\" v-else>文件小于{{ size }}M</div>\n </div>\n </section>\n </FileUpload>\n <section class=\"ele-files__wrapper\">\n <!-- 显示正在上传的文件(有进度条) -->\n <div class=\"ele-file__item\" v-for=\"(file, idx) in uploadingFiles\" :key=\"`uploading-${idx}`\">\n <div class=\"ele-file__suffix--icon\">\n <ele-icon :type=\"fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'\"></ele-icon>\n </div>\n <div class=\"ele-file__name\">\n <div class=\"ele-file__inner\">{{ file.name }}</div>\n <div v-if=\"file.progress !== undefined\" class=\"ele-uplpad__progress\">\n <a-progress :strokeWidth=\"2\" :percent=\"Number(file.progress)\" size=\"small\" />\n </div>\n </div>\n <div class=\"ele-file__delete\" v-if=\"file.success || file.error\">\n <span class=\"ele-file__size\">{{ (file.size / byteConversion).toFixed(2) }}M</span>\n <span class=\"ele-file__delete--icon\" @click=\"handleClickDelete(file)\">\n <ele-icon type=\"delete\"></ele-icon>\n </span>\n </div>\n </div>\n \n <!-- 显示已上传完成的文件 -->\n <div class=\"ele-file__item\" v-for=\"(file, idx) in completedFiles\" :key=\"`completed-${idx}`\">\n <div class=\"ele-file__suffix--icon\">\n <ele-icon :type=\"fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'\"></ele-icon>\n </div>\n <div class=\"ele-file__name\">\n <div class=\"ele-file__inner\" @click=\"handleClickDownload(file)\">{{ file.name }}</div>\n </div>\n <div class=\"ele-file__delete\">\n <span class=\"ele-file__size\">{{ (file.size / byteConversion).toFixed(2) }}M</span>\n <span class=\"ele-file__delete--icon\" @click=\"handleClickDelete(file)\">\n <ele-icon type=\"delete\"></ele-icon>\n </span>\n </div>\n </div>\n </section>\n </div>\n</template>\n\n<script>\nimport FileUpload from 'vue-upload-component'\nimport { v4 as uuidv4 } from 'uuid'\nimport { route, net, type } from '@idooel/shared'\n\n// 常量定义\nconst CONSTANTS = {\n DEFAULT_URL: 'zuul/api-file/workbench/file',\n DEFAULT_ICON: '上传',\n DEFAULT_SIZE: 100,\n DEFAULT_MESSAGE: '单击或拖动文件到该区域以上传',\n DEFAULT_MAXIMUM: 20,\n BYTE_CONVERSION: 1024 * 1024,\n CHUNK_MIN_SIZE: 3 * 1024 * 1024,\n CHUNK_MAX_ACTIVE: 3,\n CHUNK_MAX_RETRIES: 5,\n SAVE_INTERVAL: 2000\n}\n\n// 文件后缀图标映射\nconst FILE_SUFFIX_ICONS = {\n 'doc': { name: 'icon-doc' },\n 'html': { name: 'icon-html' },\n 'mp4': { name: 'icon-mp' },\n 'pdf': { name: 'icon-pdf' },\n 'ppt': { name: 'icon-ppt' },\n 'psd': { name: 'icon-psd' },\n 'rtf': { name: 'icon-rtf' },\n 'txt': { name: 'icon-txt' },\n 'vis': { name: 'icon-vis' },\n 'xls': { name: 'icon-xls' },\n 'xml': { name: 'icon-xml' },\n 'zip': { name: 'icon-zip' },\n 'jpg': { name: 'icon-img' },\n 'mp3': { name: 'icon-mp1' }\n}\n\nexport default {\n name: 'ele-upload',\n components: {\n FileUpload\n },\n model: {\n prop: 'value',\n event: 'change'\n },\n props: {\n url: {\n type: String,\n default: CONSTANTS.DEFAULT_URL\n },\n icon: {\n type: String,\n default: CONSTANTS.DEFAULT_ICON\n },\n size: {\n type: Number,\n default: CONSTANTS.DEFAULT_SIZE\n },\n message: {\n type: String,\n default: CONSTANTS.DEFAULT_MESSAGE\n },\n ext: {\n type: String\n },\n extensions: {\n type: String\n },\n accept: {\n type: String\n },\n maximum: {\n type: Number,\n default: CONSTANTS.DEFAULT_MAXIMUM\n },\n multiple: {\n type: Boolean,\n default: false\n },\n drop: {\n type: Boolean,\n default: true\n },\n value: {\n type: [String, Array]\n },\n querys: {\n type: Object,\n default: () => ({\n _csrf: localStorage.getItem('token'),\n _t: new Date().valueOf()\n })\n },\n headers: {\n type: Object,\n default: () => ({\n 'X-XSRF-TOKEN': localStorage.getItem('token')\n })\n },\n byteConversion: {\n type: Number,\n default: CONSTANTS.BYTE_CONVERSION\n },\n chunkEnabled: {\n type: Boolean,\n default: true\n }\n },\n data() {\n return {\n // 文件状态管理\n files: [], // vue-upload-component 管理的文件\n buildedFiles: [], // 已构建完成的文件列表\n \n // 上传状态管理\n saveToServerAsyncPageTimer: null,\n uploadRefId: null,\n groupId: null\n }\n },\n created() {\n // 多文件模式下,如果没有外部 groupId,则生成一个\n if (this.multiple && !this.value) {\n this.groupId = uuidv4()\n console.log('Created with new groupId:', this.groupId)\n }\n },\n watch: {\n value: {\n async handler(value) {\n console.log('watch.value triggered:', { value, multiple: this.multiple, currentGroupId: this.groupId })\n \n if (type.isEmpty(value)) {\n this.resetFiles()\n } else if (this.multiple) {\n this.handleMultipleFileValue(value)\n } else {\n this.handleSingleFileValue()\n }\n },\n immediate: true\n }\n },\n computed: {\n // ==================== 基础配置 ====================\n prefixPath() {\n return window.prefixPath\n },\n \n uploadRef() {\n if (!this.uploadRefId) {\n this.uploadRefId = `uploadRef_${uuidv4()}`\n }\n return this.uploadRefId\n },\n \n iconIsZhWord() {\n return type.isZhWord(this.icon)\n },\n \n // ==================== 上传配置 ====================\n uploadParams() {\n return this.multiple ? { groupID: this.groupId } : {}\n },\n \n fileSizeLimit() {\n return this.size * this.byteConversion\n },\n \n postAction() {\n const queryString = route.toQueryString(this.querys)\n return `${this.prefixPath}${this.url}?${queryString}`\n },\n \n chunkConfig() {\n return {\n action: `${this.prefixPath}zuul/api-file/workbench/file/temp/chunk/vue`,\n headers: { ...this.headers },\n minSize: CONSTANTS.CHUNK_MIN_SIZE,\n maxActive: CONSTANTS.CHUNK_MAX_ACTIVE,\n maxRetries: CONSTANTS.CHUNK_MAX_RETRIES,\n startBody: { override: true, path: '/cw' },\n uploadBody: { override: true, path: '/cw' },\n finishBody: { override: true, path: '/cw' }\n }\n },\n \n getMaximum() {\n return this.multiple ? this.maximum : 1\n },\n \n // ==================== 文件状态 ====================\n uploadingFiles() {\n return this.files.filter(file => file.progress !== undefined && !file.success)\n },\n \n completedFiles() {\n return this.buildedFiles.filter(file => file.fileID)\n },\n \n totalFiles() {\n return this.uploadingFiles.length + this.completedFiles.length\n },\n \n isFileUploadSuccessed() {\n const currentUploadingFiles = this.files.filter(file => file.response !== undefined)\n if (currentUploadingFiles.length === 0) {\n return this.buildedFiles.length > 0\n }\n return currentUploadingFiles.every(file => file.success)\n },\n \n isShowUploadContainer() {\n const maxFiles = this.multiple ? this.maximum : 1\n return this.totalFiles < maxFiles\n },\n \n // ==================== 文件信息 ====================\n fileSuffixIcon() {\n return FILE_SUFFIX_ICONS\n },\n \n fileIds() {\n if (this.multiple) {\n return this.groupId\n } else {\n const fileIds = this.buildedFiles.map(file => file.fileID)\n return fileIds[0]\n }\n },\n \n fileResponseData() {\n return this.multiple ? this.buildedFiles : this.buildedFiles[0]\n }\n },\n methods: {\n // ==================== 文件管理 ====================\n \n /**\n * 从多个数组中移除文件\n */\n removeFromArrays(file, arrays, key = 'fileID') {\n return arrays.map(arr => \n arr.filter(item => item[key] !== file[key] && item.id !== file.id)\n )\n },\n \n /**\n * 检查文件是否为新文件\n */\n isNewFile(newFile, existingFiles, key = 'fileID') {\n return newFile[key] && !existingFiles.some(existing => existing[key] === newFile[key])\n },\n \n /**\n * 合并文件数据\n */\n mergeFileData(uploadFile) {\n return {\n ...uploadFile.response.data,\n ...uploadFile\n }\n },\n \n /**\n * 初始化文件列表\n */\n async initializeFiles() {\n if (!this.value) return\n \n if (this.multiple) {\n await this.fetchFilesWithGroupId()\n } else {\n await this.fetchFileWithFileId()\n }\n },\n \n /**\n * 获取多文件组\n */\n async fetchFilesWithGroupId() {\n try {\n const response = await net.get(`/api-file/workbench/file/group/${this.value}`)\n const data = response.data || []\n \n // 只有在没有现有文件时才设置初始文件列表\n if (this.buildedFiles.length === 0) {\n this.buildedFiles = data\n console.log('Initial files loaded:', this.buildedFiles.length)\n } else {\n console.log('Keep existing files, skip initial load')\n }\n } catch (error) {\n console.log('fetchFilesWithGroupId error:', error)\n console.log('Keep current files, do not clear due to API error')\n }\n },\n \n /**\n * 获取单文件\n */\n async fetchFileWithFileId() {\n try {\n const response = await net.get(`/api-file/file/${this.value}`)\n const data = response.data\n this.buildedFiles = [data]\n this.files = [data]\n } catch (error) {\n console.log('fetchFileWithFileId error:', error)\n }\n },\n \n /**\n * 处理文件删除\n */\n handleClickDelete(file) {\n const { fileID } = file\n console.log('Deleting file:', { name: file.name, fileID })\n \n // 从上传组件中移除文件\n if (this.$refs[this.uploadRef]) {\n this.$refs[this.uploadRef].remove(file)\n }\n \n // 从所有数组中移除文件\n [this.files, this.buildedFiles] = this.removeFromArrays(file, [this.files, this.buildedFiles])\n \n console.log('After deletion - files:', this.files.length, 'buildedFiles:', this.buildedFiles.length)\n \n // 多文件模式下,如果删除最后一个文件,重置 groupId\n if (this.multiple && this.buildedFiles.length === 0) {\n this.groupId = null\n console.log('Reset groupId after deleting last file')\n }\n \n // 触发 change 事件\n this.$emit('change', this.fileIds)\n },\n \n /**\n * 处理文件下载\n */\n handleClickDownload(file) {\n const { fileID: fileId } = file\n window.open(`/api-file/workbench/file/stream/${fileId}?origin=true`)\n },\n // ==================== 上传处理 ====================\n \n /**\n * 处理文件上传状态变化\n */\n onWatchFiles(files) {\n console.log('onWatchFiles called with files:', files.length)\n console.log('Current buildedFiles:', this.buildedFiles.length)\n \n // 更新文件状态\n this.files = files\n \n // 处理已上传成功的文件\n this.processUploadedFiles(files)\n \n // 检查上传是否完成\n if (this.isFileUploadSuccessed) {\n this.$emit('change', this.fileIds)\n this.$emit('on-success', this.fileResponseData)\n }\n },\n \n /**\n * 处理已上传成功的文件\n */\n processUploadedFiles(files) {\n // 处理所有有响应的文件(包括正在上传和已完成的)\n const uploadedFiles = files.filter(file => file.response)\n const newBuildedFiles = uploadedFiles.map(file => this.mergeFileData(file))\n \n if (this.multiple) {\n this.processMultipleFiles(newBuildedFiles)\n } else {\n // 单文件模式:只保留最新的文件\n this.buildedFiles = newBuildedFiles\n }\n \n this.logFileStatus()\n },\n \n /**\n * 处理多文件模式\n */\n processMultipleFiles(newBuildedFiles) {\n // 获取已存在的文件ID集合\n const existingFileIds = new Set(this.buildedFiles.map(f => f.fileID).filter(id => id))\n \n // 过滤出真正的新文件\n const trulyNewFiles = newBuildedFiles.filter(newFile => \n this.isNewFile(newFile, this.buildedFiles)\n )\n \n console.log('Existing fileIDs:', Array.from(existingFileIds))\n console.log('New uploaded files:', newBuildedFiles.map(f => ({ name: f.name, fileID: f.fileID })))\n console.log('Truly new files:', trulyNewFiles.map(f => ({ name: f.name, fileID: f.fileID })))\n \n // 将新文件追加到现有文件列表\n if (trulyNewFiles.length > 0) {\n this.buildedFiles = [...this.buildedFiles, ...trulyNewFiles]\n console.log('Added new files, total buildedFiles:', this.buildedFiles.length)\n }\n \n // 更新现有文件的状态(包括新添加的文件)\n this.updateExistingFiles(newBuildedFiles)\n },\n \n /**\n * 更新现有文件状态\n */\n updateExistingFiles(newBuildedFiles) {\n this.buildedFiles = this.buildedFiles.map(existingFile => {\n const updatedFile = newBuildedFiles.find(newFile => newFile.fileID === existingFile.fileID)\n return updatedFile ? { ...existingFile, ...updatedFile } : existingFile\n })\n },\n \n /**\n * 记录文件状态日志\n */\n logFileStatus() {\n console.log('Final buildedFiles:', this.buildedFiles.length)\n console.log('buildedFiles details:', this.buildedFiles.map(f => ({ name: f.name, fileID: f.fileID, success: f.success })))\n console.log('Uploading files:', this.uploadingFiles.length)\n console.log('Completed files:', this.completedFiles.length)\n },\n // ==================== 异步处理 ====================\n \n /**\n * 异步保存文件到服务器\n */\n async saveToServerAsyncPage(payloads = {}) {\n try {\n const response = await net.post('zuul/api-file/workbench/file/temp/saveToServerAsyncPage', payloads, { \n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'\n }\n })\n \n const { data } = response\n if (data !== 'saveToServerAsyncPage') {\n clearInterval(this.saveToServerAsyncPageTimer)\n }\n } catch (error) {\n console.error('saveToServerAsyncPage error:', error)\n clearInterval(this.saveToServerAsyncPageTimer)\n }\n },\n \n // ==================== 文件验证 ====================\n \n /**\n * 验证文件类型\n */\n validateFileType(file) {\n if (!file || !file.name) {\n console.log('文件或文件名不存在')\n return false\n }\n \n const fileExt = this.getFileExtension(file.name)\n console.log('文件扩展名:', fileExt)\n \n if (this.extensions) {\n const allowedExts = this.getAllowedExtensions()\n console.log('允许的扩展名:', allowedExts)\n \n if (!allowedExts.includes(fileExt)) {\n console.log('扩展名不在允许列表中')\n this.$message.error(`不支持的文件类型 \"${fileExt}\",请上传 ${this.extensions} 格式的文件`)\n return false\n }\n }\n \n console.log('文件类型验证通过')\n return true\n },\n \n /**\n * 获取文件扩展名\n */\n getFileExtension(fileName) {\n return fileName.toLowerCase().substring(fileName.lastIndexOf('.'))\n },\n \n /**\n * 获取允许的扩展名列表\n */\n getAllowedExtensions() {\n return this.extensions.toLowerCase()\n .split(',')\n .map(ext => ext.trim().startsWith('.') ? ext.trim() : `.${ext.trim()}`)\n },\n // ==================== 事件处理 ====================\n \n /**\n * 处理文件输入事件\n */\n onWatchInputFiles(newFile, oldFile) {\n if (newFile && !oldFile) {\n this.handleFileAdd(newFile)\n } else if (newFile && oldFile) {\n this.handleFileUpdate(newFile)\n } else if (!newFile && oldFile) {\n this.handleFileDelete()\n }\n \n // 激活上传组件\n this.activateUploadComponent(newFile, oldFile)\n },\n \n /**\n * 处理文件添加\n */\n handleFileAdd(newFile) {\n console.log('add file:', newFile)\n console.log('extensions:', this.extensions)\n console.log('accept:', this.accept)\n \n // 生成或使用 groupId\n this.ensureGroupId()\n \n // 验证文件类型\n if (!this.validateFileType(newFile)) {\n this.removeInvalidFile(newFile)\n return\n }\n \n console.log('文件类型验证通过,继续上传')\n },\n \n /**\n * 处理文件更新\n */\n handleFileUpdate(newFile) {\n console.log('update', newFile)\n const { success, active, chunk, response } = newFile\n \n if (chunk && success && !active) {\n console.log('chunk end')\n this.handleChunkComplete(response)\n }\n },\n \n /**\n * 处理文件删除\n */\n handleFileDelete() {\n console.log('delete')\n },\n \n /**\n * 确保 groupId 存在\n */\n ensureGroupId() {\n console.log('onWatchInputFiles - multiple:', this.multiple, 'current groupId:', this.groupId)\n \n if (this.multiple && !this.groupId) {\n this.groupId = uuidv4()\n console.log('Generated new groupId:', this.groupId)\n } else if (this.multiple && this.groupId) {\n console.log('Using existing groupId:', this.groupId)\n }\n },\n \n /**\n * 移除无效文件\n */\n removeInvalidFile(file) {\n console.log('文件类型验证失败,尝试移除文件')\n console.log('uploadRef:', this.uploadRef)\n console.log('$refs:', this.$refs)\n \n if (this.$refs[this.uploadRef]) {\n this.$refs[this.uploadRef].remove(file)\n } else {\n console.error('无法找到 uploadRef 引用')\n }\n },\n \n /**\n * 处理分片上传完成\n */\n handleChunkComplete(response) {\n const { data: { file, type } } = response\n const payloads = {\n filePath: file.match(/\\/cw(.*)/) ? file.match(/\\/cw(.*)/)[0] : void 0,\n asyncID: uuidv4(),\n isDeleteOrigin: false,\n toImage: type === 'pdf',\n unzip: type === 'zip',\n _csrf: localStorage.getItem('token')\n }\n \n this.saveToServerAsyncPageTimer = setInterval(() => {\n this.saveToServerAsyncPage(payloads)\n }, CONSTANTS.SAVE_INTERVAL)\n },\n \n /**\n * 激活上传组件\n */\n activateUploadComponent(newFile, oldFile) {\n if (Boolean(newFile) !== Boolean(oldFile) || oldFile.error !== newFile.error) {\n if (!this.$refs[this.uploadRef].active) {\n this.$refs[this.uploadRef].active = true\n }\n }\n },\n \n // ==================== 值变化处理 ====================\n \n /**\n * 重置文件状态\n */\n resetFiles() {\n this.files = []\n this.buildedFiles = []\n this.groupId = null\n console.log('Reset groupId to null')\n },\n \n /**\n * 处理多文件模式的值变化\n */\n async handleMultipleFileValue(value) {\n // multiple - value 就是 groupId\n // 只有当 groupId 发生变化时才重新获取文件列表(初始化回显)\n if (this.groupId !== value) {\n this.groupId = value\n console.log('Set groupId from external value:', this.groupId)\n await this.fetchFilesWithGroupId()\n } else {\n console.log('GroupId unchanged, skip fetchFilesWithGroupId')\n }\n },\n \n /**\n * 处理单文件模式的值变化\n */\n async handleSingleFileValue() {\n await this.fetchFileWithFileId()\n }\n }\n}\n</script>\n\n<style lang=\"scss\" scoped>\n::v-deep .ele-upload__inner {\n opacity: 1 !important;\n cursor: pointer;\n border: 1px dashed var(--idooel-form-title-border-color);\n background: var(--idooel-form-upload-bg-color) !important;\n &:hover {\n border-color: var(--idooel-form-upload-border-hover-color);\n }\n border-radius: var(--idooel-form-border-radius);\n}\n.ele-upload__wrapper {\n width: 100%;\n .ele-upload__area {\n padding: 16px;\n width: 100%;\n height: 80px;\n display: flex;\n flex-direction: row;\n .ele-upload__area--icon {\n color: var(--idooel-primary-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n font-size: 16x;\n .anticon-cloud-upload {\n font-size: 48px;\n color: var(--idooel-primary-color);\n }\n .anticon {\n font-size: 48px;\n color: var(--idooel-primary-color);\n }\n }\n .ele-upload__area--text {\n margin-left: 16px;\n .ele-upload__message {\n font-size: 16px;\n color: var(--idoole-black-088);\n text-align: left;\n }\n .ele-upload__ext {\n text-align: left;\n font-size: 14px;\n color: var(--idoole-black-06);\n }\n }\n }\n .ele-files__wrapper {\n .ele-file__item {\n width: 100%;\n margin-top: 8px;\n padding: 8px 12px;\n border-radius: var(--idooel-form-border-radius);\n background: var(--idooel-form-upload-bg-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n .ele-file__suffix--icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n }\n .ele-file__name {\n flex: 1;\n text-align: left;\n white-space: nowrap;\n overflow: hidden;\n font-size: 14px;\n margin-left: 8px;\n cursor: pointer;\n .ele-file__inner {\n overflow: hidden;\n text-overflow: ellipsis;\n }\n }\n .ele-file__delete {\n margin-left: 8px;\n .ele-file__delete--icon {\n margin-left: 8px;\n cursor: pointer;\n }\n }\n }\n }\n}\n</style>","::v-deep .ele-upload__inner {\n opacity: 1 !important;\n cursor: pointer;\n border: 1px dashed var(--idooel-form-title-border-color);\n background: var(--idooel-form-upload-bg-color) !important;\n border-radius: var(--idooel-form-border-radius);\n}\n::v-deep .ele-upload__inner:hover {\n border-color: var(--idooel-form-upload-border-hover-color);\n}\n\n.ele-upload__wrapper {\n width: 100%;\n}\n.ele-upload__wrapper .ele-upload__area {\n padding: 16px;\n width: 100%;\n height: 80px;\n display: flex;\n flex-direction: row;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon {\n color: var(--idooel-primary-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n font-size: 16x;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon .anticon-cloud-upload {\n font-size: 48px;\n color: var(--idooel-primary-color);\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon .anticon {\n font-size: 48px;\n color: var(--idooel-primary-color);\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text {\n margin-left: 16px;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text .ele-upload__message {\n font-size: 16px;\n color: var(--idoole-black-088);\n text-align: left;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text .ele-upload__ext {\n text-align: left;\n font-size: 14px;\n color: var(--idoole-black-06);\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item {\n width: 100%;\n margin-top: 8px;\n padding: 8px 12px;\n border-radius: var(--idooel-form-border-radius);\n background: var(--idooel-form-upload-bg-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__suffix--icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__name {\n flex: 1;\n text-align: left;\n white-space: nowrap;\n overflow: hidden;\n font-size: 14px;\n margin-left: 8px;\n cursor: pointer;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__name .ele-file__inner {\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__delete {\n margin-left: 8px;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__delete .ele-file__delete--icon {\n margin-left: 8px;\n cursor: pointer;\n}\n\n/*# sourceMappingURL=index.vue.map */"]}, media: undefined });
|
|
6598
|
+
inject("data-v-48a2255a_0", { source: "[data-v-48a2255a] .ele-upload__inner {\n opacity: 1 !important;\n cursor: pointer;\n border: 1px dashed var(--idooel-form-title-border-color);\n background: var(--idooel-form-upload-bg-color) !important;\n border-radius: var(--idooel-form-border-radius);\n}\n[data-v-48a2255a] .ele-upload__inner:hover {\n border-color: var(--idooel-form-upload-border-hover-color);\n}\n.ele-upload__wrapper[data-v-48a2255a] {\n width: 100%;\n}\n.ele-upload__wrapper .ele-upload__area[data-v-48a2255a] {\n padding: 16px;\n width: 100%;\n height: 80px;\n display: flex;\n flex-direction: row;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon[data-v-48a2255a] {\n color: var(--idooel-primary-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n font-size: 16x;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon .anticon-cloud-upload[data-v-48a2255a] {\n font-size: 48px;\n color: var(--idooel-primary-color);\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon .anticon[data-v-48a2255a] {\n font-size: 48px;\n color: var(--idooel-primary-color);\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text[data-v-48a2255a] {\n margin-left: 16px;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text .ele-upload__message[data-v-48a2255a] {\n font-size: 16px;\n color: var(--idoole-black-088);\n text-align: left;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text .ele-upload__ext[data-v-48a2255a] {\n text-align: left;\n font-size: 14px;\n color: var(--idoole-black-06);\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item[data-v-48a2255a] {\n width: 100%;\n margin-top: 8px;\n padding: 8px 12px;\n border-radius: var(--idooel-form-border-radius);\n background: var(--idooel-form-upload-bg-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__suffix--icon[data-v-48a2255a] {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__name[data-v-48a2255a] {\n flex: 1;\n text-align: left;\n white-space: nowrap;\n overflow: hidden;\n font-size: 14px;\n margin-left: 8px;\n cursor: pointer;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__name .ele-file__inner[data-v-48a2255a] {\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__delete[data-v-48a2255a] {\n margin-left: 8px;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__delete .ele-file__delete--icon[data-v-48a2255a] {\n margin-left: 8px;\n cursor: pointer;\n}\n\n/*# sourceMappingURL=index.vue.map */", map: {"version":3,"sources":["/Users/huangshan/Goldgov/GanJiao/base-elearning-frontend-model/packages/components/packages/upload/src/index.vue","index.vue"],"names":[],"mappings":"AAmuBA;EACA,qBAAA;EACA,eAAA;EACA,wDAAA;EACA,yDAAA;EAIA,+CAAA;ACruBA;ADkuBA;EACA,0DAAA;AChuBA;ADouBA;EACA,WAAA;ACjuBA;ADkuBA;EACA,aAAA;EACA,WAAA;EACA,YAAA;EACA,aAAA;EACA,mBAAA;AChuBA;ADiuBA;EACA,kCAAA;EACA,aAAA;EACA,mBAAA;EACA,mBAAA;EACA,cAAA;AC/tBA;ADguBA;EACA,eAAA;EACA,kCAAA;AC9tBA;ADguBA;EACA,eAAA;EACA,kCAAA;AC9tBA;ADiuBA;EACA,iBAAA;AC/tBA;ADguBA;EACA,eAAA;EACA,8BAAA;EACA,gBAAA;AC9tBA;ADguBA;EACA,gBAAA;EACA,eAAA;EACA,6BAAA;AC9tBA;ADmuBA;EACA,WAAA;EACA,eAAA;EACA,iBAAA;EACA,+CAAA;EACA,8CAAA;EACA,aAAA;EACA,mBAAA;EACA,mBAAA;ACjuBA;ADkuBA;EACA,aAAA;EACA,mBAAA;EACA,uBAAA;EACA,WAAA;EACA,YAAA;AChuBA;ADkuBA;EACA,OAAA;EACA,gBAAA;EACA,mBAAA;EACA,gBAAA;EACA,eAAA;EACA,gBAAA;EACA,eAAA;AChuBA;ADiuBA;EACA,gBAAA;EACA,uBAAA;AC/tBA;ADkuBA;EACA,gBAAA;AChuBA;ADiuBA;EACA,gBAAA;EACA,eAAA;AC/tBA;;AAEA,oCAAoC","file":"index.vue","sourcesContent":["<template>\n <div class=\"ele-upload__wrapper\">\n <FileUpload\n class=\"ele-upload__inner\"\n v-show=\"isShowUploadContainer\"\n v-model=\"files\"\n :ref=\"uploadRef\"\n :drop=\"drop\"\n :chunk-enabled=\"chunkEnabled\"\n :chunk=\"chunkConfig\"\n :accept=\"accept\"\n :size=\"fileSizeLimit\"\n :post-action=\"postAction\"\n :multiple=\"multiple\"\n :headers=\"headers\"\n :maximum=\"getMaximum\"\n :data=\"uploadParams\"\n @input-file=\"onWatchInputFiles\"\n @input=\"onWatchFiles\"\n style=\"width: 100%;\">\n <section class=\"ele-upload__area\">\n <div class=\"ele-upload__area--icon\">\n <template v-if=\"iconIsZhWrod\">\n {{ icon }}\n </template>\n <template v-else>\n <ele-icon :type=\"icon\"></ele-icon>\n </template>\n </div>\n <div class=\"ele-upload__area--text\">\n <div class=\"ele-upload__message\" v-if=\"message\" v-html=\"message\"></div>\n <div class=\"ele-upload__message\" v-else>单击或拖动文件到该区域以上传</div>\n <div class=\"ele-upload__ext\" v-if=\"ext\" v-html=\"ext\"></div>\n <div class=\"ele-upload__ext\" v-else>文件小于{{ size }}M</div>\n </div>\n </section>\n </FileUpload>\n <section class=\"ele-files__wrapper\">\n <!-- 显示正在上传的文件(有进度条) -->\n <div class=\"ele-file__item\" v-for=\"(file, idx) in uploadingFiles\" :key=\"`uploading-${idx}`\">\n <div class=\"ele-file__suffix--icon\">\n <ele-icon :type=\"fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'\"></ele-icon>\n </div>\n <div class=\"ele-file__name\">\n <div class=\"ele-file__inner\">{{ file.name }}</div>\n <div v-if=\"file.progress !== undefined\" class=\"ele-uplpad__progress\">\n <a-progress :strokeWidth=\"2\" :percent=\"Number(file.progress)\" size=\"small\" />\n </div>\n </div>\n <div class=\"ele-file__delete\" v-if=\"file.success || file.error\">\n <span class=\"ele-file__size\">{{ (file.size / byteConversion).toFixed(2) }}M</span>\n <span class=\"ele-file__delete--icon\" @click=\"handleClickDelete(file)\">\n <ele-icon type=\"delete\"></ele-icon>\n </span>\n </div>\n </div>\n \n <!-- 显示已上传完成的文件 -->\n <div class=\"ele-file__item\" v-for=\"(file, idx) in completedFiles\" :key=\"`completed-${idx}`\">\n <div class=\"ele-file__suffix--icon\">\n <ele-icon :type=\"fileSuffixIcon[file.suffix] ? fileSuffixIcon[file.suffix].name : 'icon-file'\"></ele-icon>\n </div>\n <div class=\"ele-file__name\">\n <div class=\"ele-file__inner\" @click=\"handleClickDownload(file)\">{{ file.name }}</div>\n </div>\n <div class=\"ele-file__delete\">\n <span class=\"ele-file__size\">{{ (file.size / byteConversion).toFixed(2) }}M</span>\n <span class=\"ele-file__delete--icon\" @click=\"handleClickDelete(file)\">\n <ele-icon type=\"delete\"></ele-icon>\n </span>\n </div>\n </div>\n </section>\n </div>\n</template>\n\n<script>\nimport FileUpload from 'vue-upload-component'\nimport { v4 as uuidv4 } from 'uuid'\nimport { route, net, type } from '@idooel/shared'\n\n// 常量定义\nconst CONSTANTS = {\n DEFAULT_URL: 'zuul/api-file/workbench/file',\n DEFAULT_ICON: '上传',\n DEFAULT_SIZE: 100,\n DEFAULT_MESSAGE: '单击或拖动文件到该区域以上传',\n DEFAULT_MAXIMUM: 20,\n BYTE_CONVERSION: 1024 * 1024,\n CHUNK_MIN_SIZE: 3 * 1024 * 1024,\n CHUNK_MAX_ACTIVE: 3,\n CHUNK_MAX_RETRIES: 5,\n SAVE_INTERVAL: 2000\n}\n\n// 文件后缀图标映射\nconst FILE_SUFFIX_ICONS = {\n 'doc': { name: 'icon-doc' },\n 'html': { name: 'icon-html' },\n 'mp4': { name: 'icon-mp' },\n 'pdf': { name: 'icon-pdf' },\n 'ppt': { name: 'icon-ppt' },\n 'psd': { name: 'icon-psd' },\n 'rtf': { name: 'icon-rtf' },\n 'txt': { name: 'icon-txt' },\n 'vis': { name: 'icon-vis' },\n 'xls': { name: 'icon-xls' },\n 'xml': { name: 'icon-xml' },\n 'zip': { name: 'icon-zip' },\n 'jpg': { name: 'icon-img' },\n 'mp3': { name: 'icon-mp1' }\n}\n\nexport default {\n name: 'ele-upload',\n components: {\n FileUpload\n },\n model: {\n prop: 'value',\n event: 'change'\n },\n props: {\n url: {\n type: String,\n default: CONSTANTS.DEFAULT_URL\n },\n icon: {\n type: String,\n default: CONSTANTS.DEFAULT_ICON\n },\n size: {\n type: Number,\n default: CONSTANTS.DEFAULT_SIZE\n },\n message: {\n type: String,\n default: CONSTANTS.DEFAULT_MESSAGE\n },\n ext: {\n type: String\n },\n extensions: {\n type: String\n },\n accept: {\n type: String\n },\n maximum: {\n type: Number,\n default: CONSTANTS.DEFAULT_MAXIMUM\n },\n multiple: {\n type: Boolean,\n default: false\n },\n drop: {\n type: Boolean,\n default: true\n },\n value: {\n type: [String, Array]\n },\n querys: {\n type: Object,\n default: () => ({\n _csrf: localStorage.getItem('token'),\n _t: new Date().valueOf()\n })\n },\n headers: {\n type: Object,\n default: () => ({\n 'X-XSRF-TOKEN': localStorage.getItem('token')\n })\n },\n byteConversion: {\n type: Number,\n default: CONSTANTS.BYTE_CONVERSION\n },\n chunkEnabled: {\n type: Boolean,\n default: true\n }\n },\n data() {\n return {\n // 文件状态管理\n files: [], // vue-upload-component 管理的文件\n buildedFiles: [], // 已构建完成的文件列表\n \n // 上传状态管理\n saveToServerAsyncPageTimer: null,\n uploadRefId: null,\n // 多选且外部无值时,预先生成 groupId,确保首次上传参数完整\n groupId: (this.multiple && !this.value) ? uuidv4() : null\n }\n },\n created() {\n // 多文件模式下,如果没有外部 groupId,则生成一个\n if (this.multiple && !this.value) {\n this.groupId = uuidv4()\n console.log('Created with new groupId:', this.groupId)\n }\n },\n watch: {\n value: {\n async handler(value) {\n if (type.isEmpty(value)) {\n this.resetFiles()\n } else if (this.multiple) {\n this.handleMultipleFileValue(value)\n } else {\n this.handleSingleFileValue()\n }\n },\n immediate: true\n }\n },\n computed: {\n // ==================== 基础配置 ====================\n prefixPath() {\n return window.prefixPath\n },\n \n uploadRef() {\n if (!this.uploadRefId) {\n this.uploadRefId = `uploadRef_${uuidv4()}`\n }\n return this.uploadRefId\n },\n \n iconIsZhWord() {\n return type.isZhWord(this.icon)\n },\n \n // ==================== 上传配置 ====================\n uploadParams() {\n return this.multiple ? { groupID: this.groupId } : {}\n },\n \n fileSizeLimit() {\n return this.size * this.byteConversion\n },\n \n postAction() {\n const queryString = route.toQueryString(this.querys)\n return `${this.prefixPath}${this.url}?${queryString}`\n },\n \n chunkConfig() {\n return {\n action: `${this.prefixPath}zuul/api-file/workbench/file/temp/chunk/vue`,\n headers: { ...this.headers },\n minSize: CONSTANTS.CHUNK_MIN_SIZE,\n maxActive: CONSTANTS.CHUNK_MAX_ACTIVE,\n maxRetries: CONSTANTS.CHUNK_MAX_RETRIES,\n startBody: { override: true, path: '/cw' },\n uploadBody: { override: true, path: '/cw' },\n finishBody: { override: true, path: '/cw' }\n }\n },\n \n getMaximum() {\n return this.multiple ? this.maximum : 1\n },\n \n // ==================== 文件状态 ====================\n uploadingFiles() {\n return this.files.filter(file => file.progress !== undefined && !file.success)\n },\n \n completedFiles() {\n return this.buildedFiles.filter(file => file.fileID)\n },\n \n totalFiles() {\n return this.uploadingFiles.length + this.completedFiles.length\n },\n \n isFileUploadSuccessed() {\n const currentUploadingFiles = this.files.filter(file => file.response !== undefined)\n if (currentUploadingFiles.length === 0) {\n return this.buildedFiles.length > 0\n }\n return currentUploadingFiles.every(file => file.success)\n },\n \n isShowUploadContainer() {\n const maxFiles = this.multiple ? this.maximum : 1\n return this.totalFiles < maxFiles\n },\n \n // ==================== 文件信息 ====================\n fileSuffixIcon() {\n return FILE_SUFFIX_ICONS\n },\n \n fileIds() {\n if (this.multiple) {\n return this.groupId\n } else {\n const fileIds = this.buildedFiles.map(file => file.fileID)\n return fileIds[0]\n }\n },\n \n fileResponseData() {\n return this.multiple ? this.buildedFiles : this.buildedFiles[0]\n }\n },\n methods: {\n // ==================== 文件管理 ====================\n \n /**\n * 从多个数组中移除文件\n */\n removeFromArrays(file, arrays, key = 'fileID') {\n return arrays.map(arr => \n arr.filter(item => item[key] !== file[key] && item.id !== file.id)\n )\n },\n \n /**\n * 检查文件是否为新文件\n */\n isNewFile(newFile, existingFiles, key = 'fileID') {\n return newFile[key] && !existingFiles.some(existing => existing[key] === newFile[key])\n },\n \n /**\n * 合并文件数据\n */\n mergeFileData(uploadFile) {\n return {\n ...uploadFile.response.data,\n ...uploadFile\n }\n },\n \n /**\n * 初始化文件列表\n */\n async initializeFiles() {\n if (!this.value) return\n \n if (this.multiple) {\n await this.fetchFilesWithGroupId()\n } else {\n await this.fetchFileWithFileId()\n }\n },\n \n /**\n * 获取多文件组\n */\n async fetchFilesWithGroupId() {\n try {\n const response = await net.get(`/api-file/workbench/file/group/${this.value}`)\n const data = response.data || []\n \n // 只有在没有现有文件时才设置初始文件列表\n if (this.buildedFiles.length === 0) {\n this.buildedFiles = data\n console.log('Initial files loaded:', this.buildedFiles.length)\n } else {\n console.log('Keep existing files, skip initial load')\n }\n } catch (error) {\n console.log('fetchFilesWithGroupId error:', error)\n console.log('Keep current files, do not clear due to API error')\n }\n },\n \n /**\n * 获取单文件\n */\n async fetchFileWithFileId() {\n try {\n const response = await net.get(`/api-file/file/${this.value}`)\n const data = response.data\n this.buildedFiles = [data]\n this.files = [data]\n } catch (error) {\n console.log('fetchFileWithFileId error:', error)\n }\n },\n \n /**\n * 处理文件删除\n */\n handleClickDelete(file) {\n const { fileID } = file\n console.log('Deleting file:', { name: file.name, fileID })\n \n // 从上传组件中移除文件\n if (this.$refs[this.uploadRef]) {\n this.$refs[this.uploadRef].remove(file)\n }\n \n // 从所有数组中移除文件\n [this.files, this.buildedFiles] = this.removeFromArrays(file, [this.files, this.buildedFiles])\n \n console.log('After deletion - files:', this.files.length, 'buildedFiles:', this.buildedFiles.length)\n \n // 多文件模式下,如果删除最后一个文件,重置 groupId\n if (this.multiple && this.buildedFiles.length === 0) {\n this.groupId = null\n console.log('Reset groupId after deleting last file')\n }\n \n // 触发 change 事件\n this.$emit('change', this.fileIds)\n },\n \n /**\n * 处理文件下载\n */\n handleClickDownload(file) {\n const { fileID: fileId } = file\n window.open(`/api-file/workbench/file/stream/${fileId}?origin=true`)\n },\n // ==================== 上传处理 ====================\n \n /**\n * 处理文件上传状态变化\n */\n onWatchFiles(files) {\n console.log('onWatchFiles called with files:', files.length)\n console.log('Current buildedFiles:', this.buildedFiles.length)\n \n // 更新文件状态\n this.files = files\n \n // 处理已上传成功的文件\n this.processUploadedFiles(files)\n \n // 检查上传是否完成\n if (this.isFileUploadSuccessed) {\n this.$emit('change', this.fileIds)\n this.$emit('on-success', this.fileResponseData)\n }\n },\n \n /**\n * 处理已上传成功的文件\n */\n processUploadedFiles(files) {\n // 处理所有有响应的文件(包括正在上传和已完成的)\n const uploadedFiles = files.filter(file => file.response)\n const newBuildedFiles = uploadedFiles.map(file => this.mergeFileData(file))\n \n if (this.multiple) {\n this.processMultipleFiles(newBuildedFiles)\n } else {\n // 单文件模式:只保留最新的文件\n this.buildedFiles = newBuildedFiles\n }\n \n this.logFileStatus()\n },\n \n /**\n * 处理多文件模式\n */\n processMultipleFiles(newBuildedFiles) {\n // 获取已存在的文件ID集合\n const existingFileIds = new Set(this.buildedFiles.map(f => f.fileID).filter(id => id))\n \n // 过滤出真正的新文件\n const trulyNewFiles = newBuildedFiles.filter(newFile => \n this.isNewFile(newFile, this.buildedFiles)\n )\n \n console.log('Existing fileIDs:', Array.from(existingFileIds))\n console.log('New uploaded files:', newBuildedFiles.map(f => ({ name: f.name, fileID: f.fileID })))\n console.log('Truly new files:', trulyNewFiles.map(f => ({ name: f.name, fileID: f.fileID })))\n \n // 将新文件追加到现有文件列表\n if (trulyNewFiles.length > 0) {\n this.buildedFiles = [...this.buildedFiles, ...trulyNewFiles]\n console.log('Added new files, total buildedFiles:', this.buildedFiles.length)\n }\n \n // 更新现有文件的状态(包括新添加的文件)\n this.updateExistingFiles(newBuildedFiles)\n },\n \n /**\n * 更新现有文件状态\n */\n updateExistingFiles(newBuildedFiles) {\n this.buildedFiles = this.buildedFiles.map(existingFile => {\n const updatedFile = newBuildedFiles.find(newFile => newFile.fileID === existingFile.fileID)\n return updatedFile ? { ...existingFile, ...updatedFile } : existingFile\n })\n },\n \n /**\n * 记录文件状态日志\n */\n logFileStatus() {\n console.log('Final buildedFiles:', this.buildedFiles.length)\n console.log('buildedFiles details:', this.buildedFiles.map(f => ({ name: f.name, fileID: f.fileID, success: f.success })))\n console.log('Uploading files:', this.uploadingFiles.length)\n console.log('Completed files:', this.completedFiles.length)\n },\n // ==================== 异步处理 ====================\n \n /**\n * 异步保存文件到服务器\n */\n async saveToServerAsyncPage(payloads = {}) {\n try {\n const response = await net.post('zuul/api-file/workbench/file/temp/saveToServerAsyncPage', payloads, { \n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'\n }\n })\n \n const { data } = response\n if (data !== 'saveToServerAsyncPage') {\n clearInterval(this.saveToServerAsyncPageTimer)\n }\n } catch (error) {\n console.error('saveToServerAsyncPage error:', error)\n clearInterval(this.saveToServerAsyncPageTimer)\n }\n },\n \n // ==================== 文件验证 ====================\n \n /**\n * 验证文件类型\n */\n validateFileType(file) {\n if (!file || !file.name) {\n console.log('文件或文件名不存在')\n return false\n }\n \n const fileExt = this.getFileExtension(file.name)\n console.log('文件扩展名:', fileExt)\n \n if (this.extensions) {\n const allowedExts = this.getAllowedExtensions()\n console.log('允许的扩展名:', allowedExts)\n \n if (!allowedExts.includes(fileExt)) {\n console.log('扩展名不在允许列表中')\n this.$message.error(`不支持的文件类型 \"${fileExt}\",请上传 ${this.extensions} 格式的文件`)\n return false\n }\n }\n \n console.log('文件类型验证通过')\n return true\n },\n \n /**\n * 获取文件扩展名\n */\n getFileExtension(fileName) {\n return fileName.toLowerCase().substring(fileName.lastIndexOf('.'))\n },\n \n /**\n * 获取允许的扩展名列表\n */\n getAllowedExtensions() {\n return this.extensions.toLowerCase()\n .split(',')\n .map(ext => ext.trim().startsWith('.') ? ext.trim() : `.${ext.trim()}`)\n },\n // ==================== 事件处理 ====================\n \n /**\n * 处理文件输入事件\n */\n onWatchInputFiles(newFile, oldFile) {\n if (newFile && !oldFile) {\n this.handleFileAdd(newFile)\n } else if (newFile && oldFile) {\n this.handleFileUpdate(newFile)\n } else if (!newFile && oldFile) {\n this.handleFileDelete()\n }\n \n // 激活上传组件\n this.activateUploadComponent(newFile, oldFile)\n },\n \n /**\n * 处理文件添加\n */\n handleFileAdd(newFile) {\n console.log('add file:', newFile)\n console.log('extensions:', this.extensions)\n console.log('accept:', this.accept)\n \n // 生成或使用 groupId\n this.ensureGroupId()\n \n // 验证文件类型\n if (!this.validateFileType(newFile)) {\n this.removeInvalidFile(newFile)\n return\n }\n \n console.log('文件类型验证通过,继续上传')\n },\n \n /**\n * 处理文件更新\n */\n handleFileUpdate(newFile) {\n console.log('update', newFile)\n const { success, active, chunk, response } = newFile\n \n if (chunk && success && !active) {\n console.log('chunk end')\n this.handleChunkComplete(response)\n }\n },\n \n /**\n * 处理文件删除\n */\n handleFileDelete() {\n console.log('delete')\n },\n \n /**\n * 确保 groupId 存在\n */\n ensureGroupId() {\n console.log('onWatchInputFiles - multiple:', this.multiple, 'current groupId:', this.groupId)\n \n if (this.multiple && !this.groupId) {\n this.groupId = uuidv4()\n console.log('Generated new groupId:', this.groupId)\n } else if (this.multiple && this.groupId) {\n console.log('Using existing groupId:', this.groupId)\n }\n },\n \n /**\n * 移除无效文件\n */\n removeInvalidFile(file) {\n console.log('文件类型验证失败,尝试移除文件')\n console.log('uploadRef:', this.uploadRef)\n console.log('$refs:', this.$refs)\n \n if (this.$refs[this.uploadRef]) {\n this.$refs[this.uploadRef].remove(file)\n } else {\n console.error('无法找到 uploadRef 引用')\n }\n },\n \n /**\n * 处理分片上传完成\n */\n handleChunkComplete(response) {\n const { data: { file, type } } = response\n const payloads = {\n filePath: file.match(/\\/cw(.*)/) ? file.match(/\\/cw(.*)/)[0] : void 0,\n asyncID: uuidv4(),\n isDeleteOrigin: false,\n toImage: type === 'pdf',\n unzip: type === 'zip',\n _csrf: localStorage.getItem('token')\n }\n \n this.saveToServerAsyncPageTimer = setInterval(() => {\n this.saveToServerAsyncPage(payloads)\n }, CONSTANTS.SAVE_INTERVAL)\n },\n \n /**\n * 激活上传组件\n */\n activateUploadComponent(newFile, oldFile) {\n if (Boolean(newFile) !== Boolean(oldFile) || oldFile.error !== newFile.error) {\n if (!this.$refs[this.uploadRef].active) {\n this.$refs[this.uploadRef].active = true\n }\n }\n },\n \n // ==================== 值变化处理 ====================\n \n /**\n * 重置文件状态\n */\n resetFiles() {\n this.files = []\n this.buildedFiles = []\n // 多选模式下保留或生成 groupId,避免首次上传为空\n if (this.multiple) {\n if (!this.groupId) {\n this.groupId = uuidv4()\n console.log('Generated groupId in resetFiles:', this.groupId)\n } else {\n console.log('Preserve existing groupId in resetFiles:', this.groupId)\n }\n } else {\n this.groupId = null\n console.log('Reset groupId to null (single mode)')\n }\n },\n \n /**\n * 处理多文件模式的值变化\n */\n async handleMultipleFileValue(value) {\n // multiple - value 就是 groupId\n // 只有当 groupId 发生变化时才重新获取文件列表(初始化回显)\n if (this.groupId !== value) {\n this.groupId = value\n console.log('Set groupId from external value:', this.groupId)\n await this.fetchFilesWithGroupId()\n } else {\n console.log('GroupId unchanged, skip fetchFilesWithGroupId')\n }\n },\n \n /**\n * 处理单文件模式的值变化\n */\n async handleSingleFileValue() {\n await this.fetchFileWithFileId()\n }\n }\n}\n</script>\n\n<style lang=\"scss\" scoped>\n::v-deep .ele-upload__inner {\n opacity: 1 !important;\n cursor: pointer;\n border: 1px dashed var(--idooel-form-title-border-color);\n background: var(--idooel-form-upload-bg-color) !important;\n &:hover {\n border-color: var(--idooel-form-upload-border-hover-color);\n }\n border-radius: var(--idooel-form-border-radius);\n}\n.ele-upload__wrapper {\n width: 100%;\n .ele-upload__area {\n padding: 16px;\n width: 100%;\n height: 80px;\n display: flex;\n flex-direction: row;\n .ele-upload__area--icon {\n color: var(--idooel-primary-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n font-size: 16x;\n .anticon-cloud-upload {\n font-size: 48px;\n color: var(--idooel-primary-color);\n }\n .anticon {\n font-size: 48px;\n color: var(--idooel-primary-color);\n }\n }\n .ele-upload__area--text {\n margin-left: 16px;\n .ele-upload__message {\n font-size: 16px;\n color: var(--idoole-black-088);\n text-align: left;\n }\n .ele-upload__ext {\n text-align: left;\n font-size: 14px;\n color: var(--idoole-black-06);\n }\n }\n }\n .ele-files__wrapper {\n .ele-file__item {\n width: 100%;\n margin-top: 8px;\n padding: 8px 12px;\n border-radius: var(--idooel-form-border-radius);\n background: var(--idooel-form-upload-bg-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n .ele-file__suffix--icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n }\n .ele-file__name {\n flex: 1;\n text-align: left;\n white-space: nowrap;\n overflow: hidden;\n font-size: 14px;\n margin-left: 8px;\n cursor: pointer;\n .ele-file__inner {\n overflow: hidden;\n text-overflow: ellipsis;\n }\n }\n .ele-file__delete {\n margin-left: 8px;\n .ele-file__delete--icon {\n margin-left: 8px;\n cursor: pointer;\n }\n }\n }\n }\n}\n</style>","::v-deep .ele-upload__inner {\n opacity: 1 !important;\n cursor: pointer;\n border: 1px dashed var(--idooel-form-title-border-color);\n background: var(--idooel-form-upload-bg-color) !important;\n border-radius: var(--idooel-form-border-radius);\n}\n::v-deep .ele-upload__inner:hover {\n border-color: var(--idooel-form-upload-border-hover-color);\n}\n\n.ele-upload__wrapper {\n width: 100%;\n}\n.ele-upload__wrapper .ele-upload__area {\n padding: 16px;\n width: 100%;\n height: 80px;\n display: flex;\n flex-direction: row;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon {\n color: var(--idooel-primary-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n font-size: 16x;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon .anticon-cloud-upload {\n font-size: 48px;\n color: var(--idooel-primary-color);\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--icon .anticon {\n font-size: 48px;\n color: var(--idooel-primary-color);\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text {\n margin-left: 16px;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text .ele-upload__message {\n font-size: 16px;\n color: var(--idoole-black-088);\n text-align: left;\n}\n.ele-upload__wrapper .ele-upload__area .ele-upload__area--text .ele-upload__ext {\n text-align: left;\n font-size: 14px;\n color: var(--idoole-black-06);\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item {\n width: 100%;\n margin-top: 8px;\n padding: 8px 12px;\n border-radius: var(--idooel-form-border-radius);\n background: var(--idooel-form-upload-bg-color);\n display: flex;\n flex-direction: row;\n align-items: center;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__suffix--icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__name {\n flex: 1;\n text-align: left;\n white-space: nowrap;\n overflow: hidden;\n font-size: 14px;\n margin-left: 8px;\n cursor: pointer;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__name .ele-file__inner {\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__delete {\n margin-left: 8px;\n}\n.ele-upload__wrapper .ele-files__wrapper .ele-file__item .ele-file__delete .ele-file__delete--icon {\n margin-left: 8px;\n cursor: pointer;\n}\n\n/*# sourceMappingURL=index.vue.map */"]}, media: undefined });
|
|
6151
6599
|
|
|
6152
6600
|
};
|
|
6153
6601
|
/* scoped */
|
|
6154
|
-
const __vue_scope_id__$t = "data-v-
|
|
6602
|
+
const __vue_scope_id__$t = "data-v-48a2255a";
|
|
6155
6603
|
/* module identifier */
|
|
6156
6604
|
const __vue_module_identifier__$t = undefined;
|
|
6157
6605
|
/* functional template */
|