@lightsoft/js-sdk 1.0.0 → 1.0.2

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.umd.js CHANGED
@@ -1,252 +1,946 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.s = {}));
5
- })(this, (function (exports) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.s = {}, global.Vue));
5
+ })(this, (function (exports, vue) { 'use strict';
6
6
 
7
- var TAG_NAME_REGEX = /<\/?\s*([a-zA-Z][a-zA-Z0-9-]*)\b/; // 获取开始或结束标签的名
8
- var SINGLE_TAG_REGEX = /<([^\s>]+)/; // 单标签
9
- var TAG_REGEX = /<\/?[a-z]+[^>]*>|[^<>]+/gi; // 开始和结束标签
10
- var $FOR_REGEX = /r-for\s*=\s*"([^"]+)"/; //$for 属性值
11
- var $IF_REGEX = /r-if\s*=\s*"([^"]+)"/; //$if 属性值
12
- var $STYLE_REGEX = /r-style\s*=\s*"([^"]+)"/; //$style 属性值
13
- var $CLASS_REGEX = /r-class\s*=\s*"([^"]+)"/; //$class 属性值
14
- var $ATTRS_REGEX = /\sr-[a-z]\w+\s*=\s*"[^"]*"/g; // 所有$符号的属性
15
- var $CONTENT_REGEX = /\{\{(.+?)\}\}/g; // $符号内容
16
- var RELATIONAL_SYMBOLS_REGEX = /<=|>=|\=+|>|</; // 关系符号
17
- var STR_REGEX = /^("|'|`)(.*)\1$/;
18
- var CALLBACK_REGEX = /\s*setContent\((.*?)\)\s*/g;
19
- var FUN_NAME_REGEX = /([a-zA-Z_$][a-zA-Z0-9_$]*)/;
20
- function useId() {
21
- return Math.random().toString(36).substring(2, 15);
22
- }
23
- function hasSingleTag(tag) {
24
- var _a;
25
- return ['img', 'br', 'input'].includes((_a = tag.match(SINGLE_TAG_REGEX)) === null || _a === void 0 ? void 0 : _a[1]);
26
- }
27
- function findStartTag(currentIndex, tags) {
28
- var _a, _b, _c, _d;
29
- var index = 1;
30
- var prevTag = tags[currentIndex - index];
31
- var currentTag = tags[currentIndex];
32
- var currentTagName = (_b = (_a = currentTag.tag) === null || _a === void 0 ? void 0 : _a.match(TAG_NAME_REGEX)) === null || _b === void 0 ? void 0 : _b[1];
33
- var prevTagName;
34
- while (currentTagName !== prevTagName) {
35
- prevTag = tags[currentIndex - index] || prevTag;
36
- prevTagName = (_d = (_c = prevTag.tag) === null || _c === void 0 ? void 0 : _c.match(TAG_NAME_REGEX)) === null || _d === void 0 ? void 0 : _d[1];
37
- index++;
7
+ /******************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
+
23
+
24
+ var __assign = function() {
25
+ __assign = Object.assign || function __assign(t) {
26
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
27
+ s = arguments[i];
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
29
+ }
30
+ return t;
31
+ };
32
+ return __assign.apply(this, arguments);
33
+ };
34
+
35
+ function __awaiter(thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ }
44
+
45
+ function __generator(thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
47
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ }
72
+
73
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
74
+ var e = new Error(message);
75
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
76
+ };
77
+
78
+ var READY_STATE;
79
+ (function (READY_STATE) {
80
+ // 未初始化
81
+ READY_STATE[READY_STATE["UNSENT"] = 0] = "UNSENT";
82
+ // 已打开
83
+ READY_STATE[READY_STATE["OPENED"] = 1] = "OPENED";
84
+ // 已获取响应头
85
+ READY_STATE[READY_STATE["HEADERS_RECEIVED"] = 2] = "HEADERS_RECEIVED";
86
+ // 已加载响应体
87
+ READY_STATE[READY_STATE["LOADING"] = 3] = "LOADING";
88
+ // 已完成
89
+ READY_STATE[READY_STATE["DONE"] = 4] = "DONE";
90
+ })(READY_STATE || (READY_STATE = {}));
91
+ var STATUS_CODE;
92
+ (function (STATUS_CODE) {
93
+ // 2xx 成功
94
+ STATUS_CODE[STATUS_CODE["OK"] = 200] = "OK";
95
+ STATUS_CODE[STATUS_CODE["CREATED"] = 201] = "CREATED";
96
+ STATUS_CODE[STATUS_CODE["ACCEPTED"] = 202] = "ACCEPTED";
97
+ STATUS_CODE[STATUS_CODE["NO_CONTENT"] = 204] = "NO_CONTENT";
98
+ // 3xx 重定向
99
+ STATUS_CODE[STATUS_CODE["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
100
+ STATUS_CODE[STATUS_CODE["FOUND"] = 302] = "FOUND";
101
+ STATUS_CODE[STATUS_CODE["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
102
+ // 4xx 客户端错误
103
+ STATUS_CODE[STATUS_CODE["BAD_REQUEST"] = 400] = "BAD_REQUEST";
104
+ STATUS_CODE[STATUS_CODE["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
105
+ STATUS_CODE[STATUS_CODE["FORBIDDEN"] = 403] = "FORBIDDEN";
106
+ STATUS_CODE[STATUS_CODE["NOT_FOUND"] = 404] = "NOT_FOUND";
107
+ // 5xx 服务器错误
108
+ STATUS_CODE[STATUS_CODE["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
109
+ STATUS_CODE[STATUS_CODE["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
110
+ STATUS_CODE[STATUS_CODE["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
111
+ })(STATUS_CODE || (STATUS_CODE = {}));
112
+ var HTTP_STATUS_MESSAGE;
113
+ (function (HTTP_STATUS_MESSAGE) {
114
+ // 2xx 成功
115
+ HTTP_STATUS_MESSAGE["OK"] = "\u8BF7\u6C42\u6210\u529F";
116
+ HTTP_STATUS_MESSAGE["CREATED"] = "\u521B\u5EFA\u6210\u529F";
117
+ HTTP_STATUS_MESSAGE["ACCEPTED"] = "\u5DF2\u63A5\u6536";
118
+ HTTP_STATUS_MESSAGE["NO_CONTENT"] = "\u65E0\u5185\u5BB9";
119
+ // 3xx 重定向
120
+ HTTP_STATUS_MESSAGE["MOVED_PERMANENTLY"] = "\u5DF2\u6C38\u4E45\u79FB\u52A8";
121
+ HTTP_STATUS_MESSAGE["FOUND"] = "\u5DF2\u627E\u5230";
122
+ HTTP_STATUS_MESSAGE["NOT_MODIFIED"] = "\u672A\u4FEE\u6539";
123
+ // 4xx 客户端错误
124
+ HTTP_STATUS_MESSAGE["BAD_REQUEST"] = "\u8BF7\u6C42\u9519\u8BEF";
125
+ HTTP_STATUS_MESSAGE["UNAUTHORIZED"] = "\u672A\u6388\u6743";
126
+ HTTP_STATUS_MESSAGE["FORBIDDEN"] = "\u7981\u6B62\u8BBF\u95EE";
127
+ HTTP_STATUS_MESSAGE["NOT_FOUND"] = "\u672A\u627E\u5230";
128
+ // 5xx 服务器错误
129
+ HTTP_STATUS_MESSAGE["INTERNAL_SERVER_ERROR"] = "\u670D\u52A1\u5668\u9519\u8BEF";
130
+ HTTP_STATUS_MESSAGE["SERVICE_UNAVAILABLE"] = "\u670D\u52A1\u4E0D\u53EF\u7528";
131
+ HTTP_STATUS_MESSAGE["GATEWAY_TIMEOUT"] = "\u7F51\u5173\u8D85\u65F6";
132
+ })(HTTP_STATUS_MESSAGE || (HTTP_STATUS_MESSAGE = {}));
133
+ var HTTP_METHOD;
134
+ (function (HTTP_METHOD) {
135
+ HTTP_METHOD["GET"] = "GET";
136
+ HTTP_METHOD["POST"] = "POST";
137
+ HTTP_METHOD["PUT"] = "PUT";
138
+ HTTP_METHOD["DELETE"] = "DELETE";
139
+ })(HTTP_METHOD || (HTTP_METHOD = {}));
140
+ var HTTP_HEADER;
141
+ (function (HTTP_HEADER) {
142
+ HTTP_HEADER["CONTENT_TYPE"] = "Content-Type";
143
+ HTTP_HEADER["ACCEPT"] = "Accept";
144
+ HTTP_HEADER["AUTHORIZATION"] = "Authorization";
145
+ })(HTTP_HEADER || (HTTP_HEADER = {}));
146
+ var HTTP_CONTENT_TYPE;
147
+ (function (HTTP_CONTENT_TYPE) {
148
+ HTTP_CONTENT_TYPE["JSON"] = "application/json";
149
+ HTTP_CONTENT_TYPE["FORM_URLENCODED"] = "application/x-www-form-urlencoded";
150
+ HTTP_CONTENT_TYPE["MULTIPART_FORM_DATA"] = "multipart/form-data";
151
+ })(HTTP_CONTENT_TYPE || (HTTP_CONTENT_TYPE = {}));
152
+ var HTTP_STATUS;
153
+ (function (HTTP_STATUS) {
154
+ HTTP_STATUS[HTTP_STATUS["OK"] = 200] = "OK";
155
+ HTTP_STATUS[HTTP_STATUS["CREATED"] = 201] = "CREATED";
156
+ HTTP_STATUS[HTTP_STATUS["ACCEPTED"] = 202] = "ACCEPTED";
157
+ HTTP_STATUS[HTTP_STATUS["NO_CONTENT"] = 204] = "NO_CONTENT";
158
+ })(HTTP_STATUS || (HTTP_STATUS = {}));
159
+
160
+ var Request = /** @class */ (function () {
161
+ function Request() {
162
+ this.beforeRequestOptions = {};
163
+ this.xhr = this.create();
38
164
  }
39
- return prevTag;
40
- }
41
- function operatorsParse(content) {
42
- if (content === void 0) { content = ''; }
43
- return content.replace('&gt;', '>').replace('&lt;', '<').replaceAll('&amp;', '&');
44
- }
45
- function resolver(htmlStr) {
46
- var _a, _b, _c, _d, _e, _f;
47
- var tags = [];
48
- var match;
49
- var index = 0;
50
- var annotation = false;
51
- htmlStr = htmlStr.replace('<!--', '<annotation>').replace('-->', '</annotation>');
52
- while ((match = TAG_REGEX.exec(htmlStr)) !== null) {
53
- var tag = match[0].trim();
54
- if (!tag)
55
- continue;
56
- if (tag.startsWith('</')) {
57
- var item = {
58
- type: 'node',
59
- tag: tag,
165
+ Request.prototype.create = function () {
166
+ if (window.XMLHttpRequest)
167
+ return new XMLHttpRequest();
168
+ else if (window.ActiveXObject)
169
+ return new ActiveXObject('Microsoft.XMLHTTP');
170
+ throw new Error('您的浏览器暂不支持XMLHttpRequest');
171
+ };
172
+ Request.prototype.useState = function (state) {
173
+ switch (state) {
174
+ case 'SUCCESS':
175
+ return this.xhr.readyState === READY_STATE.DONE && this.xhr.status >= 200 && this.xhr.status < 300;
176
+ case 'FAIL':
177
+ return this.xhr.readyState === READY_STATE.DONE && (this.xhr.status < 200 || this.xhr.status >= 300);
178
+ case 'PENDING':
179
+ return this.xhr.readyState < READY_STATE.DONE;
180
+ default:
181
+ return false;
182
+ }
183
+ };
184
+ Request.prototype.send = function (type, url, options) {
185
+ if (options === void 0) { options = {}; }
186
+ var _a = this, xhr = _a.xhr, beforeRequestOptions = _a.beforeRequestOptions, beforeResponseCallback = _a.beforeResponseCallback;
187
+ var useState = this.useState.bind(this);
188
+ var transformResponse = this.transformResponse.bind(this);
189
+ return new Promise(function (resolve, reject) {
190
+ xhr.open(type, url, options.async || true);
191
+ var requestOptions = __assign(__assign({}, beforeRequestOptions), options);
192
+ Object.keys(requestOptions.headers || {}).forEach(function (key) {
193
+ var _a;
194
+ xhr.setRequestHeader(key, (_a = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) === null || _a === void 0 ? void 0 : _a[key]);
195
+ });
196
+ xhr.onreadystatechange = function () {
197
+ var success = useState('SUCCESS');
198
+ var fail = useState('FAIL');
199
+ if (success) {
200
+ beforeResponseCallback
201
+ ? beforeResponseCallback(transformResponse(xhr), resolve, reject)
202
+ : resolve(transformResponse(xhr));
203
+ }
204
+ else if (fail) {
205
+ reject(transformResponse(xhr));
206
+ }
60
207
  };
61
- if (annotation)
62
- item.$disabledFor = true;
63
- if ((_a = item === null || item === void 0 ? void 0 : item.tag) === null || _a === void 0 ? void 0 : _a.includes('</annotation>'))
64
- annotation = false;
65
- tags.push(item);
66
- var prevTag = findStartTag(index, tags);
67
- prevTag.endIndex = index;
68
- }
69
- else if (tag.startsWith('<')) {
70
- var forMatch = (_b = tag.match($FOR_REGEX)) === null || _b === void 0 ? void 0 : _b[1];
71
- var ifMatch = (_c = tag.match($IF_REGEX)) === null || _c === void 0 ? void 0 : _c[1];
72
- var styleMatch = (_d = tag.match($STYLE_REGEX)) === null || _d === void 0 ? void 0 : _d[1];
73
- var classMatch = (_e = tag.match($CLASS_REGEX)) === null || _e === void 0 ? void 0 : _e[1];
74
- var item = {
75
- type: 'node',
76
- tag: tag.replace($ATTRS_REGEX, '')
208
+ xhr.onerror = function () {
209
+ reject(transformResponse(xhr));
77
210
  };
78
- if (forMatch)
79
- item.$for = forMatch;
80
- if (ifMatch)
81
- item.$if = operatorsParse(ifMatch);
82
- if (styleMatch)
83
- item.$style = operatorsParse(styleMatch);
84
- if (classMatch)
85
- item.$class = operatorsParse(classMatch);
86
- if ((_f = item === null || item === void 0 ? void 0 : item.tag) === null || _f === void 0 ? void 0 : _f.includes('<annotation>'))
87
- annotation = true;
88
- if (annotation)
89
- item.$disabledFor = true;
90
- tags.push(item);
211
+ if (options.data instanceof FormData) {
212
+ xhr.send(options.data);
213
+ }
214
+ else if (type === 'POST' || type === 'PUT') {
215
+ xhr.send(JSON.stringify(options.data));
216
+ }
217
+ else {
218
+ xhr.send();
219
+ }
220
+ });
221
+ };
222
+ Request.prototype.transformResponse = function (response) {
223
+ return {
224
+ data: JSON.parse(response.responseText),
225
+ code: response.status,
226
+ message: response.statusText,
227
+ };
228
+ };
229
+ Request.prototype.transformQuery = function (url, query) {
230
+ var queryData = Object.keys(query || {});
231
+ if (!queryData.length)
232
+ return url;
233
+ var queryString = queryData.map(function (key) {
234
+ return window.encodeURIComponent(key) + '=' + window.encodeURIComponent(query[key]);
235
+ }).join('&');
236
+ url += (url.includes('?') ? '&' : '?') + queryString;
237
+ return url;
238
+ };
239
+ Request.prototype.beforeSend = function (callback) {
240
+ this.beforeRequestOptions = callback();
241
+ };
242
+ Request.prototype.beforeResponse = function (callback) {
243
+ this.beforeResponseCallback = callback;
244
+ };
245
+ Request.prototype.abort = function () {
246
+ this.xhr.abort();
247
+ };
248
+ Request.prototype.get = function (url, query, headers) {
249
+ if (headers === void 0) { headers = {}; }
250
+ var newUrl = this.transformQuery(url, query);
251
+ return this.send('GET', newUrl, { headers: headers });
252
+ };
253
+ Request.prototype.post = function (url, data, headers) {
254
+ if (headers === void 0) { headers = {}; }
255
+ return this.send('POST', url, { data: data, headers: headers });
256
+ };
257
+ Request.prototype.put = function (url, data, headers) {
258
+ if (headers === void 0) { headers = {}; }
259
+ return this.send('PUT', url, { data: data, headers: headers });
260
+ };
261
+ Request.prototype.delete = function (url, data, headers) {
262
+ if (headers === void 0) { headers = {}; }
263
+ return this.send('DELETE', url, { data: data, headers: headers });
264
+ };
265
+ Request.prototype.patch = function (url, data, headers) {
266
+ if (headers === void 0) { headers = {}; }
267
+ return this.send('PATCH', url, { data: data, headers: headers });
268
+ };
269
+ Request.prototype.options = function (url, data, headers) {
270
+ if (headers === void 0) { headers = {}; }
271
+ return this.send('OPTIONS', url, { data: data, headers: headers });
272
+ };
273
+ Request.prototype.head = function (url, data, headers) {
274
+ if (headers === void 0) { headers = {}; }
275
+ return this.send('HEAD', url, { data: data, headers: headers });
276
+ };
277
+ Request.prototype.trace = function (url, data, headers) {
278
+ if (headers === void 0) { headers = {}; }
279
+ return this.send('TRACE', url, { data: data, headers: headers });
280
+ };
281
+ Request.prototype.connect = function (url, data, headers) {
282
+ if (headers === void 0) { headers = {}; }
283
+ return this.send('CONNECT', url, { data: data, headers: headers });
284
+ };
285
+ return Request;
286
+ }());
287
+ var RequestChain = /** @class */ (function () {
288
+ function RequestChain() {
289
+ var args = [];
290
+ for (var _i = 0; _i < arguments.length; _i++) {
291
+ args[_i] = arguments[_i];
292
+ }
293
+ this.fieldList = [{}];
294
+ this.responses = [];
295
+ this.setParams.apply(this, args);
296
+ }
297
+ RequestChain.prototype.getParams = function (type, data, fields) {
298
+ var keys = Object.keys(fields);
299
+ var values = Object.values(fields);
300
+ if (type === 'query') {
301
+ var query = keys.map(function (key, index) {
302
+ return "".concat(key, "=").concat(data[values[index]]);
303
+ }).join('&');
304
+ return query;
91
305
  }
92
306
  else {
93
- tags.push({
94
- type: 'content',
95
- content: tag,
307
+ var body_1 = {};
308
+ keys.forEach(function (key, index) {
309
+ body_1[key] = data[values[index]];
96
310
  });
311
+ return body_1;
97
312
  }
98
- index++;
99
- }
100
- return tags;
101
- }
102
- function callbackParse(content) {
103
- if (content === void 0) { content = ''; }
104
- return content.replace(CALLBACK_REGEX, function (_match, args) {
105
- var _a;
106
- var newArgs = args.split(',').map(function (arg) {
107
- if (STR_REGEX.test(arg.trim()))
108
- return arg;
109
- return 'this.' + arg.trim();
313
+ };
314
+ RequestChain.prototype.setParams = function () {
315
+ var args = [];
316
+ for (var _i = 0; _i < arguments.length; _i++) {
317
+ args[_i] = arguments[_i];
318
+ }
319
+ for (var i = 0; i < args.length; i++) {
320
+ var arg = args[i];
321
+ this.fieldList.push(arg);
322
+ }
323
+ };
324
+ RequestChain.prototype.chain = function (list) {
325
+ var _this = this;
326
+ return list.reduce(function (pre, cur, index) {
327
+ return new Promise(function (resolve, reject) {
328
+ pre().then(function (preRes) {
329
+ var fields = _this.fieldList[index];
330
+ var type = (fields === null || fields === void 0 ? void 0 : fields.query) ? 'query' : 'body';
331
+ var params = _this.getParams(type, preRes, (fields === null || fields === void 0 ? void 0 : fields.query) || fields);
332
+ _this.responses.push(preRes);
333
+ cur(params).then(function (curRes) {
334
+ _this.responses.push(curRes);
335
+ resolve(_this.responses);
336
+ });
337
+ });
338
+ });
110
339
  });
111
- var funName = (_a = content.match(FUN_NAME_REGEX)) === null || _a === void 0 ? void 0 : _a[0];
112
- return "".concat(funName, "(").concat(newArgs, ")");
113
- });
114
- }
115
- function contentParse(content) {
116
- if (content === void 0) { content = ''; }
117
- return content.replace($CONTENT_REGEX, function (_match, key) {
118
- var newKey = callbackParse(key);
119
- return '${this.' + newKey + '}';
120
- });
121
- }
122
- function parseIf(ifContent) {
123
- ifContent = ifContent.replace(/^\s*if\s*=\s*/, '');
124
- var operator = ifContent.match(RELATIONAL_SYMBOLS_REGEX);
125
- var _a = ifContent.split(RELATIONAL_SYMBOLS_REGEX), left = _a[0], right = _a[1];
126
- var leftVariable = (STR_REGEX.test(left.trim()) || /\d/.test(left.trim())) ? left.trim() : "this.".concat(left.trim());
127
- var rightVariable = (STR_REGEX.test(right.trim()) || /\d/.test(right.trim())) ? right.trim() : "this.".concat(right.trim());
128
- var code = '';
129
- code += "if(";
130
- code += "".concat(leftVariable);
131
- code += "".concat(operator);
132
- code += "".concat(rightVariable);
133
- code += ") {\n";
134
- return code;
135
- }
136
- function styleParse(styleContent) {
137
- var _a;
138
- var styleValue = contentParse((_a = styleContent.match($CONTENT_REGEX)) === null || _a === void 0 ? void 0 : _a[0]);
139
- return styleContent.replace($CONTENT_REGEX, styleValue);
340
+ };
341
+ return RequestChain;
342
+ }());
343
+
344
+ /**
345
+ *
346
+ * @param {number} num 倒计时时间
347
+ * @param {string} text 按钮文本
348
+ * @returns { object } countdownText 倒计时文本 isDisabled 是否禁用 send 发送验证码方法
349
+ * @description 发送验证码倒计时
350
+ */
351
+ function useCountDown(num, text) {
352
+ if (text === void 0) { text = '发送验证码'; }
353
+ var countdownNum = vue.ref(num);
354
+ var countdownText = vue.ref(text);
355
+ var disabled = vue.ref(false);
356
+ var send = function () {
357
+ countdownText.value = "".concat(countdownNum.value, "s");
358
+ disabled.value = true;
359
+ var timer = setInterval(function () {
360
+ countdownNum.value--;
361
+ countdownText.value = "".concat(countdownNum.value, "s");
362
+ if (countdownNum.value === 0) {
363
+ clearInterval(timer);
364
+ countdownNum.value = num;
365
+ countdownText.value = text;
366
+ disabled.value = false;
367
+ }
368
+ }, 1000);
369
+ };
370
+ return { countdownText: countdownText, disabled: disabled, send: send };
371
+ }
372
+
373
+ exports.RecordType = void 0;
374
+ (function (RecordType) {
375
+ RecordType["AUDIO"] = "audio";
376
+ RecordType["VIDEO"] = "video";
377
+ RecordType["SCREEN"] = "screen";
378
+ })(exports.RecordType || (exports.RecordType = {}));
379
+ exports.LOGIN_TYPE = void 0;
380
+ (function (LOGIN_TYPE) {
381
+ LOGIN_TYPE["CODE"] = "CODE";
382
+ LOGIN_TYPE["ACCOUNT"] = "ACCOUNT";
383
+ })(exports.LOGIN_TYPE || (exports.LOGIN_TYPE = {}));
384
+ exports.LENGTH_LIMIT = void 0;
385
+ (function (LENGTH_LIMIT) {
386
+ LENGTH_LIMIT[LENGTH_LIMIT["MIN_11"] = 11] = "MIN_11";
387
+ LENGTH_LIMIT[LENGTH_LIMIT["MAX_11"] = 11] = "MAX_11";
388
+ LENGTH_LIMIT[LENGTH_LIMIT["MIN_18"] = 18] = "MIN_18";
389
+ LENGTH_LIMIT[LENGTH_LIMIT["MAX_18"] = 18] = "MAX_18";
390
+ LENGTH_LIMIT[LENGTH_LIMIT["MIN_15"] = 15] = "MIN_15";
391
+ LENGTH_LIMIT[LENGTH_LIMIT["MAX_15"] = 15] = "MAX_15";
392
+ })(exports.LENGTH_LIMIT || (exports.LENGTH_LIMIT = {}));
393
+ // 节点基础类型
394
+ exports.HAS_FEILD = void 0;
395
+ (function (HAS_FEILD) {
396
+ HAS_FEILD["LABEL"] = "label";
397
+ HAS_FEILD["VALUE"] = "value";
398
+ HAS_FEILD["CHILDREN"] = "children";
399
+ HAS_FEILD["LEAF"] = "leaf";
400
+ })(exports.HAS_FEILD || (exports.HAS_FEILD = {}));
401
+
402
+ function allToString(obj, splitter) {
403
+ var k;
404
+ for (k in obj) {
405
+ var item = obj[k];
406
+ if (Array.isArray(item))
407
+ obj[k] = item.join(splitter);
408
+ }
409
+ return obj;
140
410
  }
141
- function classParse(classContent) {
411
+ /**
412
+ * 对象数组转为字符串
413
+ * @param {object} obj 目标对象
414
+ * @param {string | string[]} keys 键名
415
+ * @param {string} splitter 分隔符
416
+ */
417
+ function objectArrayToString(obj, keys, splitter) {
142
418
  var _a;
143
- if (classContent === void 0) { classContent = ''; }
144
- var classValue = contentParse((_a = classContent.match($CONTENT_REGEX)) === null || _a === void 0 ? void 0 : _a[0]);
145
- return classContent.replace($CONTENT_REGEX, classValue);
146
- }
147
- function attributeParse(tagData) {
148
- var tag = tagData.tag;
149
- var styleValue = styleParse(tagData.$style || '');
150
- var classValue = classParse(tagData.$class || '');
151
- var _style = styleValue ? ' style="' + styleValue + '"' : '';
152
- var _class = classValue ? ' class="' + classValue + '"' : '';
153
- return tag.replace('>', _style + _class + '>');
154
- }
155
- function parseFor(forContent) {
156
- var expressionFor = forContent.split(/\s(in)\s/);
157
- var iterable = expressionFor[expressionFor.length - 1];
158
- var expressionLeft = expressionFor[0].split(',');
159
- var itemKey = expressionLeft[0];
160
- var indexKey = expressionLeft[1];
161
- var code = '';
162
- code += "for (this['".concat(itemKey, "'] of this.").concat(iterable, " || []) {\n");
163
- if (indexKey)
164
- code += "this.".concat(indexKey, " = this.").concat(iterable, ".indexOf(this.").concat(itemKey, ");\n");
165
- return code;
166
- }
167
- function compose(tags) {
168
- var code = '';
169
- for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
170
- var t = tags_1[_i];
171
- var type = t.type, content = t.content;
172
- if (type === 'node') {
173
- if (t.$if) {
174
- code += parseIf(t.$if);
175
- tags[t.endIndex].isIf = true;
176
- }
177
- if (t.$for && !t.$disabledFor) {
178
- code += parseFor(t.$for);
179
- if (hasSingleTag(t.tag))
180
- t.isFor = true;
181
- else
182
- tags[t.endIndex].isFor = true;
419
+ var newObj = __assign({}, obj);
420
+ if (keys === '$all')
421
+ return allToString(newObj, splitter);
422
+ var k = typeof keys === 'string' ? [keys] : keys;
423
+ for (var i = 0; i < k.length; i++) {
424
+ var key = k[i];
425
+ var value = (_a = newObj[key]) === null || _a === void 0 ? void 0 : _a.join(splitter);
426
+ newObj[key] = value;
427
+ }
428
+ return newObj;
429
+ }
430
+ /**
431
+ * 防抖
432
+ * @param {Function} fn 回调函数
433
+ * @param {number} delay 延迟时间
434
+ */
435
+ function debounce(fn, delay) {
436
+ var time = null;
437
+ return function (value) {
438
+ if (time !== null) {
439
+ clearTimeout(time);
440
+ }
441
+ time = setTimeout(function () {
442
+ fn === null || fn === void 0 ? void 0 : fn(value);
443
+ }, delay);
444
+ };
445
+ }
446
+ /**
447
+ *
448
+ * 判断是否移动端
449
+ * @return {boolean}
450
+ */
451
+ function isMobileDevice() {
452
+ return /android|iphone|ipad|ipod|ios/i.test(navigator.userAgent);
453
+ }
454
+ /**
455
+ * 节流
456
+ * @param {Function} fn 回调函数
457
+ * @param {number} delay 延迟时间
458
+ */
459
+ function throttle(fn, delay) {
460
+ var time = null;
461
+ return function (value) {
462
+ if (time !== null) {
463
+ clearTimeout(time);
464
+ }
465
+ time = setTimeout(function () {
466
+ fn === null || fn === void 0 ? void 0 : fn(value);
467
+ }, delay);
468
+ };
469
+ }
470
+ /**
471
+ * 深度合并对象
472
+ * @param target 目标对象
473
+ * @param source 源对象
474
+ */
475
+ function deepMerge(target, source) {
476
+ for (var key in source) {
477
+ if (source[key] instanceof Object) {
478
+ target[key] = deepMerge(target[key], source[key]);
479
+ }
480
+ else {
481
+ target[key] = source[key];
482
+ }
483
+ }
484
+ return target;
485
+ }
486
+ /**
487
+ * input类型验证
488
+ */
489
+ var InputLegalityValidate = /** @class */ (function () {
490
+ function InputLegalityValidate() {
491
+ this._phoneReg = /^1[3-9]\d{9}$/;
492
+ this._mailReg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
493
+ this._idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}([\dX])$)/i;
494
+ }
495
+ /**
496
+ * 验证手机号
497
+ * @param phone 手机号
498
+ */
499
+ InputLegalityValidate.prototype.phone = function (phone) {
500
+ return this._phoneReg.test(phone);
501
+ };
502
+ /**
503
+ * 验证邮箱
504
+ * @param email 手机号
505
+ */
506
+ InputLegalityValidate.prototype.email = function (email) {
507
+ return this._mailReg.test(email);
508
+ };
509
+ /**
510
+ * 验证身份证
511
+ * @param idCard 身份证号
512
+ */
513
+ InputLegalityValidate.prototype.idCard = function (idCard) {
514
+ return this._idCardReg.test(idCard);
515
+ };
516
+ return InputLegalityValidate;
517
+ }());
518
+ /**
519
+ * input长度验证
520
+ */
521
+ var InputLengthValidate = /** @class */ (function () {
522
+ function InputLengthValidate() {
523
+ var _this = this;
524
+ this.validators = {
525
+ // 修改 validators 的 key 类型
526
+ MIN_11: function (value) { return value.length >= exports.LENGTH_LIMIT.MIN_11; },
527
+ MAX_11: function (value) { return value.length <= exports.LENGTH_LIMIT.MAX_11; },
528
+ MIN_18: function (value) { return value.length >= exports.LENGTH_LIMIT.MIN_18; },
529
+ MAX_18: function (value) { return value.length <= exports.LENGTH_LIMIT.MAX_18; },
530
+ MIN_15: function (value) { return value.length >= exports.LENGTH_LIMIT.MIN_15; },
531
+ MAX_15: function (value) { return value.length <= exports.LENGTH_LIMIT.MAX_15; },
532
+ };
533
+ var _loop_1 = function (key) {
534
+ if (Number.isNaN(Number(key))) {
535
+ var prefix = key.slice(0, 3);
536
+ var num = Number.parseInt(key.slice(4), 10);
537
+ var funcName = "".concat(prefix).concat(num);
538
+ this_1[funcName] = function (value) { return _this.checkLength(value, key); }; // 传递 key 而不是 limit
183
539
  }
184
- if (t.$style || t.$class) {
185
- t.tag = attributeParse(t);
540
+ };
541
+ var this_1 = this;
542
+ for (var key in exports.LENGTH_LIMIT) {
543
+ _loop_1(key);
544
+ }
545
+ }
546
+ InputLengthValidate.prototype.checkLength = function (value, key) {
547
+ // 修改 limit 参数类型
548
+ return this.validators[key](value); // 使用 key 获取 validator
549
+ };
550
+ InputLengthValidate.prototype.maxLength = function (value, limit) {
551
+ if (value.length > limit) {
552
+ return value.slice(0, limit);
553
+ }
554
+ return value;
555
+ };
556
+ // 新增方法:限制最大长度
557
+ InputLengthValidate.prototype.limitLength = function (value, limit) {
558
+ return this.maxLength(value, limit);
559
+ };
560
+ return InputLengthValidate;
561
+ }());
562
+ /**
563
+ * 检查值是否为空
564
+ * @param value 要检查的值
565
+ * @return {boolean} 如果值为空返回 true,否则返回 false
566
+ */
567
+ function isNull(value) {
568
+ return (value === 'null'
569
+ || value === null
570
+ || value === 'undefined'
571
+ || value === undefined
572
+ || value === ''
573
+ || value === ' '
574
+ || value === '0'
575
+ || value === 0
576
+ || value === 'false'
577
+ || value === false);
578
+ }
579
+ var dataHandler = /** @class */ (function () {
580
+ // 构造函数,接收三个参数:fields,node,mapping
581
+ function dataHandler(fields, node, mapping) {
582
+ // 将参数fields赋值给实例变量this.fields
583
+ this.fields = fields;
584
+ // 将参数node赋值给实例变量this.node
585
+ this.node = node;
586
+ this.mapping = mapping;
587
+ }
588
+ // 处理过程
589
+ dataHandler.prototype.processNode = function (node) {
590
+ var _this = this;
591
+ Object.values(exports.HAS_FEILD).forEach(function (field) {
592
+ if (!(field in node)) {
593
+ var sourceField = Object.keys(_this.mapping).find(function (key) { return _this.mapping[key] === field; });
594
+ if (!sourceField) {
595
+ switch (field) {
596
+ case exports.HAS_FEILD.LABEL:
597
+ node[field] = node[_this.mapping.label] || '';
598
+ break;
599
+ case exports.HAS_FEILD.VALUE:
600
+ node[field] = node[_this.mapping.value] || '';
601
+ break;
602
+ case exports.HAS_FEILD.CHILDREN:
603
+ node[field] = _this.mapping.children;
604
+ break;
605
+ case exports.HAS_FEILD.LEAF:
606
+ node[field] = _this.mapping.leaf;
607
+ break;
608
+ default:
609
+ node[field] = null;
610
+ break;
611
+ }
612
+ }
186
613
  }
187
- code += 'html +=`' + t.tag + '`;\n';
188
- if (t.isFor)
189
- code += '}\n';
190
- if (t.isIf)
191
- code += '}\n';
614
+ });
615
+ return node;
616
+ };
617
+ // 递归
618
+ dataHandler.prototype.processAllNodes = function (node) {
619
+ var _this = this;
620
+ var processedNode = this.processNode(node);
621
+ if (processedNode[this.fields.CHILDREN] && Array.isArray(processedNode[this.fields.CHILDREN])) {
622
+ processedNode[this.fields.CHILDREN] = processedNode[this.fields.CHILDREN].map(function (child) {
623
+ return _this.processAllNodes(child);
624
+ });
192
625
  }
193
- else {
194
- code += 'html +=`' + contentParse(content) + '`;\n';
626
+ return processedNode;
627
+ };
628
+ // getter
629
+ dataHandler.prototype.getProcessedData = function () {
630
+ return this.processAllNodes(this.node);
631
+ };
632
+ return dataHandler;
633
+ }());
634
+ /**
635
+ * @param node 节点
636
+ * @param childPath 子节点路径
637
+ * @returns 构建节点路径的辅助函数
638
+ */
639
+ function buildPath(node, childPath) {
640
+ var path = node.deptName + (childPath ? " -> ".concat(childPath) : '');
641
+ return path;
642
+ }
643
+ /**
644
+ * @param data 树形数据
645
+ * @param targetDeptCode 子节点DeptCode
646
+ * @returns 查找叶子节点并返回路径
647
+ */
648
+ function findTreeDataNode(data, targetDeptCode) {
649
+ for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
650
+ var node = data_1[_i];
651
+ // 如果当前节点的 deptCode 符合目标值
652
+ if (node.deptCode === targetDeptCode) {
653
+ return buildPath(node);
654
+ }
655
+ // 递归查找子节点
656
+ var childPath = findTreeDataNode(node.cldOrgDepts, targetDeptCode);
657
+ if (childPath) {
658
+ return buildPath(node, childPath);
659
+ }
660
+ }
661
+ return null; // 如果没有找到,返回 null
662
+ }
663
+ /**
664
+ * @param dept 树形数据
665
+ * @param queryString 子节点DeptCode
666
+ * @param results 查找结果集
667
+ */
668
+ function findTreeDataNodeName(dept, queryString, results) {
669
+ if (dept.deptName.includes(queryString)) {
670
+ results.push(dept);
671
+ }
672
+ // 如果有子部门,递归查找
673
+ if (dept.cldOrgDepts && dept.cldOrgDepts.length > 0) {
674
+ for (var _i = 0, _a = dept.cldOrgDepts; _i < _a.length; _i++) {
675
+ var child = _a[_i];
676
+ findTreeDataNodeName(child, queryString, results);
195
677
  }
196
678
  }
197
- return code;
198
- }
199
- // 解析模板
200
- // 1. 解析标签
201
- // 2. 替换内容
202
- // 3. 返回渲染结果
203
- // 4. 处理循环和条件
204
- // 5. 返回最终的HTML字符串
205
- // 6. 支持嵌套标签
206
- // 7. 支持条件渲染
207
- // 8. 支持循环渲染
208
- // 9. 支持数据绑定
209
- // 10. 支持内嵌样式绑定
210
- // 11. 支持类绑定
211
- function render(html, context) {
212
- if (context === void 0) { context = {}; }
213
- if (!Reflect.ownKeys(context).length)
214
- return '';
215
- var tags = resolver(html);
216
- var code = compose(tags)
217
- .replaceAll('<annotation>', '<!--')
218
- .replaceAll('</annotation>', '-->');
219
- var renderedContent = new Function("\n let html = ''\n;\n ".concat(code, "\n return html;\n\n "));
220
- return renderedContent.call(context);
221
- }
222
- function replaceElementWithPlaceholder(el, placeholderText) {
223
- if (placeholderText === void 0) { placeholderText = 'PLACEHOLDER'; }
224
- var comment = document.createComment(placeholderText);
225
- el.replaceWith(comment);
226
- return comment; // 可以用于恢复
227
- }
228
- function rebuild(selector, context) {
229
- var element = document.querySelector(selector);
230
- if (!element)
231
- return;
232
- var outerHTML = element.outerHTML;
233
- element.setAttribute('hidden', 'true');
234
- var id = useId();
235
- replaceElementWithPlaceholder(element, id);
236
- var newHtml = render(outerHTML, context);
237
- document.body.innerHTML = document.body.innerHTML.replace("<!--".concat(id, "-->"), newHtml);
238
- element.setAttribute('hidden', 'false');
239
- }
240
- window.s = {
241
- rebuild: rebuild,
242
- render: render
679
+ }
680
+
681
+ var Mask = /** @class */ (function () {
682
+ function Mask(selectors, opacity) {
683
+ if (opacity === void 0) { opacity = 0.3; }
684
+ this.task = [];
685
+ this.selectors = [];
686
+ this.opacity = 0.3;
687
+ this.elementIndex = 0;
688
+ this.selectors = selectors;
689
+ this.opacity = opacity;
690
+ }
691
+ Mask.prototype.start = function () {
692
+ var _this = this;
693
+ this.task.reduce(function (pre, cur, index) { return __awaiter(_this, void 0, void 0, function () {
694
+ return __generator(this, function (_a) {
695
+ switch (_a.label) {
696
+ case 0: return [4 /*yield*/, pre];
697
+ case 1:
698
+ _a.sent();
699
+ return [4 /*yield*/, new Promise(function (resolve) {
700
+ cur.callback(resolve, index);
701
+ })];
702
+ case 2:
703
+ _a.sent();
704
+ this.close();
705
+ return [2 /*return*/];
706
+ }
707
+ });
708
+ }); }, Promise.resolve());
709
+ };
710
+ Mask.prototype.process = function (handle) {
711
+ var _this = this;
712
+ this.task.push({
713
+ callback: function (resolve, index) {
714
+ _this.elementIndex = index;
715
+ _this.open();
716
+ handle(resolve, index, document.querySelector(_this.selectors[index]));
717
+ }
718
+ });
719
+ return this;
720
+ };
721
+ Mask.prototype.open = function (element) {
722
+ if ((element === null || element === void 0 ? void 0 : element.nodeType) === Node.ELEMENT_NODE)
723
+ this.selectors.push(element);
724
+ var currentElement = document.querySelector(this.selectors[this.elementIndex]);
725
+ if (!currentElement)
726
+ return;
727
+ currentElement.style.position = 'relative';
728
+ currentElement.style.boxShadow = "1px 1px 0 100vw rgba(0, 0, 0, ".concat(this.opacity, ")");
729
+ };
730
+ Mask.prototype.close = function () {
731
+ var currentElement = document.querySelector(this.selectors[this.elementIndex]);
732
+ currentElement.style.removeProperty('position');
733
+ currentElement.style.removeProperty('box-shadow');
734
+ };
735
+ return Mask;
736
+ }());
737
+
738
+ var Tour = /** @class */ (function () {
739
+ function Tour(selectors) {
740
+ this.selectors = [];
741
+ this.elementIndex = 0;
742
+ this.tourTargetElement = null;
743
+ this.tourElement = null;
744
+ this.tourElementContentTemplate = "\n <style>\n .tour-content-title {\n font-size: 16px;\n font-weight: 500;\n }\n\n .tour-buttons {\n display: flex;\n justify-content: end;\n margin-top: 14px;\n }\n\n .tour-prev, .tour-next {\n padding: 4px;\n min-width: 40px;\n text-align: center;\n border: 1px solid #000;\n border-radius: 4px;\n cursor: pointer;\n }\n\n .tour-next {\n margin-left: 6px;\n }\n </style>\n <div class=\"tour-content\">\n <p class=\"tour-content-title\">\n <$title>\n </p>\n <p class=\"tour-content-text\">\n <$text>\n </p>\n </div>\n <div class=\"tour-buttons\">\n <div class=\"tour-prev\">prev</div>\n <div class=\"tour-next\"><$next></div>\n </div>\n ";
745
+ this.placeholder = {
746
+ title: '<$title>',
747
+ text: '<$text>',
748
+ next: '<$next>',
749
+ };
750
+ this.config = {
751
+ prev: '.tour-prev',
752
+ next: '.tour-next',
753
+ nextText: 'next',
754
+ closeText: 'close',
755
+ };
756
+ this.selectors = selectors;
757
+ this.tourTargetElement = document.createElement('div');
758
+ this.tourElement = document.createElement('div');
759
+ }
760
+ Tour.prototype.setPlaceholder = function (placeholder) {
761
+ this.placeholder = placeholder;
762
+ };
763
+ Tour.prototype.setContentTemplate = function (template) {
764
+ this.tourElementContentTemplate = template;
765
+ };
766
+ Tour.prototype.setConfig = function (config) {
767
+ this.config = __assign(__assign({}, this.config), config);
768
+ };
769
+ Tour.prototype.start = function () {
770
+ var elementName = this.selectors[this.elementIndex].el;
771
+ var element = document.querySelector(elementName);
772
+ if (element instanceof HTMLElement)
773
+ this.layout(element);
774
+ };
775
+ Tour.prototype.layout = function (element) {
776
+ var _this = this;
777
+ var rect = element === null || element === void 0 ? void 0 : element.getBoundingClientRect();
778
+ var tourTargetElement = this.tourTargetElement;
779
+ var tourElement = this.tourElement;
780
+ if (!tourTargetElement || !tourElement)
781
+ return;
782
+ tourTargetElement.style.padding = '4px';
783
+ tourTargetElement.style.position = 'fixed';
784
+ tourTargetElement.style.top = "".concat((rect === null || rect === void 0 ? void 0 : rect.top) - 4, "px");
785
+ tourTargetElement.style.left = "".concat((rect === null || rect === void 0 ? void 0 : rect.left) - 4, "px");
786
+ tourTargetElement.style.width = "".concat(rect === null || rect === void 0 ? void 0 : rect.width, "px");
787
+ tourTargetElement.style.height = "".concat(rect === null || rect === void 0 ? void 0 : rect.height, "px");
788
+ tourTargetElement.style.zIndex = '60';
789
+ tourTargetElement.style.boxShadow = "1px 1px 0 1000vw rgba(0, 0, 0, 0.3)";
790
+ document.body.appendChild(tourTargetElement);
791
+ tourElement.style.padding = '16px';
792
+ tourElement.style.position = 'fixed';
793
+ tourElement.style.width = "200px";
794
+ tourElement.style.backgroundColor = '#fff';
795
+ tourElement.style.borderRadius = '4px';
796
+ tourElement.style.zIndex = '62';
797
+ tourElement.innerHTML = this.tourElementContentTemplate
798
+ .replace(this.placeholder.title, this.selectors[this.elementIndex].title)
799
+ .replace(this.placeholder.text, this.selectors[this.elementIndex].text)
800
+ .replace(this.placeholder.next, this.elementIndex === this.selectors.length - 1 ? this.config.closeText : this.config.nextText);
801
+ var prevButton = tourElement.querySelector(this.config.prev);
802
+ var nextButton = tourElement.querySelector(this.config.next);
803
+ prevButton === null || prevButton === void 0 ? void 0 : prevButton.addEventListener('click', function () {
804
+ _this.elementIndex--;
805
+ if (_this.elementIndex < 0)
806
+ _this.elementIndex = _this.selectors.length - 1;
807
+ _this.start();
808
+ });
809
+ nextButton === null || nextButton === void 0 ? void 0 : nextButton.addEventListener('click', function () {
810
+ _this.elementIndex++;
811
+ if (_this.elementIndex > _this.selectors.length - 1) {
812
+ _this.elementIndex = 0;
813
+ _this.close();
814
+ return;
815
+ }
816
+ _this.start();
817
+ });
818
+ document.body.appendChild(tourElement);
819
+ if (rect.bottom + 14 + tourElement.offsetHeight >= document.documentElement.clientHeight)
820
+ tourElement.style.top = "".concat((rect === null || rect === void 0 ? void 0 : rect.top) - tourElement.offsetHeight - 14, "px");
821
+ else
822
+ tourElement.style.top = "".concat((rect === null || rect === void 0 ? void 0 : rect.bottom) + 14, "px");
823
+ if (rect.left + tourElement.offsetWidth >= document.documentElement.clientWidth)
824
+ tourElement.style.left = "".concat((rect === null || rect === void 0 ? void 0 : rect.left) - tourElement.offsetWidth - 14, "px");
825
+ else
826
+ tourElement.style.left = "".concat((rect === null || rect === void 0 ? void 0 : rect.left) + 14, "px");
827
+ };
828
+ Tour.prototype.close = function () {
829
+ var tourElement = this.tourElement;
830
+ document.body.removeChild(tourElement);
831
+ document.body.removeChild(this.tourTargetElement);
832
+ };
833
+ return Tour;
834
+ }());
835
+
836
+ var defaultWebSocketConfig = {
837
+ timeout: 6000,
838
+ reconnect: false,
839
+ reconnectTime: 1000,
840
+ maxReconnectNumber: 3,
243
841
  };
842
+ function createWebSocket(url, config, onOpen) {
843
+ config = __assign(__assign({}, defaultWebSocketConfig), config);
844
+ var open = reconnectWebSocket();
845
+ var init = function () {
846
+ var ws = new WebSocket(url);
847
+ ws.onopen = function () {
848
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen();
849
+ };
850
+ ws.onerror = function () {
851
+ if ((config === null || config === void 0 ? void 0 : config.reconnect) && open) {
852
+ open(ws, config, init);
853
+ }
854
+ else {
855
+ open = null;
856
+ config = null;
857
+ }
858
+ };
859
+ return ws;
860
+ };
861
+ return init();
862
+ }
863
+ function reconnectWebSocket() {
864
+ var reconnectTimeout;
865
+ var reconnectNumber = 0;
866
+ var open = function (ws, config, callback) {
867
+ var reconnectTime = config.reconnectTime, _a = config.maxReconnectNumber, maxReconnectNumber = _a === void 0 ? 1 : _a;
868
+ var isOpen = getState(ws, 'OPEN');
869
+ if (isOpen || (reconnectTimeout && reconnectNumber >= maxReconnectNumber)) {
870
+ clearTimeout(reconnectTimeout);
871
+ reconnectTimeout = null;
872
+ reconnectNumber = null;
873
+ config.reconnect = false;
874
+ return;
875
+ }
876
+ reconnectTimeout = setTimeout(function () {
877
+ reconnectNumber += 1;
878
+ callback();
879
+ }, reconnectTime);
880
+ };
881
+ return open;
882
+ }
883
+ function useSendMessage(ws, data) {
884
+ var isOpen = getState(ws, 'OPEN');
885
+ if (isOpen)
886
+ ws.send(JSON.stringify(data));
887
+ }
888
+ function useWebSocketMessage(ws, callback) {
889
+ try {
890
+ ws.onmessage = function (e) {
891
+ var data = JSON.parse(e.data);
892
+ callback(data, e);
893
+ };
894
+ }
895
+ catch (error) {
896
+ console.error(error);
897
+ }
898
+ }
899
+ function useWebSocketClose(ws, code, message) {
900
+ code = code || 1000;
901
+ message = message || 'connection closed by client';
902
+ ws.close(code, message);
903
+ }
904
+ function getState(ws, type) {
905
+ return ws.readyState === WebSocket[type];
906
+ }
244
907
 
245
- exports.RecordType = void 0;
246
- (function (RecordType) {
247
- RecordType["AUDIO"] = "audio";
248
- RecordType["VIDEO"] = "video";
249
- RecordType["SCREEN"] = "screen";
250
- })(exports.RecordType || (exports.RecordType = {}));
908
+ /**
909
+ * 匹配中文字母数字
910
+ */
911
+ var ZN_LETTER_NUMBER = /^[\u4E00-\u9FA5\w]+$/;
912
+ /**
913
+ * 匹配 IP
914
+ */
915
+ var IP = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})$/;
916
+ /**
917
+ * 匹配手机号
918
+ */
919
+ var PHONE = /^1[3-9]\d{9}$/;
920
+
921
+ exports.IP = IP;
922
+ exports.InputLegalityValidate = InputLegalityValidate;
923
+ exports.InputLengthValidate = InputLengthValidate;
924
+ exports.Mask = Mask;
925
+ exports.PHONE = PHONE;
926
+ exports.Request = Request;
927
+ exports.RequestChain = RequestChain;
928
+ exports.Tour = Tour;
929
+ exports.ZN_LETTER_NUMBER = ZN_LETTER_NUMBER;
930
+ exports.createWebSocket = createWebSocket;
931
+ exports.dataHandler = dataHandler;
932
+ exports.debounce = debounce;
933
+ exports.deepMerge = deepMerge;
934
+ exports.findTreeDataNode = findTreeDataNode;
935
+ exports.findTreeDataNodeName = findTreeDataNodeName;
936
+ exports.getState = getState;
937
+ exports.isMobileDevice = isMobileDevice;
938
+ exports.isNull = isNull;
939
+ exports.objectArrayToString = objectArrayToString;
940
+ exports.throttle = throttle;
941
+ exports.useCountDown = useCountDown;
942
+ exports.useSendMessage = useSendMessage;
943
+ exports.useWebSocketClose = useWebSocketClose;
944
+ exports.useWebSocketMessage = useWebSocketMessage;
251
945
 
252
946
  }));