@rugal.tu/vuemodel3 1.0.0-beta.1
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/VueModel.esm.js +854 -0
- package/dist/VueModel.esm.min.js +2 -0
- package/dist/VueModel.esm.min.js.map +7 -0
- package/dist/VueModel.sys.js +871 -0
- package/dist/VueModel.sys.min.js +2 -0
- package/dist/VueModel.sys.min.js.map +7 -0
- package/dist/VueModel.umd.js +871 -0
- package/dist/VueModel.umd.min.js +2 -0
- package/dist/VueModel.umd.min.js.map +7 -0
- package/package.json +13 -0
- package/src/VueModel.js +860 -0
- package/src/VueModel.ts +1056 -0
- package/src/esm/VueModel.js +854 -0
- package/src/esm/VueModel.js.map +1 -0
- package/src/sys/VueModel.js +871 -0
- package/src/sys/VueModel.js.map +1 -0
- package/src/umd/VueModel.js +871 -0
- package/src/umd/VueModel.js.map +1 -0
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
//#region DomQueryer
|
|
2
|
+
class QueryNode {
|
|
3
|
+
Dom;
|
|
4
|
+
DomName = null;
|
|
5
|
+
Parent = null;
|
|
6
|
+
Children = [];
|
|
7
|
+
ElementDeep = 0;
|
|
8
|
+
NodeDeep = 0;
|
|
9
|
+
constructor(Dom) {
|
|
10
|
+
this.Dom = Dom;
|
|
11
|
+
}
|
|
12
|
+
Query(DomName) {
|
|
13
|
+
return this.$RCS_QueryChildren(this, DomName);
|
|
14
|
+
}
|
|
15
|
+
$RCS_QueryChildren(TargetNode, DomName) {
|
|
16
|
+
for (let Item of TargetNode.Children) {
|
|
17
|
+
if (Item.DomName == DomName)
|
|
18
|
+
return Item;
|
|
19
|
+
let ChildrenResult = this.$RCS_QueryChildren(Item, DomName);
|
|
20
|
+
if (ChildrenResult != null)
|
|
21
|
+
return ChildrenResult;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class DomQueryer {
|
|
27
|
+
$Root = null;
|
|
28
|
+
$RootNode = null;
|
|
29
|
+
$Nodes = [];
|
|
30
|
+
$QueryDomName = null;
|
|
31
|
+
WithRoot(Filter) {
|
|
32
|
+
this.$Root = document.querySelector(Filter);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
WithDomName(QueryDomName) {
|
|
36
|
+
this.$QueryDomName = QueryDomName;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
Init() {
|
|
40
|
+
this.$Root ??= document.body;
|
|
41
|
+
this.$RootNode = new QueryNode(this.$Root);
|
|
42
|
+
this.$RCS_Visit(this.$Root, this.$RootNode, 0);
|
|
43
|
+
this.$Nodes = this.$Nodes.sort((A, B) => A.NodeDeep - B.NodeDeep);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
Query(DomName, TargetNode) {
|
|
47
|
+
TargetNode ??= this.$RootNode;
|
|
48
|
+
return TargetNode.Query(DomName);
|
|
49
|
+
}
|
|
50
|
+
Using(DomName, UsingFunc, TargetNode) {
|
|
51
|
+
TargetNode ??= this.$RootNode;
|
|
52
|
+
let QueryNode = TargetNode.Query(DomName);
|
|
53
|
+
if (QueryNode != null)
|
|
54
|
+
UsingFunc({
|
|
55
|
+
Node: TargetNode,
|
|
56
|
+
Dom: TargetNode.Dom,
|
|
57
|
+
});
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
$RCS_Visit(DomNode, Parent, ElementDeep) {
|
|
61
|
+
let NextNode = this.$AddNode(DomNode, Parent, ElementDeep);
|
|
62
|
+
NextNode ??= Parent;
|
|
63
|
+
let Children = DomNode.children;
|
|
64
|
+
if (DomNode instanceof HTMLTemplateElement)
|
|
65
|
+
Children = DomNode.content.children;
|
|
66
|
+
if (Children == null || Children.length == 0)
|
|
67
|
+
return;
|
|
68
|
+
for (let i = 0; i < Children.length; i++) {
|
|
69
|
+
let Item = Children[i];
|
|
70
|
+
if (Item instanceof HTMLElement)
|
|
71
|
+
this.$RCS_Visit(Item, NextNode, ElementDeep + 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
$AddNode(Dom, Parent, ElementDeep) {
|
|
75
|
+
if (this.$QueryDomName != null && !Dom.matches(`[${this.$QueryDomName}]`))
|
|
76
|
+
return null;
|
|
77
|
+
let DomName = Dom.getAttribute(this.$QueryDomName);
|
|
78
|
+
let NewNode = new QueryNode(Dom);
|
|
79
|
+
NewNode.DomName = DomName;
|
|
80
|
+
NewNode.ElementDeep = ElementDeep;
|
|
81
|
+
this.$Nodes.push(NewNode);
|
|
82
|
+
if (Parent != null) {
|
|
83
|
+
NewNode.Parent = Parent;
|
|
84
|
+
NewNode.NodeDeep = Parent.NodeDeep + 1;
|
|
85
|
+
Parent.Children.push(NewNode);
|
|
86
|
+
}
|
|
87
|
+
return NewNode;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var Queryer = new DomQueryer();
|
|
91
|
+
export { DomQueryer, Queryer };
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region CommonFunc
|
|
94
|
+
class CommonFunc {
|
|
95
|
+
//#region Protected Property
|
|
96
|
+
$NavigateToFunc;
|
|
97
|
+
//#endregion
|
|
98
|
+
constructor() {
|
|
99
|
+
this.$NavigateToFunc = null;
|
|
100
|
+
}
|
|
101
|
+
//#region Public With Method
|
|
102
|
+
WithNavigateTo(NavigateToFunc) {
|
|
103
|
+
this.$NavigateToFunc = NavigateToFunc;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region Public Method
|
|
108
|
+
GenerateId() {
|
|
109
|
+
let NewId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {
|
|
110
|
+
let RandomValue = crypto.getRandomValues(new Uint8Array(1))[0] & 15;
|
|
111
|
+
let Id = char === 'x' ? RandomValue : (RandomValue & 0x3) | 0x8;
|
|
112
|
+
return Id.toString(16);
|
|
113
|
+
});
|
|
114
|
+
return NewId;
|
|
115
|
+
}
|
|
116
|
+
NavigateTo(Url, UrlParam = null) {
|
|
117
|
+
if (!Array.isArray(Url))
|
|
118
|
+
Url = [Url];
|
|
119
|
+
if (Url == null || Url.length == 0 || Url[0].length == 0)
|
|
120
|
+
this.$Throw('Url can not be null or empty');
|
|
121
|
+
let IsAbsolute = Url[0][0] == '/';
|
|
122
|
+
let CombineUrl = Url
|
|
123
|
+
.map(Item => this.$ClearUrl(Item))
|
|
124
|
+
.join('/');
|
|
125
|
+
if (IsAbsolute)
|
|
126
|
+
CombineUrl = `/${CombineUrl}`;
|
|
127
|
+
if (UrlParam != null) {
|
|
128
|
+
if (typeof (UrlParam) != 'string')
|
|
129
|
+
UrlParam = this.$ConvertTo_UrlQuery(UrlParam);
|
|
130
|
+
CombineUrl += `?${UrlParam}`;
|
|
131
|
+
}
|
|
132
|
+
if (this.$NavigateToFunc)
|
|
133
|
+
this.$NavigateToFunc(CombineUrl);
|
|
134
|
+
else
|
|
135
|
+
window.location.href = CombineUrl;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
ForEachObject(Param, Func) {
|
|
139
|
+
let AllKey = Object.keys(Param);
|
|
140
|
+
for (let i = 0; i < AllKey.length; i++) {
|
|
141
|
+
let Key = AllKey[i];
|
|
142
|
+
let Value = Param[Key];
|
|
143
|
+
if (Func != null)
|
|
144
|
+
Func.call(this, Key, Value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
DeepObjectExtend(Target, Source, MaxDepth = 10) {
|
|
148
|
+
if (MaxDepth == 0)
|
|
149
|
+
return {
|
|
150
|
+
...Target,
|
|
151
|
+
...Source,
|
|
152
|
+
};
|
|
153
|
+
let AllKeys = Object.keys(Source);
|
|
154
|
+
for (let i = 0; i < AllKeys.length; i++) {
|
|
155
|
+
let Key = AllKeys[i];
|
|
156
|
+
if (!(Key in Target))
|
|
157
|
+
Target[Key] = Source[Key];
|
|
158
|
+
else if (typeof Source[Key] != "object")
|
|
159
|
+
Target[Key] = Source[Key];
|
|
160
|
+
else {
|
|
161
|
+
let NewObject = {
|
|
162
|
+
...this.DeepObjectExtend(Target[Key], Source[Key], MaxDepth - 1),
|
|
163
|
+
};
|
|
164
|
+
Target[Key] = NewObject;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return Target;
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region Protected Process
|
|
171
|
+
$ConvertTo_UrlQuery(Param) {
|
|
172
|
+
if (typeof Param === 'string')
|
|
173
|
+
return Param;
|
|
174
|
+
let AllParam = [];
|
|
175
|
+
this.ForEachObject(Param, (Key, Value) => {
|
|
176
|
+
AllParam.push(`${Key}=${Value}`);
|
|
177
|
+
});
|
|
178
|
+
let QueryString = AllParam.join('&');
|
|
179
|
+
return QueryString;
|
|
180
|
+
}
|
|
181
|
+
$ClearUrl(ApiUrl) {
|
|
182
|
+
let ClearUrl = ApiUrl.replace(/^\/+|\/+$/g, '');
|
|
183
|
+
return ClearUrl;
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region Console And Throw
|
|
187
|
+
$Throw(Message) {
|
|
188
|
+
throw new Error(Message);
|
|
189
|
+
}
|
|
190
|
+
$Error(Data) {
|
|
191
|
+
console.error(Data);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region Data Type
|
|
196
|
+
class FileDataType {
|
|
197
|
+
FileId;
|
|
198
|
+
File;
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
class ApiStore extends CommonFunc {
|
|
202
|
+
//#region Private Property
|
|
203
|
+
#ApiDomain = null;
|
|
204
|
+
#ApiToken = null;
|
|
205
|
+
#OnEventFunc = {};
|
|
206
|
+
#OnEventName = {
|
|
207
|
+
ApiStore: {
|
|
208
|
+
AddApi: 'AddApi',
|
|
209
|
+
UpdateStore: 'UpdateStore',
|
|
210
|
+
AddStore: 'AddStore',
|
|
211
|
+
SetStore: 'SetStore',
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
#Store = {
|
|
215
|
+
FileStore: {},
|
|
216
|
+
};
|
|
217
|
+
#Func_ConvertTo_FormData = [];
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region Protected Property
|
|
220
|
+
$ApiStore = {};
|
|
221
|
+
//#endregion
|
|
222
|
+
constructor() {
|
|
223
|
+
super();
|
|
224
|
+
this.UseFormJsonBody();
|
|
225
|
+
}
|
|
226
|
+
//#region Get/Set Property
|
|
227
|
+
get ApiDomain() {
|
|
228
|
+
if (this.#ApiDomain == null)
|
|
229
|
+
return null;
|
|
230
|
+
return this.$ClearUrl(this.#ApiDomain);
|
|
231
|
+
}
|
|
232
|
+
set ApiDomain(ApiDomain) {
|
|
233
|
+
this.#ApiDomain = this.$ClearUrl(ApiDomain);
|
|
234
|
+
}
|
|
235
|
+
get OnEventName() {
|
|
236
|
+
return this.#OnEventName;
|
|
237
|
+
}
|
|
238
|
+
get #EventName() {
|
|
239
|
+
return this.OnEventName.ApiStore;
|
|
240
|
+
}
|
|
241
|
+
get Store() {
|
|
242
|
+
return this.#Store;
|
|
243
|
+
}
|
|
244
|
+
set Store(Store) {
|
|
245
|
+
this.#Store = Store;
|
|
246
|
+
}
|
|
247
|
+
get FileStore() {
|
|
248
|
+
return this.Store.FileStore;
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region Public With Method
|
|
252
|
+
WithApiToken(ApiToken) {
|
|
253
|
+
this.#ApiToken = ApiToken;
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
WithApiDomain(ApiDomain) {
|
|
257
|
+
this.ApiDomain = ApiDomain;
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region ConvertTo Method
|
|
262
|
+
WithConvertTo_FormParam(ConvertToFunc) {
|
|
263
|
+
this.#Func_ConvertTo_FormData.push(ConvertToFunc);
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
ClearConvertTo_FormParam() {
|
|
267
|
+
this.#Func_ConvertTo_FormData = [];
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region Api Method
|
|
272
|
+
AddApi(AddApi) {
|
|
273
|
+
for (let ApiKey in AddApi) {
|
|
274
|
+
let ApiOption = AddApi[ApiKey];
|
|
275
|
+
let SetApi = {
|
|
276
|
+
ApiKey,
|
|
277
|
+
Url: ApiOption.Url,
|
|
278
|
+
Method: ApiOption.Method,
|
|
279
|
+
Param: ApiOption.Param,
|
|
280
|
+
OnSuccess: ApiOption.OnSuccess,
|
|
281
|
+
OnError: ApiOption.OnError,
|
|
282
|
+
OnComplete: ApiOption.OnComplete,
|
|
283
|
+
IsUpdateStore: ApiOption.IsUpdateStore ?? true,
|
|
284
|
+
};
|
|
285
|
+
this.$ApiStore[ApiKey] = SetApi;
|
|
286
|
+
this.$EventTrigger(this.#EventName.AddApi, SetApi);
|
|
287
|
+
}
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
ApiCall(ApiKey, Option = null) {
|
|
291
|
+
this.$BaseApiCall(ApiKey, Option, false);
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
294
|
+
ApiCall_Form(ApiKey, Option = null) {
|
|
295
|
+
this.$BaseApiCall(ApiKey, Option, true);
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
$BaseApiCall(ApiKey, Option, IsFormRequest) {
|
|
299
|
+
let Api = this.$ApiStore[ApiKey];
|
|
300
|
+
if (Api == null)
|
|
301
|
+
this.$Throw(`Api setting not found of "${ApiKey}"`);
|
|
302
|
+
let Param = Option?.Param ?? Api.Param;
|
|
303
|
+
if (typeof Param === 'function')
|
|
304
|
+
Param = Param();
|
|
305
|
+
let IsUpdateStore = Option?.IsUpdateStore ?? Api.IsUpdateStore ?? true;
|
|
306
|
+
let Url = this.$ConvertTo_ApiDomainUrl(Api.Url, Param?.Query);
|
|
307
|
+
let FetchRequest = this.$GenerateFetchRequest(Api, Param, IsFormRequest);
|
|
308
|
+
Api.OnCalling?.call(this, FetchRequest);
|
|
309
|
+
Option?.OnCalling?.call(this, FetchRequest);
|
|
310
|
+
fetch(Url, FetchRequest)
|
|
311
|
+
.then(async (ApiResult) => {
|
|
312
|
+
if (!ApiResult.ok)
|
|
313
|
+
throw ApiResult;
|
|
314
|
+
let ConvertResult = await this.$ProcessApiReturn(ApiResult);
|
|
315
|
+
if (IsUpdateStore) {
|
|
316
|
+
let StoreKey = Api.ApiKey;
|
|
317
|
+
this.UpdateStore(StoreKey, ConvertResult);
|
|
318
|
+
}
|
|
319
|
+
Api.OnSuccess?.call(this, ConvertResult);
|
|
320
|
+
Option?.OnSuccess?.call(this, ConvertResult);
|
|
321
|
+
return ConvertResult;
|
|
322
|
+
})
|
|
323
|
+
.catch(ex => {
|
|
324
|
+
Api.OnError?.call(this, ex);
|
|
325
|
+
Option?.OnError?.call(this, ex);
|
|
326
|
+
this.$Error(ex.message);
|
|
327
|
+
})
|
|
328
|
+
.then(ConvertResult => {
|
|
329
|
+
Api.OnComplete?.call(this, ConvertResult);
|
|
330
|
+
Option?.OnComplete?.call(this, ConvertResult);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
$GenerateFetchRequest(Api, Param, IsFormRequest) {
|
|
334
|
+
let Body = Param?.Body;
|
|
335
|
+
let Header = {
|
|
336
|
+
Authorization: this.#ApiToken,
|
|
337
|
+
};
|
|
338
|
+
let FetchRequest = {
|
|
339
|
+
method: Api.Method,
|
|
340
|
+
headers: Header,
|
|
341
|
+
};
|
|
342
|
+
if (IsFormRequest) {
|
|
343
|
+
let SendForm = this.$ConvertTo_FormData(Body, new FormData());
|
|
344
|
+
SendForm = this.$ConvertTo_FormFile(Param?.File, SendForm);
|
|
345
|
+
FetchRequest.body = SendForm;
|
|
346
|
+
FetchRequest.method = 'POST';
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
Header['content-type'] = 'application/json';
|
|
350
|
+
if (Api.Method == 'POST')
|
|
351
|
+
FetchRequest.body = JSON.stringify(Body ?? {});
|
|
352
|
+
}
|
|
353
|
+
return FetchRequest;
|
|
354
|
+
}
|
|
355
|
+
//#endregion
|
|
356
|
+
//#region Default Use Method
|
|
357
|
+
UseFormJsonBody(JsonBodyKey = 'Body') {
|
|
358
|
+
this.WithConvertTo_FormParam((FormDataBody, Form) => {
|
|
359
|
+
let ConvertParam = {};
|
|
360
|
+
ConvertParam[JsonBodyKey] = JSON.stringify(FormDataBody);
|
|
361
|
+
return ConvertParam;
|
|
362
|
+
});
|
|
363
|
+
return this;
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region Public Event Add
|
|
367
|
+
EventAdd_AddApi(EventFunc) {
|
|
368
|
+
this.$EventAdd(this.#EventName.AddApi, EventFunc);
|
|
369
|
+
return this;
|
|
370
|
+
}
|
|
371
|
+
EventAdd_UpdateStore(EventFunc) {
|
|
372
|
+
this.$EventAdd(this.#EventName.UpdateStore, EventFunc);
|
|
373
|
+
return this;
|
|
374
|
+
}
|
|
375
|
+
EventAdd_AddStore(EventFunc) {
|
|
376
|
+
this.$EventAdd(this.#EventName.AddStore, EventFunc);
|
|
377
|
+
return this;
|
|
378
|
+
}
|
|
379
|
+
EventAdd_SetStore(EventFunc) {
|
|
380
|
+
this.$EventAdd(this.#EventName.SetStore, EventFunc);
|
|
381
|
+
return this;
|
|
382
|
+
}
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region Protected Event Process
|
|
385
|
+
$EventAdd(EventName, OnFunc) {
|
|
386
|
+
if (EventName in this.#OnEventFunc == false)
|
|
387
|
+
this.#OnEventFunc[EventName] = [];
|
|
388
|
+
this.#OnEventFunc[EventName].push(OnFunc);
|
|
389
|
+
}
|
|
390
|
+
$EventTrigger(EventName, EventArg) {
|
|
391
|
+
let EventFuncs = this.#OnEventFunc[EventName];
|
|
392
|
+
if (EventFuncs == null)
|
|
393
|
+
return;
|
|
394
|
+
for (let Item of EventFuncs)
|
|
395
|
+
Item(EventArg);
|
|
396
|
+
}
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region Store Control
|
|
399
|
+
//#region Public Data Store Contorl
|
|
400
|
+
UpdateStore(StorePath, StoreData) {
|
|
401
|
+
this.$RCS_SetStore(StorePath, StoreData, this.Store, {
|
|
402
|
+
IsDeepSet: true,
|
|
403
|
+
});
|
|
404
|
+
this.$EventTrigger(this.#EventName.UpdateStore, {
|
|
405
|
+
Path: StorePath,
|
|
406
|
+
Data: StoreData,
|
|
407
|
+
});
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
AddStore(StorePath, StoreData = null) {
|
|
411
|
+
if (this.GetStore(StorePath) != null)
|
|
412
|
+
return this;
|
|
413
|
+
this.$RCS_SetStore(StorePath, StoreData, this.Store, {
|
|
414
|
+
IsDeepSet: true,
|
|
415
|
+
});
|
|
416
|
+
this.$EventTrigger(this.#EventName.AddStore, {
|
|
417
|
+
Path: StorePath,
|
|
418
|
+
Data: StoreData,
|
|
419
|
+
});
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
SetStore(StorePath, StoreData) {
|
|
423
|
+
this.$RCS_SetStore(StorePath, StoreData, this.Store, {
|
|
424
|
+
IsDeepSet: false,
|
|
425
|
+
});
|
|
426
|
+
this.$EventTrigger(this.#EventName.SetStore, {
|
|
427
|
+
Path: StorePath,
|
|
428
|
+
Data: StoreData,
|
|
429
|
+
});
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
GetStore(StorePath, Option = null) {
|
|
433
|
+
Option ??= {
|
|
434
|
+
CreateIfNull: false,
|
|
435
|
+
DefaultValue: {},
|
|
436
|
+
};
|
|
437
|
+
Option.CreateIfNull ??= false;
|
|
438
|
+
Option.DefaultValue ??= {};
|
|
439
|
+
let Result = this.$RCS_GetStore(StorePath, this.Store, {
|
|
440
|
+
CreateIfNull: Option.CreateIfNull,
|
|
441
|
+
DefaultValue: Option.DefaultValue,
|
|
442
|
+
});
|
|
443
|
+
return Result;
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region Protected Data Store Process
|
|
447
|
+
$RCS_GetStore(StorePath, FindStore, Option) {
|
|
448
|
+
if (FindStore == null)
|
|
449
|
+
return null;
|
|
450
|
+
let StorePaths = StorePath.split('.');
|
|
451
|
+
let FirstKey = StorePaths.shift();
|
|
452
|
+
if (FindStore[FirstKey] == null && Option.CreateIfNull)
|
|
453
|
+
FindStore[FirstKey] = Option.DefaultValue;
|
|
454
|
+
let NextStore = FindStore[FirstKey];
|
|
455
|
+
if (StorePaths.length == 0)
|
|
456
|
+
return NextStore;
|
|
457
|
+
let NextKey = StorePaths.join('.');
|
|
458
|
+
return this.$RCS_GetStore(NextKey, NextStore, Option);
|
|
459
|
+
}
|
|
460
|
+
$RCS_SetStore(StorePath, StoreData, FindStore, Option = {
|
|
461
|
+
IsDeepSet: true,
|
|
462
|
+
}) {
|
|
463
|
+
if (StorePath.includes('.')) {
|
|
464
|
+
let StorePaths = StorePath.split('.');
|
|
465
|
+
let FirstKey = StorePaths.shift();
|
|
466
|
+
if (FindStore[FirstKey] == null)
|
|
467
|
+
FindStore[FirstKey] = {};
|
|
468
|
+
let NextStore = FindStore[FirstKey];
|
|
469
|
+
let NextKey = StorePaths.join('.');
|
|
470
|
+
return this.$RCS_SetStore(NextKey, NextStore, StoreData, Option);
|
|
471
|
+
}
|
|
472
|
+
let IsAwaysSet = !Option.IsDeepSet ||
|
|
473
|
+
FindStore[StorePath] == null ||
|
|
474
|
+
StoreData == null || typeof StoreData != 'object';
|
|
475
|
+
if (IsAwaysSet) {
|
|
476
|
+
FindStore[StorePath] = StoreData;
|
|
477
|
+
return StoreData;
|
|
478
|
+
}
|
|
479
|
+
this.$DeepSetObject(StorePath, StoreData, FindStore);
|
|
480
|
+
return StoreData;
|
|
481
|
+
}
|
|
482
|
+
$DeepSetObject(StorePath, SetData, FindStore) {
|
|
483
|
+
if (!Array.isArray(SetData)) {
|
|
484
|
+
this.ForEachObject(SetData, (Key, Value) => {
|
|
485
|
+
FindStore[StorePath][Key] = Value;
|
|
486
|
+
});
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (!Array.isArray(FindStore[StorePath]))
|
|
490
|
+
FindStore[StorePath] = [];
|
|
491
|
+
if (FindStore[StorePath].length > 0)
|
|
492
|
+
FindStore[StorePath].splice(0, FindStore[StorePath].length);
|
|
493
|
+
FindStore[StorePath].push(...SetData);
|
|
494
|
+
}
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region File Store
|
|
497
|
+
AddFileStore(FileStoreKey) {
|
|
498
|
+
if (this.FileStore[FileStoreKey] == null)
|
|
499
|
+
this.FileStore[FileStoreKey] = [];
|
|
500
|
+
return this;
|
|
501
|
+
}
|
|
502
|
+
Files(FileStoreKey, MapFunc = null) {
|
|
503
|
+
let GetFiles = this.FileStore[FileStoreKey];
|
|
504
|
+
if (GetFiles == null)
|
|
505
|
+
return [];
|
|
506
|
+
let MapFiles = MapFunc != null ?
|
|
507
|
+
GetFiles.map(Item => MapFunc(Item)) :
|
|
508
|
+
GetFiles.map(Item => Item['File']);
|
|
509
|
+
return MapFiles;
|
|
510
|
+
}
|
|
511
|
+
//#endregion
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region Protected Process
|
|
514
|
+
$ProcessApiReturn(ApiResponse) {
|
|
515
|
+
let GetContentType = ApiResponse.headers.get("content-type");
|
|
516
|
+
let ConvertSuccess = null;
|
|
517
|
+
if (GetContentType && GetContentType.includes('application/json')) {
|
|
518
|
+
ConvertSuccess = ApiResponse.json()
|
|
519
|
+
.then(GetJson => GetJson);
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
ConvertSuccess = ApiResponse.text()
|
|
523
|
+
.then(GetText => GetText);
|
|
524
|
+
}
|
|
525
|
+
return ConvertSuccess;
|
|
526
|
+
}
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region Protected ConvertTo
|
|
529
|
+
$ConvertTo_ApiDomainUrl(Url, Param = null) {
|
|
530
|
+
let ApiDomainUrl = this.$ClearUrl(Url);
|
|
531
|
+
if (this.ApiDomain != null && !ApiDomainUrl.includes('http'))
|
|
532
|
+
ApiDomainUrl = `${this.ApiDomain}/${ApiDomainUrl}`;
|
|
533
|
+
if (Param != null)
|
|
534
|
+
ApiDomainUrl = `${ApiDomainUrl}?${this.$ConvertTo_UrlQuery(Param)}`;
|
|
535
|
+
return ApiDomainUrl;
|
|
536
|
+
}
|
|
537
|
+
$ConvertTo_FormData(ConvertFormData, Form) {
|
|
538
|
+
Form ??= new FormData();
|
|
539
|
+
if (ConvertFormData == null)
|
|
540
|
+
return Form;
|
|
541
|
+
this.#Func_ConvertTo_FormData.forEach(Func => {
|
|
542
|
+
ConvertFormData = Func(ConvertFormData, Form);
|
|
543
|
+
});
|
|
544
|
+
if (ConvertFormData instanceof FormData)
|
|
545
|
+
return ConvertFormData;
|
|
546
|
+
this.ForEachObject(ConvertFormData, (Key, Value) => {
|
|
547
|
+
Form.append(Key, Value);
|
|
548
|
+
});
|
|
549
|
+
return Form;
|
|
550
|
+
}
|
|
551
|
+
$ConvertTo_FormFile(FileParam, Form) {
|
|
552
|
+
Form ??= new FormData();
|
|
553
|
+
if (FileParam == null)
|
|
554
|
+
return Form;
|
|
555
|
+
let DefaultKey = 'Files';
|
|
556
|
+
if (Array.isArray(FileParam)) {
|
|
557
|
+
this.$AppendFileDataArray(DefaultKey, Form, FileParam);
|
|
558
|
+
return Form;
|
|
559
|
+
}
|
|
560
|
+
if (FileParam instanceof File || FileParam instanceof FileDataType) {
|
|
561
|
+
this.$AppendFileData(DefaultKey, Form, FileParam);
|
|
562
|
+
return Form;
|
|
563
|
+
}
|
|
564
|
+
let Keys = Object.keys(FileParam);
|
|
565
|
+
for (let i = 0; i < Keys.length; i++) {
|
|
566
|
+
let FileKey = Keys[i];
|
|
567
|
+
let FileValue = FileParam[FileKey];
|
|
568
|
+
if (Array.isArray(FileValue)) {
|
|
569
|
+
this.$AppendFileDataArray(FileKey, Form, FileValue);
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
this.$AppendFileData(FileKey, Form, FileValue);
|
|
573
|
+
}
|
|
574
|
+
return Form;
|
|
575
|
+
}
|
|
576
|
+
$AppendFileDataArray(FileKey, Form, FileDatas) {
|
|
577
|
+
FileDatas.forEach(FileData => {
|
|
578
|
+
this.$AppendFileData(FileKey, Form, FileData);
|
|
579
|
+
});
|
|
580
|
+
return Form;
|
|
581
|
+
}
|
|
582
|
+
$AppendFileData(FileKey, Form, FileData) {
|
|
583
|
+
if (FileData instanceof File)
|
|
584
|
+
Form.append(FileKey, FileData);
|
|
585
|
+
else
|
|
586
|
+
Form.append(FileKey, FileData.File);
|
|
587
|
+
return Form;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
import { createApp, reactive } from 'vue';
|
|
591
|
+
class VueStore extends ApiStore {
|
|
592
|
+
$VueProxy = null;
|
|
593
|
+
$VueOption = {
|
|
594
|
+
methods: {},
|
|
595
|
+
components: {},
|
|
596
|
+
watch: {},
|
|
597
|
+
computed: {},
|
|
598
|
+
};
|
|
599
|
+
$VueApp = null;
|
|
600
|
+
$VueUse = [];
|
|
601
|
+
$MountedFuncs = [];
|
|
602
|
+
constructor() {
|
|
603
|
+
super();
|
|
604
|
+
this.#Setup();
|
|
605
|
+
}
|
|
606
|
+
//#region Private Setup
|
|
607
|
+
#Setup() {
|
|
608
|
+
this
|
|
609
|
+
.EventAdd_AddApi(Arg => {
|
|
610
|
+
this.AddStore(Arg.ApiKey);
|
|
611
|
+
})
|
|
612
|
+
.EventAdd_UpdateStore(() => {
|
|
613
|
+
this.ForceUpdate();
|
|
614
|
+
})
|
|
615
|
+
.EventAdd_AddStore(() => {
|
|
616
|
+
this.ForceUpdate();
|
|
617
|
+
})
|
|
618
|
+
.EventAdd_SetStore(() => {
|
|
619
|
+
this.ForceUpdate();
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region Get/Set Property
|
|
624
|
+
get Store() {
|
|
625
|
+
if (this.$VueProxy != null)
|
|
626
|
+
return this.$VueProxy;
|
|
627
|
+
return super.Store;
|
|
628
|
+
}
|
|
629
|
+
set Store(Store) {
|
|
630
|
+
super.Store = Store;
|
|
631
|
+
}
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region Public With Method
|
|
634
|
+
WithVueOption(VueOption = {}) {
|
|
635
|
+
this.$VueOption = this.DeepObjectExtend(this.$VueOption, VueOption);
|
|
636
|
+
return this;
|
|
637
|
+
}
|
|
638
|
+
WithMounted(MountedFunc = () => { }) {
|
|
639
|
+
this.$MountedFuncs.push(MountedFunc);
|
|
640
|
+
return this;
|
|
641
|
+
}
|
|
642
|
+
WithComponent(Component = {}) {
|
|
643
|
+
this.$VueOption.components = this.DeepObjectExtend(this.$VueOption.components, Component);
|
|
644
|
+
return this;
|
|
645
|
+
}
|
|
646
|
+
//#endregion
|
|
647
|
+
//#region Public Method
|
|
648
|
+
ForceUpdate() {
|
|
649
|
+
this.$VueProxy?.$forceUpdate();
|
|
650
|
+
return this;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
class VueCmd extends VueStore {
|
|
654
|
+
//#region Path Command
|
|
655
|
+
AddV_Text(DomName, StorePath) {
|
|
656
|
+
this.$AddCommand(DomName, StorePath, 'v-text');
|
|
657
|
+
return this;
|
|
658
|
+
}
|
|
659
|
+
AddV_Model(DomName, StorePath) {
|
|
660
|
+
this.$AddCommand(DomName, StorePath, 'v-model');
|
|
661
|
+
return this;
|
|
662
|
+
}
|
|
663
|
+
AddV_Slot(DomName, SlotKey, StorePath) {
|
|
664
|
+
this.$AddCommand(DomName, StorePath, `v-slot:${SlotKey}`);
|
|
665
|
+
return this;
|
|
666
|
+
}
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region Path/Function Command
|
|
669
|
+
AddV_For(DomName, StorePath) {
|
|
670
|
+
this.$AddCommand(DomName, StorePath, 'v-for');
|
|
671
|
+
return this;
|
|
672
|
+
}
|
|
673
|
+
AddV_If(DomName, StorePath) {
|
|
674
|
+
this.$AddCommand(DomName, StorePath, 'v-if');
|
|
675
|
+
return this;
|
|
676
|
+
}
|
|
677
|
+
AddV_Show(DomName, StorePath) {
|
|
678
|
+
this.$AddCommand(DomName, StorePath, 'v-show');
|
|
679
|
+
return this;
|
|
680
|
+
}
|
|
681
|
+
AddV_Bind(DomName, StorePath) {
|
|
682
|
+
this.$AddCommand(DomName, StorePath, 'v-bind');
|
|
683
|
+
return this;
|
|
684
|
+
}
|
|
685
|
+
AddV_On(DomName, EventName, EventFunc) {
|
|
686
|
+
this.$AddCommand(DomName, EventFunc, `v-on:${EventName}`);
|
|
687
|
+
return this;
|
|
688
|
+
}
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region Customer Command
|
|
691
|
+
AddV_OnChange(DomName, ChangeFunc) {
|
|
692
|
+
this.AddV_On(DomName, 'change', ChangeFunc);
|
|
693
|
+
return this;
|
|
694
|
+
}
|
|
695
|
+
AddV_Click(DomName, ClickFunc) {
|
|
696
|
+
this.AddV_On(DomName, 'click', ClickFunc);
|
|
697
|
+
return this;
|
|
698
|
+
}
|
|
699
|
+
AddV_Function(FuncName, Func) {
|
|
700
|
+
this.$VueOption.methods[FuncName] = Func;
|
|
701
|
+
return this;
|
|
702
|
+
}
|
|
703
|
+
AddV_Watch(WatchPath, Func, Deep = false, Option = {}) {
|
|
704
|
+
let SetWatch = {
|
|
705
|
+
handler: Func,
|
|
706
|
+
deep: Deep,
|
|
707
|
+
...Option,
|
|
708
|
+
};
|
|
709
|
+
this.$VueOption.watch[WatchPath] = SetWatch;
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
//#endregion
|
|
713
|
+
//#region Property Method
|
|
714
|
+
AddV_Property(PropertyPath, Option) {
|
|
715
|
+
let SetStore = this.Store;
|
|
716
|
+
let PropertyKey = PropertyPath;
|
|
717
|
+
if (PropertyPath.includes('.')) {
|
|
718
|
+
let PropertyPaths = PropertyPath.split('.');
|
|
719
|
+
PropertyKey = PropertyPaths.pop();
|
|
720
|
+
let FindPath = PropertyPaths.join('.');
|
|
721
|
+
SetStore = this.GetStore(FindPath, {
|
|
722
|
+
CreateIfNull: true,
|
|
723
|
+
DefaultValue: {},
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
let SetProperty = this.$BaseAddProperty(SetStore, PropertyKey, Option);
|
|
727
|
+
if (Option.Bind) {
|
|
728
|
+
if (!Array.isArray(Option.Bind))
|
|
729
|
+
Option.Bind = [Option.Bind];
|
|
730
|
+
for (let BindPath of Option.Bind) {
|
|
731
|
+
this.AddV_Property(BindPath, {
|
|
732
|
+
Target: PropertyPath,
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
SetProperty['Bind'] = Option.Bind;
|
|
736
|
+
}
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
$BaseAddProperty(PropertyStore, PropertyKey, Option) {
|
|
740
|
+
let ThisModel = this;
|
|
741
|
+
let PropertyContent = {
|
|
742
|
+
get() {
|
|
743
|
+
if (Option.Target == null)
|
|
744
|
+
return this[`$${PropertyKey}`];
|
|
745
|
+
return ThisModel.GetStore(Option.Target);
|
|
746
|
+
},
|
|
747
|
+
set(Value) {
|
|
748
|
+
if (Option.Target == null)
|
|
749
|
+
this[`$${PropertyKey}`] = Value;
|
|
750
|
+
else
|
|
751
|
+
ThisModel.SetStore(Option.Target, Value);
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
let HasGet = Option.get != null;
|
|
755
|
+
let HasSet = Option.set != null;
|
|
756
|
+
if (HasGet || HasSet) {
|
|
757
|
+
PropertyContent = {};
|
|
758
|
+
if (HasGet)
|
|
759
|
+
PropertyContent.get = Option.get;
|
|
760
|
+
if (HasSet)
|
|
761
|
+
PropertyContent.set = Option.set;
|
|
762
|
+
}
|
|
763
|
+
let SetProperty = Object.defineProperty(PropertyStore, PropertyKey, PropertyContent);
|
|
764
|
+
if (Option.Value != null && HasSet)
|
|
765
|
+
SetProperty[PropertyKey] = Option.Value;
|
|
766
|
+
return SetProperty;
|
|
767
|
+
}
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region Protected Process
|
|
770
|
+
$AddCommand(DomName, StorePath, Command) {
|
|
771
|
+
Queryer.Using(DomName, ({ Dom }) => {
|
|
772
|
+
if (StorePath instanceof Function) {
|
|
773
|
+
this.$SetFuncCommand(DomName, StorePath, Command);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
this.$SetAttribute(Dom, Command, StorePath, {
|
|
777
|
+
Command,
|
|
778
|
+
StorePath,
|
|
779
|
+
DomName,
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
$SetAttribute(Dom, AttrName, AttrValue, Option) {
|
|
784
|
+
if (Dom == null) {
|
|
785
|
+
let Tail = [];
|
|
786
|
+
if (Option?.Command)
|
|
787
|
+
Tail.push(Option.Command);
|
|
788
|
+
if (Option?.StorePath)
|
|
789
|
+
Tail.push(Option.StorePath);
|
|
790
|
+
let TailMessage = Tail.join(', ');
|
|
791
|
+
let Message = `Dom Element is null. ${TailMessage}`;
|
|
792
|
+
console.warn(Message);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
Dom.setAttribute(AttrName, AttrValue);
|
|
796
|
+
}
|
|
797
|
+
//#region Function Control
|
|
798
|
+
$RandomFuncName(BaseFuncName) {
|
|
799
|
+
return `${BaseFuncName}${this.GenerateId()}`.replace(/[-:]/g, '_');
|
|
800
|
+
}
|
|
801
|
+
$SetFuncCommand(DomName, EventFunc, Command) {
|
|
802
|
+
let FuncName = this.$RandomFuncName(`${DomName}_${Command}_`);
|
|
803
|
+
this.AddV_Function(FuncName, EventFunc);
|
|
804
|
+
this.$AddCommand(DomName, FuncName, Command);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
class VueModel extends VueCmd {
|
|
808
|
+
$IsInited = false;
|
|
809
|
+
$MountId = null;
|
|
810
|
+
$QueryAttribute = null;
|
|
811
|
+
constructor() {
|
|
812
|
+
super();
|
|
813
|
+
}
|
|
814
|
+
//#region With Method
|
|
815
|
+
WithMountId(MountId) {
|
|
816
|
+
this.$MountId = MountId;
|
|
817
|
+
return this;
|
|
818
|
+
}
|
|
819
|
+
WithQueryAttribute(QueryAttribute) {
|
|
820
|
+
this.$QueryAttribute = QueryAttribute;
|
|
821
|
+
return this;
|
|
822
|
+
}
|
|
823
|
+
//#endregion
|
|
824
|
+
//#region Public Method
|
|
825
|
+
Init() {
|
|
826
|
+
if (this.$IsInited)
|
|
827
|
+
return this;
|
|
828
|
+
this.Store = reactive(this.Store);
|
|
829
|
+
let GetStore = this.Store;
|
|
830
|
+
let MountedFunc = this.$MountedFuncs;
|
|
831
|
+
this.$VueApp = createApp({
|
|
832
|
+
...this.$VueOption,
|
|
833
|
+
data() {
|
|
834
|
+
return GetStore;
|
|
835
|
+
},
|
|
836
|
+
mounted: () => {
|
|
837
|
+
for (let Func of MountedFunc)
|
|
838
|
+
Func();
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
for (let Item of this.$VueUse)
|
|
842
|
+
this.$VueApp.use(Item);
|
|
843
|
+
this.$VueProxy = this.$VueApp.mount(`#${this.$MountId}`);
|
|
844
|
+
this.$IsInited = true;
|
|
845
|
+
return this;
|
|
846
|
+
}
|
|
847
|
+
Using(UseFunc = () => { }) {
|
|
848
|
+
UseFunc();
|
|
849
|
+
return this;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
var Model = new VueModel();
|
|
853
|
+
export { Model, CommonFunc, ApiStore, VueStore, };
|
|
854
|
+
//# sourceMappingURL=VueModel.js.map
|