clickgo 3.1.1-dev10 → 3.1.3-dev12
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/app/demo/app.js +0 -72
- package/dist/app/demo/config.json +109 -0
- package/dist/app/demo/form/control/button/button.js +12 -11
- package/dist/app/demo/form/control/button/button.xml +6 -6
- package/dist/app/demo/form/control/check/check.js +14 -10
- package/dist/app/demo/form/control/file/file.js +15 -13
- package/dist/app/demo/form/control/{overflow/overflow.css → flow/flow.css} +0 -0
- package/dist/app/demo/form/control/flow/flow.js +64 -0
- package/dist/app/demo/form/control/{overflow/overflow.scss → flow/flow.scss} +0 -0
- package/dist/app/demo/form/control/flow/flow.xml +101 -0
- package/dist/app/demo/form/control/form/form.js +1 -1
- package/dist/app/demo/form/control/form/form.xml +3 -3
- package/dist/app/demo/form/control/img/img.xml +2 -2
- package/dist/app/demo/form/control/list/list.js +95 -75
- package/dist/app/demo/form/control/list/list.xml +15 -11
- package/dist/app/demo/form/control/marquee/marquee.js +12 -10
- package/dist/app/demo/form/control/menu/menu.js +10 -6
- package/dist/app/demo/form/control/monaco/monaco.js +50 -60
- package/dist/app/demo/form/control/monaco/monaco.xml +6 -5
- package/dist/app/demo/form/control/property/property.js +131 -127
- package/dist/app/demo/form/control/radio/radio.js +9 -5
- package/dist/app/demo/form/control/scroll/scroll.js +16 -12
- package/dist/app/demo/form/control/scroll/scroll.xml +10 -10
- package/dist/app/demo/form/control/select/select.js +132 -71
- package/dist/app/demo/form/control/select/select.xml +69 -67
- package/dist/app/demo/form/control/tab/tab.js +21 -20
- package/dist/app/demo/form/control/tab/tab.xml +2 -2
- package/dist/app/demo/form/control/text/text.js +53 -45
- package/dist/app/demo/form/control/text/text.xml +3 -3
- package/dist/app/demo/form/control/{greatview/greatview.css → vflow/vflow.css} +0 -0
- package/dist/app/demo/form/control/vflow/vflow.js +79 -0
- package/dist/app/demo/form/control/{greatview/greatview.scss → vflow/vflow.scss} +0 -0
- package/dist/app/demo/form/control/{greatview/greatview.xml → vflow/vflow.xml} +25 -25
- package/dist/app/demo/form/event/form/form.js +58 -56
- package/dist/app/demo/form/event/form/form.xml +3 -3
- package/dist/app/demo/form/event/screen/screen.js +30 -28
- package/dist/app/demo/form/event/screen/screen.xml +2 -2
- package/dist/app/demo/form/event/task/task.js +31 -31
- package/dist/app/demo/form/event/task/task.xml +3 -3
- package/dist/app/demo/form/main.js +166 -5
- package/dist/app/demo/form/main.xml +37 -35
- package/dist/app/demo/form/method/aform/aform.js +57 -0
- package/dist/app/demo/form/method/aform/aform.xml +35 -0
- package/dist/app/demo/form/method/aform/test.xml +6 -0
- package/dist/app/demo/form/method/core/core.js +11 -8
- package/dist/app/demo/form/method/core/core.xml +2 -1
- package/dist/app/demo/form/method/dom/dom.js +91 -99
- package/dist/app/demo/form/method/dom/dom.xml +6 -7
- package/dist/app/demo/form/method/form/form.js +10 -28
- package/dist/app/demo/form/method/form/form.xml +8 -15
- package/dist/app/demo/form/method/fs/fs.js +34 -33
- package/dist/app/demo/form/method/fs/fs.xml +1 -1
- package/dist/app/demo/form/method/fs/text.js +12 -12
- package/dist/app/demo/form/method/native/native.js +50 -0
- package/dist/app/demo/form/method/native/native.xml +12 -0
- package/dist/app/demo/form/method/system/system.js +50 -0
- package/dist/app/demo/form/method/system/system.xml +11 -0
- package/dist/app/demo/form/method/task/task.js +59 -61
- package/dist/app/demo/form/method/task/task.xml +4 -6
- package/dist/app/demo/form/method/theme/theme.js +14 -14
- package/dist/app/demo/form/method/tool/tool.js +29 -28
- package/dist/app/demo/form/method/tool/tool.xml +3 -3
- package/dist/app/demo/form/method/zip/zip.js +46 -41
- package/dist/app/demo/form/method/zip/zip.xml +1 -1
- package/dist/app/task/app.js +0 -25
- package/dist/app/task/config.json +29 -0
- package/dist/app/task/form/bar/bar.js +2 -2
- package/dist/app/task/form/bar/bar.xml +1 -1
- package/dist/clickgo.js +17 -5
- package/dist/clickgo.ts +22 -3
- package/dist/control/common.cgc +0 -0
- package/dist/control/form.cgc +0 -0
- package/dist/control/monaco.cgc +0 -0
- package/dist/control/property.cgc +0 -0
- package/dist/control/task.cgc +0 -0
- package/dist/global.css +1 -1
- package/dist/index.js +28 -8
- package/dist/index.ts +33 -7
- package/dist/lib/control.js +75 -105
- package/dist/lib/control.ts +102 -124
- package/dist/lib/core.js +108 -252
- package/dist/lib/core.ts +122 -268
- package/dist/lib/dom.js +564 -483
- package/dist/lib/dom.ts +703 -546
- package/dist/lib/form.js +170 -153
- package/dist/lib/form.ts +132 -99
- package/dist/lib/fs.js +1 -1
- package/dist/lib/fs.ts +1 -1
- package/dist/lib/native.js +135 -8
- package/dist/lib/native.ts +176 -12
- package/dist/lib/task.js +301 -175
- package/dist/lib/task.ts +330 -207
- package/dist/lib/tool.js +48 -1
- package/dist/lib/tool.ts +61 -0
- package/dist/lib/zip.ts +2 -0
- package/dist/theme/familiar.cgt +0 -0
- package/package.json +1 -1
- package/types/index.d.ts +26 -29
- package/dist/app/demo/form/control/greatview/greatview.js +0 -92
- package/dist/app/demo/form/control/overflow/overflow.js +0 -70
- package/dist/app/demo/form/control/overflow/overflow.xml +0 -98
- package/dist/app/demo/form/control/view/view.css +0 -1
- package/dist/app/demo/form/control/view/view.js +0 -73
- package/dist/app/demo/form/control/view/view.scss +0 -18
- package/dist/app/demo/form/control/view/view.xml +0 -94
- package/dist/app/demo/form/method/form/test.xml +0 -5
package/dist/lib/control.js
CHANGED
|
@@ -20,6 +20,7 @@ const fs = require("./fs");
|
|
|
20
20
|
class AbstractControl {
|
|
21
21
|
constructor() {
|
|
22
22
|
this.props = {};
|
|
23
|
+
this.slots = {};
|
|
23
24
|
}
|
|
24
25
|
get filename() {
|
|
25
26
|
return '';
|
|
@@ -85,33 +86,32 @@ class AbstractControl {
|
|
|
85
86
|
}
|
|
86
87
|
core.trigger(name, this.taskId, this.formId, param1, param2);
|
|
87
88
|
}
|
|
89
|
+
get propBoolean() {
|
|
90
|
+
return (name) => {
|
|
91
|
+
return tool.getBoolean(this.props[name]);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
get propNumber() {
|
|
95
|
+
return (name) => {
|
|
96
|
+
return tool.getNumber(this.props[name]);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
get propInt() {
|
|
100
|
+
return (name) => {
|
|
101
|
+
return Math.round(this.propNumber(name));
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
get propArray() {
|
|
105
|
+
return (name) => {
|
|
106
|
+
return tool.getArray(this.props[name]);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
88
109
|
get element() {
|
|
89
110
|
return this.$el;
|
|
90
111
|
}
|
|
91
112
|
emit(name, ...v) {
|
|
92
113
|
this.$emit(name, ...v);
|
|
93
114
|
}
|
|
94
|
-
get slots() {
|
|
95
|
-
return (name = 'default') => {
|
|
96
|
-
const d = this.$slots[name];
|
|
97
|
-
if (!d) {
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
const slots = [];
|
|
101
|
-
const list = d();
|
|
102
|
-
for (const item of list) {
|
|
103
|
-
if (typeof item.type === 'symbol') {
|
|
104
|
-
for (const item2 of item.children) {
|
|
105
|
-
slots.push(item2);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
slots.push(item);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return slots;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
115
|
get parent() {
|
|
116
116
|
return this.$parent;
|
|
117
117
|
}
|
|
@@ -162,92 +162,56 @@ function read(blob) {
|
|
|
162
162
|
return false;
|
|
163
163
|
}
|
|
164
164
|
const controlPkg = {};
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
165
|
+
const list = z.readDir('/');
|
|
166
|
+
for (const sub of list) {
|
|
167
|
+
if (sub.isFile) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const configContent = yield z.getContent('/' + sub.name + '/config.json');
|
|
171
|
+
if (!configContent) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const config = JSON.parse(configContent);
|
|
175
|
+
controlPkg[config.name] = {
|
|
176
|
+
'type': 'control',
|
|
177
|
+
'config': config,
|
|
178
|
+
'files': {}
|
|
174
179
|
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
const list = z.readDir('/' + sub.name + '/', {
|
|
181
|
+
'hasChildren': true
|
|
182
|
+
});
|
|
183
|
+
for (const file of list) {
|
|
184
|
+
const pre = file.path.slice(config.name.length + 1);
|
|
185
|
+
const mime = tool.getMimeByPath(file.name);
|
|
186
|
+
if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
|
|
187
|
+
const fab = yield z.getContent(file.path + file.name, 'string');
|
|
188
|
+
if (!fab) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
controlPkg[config.name].files[pre + file.name] = fab.replace(/^\ufeff/, '');
|
|
179
192
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const files = {};
|
|
188
|
-
const filesLength = Object.keys(config.files).length;
|
|
189
|
-
let fileLoadedLength = 0;
|
|
190
|
-
yield new Promise(function (resolve) {
|
|
191
|
-
const loadedCb = function () {
|
|
192
|
-
++fileLoadedLength;
|
|
193
|
-
if (fileLoadedLength < filesLength) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
resolve();
|
|
197
|
-
};
|
|
198
|
-
for (const file of config.files) {
|
|
199
|
-
const mime = tool.getMimeByPath(file);
|
|
200
|
-
if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
|
|
201
|
-
z.getContent('/' + control.name + file, 'string').then(function (fab) {
|
|
202
|
-
if (!fab) {
|
|
203
|
-
loadedCb();
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
files[file] = fab.replace(/^\ufeff/, '');
|
|
207
|
-
loadedCb();
|
|
208
|
-
}).catch(function () {
|
|
209
|
-
loadedCb();
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
z.getContent('/' + control.name + file, 'arraybuffer').then(function (fab) {
|
|
214
|
-
if (!fab) {
|
|
215
|
-
loadedCb();
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
files[file] = new Blob([fab], {
|
|
219
|
-
'type': mime.mime
|
|
220
|
-
});
|
|
221
|
-
loadedCb();
|
|
222
|
-
}).catch(function () {
|
|
223
|
-
loadedCb();
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
controlPkg[control.name] = {
|
|
229
|
-
'type': 'control',
|
|
230
|
-
'config': config,
|
|
231
|
-
'files': files
|
|
232
|
-
};
|
|
233
|
-
controlCb();
|
|
193
|
+
else {
|
|
194
|
+
const fab = yield z.getContent(file.path + file.name, 'arraybuffer');
|
|
195
|
+
if (!fab) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
controlPkg[config.name].files[pre + file.name] = new Blob([fab], {
|
|
199
|
+
'type': mime.mime
|
|
234
200
|
});
|
|
235
|
-
}
|
|
236
|
-
controlCb();
|
|
237
|
-
});
|
|
201
|
+
}
|
|
238
202
|
}
|
|
239
|
-
}
|
|
203
|
+
}
|
|
240
204
|
return controlPkg;
|
|
241
205
|
});
|
|
242
206
|
}
|
|
243
207
|
exports.read = read;
|
|
244
|
-
function init(taskId) {
|
|
208
|
+
function init(taskId, invoke) {
|
|
245
209
|
return __awaiter(this, void 0, void 0, function* () {
|
|
246
210
|
const t = task.list[taskId];
|
|
247
211
|
if (!t) {
|
|
248
|
-
return
|
|
212
|
+
return -1;
|
|
249
213
|
}
|
|
250
|
-
for (let path of t.config.controls) {
|
|
214
|
+
for (let path of t.app.config.controls) {
|
|
251
215
|
if (!path.endsWith('.cgc')) {
|
|
252
216
|
path += '.cgc';
|
|
253
217
|
}
|
|
@@ -276,7 +240,7 @@ function init(taskId) {
|
|
|
276
240
|
};
|
|
277
241
|
t.controls[name].layout = item.files[item.config.layout + '.html'];
|
|
278
242
|
if (t.controls[name].layout === undefined) {
|
|
279
|
-
return
|
|
243
|
+
return -2;
|
|
280
244
|
}
|
|
281
245
|
t.controls[name].layout = t.controls[name].layout.replace(/^(<[a-zA-Z0-9-]+)( |>)/, '$1 data-cg-control-' + name + '$2');
|
|
282
246
|
const style = item.files[item.config.style + '.css'];
|
|
@@ -299,6 +263,9 @@ function init(taskId) {
|
|
|
299
263
|
});
|
|
300
264
|
}
|
|
301
265
|
t.controls[name].layout = tool.eventsAttrWrap(t.controls[name].layout);
|
|
266
|
+
if (t.controls[name].layout.includes('<teleport')) {
|
|
267
|
+
t.controls[name].layout = tool.teleportGlue(t.controls[name].layout, '{{{formId}}}');
|
|
268
|
+
}
|
|
302
269
|
let cls;
|
|
303
270
|
if (item.files[item.config.code + '.js']) {
|
|
304
271
|
item.files['/invoke/clickgo.js'] = `module.exports = invokeClickgo;`;
|
|
@@ -306,7 +273,7 @@ function init(taskId) {
|
|
|
306
273
|
try {
|
|
307
274
|
expo = loader.require(item.config.code, item.files, {
|
|
308
275
|
'dir': '/',
|
|
309
|
-
'invoke':
|
|
276
|
+
'invoke': invoke,
|
|
310
277
|
'preprocess': function (code, path) {
|
|
311
278
|
const exec = /eval\W/.exec(code);
|
|
312
279
|
if (exec) {
|
|
@@ -329,12 +296,12 @@ function init(taskId) {
|
|
|
329
296
|
}
|
|
330
297
|
catch (e) {
|
|
331
298
|
core.trigger('error', taskId, 0, e, e.message + '(-4)');
|
|
332
|
-
return
|
|
299
|
+
return -3;
|
|
333
300
|
}
|
|
334
301
|
if (!(expo === null || expo === void 0 ? void 0 : expo.default)) {
|
|
335
302
|
const msg = '"default" not found on "' + item.config.code + '" of "' + name + '" control.';
|
|
336
303
|
core.trigger('error', taskId, 0, new Error(msg), msg);
|
|
337
|
-
return
|
|
304
|
+
return -4;
|
|
338
305
|
}
|
|
339
306
|
cls = new expo.default();
|
|
340
307
|
}
|
|
@@ -397,13 +364,11 @@ function init(taskId) {
|
|
|
397
364
|
'content': 'Control failed to load.\nTask id: ' + t.id.toString() + '\nPath: ' + path,
|
|
398
365
|
'type': 'danger'
|
|
399
366
|
});
|
|
400
|
-
return
|
|
367
|
+
return -5;
|
|
401
368
|
}
|
|
402
369
|
}
|
|
403
370
|
}
|
|
404
|
-
|
|
405
|
-
delete t.invoke;
|
|
406
|
-
return true;
|
|
371
|
+
return 1;
|
|
407
372
|
});
|
|
408
373
|
}
|
|
409
374
|
exports.init = init;
|
|
@@ -441,16 +406,21 @@ function buildComponents(taskId, formId, path) {
|
|
|
441
406
|
}
|
|
442
407
|
};
|
|
443
408
|
components['cg-' + name] = {
|
|
444
|
-
'template': control.layout,
|
|
409
|
+
'template': control.layout.replace(/{{{formId}}}/g, formId.toString()),
|
|
445
410
|
'props': control.props,
|
|
446
411
|
'data': function () {
|
|
447
|
-
|
|
412
|
+
const data = tool.clone(control.data);
|
|
413
|
+
if (data.props) {
|
|
414
|
+
delete data.props;
|
|
415
|
+
}
|
|
416
|
+
return tool.clone(data);
|
|
448
417
|
},
|
|
449
418
|
'methods': control.methods,
|
|
450
419
|
'computed': computed,
|
|
451
420
|
beforeCreate: control.methods.onBeforeCreate,
|
|
452
421
|
created: function () {
|
|
453
422
|
this.props = this.$props;
|
|
423
|
+
this.slots = this.$slots;
|
|
454
424
|
this.access = tool.clone(control.access);
|
|
455
425
|
this.onCreated();
|
|
456
426
|
},
|
package/dist/lib/control.ts
CHANGED
|
@@ -162,6 +162,45 @@ export abstract class AbstractControl {
|
|
|
162
162
|
/** --- 组件参数,由用户定义重写 --- */
|
|
163
163
|
public readonly props = {};
|
|
164
164
|
|
|
165
|
+
/** --- 组件的子插槽 --- */
|
|
166
|
+
public readonly slots: Record<string, any> = {};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* --- 获取 props 中的 boolean 类型的值 ----
|
|
170
|
+
*/
|
|
171
|
+
public get propBoolean() {
|
|
172
|
+
return (name: keyof this['props']): boolean => {
|
|
173
|
+
return tool.getBoolean((this.props as any)[name]);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* --- 获取 props 中的 number 类型的值 ----
|
|
179
|
+
*/
|
|
180
|
+
public get propNumber() {
|
|
181
|
+
return (name: keyof this['props']): number => {
|
|
182
|
+
return tool.getNumber((this.props as any)[name]);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* --- 获取 props 中的 int 类型的值 ----
|
|
188
|
+
*/
|
|
189
|
+
public get propInt() {
|
|
190
|
+
return (name: keyof this['props']): number => {
|
|
191
|
+
return Math.round(this.propNumber(name));
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* --- 获取 props 中的 array 类型的值 ----
|
|
197
|
+
*/
|
|
198
|
+
public get propArray() {
|
|
199
|
+
return (name: keyof this['props']): any[] => {
|
|
200
|
+
return tool.getArray((this.props as any)[name]);
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
165
204
|
/** --- 获取当前的 HTML DOM --- */
|
|
166
205
|
public get element(): HTMLElement {
|
|
167
206
|
return (this as any).$el;
|
|
@@ -176,36 +215,10 @@ export abstract class AbstractControl {
|
|
|
176
215
|
(this as any).$emit(name, ...v);
|
|
177
216
|
}
|
|
178
217
|
|
|
179
|
-
/**
|
|
180
|
-
* --- 获取目前现存的所有子 slots ---
|
|
181
|
-
*/
|
|
182
|
-
public get slots(): (name?: string) => types.IVNode[] {
|
|
183
|
-
return (name: string = 'default'): types.IVNode[] => {
|
|
184
|
-
const d = (this as any).$slots[name];
|
|
185
|
-
if (!d) {
|
|
186
|
-
return [];
|
|
187
|
-
}
|
|
188
|
-
const slots = [];
|
|
189
|
-
const list = d();
|
|
190
|
-
for (const item of list) {
|
|
191
|
-
if (typeof item.type === 'symbol') {
|
|
192
|
-
// --- 动态的 slot,例如 v-for 产生的 slot ---
|
|
193
|
-
for (const item2 of item.children) {
|
|
194
|
-
slots.push(item2);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
slots.push(item);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return slots;
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
218
|
/**
|
|
206
219
|
* --- 获取上层控件 ---
|
|
207
220
|
*/
|
|
208
|
-
public get parent(): AbstractControl {
|
|
221
|
+
public get parent(): AbstractControl & form.AbstractForm {
|
|
209
222
|
return (this as any).$parent;
|
|
210
223
|
}
|
|
211
224
|
|
|
@@ -274,107 +287,65 @@ export async function read(blob: Blob): Promise<false | types.TControlPackage> {
|
|
|
274
287
|
}
|
|
275
288
|
/** --- 要返回的 control pkg 对象 --- */
|
|
276
289
|
const controlPkg: types.TControlPackage = {};
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
|
|
291
|
+
// --- 读取包 ---
|
|
292
|
+
const list = z.readDir('/');
|
|
293
|
+
for (const sub of list) {
|
|
294
|
+
if (sub.isFile) {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const configContent = await z.getContent('/' + sub.name + '/config.json');
|
|
298
|
+
if (!configContent) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
// --- 读取本条控件内容 ---
|
|
302
|
+
const config: types.IControlConfig = JSON.parse(configContent);
|
|
303
|
+
controlPkg[config.name] = {
|
|
304
|
+
'type': 'control',
|
|
305
|
+
'config': config,
|
|
306
|
+
'files': {}
|
|
291
307
|
};
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
308
|
+
// --- 读取控件包文件 ---
|
|
309
|
+
const list = z.readDir('/' + sub.name + '/', {
|
|
310
|
+
'hasChildren': true
|
|
311
|
+
});
|
|
312
|
+
for (const file of list) {
|
|
313
|
+
const pre = file.path.slice(config.name.length + 1);
|
|
314
|
+
const mime = tool.getMimeByPath(file.name);
|
|
315
|
+
if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
|
|
316
|
+
const fab = await z.getContent(file.path + file.name, 'string');
|
|
317
|
+
if (!fab) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
controlPkg[config.name].files[pre + file.name] = fab.replace(/^\ufeff/, '');
|
|
296
321
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
322
|
+
else {
|
|
323
|
+
const fab = await z.getContent(file.path + file.name, 'arraybuffer');
|
|
324
|
+
if (!fab) {
|
|
325
|
+
continue;
|
|
301
326
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
// --- 开始读取文件 ---
|
|
305
|
-
const files: Record<string, Blob | string> = {};
|
|
306
|
-
/** --- 配置文件中的文件数量总数 --- */
|
|
307
|
-
const filesLength = Object.keys(config.files).length;
|
|
308
|
-
/** --- 已处理的文件数 --- */
|
|
309
|
-
let fileLoadedLength = 0;
|
|
310
|
-
// --- 开始加载子控件中的文件 ---
|
|
311
|
-
await new Promise<void>(function(resolve) {
|
|
312
|
-
/** --- 一个文件加载完后就执行一次 --- */
|
|
313
|
-
const loadedCb = function(): void {
|
|
314
|
-
++fileLoadedLength;
|
|
315
|
-
if (fileLoadedLength < filesLength) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
// --- 加载完毕 ---
|
|
319
|
-
resolve();
|
|
320
|
-
};
|
|
321
|
-
for (const file of config.files) {
|
|
322
|
-
const mime = tool.getMimeByPath(file);
|
|
323
|
-
if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
|
|
324
|
-
z.getContent('/' + control.name + file, 'string').then(function(fab) {
|
|
325
|
-
if (!fab) {
|
|
326
|
-
loadedCb();
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
// --- 去除 BOM ---
|
|
330
|
-
files[file] = fab.replace(/^\ufeff/, '');
|
|
331
|
-
loadedCb();
|
|
332
|
-
}).catch(function() {
|
|
333
|
-
loadedCb();
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
z.getContent('/' + control.name + file, 'arraybuffer').then(function(fab) {
|
|
338
|
-
if (!fab) {
|
|
339
|
-
loadedCb();
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
files[file] = new Blob([fab], {
|
|
343
|
-
'type': mime.mime
|
|
344
|
-
});
|
|
345
|
-
loadedCb();
|
|
346
|
-
}).catch(function() {
|
|
347
|
-
loadedCb();
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
327
|
+
controlPkg[config.name].files[pre + file.name] = new Blob([fab], {
|
|
328
|
+
'type': mime.mime
|
|
351
329
|
});
|
|
352
|
-
|
|
353
|
-
'type': 'control',
|
|
354
|
-
'config': config,
|
|
355
|
-
'files': files
|
|
356
|
-
};
|
|
357
|
-
controlCb();
|
|
358
|
-
}).catch(function() {
|
|
359
|
-
controlCb();
|
|
360
|
-
});
|
|
330
|
+
}
|
|
361
331
|
}
|
|
362
|
-
}
|
|
332
|
+
}
|
|
363
333
|
return controlPkg;
|
|
364
334
|
}
|
|
365
335
|
|
|
366
336
|
/**
|
|
367
|
-
* --- 任务创建过程中,需要对 control
|
|
337
|
+
* --- 任务创建过程中,需要对 control 进行先行初始化,并将样式表插入到实际的任务 DOM 中 ---
|
|
368
338
|
* @param taskId 要处理的任务 ID
|
|
369
339
|
*/
|
|
370
340
|
export async function init(
|
|
371
|
-
taskId: number
|
|
372
|
-
|
|
341
|
+
taskId: number,
|
|
342
|
+
invoke: Record<string, any>
|
|
343
|
+
): Promise<number> {
|
|
373
344
|
const t = task.list[taskId];
|
|
374
345
|
if (!t) {
|
|
375
|
-
return
|
|
346
|
+
return -1;
|
|
376
347
|
}
|
|
377
|
-
for (let path of t.config.controls) {
|
|
348
|
+
for (let path of t.app.config.controls) {
|
|
378
349
|
if (!path.endsWith('.cgc')) {
|
|
379
350
|
path += '.cgc';
|
|
380
351
|
}
|
|
@@ -409,7 +380,7 @@ export async function init(
|
|
|
409
380
|
t.controls[name].layout = item.files[item.config.layout + '.html'] as string;
|
|
410
381
|
if (t.controls[name].layout === undefined) {
|
|
411
382
|
// --- 控件没有 layout 那肯定不能用 ---
|
|
412
|
-
return
|
|
383
|
+
return -2;
|
|
413
384
|
}
|
|
414
385
|
// --- 给 layout 增加 data-cg-control-xxx ---
|
|
415
386
|
t.controls[name].layout = t.controls[name].layout.replace(/^(<[a-zA-Z0-9-]+)( |>)/, '$1 data-cg-control-' + name + '$2');
|
|
@@ -440,6 +411,10 @@ export async function init(
|
|
|
440
411
|
}
|
|
441
412
|
// --- 给 event 增加包裹 ---
|
|
442
413
|
t.controls[name].layout = tool.eventsAttrWrap(t.controls[name].layout);
|
|
414
|
+
// --- 给 teleport 做处理 ---
|
|
415
|
+
if (t.controls[name].layout.includes('<teleport')) {
|
|
416
|
+
t.controls[name].layout = tool.teleportGlue(t.controls[name].layout, '{{{formId}}}');
|
|
417
|
+
}
|
|
443
418
|
// --- 检测是否有 js ---
|
|
444
419
|
let cls: any;
|
|
445
420
|
if (item.files[item.config.code + '.js']) {
|
|
@@ -448,7 +423,7 @@ export async function init(
|
|
|
448
423
|
try {
|
|
449
424
|
expo = loader.require(item.config.code, item.files, {
|
|
450
425
|
'dir': '/',
|
|
451
|
-
'invoke':
|
|
426
|
+
'invoke': invoke,
|
|
452
427
|
'preprocess': function(code: string, path: string): string {
|
|
453
428
|
// --- 屏蔽 eval 函数 ---
|
|
454
429
|
const exec = /eval\W/.exec(code);
|
|
@@ -473,12 +448,12 @@ export async function init(
|
|
|
473
448
|
}
|
|
474
449
|
catch (e: any) {
|
|
475
450
|
core.trigger('error', taskId, 0, e, e.message + '(-4)');
|
|
476
|
-
return
|
|
451
|
+
return -3;
|
|
477
452
|
}
|
|
478
453
|
if (!expo?.default) {
|
|
479
454
|
const msg = '"default" not found on "' + item.config.code + '" of "' + name + '" control.';
|
|
480
455
|
core.trigger('error', taskId, 0, new Error(msg), msg);
|
|
481
|
-
return
|
|
456
|
+
return -4;
|
|
482
457
|
}
|
|
483
458
|
cls = new expo.default();
|
|
484
459
|
}
|
|
@@ -501,6 +476,7 @@ export async function init(
|
|
|
501
476
|
const cdata = Object.entries(cls);
|
|
502
477
|
for (const item of cdata) {
|
|
503
478
|
if (item[0] === 'access') {
|
|
479
|
+
// --- access 属性不放在 data 当中 ---
|
|
504
480
|
t.controls[name].access = item[1] as any;
|
|
505
481
|
continue;
|
|
506
482
|
}
|
|
@@ -543,13 +519,11 @@ export async function init(
|
|
|
543
519
|
'content': 'Control failed to load.\nTask id: ' + t.id.toString() + '\nPath: ' + path,
|
|
544
520
|
'type': 'danger'
|
|
545
521
|
});
|
|
546
|
-
return
|
|
522
|
+
return -5;
|
|
547
523
|
}
|
|
548
524
|
}
|
|
549
525
|
}
|
|
550
|
-
|
|
551
|
-
delete t.invoke;
|
|
552
|
-
return true;
|
|
526
|
+
return 1;
|
|
553
527
|
}
|
|
554
528
|
|
|
555
529
|
/**
|
|
@@ -597,13 +571,16 @@ export function buildComponents(
|
|
|
597
571
|
});
|
|
598
572
|
}
|
|
599
573
|
};
|
|
600
|
-
// --- 为什么要用 ?.(), 因为有些控件是没有 js 文件的,没有 Control 类继承 ---
|
|
601
574
|
components['cg-' + name] = {
|
|
602
|
-
'template': control.layout,
|
|
575
|
+
'template': control.layout.replace(/{{{formId}}}/g, formId.toString()),
|
|
603
576
|
'props': control.props,
|
|
604
577
|
|
|
605
578
|
'data': function() {
|
|
606
|
-
|
|
579
|
+
const data = tool.clone(control.data);
|
|
580
|
+
if (data.props) {
|
|
581
|
+
delete data.props;
|
|
582
|
+
}
|
|
583
|
+
return tool.clone(data);
|
|
607
584
|
},
|
|
608
585
|
'methods': control.methods,
|
|
609
586
|
'computed': computed,
|
|
@@ -611,6 +588,7 @@ export function buildComponents(
|
|
|
611
588
|
beforeCreate: control.methods.onBeforeCreate,
|
|
612
589
|
created: function() {
|
|
613
590
|
this.props = this.$props;
|
|
591
|
+
this.slots = this.$slots;
|
|
614
592
|
this.access = tool.clone(control.access);
|
|
615
593
|
this.onCreated();
|
|
616
594
|
},
|