@rugal.tu/vuemodel3 1.5.8 → 1.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/VueModel.d.ts +8 -6
- package/src/VueModel.ts +36 -15
- package/dist/VueModel.esm.js +0 -1963
- package/dist/VueModel.esm.min.js +0 -2
- package/dist/VueModel.esm.min.js.map +0 -7
- package/dist/VueModel.umd.js +0 -1984
- package/dist/VueModel.umd.min.js +0 -2
- package/dist/VueModel.umd.min.js.map +0 -7
- package/src/esm/VueModel.js +0 -1963
- package/src/esm/VueModel.js.map +0 -1
- package/src/umd/VueModel.js +0 -1984
- package/src/umd/VueModel.js.map +0 -1
package/dist/VueModel.umd.js
DELETED
|
@@ -1,1984 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "vue", "vue"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Model = exports.VueModel = exports.VueCommand = exports.VueStore = exports.ApiStore = exports.FileItem = exports.Queryer = exports.DomQueryer = exports.QueryNode = exports.FuncBase = void 0;
|
|
13
|
-
class FuncBase {
|
|
14
|
-
$NavigateToFunc;
|
|
15
|
-
$DefaultDateJoinChar;
|
|
16
|
-
constructor() {
|
|
17
|
-
this.$NavigateToFunc = null;
|
|
18
|
-
this.WithDateTextJoinChar('/');
|
|
19
|
-
}
|
|
20
|
-
WithNavigateTo(NavigateToFunc) {
|
|
21
|
-
this.$NavigateToFunc = NavigateToFunc;
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
WithDateTextJoinChar(JoinChar) {
|
|
25
|
-
this.$DefaultDateJoinChar = JoinChar;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
GenerateId() {
|
|
29
|
-
let NewId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {
|
|
30
|
-
let RandomValue = crypto.getRandomValues(new Uint8Array(1))[0] & 15;
|
|
31
|
-
let Id = char === 'x' ? RandomValue : (RandomValue & 0x3) | 0x8;
|
|
32
|
-
return Id.toString(16);
|
|
33
|
-
});
|
|
34
|
-
return NewId;
|
|
35
|
-
}
|
|
36
|
-
GenerateIdReplace(FillString) {
|
|
37
|
-
let Id = this.GenerateId().replaceAll('-', FillString);
|
|
38
|
-
return Id;
|
|
39
|
-
}
|
|
40
|
-
GenerateUrl(Url, UrlParam = null) {
|
|
41
|
-
let UrlPaths = this.Paths(Url);
|
|
42
|
-
if (UrlPaths == null || UrlPaths.length == 0 || UrlPaths[0].length == 0)
|
|
43
|
-
this.$Throw('Url can not be null or empty');
|
|
44
|
-
UrlPaths = UrlPaths.map(Item => Item.replace(/\/+$/g, '').replace(/^\/+/g, '/'));
|
|
45
|
-
let CombineUrl = this.ToJoin(UrlPaths, '/');
|
|
46
|
-
if (CombineUrl == null || CombineUrl == '')
|
|
47
|
-
CombineUrl = '/';
|
|
48
|
-
if (UrlParam != null) {
|
|
49
|
-
UrlParam = this.ConvertTo_UrlQuery(UrlParam);
|
|
50
|
-
CombineUrl += `?${UrlParam}`;
|
|
51
|
-
}
|
|
52
|
-
return CombineUrl;
|
|
53
|
-
}
|
|
54
|
-
$BaseNavigateTo(Url) {
|
|
55
|
-
if (this.$NavigateToFunc)
|
|
56
|
-
this.$NavigateToFunc(Url);
|
|
57
|
-
else
|
|
58
|
-
window.location.href = Url;
|
|
59
|
-
}
|
|
60
|
-
NavigateToRoot() {
|
|
61
|
-
let RootUrl = '/';
|
|
62
|
-
this.$BaseNavigateTo(RootUrl);
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
NavigateTo(Url, UrlParam = null) {
|
|
66
|
-
let TargetUrl = this.GenerateUrl(Url, UrlParam);
|
|
67
|
-
this.$BaseNavigateTo(TargetUrl);
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
$BaseNavigateBlank(Url) {
|
|
71
|
-
let Link = document.createElement('a');
|
|
72
|
-
Link.href = Url;
|
|
73
|
-
Link.target = '_blank';
|
|
74
|
-
Link.rel = 'noopener noreferrer';
|
|
75
|
-
Link.click();
|
|
76
|
-
}
|
|
77
|
-
NavigateBlank(Url, UrlParam = null) {
|
|
78
|
-
let TargetUrl = this.GenerateUrl(Url, UrlParam);
|
|
79
|
-
this.$BaseNavigateBlank(TargetUrl);
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
ForEachObject(Param, Func) {
|
|
83
|
-
for (let Key of Object.getOwnPropertyNames(Param)) {
|
|
84
|
-
if (Key.match(/^$/g))
|
|
85
|
-
continue;
|
|
86
|
-
let Value = Param[Key];
|
|
87
|
-
if (Func != null)
|
|
88
|
-
Func.call(this, Key, Value);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
DeepObjectExtend(Target, Source, MaxDepth = 10) {
|
|
92
|
-
if (MaxDepth == 0)
|
|
93
|
-
return {
|
|
94
|
-
...Target,
|
|
95
|
-
...Source,
|
|
96
|
-
};
|
|
97
|
-
let AllKeys = Object.keys(Source);
|
|
98
|
-
for (let i = 0; i < AllKeys.length; i++) {
|
|
99
|
-
let Key = AllKeys[i];
|
|
100
|
-
if (!(Key in Target))
|
|
101
|
-
Target[Key] = Source[Key];
|
|
102
|
-
else if (typeof Source[Key] != "object")
|
|
103
|
-
Target[Key] = Source[Key];
|
|
104
|
-
else {
|
|
105
|
-
let NewObject = {
|
|
106
|
-
...this.DeepObjectExtend(Target[Key], Source[Key], MaxDepth - 1),
|
|
107
|
-
};
|
|
108
|
-
Target[Key] = NewObject;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return Target;
|
|
112
|
-
}
|
|
113
|
-
ToDateInfo(QueryDate) {
|
|
114
|
-
QueryDate ??= new Date();
|
|
115
|
-
let Info = this.$CreateDateInfo(QueryDate);
|
|
116
|
-
return Info;
|
|
117
|
-
}
|
|
118
|
-
ToDateText(QueryDate, Option) {
|
|
119
|
-
QueryDate = this.$CreateDateInfo(QueryDate);
|
|
120
|
-
Option ??= {};
|
|
121
|
-
if (typeof Option == 'string')
|
|
122
|
-
Option = { Format: Option };
|
|
123
|
-
Option.DateJoinChar ??= this.$DefaultDateJoinChar;
|
|
124
|
-
Option.Format ??= `yyyy${Option.DateJoinChar}MM${Option.DateJoinChar}dd`;
|
|
125
|
-
let Result = Option.Format;
|
|
126
|
-
Result = Result.replaceAll('yyyy', QueryDate.Year.toString().padStart(4, '0'));
|
|
127
|
-
Result = Result.replaceAll('MM', QueryDate.Month.toString().padStart(2, '0'));
|
|
128
|
-
Result = Result.replaceAll('dd', QueryDate.Day.toString().padStart(2, '0'));
|
|
129
|
-
Option.Format = Result;
|
|
130
|
-
return Result;
|
|
131
|
-
}
|
|
132
|
-
ToDateTimeText(QueryDate, Option) {
|
|
133
|
-
Option ??= {};
|
|
134
|
-
if (typeof Option == 'string')
|
|
135
|
-
Option = { Format: Option };
|
|
136
|
-
Option.DateJoinChar ??= this.$DefaultDateJoinChar;
|
|
137
|
-
Option.Format ??= `yyyy${Option.DateJoinChar}MM${Option.DateJoinChar}dd HH:mm:ss`;
|
|
138
|
-
Option = { ...Option };
|
|
139
|
-
QueryDate = this.$CreateDateInfo(QueryDate);
|
|
140
|
-
this.ToDateText(QueryDate, Option);
|
|
141
|
-
let Result = Option.Format;
|
|
142
|
-
Result = Result.replaceAll('HH', QueryDate.Hour.toString().padStart(2, '0'));
|
|
143
|
-
Result = Result.replaceAll('mm', QueryDate.Minute.toString().padStart(2, '0'));
|
|
144
|
-
Result = Result.replaceAll('ss', QueryDate.Second.toString().padStart(2, '0'));
|
|
145
|
-
return Result;
|
|
146
|
-
}
|
|
147
|
-
$CreateDateInfo(DateOrText) {
|
|
148
|
-
DateOrText ??= new Date();
|
|
149
|
-
if (typeof DateOrText === 'string')
|
|
150
|
-
DateOrText = new Date(DateOrText);
|
|
151
|
-
if (DateOrText instanceof Date == false)
|
|
152
|
-
return DateOrText;
|
|
153
|
-
let Result = {
|
|
154
|
-
Date: DateOrText,
|
|
155
|
-
Year: DateOrText.getFullYear(),
|
|
156
|
-
Month: DateOrText.getMonth() + 1,
|
|
157
|
-
Day: DateOrText.getDate(),
|
|
158
|
-
Hour: DateOrText.getHours(),
|
|
159
|
-
Minute: DateOrText.getMinutes(),
|
|
160
|
-
Second: DateOrText.getSeconds(),
|
|
161
|
-
};
|
|
162
|
-
return Result;
|
|
163
|
-
}
|
|
164
|
-
ConvertTo_UrlQuery(Param) {
|
|
165
|
-
if (typeof Param === 'string')
|
|
166
|
-
return Param;
|
|
167
|
-
let AllParam = [];
|
|
168
|
-
this.ForEachObject(Param, (Key, Value) => {
|
|
169
|
-
AllParam.push(`${Key}=${Value}`);
|
|
170
|
-
});
|
|
171
|
-
let QueryString = AllParam.join('&');
|
|
172
|
-
return QueryString;
|
|
173
|
-
}
|
|
174
|
-
ClearUrl(ApiUrl) {
|
|
175
|
-
let ClearUrl = ApiUrl.replace(/^\/+|\/+$/g, '');
|
|
176
|
-
return ClearUrl;
|
|
177
|
-
}
|
|
178
|
-
ToJoin(Value, Separator = '.') {
|
|
179
|
-
let ConvertArray = this.Paths(Value);
|
|
180
|
-
let Result = ConvertArray.join(Separator);
|
|
181
|
-
return Result;
|
|
182
|
-
}
|
|
183
|
-
Paths(...Value) {
|
|
184
|
-
if (!Array.isArray(Value))
|
|
185
|
-
return [Value];
|
|
186
|
-
let Result = [];
|
|
187
|
-
for (let Item of Value) {
|
|
188
|
-
if (Item == null)
|
|
189
|
-
continue;
|
|
190
|
-
if (!Array.isArray(Item)) {
|
|
191
|
-
Result.push(Item);
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
if (Item.length == 0)
|
|
195
|
-
continue;
|
|
196
|
-
Result.push(...this.Paths(...Item));
|
|
197
|
-
}
|
|
198
|
-
return Result;
|
|
199
|
-
}
|
|
200
|
-
IsPathType(CheckPathType) {
|
|
201
|
-
if (Array.isArray(CheckPathType)) {
|
|
202
|
-
for (let Item of CheckPathType) {
|
|
203
|
-
let IsTrue = this.IsPathType(Item);
|
|
204
|
-
if (!IsTrue)
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
else if (typeof (CheckPathType) == 'string') {
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
$Throw(Message) {
|
|
215
|
-
throw new Error(Message);
|
|
216
|
-
}
|
|
217
|
-
$Error(Data) {
|
|
218
|
-
console.error(Data);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
exports.FuncBase = FuncBase;
|
|
222
|
-
class QueryNode extends FuncBase {
|
|
223
|
-
NodeId;
|
|
224
|
-
Dom;
|
|
225
|
-
DomName = null;
|
|
226
|
-
Parent = null;
|
|
227
|
-
Children = [];
|
|
228
|
-
ElementDeep = 0;
|
|
229
|
-
NodeDeep = 0;
|
|
230
|
-
constructor(Dom) {
|
|
231
|
-
super();
|
|
232
|
-
this.Dom = Dom;
|
|
233
|
-
this.NodeId = this.GenerateIdReplace('');
|
|
234
|
-
}
|
|
235
|
-
Query(DomName, Option) {
|
|
236
|
-
return this.$RCS_QueryChildrens(this, DomName, Option);
|
|
237
|
-
}
|
|
238
|
-
QueryCss(Selector, Option) {
|
|
239
|
-
return this.$RCS_QueryCssChildrens(this, Selector, Option);
|
|
240
|
-
}
|
|
241
|
-
Selector(Selector) {
|
|
242
|
-
return this.Dom.querySelector(Selector);
|
|
243
|
-
}
|
|
244
|
-
SelectorAll(Selector) {
|
|
245
|
-
return this.Dom.querySelectorAll(Selector);
|
|
246
|
-
}
|
|
247
|
-
$RCS_QueryChildrens(TargetNode, DomName, Option) {
|
|
248
|
-
if (DomName == null)
|
|
249
|
-
return null;
|
|
250
|
-
DomName = this.Paths(DomName);
|
|
251
|
-
if (DomName.length == 1)
|
|
252
|
-
DomName = DomName[0];
|
|
253
|
-
let Results = [];
|
|
254
|
-
for (let NodeItem of TargetNode.Children) {
|
|
255
|
-
if (Array.isArray(DomName)) {
|
|
256
|
-
let Names = [...DomName];
|
|
257
|
-
let FirstName = Names.shift();
|
|
258
|
-
if (NodeItem.DomName == FirstName) {
|
|
259
|
-
if (Names.length == 1)
|
|
260
|
-
Names = Names[0];
|
|
261
|
-
let FindChildren = this.$RCS_QueryChildrens(NodeItem, Names, Option);
|
|
262
|
-
if (FindChildren != null) {
|
|
263
|
-
Results.push(...FindChildren);
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
else if (NodeItem.DomName == DomName) {
|
|
269
|
-
Results.push(NodeItem);
|
|
270
|
-
if (Option.Mode == 'Multi')
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
let ChildrenResult = this.$RCS_QueryChildrens(NodeItem, DomName, Option);
|
|
274
|
-
if (ChildrenResult != null)
|
|
275
|
-
Results.push(...ChildrenResult);
|
|
276
|
-
}
|
|
277
|
-
return Results;
|
|
278
|
-
}
|
|
279
|
-
$RCS_QueryCssChildrens(TargetNode, Selector, Option) {
|
|
280
|
-
let Results = [];
|
|
281
|
-
for (let NodeItem of TargetNode.Children) {
|
|
282
|
-
if (NodeItem.Dom.matches(Selector)) {
|
|
283
|
-
Results.push(NodeItem);
|
|
284
|
-
if (Option.Mode == 'Multi')
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
let ChildrenResult = this.$RCS_QueryCssChildrens(NodeItem, Selector, Option);
|
|
288
|
-
if (ChildrenResult != null)
|
|
289
|
-
Results.push(...ChildrenResult);
|
|
290
|
-
}
|
|
291
|
-
return Results;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
exports.QueryNode = QueryNode;
|
|
295
|
-
class DomQueryer {
|
|
296
|
-
$Root = null;
|
|
297
|
-
$RootNode = null;
|
|
298
|
-
$Nodes = [];
|
|
299
|
-
$QueryDomName = null;
|
|
300
|
-
IsInited = false;
|
|
301
|
-
WithRoot(Filter) {
|
|
302
|
-
this.$Root = document.querySelector(Filter);
|
|
303
|
-
return this;
|
|
304
|
-
}
|
|
305
|
-
WithDomName(QueryDomName) {
|
|
306
|
-
this.$QueryDomName = QueryDomName;
|
|
307
|
-
return this;
|
|
308
|
-
}
|
|
309
|
-
Init(IsReInited = false) {
|
|
310
|
-
if (this.IsInited && !IsReInited)
|
|
311
|
-
return this;
|
|
312
|
-
this.$Root ??= document.body;
|
|
313
|
-
this.$RootNode = new QueryNode(this.$Root);
|
|
314
|
-
this.$RCS_Visit(this.$Root, this.$RootNode, 0);
|
|
315
|
-
this.$Nodes = this.$Nodes.sort((A, B) => A.NodeDeep - B.NodeDeep);
|
|
316
|
-
this.IsInited = true;
|
|
317
|
-
return this;
|
|
318
|
-
}
|
|
319
|
-
Query(DomName, Option) {
|
|
320
|
-
if (!exports.Queryer.IsInited)
|
|
321
|
-
exports.Queryer.Init();
|
|
322
|
-
if (Option == null) {
|
|
323
|
-
Option = {
|
|
324
|
-
Mode: 'Multi',
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
else if (Option instanceof QueryNode) {
|
|
328
|
-
Option = {
|
|
329
|
-
Mode: 'Multi',
|
|
330
|
-
TargetNode: Option,
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
if (Option.TargetNode == null)
|
|
334
|
-
Option.TargetNode = this.$RootNode;
|
|
335
|
-
return Option.TargetNode.Query(DomName, Option);
|
|
336
|
-
}
|
|
337
|
-
QueryCss(Selector, Option) {
|
|
338
|
-
if (!exports.Queryer.IsInited)
|
|
339
|
-
exports.Queryer.Init();
|
|
340
|
-
if (Option == null) {
|
|
341
|
-
Option = {
|
|
342
|
-
Mode: 'Multi',
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
else if (Option instanceof QueryNode) {
|
|
346
|
-
Option = {
|
|
347
|
-
Mode: 'Multi',
|
|
348
|
-
TargetNode: Option,
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
if (Option.TargetNode == null)
|
|
352
|
-
Option.TargetNode = this.$RootNode;
|
|
353
|
-
return Option.TargetNode.QueryCss(Selector, Option);
|
|
354
|
-
}
|
|
355
|
-
Using(DomName, UsingFunc, TargetNode) {
|
|
356
|
-
let QueryNodes = this.Query(DomName, {
|
|
357
|
-
Mode: 'Multi',
|
|
358
|
-
TargetNode: TargetNode,
|
|
359
|
-
});
|
|
360
|
-
if (QueryNodes != null && QueryNodes.length > 0) {
|
|
361
|
-
UsingFunc({
|
|
362
|
-
QueryNodes,
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
return this;
|
|
366
|
-
}
|
|
367
|
-
$RCS_Visit(DomNode, Parent, ElementDeep) {
|
|
368
|
-
let NextNode = this.$AddNode(DomNode, Parent, ElementDeep);
|
|
369
|
-
NextNode ??= Parent;
|
|
370
|
-
let Children = DomNode.children;
|
|
371
|
-
if (DomNode instanceof HTMLTemplateElement)
|
|
372
|
-
Children = DomNode.content.children;
|
|
373
|
-
if (Children == null || Children.length == 0)
|
|
374
|
-
return;
|
|
375
|
-
for (let i = 0; i < Children.length; i++) {
|
|
376
|
-
let Item = Children[i];
|
|
377
|
-
if (Item instanceof HTMLElement)
|
|
378
|
-
this.$RCS_Visit(Item, NextNode, ElementDeep + 1);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
$AddNode(Dom, Parent, ElementDeep) {
|
|
382
|
-
if (this.$QueryDomName != null && !Dom.matches(`[${this.$QueryDomName}]`))
|
|
383
|
-
return null;
|
|
384
|
-
let DomName = Dom.getAttribute(this.$QueryDomName);
|
|
385
|
-
let NewNode = new QueryNode(Dom);
|
|
386
|
-
NewNode.DomName = DomName;
|
|
387
|
-
NewNode.ElementDeep = ElementDeep;
|
|
388
|
-
this.$Nodes.push(NewNode);
|
|
389
|
-
if (Parent != null) {
|
|
390
|
-
NewNode.Parent = Parent;
|
|
391
|
-
NewNode.NodeDeep = Parent.NodeDeep + 1;
|
|
392
|
-
Parent.Children.push(NewNode);
|
|
393
|
-
}
|
|
394
|
-
return NewNode;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
exports.DomQueryer = DomQueryer;
|
|
398
|
-
exports.Queryer = new DomQueryer();
|
|
399
|
-
class FileItem {
|
|
400
|
-
OnChangeBase64;
|
|
401
|
-
OnChangeBuffer;
|
|
402
|
-
$Store;
|
|
403
|
-
constructor(File, ConvertType = 'none') {
|
|
404
|
-
if (File == null)
|
|
405
|
-
this.$Store = (0, vue_1.reactive)({});
|
|
406
|
-
else {
|
|
407
|
-
this.$Store = (0, vue_1.reactive)({
|
|
408
|
-
FileId: new FuncBase().GenerateId(),
|
|
409
|
-
File: File,
|
|
410
|
-
ConvertType: ConvertType,
|
|
411
|
-
Base64: null,
|
|
412
|
-
Buffer: null,
|
|
413
|
-
IsLoaded: false,
|
|
414
|
-
IsLoading: true,
|
|
415
|
-
Error: null,
|
|
416
|
-
});
|
|
417
|
-
this.$ConvertFile();
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
get FileId() {
|
|
421
|
-
return this.$Store.FileId;
|
|
422
|
-
}
|
|
423
|
-
set FileId(Value) {
|
|
424
|
-
this.$Store.FileId = Value;
|
|
425
|
-
}
|
|
426
|
-
get File() {
|
|
427
|
-
return this.$Store.File;
|
|
428
|
-
}
|
|
429
|
-
set File(Value) {
|
|
430
|
-
this.$Store.File = Value;
|
|
431
|
-
}
|
|
432
|
-
get ConvertType() {
|
|
433
|
-
return this.$Store.ConvertType;
|
|
434
|
-
}
|
|
435
|
-
set ConvertType(Value) {
|
|
436
|
-
this.$Store.ConvertType = Value;
|
|
437
|
-
}
|
|
438
|
-
get Base64() {
|
|
439
|
-
return this.$Store.Base64;
|
|
440
|
-
}
|
|
441
|
-
set Base64(Value) {
|
|
442
|
-
this.$Store.Base64 = Value;
|
|
443
|
-
this.OnChangeBase64?.call(this, this.$Store.Base64);
|
|
444
|
-
}
|
|
445
|
-
get Buffer() {
|
|
446
|
-
return this.$Store.Buffer;
|
|
447
|
-
}
|
|
448
|
-
set Buffer(Value) {
|
|
449
|
-
this.$Store.Buffer = Value;
|
|
450
|
-
this.OnChangeBuffer?.call(this, this.$Store.Buffer);
|
|
451
|
-
}
|
|
452
|
-
get InnerStore() {
|
|
453
|
-
return this.$Store;
|
|
454
|
-
}
|
|
455
|
-
get IsLoaded() {
|
|
456
|
-
return this.$Store.IsLoaded;
|
|
457
|
-
}
|
|
458
|
-
get IsLoading() {
|
|
459
|
-
return this.$Store.IsLoading;
|
|
460
|
-
}
|
|
461
|
-
get Error() {
|
|
462
|
-
return this.$Store.Error;
|
|
463
|
-
}
|
|
464
|
-
Clear() {
|
|
465
|
-
this.$Store.Base64 = null;
|
|
466
|
-
this.$Store.Buffer = null;
|
|
467
|
-
this.$Store.File = null;
|
|
468
|
-
}
|
|
469
|
-
From(Item) {
|
|
470
|
-
this.$Store = Item.InnerStore;
|
|
471
|
-
}
|
|
472
|
-
CheckLoadAsync() {
|
|
473
|
-
return new Promise((resolve, reject) => {
|
|
474
|
-
try {
|
|
475
|
-
if (this.$Store.IsLoaded || !this.$Store.IsLoading)
|
|
476
|
-
return resolve(this.$Store.IsLoaded);
|
|
477
|
-
const timeout = setTimeout(() => {
|
|
478
|
-
if (timer)
|
|
479
|
-
clearInterval(timer);
|
|
480
|
-
this.$Store.Error = 'timeout';
|
|
481
|
-
console.error("WaitLoadAsync: timeout");
|
|
482
|
-
reject(false);
|
|
483
|
-
}, 60000);
|
|
484
|
-
const timer = setInterval(() => {
|
|
485
|
-
if (this.$Store.IsLoaded || !this.$Store.IsLoading) {
|
|
486
|
-
clearInterval(timer);
|
|
487
|
-
clearTimeout(timeout);
|
|
488
|
-
resolve(this.$Store.IsLoaded);
|
|
489
|
-
}
|
|
490
|
-
}, 100);
|
|
491
|
-
}
|
|
492
|
-
catch (e) {
|
|
493
|
-
this.$Store.Error = e;
|
|
494
|
-
console.error(e);
|
|
495
|
-
reject(false);
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
$ConvertFile() {
|
|
500
|
-
if (this.ConvertType == null)
|
|
501
|
-
return;
|
|
502
|
-
let GetConvertType = [];
|
|
503
|
-
if (Array.isArray(this.ConvertType))
|
|
504
|
-
GetConvertType = this.ConvertType;
|
|
505
|
-
else
|
|
506
|
-
GetConvertType = [this.ConvertType];
|
|
507
|
-
for (let i = 0; i < GetConvertType.length; i++) {
|
|
508
|
-
let TypeItem = GetConvertType[i];
|
|
509
|
-
switch (TypeItem) {
|
|
510
|
-
case 'base64':
|
|
511
|
-
this.$Store.IsLoading = true;
|
|
512
|
-
this.$ConvertBase64();
|
|
513
|
-
break;
|
|
514
|
-
case 'buffer':
|
|
515
|
-
this.$Store.IsLoading = true;
|
|
516
|
-
this.$ConvertBuffer();
|
|
517
|
-
break;
|
|
518
|
-
default:
|
|
519
|
-
this.$Store.IsLoaded = true;
|
|
520
|
-
break;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
$ConvertBase64(IsForce = false) {
|
|
525
|
-
if (this.File == null)
|
|
526
|
-
return this;
|
|
527
|
-
if (this.Base64 != null && IsForce == false)
|
|
528
|
-
return this;
|
|
529
|
-
let Reader = new FileReader();
|
|
530
|
-
Reader.readAsDataURL(this.File);
|
|
531
|
-
Reader.onload = () => {
|
|
532
|
-
this.Base64 = Reader.result;
|
|
533
|
-
this.$Store.IsLoaded = true;
|
|
534
|
-
this.$Store.IsLoading = false;
|
|
535
|
-
};
|
|
536
|
-
return this;
|
|
537
|
-
}
|
|
538
|
-
$ConvertBuffer() {
|
|
539
|
-
let Reader = new FileReader();
|
|
540
|
-
Reader.readAsArrayBuffer(this.File);
|
|
541
|
-
Reader.onload = () => {
|
|
542
|
-
this.Buffer = Reader.result;
|
|
543
|
-
this.$Store.IsLoaded = true;
|
|
544
|
-
this.$Store.IsLoading = false;
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
exports.FileItem = FileItem;
|
|
549
|
-
class ApiStore extends FuncBase {
|
|
550
|
-
#ApiDomain = null;
|
|
551
|
-
#RootRoute = null;
|
|
552
|
-
#AccessToken = null;
|
|
553
|
-
#RefreshToken = null;
|
|
554
|
-
#HeaderFuncs = [];
|
|
555
|
-
#OnEventFunc = {};
|
|
556
|
-
#OnEventName = {
|
|
557
|
-
ApiStore: {
|
|
558
|
-
AddApi: 'AddApi',
|
|
559
|
-
UpdateStore: 'UpdateStore',
|
|
560
|
-
AddStore: 'AddStore',
|
|
561
|
-
SetStore: 'SetStore',
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
#OnSuccess;
|
|
565
|
-
#OnError;
|
|
566
|
-
#OnComplete;
|
|
567
|
-
#ExportSuccessStore;
|
|
568
|
-
#Store = {
|
|
569
|
-
FileStore: {},
|
|
570
|
-
};
|
|
571
|
-
#Func_ConvertTo_FormData = [];
|
|
572
|
-
constructor() {
|
|
573
|
-
super();
|
|
574
|
-
this.SetStore('api', {});
|
|
575
|
-
}
|
|
576
|
-
get ApiDomain() {
|
|
577
|
-
if (this.#ApiDomain == null)
|
|
578
|
-
return null;
|
|
579
|
-
return this.ClearUrl(this.#ApiDomain);
|
|
580
|
-
}
|
|
581
|
-
set ApiDomain(ApiDomain) {
|
|
582
|
-
this.#ApiDomain = this.ClearUrl(ApiDomain);
|
|
583
|
-
}
|
|
584
|
-
get OnEventName() {
|
|
585
|
-
return this.#OnEventName;
|
|
586
|
-
}
|
|
587
|
-
get #EventName() {
|
|
588
|
-
return this.OnEventName.ApiStore;
|
|
589
|
-
}
|
|
590
|
-
get Store() {
|
|
591
|
-
return this.#Store;
|
|
592
|
-
}
|
|
593
|
-
set Store(Store) {
|
|
594
|
-
this.#Store = Store;
|
|
595
|
-
}
|
|
596
|
-
get ApiStore() {
|
|
597
|
-
return this.GetStore('api');
|
|
598
|
-
}
|
|
599
|
-
get FileStore() {
|
|
600
|
-
return this.Store.FileStore;
|
|
601
|
-
}
|
|
602
|
-
WithAccessToken(AccessToken) {
|
|
603
|
-
this.#AccessToken = AccessToken;
|
|
604
|
-
return this;
|
|
605
|
-
}
|
|
606
|
-
WithRefreshToken(RefreshToken) {
|
|
607
|
-
this.#RefreshToken = RefreshToken;
|
|
608
|
-
return this;
|
|
609
|
-
}
|
|
610
|
-
WithApiDomain(ApiDomain) {
|
|
611
|
-
this.ApiDomain = ApiDomain;
|
|
612
|
-
return this;
|
|
613
|
-
}
|
|
614
|
-
WithRootRoute(Route) {
|
|
615
|
-
this.#RootRoute = Route;
|
|
616
|
-
return this;
|
|
617
|
-
}
|
|
618
|
-
WithHeader(Func) {
|
|
619
|
-
this.#HeaderFuncs.push(Func);
|
|
620
|
-
return this;
|
|
621
|
-
}
|
|
622
|
-
WithOnSuccess(SuccessFunc) {
|
|
623
|
-
this.#OnSuccess = SuccessFunc;
|
|
624
|
-
return this;
|
|
625
|
-
}
|
|
626
|
-
WithOnError(ErrorFunc) {
|
|
627
|
-
this.#OnError = ErrorFunc;
|
|
628
|
-
return this;
|
|
629
|
-
}
|
|
630
|
-
WithOnComplete(CompleteFunc) {
|
|
631
|
-
this.#OnComplete = CompleteFunc;
|
|
632
|
-
return this;
|
|
633
|
-
}
|
|
634
|
-
WithExportSuccessStore(ExportSuccessStoreFunc) {
|
|
635
|
-
this.#ExportSuccessStore = ExportSuccessStoreFunc;
|
|
636
|
-
return this;
|
|
637
|
-
}
|
|
638
|
-
WithConvertTo_FormParam(ConvertToFunc) {
|
|
639
|
-
this.#Func_ConvertTo_FormData.push(ConvertToFunc);
|
|
640
|
-
return this;
|
|
641
|
-
}
|
|
642
|
-
ClearConvertTo_FormParam() {
|
|
643
|
-
this.#Func_ConvertTo_FormData = [];
|
|
644
|
-
return this;
|
|
645
|
-
}
|
|
646
|
-
ConvertTo_ApiUrl(Url, Param = null) {
|
|
647
|
-
let ApiDomainUrl = Url;
|
|
648
|
-
if (this.ApiDomain != null && !ApiDomainUrl.includes('http'))
|
|
649
|
-
ApiDomainUrl = `${this.ApiDomain}/${this.ClearUrl(ApiDomainUrl)}`;
|
|
650
|
-
if (Param != null)
|
|
651
|
-
ApiDomainUrl = `${ApiDomainUrl}?${this.ConvertTo_UrlQuery(Param)}`;
|
|
652
|
-
return ApiDomainUrl;
|
|
653
|
-
}
|
|
654
|
-
AddApi(AddApi) {
|
|
655
|
-
for (let ApiKey in AddApi) {
|
|
656
|
-
let ApiOption = AddApi[ApiKey];
|
|
657
|
-
let SetApi = {
|
|
658
|
-
ApiKey,
|
|
659
|
-
...ApiOption,
|
|
660
|
-
};
|
|
661
|
-
this.AddStoreFrom(this.ApiStore, ApiKey, {});
|
|
662
|
-
this.UpdateStoreFrom(this.ApiStore, ApiKey, SetApi);
|
|
663
|
-
this.$EventTrigger(this.#EventName.AddApi, SetApi);
|
|
664
|
-
}
|
|
665
|
-
return this;
|
|
666
|
-
}
|
|
667
|
-
ApiCall(ApiKey, Option = null) {
|
|
668
|
-
this.$BaseApiCall(ApiKey, Option, false);
|
|
669
|
-
return this;
|
|
670
|
-
}
|
|
671
|
-
ApiCall_Form(ApiKey, Option = null) {
|
|
672
|
-
this.$BaseApiCall(ApiKey, Option, true);
|
|
673
|
-
return this;
|
|
674
|
-
}
|
|
675
|
-
$BaseApiCall(ApiKey, Option, IsFormRequest) {
|
|
676
|
-
let Api = this.ApiStore[ApiKey];
|
|
677
|
-
if (Api == null)
|
|
678
|
-
this.$Throw(`Api setting not found of "${ApiKey}"`);
|
|
679
|
-
let ParamQuery = Option?.Query ?? Api.Query;
|
|
680
|
-
let ParamBody = Option?.Body ?? Api.Body;
|
|
681
|
-
let ParamFile = Option?.File ?? Api.File;
|
|
682
|
-
if (typeof (ParamQuery) == 'function')
|
|
683
|
-
ParamQuery = ParamQuery();
|
|
684
|
-
if (typeof (ParamBody) == 'function')
|
|
685
|
-
ParamBody = ParamBody();
|
|
686
|
-
if (typeof (ParamFile) == 'function')
|
|
687
|
-
ParamFile = ParamFile();
|
|
688
|
-
let IsUpdateStore = Option?.IsUpdateStore ?? Api.IsUpdateStore ?? true;
|
|
689
|
-
let Url = this.ConvertTo_ApiUrl(Api.Url, ParamQuery);
|
|
690
|
-
let FetchRequest = this.$GenerateFetchRequest(Api, ParamBody, ParamFile, IsFormRequest);
|
|
691
|
-
this.PubApi(ApiKey, 'IsCalling', true);
|
|
692
|
-
Api.OnCalling?.call(this, FetchRequest);
|
|
693
|
-
Option?.OnCalling?.call(this, FetchRequest);
|
|
694
|
-
fetch(Url, FetchRequest)
|
|
695
|
-
.then(async (ApiResponse) => {
|
|
696
|
-
if (!ApiResponse.ok)
|
|
697
|
-
throw ApiResponse;
|
|
698
|
-
let ConvertResult = await this.$ProcessApiReturn(ApiResponse);
|
|
699
|
-
if (IsUpdateStore) {
|
|
700
|
-
if (Api.Export != false) {
|
|
701
|
-
if (typeof Api.Export === 'function') {
|
|
702
|
-
ConvertResult = Api.Export?.call(this, ConvertResult, ApiResponse);
|
|
703
|
-
}
|
|
704
|
-
else if (this.#ExportSuccessStore != null) {
|
|
705
|
-
ConvertResult = this.#ExportSuccessStore?.call(this, ConvertResult, ApiResponse);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
let StoreKey = Api.ApiKey;
|
|
709
|
-
this.UpdateStore(StoreKey, ConvertResult);
|
|
710
|
-
}
|
|
711
|
-
this.PubApi(ApiKey, 'IsSuccess', true);
|
|
712
|
-
this.PubApi(ApiKey, 'IsError', false);
|
|
713
|
-
Api.OnSuccess?.call(this, ConvertResult, ApiResponse);
|
|
714
|
-
Option?.OnSuccess?.call(this, ConvertResult, ApiResponse);
|
|
715
|
-
this.#OnSuccess?.call(this, ConvertResult, ApiResponse);
|
|
716
|
-
return { ConvertResult, ApiResponse };
|
|
717
|
-
})
|
|
718
|
-
.catch(ex => {
|
|
719
|
-
this.PubApi(ApiKey, 'IsError', true);
|
|
720
|
-
this.PubApi(ApiKey, 'IsSuccess', false);
|
|
721
|
-
this.$Error(ex.message);
|
|
722
|
-
Api.OnError?.call(this, ex);
|
|
723
|
-
Option?.OnError?.call(this, ex);
|
|
724
|
-
this.#OnError?.call(this, ex);
|
|
725
|
-
})
|
|
726
|
-
.then(Result => {
|
|
727
|
-
this.PubApi(ApiKey, 'IsCalling', false);
|
|
728
|
-
this.PubApi(ApiKey, 'IsComplete', true);
|
|
729
|
-
if (Result instanceof Object) {
|
|
730
|
-
Api.OnComplete?.call(this, Result.ConvertResult, Result.ApiResponse);
|
|
731
|
-
Option?.OnComplete?.call(this, Result.ConvertResult, Result.ApiResponse);
|
|
732
|
-
this.#OnComplete?.call(this, Result.ConvertResult, Result.ApiResponse);
|
|
733
|
-
}
|
|
734
|
-
else {
|
|
735
|
-
Api.OnComplete?.call(this);
|
|
736
|
-
Option?.OnComplete?.call(this);
|
|
737
|
-
this.#OnComplete?.call(this, null, null);
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
$GenerateFetchRequest(Api, ParamBody, ParamFile, IsFormRequest) {
|
|
742
|
-
let Header = new Headers();
|
|
743
|
-
Header.set('Authorization', `Bearer ${this.#AccessToken}`);
|
|
744
|
-
if (this.#HeaderFuncs.length > 0) {
|
|
745
|
-
for (let Func of this.#HeaderFuncs) {
|
|
746
|
-
Func(Header);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
let FetchRequest = {
|
|
750
|
-
method: Api.Method,
|
|
751
|
-
headers: Header,
|
|
752
|
-
};
|
|
753
|
-
if (IsFormRequest) {
|
|
754
|
-
let SendForm = this.$ConvertTo_FormData(ParamBody, new FormData());
|
|
755
|
-
SendForm = this.$ConvertTo_FormFile(ParamFile, SendForm);
|
|
756
|
-
FetchRequest.body = SendForm;
|
|
757
|
-
FetchRequest.method = 'POST';
|
|
758
|
-
}
|
|
759
|
-
else {
|
|
760
|
-
Header.set('content-type', 'application/json');
|
|
761
|
-
if (Api.Method != 'GET')
|
|
762
|
-
FetchRequest.body = JSON.stringify(ParamBody ?? {});
|
|
763
|
-
}
|
|
764
|
-
return FetchRequest;
|
|
765
|
-
}
|
|
766
|
-
AddSubApi(ApiKey, Option) {
|
|
767
|
-
if (typeof Option === 'function')
|
|
768
|
-
Option = {
|
|
769
|
-
NotifyEvent: Option,
|
|
770
|
-
};
|
|
771
|
-
let SubApiStore = {
|
|
772
|
-
...Option,
|
|
773
|
-
};
|
|
774
|
-
this.AddStoreFrom(this.ApiStore, ApiKey, {});
|
|
775
|
-
let GetApiStore = this.ApiStore[ApiKey];
|
|
776
|
-
GetApiStore.$sub ??= [];
|
|
777
|
-
GetApiStore.$sub.push(SubApiStore);
|
|
778
|
-
return this;
|
|
779
|
-
}
|
|
780
|
-
PubApi(ApiKey, PropertyName, Value) {
|
|
781
|
-
let GetApiStore = this.ApiStore[ApiKey];
|
|
782
|
-
GetApiStore[PropertyName] = Value;
|
|
783
|
-
if (GetApiStore.$sub == null || !Array.isArray(GetApiStore.$sub))
|
|
784
|
-
return this;
|
|
785
|
-
for (let Sub of GetApiStore.$sub) {
|
|
786
|
-
let SubStore = Sub;
|
|
787
|
-
if (SubStore.PropertyName != null && SubStore.PropertyName != PropertyName)
|
|
788
|
-
continue;
|
|
789
|
-
SubStore.NotifyEvent({
|
|
790
|
-
PropertyName: PropertyName,
|
|
791
|
-
ApiStore: GetApiStore,
|
|
792
|
-
Value: GetApiStore[PropertyName],
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
return this;
|
|
796
|
-
}
|
|
797
|
-
UseFormJsonBody(JsonBodyKey = 'Body') {
|
|
798
|
-
this.WithConvertTo_FormParam((FormDataBody, Form) => {
|
|
799
|
-
let ConvertParam = {};
|
|
800
|
-
ConvertParam[JsonBodyKey] = JSON.stringify(FormDataBody);
|
|
801
|
-
return ConvertParam;
|
|
802
|
-
});
|
|
803
|
-
return this;
|
|
804
|
-
}
|
|
805
|
-
EventAdd_AddApi(EventFunc) {
|
|
806
|
-
this.$EventAdd(this.#EventName.AddApi, EventFunc);
|
|
807
|
-
return this;
|
|
808
|
-
}
|
|
809
|
-
EventAdd_UpdateStore(EventFunc) {
|
|
810
|
-
this.$EventAdd(this.#EventName.UpdateStore, EventFunc);
|
|
811
|
-
return this;
|
|
812
|
-
}
|
|
813
|
-
EventAdd_AddStore(EventFunc) {
|
|
814
|
-
this.$EventAdd(this.#EventName.AddStore, EventFunc);
|
|
815
|
-
return this;
|
|
816
|
-
}
|
|
817
|
-
EventAdd_SetStore(EventFunc) {
|
|
818
|
-
this.$EventAdd(this.#EventName.SetStore, EventFunc);
|
|
819
|
-
return this;
|
|
820
|
-
}
|
|
821
|
-
$EventAdd(EventName, OnFunc) {
|
|
822
|
-
if (EventName in this.#OnEventFunc == false)
|
|
823
|
-
this.#OnEventFunc[EventName] = [];
|
|
824
|
-
this.#OnEventFunc[EventName].push(OnFunc);
|
|
825
|
-
}
|
|
826
|
-
$EventTrigger(EventName, EventArg) {
|
|
827
|
-
let EventFuncs = this.#OnEventFunc[EventName];
|
|
828
|
-
if (EventFuncs == null)
|
|
829
|
-
return;
|
|
830
|
-
for (let Item of EventFuncs)
|
|
831
|
-
Item(EventArg);
|
|
832
|
-
}
|
|
833
|
-
GetStore(StorePath, Option) {
|
|
834
|
-
return this.GetStoreFrom(this.Store, StorePath, Option);
|
|
835
|
-
}
|
|
836
|
-
AddStore(StorePath, StoreData = null) {
|
|
837
|
-
return this.AddStoreFrom(this.Store, StorePath, StoreData);
|
|
838
|
-
}
|
|
839
|
-
SetStore(StorePath, StoreData) {
|
|
840
|
-
return this.SetStoreFrom(this.Store, StorePath, StoreData);
|
|
841
|
-
}
|
|
842
|
-
UpdateStore(StorePath, StoreData) {
|
|
843
|
-
return this.UpdateStoreFrom(this.Store, StorePath, StoreData);
|
|
844
|
-
}
|
|
845
|
-
ClearStore(StorePath, Option) {
|
|
846
|
-
return this.ClearStoreFrom(this.Store, StorePath, Option);
|
|
847
|
-
}
|
|
848
|
-
GetStoreFrom(SourceStore, StorePath, Option) {
|
|
849
|
-
if (typeof Option == 'boolean')
|
|
850
|
-
Option = { Clone: Option };
|
|
851
|
-
Option ??= {};
|
|
852
|
-
Option.Clone ??= false;
|
|
853
|
-
Option.CreateIfNull ??= false;
|
|
854
|
-
if (Option.DefaultValue == null)
|
|
855
|
-
Option.DefaultValue = {};
|
|
856
|
-
StorePath = this.ToJoin(StorePath);
|
|
857
|
-
let FindStore = this.$RCS_GetStore(StorePath, SourceStore, {
|
|
858
|
-
CreateIfNull: Option.CreateIfNull,
|
|
859
|
-
DefaultValue: Option.DefaultValue,
|
|
860
|
-
});
|
|
861
|
-
if (Option.Clone) {
|
|
862
|
-
let CloneResult = {};
|
|
863
|
-
let AllKeys = Object.getOwnPropertyNames(FindStore);
|
|
864
|
-
for (let Key of AllKeys) {
|
|
865
|
-
if (!Key.match(/^\$/g))
|
|
866
|
-
CloneResult[Key] = FindStore[Key];
|
|
867
|
-
}
|
|
868
|
-
return CloneResult;
|
|
869
|
-
}
|
|
870
|
-
return FindStore;
|
|
871
|
-
}
|
|
872
|
-
AddStoreFrom(SourceStore, StorePath, StoreData = null) {
|
|
873
|
-
StorePath = this.ToJoin(StorePath);
|
|
874
|
-
if (this.GetStoreFrom(SourceStore, StorePath) != null)
|
|
875
|
-
return this;
|
|
876
|
-
this.$RCS_SetStore(StorePath, StoreData, SourceStore, {
|
|
877
|
-
IsDeepSet: true,
|
|
878
|
-
});
|
|
879
|
-
this.$EventTrigger(this.#EventName.AddStore, {
|
|
880
|
-
Path: StorePath,
|
|
881
|
-
Data: StoreData,
|
|
882
|
-
});
|
|
883
|
-
return this;
|
|
884
|
-
}
|
|
885
|
-
SetStoreFrom(SourceStore, StorePath, StoreData) {
|
|
886
|
-
if (StorePath != null)
|
|
887
|
-
StorePath = this.ToJoin(StorePath);
|
|
888
|
-
this.$RCS_SetStore(StorePath, StoreData, SourceStore, {
|
|
889
|
-
IsDeepSet: false,
|
|
890
|
-
});
|
|
891
|
-
this.$EventTrigger(this.#EventName.SetStore, {
|
|
892
|
-
Path: StorePath,
|
|
893
|
-
Data: StoreData,
|
|
894
|
-
});
|
|
895
|
-
return this;
|
|
896
|
-
}
|
|
897
|
-
UpdateStoreFrom(SourceStore, StorePath, StoreData) {
|
|
898
|
-
if (StorePath != null)
|
|
899
|
-
StorePath = this.ToJoin(StorePath);
|
|
900
|
-
this.$RCS_SetStore(StorePath, StoreData, SourceStore, {
|
|
901
|
-
IsDeepSet: true,
|
|
902
|
-
});
|
|
903
|
-
this.$EventTrigger(this.#EventName.UpdateStore, {
|
|
904
|
-
Path: StorePath,
|
|
905
|
-
Data: StoreData,
|
|
906
|
-
});
|
|
907
|
-
return this;
|
|
908
|
-
}
|
|
909
|
-
ClearStoreFrom(SourceStore, StorePath, Option) {
|
|
910
|
-
Option ??= {};
|
|
911
|
-
if (typeof Option === 'boolean')
|
|
912
|
-
Option = { DeepClear: Option };
|
|
913
|
-
let TargetStore = StorePath == null ? SourceStore : this.GetStoreFrom(SourceStore, StorePath);
|
|
914
|
-
if (TargetStore == null)
|
|
915
|
-
return this;
|
|
916
|
-
this.$RCS_ClearStore(TargetStore, Option);
|
|
917
|
-
return this;
|
|
918
|
-
}
|
|
919
|
-
$RCS_GetStore(StorePath, FindStore, Option) {
|
|
920
|
-
if (FindStore == null)
|
|
921
|
-
return null;
|
|
922
|
-
StorePath = StorePath.replaceAll(/\[|\]/g, '.').replace(/\.+/g, '.').replace(/\.$/, '');
|
|
923
|
-
let StorePaths = StorePath.split('.');
|
|
924
|
-
let FirstKey = StorePaths.shift();
|
|
925
|
-
if (FindStore[FirstKey] == null && Option.CreateIfNull) {
|
|
926
|
-
if (Array.isArray(Option.DefaultValue))
|
|
927
|
-
FindStore[FirstKey] = [...Option.DefaultValue];
|
|
928
|
-
else if (typeof Option.DefaultValue == 'object')
|
|
929
|
-
FindStore[FirstKey] = { ...Option.DefaultValue };
|
|
930
|
-
else
|
|
931
|
-
FindStore[FirstKey] = Option.DefaultValue;
|
|
932
|
-
}
|
|
933
|
-
let NextStore = FindStore[FirstKey];
|
|
934
|
-
if (StorePaths.length == 0)
|
|
935
|
-
return NextStore;
|
|
936
|
-
let NextKey = StorePaths.join('.');
|
|
937
|
-
return this.$RCS_GetStore(NextKey, NextStore, Option);
|
|
938
|
-
}
|
|
939
|
-
$RCS_SetStore(StorePath, StoreData, FindStore, Option = {
|
|
940
|
-
IsDeepSet: true,
|
|
941
|
-
}) {
|
|
942
|
-
if (StorePath == null) {
|
|
943
|
-
this.$DeepSetObject(StoreData, FindStore);
|
|
944
|
-
return StoreData;
|
|
945
|
-
}
|
|
946
|
-
StorePath = StorePath.replaceAll(/\[|\]/g, '.').replace(/\.+/g, '.').replace(/\.$/, '');
|
|
947
|
-
if (StorePath.includes('.')) {
|
|
948
|
-
let StorePaths = StorePath.split('.');
|
|
949
|
-
let FirstKey = StorePaths.shift();
|
|
950
|
-
if (FindStore[FirstKey] == null)
|
|
951
|
-
FindStore[FirstKey] = {};
|
|
952
|
-
let NextStore = FindStore[FirstKey];
|
|
953
|
-
let NextKey = StorePaths.join('.');
|
|
954
|
-
return this.$RCS_SetStore(NextKey, StoreData, NextStore, Option);
|
|
955
|
-
}
|
|
956
|
-
let IsAwaysSet = StoreData == null ||
|
|
957
|
-
!Option.IsDeepSet ||
|
|
958
|
-
FindStore[StorePath] == null ||
|
|
959
|
-
typeof StoreData != 'object';
|
|
960
|
-
if (IsAwaysSet) {
|
|
961
|
-
FindStore[StorePath] = StoreData;
|
|
962
|
-
return StoreData;
|
|
963
|
-
}
|
|
964
|
-
return this.$RCS_SetStore(null, StoreData, FindStore[StorePath]);
|
|
965
|
-
}
|
|
966
|
-
$RCS_ClearStore(TargetStore, Option) {
|
|
967
|
-
if (typeof TargetStore != 'object')
|
|
968
|
-
return;
|
|
969
|
-
if (Array.isArray(TargetStore)) {
|
|
970
|
-
TargetStore.length = 0;
|
|
971
|
-
return;
|
|
972
|
-
}
|
|
973
|
-
let AllProperty = Object.getOwnPropertyNames(TargetStore);
|
|
974
|
-
for (let Key of AllProperty) {
|
|
975
|
-
if (Key.match(/^\$/g))
|
|
976
|
-
continue;
|
|
977
|
-
if (typeof TargetStore[Key] === 'function')
|
|
978
|
-
continue;
|
|
979
|
-
else if (Option.DeepClear && typeof TargetStore[Key] === 'object')
|
|
980
|
-
this.$RCS_ClearStore(TargetStore[Key], Option);
|
|
981
|
-
else
|
|
982
|
-
TargetStore[Key] = null;
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
$DeepSetObject(SetData, FindStore) {
|
|
986
|
-
if (SetData == null) {
|
|
987
|
-
this.ClearStoreFrom(FindStore);
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
if (Array.isArray(SetData)) {
|
|
991
|
-
if (!Array.isArray(FindStore))
|
|
992
|
-
return;
|
|
993
|
-
FindStore.length = 0;
|
|
994
|
-
SetData.forEach(item => FindStore.push(item));
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
this.ForEachObject(SetData, (Key, Value) => {
|
|
998
|
-
let IsGoNext = false;
|
|
999
|
-
if (Array.isArray(Value)) {
|
|
1000
|
-
if (FindStore[Key] == null || !Array.isArray(FindStore[Key]))
|
|
1001
|
-
FindStore[Key] = [];
|
|
1002
|
-
IsGoNext = true;
|
|
1003
|
-
}
|
|
1004
|
-
else if (Value != null && typeof Value == 'object') {
|
|
1005
|
-
if (FindStore[Key] == null || typeof FindStore[Key] != 'object')
|
|
1006
|
-
FindStore[Key] = {};
|
|
1007
|
-
IsGoNext = true;
|
|
1008
|
-
}
|
|
1009
|
-
if (IsGoNext)
|
|
1010
|
-
this.$DeepSetObject(Value, FindStore[Key]);
|
|
1011
|
-
else
|
|
1012
|
-
FindStore[Key] = Value;
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
AddFileStore(FileStoreKey, Option) {
|
|
1016
|
-
Option ??= {};
|
|
1017
|
-
if (this.FileStore[FileStoreKey] == null) {
|
|
1018
|
-
if (Option.Multi == true)
|
|
1019
|
-
this.FileStore[FileStoreKey] = [];
|
|
1020
|
-
else {
|
|
1021
|
-
this.FileStore[FileStoreKey] = new FileItem();
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
return this;
|
|
1025
|
-
}
|
|
1026
|
-
Files(FileStoreKey, WhereFunc = null) {
|
|
1027
|
-
let GetFiles = this.FileStore[FileStoreKey];
|
|
1028
|
-
if (GetFiles == null)
|
|
1029
|
-
return [];
|
|
1030
|
-
if (!Array.isArray(GetFiles))
|
|
1031
|
-
GetFiles = [GetFiles];
|
|
1032
|
-
if (WhereFunc != null)
|
|
1033
|
-
GetFiles = GetFiles.filter(Item => WhereFunc(Item));
|
|
1034
|
-
let Result = GetFiles.map(Item => Item.File);
|
|
1035
|
-
return Result;
|
|
1036
|
-
}
|
|
1037
|
-
File(FileStoreKey, WhereFunc = null) {
|
|
1038
|
-
let GetFiles = this.Files(FileStoreKey, WhereFunc);
|
|
1039
|
-
if (GetFiles == null || GetFiles.length == 0)
|
|
1040
|
-
return null;
|
|
1041
|
-
return GetFiles[0];
|
|
1042
|
-
}
|
|
1043
|
-
AddFile(FileStoreKey, AddFile, ConvertType = 'none') {
|
|
1044
|
-
if (AddFile == null)
|
|
1045
|
-
return;
|
|
1046
|
-
this.AddFileStore(FileStoreKey);
|
|
1047
|
-
let GetStore = this.FileStore[FileStoreKey];
|
|
1048
|
-
if (Array.isArray(AddFile)) {
|
|
1049
|
-
if (Array.isArray(GetStore))
|
|
1050
|
-
AddFile.forEach(Item => this.AddFile(FileStoreKey, Item));
|
|
1051
|
-
else
|
|
1052
|
-
this.AddFile(FileStoreKey, AddFile[0]);
|
|
1053
|
-
}
|
|
1054
|
-
else {
|
|
1055
|
-
if (AddFile instanceof FileItem == false)
|
|
1056
|
-
AddFile = new FileItem(AddFile, ConvertType);
|
|
1057
|
-
if (Array.isArray(GetStore)) {
|
|
1058
|
-
GetStore.push(AddFile);
|
|
1059
|
-
}
|
|
1060
|
-
else {
|
|
1061
|
-
GetStore.From(AddFile);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
return this;
|
|
1065
|
-
}
|
|
1066
|
-
RemoveFile(FileStoreKey, DeleteFileId) {
|
|
1067
|
-
let GetStore = this.FileStore[FileStoreKey];
|
|
1068
|
-
if (GetStore == null)
|
|
1069
|
-
return this;
|
|
1070
|
-
if (Array.isArray(DeleteFileId))
|
|
1071
|
-
DeleteFileId.forEach(Item => this.RemoveFile(FileStoreKey, Item));
|
|
1072
|
-
else {
|
|
1073
|
-
if (Array.isArray(GetStore)) {
|
|
1074
|
-
let DeleteIndex = GetStore.findIndex(Item => Item.FileId == DeleteFileId);
|
|
1075
|
-
if (DeleteIndex >= 0)
|
|
1076
|
-
GetStore.splice(DeleteIndex, 1);
|
|
1077
|
-
}
|
|
1078
|
-
else {
|
|
1079
|
-
GetStore.Clear();
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
return this;
|
|
1083
|
-
}
|
|
1084
|
-
ClearFile(FileStoreKey) {
|
|
1085
|
-
let GetStore = this.FileStore[FileStoreKey];
|
|
1086
|
-
if (GetStore == null)
|
|
1087
|
-
return this;
|
|
1088
|
-
if (Array.isArray(GetStore)) {
|
|
1089
|
-
GetStore.splice(0, GetStore.length);
|
|
1090
|
-
}
|
|
1091
|
-
else {
|
|
1092
|
-
GetStore.Clear();
|
|
1093
|
-
}
|
|
1094
|
-
return this;
|
|
1095
|
-
}
|
|
1096
|
-
$ProcessApiReturn(ApiResponse) {
|
|
1097
|
-
let GetContentType = ApiResponse.headers.get("content-type");
|
|
1098
|
-
if (GetContentType.includes('application/json')) {
|
|
1099
|
-
return ApiResponse.json();
|
|
1100
|
-
}
|
|
1101
|
-
if (GetContentType.includes('text')) {
|
|
1102
|
-
return ApiResponse.text();
|
|
1103
|
-
}
|
|
1104
|
-
return new Promise(reslove => { reslove(ApiResponse); });
|
|
1105
|
-
}
|
|
1106
|
-
NavigateToRoot() {
|
|
1107
|
-
let RootUrl = this.#RootRoute ?? '/';
|
|
1108
|
-
super.$BaseNavigateTo(RootUrl);
|
|
1109
|
-
return this;
|
|
1110
|
-
}
|
|
1111
|
-
$ConvertTo_FormData(ConvertFormData, Form) {
|
|
1112
|
-
Form ??= new FormData();
|
|
1113
|
-
if (ConvertFormData == null)
|
|
1114
|
-
return Form;
|
|
1115
|
-
this.#Func_ConvertTo_FormData.forEach(Func => {
|
|
1116
|
-
ConvertFormData = Func(ConvertFormData, Form);
|
|
1117
|
-
});
|
|
1118
|
-
if (ConvertFormData instanceof FormData)
|
|
1119
|
-
return ConvertFormData;
|
|
1120
|
-
this.ForEachObject(ConvertFormData, (Key, Value) => {
|
|
1121
|
-
Form.append(Key, Value);
|
|
1122
|
-
});
|
|
1123
|
-
return Form;
|
|
1124
|
-
}
|
|
1125
|
-
$ConvertTo_FormFile(FileParam, Form) {
|
|
1126
|
-
Form ??= new FormData();
|
|
1127
|
-
if (FileParam == null)
|
|
1128
|
-
return Form;
|
|
1129
|
-
let DefaultKey = 'Files';
|
|
1130
|
-
if (Array.isArray(FileParam)) {
|
|
1131
|
-
this.$AppendFileToFormData(DefaultKey, Form, FileParam);
|
|
1132
|
-
return Form;
|
|
1133
|
-
}
|
|
1134
|
-
if (FileParam instanceof File || FileParam instanceof FileItem) {
|
|
1135
|
-
this.$AppendFileToFormData(DefaultKey, Form, FileParam);
|
|
1136
|
-
return Form;
|
|
1137
|
-
}
|
|
1138
|
-
let Keys = Object.keys(FileParam);
|
|
1139
|
-
for (let i = 0; i < Keys.length; i++) {
|
|
1140
|
-
let FileKey = Keys[i];
|
|
1141
|
-
let FileValue = FileParam[FileKey];
|
|
1142
|
-
this.$AppendFileToFormData(FileKey, Form, FileValue);
|
|
1143
|
-
}
|
|
1144
|
-
return Form;
|
|
1145
|
-
}
|
|
1146
|
-
$AppendFileToFormData(FileKey, Form, FileData) {
|
|
1147
|
-
if (Array.isArray(FileData)) {
|
|
1148
|
-
for (let i = 0; i < FileData.length; i++)
|
|
1149
|
-
this.$AppendFileToFormData(FileKey, Form, FileData[i]);
|
|
1150
|
-
}
|
|
1151
|
-
else if (FileData instanceof File)
|
|
1152
|
-
Form.append(FileKey, FileData);
|
|
1153
|
-
else
|
|
1154
|
-
Form.append(FileKey, FileData.File);
|
|
1155
|
-
return Form;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
exports.ApiStore = ApiStore;
|
|
1159
|
-
const vue_1 = require("vue");
|
|
1160
|
-
const vue_2 = require("vue");
|
|
1161
|
-
class VueStore extends ApiStore {
|
|
1162
|
-
$VueProxy = null;
|
|
1163
|
-
$VueOption = {
|
|
1164
|
-
methods: {},
|
|
1165
|
-
components: {},
|
|
1166
|
-
computed: {},
|
|
1167
|
-
};
|
|
1168
|
-
$VueApp = null;
|
|
1169
|
-
$VueUse = [];
|
|
1170
|
-
$CoreStore = 'app';
|
|
1171
|
-
$MountedFuncs = [];
|
|
1172
|
-
$Directive = [];
|
|
1173
|
-
constructor() {
|
|
1174
|
-
super();
|
|
1175
|
-
this.#Setup();
|
|
1176
|
-
}
|
|
1177
|
-
#Setup() {
|
|
1178
|
-
this
|
|
1179
|
-
.EventAdd_AddApi(Arg => {
|
|
1180
|
-
this.AddStore(Arg.ApiKey);
|
|
1181
|
-
})
|
|
1182
|
-
.EventAdd_UpdateStore(() => {
|
|
1183
|
-
this.ForceUpdate();
|
|
1184
|
-
})
|
|
1185
|
-
.EventAdd_AddStore(() => {
|
|
1186
|
-
this.ForceUpdate();
|
|
1187
|
-
})
|
|
1188
|
-
.EventAdd_SetStore(() => {
|
|
1189
|
-
this.ForceUpdate();
|
|
1190
|
-
})
|
|
1191
|
-
.AddStore(this.$CoreStore, {})
|
|
1192
|
-
.WithMounted(() => {
|
|
1193
|
-
this.UpdateStore([this.$CoreStore, 'IsMounted'], true);
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
get Store() {
|
|
1197
|
-
if (this.$VueProxy != null)
|
|
1198
|
-
return this.$VueProxy;
|
|
1199
|
-
return super.Store;
|
|
1200
|
-
}
|
|
1201
|
-
set Store(Store) {
|
|
1202
|
-
super.Store = Store;
|
|
1203
|
-
}
|
|
1204
|
-
WithVueOption(VueOption = {}) {
|
|
1205
|
-
this.$VueOption = this.DeepObjectExtend(this.$VueOption, VueOption);
|
|
1206
|
-
return this;
|
|
1207
|
-
}
|
|
1208
|
-
WithMounted(MountedFunc = () => { }) {
|
|
1209
|
-
this.$MountedFuncs.push(MountedFunc);
|
|
1210
|
-
return this;
|
|
1211
|
-
}
|
|
1212
|
-
WithComponent(Component = {}) {
|
|
1213
|
-
this.$VueOption.components = this.DeepObjectExtend(this.$VueOption.components, Component);
|
|
1214
|
-
return this;
|
|
1215
|
-
}
|
|
1216
|
-
WithVueUse(...UsePlugin) {
|
|
1217
|
-
for (let Item of UsePlugin) {
|
|
1218
|
-
this.$VueUse.push(Item);
|
|
1219
|
-
}
|
|
1220
|
-
return this;
|
|
1221
|
-
}
|
|
1222
|
-
WithDirective(Name, Directive) {
|
|
1223
|
-
this.$Directive.push({
|
|
1224
|
-
Name,
|
|
1225
|
-
Directive
|
|
1226
|
-
});
|
|
1227
|
-
return this;
|
|
1228
|
-
}
|
|
1229
|
-
ForceUpdate() {
|
|
1230
|
-
this.$VueProxy?.$forceUpdate();
|
|
1231
|
-
return this;
|
|
1232
|
-
}
|
|
1233
|
-
Refs(RefName) {
|
|
1234
|
-
if (!this.$VueProxy)
|
|
1235
|
-
return null;
|
|
1236
|
-
return this.$VueProxy.$refs[Model.ToJoin(RefName)];
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
exports.VueStore = VueStore;
|
|
1240
|
-
class VueCommand extends VueStore {
|
|
1241
|
-
$IsInited = false;
|
|
1242
|
-
$CommandMap;
|
|
1243
|
-
$QueryDomName = null;
|
|
1244
|
-
constructor() {
|
|
1245
|
-
super();
|
|
1246
|
-
this.$SetupCommandMap();
|
|
1247
|
-
}
|
|
1248
|
-
WithQueryDomName(QueryDomName) {
|
|
1249
|
-
this.$QueryDomName = QueryDomName;
|
|
1250
|
-
exports.Queryer.WithDomName(this.$QueryDomName);
|
|
1251
|
-
return this;
|
|
1252
|
-
}
|
|
1253
|
-
AddV_Text(DomName, Option) {
|
|
1254
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1255
|
-
if (typeof SetOption.Target != 'function') {
|
|
1256
|
-
let FullPaths = Model.ToJoin(SetOption.Target);
|
|
1257
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*(\.[A-Za-z_$][A-Za-z0-9_$]*)*$/.test(FullPaths)) {
|
|
1258
|
-
Model.AddStore(SetOption.Target);
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
SetOption.FuncAction = true;
|
|
1262
|
-
this.$AddCommand(DomName, 'v-text', SetOption);
|
|
1263
|
-
return this;
|
|
1264
|
-
}
|
|
1265
|
-
AddV_Model(DomName, StorePath, Option) {
|
|
1266
|
-
let SetOption = this.$ConvertCommandOption(StorePath);
|
|
1267
|
-
Option ??= {};
|
|
1268
|
-
Option.DefaultValue ??= null;
|
|
1269
|
-
SetOption.CommandKey = Option.ModelValue;
|
|
1270
|
-
this.AddStore(StorePath, Option.DefaultValue);
|
|
1271
|
-
this.$AddCommand(DomName, 'v-model', SetOption);
|
|
1272
|
-
return this;
|
|
1273
|
-
}
|
|
1274
|
-
AddV_Slot(DomName, SlotKey, Option) {
|
|
1275
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1276
|
-
if (SlotKey != null)
|
|
1277
|
-
SetOption.CommandKey = SlotKey;
|
|
1278
|
-
this.$AddCommand(DomName, `v-slot`, SetOption);
|
|
1279
|
-
return this;
|
|
1280
|
-
}
|
|
1281
|
-
AddV_For(DomName, Option, ForKey) {
|
|
1282
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1283
|
-
if (ForKey) {
|
|
1284
|
-
ForKey = this.ToJoin(ForKey);
|
|
1285
|
-
if (!/^\(/.test(ForKey))
|
|
1286
|
-
ForKey = `(${ForKey}`;
|
|
1287
|
-
if (!/\)$/.test(ForKey))
|
|
1288
|
-
ForKey += ')';
|
|
1289
|
-
SetOption.TargetHead = `${ForKey} in `;
|
|
1290
|
-
}
|
|
1291
|
-
let Target = Model.ToJoin(SetOption.Target);
|
|
1292
|
-
if (!/\b(in|of)\b/.test(Target))
|
|
1293
|
-
SetOption.TargetHead ??= '(item, index) in ';
|
|
1294
|
-
SetOption.FuncAction = true;
|
|
1295
|
-
this.$AddCommand(DomName, 'v-for', SetOption);
|
|
1296
|
-
return this;
|
|
1297
|
-
}
|
|
1298
|
-
AddV_If(DomName, Option) {
|
|
1299
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1300
|
-
SetOption.FuncAction = true;
|
|
1301
|
-
this.$AddCommand(DomName, 'v-if', SetOption);
|
|
1302
|
-
return this;
|
|
1303
|
-
}
|
|
1304
|
-
AddV_ElseIf(DomName, Option) {
|
|
1305
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1306
|
-
SetOption.FuncAction = true;
|
|
1307
|
-
this.$AddCommand(DomName, 'v-else-if', SetOption);
|
|
1308
|
-
return this;
|
|
1309
|
-
}
|
|
1310
|
-
AddV_Else(DomName) {
|
|
1311
|
-
let SetOption = this.$ConvertCommandOption(DomName);
|
|
1312
|
-
SetOption.Target = '';
|
|
1313
|
-
this.$AddCommand(DomName, 'v-else', SetOption);
|
|
1314
|
-
return this;
|
|
1315
|
-
}
|
|
1316
|
-
AddV_Show(DomName, Option) {
|
|
1317
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1318
|
-
SetOption.FuncAction = true;
|
|
1319
|
-
this.$AddCommand(DomName, 'v-show', SetOption);
|
|
1320
|
-
return this;
|
|
1321
|
-
}
|
|
1322
|
-
AddV_Bind(DomName, BindKey, Option, Args) {
|
|
1323
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option, Args);
|
|
1324
|
-
SetOption.CommandKey = BindKey;
|
|
1325
|
-
this.$AddCommand(DomName, 'v-bind', SetOption);
|
|
1326
|
-
return this;
|
|
1327
|
-
}
|
|
1328
|
-
AddV_On(DomName, EventName, Option, Args) {
|
|
1329
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option, Args);
|
|
1330
|
-
SetOption.CommandKey = EventName;
|
|
1331
|
-
this.$AddCommand(DomName, `v-on`, SetOption);
|
|
1332
|
-
return this;
|
|
1333
|
-
}
|
|
1334
|
-
Watch(WatchPath, Callback, Option = {}) {
|
|
1335
|
-
let Handle;
|
|
1336
|
-
if (typeof WatchPath == 'function')
|
|
1337
|
-
Handle = (0, vue_2.watch)(WatchPath, Callback, Option);
|
|
1338
|
-
else {
|
|
1339
|
-
Model.AddStore(WatchPath);
|
|
1340
|
-
Handle = (0, vue_2.watch)(() => Model.GetStore(WatchPath), Callback, Option);
|
|
1341
|
-
}
|
|
1342
|
-
return Handle;
|
|
1343
|
-
}
|
|
1344
|
-
AddV_Watch(WatchPath, Callback, Option = {}) {
|
|
1345
|
-
Model.WithMounted(() => {
|
|
1346
|
-
this.Watch(WatchPath, Callback, Option);
|
|
1347
|
-
});
|
|
1348
|
-
return this;
|
|
1349
|
-
}
|
|
1350
|
-
AddV_Function(FuncName, Func) {
|
|
1351
|
-
if (this.$IsInited && !Array.isArray(FuncName))
|
|
1352
|
-
this.$VueOption.methods[FuncName] = Func;
|
|
1353
|
-
else
|
|
1354
|
-
Model.UpdateStore(FuncName, Func);
|
|
1355
|
-
return this;
|
|
1356
|
-
}
|
|
1357
|
-
AddV_OnChange(DomName, ChangeFunc, Args) {
|
|
1358
|
-
this.AddV_On(DomName, 'change', ChangeFunc, Args);
|
|
1359
|
-
return this;
|
|
1360
|
-
}
|
|
1361
|
-
AddV_Click(DomName, Option, Args) {
|
|
1362
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option, Args);
|
|
1363
|
-
this.AddV_On(DomName, 'click', SetOption);
|
|
1364
|
-
return this;
|
|
1365
|
-
}
|
|
1366
|
-
AddV_FilePicker(DomName, Option) {
|
|
1367
|
-
let FileStorePath = null;
|
|
1368
|
-
let Accept = null;
|
|
1369
|
-
let ConvertType = 'none';
|
|
1370
|
-
let Multi = false;
|
|
1371
|
-
let OnSuccess;
|
|
1372
|
-
let OnError;
|
|
1373
|
-
if (typeof (Option) == 'string')
|
|
1374
|
-
FileStorePath = Option;
|
|
1375
|
-
else {
|
|
1376
|
-
FileStorePath = Option.Store;
|
|
1377
|
-
ConvertType = Option.ConvertType;
|
|
1378
|
-
Multi = Option.Multiple;
|
|
1379
|
-
OnSuccess = Option.OnSuccess;
|
|
1380
|
-
if (Array.isArray(Option.Accept))
|
|
1381
|
-
Accept = Option.Accept.join(' ');
|
|
1382
|
-
else
|
|
1383
|
-
Accept = Option.Accept;
|
|
1384
|
-
}
|
|
1385
|
-
this.AddFileStore(FileStorePath, {
|
|
1386
|
-
Multi: Multi,
|
|
1387
|
-
});
|
|
1388
|
-
this.AddV_Click(DomName, () => {
|
|
1389
|
-
let TempInput = document.createElement('input');
|
|
1390
|
-
TempInput.type = 'file';
|
|
1391
|
-
if (Accept != null)
|
|
1392
|
-
TempInput.accept = Accept;
|
|
1393
|
-
if (Multi != null)
|
|
1394
|
-
TempInput.multiple = Multi;
|
|
1395
|
-
TempInput.onchange = async (Event) => {
|
|
1396
|
-
if (TempInput.files == null || TempInput.files.length == 0)
|
|
1397
|
-
return;
|
|
1398
|
-
const Files = TempInput.files;
|
|
1399
|
-
const FileItems = [];
|
|
1400
|
-
for (let i = 0; i < Files.length; i++) {
|
|
1401
|
-
let PickFile = Files[i];
|
|
1402
|
-
this.AddFile(FileStorePath, PickFile, ConvertType);
|
|
1403
|
-
let fileData = Model.FileStore[FileStorePath];
|
|
1404
|
-
if (!Array.isArray(fileData)) {
|
|
1405
|
-
fileData = [fileData];
|
|
1406
|
-
}
|
|
1407
|
-
FileItems.push(...fileData);
|
|
1408
|
-
}
|
|
1409
|
-
if (OnSuccess) {
|
|
1410
|
-
let isChecked = true;
|
|
1411
|
-
for (const item of FileItems) {
|
|
1412
|
-
if (item instanceof FileItem) {
|
|
1413
|
-
if (!await item.CheckLoadAsync()) {
|
|
1414
|
-
if (OnError)
|
|
1415
|
-
OnError(item);
|
|
1416
|
-
isChecked = false;
|
|
1417
|
-
break;
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
if (isChecked)
|
|
1422
|
-
OnSuccess(FileItems);
|
|
1423
|
-
}
|
|
1424
|
-
};
|
|
1425
|
-
TempInput.click();
|
|
1426
|
-
});
|
|
1427
|
-
return this;
|
|
1428
|
-
}
|
|
1429
|
-
AddV_Tree(TreeRoot, TreeSet, Option) {
|
|
1430
|
-
let AllSetInfo = [];
|
|
1431
|
-
let RootNode;
|
|
1432
|
-
let UsingRootNode = TreeRoot instanceof QueryNode;
|
|
1433
|
-
if (UsingRootNode)
|
|
1434
|
-
RootNode = TreeRoot;
|
|
1435
|
-
let RootPaths = UsingRootNode ? [] : this.Paths(TreeRoot);
|
|
1436
|
-
this.$ParseTreeSet(RootPaths, TreeSet, AllSetInfo);
|
|
1437
|
-
for (let Info of AllSetInfo) {
|
|
1438
|
-
let ActionSet = this.$CommandMap[Info.Command];
|
|
1439
|
-
if (ActionSet == null) {
|
|
1440
|
-
Model.$Error(`${Info.Command} command is not allowed, path: ${this.ToJoin(Info.DomPaths)}`);
|
|
1441
|
-
continue;
|
|
1442
|
-
}
|
|
1443
|
-
if (Info.StoreValue == '' || Info.StoreValue == null && ActionSet.AcceptNull != true)
|
|
1444
|
-
continue;
|
|
1445
|
-
if (Info.StoreValue == '.' && ActionSet.AcceptSelf != true)
|
|
1446
|
-
continue;
|
|
1447
|
-
let NeedQuery = Info.Command == 'using';
|
|
1448
|
-
let QueryOption = {
|
|
1449
|
-
Mode: 'Multi',
|
|
1450
|
-
};
|
|
1451
|
-
if (UsingRootNode) {
|
|
1452
|
-
NeedQuery = true;
|
|
1453
|
-
QueryOption.TargetNode = RootNode;
|
|
1454
|
-
}
|
|
1455
|
-
if (Option?.UseDeepQuery) {
|
|
1456
|
-
NeedQuery = true;
|
|
1457
|
-
QueryOption.Mode = 'DeepMulti';
|
|
1458
|
-
}
|
|
1459
|
-
if (NeedQuery) {
|
|
1460
|
-
let QueryNodes = [RootNode];
|
|
1461
|
-
if (Info.DomPaths.length > 0)
|
|
1462
|
-
QueryNodes = exports.Queryer.Query(Info.DomPaths, QueryOption);
|
|
1463
|
-
Info.Nodes = QueryNodes;
|
|
1464
|
-
}
|
|
1465
|
-
let TargetDom = NeedQuery ? Info.Nodes : Info.DomPaths;
|
|
1466
|
-
let TargetValue;
|
|
1467
|
-
if (typeof Info.StoreValue === 'function') {
|
|
1468
|
-
TargetValue = {
|
|
1469
|
-
Target: Info.StoreValue,
|
|
1470
|
-
FuncArgs: Info.Args,
|
|
1471
|
-
};
|
|
1472
|
-
}
|
|
1473
|
-
else {
|
|
1474
|
-
if (typeof Info.StoreValue === 'string' || Array.isArray(Info.StoreValue)) {
|
|
1475
|
-
if (Info.StoreValue == '.')
|
|
1476
|
-
TargetValue = this.Paths(Info.TreePaths, Info.DomName);
|
|
1477
|
-
else if (Info.StoreValue != null && Info.StoreValue != '')
|
|
1478
|
-
TargetValue = Info.StoreValue;
|
|
1479
|
-
}
|
|
1480
|
-
else {
|
|
1481
|
-
TargetValue = {
|
|
1482
|
-
Target: Info.StoreValue?.TargetFunc,
|
|
1483
|
-
FuncArgs: Info.StoreValue?.Args,
|
|
1484
|
-
};
|
|
1485
|
-
if (Info.StoreValue?.Args != null) {
|
|
1486
|
-
let TargetArgs = Info.StoreValue.Args;
|
|
1487
|
-
if (Info.Args == null)
|
|
1488
|
-
Info.Args = Model.ToJoin(TargetArgs, ', ');
|
|
1489
|
-
else
|
|
1490
|
-
Info.Args = Model.ToJoin([Info.Args, TargetArgs], ', ');
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
ActionSet.Execute(Info, {
|
|
1495
|
-
TargetDom,
|
|
1496
|
-
TargetValue,
|
|
1497
|
-
});
|
|
1498
|
-
}
|
|
1499
|
-
return this;
|
|
1500
|
-
}
|
|
1501
|
-
$ParseTreeSet(Paths, TreeSet, Result) {
|
|
1502
|
-
const TreeNodeReges = /^:(?<next>.+)$/;
|
|
1503
|
-
const AllKeys = Object.keys(TreeSet);
|
|
1504
|
-
for (let i = 0; i < AllKeys.length; i++) {
|
|
1505
|
-
const Command = AllKeys[i];
|
|
1506
|
-
const SetPair = TreeSet[Command];
|
|
1507
|
-
const DomPaths = [...Paths];
|
|
1508
|
-
const TreePaths = [...Paths];
|
|
1509
|
-
const DomName = TreePaths.pop();
|
|
1510
|
-
const TreeNodeResult = Command.match(TreeNodeReges);
|
|
1511
|
-
if (TreeNodeResult) {
|
|
1512
|
-
const NextDomName = TreeNodeResult.groups.next;
|
|
1513
|
-
if (typeof SetPair === 'function') {
|
|
1514
|
-
Result.push({
|
|
1515
|
-
Command: 'using',
|
|
1516
|
-
StoreValue: SetPair,
|
|
1517
|
-
TreePaths: [...DomPaths],
|
|
1518
|
-
DomPaths: [...DomPaths, NextDomName],
|
|
1519
|
-
DomName: NextDomName,
|
|
1520
|
-
});
|
|
1521
|
-
}
|
|
1522
|
-
else {
|
|
1523
|
-
this.$ParseTreeSet([...Paths, NextDomName], SetPair, Result);
|
|
1524
|
-
}
|
|
1525
|
-
continue;
|
|
1526
|
-
}
|
|
1527
|
-
const GetCommandPart = (FindCommand, StartChar, EndChar) => {
|
|
1528
|
-
if (!FindCommand.includes(StartChar) || !FindCommand.includes(EndChar))
|
|
1529
|
-
return null;
|
|
1530
|
-
const StartIndex = FindCommand.indexOf(StartChar);
|
|
1531
|
-
const EndIndex = FindCommand.lastIndexOf(EndChar);
|
|
1532
|
-
const Result = FindCommand.slice(StartIndex + 1, EndIndex).trim();
|
|
1533
|
-
return Result?.trim();
|
|
1534
|
-
};
|
|
1535
|
-
const GetCommandWithKey = (FindCommand) => {
|
|
1536
|
-
let ArgsStart = null;
|
|
1537
|
-
let ForKeyStart = null;
|
|
1538
|
-
if (FindCommand.includes('('))
|
|
1539
|
-
ArgsStart = FindCommand.indexOf('(');
|
|
1540
|
-
if (FindCommand.includes('<'))
|
|
1541
|
-
ForKeyStart = FindCommand.indexOf('<');
|
|
1542
|
-
let CommandWithKey = null;
|
|
1543
|
-
if (ArgsStart == null && ForKeyStart == null) {
|
|
1544
|
-
CommandWithKey = FindCommand;
|
|
1545
|
-
}
|
|
1546
|
-
else if (ArgsStart == null || ForKeyStart == null) {
|
|
1547
|
-
let MinIndex = ArgsStart ?? ForKeyStart;
|
|
1548
|
-
CommandWithKey = FindCommand.slice(0, MinIndex);
|
|
1549
|
-
}
|
|
1550
|
-
else {
|
|
1551
|
-
let MinIndex = Math.min(ArgsStart, ForKeyStart);
|
|
1552
|
-
CommandWithKey = FindCommand.slice(0, MinIndex);
|
|
1553
|
-
}
|
|
1554
|
-
let Command = CommandWithKey;
|
|
1555
|
-
let CommandKey = null;
|
|
1556
|
-
if (CommandWithKey.includes(':')) {
|
|
1557
|
-
let CommandKeyStart = Command.indexOf(':');
|
|
1558
|
-
Command = CommandWithKey.slice(0, CommandKeyStart);
|
|
1559
|
-
CommandKey = CommandWithKey.slice(CommandKeyStart + 1);
|
|
1560
|
-
}
|
|
1561
|
-
return {
|
|
1562
|
-
Command: Command?.trim(),
|
|
1563
|
-
CommandKey: CommandKey?.trim(),
|
|
1564
|
-
};
|
|
1565
|
-
};
|
|
1566
|
-
const Args = GetCommandPart(Command, '(', ')');
|
|
1567
|
-
const ForKey = GetCommandPart(Command, '<', '>');
|
|
1568
|
-
const CommandWithKey = GetCommandWithKey(Command);
|
|
1569
|
-
Result.push({
|
|
1570
|
-
Command: CommandWithKey?.Command,
|
|
1571
|
-
CommandKey: CommandWithKey?.CommandKey,
|
|
1572
|
-
ForKey: ForKey,
|
|
1573
|
-
Args: Args,
|
|
1574
|
-
StoreValue: SetPair,
|
|
1575
|
-
TreePaths: TreePaths,
|
|
1576
|
-
DomPaths: DomPaths,
|
|
1577
|
-
DomName: DomName,
|
|
1578
|
-
});
|
|
1579
|
-
continue;
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
$SetupCommandMap() {
|
|
1583
|
-
this.$CommandMap = {
|
|
1584
|
-
'v-text': {
|
|
1585
|
-
Execute: (Info, Option) => {
|
|
1586
|
-
Model.AddV_Text(Option.TargetDom, Option.TargetValue);
|
|
1587
|
-
},
|
|
1588
|
-
AcceptSelf: true,
|
|
1589
|
-
},
|
|
1590
|
-
'v-model': {
|
|
1591
|
-
Execute: (Info, Option) => {
|
|
1592
|
-
if (typeof (Option.TargetValue) == 'function') {
|
|
1593
|
-
Model.$Error(`v-model command value must be a string or string[], path: ${this.ToJoin(Info.DomPaths)}`);
|
|
1594
|
-
return;
|
|
1595
|
-
}
|
|
1596
|
-
Model.AddV_Model(Option.TargetDom, Option.TargetValue, {
|
|
1597
|
-
ModelValue: Info.CommandKey,
|
|
1598
|
-
});
|
|
1599
|
-
},
|
|
1600
|
-
AcceptSelf: true,
|
|
1601
|
-
},
|
|
1602
|
-
'v-for': {
|
|
1603
|
-
Execute: (Info, Option) => {
|
|
1604
|
-
Model.AddV_For(Option.TargetDom, Option.TargetValue, Info.ForKey);
|
|
1605
|
-
},
|
|
1606
|
-
AcceptSelf: true,
|
|
1607
|
-
},
|
|
1608
|
-
'v-show': {
|
|
1609
|
-
Execute: (Info, Option) => {
|
|
1610
|
-
Model.AddV_Show(Option.TargetDom, Option.TargetValue);
|
|
1611
|
-
},
|
|
1612
|
-
AcceptSelf: true,
|
|
1613
|
-
},
|
|
1614
|
-
'v-if': {
|
|
1615
|
-
Execute: (Info, Option) => {
|
|
1616
|
-
Model.AddV_If(Option.TargetDom, Option.TargetValue);
|
|
1617
|
-
},
|
|
1618
|
-
AcceptSelf: true,
|
|
1619
|
-
},
|
|
1620
|
-
'v-else-if': {
|
|
1621
|
-
Execute: (Info, Option) => {
|
|
1622
|
-
Model.AddV_ElseIf(Option.TargetDom, Option.TargetValue);
|
|
1623
|
-
},
|
|
1624
|
-
AcceptSelf: true,
|
|
1625
|
-
},
|
|
1626
|
-
'v-else': {
|
|
1627
|
-
Execute: (Info, Option) => {
|
|
1628
|
-
Model.AddV_Else(Option.TargetDom);
|
|
1629
|
-
},
|
|
1630
|
-
AcceptNull: true,
|
|
1631
|
-
},
|
|
1632
|
-
'v-bind': {
|
|
1633
|
-
Execute: (Info, Option) => {
|
|
1634
|
-
Model.AddV_Bind(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Args);
|
|
1635
|
-
},
|
|
1636
|
-
},
|
|
1637
|
-
'v-on': {
|
|
1638
|
-
Execute: (Info, Option) => {
|
|
1639
|
-
Model.AddV_On(Option.TargetDom, Info.CommandKey, Option.TargetValue, Info.Args);
|
|
1640
|
-
},
|
|
1641
|
-
},
|
|
1642
|
-
'v-slot': {
|
|
1643
|
-
Execute: (Info, Option) => {
|
|
1644
|
-
Model.AddV_Slot(Option.TargetDom, Info.CommandKey, Option.TargetValue);
|
|
1645
|
-
},
|
|
1646
|
-
},
|
|
1647
|
-
'v-on-mounted': {
|
|
1648
|
-
Execute: (Info, Option) => {
|
|
1649
|
-
Model.AddV_OnMounted(Option.TargetDom, Option.TargetValue, Info.Args);
|
|
1650
|
-
},
|
|
1651
|
-
},
|
|
1652
|
-
'v-on-unmounted': {
|
|
1653
|
-
Execute: (Info, Option) => {
|
|
1654
|
-
Model.AddV_OnUnMounted(Option.TargetDom, Option.TargetValue, Info.Args);
|
|
1655
|
-
},
|
|
1656
|
-
},
|
|
1657
|
-
'v-on-ready': {
|
|
1658
|
-
Execute: (Info, Option) => {
|
|
1659
|
-
Model.AddV_OnReady(Option.TargetDom, Option.TargetValue, Info.Args);
|
|
1660
|
-
},
|
|
1661
|
-
},
|
|
1662
|
-
'watch': {
|
|
1663
|
-
Execute: (Info, Option) => {
|
|
1664
|
-
let WatchPaths = [Info.DomPaths];
|
|
1665
|
-
if (Info.CommandKey)
|
|
1666
|
-
WatchPaths.push(Info.CommandKey.split(':'));
|
|
1667
|
-
WatchPaths = Model.Paths(WatchPaths);
|
|
1668
|
-
if (typeof (Info.StoreValue) === 'function')
|
|
1669
|
-
Model.AddV_Watch(WatchPaths, Info.StoreValue);
|
|
1670
|
-
else {
|
|
1671
|
-
let Target = Info.StoreValue;
|
|
1672
|
-
Model.AddV_Watch(WatchPaths, Target?.CallBack, Target?.Option);
|
|
1673
|
-
}
|
|
1674
|
-
},
|
|
1675
|
-
},
|
|
1676
|
-
'func': {
|
|
1677
|
-
Execute: (Info, Option) => {
|
|
1678
|
-
if (typeof (Info.StoreValue) != 'function') {
|
|
1679
|
-
Model.$Error(`func command value must be a function, path: ${this.ToJoin(Info.DomPaths)}`);
|
|
1680
|
-
return;
|
|
1681
|
-
}
|
|
1682
|
-
Model.AddV_Function(Model.Paths(...Info.DomPaths, Info.CommandKey ?? 'func'), Info.StoreValue);
|
|
1683
|
-
},
|
|
1684
|
-
},
|
|
1685
|
-
'using': {
|
|
1686
|
-
Execute: (Info, Option) => {
|
|
1687
|
-
if (typeof (Info.StoreValue) === 'function') {
|
|
1688
|
-
const nodes = Info.Nodes;
|
|
1689
|
-
const node = nodes != null ? nodes[0] : null;
|
|
1690
|
-
Info.StoreValue(Info.DomPaths, node, nodes);
|
|
1691
|
-
}
|
|
1692
|
-
},
|
|
1693
|
-
},
|
|
1694
|
-
'store': {
|
|
1695
|
-
Execute: (Info, Option) => {
|
|
1696
|
-
Model.UpdateStore(Info.DomPaths, Info.StoreValue);
|
|
1697
|
-
},
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
}
|
|
1701
|
-
AddV_Property(PropertyPath, Option) {
|
|
1702
|
-
return this.AddV_PropertyFrom(this.Store, PropertyPath, Option);
|
|
1703
|
-
}
|
|
1704
|
-
AddV_PropertyFrom(SourceStore, PropertyPath, Option) {
|
|
1705
|
-
if (PropertyPath == null)
|
|
1706
|
-
return;
|
|
1707
|
-
let SetStore = SourceStore;
|
|
1708
|
-
PropertyPath = this.ToJoin(PropertyPath);
|
|
1709
|
-
let PropertyKey = PropertyPath;
|
|
1710
|
-
if (PropertyPath.includes('.')) {
|
|
1711
|
-
let PropertyPaths = PropertyPath.split('.');
|
|
1712
|
-
PropertyKey = PropertyPaths.pop();
|
|
1713
|
-
let FindPath = PropertyPaths.join('.');
|
|
1714
|
-
SetStore = this.GetStoreFrom(SourceStore, FindPath, {
|
|
1715
|
-
CreateIfNull: true,
|
|
1716
|
-
});
|
|
1717
|
-
}
|
|
1718
|
-
let SetProperty = this.$BaseAddProperty(SetStore, PropertyKey, Option);
|
|
1719
|
-
if (Option.Bind) {
|
|
1720
|
-
if (!Array.isArray(Option.Bind))
|
|
1721
|
-
Option.Bind = [Option.Bind];
|
|
1722
|
-
for (let BindPath of Option.Bind) {
|
|
1723
|
-
if (BindPath == null)
|
|
1724
|
-
continue;
|
|
1725
|
-
this.AddV_Property(BindPath, {
|
|
1726
|
-
Target: PropertyPath,
|
|
1727
|
-
});
|
|
1728
|
-
}
|
|
1729
|
-
SetProperty['Bind'] = Option.Bind;
|
|
1730
|
-
}
|
|
1731
|
-
return this;
|
|
1732
|
-
}
|
|
1733
|
-
$BaseAddProperty(PropertyStore, PropertyKey, Option) {
|
|
1734
|
-
let ThisModel = this;
|
|
1735
|
-
let PropertyContent = {
|
|
1736
|
-
get() {
|
|
1737
|
-
if (Option.get)
|
|
1738
|
-
return Option.get();
|
|
1739
|
-
return this.$get(PropertyKey);
|
|
1740
|
-
},
|
|
1741
|
-
set(Value) {
|
|
1742
|
-
if (Option.set) {
|
|
1743
|
-
Option.set(Value);
|
|
1744
|
-
return;
|
|
1745
|
-
}
|
|
1746
|
-
this.$set(PropertyKey, Value);
|
|
1747
|
-
}
|
|
1748
|
-
};
|
|
1749
|
-
if (Option.get)
|
|
1750
|
-
PropertyContent.get = Option.get;
|
|
1751
|
-
if (Option.set != null)
|
|
1752
|
-
PropertyContent.set = Option.set;
|
|
1753
|
-
let OriginalValue = PropertyStore[PropertyKey];
|
|
1754
|
-
let SetProperty = Object.defineProperty(PropertyStore, PropertyKey, PropertyContent);
|
|
1755
|
-
SetProperty.$properties ??= {};
|
|
1756
|
-
SetProperty.$properties[PropertyKey] = { ...Option };
|
|
1757
|
-
SetProperty.$get ??= (PropertyKey) => {
|
|
1758
|
-
let PropertyOption = SetProperty.$properties[PropertyKey];
|
|
1759
|
-
if (PropertyOption?.Target == null)
|
|
1760
|
-
return PropertyOption[`$${PropertyKey}`];
|
|
1761
|
-
return ThisModel.GetStore(PropertyOption.Target);
|
|
1762
|
-
};
|
|
1763
|
-
SetProperty.$set ??= (PropertyKey, Value) => {
|
|
1764
|
-
let PropertyOption = SetProperty.$properties[PropertyKey];
|
|
1765
|
-
if (PropertyOption?.Target)
|
|
1766
|
-
ThisModel.SetStore(PropertyOption.Target, Value);
|
|
1767
|
-
else
|
|
1768
|
-
PropertyOption[`$${PropertyKey}`] = Value;
|
|
1769
|
-
};
|
|
1770
|
-
if (Option.Value != null)
|
|
1771
|
-
SetProperty[PropertyKey] = Option.Value;
|
|
1772
|
-
else if (OriginalValue != null)
|
|
1773
|
-
SetProperty[PropertyKey] = OriginalValue;
|
|
1774
|
-
return SetProperty;
|
|
1775
|
-
}
|
|
1776
|
-
$ConvertCommandOption(DomName, Option, Args) {
|
|
1777
|
-
let Result;
|
|
1778
|
-
if (Option == null || Option == '.') {
|
|
1779
|
-
if (this.IsPathType(DomName))
|
|
1780
|
-
Result = {
|
|
1781
|
-
Target: DomName
|
|
1782
|
-
};
|
|
1783
|
-
else {
|
|
1784
|
-
let Nodes = DomName;
|
|
1785
|
-
let NodeNames = Nodes.map(Item => Item.DomName);
|
|
1786
|
-
Result = {
|
|
1787
|
-
Target: NodeNames
|
|
1788
|
-
};
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
else if (typeof Option == 'string' || typeof Option == 'function' || Array.isArray(Option))
|
|
1792
|
-
Result = {
|
|
1793
|
-
Target: Option
|
|
1794
|
-
};
|
|
1795
|
-
else
|
|
1796
|
-
Result = Option;
|
|
1797
|
-
if (Args)
|
|
1798
|
-
Result.FuncArgs = Args;
|
|
1799
|
-
Result.FuncAction ??= false;
|
|
1800
|
-
if (Result.FuncArgs)
|
|
1801
|
-
Result.FuncAction = true;
|
|
1802
|
-
return Result;
|
|
1803
|
-
}
|
|
1804
|
-
$AddCommand(DomName, Command, Option) {
|
|
1805
|
-
if (DomName == null)
|
|
1806
|
-
return;
|
|
1807
|
-
if (!Array.isArray(DomName))
|
|
1808
|
-
DomName = [DomName];
|
|
1809
|
-
let IsFromQueryNode = DomName[0] instanceof QueryNode;
|
|
1810
|
-
let QueryNodes;
|
|
1811
|
-
if (IsFromQueryNode)
|
|
1812
|
-
QueryNodes = DomName;
|
|
1813
|
-
else
|
|
1814
|
-
QueryNodes = exports.Queryer.Query(DomName);
|
|
1815
|
-
let Target = Option.Target;
|
|
1816
|
-
if (typeof (Target) == 'function') {
|
|
1817
|
-
let FuncDomName = [];
|
|
1818
|
-
if (IsFromQueryNode)
|
|
1819
|
-
FuncDomName = DomName.at(-1).DomName;
|
|
1820
|
-
else
|
|
1821
|
-
FuncDomName = DomName;
|
|
1822
|
-
Target = this.$GenerateEventFunction(FuncDomName, Target, Command);
|
|
1823
|
-
if (Option.FuncArgs) {
|
|
1824
|
-
let Args = this.ToJoin(Option.FuncArgs, ',');
|
|
1825
|
-
Target += `(${Args})`;
|
|
1826
|
-
}
|
|
1827
|
-
else if (Option.FuncAction) {
|
|
1828
|
-
Target += `()`;
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
else
|
|
1832
|
-
Target = this.ToJoin(Target);
|
|
1833
|
-
if (Option.TargetHead)
|
|
1834
|
-
Target = Option.TargetHead + Target;
|
|
1835
|
-
if (Option.TargetTail)
|
|
1836
|
-
Target += Option.TargetTail;
|
|
1837
|
-
if (Option.CommandKey)
|
|
1838
|
-
Command += `:${Option.CommandKey}`;
|
|
1839
|
-
for (let i = 0; i < QueryNodes.length; i++) {
|
|
1840
|
-
let NodeItem = QueryNodes[i];
|
|
1841
|
-
let Dom = NodeItem.Dom;
|
|
1842
|
-
this.$SetAttribute(Dom, Command, Target);
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
$SetAttribute(Dom, AttrName, AttrValue) {
|
|
1846
|
-
if (Dom == null) {
|
|
1847
|
-
let Message = `Dom Element is null. ${AttrValue}`;
|
|
1848
|
-
console.warn(Message);
|
|
1849
|
-
return;
|
|
1850
|
-
}
|
|
1851
|
-
Dom.setAttribute(AttrName, AttrValue);
|
|
1852
|
-
}
|
|
1853
|
-
$RandomFuncName(BaseFuncName) {
|
|
1854
|
-
return `${BaseFuncName}${this.GenerateIdReplace('')}`.replace(/[-:.]/g, '_');
|
|
1855
|
-
}
|
|
1856
|
-
$GenerateEventFunction(DomName, EventFunc, Command) {
|
|
1857
|
-
let FuncName = this.$RandomFuncName(`${Command}_`);
|
|
1858
|
-
DomName = this.Paths(DomName);
|
|
1859
|
-
let FullFuncPath = ['event', ...DomName, FuncName];
|
|
1860
|
-
this.AddV_Function(FullFuncPath, EventFunc);
|
|
1861
|
-
return this.ToJoin(FullFuncPath);
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
exports.VueCommand = VueCommand;
|
|
1865
|
-
class VueModel extends VueCommand {
|
|
1866
|
-
$NativeWarn;
|
|
1867
|
-
$IsEnableVueWarn;
|
|
1868
|
-
$MountId = null;
|
|
1869
|
-
Id;
|
|
1870
|
-
constructor() {
|
|
1871
|
-
super();
|
|
1872
|
-
this.Id = this.GenerateId();
|
|
1873
|
-
this.$MountId = 'app';
|
|
1874
|
-
this.WithVueWarn(false);
|
|
1875
|
-
this.WithLifeCycleDirective();
|
|
1876
|
-
}
|
|
1877
|
-
WithMountId(MountId) {
|
|
1878
|
-
this.$MountId = MountId;
|
|
1879
|
-
return this;
|
|
1880
|
-
}
|
|
1881
|
-
WithVueWarn(Enable) {
|
|
1882
|
-
this.$IsEnableVueWarn = Enable;
|
|
1883
|
-
this.$NativeWarn = console.warn;
|
|
1884
|
-
console.warn = (...Message) => {
|
|
1885
|
-
if (Message == null)
|
|
1886
|
-
return;
|
|
1887
|
-
if (Message.length == 0)
|
|
1888
|
-
return;
|
|
1889
|
-
if (Message[0].toLowerCase().includes('[vue warn]') && this.$IsEnableVueWarn == false)
|
|
1890
|
-
return;
|
|
1891
|
-
this.$NativeWarn(Message);
|
|
1892
|
-
};
|
|
1893
|
-
return this;
|
|
1894
|
-
}
|
|
1895
|
-
WithLifeCycleDirective() {
|
|
1896
|
-
this.WithDirective('on-mounted', {
|
|
1897
|
-
mounted(el, binding, vnode) {
|
|
1898
|
-
if (typeof binding.value === 'function')
|
|
1899
|
-
binding.value(el, vnode);
|
|
1900
|
-
}
|
|
1901
|
-
});
|
|
1902
|
-
this.WithDirective('on-unmounted', {
|
|
1903
|
-
unmounted(el, binding, vnode) {
|
|
1904
|
-
if (typeof binding.value === 'function')
|
|
1905
|
-
binding.value(el, vnode);
|
|
1906
|
-
}
|
|
1907
|
-
});
|
|
1908
|
-
this.WithDirective('on-ready', {
|
|
1909
|
-
mounted(el, binding, vnode) {
|
|
1910
|
-
if (typeof binding.value === 'function')
|
|
1911
|
-
(0, vue_1.nextTick)(() => binding.value(el, vnode));
|
|
1912
|
-
}
|
|
1913
|
-
});
|
|
1914
|
-
}
|
|
1915
|
-
Init() {
|
|
1916
|
-
if (this.$IsInited)
|
|
1917
|
-
return this;
|
|
1918
|
-
this.Store = (0, vue_1.reactive)(this.Store);
|
|
1919
|
-
let GetStore = this.Store;
|
|
1920
|
-
let MountedFunc = this.$MountedFuncs;
|
|
1921
|
-
this.$VueApp = (0, vue_1.createApp)({
|
|
1922
|
-
...this.$VueOption,
|
|
1923
|
-
data() {
|
|
1924
|
-
return GetStore;
|
|
1925
|
-
},
|
|
1926
|
-
mounted: () => {
|
|
1927
|
-
for (let Func of MountedFunc)
|
|
1928
|
-
Func();
|
|
1929
|
-
}
|
|
1930
|
-
});
|
|
1931
|
-
for (let Item of this.$VueUse)
|
|
1932
|
-
this.$VueApp.use(Item);
|
|
1933
|
-
for (let Item of this.$Directive)
|
|
1934
|
-
this.$VueApp.directive(Item.Name, Item.Directive);
|
|
1935
|
-
this.$VueProxy = this.$VueApp.mount(`#${this.$MountId}`);
|
|
1936
|
-
this.$IsInited = true;
|
|
1937
|
-
return this;
|
|
1938
|
-
}
|
|
1939
|
-
Using(UseFunc = () => { }) {
|
|
1940
|
-
UseFunc();
|
|
1941
|
-
return this;
|
|
1942
|
-
}
|
|
1943
|
-
UsingVueApp(UsingFunc) {
|
|
1944
|
-
UsingFunc?.call(this, this.$VueApp);
|
|
1945
|
-
this.$VueApp.directive;
|
|
1946
|
-
return this;
|
|
1947
|
-
}
|
|
1948
|
-
AddV_OnMounted(DomName, Option, Args) {
|
|
1949
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1950
|
-
if (Args) {
|
|
1951
|
-
SetOption.FuncArgs = Args;
|
|
1952
|
-
SetOption.TargetHead = '($el, $vnode) => ';
|
|
1953
|
-
}
|
|
1954
|
-
SetOption.FuncAction = false;
|
|
1955
|
-
this.$AddCommand(DomName, `v-on-mounted`, SetOption);
|
|
1956
|
-
return this;
|
|
1957
|
-
}
|
|
1958
|
-
AddV_OnUnMounted(DomName, Option, Args) {
|
|
1959
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1960
|
-
if (Args) {
|
|
1961
|
-
SetOption.FuncArgs = Args;
|
|
1962
|
-
SetOption.TargetHead = '($el, $vnode) => ';
|
|
1963
|
-
}
|
|
1964
|
-
SetOption.FuncAction = false;
|
|
1965
|
-
this.$AddCommand(DomName, `v-on-unmounted`, SetOption);
|
|
1966
|
-
return this;
|
|
1967
|
-
}
|
|
1968
|
-
AddV_OnReady(DomName, Option, Args) {
|
|
1969
|
-
let SetOption = this.$ConvertCommandOption(DomName, Option);
|
|
1970
|
-
if (Args) {
|
|
1971
|
-
SetOption.FuncArgs = Args;
|
|
1972
|
-
SetOption.TargetHead = '($el, $vnode) => ';
|
|
1973
|
-
}
|
|
1974
|
-
SetOption.FuncAction = false;
|
|
1975
|
-
this.$AddCommand(DomName, `v-on-ready`, SetOption);
|
|
1976
|
-
return this;
|
|
1977
|
-
}
|
|
1978
|
-
}
|
|
1979
|
-
exports.VueModel = VueModel;
|
|
1980
|
-
const Model = new VueModel();
|
|
1981
|
-
exports.Model = Model;
|
|
1982
|
-
window.Model = Model;
|
|
1983
|
-
});
|
|
1984
|
-
//# sourceMappingURL=VueModel.js.map
|