@ibiz-template/core 0.0.4-beta.1 → 0.0.4-beta.3
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/index.esm.js +2198 -0
- package/dist/index.system.min.js +1 -0
- package/out/error/http-error/http-error.d.ts +1 -1
- package/out/error/http-error/http-error.d.ts.map +1 -1
- package/out/error/http-error/http-error.js +2 -1
- package/out/error/runtime-error/runtime-error.d.ts +1 -1
- package/out/error/runtime-error/runtime-error.d.ts.map +1 -1
- package/out/error/runtime-error/runtime-error.js +2 -1
- package/out/ibizsys.d.ts +1 -1
- package/out/ibizsys.js +1 -1
- package/out/types.d.ts +8 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/index.d.ts +0 -1
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +0 -1
- package/package.json +5 -7
- package/src/error/http-error/http-error.ts +2 -1
- package/src/error/runtime-error/runtime-error.ts +4 -2
- package/src/ibizsys.ts +1 -1
- package/src/types.ts +9 -0
- package/src/utils/index.ts +0 -1
- package/dist/system/index.system.js +0 -1
- package/out/utils/plural/plural.d.ts +0 -21
- package/out/utils/plural/plural.d.ts.map +0 -1
- package/out/utils/plural/plural.js +0 -25
- package/src/utils/plural/plural.ts +0 -27
|
@@ -0,0 +1,2198 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/loglevel@1.8.1/node_modules/loglevel/lib/loglevel.js
|
|
28
|
+
var require_loglevel = __commonJS({
|
|
29
|
+
"../../node_modules/.pnpm/loglevel@1.8.1/node_modules/loglevel/lib/loglevel.js"(exports, module) {
|
|
30
|
+
(function(root, definition) {
|
|
31
|
+
"use strict";
|
|
32
|
+
if (typeof define === "function" && define.amd) {
|
|
33
|
+
define(definition);
|
|
34
|
+
} else if (typeof module === "object" && module.exports) {
|
|
35
|
+
module.exports = definition();
|
|
36
|
+
} else {
|
|
37
|
+
root.log = definition();
|
|
38
|
+
}
|
|
39
|
+
})(exports, function() {
|
|
40
|
+
"use strict";
|
|
41
|
+
var noop = function() {
|
|
42
|
+
};
|
|
43
|
+
var undefinedType = "undefined";
|
|
44
|
+
var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
|
|
45
|
+
var logMethods = [
|
|
46
|
+
"trace",
|
|
47
|
+
"debug",
|
|
48
|
+
"info",
|
|
49
|
+
"warn",
|
|
50
|
+
"error"
|
|
51
|
+
];
|
|
52
|
+
function bindMethod(obj, methodName) {
|
|
53
|
+
var method = obj[methodName];
|
|
54
|
+
if (typeof method.bind === "function") {
|
|
55
|
+
return method.bind(obj);
|
|
56
|
+
} else {
|
|
57
|
+
try {
|
|
58
|
+
return Function.prototype.bind.call(method, obj);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return function() {
|
|
61
|
+
return Function.prototype.apply.apply(method, [obj, arguments]);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function traceForIE() {
|
|
67
|
+
if (console.log) {
|
|
68
|
+
if (console.log.apply) {
|
|
69
|
+
console.log.apply(console, arguments);
|
|
70
|
+
} else {
|
|
71
|
+
Function.prototype.apply.apply(console.log, [console, arguments]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (console.trace)
|
|
75
|
+
console.trace();
|
|
76
|
+
}
|
|
77
|
+
function realMethod(methodName) {
|
|
78
|
+
if (methodName === "debug") {
|
|
79
|
+
methodName = "log";
|
|
80
|
+
}
|
|
81
|
+
if (typeof console === undefinedType) {
|
|
82
|
+
return false;
|
|
83
|
+
} else if (methodName === "trace" && isIE) {
|
|
84
|
+
return traceForIE;
|
|
85
|
+
} else if (console[methodName] !== void 0) {
|
|
86
|
+
return bindMethod(console, methodName);
|
|
87
|
+
} else if (console.log !== void 0) {
|
|
88
|
+
return bindMethod(console, "log");
|
|
89
|
+
} else {
|
|
90
|
+
return noop;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function replaceLoggingMethods(level, loggerName) {
|
|
94
|
+
for (var i = 0; i < logMethods.length; i++) {
|
|
95
|
+
var methodName = logMethods[i];
|
|
96
|
+
this[methodName] = i < level ? noop : this.methodFactory(methodName, level, loggerName);
|
|
97
|
+
}
|
|
98
|
+
this.log = this.debug;
|
|
99
|
+
}
|
|
100
|
+
function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
|
|
101
|
+
return function() {
|
|
102
|
+
if (typeof console !== undefinedType) {
|
|
103
|
+
replaceLoggingMethods.call(this, level, loggerName);
|
|
104
|
+
this[methodName].apply(this, arguments);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function defaultMethodFactory(methodName, level, loggerName) {
|
|
109
|
+
return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
|
|
110
|
+
}
|
|
111
|
+
function Logger2(name, defaultLevel, factory) {
|
|
112
|
+
var self = this;
|
|
113
|
+
var currentLevel;
|
|
114
|
+
defaultLevel = defaultLevel == null ? "WARN" : defaultLevel;
|
|
115
|
+
var storageKey = "loglevel";
|
|
116
|
+
if (typeof name === "string") {
|
|
117
|
+
storageKey += ":" + name;
|
|
118
|
+
} else if (typeof name === "symbol") {
|
|
119
|
+
storageKey = void 0;
|
|
120
|
+
}
|
|
121
|
+
function persistLevelIfPossible(levelNum) {
|
|
122
|
+
var levelName = (logMethods[levelNum] || "silent").toUpperCase();
|
|
123
|
+
if (typeof window === undefinedType || !storageKey)
|
|
124
|
+
return;
|
|
125
|
+
try {
|
|
126
|
+
window.localStorage[storageKey] = levelName;
|
|
127
|
+
return;
|
|
128
|
+
} catch (ignore) {
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
|
|
132
|
+
} catch (ignore) {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function getPersistedLevel() {
|
|
136
|
+
var storedLevel;
|
|
137
|
+
if (typeof window === undefinedType || !storageKey)
|
|
138
|
+
return;
|
|
139
|
+
try {
|
|
140
|
+
storedLevel = window.localStorage[storageKey];
|
|
141
|
+
} catch (ignore) {
|
|
142
|
+
}
|
|
143
|
+
if (typeof storedLevel === undefinedType) {
|
|
144
|
+
try {
|
|
145
|
+
var cookie = window.document.cookie;
|
|
146
|
+
var location = cookie.indexOf(
|
|
147
|
+
encodeURIComponent(storageKey) + "="
|
|
148
|
+
);
|
|
149
|
+
if (location !== -1) {
|
|
150
|
+
storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
|
|
151
|
+
}
|
|
152
|
+
} catch (ignore) {
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (self.levels[storedLevel] === void 0) {
|
|
156
|
+
storedLevel = void 0;
|
|
157
|
+
}
|
|
158
|
+
return storedLevel;
|
|
159
|
+
}
|
|
160
|
+
function clearPersistedLevel() {
|
|
161
|
+
if (typeof window === undefinedType || !storageKey)
|
|
162
|
+
return;
|
|
163
|
+
try {
|
|
164
|
+
window.localStorage.removeItem(storageKey);
|
|
165
|
+
return;
|
|
166
|
+
} catch (ignore) {
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
170
|
+
} catch (ignore) {
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
self.name = name;
|
|
174
|
+
self.levels = {
|
|
175
|
+
"TRACE": 0,
|
|
176
|
+
"DEBUG": 1,
|
|
177
|
+
"INFO": 2,
|
|
178
|
+
"WARN": 3,
|
|
179
|
+
"ERROR": 4,
|
|
180
|
+
"SILENT": 5
|
|
181
|
+
};
|
|
182
|
+
self.methodFactory = factory || defaultMethodFactory;
|
|
183
|
+
self.getLevel = function() {
|
|
184
|
+
return currentLevel;
|
|
185
|
+
};
|
|
186
|
+
self.setLevel = function(level, persist) {
|
|
187
|
+
if (typeof level === "string" && self.levels[level.toUpperCase()] !== void 0) {
|
|
188
|
+
level = self.levels[level.toUpperCase()];
|
|
189
|
+
}
|
|
190
|
+
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
|
191
|
+
currentLevel = level;
|
|
192
|
+
if (persist !== false) {
|
|
193
|
+
persistLevelIfPossible(level);
|
|
194
|
+
}
|
|
195
|
+
replaceLoggingMethods.call(self, level, name);
|
|
196
|
+
if (typeof console === undefinedType && level < self.levels.SILENT) {
|
|
197
|
+
return "No console available for logging";
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
throw "log.setLevel() called with invalid level: " + level;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
self.setDefaultLevel = function(level) {
|
|
204
|
+
defaultLevel = level;
|
|
205
|
+
if (!getPersistedLevel()) {
|
|
206
|
+
self.setLevel(level, false);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
self.resetLevel = function() {
|
|
210
|
+
self.setLevel(defaultLevel, false);
|
|
211
|
+
clearPersistedLevel();
|
|
212
|
+
};
|
|
213
|
+
self.enableAll = function(persist) {
|
|
214
|
+
self.setLevel(self.levels.TRACE, persist);
|
|
215
|
+
};
|
|
216
|
+
self.disableAll = function(persist) {
|
|
217
|
+
self.setLevel(self.levels.SILENT, persist);
|
|
218
|
+
};
|
|
219
|
+
var initialLevel = getPersistedLevel();
|
|
220
|
+
if (initialLevel == null) {
|
|
221
|
+
initialLevel = defaultLevel;
|
|
222
|
+
}
|
|
223
|
+
self.setLevel(initialLevel, false);
|
|
224
|
+
}
|
|
225
|
+
var defaultLogger = new Logger2();
|
|
226
|
+
var _loggersByName = {};
|
|
227
|
+
defaultLogger.getLogger = function getLogger(name) {
|
|
228
|
+
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
229
|
+
throw new TypeError("You must supply a name when creating a logger.");
|
|
230
|
+
}
|
|
231
|
+
var logger = _loggersByName[name];
|
|
232
|
+
if (!logger) {
|
|
233
|
+
logger = _loggersByName[name] = new Logger2(
|
|
234
|
+
name,
|
|
235
|
+
defaultLogger.getLevel(),
|
|
236
|
+
defaultLogger.methodFactory
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return logger;
|
|
240
|
+
};
|
|
241
|
+
var _log = typeof window !== undefinedType ? window.log : void 0;
|
|
242
|
+
defaultLogger.noConflict = function() {
|
|
243
|
+
if (typeof window !== undefinedType && window.log === defaultLogger) {
|
|
244
|
+
window.log = _log;
|
|
245
|
+
}
|
|
246
|
+
return defaultLogger;
|
|
247
|
+
};
|
|
248
|
+
defaultLogger.getLoggers = function getLoggers() {
|
|
249
|
+
return _loggersByName;
|
|
250
|
+
};
|
|
251
|
+
defaultLogger["default"] = defaultLogger;
|
|
252
|
+
return defaultLogger;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// src/command/utils/linked-list.ts
|
|
258
|
+
var _Node = class {
|
|
259
|
+
constructor(element) {
|
|
260
|
+
this.element = element;
|
|
261
|
+
this.next = _Node.Undefined;
|
|
262
|
+
this.prev = _Node.Undefined;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var Node = _Node;
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
267
|
+
Node.Undefined = new _Node(void 0);
|
|
268
|
+
var LinkedList = class {
|
|
269
|
+
constructor() {
|
|
270
|
+
this._first = Node.Undefined;
|
|
271
|
+
this._last = Node.Undefined;
|
|
272
|
+
this._size = 0;
|
|
273
|
+
}
|
|
274
|
+
get size() {
|
|
275
|
+
return this._size;
|
|
276
|
+
}
|
|
277
|
+
isEmpty() {
|
|
278
|
+
return this._first === Node.Undefined;
|
|
279
|
+
}
|
|
280
|
+
clear() {
|
|
281
|
+
let node = this._first;
|
|
282
|
+
while (node !== Node.Undefined) {
|
|
283
|
+
const { next } = node;
|
|
284
|
+
node.prev = Node.Undefined;
|
|
285
|
+
node.next = Node.Undefined;
|
|
286
|
+
node = next;
|
|
287
|
+
}
|
|
288
|
+
this._first = Node.Undefined;
|
|
289
|
+
this._last = Node.Undefined;
|
|
290
|
+
this._size = 0;
|
|
291
|
+
}
|
|
292
|
+
unshift(element) {
|
|
293
|
+
return this._insert(element, false);
|
|
294
|
+
}
|
|
295
|
+
push(element) {
|
|
296
|
+
return this._insert(element, true);
|
|
297
|
+
}
|
|
298
|
+
_insert(element, atTheEnd) {
|
|
299
|
+
const newNode = new Node(element);
|
|
300
|
+
if (this._first === Node.Undefined) {
|
|
301
|
+
this._first = newNode;
|
|
302
|
+
this._last = newNode;
|
|
303
|
+
} else if (atTheEnd) {
|
|
304
|
+
const oldLast = this._last;
|
|
305
|
+
this._last = newNode;
|
|
306
|
+
newNode.prev = oldLast;
|
|
307
|
+
oldLast.next = newNode;
|
|
308
|
+
} else {
|
|
309
|
+
const oldFirst = this._first;
|
|
310
|
+
this._first = newNode;
|
|
311
|
+
newNode.next = oldFirst;
|
|
312
|
+
oldFirst.prev = newNode;
|
|
313
|
+
}
|
|
314
|
+
this._size += 1;
|
|
315
|
+
let didRemove = false;
|
|
316
|
+
return () => {
|
|
317
|
+
if (!didRemove) {
|
|
318
|
+
didRemove = true;
|
|
319
|
+
this._remove(newNode);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
shift() {
|
|
324
|
+
if (this._first === Node.Undefined) {
|
|
325
|
+
return void 0;
|
|
326
|
+
}
|
|
327
|
+
const res = this._first.element;
|
|
328
|
+
this._remove(this._first);
|
|
329
|
+
return res;
|
|
330
|
+
}
|
|
331
|
+
pop() {
|
|
332
|
+
if (this._last === Node.Undefined) {
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
const res = this._last.element;
|
|
336
|
+
this._remove(this._last);
|
|
337
|
+
return res;
|
|
338
|
+
}
|
|
339
|
+
_remove(node) {
|
|
340
|
+
if (node.prev !== Node.Undefined && node.next !== Node.Undefined) {
|
|
341
|
+
const anchor = node.prev;
|
|
342
|
+
anchor.next = node.next;
|
|
343
|
+
node.next.prev = anchor;
|
|
344
|
+
} else if (node.prev === Node.Undefined && node.next === Node.Undefined) {
|
|
345
|
+
this._first = Node.Undefined;
|
|
346
|
+
this._last = Node.Undefined;
|
|
347
|
+
} else if (node.next === Node.Undefined) {
|
|
348
|
+
this._last = this._last.prev;
|
|
349
|
+
this._last.next = Node.Undefined;
|
|
350
|
+
} else if (node.prev === Node.Undefined) {
|
|
351
|
+
this._first = this._first.next;
|
|
352
|
+
this._first.prev = Node.Undefined;
|
|
353
|
+
}
|
|
354
|
+
this._size -= 1;
|
|
355
|
+
}
|
|
356
|
+
*[Symbol.iterator]() {
|
|
357
|
+
let node = this._first;
|
|
358
|
+
while (node !== Node.Undefined) {
|
|
359
|
+
yield node.element;
|
|
360
|
+
node = node.next;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// src/command/utils/util.ts
|
|
366
|
+
function once(fn) {
|
|
367
|
+
const _this = this;
|
|
368
|
+
let didCall = false;
|
|
369
|
+
let result;
|
|
370
|
+
return function() {
|
|
371
|
+
if (didCall) {
|
|
372
|
+
return result;
|
|
373
|
+
}
|
|
374
|
+
didCall = true;
|
|
375
|
+
result = fn.apply(_this, arguments);
|
|
376
|
+
return result;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function toDisposable(fn) {
|
|
380
|
+
const self = {
|
|
381
|
+
dispose: once(() => {
|
|
382
|
+
fn();
|
|
383
|
+
})
|
|
384
|
+
};
|
|
385
|
+
return self;
|
|
386
|
+
}
|
|
387
|
+
function debounce(func, wait, immediate) {
|
|
388
|
+
let timer;
|
|
389
|
+
return function(...args) {
|
|
390
|
+
if (timer) {
|
|
391
|
+
clearTimeout(timer);
|
|
392
|
+
}
|
|
393
|
+
if (immediate) {
|
|
394
|
+
const callNow = !timer;
|
|
395
|
+
timer = setTimeout(() => {
|
|
396
|
+
timer = null;
|
|
397
|
+
}, wait);
|
|
398
|
+
if (callNow) {
|
|
399
|
+
func.apply(this, args);
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
timer = setTimeout(() => {
|
|
403
|
+
func.apply(this, args);
|
|
404
|
+
}, wait);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function throttle(fn, wait) {
|
|
409
|
+
let timer = null;
|
|
410
|
+
return function(...args) {
|
|
411
|
+
if (!timer) {
|
|
412
|
+
timer = setTimeout(() => {
|
|
413
|
+
fn.apply(this, args);
|
|
414
|
+
timer = null;
|
|
415
|
+
}, wait);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/command/command-register.ts
|
|
421
|
+
var CommandsRegistry = class {
|
|
422
|
+
constructor() {
|
|
423
|
+
/**
|
|
424
|
+
* 已经注册的所有指令
|
|
425
|
+
*
|
|
426
|
+
* @author chitanda
|
|
427
|
+
* @date 2022-07-21 15:07:47
|
|
428
|
+
* @private
|
|
429
|
+
*/
|
|
430
|
+
this.commands = /* @__PURE__ */ new Map();
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* 注册指令
|
|
434
|
+
*
|
|
435
|
+
* @author chitanda
|
|
436
|
+
* @date 2022-06-27 13:06:31
|
|
437
|
+
* @param {(string | ICommand)} idOrCommand
|
|
438
|
+
* @param {ICommandHandler} [handler]
|
|
439
|
+
* @return {*} {IDisposable}
|
|
440
|
+
*/
|
|
441
|
+
registerCommand(idOrCommand, handler, opts) {
|
|
442
|
+
if (!idOrCommand) {
|
|
443
|
+
throw new Error(`invalid command`);
|
|
444
|
+
}
|
|
445
|
+
if (typeof idOrCommand === "string") {
|
|
446
|
+
if (!handler) {
|
|
447
|
+
throw new Error(`invalid command`);
|
|
448
|
+
}
|
|
449
|
+
return this.registerCommand({ id: idOrCommand, handler, opts });
|
|
450
|
+
}
|
|
451
|
+
const { id } = idOrCommand;
|
|
452
|
+
let commands2 = this.commands.get(id);
|
|
453
|
+
if (!commands2) {
|
|
454
|
+
commands2 = new LinkedList();
|
|
455
|
+
this.commands.set(id, commands2);
|
|
456
|
+
}
|
|
457
|
+
const removeFn = commands2.unshift(idOrCommand);
|
|
458
|
+
const ret = toDisposable(() => {
|
|
459
|
+
removeFn();
|
|
460
|
+
const command = this.commands.get(id);
|
|
461
|
+
if (command == null ? void 0 : command.isEmpty()) {
|
|
462
|
+
this.commands.delete(id);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
return ret;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* 指令是否已经注册
|
|
469
|
+
*
|
|
470
|
+
* @author chitanda
|
|
471
|
+
* @date 2022-07-21 15:07:58
|
|
472
|
+
* @param {string} id
|
|
473
|
+
* @return {*} {boolean}
|
|
474
|
+
*/
|
|
475
|
+
hasCommand(id) {
|
|
476
|
+
return this.commands.has(id);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* 查找指令
|
|
480
|
+
*
|
|
481
|
+
* @author chitanda
|
|
482
|
+
* @date 2022-07-21 16:07:12
|
|
483
|
+
* @param {string} id
|
|
484
|
+
* @return {*} {(ICommand | undefined)}
|
|
485
|
+
*/
|
|
486
|
+
getCommand(id) {
|
|
487
|
+
const list = this.commands.get(id);
|
|
488
|
+
if (!list || list.isEmpty()) {
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
return list[Symbol.iterator]().next().value;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* 获取所有指令
|
|
495
|
+
*
|
|
496
|
+
* @author chitanda
|
|
497
|
+
* @date 2022-07-21 16:07:20
|
|
498
|
+
* @return {*} {ICommandsMap}
|
|
499
|
+
*/
|
|
500
|
+
getCommands() {
|
|
501
|
+
const result = /* @__PURE__ */ new Map();
|
|
502
|
+
const keys = this.commands.keys();
|
|
503
|
+
for (const key of keys) {
|
|
504
|
+
const command = this.getCommand(key);
|
|
505
|
+
if (command) {
|
|
506
|
+
result.set(key, command);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* 获取指令配置参数
|
|
513
|
+
*
|
|
514
|
+
* @author chitanda
|
|
515
|
+
* @date 2022-07-21 16:07:27
|
|
516
|
+
* @param {string} id
|
|
517
|
+
* @return {*} {(ICommandOption | undefined)}
|
|
518
|
+
*/
|
|
519
|
+
getCommandOpt(id) {
|
|
520
|
+
const cmd = this.getCommand(id);
|
|
521
|
+
return cmd == null ? void 0 : cmd.opts;
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// src/command/command.ts
|
|
526
|
+
var CommandController = class {
|
|
527
|
+
constructor() {
|
|
528
|
+
this.commandRegister = new CommandsRegistry();
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* 注册指令
|
|
532
|
+
*
|
|
533
|
+
* @author chitanda
|
|
534
|
+
* @date 2022-06-28 19:06:45
|
|
535
|
+
* @param {string} id
|
|
536
|
+
* @param {ICommandHandler} handler
|
|
537
|
+
* @param {ICommandOption} [opts]
|
|
538
|
+
* @return {*} {IDisposable}
|
|
539
|
+
*/
|
|
540
|
+
register(id, handler, opts) {
|
|
541
|
+
return this.commandRegister.registerCommand(id, handler, opts);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* 执行指令
|
|
545
|
+
*
|
|
546
|
+
* @author chitanda
|
|
547
|
+
* @date 2022-06-28 19:06:38
|
|
548
|
+
* @template T
|
|
549
|
+
* @param {string} id
|
|
550
|
+
* @param {...unknown[]} args
|
|
551
|
+
* @return {*} {Promise<T>}
|
|
552
|
+
*/
|
|
553
|
+
async execute(id, ...args) {
|
|
554
|
+
const command = this.commandRegister.getCommand(id);
|
|
555
|
+
if (command) {
|
|
556
|
+
return command.handler(...args);
|
|
557
|
+
}
|
|
558
|
+
throw new Error(`\u672A\u6CE8\u518C\u6307\u4EE4: ${id}\uFF0C\u8BF7\u5148\u6CE8\u518C\u6307\u4EE4`);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* 判断指令是否存在,可直接抛出异常
|
|
562
|
+
*
|
|
563
|
+
* @author chitanda
|
|
564
|
+
* @date 2022-06-28 19:06:11
|
|
565
|
+
* @param {string} id
|
|
566
|
+
* @param {boolean} [err]
|
|
567
|
+
* @return {*} {boolean}
|
|
568
|
+
*/
|
|
569
|
+
hasCommand(id, err) {
|
|
570
|
+
const bol = !!this.commandRegister.hasCommand(id);
|
|
571
|
+
if (err === true && bol === true) {
|
|
572
|
+
throw new Error(`\u672A\u6CE8\u518C\u6307\u4EE4: ${id}\uFF0C\u8BF7\u5148\u6CE8\u518C\u6307\u4EE4`);
|
|
573
|
+
}
|
|
574
|
+
return bol;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* 获取指令配置参数
|
|
578
|
+
*
|
|
579
|
+
* @author chitanda
|
|
580
|
+
* @date 2022-07-21 17:07:11
|
|
581
|
+
* @param {string} id
|
|
582
|
+
* @return {*} {(ICommandOption | undefined)}
|
|
583
|
+
*/
|
|
584
|
+
getCommandOpts(id) {
|
|
585
|
+
return this.commandRegister.getCommandOpt(id);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
// src/command/index.ts
|
|
590
|
+
var commands = new CommandController();
|
|
591
|
+
|
|
592
|
+
// src/constant/core/core.ts
|
|
593
|
+
var CoreConst = class {
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* 默认模型服务标识
|
|
597
|
+
*/
|
|
598
|
+
CoreConst.DEFAULT_MODEL_SERVICE_TAG = "default";
|
|
599
|
+
/**
|
|
600
|
+
* 访问令牌标识
|
|
601
|
+
*
|
|
602
|
+
* @author chitanda
|
|
603
|
+
* @date 2022-07-20 15:07:28
|
|
604
|
+
* @static
|
|
605
|
+
*/
|
|
606
|
+
CoreConst.TOKEN = "access_token";
|
|
607
|
+
/**
|
|
608
|
+
* 访问令牌标识过期时间
|
|
609
|
+
*
|
|
610
|
+
* @author lxm
|
|
611
|
+
* @date 2023-02-13 07:11:33
|
|
612
|
+
* @static
|
|
613
|
+
* @memberof CoreConst
|
|
614
|
+
*/
|
|
615
|
+
CoreConst.TOKEN_EXPIRES = "access_token_expires";
|
|
616
|
+
|
|
617
|
+
// src/constant/util/util.ts
|
|
618
|
+
var NOOP = () => {
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// src/constant/http-status-message/http-status-message.ts
|
|
622
|
+
var HttpStatusMessageConst = {
|
|
623
|
+
200: "\u670D\u52A1\u5668\u6210\u529F\u8FD4\u56DE\u8BF7\u6C42\u7684\u6570\u636E\u3002",
|
|
624
|
+
201: "\u65B0\u5EFA\u6216\u4FEE\u6539\u6570\u636E\u6210\u529F\u3002",
|
|
625
|
+
202: "\u4E00\u4E2A\u8BF7\u6C42\u5DF2\u7ECF\u8FDB\u5165\u540E\u53F0\u6392\u961F\uFF08\u5F02\u6B65\u4EFB\u52A1\uFF09\u3002",
|
|
626
|
+
204: "\u5220\u9664\u6570\u636E\u6210\u529F\u3002",
|
|
627
|
+
400: "\u53D1\u51FA\u7684\u8BF7\u6C42\u6709\u9519\u8BEF\uFF0C\u670D\u52A1\u5668\u6CA1\u6709\u8FDB\u884C\u65B0\u5EFA\u6216\u4FEE\u6539\u6570\u636E\u7684\u64CD\u4F5C\u3002",
|
|
628
|
+
401: "\u7528\u6237\u6CA1\u6709\u6743\u9650\uFF08\u4EE4\u724C\u3001\u7528\u6237\u540D\u3001\u5BC6\u7801\u9519\u8BEF\uFF09\u3002",
|
|
629
|
+
403: "\u7528\u6237\u5F97\u5230\u6388\u6743\uFF0C\u4F46\u662F\u8BBF\u95EE\u662F\u88AB\u7981\u6B62\u7684\u3002",
|
|
630
|
+
404: "\u53D1\u51FA\u7684\u8BF7\u6C42\u9488\u5BF9\u7684\u662F\u4E0D\u5B58\u5728\u7684\u8BB0\u5F55\uFF0C\u670D\u52A1\u5668\u6CA1\u6709\u8FDB\u884C\u64CD\u4F5C\u3002",
|
|
631
|
+
406: "\u8BF7\u6C42\u7684\u683C\u5F0F\u4E0D\u53EF\u5F97\u3002",
|
|
632
|
+
410: "\u8BF7\u6C42\u7684\u8D44\u6E90\u88AB\u6C38\u4E45\u5220\u9664\uFF0C\u4E14\u4E0D\u4F1A\u518D\u5F97\u5230\u7684\u3002",
|
|
633
|
+
422: "\u5F53\u521B\u5EFA\u4E00\u4E2A\u5BF9\u8C61\u65F6\uFF0C\u53D1\u751F\u4E00\u4E2A\u9A8C\u8BC1\u9519\u8BEF\u3002",
|
|
634
|
+
500: "\u670D\u52A1\u5668\u53D1\u751F\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u670D\u52A1\u5668\u3002",
|
|
635
|
+
502: "\u7F51\u5173\u9519\u8BEF\u3002",
|
|
636
|
+
503: "\u670D\u52A1\u4E0D\u53EF\u7528\uFF0C\u670D\u52A1\u5668\u6682\u65F6\u8FC7\u8F7D\u6216\u7EF4\u62A4\u3002",
|
|
637
|
+
504: "\u7F51\u5173\u8D85\u65F6\u3002"
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
// src/constant/login-mode/login-mode.ts
|
|
641
|
+
var LoginMode = /* @__PURE__ */ ((LoginMode2) => {
|
|
642
|
+
LoginMode2["DEFAULT"] = "DEFAULT";
|
|
643
|
+
LoginMode2["CUSTOM"] = "CUSTOM";
|
|
644
|
+
LoginMode2["CAS"] = "CAS";
|
|
645
|
+
return LoginMode2;
|
|
646
|
+
})(LoginMode || {});
|
|
647
|
+
|
|
648
|
+
// src/constant/menu-permission-mode/menu-permission-mode.ts
|
|
649
|
+
var MenuPermissionMode = /* @__PURE__ */ ((MenuPermissionMode2) => {
|
|
650
|
+
MenuPermissionMode2["MIXIN"] = "MIXIN";
|
|
651
|
+
MenuPermissionMode2["RESOURCE"] = "RESOURCE";
|
|
652
|
+
MenuPermissionMode2["RT"] = "RT";
|
|
653
|
+
return MenuPermissionMode2;
|
|
654
|
+
})(MenuPermissionMode || {});
|
|
655
|
+
|
|
656
|
+
// src/context/index.ts
|
|
657
|
+
import { clone } from "ramda";
|
|
658
|
+
var IBizContext = class {
|
|
659
|
+
/**
|
|
660
|
+
* Creates an instance of IBizContext.
|
|
661
|
+
*
|
|
662
|
+
* @author chitanda
|
|
663
|
+
* @date 2022-07-14 10:07:15
|
|
664
|
+
* @param {IDatum} [context={}] 自身的上下文
|
|
665
|
+
* @param {IContext} [parent]
|
|
666
|
+
*/
|
|
667
|
+
// eslint-disable-next-line default-param-last
|
|
668
|
+
constructor(context = {}, parent) {
|
|
669
|
+
Object.defineProperty(this, "_associationContext", {
|
|
670
|
+
enumerable: false,
|
|
671
|
+
value: []
|
|
672
|
+
});
|
|
673
|
+
if (parent) {
|
|
674
|
+
const self = this;
|
|
675
|
+
Object.defineProperty(this, "_parent", {
|
|
676
|
+
enumerable: false,
|
|
677
|
+
writable: true,
|
|
678
|
+
value: parent
|
|
679
|
+
});
|
|
680
|
+
Object.defineProperty(this, "_context", {
|
|
681
|
+
enumerable: false,
|
|
682
|
+
writable: true,
|
|
683
|
+
value: {}
|
|
684
|
+
});
|
|
685
|
+
const properties = {};
|
|
686
|
+
const keys = Object.keys(parent);
|
|
687
|
+
keys.forEach((key) => {
|
|
688
|
+
properties[key] = {
|
|
689
|
+
enumerable: true,
|
|
690
|
+
set(val) {
|
|
691
|
+
if (val == null) {
|
|
692
|
+
self._context[key] = null;
|
|
693
|
+
} else {
|
|
694
|
+
self._context[key] = val;
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
get() {
|
|
698
|
+
if (self._context[key] !== void 0) {
|
|
699
|
+
return self._context[key];
|
|
700
|
+
}
|
|
701
|
+
return parent[key];
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
});
|
|
705
|
+
Object.defineProperties(this, properties);
|
|
706
|
+
}
|
|
707
|
+
Object.assign(this, context);
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* 返回自身的上下文,独有的和与父有差异的。
|
|
711
|
+
*
|
|
712
|
+
* @author lxm
|
|
713
|
+
* @date 2022-12-08 17:12:26
|
|
714
|
+
* @returns {*} {IDatum}
|
|
715
|
+
*/
|
|
716
|
+
getOwnContext() {
|
|
717
|
+
const result = {};
|
|
718
|
+
Object.keys(this).forEach((key) => {
|
|
719
|
+
if (!this._parent || !Object.prototype.hasOwnProperty.call(this._parent, key) || Object.prototype.hasOwnProperty.call(this._context, key)) {
|
|
720
|
+
result[key] = this[key];
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
return result;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* 销毁当前上下文对象
|
|
727
|
+
*
|
|
728
|
+
* @author chitanda
|
|
729
|
+
* @date 2023-03-13 15:03:04
|
|
730
|
+
*/
|
|
731
|
+
destroy() {
|
|
732
|
+
this._parent = void 0;
|
|
733
|
+
this._context = {};
|
|
734
|
+
this._associationContext.forEach((item) => {
|
|
735
|
+
item.destroy();
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* 在非视图中,需要断开视图上下文联系时。只能使用 clone 创建新的局部上下文
|
|
740
|
+
*
|
|
741
|
+
* @author chitanda
|
|
742
|
+
* @date 2023-03-13 16:03:13
|
|
743
|
+
* @return {*} {IBizContext}
|
|
744
|
+
*/
|
|
745
|
+
clone() {
|
|
746
|
+
const newContext = new IBizContext(
|
|
747
|
+
clone(this.getOwnContext()),
|
|
748
|
+
this._parent
|
|
749
|
+
);
|
|
750
|
+
this._associationContext.push(newContext);
|
|
751
|
+
return newContext;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* 上下文只有在视图初始化时,调用 create 方法
|
|
755
|
+
*
|
|
756
|
+
* @author chitanda
|
|
757
|
+
* @date 2023-03-13 16:03:32
|
|
758
|
+
* @static
|
|
759
|
+
* @param {IDatum} [context]
|
|
760
|
+
* @param {IContext} [parent]
|
|
761
|
+
* @return {*} {IContext}
|
|
762
|
+
*/
|
|
763
|
+
static create(context, parent) {
|
|
764
|
+
return new IBizContext(context, parent);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
// src/environment/environment.ts
|
|
769
|
+
var Environment = {
|
|
770
|
+
dev: false,
|
|
771
|
+
hub: true,
|
|
772
|
+
logLevel: "ERROR",
|
|
773
|
+
baseUrl: "/api",
|
|
774
|
+
appId: "",
|
|
775
|
+
pluginBaseUrl: "./plugins",
|
|
776
|
+
remoteModelUrl: "/remotemodel",
|
|
777
|
+
assetsUrl: "./assets",
|
|
778
|
+
dcSystem: "",
|
|
779
|
+
downloadFileUrl: "/ibizutil/download",
|
|
780
|
+
uploadFileUrl: "/ibizutil/upload",
|
|
781
|
+
casLoginUrl: "",
|
|
782
|
+
loginMode: "DEFAULT" /* DEFAULT */,
|
|
783
|
+
menuPermissionMode: "MIXIN" /* MIXIN */,
|
|
784
|
+
enablePermission: true,
|
|
785
|
+
routePlaceholder: "-",
|
|
786
|
+
enableWfAllHistory: false
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// src/error/http-error/http-error.ts
|
|
790
|
+
var HttpError = class extends Error {
|
|
791
|
+
constructor(err) {
|
|
792
|
+
super("HttpError");
|
|
793
|
+
this.name = "HttpError";
|
|
794
|
+
const res = err.response;
|
|
795
|
+
this.response = err.response;
|
|
796
|
+
if (res) {
|
|
797
|
+
if (res.data) {
|
|
798
|
+
this.message = res.data.message;
|
|
799
|
+
} else {
|
|
800
|
+
this.message = res.statusText;
|
|
801
|
+
}
|
|
802
|
+
if (!this.message) {
|
|
803
|
+
this.message = "\u7F51\u7EDC\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5!";
|
|
804
|
+
}
|
|
805
|
+
this.status = res.status;
|
|
806
|
+
} else {
|
|
807
|
+
this.message = err.message;
|
|
808
|
+
this.status = 500;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
// src/error/model-error/model-error.ts
|
|
814
|
+
var ModelError = class extends Error {
|
|
815
|
+
/**
|
|
816
|
+
* Creates an instance of ModelError.
|
|
817
|
+
*
|
|
818
|
+
* @author chitanda
|
|
819
|
+
* @date 2022-08-30 16:08:38
|
|
820
|
+
* @param {IModelObject} model 模板未支持的模型
|
|
821
|
+
* @param {string} [msg]
|
|
822
|
+
*/
|
|
823
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
824
|
+
constructor(model, msg) {
|
|
825
|
+
super(`\u300C${model.id}\u300D\u6A21\u578B${msg ? `\uFF1A ${msg}` : ""}`);
|
|
826
|
+
this.model = model;
|
|
827
|
+
this.name = "\u672A\u652F\u6301\u7684\u6A21\u578B";
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// src/error/runtime-error/runtime-error.ts
|
|
832
|
+
var RuntimeError = class extends Error {
|
|
833
|
+
constructor(message) {
|
|
834
|
+
super(message);
|
|
835
|
+
this.message = message;
|
|
836
|
+
this.name = "Runtime Error";
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
// src/error/runtime-model-error/runtime-model-error.ts
|
|
841
|
+
var RuntimeModelError = class extends Error {
|
|
842
|
+
/**
|
|
843
|
+
* Creates an instance of DefectModelError.
|
|
844
|
+
*
|
|
845
|
+
* @author chitanda
|
|
846
|
+
* @date 2022-08-30 16:08:58
|
|
847
|
+
* @param {IModelObject} model 丢失配置的模型
|
|
848
|
+
* @param {string} [msg] 缺失配置描述
|
|
849
|
+
*/
|
|
850
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
851
|
+
constructor(model, msg) {
|
|
852
|
+
super(`\u300C${model.id}\u300D\u6A21\u578B${msg ? `\uFF1A ${msg}` : ""}`);
|
|
853
|
+
this.model = model;
|
|
854
|
+
this.name = "\u6A21\u578B\u914D\u7F6E\u7F3A\u5931";
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
// src/utils/util/util.ts
|
|
859
|
+
import { debounce as debounce2 } from "lodash-es";
|
|
860
|
+
import { getCookie } from "qx-util";
|
|
861
|
+
function getToken() {
|
|
862
|
+
return getCookie(CoreConst.TOKEN);
|
|
863
|
+
}
|
|
864
|
+
function isOverlap(arr1, arr2) {
|
|
865
|
+
const newArr = Array.from(/* @__PURE__ */ new Set([...arr1, ...arr2]));
|
|
866
|
+
return newArr.length !== arr1.length + arr2.length;
|
|
867
|
+
}
|
|
868
|
+
function debounceAndMerge(func, mergeFunc, wait) {
|
|
869
|
+
let oldParams;
|
|
870
|
+
const debounceFunc = debounce2((...params) => {
|
|
871
|
+
oldParams = void 0;
|
|
872
|
+
return func(...params);
|
|
873
|
+
}, wait);
|
|
874
|
+
return (...args) => {
|
|
875
|
+
let newParams = args;
|
|
876
|
+
if (oldParams) {
|
|
877
|
+
newParams = mergeFunc(oldParams, newParams);
|
|
878
|
+
}
|
|
879
|
+
oldParams = newParams;
|
|
880
|
+
return debounceFunc(...newParams);
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
function debounceAndAsyncMerge(func, mergeFunc, wait) {
|
|
884
|
+
let oldParams;
|
|
885
|
+
let promises = [];
|
|
886
|
+
const debounceFunc = debounce2(async (...params) => {
|
|
887
|
+
oldParams = void 0;
|
|
888
|
+
try {
|
|
889
|
+
const result = await func(...params);
|
|
890
|
+
promises.forEach((promise) => {
|
|
891
|
+
promise.resolve(result);
|
|
892
|
+
});
|
|
893
|
+
promises = [];
|
|
894
|
+
return result;
|
|
895
|
+
} catch (error) {
|
|
896
|
+
promises.forEach((promise) => {
|
|
897
|
+
promise.reject(error);
|
|
898
|
+
});
|
|
899
|
+
promises = [];
|
|
900
|
+
}
|
|
901
|
+
}, wait);
|
|
902
|
+
const fun = async (...args) => {
|
|
903
|
+
let newParams = args;
|
|
904
|
+
if (oldParams) {
|
|
905
|
+
newParams = mergeFunc(oldParams, newParams);
|
|
906
|
+
}
|
|
907
|
+
oldParams = newParams;
|
|
908
|
+
debounceFunc(...newParams);
|
|
909
|
+
return new Promise((resolve, reject) => {
|
|
910
|
+
promises.push({ resolve, reject });
|
|
911
|
+
});
|
|
912
|
+
};
|
|
913
|
+
return fun;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// src/utils/interceptor/interceptor.ts
|
|
917
|
+
var Interceptor = class {
|
|
918
|
+
/**
|
|
919
|
+
* 请求之前处理
|
|
920
|
+
*
|
|
921
|
+
* @author lxm
|
|
922
|
+
* @date 2022-10-27 17:10:41
|
|
923
|
+
* @protected
|
|
924
|
+
* @param {InternalAxiosRequestConfig} config
|
|
925
|
+
* @returns {*} {Promise<InternalAxiosRequestConfig>}
|
|
926
|
+
*/
|
|
927
|
+
async onBeforeRequest(config) {
|
|
928
|
+
return config;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* 请求失败之后处理
|
|
932
|
+
*
|
|
933
|
+
* @author lxm
|
|
934
|
+
* @date 2022-10-27 17:10:40
|
|
935
|
+
* @protected
|
|
936
|
+
* @param {*} error
|
|
937
|
+
*/
|
|
938
|
+
onRequestError(error) {
|
|
939
|
+
return Promise.reject(error);
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* 响应成功之后处理
|
|
943
|
+
*
|
|
944
|
+
* @author lxm
|
|
945
|
+
* @date 2022-10-27 17:10:38
|
|
946
|
+
* @protected
|
|
947
|
+
* @param {AxiosResponse} config
|
|
948
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
949
|
+
*/
|
|
950
|
+
async onResponseSuccess(config) {
|
|
951
|
+
return config;
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* 响应失败之后处理
|
|
955
|
+
*
|
|
956
|
+
* @author lxm
|
|
957
|
+
* @date 2022-10-27 17:10:37
|
|
958
|
+
* @protected
|
|
959
|
+
* @param {*} _error
|
|
960
|
+
*/
|
|
961
|
+
onResponseError(error) {
|
|
962
|
+
return Promise.reject(error);
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* 使用拦截器
|
|
966
|
+
*
|
|
967
|
+
* @author lxm
|
|
968
|
+
* @date 2022-10-27 17:10:28
|
|
969
|
+
* @param {AxiosInstance} instance
|
|
970
|
+
*/
|
|
971
|
+
use(instance) {
|
|
972
|
+
this.requestTag = instance.interceptors.request.use(
|
|
973
|
+
this.onBeforeRequest,
|
|
974
|
+
this.onRequestError
|
|
975
|
+
);
|
|
976
|
+
this.responseTag = instance.interceptors.response.use(
|
|
977
|
+
this.onResponseSuccess,
|
|
978
|
+
this.onResponseError
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* 移出拦截器
|
|
983
|
+
*
|
|
984
|
+
* @author lxm
|
|
985
|
+
* @date 2022-10-27 17:10:27
|
|
986
|
+
* @param {AxiosInstance} instance
|
|
987
|
+
*/
|
|
988
|
+
eject(instance) {
|
|
989
|
+
if (this.requestTag) {
|
|
990
|
+
instance.interceptors.request.eject(this.requestTag);
|
|
991
|
+
}
|
|
992
|
+
if (this.responseTag) {
|
|
993
|
+
instance.interceptors.response.eject(this.responseTag);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
// src/utils/interceptor/core-interceptor.ts
|
|
999
|
+
var CoreInterceptor = class extends Interceptor {
|
|
1000
|
+
async onBeforeRequest(config) {
|
|
1001
|
+
await super.onBeforeRequest(config);
|
|
1002
|
+
const { headers } = config;
|
|
1003
|
+
headers.set("Authorization", `Bearer ${getToken()}`);
|
|
1004
|
+
const { orgData } = ibiz;
|
|
1005
|
+
if (orgData) {
|
|
1006
|
+
if (orgData.systemid) {
|
|
1007
|
+
headers.set("srfsystemid", orgData.systemid);
|
|
1008
|
+
}
|
|
1009
|
+
if (orgData.orgid) {
|
|
1010
|
+
headers.set("srforgid", orgData.orgid);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return config;
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
// src/utils/logger/logger.ts
|
|
1018
|
+
var Logger = __toESM(require_loglevel(), 1);
|
|
1019
|
+
|
|
1020
|
+
// src/utils/namespace/namespace.ts
|
|
1021
|
+
var defaultNamespace = "ibiz";
|
|
1022
|
+
var statePrefix = "is-";
|
|
1023
|
+
function _bem(namespace, block, blockSuffix, element, modifier) {
|
|
1024
|
+
let cls = `${namespace}-${block}`;
|
|
1025
|
+
if (blockSuffix) {
|
|
1026
|
+
cls += `-${blockSuffix}`;
|
|
1027
|
+
}
|
|
1028
|
+
if (element) {
|
|
1029
|
+
cls += `__${element}`;
|
|
1030
|
+
}
|
|
1031
|
+
if (modifier) {
|
|
1032
|
+
cls += `--${modifier}`;
|
|
1033
|
+
}
|
|
1034
|
+
return cls;
|
|
1035
|
+
}
|
|
1036
|
+
var Namespace = class {
|
|
1037
|
+
/**
|
|
1038
|
+
* Creates an instance of Namespace.
|
|
1039
|
+
*
|
|
1040
|
+
* @author chitanda
|
|
1041
|
+
* @date 2022-09-06 12:09:12
|
|
1042
|
+
* @param {string} block 当前命名空间的根模块,例如组件的名称
|
|
1043
|
+
* @param {string} [namespace] 指定命名空间,未指定使用默认值 ibiz
|
|
1044
|
+
*/
|
|
1045
|
+
constructor(block, namespace) {
|
|
1046
|
+
this.block = block;
|
|
1047
|
+
this.namespace = namespace || defaultNamespace;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* namespace-block
|
|
1051
|
+
* namespace-block-blockSuffix
|
|
1052
|
+
*
|
|
1053
|
+
* @author chitanda
|
|
1054
|
+
* @date 2022-09-06 12:09:08
|
|
1055
|
+
* @param {string} [blockSuffix='']
|
|
1056
|
+
* @return {*} {string}
|
|
1057
|
+
*/
|
|
1058
|
+
b(blockSuffix = "") {
|
|
1059
|
+
return _bem(this.namespace, this.block, blockSuffix, "", "");
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* namespace-block__element
|
|
1063
|
+
*
|
|
1064
|
+
* @author chitanda
|
|
1065
|
+
* @date 2022-09-06 12:09:48
|
|
1066
|
+
* @param {string} [element]
|
|
1067
|
+
* @return {*} {string}
|
|
1068
|
+
*/
|
|
1069
|
+
e(element) {
|
|
1070
|
+
return element ? _bem(this.namespace, this.block, "", element, "") : "";
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* namespace-block--modifier
|
|
1074
|
+
*
|
|
1075
|
+
* @author chitanda
|
|
1076
|
+
* @date 2022-09-06 12:09:37
|
|
1077
|
+
* @param {string} [modifier]
|
|
1078
|
+
* @return {*} {string}
|
|
1079
|
+
*/
|
|
1080
|
+
m(modifier) {
|
|
1081
|
+
return modifier ? _bem(this.namespace, this.block, "", "", modifier) : "";
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* namespace-block-blockSuffix__element
|
|
1085
|
+
*
|
|
1086
|
+
* @author chitanda
|
|
1087
|
+
* @date 2022-09-06 12:09:52
|
|
1088
|
+
* @param {string} [blockSuffix]
|
|
1089
|
+
* @param {string} [element]
|
|
1090
|
+
* @return {*} {string}
|
|
1091
|
+
*/
|
|
1092
|
+
be(blockSuffix, element) {
|
|
1093
|
+
return blockSuffix && element ? _bem(this.namespace, this.block, blockSuffix, element, "") : "";
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* namespace-block__element--modifier
|
|
1097
|
+
*
|
|
1098
|
+
* @author chitanda
|
|
1099
|
+
* @date 2022-09-06 12:09:19
|
|
1100
|
+
* @param {string} [element]
|
|
1101
|
+
* @param {string} [modifier]
|
|
1102
|
+
* @return {*} {string}
|
|
1103
|
+
*/
|
|
1104
|
+
em(element, modifier) {
|
|
1105
|
+
return element && modifier ? _bem(this.namespace, this.block, "", element, modifier) : "";
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* namespace-block-blockSuffix--modifier
|
|
1109
|
+
*
|
|
1110
|
+
* @author chitanda
|
|
1111
|
+
* @date 2022-09-06 12:09:59
|
|
1112
|
+
* @param {string} [blockSuffix]
|
|
1113
|
+
* @param {string} [modifier]
|
|
1114
|
+
* @return {*} {string}
|
|
1115
|
+
*/
|
|
1116
|
+
bm(blockSuffix, modifier) {
|
|
1117
|
+
return blockSuffix && modifier ? _bem(this.namespace, this.block, blockSuffix, "", modifier) : "";
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* namespace-block-blockSuffix__element--modifier
|
|
1121
|
+
*
|
|
1122
|
+
* @author chitanda
|
|
1123
|
+
* @date 2022-09-06 12:09:37
|
|
1124
|
+
* @param {string} [blockSuffix]
|
|
1125
|
+
* @param {string} [element]
|
|
1126
|
+
* @param {string} [modifier]
|
|
1127
|
+
* @return {*} {string}
|
|
1128
|
+
*/
|
|
1129
|
+
bem(blockSuffix, element, modifier) {
|
|
1130
|
+
return blockSuffix && element && modifier ? _bem(this.namespace, this.block, blockSuffix, element, modifier) : "";
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* 返回状态 class
|
|
1134
|
+
*
|
|
1135
|
+
* is('loading', false) => '';
|
|
1136
|
+
* is('loading', true) => 'is-loading';
|
|
1137
|
+
*
|
|
1138
|
+
* @author chitanda
|
|
1139
|
+
* @date 2022-09-06 12:09:57
|
|
1140
|
+
* @param {string} name
|
|
1141
|
+
* @param {boolean} [state]
|
|
1142
|
+
* @return {*} {string}
|
|
1143
|
+
*/
|
|
1144
|
+
is(name, state) {
|
|
1145
|
+
return name && state ? `${statePrefix}${name}` : "";
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* 生成使用到的 css 变量 style 对象
|
|
1149
|
+
*
|
|
1150
|
+
* @author chitanda
|
|
1151
|
+
* @date 2022-09-06 15:09:41
|
|
1152
|
+
* @param {Record<string, string>} object
|
|
1153
|
+
* @return {*} {Record<string, string>}
|
|
1154
|
+
*/
|
|
1155
|
+
cssVar(object) {
|
|
1156
|
+
const styles = {};
|
|
1157
|
+
for (const key in object) {
|
|
1158
|
+
if (object[key]) {
|
|
1159
|
+
styles[this.cssVarName(key)] = object[key];
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return styles;
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* 生成使用到的 css block 变量 style 对象
|
|
1166
|
+
*
|
|
1167
|
+
* @author chitanda
|
|
1168
|
+
* @date 2022-09-06 15:09:03
|
|
1169
|
+
* @param {Record<string, string>} object
|
|
1170
|
+
* @return {*} {Record<string, string>}
|
|
1171
|
+
*/
|
|
1172
|
+
cssVarBlock(object) {
|
|
1173
|
+
const styles = {};
|
|
1174
|
+
for (const key in object) {
|
|
1175
|
+
if (object[key]) {
|
|
1176
|
+
styles[this.cssVarBlockName(key)] = object[key];
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
return styles;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* 生成 css var 变量名称
|
|
1183
|
+
*
|
|
1184
|
+
* @author chitanda
|
|
1185
|
+
* @date 2022-09-06 15:09:21
|
|
1186
|
+
* @param {string} name
|
|
1187
|
+
* @return {*} {string}
|
|
1188
|
+
*/
|
|
1189
|
+
cssVarName(name) {
|
|
1190
|
+
return `--${this.namespace}-${name}`;
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* 生成块 css var 变量名称
|
|
1194
|
+
*
|
|
1195
|
+
* @author chitanda
|
|
1196
|
+
* @date 2022-09-06 15:09:35
|
|
1197
|
+
* @param {string} name
|
|
1198
|
+
* @return {*} {string}
|
|
1199
|
+
*/
|
|
1200
|
+
cssVarBlockName(name) {
|
|
1201
|
+
return `--${this.namespace}-${this.block}-${name}`;
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
|
|
1205
|
+
// src/utils/net/http-response.ts
|
|
1206
|
+
import {
|
|
1207
|
+
AxiosHeaders
|
|
1208
|
+
} from "axios";
|
|
1209
|
+
var HttpResponse = class {
|
|
1210
|
+
/**
|
|
1211
|
+
* Creates an instance of HttpResponse.
|
|
1212
|
+
*
|
|
1213
|
+
* @author chitanda
|
|
1214
|
+
* @date 2022-08-18 15:08:11
|
|
1215
|
+
* @param {unknown} [data] 返回的数据
|
|
1216
|
+
* @param {number} [status] 状态码 (默认为 200)
|
|
1217
|
+
* @param {string} [statusText] 状态描述 (默认为空字符)
|
|
1218
|
+
*/
|
|
1219
|
+
constructor(data, status, statusText) {
|
|
1220
|
+
/**
|
|
1221
|
+
* 本地仿造响应
|
|
1222
|
+
*
|
|
1223
|
+
* @author chitanda
|
|
1224
|
+
* @date 2022-08-18 15:08:06
|
|
1225
|
+
*/
|
|
1226
|
+
this.local = true;
|
|
1227
|
+
this.ok = false;
|
|
1228
|
+
this.headers = {};
|
|
1229
|
+
this.config = {
|
|
1230
|
+
headers: new AxiosHeaders()
|
|
1231
|
+
};
|
|
1232
|
+
this.data = data;
|
|
1233
|
+
this.status = status || 200;
|
|
1234
|
+
this.statusText = statusText || "";
|
|
1235
|
+
if (this.status >= 200 && this.status < 300) {
|
|
1236
|
+
this.ok = true;
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
|
|
1241
|
+
// src/utils/net/net.ts
|
|
1242
|
+
import axios from "axios";
|
|
1243
|
+
import { merge } from "lodash-es";
|
|
1244
|
+
import { stringify } from "qs";
|
|
1245
|
+
import { notNilEmpty } from "qx-util";
|
|
1246
|
+
var Net = class {
|
|
1247
|
+
/**
|
|
1248
|
+
* Creates an instance of Net.
|
|
1249
|
+
* @author lxm
|
|
1250
|
+
* @date 2022-10-27 16:10:05
|
|
1251
|
+
* @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
|
|
1252
|
+
*/
|
|
1253
|
+
constructor(config) {
|
|
1254
|
+
/**
|
|
1255
|
+
* 是否为 http || https 开头
|
|
1256
|
+
*
|
|
1257
|
+
* @author chitanda
|
|
1258
|
+
* @date 2022-11-07 14:11:28
|
|
1259
|
+
* @protected
|
|
1260
|
+
*/
|
|
1261
|
+
this.urlReg = /^http[s]?:\/\/[^\s]*/;
|
|
1262
|
+
/**
|
|
1263
|
+
* 注册的拦截器
|
|
1264
|
+
*
|
|
1265
|
+
* @author lxm
|
|
1266
|
+
* @date 2022-10-27 17:10:18
|
|
1267
|
+
* @type {Map<string, Interceptor>}
|
|
1268
|
+
*/
|
|
1269
|
+
this.interceptors = /* @__PURE__ */ new Map();
|
|
1270
|
+
this.instance = axios.create(config);
|
|
1271
|
+
this.addInterceptor("Default", new CoreInterceptor());
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* 添加拦截器
|
|
1275
|
+
*
|
|
1276
|
+
* @author lxm
|
|
1277
|
+
* @date 2022-10-27 17:10:42
|
|
1278
|
+
* @param {string} name 唯一标识
|
|
1279
|
+
* @param {Interceptor} interceptor 拦截器
|
|
1280
|
+
*/
|
|
1281
|
+
addInterceptor(name, interceptor) {
|
|
1282
|
+
interceptor.use(this.instance);
|
|
1283
|
+
this.interceptors.set(name, interceptor);
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* 删除拦截器
|
|
1287
|
+
*
|
|
1288
|
+
* @author lxm
|
|
1289
|
+
* @date 2022-10-27 17:10:27
|
|
1290
|
+
* @param {string} name 唯一标识
|
|
1291
|
+
*/
|
|
1292
|
+
removeInterceptor(name) {
|
|
1293
|
+
const interceptor = this.interceptors.get(name);
|
|
1294
|
+
if (interceptor) {
|
|
1295
|
+
interceptor.eject(this.instance);
|
|
1296
|
+
this.interceptors.delete(name);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* 预置config,绑定动态的配置
|
|
1301
|
+
*
|
|
1302
|
+
* @author lxm
|
|
1303
|
+
* @date 2022-10-27 16:10:48
|
|
1304
|
+
* @readonly
|
|
1305
|
+
* @protected
|
|
1306
|
+
* @type {AxiosRequestConfig}
|
|
1307
|
+
*/
|
|
1308
|
+
get presetConfig() {
|
|
1309
|
+
return {
|
|
1310
|
+
// 请求前缀路径
|
|
1311
|
+
baseURL: this.instance.defaults.baseURL || `${ibiz.env.baseUrl}/${ibiz.env.appId}`,
|
|
1312
|
+
headers: {
|
|
1313
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
1314
|
+
Accept: "application/json"
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* 从左到右递归合并配置参数(内置第一个合并的预置参数)
|
|
1320
|
+
*
|
|
1321
|
+
* @author lxm
|
|
1322
|
+
* @date 2022-10-27 16:10:09
|
|
1323
|
+
* @protected
|
|
1324
|
+
* @param {...AxiosRequestConfig[]} configs
|
|
1325
|
+
* @returns {*}
|
|
1326
|
+
*/
|
|
1327
|
+
mergeConfig(...configs) {
|
|
1328
|
+
const config = this.presetConfig;
|
|
1329
|
+
if (configs.length === 0) {
|
|
1330
|
+
return config;
|
|
1331
|
+
}
|
|
1332
|
+
const { url } = configs[0];
|
|
1333
|
+
if (url && this.urlReg.test(url)) {
|
|
1334
|
+
delete config.baseURL;
|
|
1335
|
+
}
|
|
1336
|
+
return merge(config, ...configs);
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Post 请求
|
|
1340
|
+
*
|
|
1341
|
+
* @author chitanda
|
|
1342
|
+
* @date 2022-10-19 11:10:30
|
|
1343
|
+
* @param {string} url
|
|
1344
|
+
* @param {IData} data
|
|
1345
|
+
* @param {IParams} [params={}]
|
|
1346
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
1347
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
1348
|
+
*/
|
|
1349
|
+
async post(url, data, params = {}, headers = {}) {
|
|
1350
|
+
url = this.handleAppPresetParam(url, params);
|
|
1351
|
+
try {
|
|
1352
|
+
const response = await this.request(url, {
|
|
1353
|
+
method: "post",
|
|
1354
|
+
data,
|
|
1355
|
+
headers
|
|
1356
|
+
});
|
|
1357
|
+
return this.doResponseResult(response);
|
|
1358
|
+
} catch (error) {
|
|
1359
|
+
throw new HttpError(error);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Get 请求
|
|
1364
|
+
*
|
|
1365
|
+
* @author chitanda
|
|
1366
|
+
* @date 2022-10-19 11:10:24
|
|
1367
|
+
* @param {string} url
|
|
1368
|
+
* @param {IParams} [params={}]
|
|
1369
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
1370
|
+
* @param {IParams} [option={}]
|
|
1371
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
1372
|
+
*/
|
|
1373
|
+
async get(url, params = {}, headers = {}, option = {}) {
|
|
1374
|
+
url = this.attachUrlParam(url, params);
|
|
1375
|
+
try {
|
|
1376
|
+
const response = await this.request(
|
|
1377
|
+
url,
|
|
1378
|
+
merge({ method: "get", headers }, option)
|
|
1379
|
+
);
|
|
1380
|
+
return this.doResponseResult(response);
|
|
1381
|
+
} catch (error) {
|
|
1382
|
+
throw new HttpError(error);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* Delete 请求
|
|
1387
|
+
*
|
|
1388
|
+
* @author chitanda
|
|
1389
|
+
* @date 2022-10-19 11:10:17
|
|
1390
|
+
* @param {string} url
|
|
1391
|
+
* @param {IParams} [params]
|
|
1392
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
1393
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
1394
|
+
*/
|
|
1395
|
+
async delete(url, params, headers = {}) {
|
|
1396
|
+
url = this.handleAppPresetParam(url, params);
|
|
1397
|
+
try {
|
|
1398
|
+
const response = await this.request(url, { method: "delete", headers });
|
|
1399
|
+
return this.doResponseResult(response);
|
|
1400
|
+
} catch (error) {
|
|
1401
|
+
throw new HttpError(error);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Put 请求
|
|
1406
|
+
*
|
|
1407
|
+
* @author chitanda
|
|
1408
|
+
* @date 2022-10-19 11:10:11
|
|
1409
|
+
* @param {string} url
|
|
1410
|
+
* @param {IData} data
|
|
1411
|
+
* @param {IParams} [params={}]
|
|
1412
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
1413
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
1414
|
+
*/
|
|
1415
|
+
async put(url, data, params = {}, headers = {}) {
|
|
1416
|
+
url = this.handleAppPresetParam(url, params);
|
|
1417
|
+
try {
|
|
1418
|
+
const response = await this.request(url, {
|
|
1419
|
+
method: "put",
|
|
1420
|
+
data,
|
|
1421
|
+
headers
|
|
1422
|
+
});
|
|
1423
|
+
return this.doResponseResult(response);
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
throw new HttpError(error);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* 获取模型数据
|
|
1430
|
+
*
|
|
1431
|
+
* @author chitanda
|
|
1432
|
+
* @date 2022-07-14 15:07:15
|
|
1433
|
+
* @param {string} url
|
|
1434
|
+
* @param {RawAxiosRequestHeaders} [headers={}]
|
|
1435
|
+
* @return {*} {Promise<IHttpResponse>}
|
|
1436
|
+
*/
|
|
1437
|
+
async getModel(url, headers = {}) {
|
|
1438
|
+
try {
|
|
1439
|
+
const response = await this.instance.get(url, {
|
|
1440
|
+
headers
|
|
1441
|
+
});
|
|
1442
|
+
return this.doResponseResult(response);
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
throw new HttpError(error);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* 基础请求方法,会合并预置配置
|
|
1449
|
+
*
|
|
1450
|
+
* @author lxm
|
|
1451
|
+
* @date 2022-10-27 14:10:06
|
|
1452
|
+
* @param {string} url
|
|
1453
|
+
* @param {AxiosRequestConfig} [config={}]
|
|
1454
|
+
* @returns {*} {Promise<IHttpResponse>}
|
|
1455
|
+
*/
|
|
1456
|
+
async request(url, config = {}) {
|
|
1457
|
+
try {
|
|
1458
|
+
const response = await this.instance.request(
|
|
1459
|
+
this.mergeConfig({ url }, config)
|
|
1460
|
+
);
|
|
1461
|
+
return this.doResponseResult(response);
|
|
1462
|
+
} catch (error) {
|
|
1463
|
+
throw new HttpError(error);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
* 创建标准 axios 请求
|
|
1468
|
+
*
|
|
1469
|
+
* @author chitanda
|
|
1470
|
+
* @date 2023-01-30 15:01:27
|
|
1471
|
+
* @param {AxiosRequestConfig<IData>} config
|
|
1472
|
+
* @return {*}
|
|
1473
|
+
*/
|
|
1474
|
+
axios(config) {
|
|
1475
|
+
return axios(config);
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* 统一处理请求返回
|
|
1479
|
+
*
|
|
1480
|
+
* @author chitanda
|
|
1481
|
+
* @date 2022-07-14 16:07:23
|
|
1482
|
+
* @private
|
|
1483
|
+
* @param {AxiosResponse} response
|
|
1484
|
+
* @return {*} {IHttpResponse}
|
|
1485
|
+
*/
|
|
1486
|
+
doResponseResult(response) {
|
|
1487
|
+
const res = response;
|
|
1488
|
+
if (res.status >= 200 && res.status <= 299) {
|
|
1489
|
+
res.ok = true;
|
|
1490
|
+
}
|
|
1491
|
+
return res;
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* 处理平台预定义参数
|
|
1495
|
+
*
|
|
1496
|
+
* @author chitanda
|
|
1497
|
+
* @date 2022-07-14 15:07:12
|
|
1498
|
+
* @private
|
|
1499
|
+
* @param {string} url
|
|
1500
|
+
* @param {IParams} [params]
|
|
1501
|
+
* @return {*} {string}
|
|
1502
|
+
*/
|
|
1503
|
+
handleAppPresetParam(url, params) {
|
|
1504
|
+
if (params) {
|
|
1505
|
+
const keys = Object.keys(params);
|
|
1506
|
+
const tempParam = {};
|
|
1507
|
+
keys.forEach((item) => {
|
|
1508
|
+
if (item.startsWith("srf") && notNilEmpty(params[item])) {
|
|
1509
|
+
tempParam[item] = params[item];
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
return this.attachUrlParam(url, params);
|
|
1513
|
+
}
|
|
1514
|
+
return url;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* url 附加请求参数
|
|
1518
|
+
*
|
|
1519
|
+
* @author chitanda
|
|
1520
|
+
* @date 2022-07-14 15:07:34
|
|
1521
|
+
* @private
|
|
1522
|
+
* @param {string} url
|
|
1523
|
+
* @param {IParams} params
|
|
1524
|
+
* @return {*} {string}
|
|
1525
|
+
*/
|
|
1526
|
+
attachUrlParam(url, params) {
|
|
1527
|
+
const strParams = stringify(params);
|
|
1528
|
+
if (notNilEmpty(strParams)) {
|
|
1529
|
+
if (url.endsWith("?")) {
|
|
1530
|
+
url = `${url}${strParams}`;
|
|
1531
|
+
} else if (url.indexOf("?") !== -1 && url.endsWith("&")) {
|
|
1532
|
+
url = `${url}${strParams}`;
|
|
1533
|
+
} else if (url.indexOf("?") !== -1 && !url.endsWith("&")) {
|
|
1534
|
+
url = `${url}&${strParams}`;
|
|
1535
|
+
} else {
|
|
1536
|
+
url = `${url}?${strParams}`;
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
return url;
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1543
|
+
// src/utils/string-util/string-util.ts
|
|
1544
|
+
import { notNilEmpty as notNilEmpty2 } from "qx-util";
|
|
1545
|
+
var StringUtil = class {
|
|
1546
|
+
/**
|
|
1547
|
+
* 填充字符串中的数据
|
|
1548
|
+
*
|
|
1549
|
+
* @author chitanda
|
|
1550
|
+
* @date 2021-04-23 20:04:17
|
|
1551
|
+
* @static
|
|
1552
|
+
* @param {string} str
|
|
1553
|
+
* @param {*} [context]
|
|
1554
|
+
* @param {*} [data]
|
|
1555
|
+
* @return {*} {string}
|
|
1556
|
+
*/
|
|
1557
|
+
static fill(str, context, data) {
|
|
1558
|
+
if (notNilEmpty2(str)) {
|
|
1559
|
+
if (notNilEmpty2(context)) {
|
|
1560
|
+
const strArr = str.match(this.contextReg);
|
|
1561
|
+
strArr == null ? void 0 : strArr.forEach((_key) => {
|
|
1562
|
+
const key = _key.slice(10, _key.length - 1);
|
|
1563
|
+
str = str.replace(`\${context.${key}}`, context[key] || "");
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
if (notNilEmpty2(data)) {
|
|
1567
|
+
const strArr = str.match(this.dataReg);
|
|
1568
|
+
strArr == null ? void 0 : strArr.forEach((_key) => {
|
|
1569
|
+
const key = _key.slice(7, _key.length - 1);
|
|
1570
|
+
str = str.replace(`\${data.${key}}`, data[key] || "");
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
return str;
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
/**
|
|
1578
|
+
* 上下文替换正则
|
|
1579
|
+
*
|
|
1580
|
+
* @author chitanda
|
|
1581
|
+
* @date 2021-04-23 20:04:01
|
|
1582
|
+
* @static
|
|
1583
|
+
*/
|
|
1584
|
+
StringUtil.contextReg = /\$\{context.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
|
|
1585
|
+
/**
|
|
1586
|
+
* 数据替换正则
|
|
1587
|
+
*
|
|
1588
|
+
* @author chitanda
|
|
1589
|
+
* @date 2021-04-23 20:04:09
|
|
1590
|
+
* @static
|
|
1591
|
+
*/
|
|
1592
|
+
StringUtil.dataReg = /\$\{data.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
|
|
1593
|
+
|
|
1594
|
+
// src/utils/url-helper/url-helper.ts
|
|
1595
|
+
var UrlHelper = class {
|
|
1596
|
+
/**
|
|
1597
|
+
* 路由路径前面的基础路径
|
|
1598
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
1599
|
+
* 返回:http://172.16.103.120:30061/portalwebapp/#
|
|
1600
|
+
*
|
|
1601
|
+
* @author lxm
|
|
1602
|
+
* @date 2022-10-11 20:10:29
|
|
1603
|
+
* @returns {*}
|
|
1604
|
+
*/
|
|
1605
|
+
static get routeBase() {
|
|
1606
|
+
return `${this.appBase}/#`;
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* 应用的的基础路径
|
|
1610
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
1611
|
+
* 返回:http://172.16.103.120:30061/portalwebapp
|
|
1612
|
+
*
|
|
1613
|
+
* @author lxm
|
|
1614
|
+
* @date 2022-10-11 20:10:29
|
|
1615
|
+
* @returns {*}
|
|
1616
|
+
*/
|
|
1617
|
+
static get appBase() {
|
|
1618
|
+
const { origin, pathname } = window.location;
|
|
1619
|
+
return `${origin}${pathname}`.replace(/\/$/, "");
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* #开始到末尾,即路由地址
|
|
1623
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
1624
|
+
* 返回:/index/appportalview?params=123
|
|
1625
|
+
*
|
|
1626
|
+
* @author lxm
|
|
1627
|
+
* @date 2022-10-11 16:10:40
|
|
1628
|
+
* @returns {*}
|
|
1629
|
+
*/
|
|
1630
|
+
static get routePath() {
|
|
1631
|
+
return window.location.hash.replace("#", "");
|
|
1632
|
+
}
|
|
1633
|
+
/**
|
|
1634
|
+
* 当前地址的全路径,包含域名和参数
|
|
1635
|
+
* 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
|
|
1636
|
+
*
|
|
1637
|
+
* @author lxm
|
|
1638
|
+
* @date 2022-10-11 21:10:39
|
|
1639
|
+
* @readonly
|
|
1640
|
+
* @static
|
|
1641
|
+
*/
|
|
1642
|
+
static get fullPath() {
|
|
1643
|
+
return window.location.href;
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
|
|
1647
|
+
// src/utils/event/event.ts
|
|
1648
|
+
function eventPath(event) {
|
|
1649
|
+
const path = event.composedPath && event.composedPath() || event.path;
|
|
1650
|
+
if (path != null)
|
|
1651
|
+
return path;
|
|
1652
|
+
function getParents(node, memo = []) {
|
|
1653
|
+
const parentNode = node.parentNode;
|
|
1654
|
+
return parentNode ? getParents(parentNode, memo.concat([parentNode])) : memo;
|
|
1655
|
+
}
|
|
1656
|
+
return [event.target].concat(getParents(event.target));
|
|
1657
|
+
}
|
|
1658
|
+
function listenJSEvent(target, eventName, listener, options = {}) {
|
|
1659
|
+
target.addEventListener(eventName, listener, options);
|
|
1660
|
+
let cleanup = () => {
|
|
1661
|
+
target.removeEventListener(eventName, listener, options);
|
|
1662
|
+
cleanup = NOOP;
|
|
1663
|
+
};
|
|
1664
|
+
return () => {
|
|
1665
|
+
cleanup();
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
function isEventInside(event, el) {
|
|
1669
|
+
return el && (event.target === el || eventPath(event).includes(el));
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
// src/utils/click-outside/click-outside.ts
|
|
1673
|
+
var defaultWindow = typeof window !== "undefined" ? window : void 0;
|
|
1674
|
+
function onClickOutside(target, handler, options = {}) {
|
|
1675
|
+
const { window: window2 = defaultWindow, ignore = [], capture = true } = options;
|
|
1676
|
+
if (!target)
|
|
1677
|
+
throw new RuntimeError("target\u5143\u7D20\u4E0D\u5B58\u5728");
|
|
1678
|
+
if (!window2)
|
|
1679
|
+
throw new RuntimeError("\u627E\u4E0D\u5230window");
|
|
1680
|
+
let shouldListen = true;
|
|
1681
|
+
const isOutside = (event) => {
|
|
1682
|
+
return ![target, ...ignore].some((el) => {
|
|
1683
|
+
return isEventInside(event, el);
|
|
1684
|
+
});
|
|
1685
|
+
};
|
|
1686
|
+
let isPaused = false;
|
|
1687
|
+
const pause = () => {
|
|
1688
|
+
isPaused = true;
|
|
1689
|
+
};
|
|
1690
|
+
const proceed = () => {
|
|
1691
|
+
isPaused = false;
|
|
1692
|
+
};
|
|
1693
|
+
let fallback;
|
|
1694
|
+
const listener = (event) => {
|
|
1695
|
+
if (isPaused)
|
|
1696
|
+
return;
|
|
1697
|
+
window2.clearTimeout(fallback);
|
|
1698
|
+
if (!(shouldListen && isOutside(event)))
|
|
1699
|
+
return;
|
|
1700
|
+
handler(event);
|
|
1701
|
+
};
|
|
1702
|
+
const cleanups = [
|
|
1703
|
+
listenJSEvent(window2, "click", listener, { passive: true, capture }),
|
|
1704
|
+
listenJSEvent(
|
|
1705
|
+
window2,
|
|
1706
|
+
"pointerdown",
|
|
1707
|
+
(e) => {
|
|
1708
|
+
if (isPaused)
|
|
1709
|
+
return;
|
|
1710
|
+
shouldListen = isOutside(e);
|
|
1711
|
+
},
|
|
1712
|
+
{ passive: true }
|
|
1713
|
+
),
|
|
1714
|
+
listenJSEvent(
|
|
1715
|
+
window2,
|
|
1716
|
+
"pointerup",
|
|
1717
|
+
(e) => {
|
|
1718
|
+
if (isPaused)
|
|
1719
|
+
return;
|
|
1720
|
+
if (e.button === 0) {
|
|
1721
|
+
const path = eventPath(e);
|
|
1722
|
+
e.composedPath = () => path;
|
|
1723
|
+
fallback = window2.setTimeout(() => listener(e), 50);
|
|
1724
|
+
}
|
|
1725
|
+
},
|
|
1726
|
+
{ passive: true }
|
|
1727
|
+
)
|
|
1728
|
+
].filter(Boolean);
|
|
1729
|
+
const stop = () => cleanups.forEach((fn) => fn());
|
|
1730
|
+
return { stop, pause, proceed };
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// src/utils/color/color.ts
|
|
1734
|
+
var r = Math.round;
|
|
1735
|
+
function toRGBA(color) {
|
|
1736
|
+
const l = color.length;
|
|
1737
|
+
const rgba = [];
|
|
1738
|
+
if (color.slice(0, 3).toLowerCase() === "rgb") {
|
|
1739
|
+
const d = color.match(/([\d|.%]{1,3})/g);
|
|
1740
|
+
rgba[0] = parseInt(d[0], 10);
|
|
1741
|
+
rgba[1] = parseInt(d[1], 10);
|
|
1742
|
+
rgba[2] = parseInt(d[2], 10);
|
|
1743
|
+
rgba[3] = d[3] ? d[3].indexOf("%") !== -1 ? parseInt(d[3], 10) / 100 : parseFloat(d[3]) : 1;
|
|
1744
|
+
} else {
|
|
1745
|
+
let d;
|
|
1746
|
+
if (l < 6)
|
|
1747
|
+
d = parseInt(
|
|
1748
|
+
String(color[1]) + color[1] + color[2] + color[2] + color[3] + color[3] + (l > 4 ? String(color[4]) + color[4] : ""),
|
|
1749
|
+
16
|
|
1750
|
+
);
|
|
1751
|
+
else
|
|
1752
|
+
d = parseInt(color.slice(1), 16);
|
|
1753
|
+
rgba[0] = d >> 16 & 255;
|
|
1754
|
+
rgba[1] = d >> 8 & 255;
|
|
1755
|
+
rgba[2] = d & 255;
|
|
1756
|
+
rgba[3] = l === 9 || l === 5 ? r((d >> 24 & 255) / 255 * 1e4) / 1e4 : 1;
|
|
1757
|
+
}
|
|
1758
|
+
return rgba;
|
|
1759
|
+
}
|
|
1760
|
+
function colorBlend(color1, color2, p = 0.5, format = "hex") {
|
|
1761
|
+
color1 = color1.trim();
|
|
1762
|
+
color2 = color2.trim();
|
|
1763
|
+
const c1 = toRGBA(color1);
|
|
1764
|
+
const c2 = toRGBA(color2);
|
|
1765
|
+
const result = [
|
|
1766
|
+
r((1 - p) * c1[0] + p * c2[0]),
|
|
1767
|
+
r((1 - p) * c1[1] + p * c2[1]),
|
|
1768
|
+
r((1 - p) * c1[2] + p * c2[2]),
|
|
1769
|
+
(1 - p) * c1[3] + p * c2[3]
|
|
1770
|
+
];
|
|
1771
|
+
if (format === "hex") {
|
|
1772
|
+
const hex = [
|
|
1773
|
+
result[0].toString(16),
|
|
1774
|
+
result[1].toString(16),
|
|
1775
|
+
result[2].toString(16),
|
|
1776
|
+
result[3] === 0 ? "00" : r(result[3] * 255).toString(16)
|
|
1777
|
+
];
|
|
1778
|
+
return `#${hex[0]}${hex[1]}${hex[2]}${hex[3]}`;
|
|
1779
|
+
}
|
|
1780
|
+
return `rgb(${result[0]} ${result[1]} ${result[2]} / ${result[3]})`;
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// src/utils/download-file/download-file.ts
|
|
1784
|
+
function calcMimeByFileName(fileName) {
|
|
1785
|
+
const ext = fileName.split(".").pop();
|
|
1786
|
+
let mime = "";
|
|
1787
|
+
switch (ext) {
|
|
1788
|
+
case ".wps":
|
|
1789
|
+
mime = "application/kswps";
|
|
1790
|
+
break;
|
|
1791
|
+
case ".doc":
|
|
1792
|
+
mime = "application/msword";
|
|
1793
|
+
break;
|
|
1794
|
+
case ".docx":
|
|
1795
|
+
mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
1796
|
+
break;
|
|
1797
|
+
case ".txt":
|
|
1798
|
+
mime = "text/plain";
|
|
1799
|
+
break;
|
|
1800
|
+
case ".zip":
|
|
1801
|
+
mime = "application/zip";
|
|
1802
|
+
break;
|
|
1803
|
+
case ".png":
|
|
1804
|
+
mime = "image/png";
|
|
1805
|
+
break;
|
|
1806
|
+
case ".gif":
|
|
1807
|
+
mime = "image/gif";
|
|
1808
|
+
break;
|
|
1809
|
+
case ".jpeg":
|
|
1810
|
+
mime = "image/jpeg";
|
|
1811
|
+
break;
|
|
1812
|
+
case ".jpg":
|
|
1813
|
+
mime = "image/jpeg";
|
|
1814
|
+
break;
|
|
1815
|
+
case ".rtf":
|
|
1816
|
+
mime = "application/rtf";
|
|
1817
|
+
break;
|
|
1818
|
+
case ".avi":
|
|
1819
|
+
mime = "video/x-msvideo";
|
|
1820
|
+
break;
|
|
1821
|
+
case ".gz":
|
|
1822
|
+
mime = "application/x-gzip";
|
|
1823
|
+
break;
|
|
1824
|
+
case ".tar":
|
|
1825
|
+
mime = "application/x-tar";
|
|
1826
|
+
break;
|
|
1827
|
+
case ".xlsx":
|
|
1828
|
+
mime = "application/vnd.ms-excel";
|
|
1829
|
+
break;
|
|
1830
|
+
default:
|
|
1831
|
+
mime = "";
|
|
1832
|
+
}
|
|
1833
|
+
return mime;
|
|
1834
|
+
}
|
|
1835
|
+
function isImage(fileName) {
|
|
1836
|
+
const ext = fileName.split(".").pop();
|
|
1837
|
+
if (!ext) {
|
|
1838
|
+
return false;
|
|
1839
|
+
}
|
|
1840
|
+
const imageTypes = [".jpeg", "jpg", "gif", "png", "bmp", "svg"];
|
|
1841
|
+
return imageTypes.includes(ext);
|
|
1842
|
+
}
|
|
1843
|
+
function downloadFileFromBlob(file, fileName) {
|
|
1844
|
+
const filetype = calcMimeByFileName(fileName);
|
|
1845
|
+
const blob = new Blob([file], { type: filetype });
|
|
1846
|
+
const href = URL.createObjectURL(blob);
|
|
1847
|
+
const a = document.createElement("a");
|
|
1848
|
+
a.href = href;
|
|
1849
|
+
a.download = fileName;
|
|
1850
|
+
document.body.appendChild(a);
|
|
1851
|
+
a.click();
|
|
1852
|
+
document.body.removeChild(a);
|
|
1853
|
+
URL.revokeObjectURL(href);
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
// src/utils/upload/select-file.ts
|
|
1857
|
+
import { merge as merge2 } from "lodash-es";
|
|
1858
|
+
function fileListToArr(fileList) {
|
|
1859
|
+
const files = [];
|
|
1860
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
1861
|
+
files.push(fileList[i]);
|
|
1862
|
+
}
|
|
1863
|
+
return files;
|
|
1864
|
+
}
|
|
1865
|
+
function selectFile(_opts) {
|
|
1866
|
+
const opts = merge2(
|
|
1867
|
+
{
|
|
1868
|
+
multiple: true,
|
|
1869
|
+
accept: ""
|
|
1870
|
+
},
|
|
1871
|
+
_opts
|
|
1872
|
+
);
|
|
1873
|
+
const input = document.createElement("input");
|
|
1874
|
+
input.setAttribute("type", "file");
|
|
1875
|
+
input.setAttribute("multiple", `${opts.multiple}`);
|
|
1876
|
+
input.setAttribute("accept", opts.accept);
|
|
1877
|
+
input.onchange = (e) => {
|
|
1878
|
+
const inputEl = e.target;
|
|
1879
|
+
const files = inputEl.files ? fileListToArr(inputEl.files) : [];
|
|
1880
|
+
if (files.length === 0) {
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
opts.onSelected(files);
|
|
1884
|
+
inputEl.value = "";
|
|
1885
|
+
};
|
|
1886
|
+
document.body.appendChild(input);
|
|
1887
|
+
input.click();
|
|
1888
|
+
document.body.removeChild(input);
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
// src/utils/upload/upload-file.ts
|
|
1892
|
+
import { cloneDeep, isFunction, merge as merge3, round, uniqueId } from "lodash-es";
|
|
1893
|
+
function uploadFile(_opts) {
|
|
1894
|
+
const opts = merge3(
|
|
1895
|
+
{
|
|
1896
|
+
multiple: true,
|
|
1897
|
+
accept: "",
|
|
1898
|
+
separate: true,
|
|
1899
|
+
beforeUpload: (_fileData, _files) => true,
|
|
1900
|
+
finish: (_resultFiles) => {
|
|
1901
|
+
},
|
|
1902
|
+
success: (_resultFiles, _res) => {
|
|
1903
|
+
},
|
|
1904
|
+
error: (_resultFiles, _error) => {
|
|
1905
|
+
},
|
|
1906
|
+
progress: (_files) => {
|
|
1907
|
+
}
|
|
1908
|
+
},
|
|
1909
|
+
_opts
|
|
1910
|
+
);
|
|
1911
|
+
const onUploadProgress = (event, files) => {
|
|
1912
|
+
files.forEach((file) => {
|
|
1913
|
+
file.percentage = round(event.progress * 100);
|
|
1914
|
+
});
|
|
1915
|
+
opts.progress(cloneDeep(files));
|
|
1916
|
+
};
|
|
1917
|
+
const uploadRequest = async (files, _onProgress) => {
|
|
1918
|
+
if (opts.request && isFunction(opts.request)) {
|
|
1919
|
+
return opts.request(files);
|
|
1920
|
+
}
|
|
1921
|
+
const data = new FormData();
|
|
1922
|
+
files.forEach((file) => {
|
|
1923
|
+
data.append("file", file);
|
|
1924
|
+
});
|
|
1925
|
+
throw new Error(`\u591A\u5E94\u7528\u6A21\u5F0F\u7B49\u5F85\u91CD\u65B0\u5B9E\u73B0\u8BF7\u6C42`);
|
|
1926
|
+
};
|
|
1927
|
+
const executeSingleUpload = async (files) => {
|
|
1928
|
+
const resultFiles = files.map((file) => {
|
|
1929
|
+
return {
|
|
1930
|
+
status: "uploading",
|
|
1931
|
+
name: file.name,
|
|
1932
|
+
uid: uniqueId(),
|
|
1933
|
+
percentage: 0
|
|
1934
|
+
};
|
|
1935
|
+
});
|
|
1936
|
+
const pass = opts.beforeUpload(files, resultFiles);
|
|
1937
|
+
if (!pass) {
|
|
1938
|
+
resultFiles.forEach((file) => {
|
|
1939
|
+
file.status = "cancel";
|
|
1940
|
+
});
|
|
1941
|
+
ibiz.log.debug("\u53D6\u6D88\u4E0A\u4F20", resultFiles);
|
|
1942
|
+
return resultFiles;
|
|
1943
|
+
}
|
|
1944
|
+
try {
|
|
1945
|
+
const res = await uploadRequest(files, (event) => {
|
|
1946
|
+
onUploadProgress(event, resultFiles);
|
|
1947
|
+
});
|
|
1948
|
+
resultFiles.forEach((file) => {
|
|
1949
|
+
file.status = "finished";
|
|
1950
|
+
});
|
|
1951
|
+
opts.success(resultFiles, res);
|
|
1952
|
+
resultFiles.forEach((file) => {
|
|
1953
|
+
file.response = res;
|
|
1954
|
+
});
|
|
1955
|
+
} catch (error) {
|
|
1956
|
+
resultFiles.forEach((file) => {
|
|
1957
|
+
file.status = "fail";
|
|
1958
|
+
});
|
|
1959
|
+
opts.error(resultFiles, error);
|
|
1960
|
+
resultFiles.forEach((file) => {
|
|
1961
|
+
file.error = error;
|
|
1962
|
+
});
|
|
1963
|
+
ibiz.log.error(error);
|
|
1964
|
+
ibiz.log.error(`${files.map((file) => file.name).join(",")}\u4E0A\u4F20\u5931\u8D25`);
|
|
1965
|
+
}
|
|
1966
|
+
return resultFiles;
|
|
1967
|
+
};
|
|
1968
|
+
const uploadFiles = async (files) => {
|
|
1969
|
+
const uploadSequence = opts.separate ? files.map((file) => [file]) : [files];
|
|
1970
|
+
const res = await Promise.allSettled(
|
|
1971
|
+
uploadSequence.map(async (sequence) => {
|
|
1972
|
+
return executeSingleUpload(sequence);
|
|
1973
|
+
})
|
|
1974
|
+
);
|
|
1975
|
+
const resultFiles = [];
|
|
1976
|
+
res.forEach((result) => {
|
|
1977
|
+
if (result.status === "fulfilled") {
|
|
1978
|
+
resultFiles.push(...result.value);
|
|
1979
|
+
}
|
|
1980
|
+
});
|
|
1981
|
+
opts.finish(resultFiles);
|
|
1982
|
+
};
|
|
1983
|
+
const select = () => {
|
|
1984
|
+
selectFile({
|
|
1985
|
+
accept: opts.accept,
|
|
1986
|
+
multiple: opts.multiple,
|
|
1987
|
+
onSelected: (files) => {
|
|
1988
|
+
uploadFiles(files);
|
|
1989
|
+
}
|
|
1990
|
+
});
|
|
1991
|
+
};
|
|
1992
|
+
select();
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
// src/utils/sync/await-timeout.ts
|
|
1996
|
+
async function awaitTimeout(wait, fun, params) {
|
|
1997
|
+
await new Promise((resolve) => {
|
|
1998
|
+
setTimeout(() => {
|
|
1999
|
+
resolve(true);
|
|
2000
|
+
}, wait);
|
|
2001
|
+
});
|
|
2002
|
+
if (fun) {
|
|
2003
|
+
return fun(...params || []);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
// src/utils/sync/count-latch.ts
|
|
2008
|
+
var CountLatch = class {
|
|
2009
|
+
constructor() {
|
|
2010
|
+
this.promise = null;
|
|
2011
|
+
this.resolve = null;
|
|
2012
|
+
/**
|
|
2013
|
+
* 计数,当前等待的异步逻辑个数
|
|
2014
|
+
*
|
|
2015
|
+
* @author lxm
|
|
2016
|
+
* @date 2022-11-24 19:11:59
|
|
2017
|
+
* @type {number}
|
|
2018
|
+
*/
|
|
2019
|
+
this.count = 0;
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* 开启promise
|
|
2023
|
+
*
|
|
2024
|
+
* @author lxm
|
|
2025
|
+
* @date 2022-11-24 19:11:32
|
|
2026
|
+
* @private
|
|
2027
|
+
*/
|
|
2028
|
+
startPromise() {
|
|
2029
|
+
this.promise = new Promise((resolve) => {
|
|
2030
|
+
this.resolve = resolve;
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* 结束promise
|
|
2035
|
+
*
|
|
2036
|
+
* @author lxm
|
|
2037
|
+
* @date 2022-11-24 19:11:44
|
|
2038
|
+
* @private
|
|
2039
|
+
*/
|
|
2040
|
+
endPromise() {
|
|
2041
|
+
if (this.resolve) {
|
|
2042
|
+
this.resolve();
|
|
2043
|
+
this.resolve = null;
|
|
2044
|
+
this.promise = null;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
/**
|
|
2048
|
+
* 上锁,计数加一
|
|
2049
|
+
* 第一次计数,开启异步
|
|
2050
|
+
*
|
|
2051
|
+
* @author lxm
|
|
2052
|
+
* @date 2022-11-24 19:11:27
|
|
2053
|
+
*/
|
|
2054
|
+
lock() {
|
|
2055
|
+
this.count += 1;
|
|
2056
|
+
if (!this.promise) {
|
|
2057
|
+
this.startPromise();
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
/**
|
|
2061
|
+
* 解锁,计数减一
|
|
2062
|
+
* 归零时结束异步
|
|
2063
|
+
*
|
|
2064
|
+
* @author lxm
|
|
2065
|
+
* @date 2022-11-24 19:11:47
|
|
2066
|
+
*/
|
|
2067
|
+
unlock() {
|
|
2068
|
+
if (this.count < 1) {
|
|
2069
|
+
throw new RuntimeError("lock\u548Cunlock\u6B21\u6570\u4E0D\u5339\u914D\uFF01");
|
|
2070
|
+
}
|
|
2071
|
+
this.count -= 1;
|
|
2072
|
+
if (this.count === 0) {
|
|
2073
|
+
this.endPromise();
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
/**
|
|
2077
|
+
* 等待,计数归零异步结束
|
|
2078
|
+
*
|
|
2079
|
+
* @author lxm
|
|
2080
|
+
* @date 2022-11-24 19:11:20
|
|
2081
|
+
*/
|
|
2082
|
+
async await() {
|
|
2083
|
+
if (this.promise) {
|
|
2084
|
+
await this.promise;
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
|
|
2089
|
+
// src/utils/style/remote-style.ts
|
|
2090
|
+
async function setRemoteStyle(url) {
|
|
2091
|
+
try {
|
|
2092
|
+
const res = await ibiz.net.get(url);
|
|
2093
|
+
const styleDom = document.createElement("style");
|
|
2094
|
+
styleDom.setAttribute("title", "app-style-css");
|
|
2095
|
+
styleDom.innerText = res.data;
|
|
2096
|
+
document.head.appendChild(styleDom);
|
|
2097
|
+
} catch (error) {
|
|
2098
|
+
Logger.debug("\u52A0\u8F7D\u8FDC\u7A0B\u6837\u5F0F\u8868\u5931\u8D25", url);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
// src/ibizsys.ts
|
|
2103
|
+
var IBizSys = class {
|
|
2104
|
+
constructor() {
|
|
2105
|
+
/**
|
|
2106
|
+
* 环境变量
|
|
2107
|
+
*
|
|
2108
|
+
* @author chitanda
|
|
2109
|
+
* @date 2022-07-19 18:07:04
|
|
2110
|
+
*/
|
|
2111
|
+
this.env = Environment;
|
|
2112
|
+
/**
|
|
2113
|
+
* 日志对象
|
|
2114
|
+
*
|
|
2115
|
+
* @author chitanda
|
|
2116
|
+
* @date 2022-10-25 20:10:22
|
|
2117
|
+
*/
|
|
2118
|
+
this.log = Logger;
|
|
2119
|
+
/**
|
|
2120
|
+
* 网络请求工具类(发送默认请求)
|
|
2121
|
+
*
|
|
2122
|
+
* @author chitanda
|
|
2123
|
+
* @date 2022-07-19 17:07:56
|
|
2124
|
+
* @type {Net}
|
|
2125
|
+
*/
|
|
2126
|
+
this.net = new Net();
|
|
2127
|
+
/**
|
|
2128
|
+
* 指令集
|
|
2129
|
+
*
|
|
2130
|
+
* @author chitanda
|
|
2131
|
+
* @date 2022-07-20 10:07:33
|
|
2132
|
+
* @type {AuthService}
|
|
2133
|
+
*/
|
|
2134
|
+
this.commands = new CommandController();
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2137
|
+
|
|
2138
|
+
// src/factory-center.ts
|
|
2139
|
+
var FactoryCenter = class {
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
// src/install.ts
|
|
2143
|
+
function install() {
|
|
2144
|
+
if (window.ibiz) {
|
|
2145
|
+
throw new Error("ibiz \u5DF2\u7ECF\u5B58\u5728, \u65E0\u9700\u91CD\u590D\u5B89\u88C5");
|
|
2146
|
+
}
|
|
2147
|
+
window.ibiz = new IBizSys();
|
|
2148
|
+
window.___fc = new FactoryCenter();
|
|
2149
|
+
}
|
|
2150
|
+
export {
|
|
2151
|
+
CommandController,
|
|
2152
|
+
CommandsRegistry,
|
|
2153
|
+
CoreConst,
|
|
2154
|
+
CoreInterceptor,
|
|
2155
|
+
CountLatch,
|
|
2156
|
+
Environment,
|
|
2157
|
+
FactoryCenter,
|
|
2158
|
+
HttpError,
|
|
2159
|
+
HttpResponse,
|
|
2160
|
+
HttpStatusMessageConst,
|
|
2161
|
+
IBizContext,
|
|
2162
|
+
IBizSys,
|
|
2163
|
+
Interceptor,
|
|
2164
|
+
LinkedList,
|
|
2165
|
+
Logger,
|
|
2166
|
+
LoginMode,
|
|
2167
|
+
MenuPermissionMode,
|
|
2168
|
+
ModelError,
|
|
2169
|
+
NOOP,
|
|
2170
|
+
Namespace,
|
|
2171
|
+
Net,
|
|
2172
|
+
RuntimeError,
|
|
2173
|
+
RuntimeModelError,
|
|
2174
|
+
StringUtil,
|
|
2175
|
+
UrlHelper,
|
|
2176
|
+
awaitTimeout,
|
|
2177
|
+
calcMimeByFileName,
|
|
2178
|
+
colorBlend,
|
|
2179
|
+
commands,
|
|
2180
|
+
debounce,
|
|
2181
|
+
debounceAndAsyncMerge,
|
|
2182
|
+
debounceAndMerge,
|
|
2183
|
+
downloadFileFromBlob,
|
|
2184
|
+
eventPath,
|
|
2185
|
+
fileListToArr,
|
|
2186
|
+
getToken,
|
|
2187
|
+
install,
|
|
2188
|
+
isEventInside,
|
|
2189
|
+
isImage,
|
|
2190
|
+
isOverlap,
|
|
2191
|
+
listenJSEvent,
|
|
2192
|
+
onClickOutside,
|
|
2193
|
+
selectFile,
|
|
2194
|
+
setRemoteStyle,
|
|
2195
|
+
throttle,
|
|
2196
|
+
toDisposable,
|
|
2197
|
+
uploadFile
|
|
2198
|
+
};
|