clickgo 3.0.0-dev
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/LICENSE +201 -0
- package/README.md +75 -0
- package/dist/app/demo/config.json +106 -0
- package/dist/app/demo/form/control/block/block.css +1 -0
- package/dist/app/demo/form/control/block/block.scss +17 -0
- package/dist/app/demo/form/control/block/block.xml +7 -0
- package/dist/app/demo/form/control/button/button.css +1 -0
- package/dist/app/demo/form/control/button/button.js +27 -0
- package/dist/app/demo/form/control/button/button.scss +18 -0
- package/dist/app/demo/form/control/button/button.xml +126 -0
- package/dist/app/demo/form/control/check/check.js +12 -0
- package/dist/app/demo/form/control/check/check.xml +13 -0
- package/dist/app/demo/form/control/dialog/dialog.js +8 -0
- package/dist/app/demo/form/control/dialog/dialog.xml +26 -0
- package/dist/app/demo/form/control/file/file.js +23 -0
- package/dist/app/demo/form/control/file/file.xml +25 -0
- package/dist/app/demo/form/control/form/form.css +1 -0
- package/dist/app/demo/form/control/form/form.js +38 -0
- package/dist/app/demo/form/control/form/form.scss +9 -0
- package/dist/app/demo/form/control/form/form.xml +28 -0
- package/dist/app/demo/form/control/greatview/greatview.css +1 -0
- package/dist/app/demo/form/control/greatview/greatview.js +92 -0
- package/dist/app/demo/form/control/greatview/greatview.scss +22 -0
- package/dist/app/demo/form/control/greatview/greatview.xml +89 -0
- package/dist/app/demo/form/control/img/img.xml +16 -0
- package/dist/app/demo/form/control/label/label.xml +11 -0
- package/dist/app/demo/form/control/list/list.css +1 -0
- package/dist/app/demo/form/control/list/list.js +194 -0
- package/dist/app/demo/form/control/list/list.scss +7 -0
- package/dist/app/demo/form/control/list/list.xml +91 -0
- package/dist/app/demo/form/control/loading/loading.xml +8 -0
- package/dist/app/demo/form/control/marquee/marquee.js +30 -0
- package/dist/app/demo/form/control/marquee/marquee.xml +36 -0
- package/dist/app/demo/form/control/menu/menu.js +8 -0
- package/dist/app/demo/form/control/menu/menu.xml +122 -0
- package/dist/app/demo/form/control/monaco/monaco.js +113 -0
- package/dist/app/demo/form/control/monaco/monaco.xml +27 -0
- package/dist/app/demo/form/control/overflow/overflow.css +1 -0
- package/dist/app/demo/form/control/overflow/overflow.js +70 -0
- package/dist/app/demo/form/control/overflow/overflow.scss +18 -0
- package/dist/app/demo/form/control/overflow/overflow.xml +98 -0
- package/dist/app/demo/form/control/property/property.js +129 -0
- package/dist/app/demo/form/control/property/property.xml +6 -0
- package/dist/app/demo/form/control/radio/radio.js +7 -0
- package/dist/app/demo/form/control/radio/radio.xml +12 -0
- package/dist/app/demo/form/control/scroll/scroll.js +14 -0
- package/dist/app/demo/form/control/scroll/scroll.xml +35 -0
- package/dist/app/demo/form/control/select/select.js +91 -0
- package/dist/app/demo/form/control/select/select.xml +74 -0
- package/dist/app/demo/form/control/tab/tab.js +75 -0
- package/dist/app/demo/form/control/tab/tab.xml +22 -0
- package/dist/app/demo/form/control/text/text.js +53 -0
- package/dist/app/demo/form/control/text/text.xml +37 -0
- package/dist/app/demo/form/control/view/view.css +1 -0
- package/dist/app/demo/form/control/view/view.js +73 -0
- package/dist/app/demo/form/control/view/view.scss +18 -0
- package/dist/app/demo/form/control/view/view.xml +94 -0
- package/dist/app/demo/form/event/form/form.css +1 -0
- package/dist/app/demo/form/event/form/form.js +129 -0
- package/dist/app/demo/form/event/form/form.scss +24 -0
- package/dist/app/demo/form/event/form/form.xml +16 -0
- package/dist/app/demo/form/event/screen/screen.js +51 -0
- package/dist/app/demo/form/event/screen/screen.xml +9 -0
- package/dist/app/demo/form/event/task/task.js +78 -0
- package/dist/app/demo/form/event/task/task.xml +20 -0
- package/dist/app/demo/form/main.css +1 -0
- package/dist/app/demo/form/main.js +25 -0
- package/dist/app/demo/form/main.scss +9 -0
- package/dist/app/demo/form/main.xml +49 -0
- package/dist/app/demo/form/method/core/core.js +25 -0
- package/dist/app/demo/form/method/core/core.xml +7 -0
- package/dist/app/demo/form/method/dom/dom.css +1 -0
- package/dist/app/demo/form/method/dom/dom.js +163 -0
- package/dist/app/demo/form/method/dom/dom.scss +10 -0
- package/dist/app/demo/form/method/dom/dom.xml +55 -0
- package/dist/app/demo/form/method/form/form.css +1 -0
- package/dist/app/demo/form/method/form/form.js +217 -0
- package/dist/app/demo/form/method/form/form.scss +3 -0
- package/dist/app/demo/form/method/form/form.xml +56 -0
- package/dist/app/demo/form/method/form/test.xml +5 -0
- package/dist/app/demo/form/method/fs/fs.js +88 -0
- package/dist/app/demo/form/method/fs/fs.xml +8 -0
- package/dist/app/demo/form/method/fs/text.js +15 -0
- package/dist/app/demo/form/method/fs/text.xml +3 -0
- package/dist/app/demo/form/method/task/locale1.json +3 -0
- package/dist/app/demo/form/method/task/locale2.json +3 -0
- package/dist/app/demo/form/method/task/task.js +153 -0
- package/dist/app/demo/form/method/task/task.xml +57 -0
- package/dist/app/demo/form/method/theme/theme.js +74 -0
- package/dist/app/demo/form/method/theme/theme.xml +9 -0
- package/dist/app/demo/form/method/tool/tool.js +64 -0
- package/dist/app/demo/form/method/tool/tool.xml +26 -0
- package/dist/app/demo/form/method/zip/zip.js +99 -0
- package/dist/app/demo/form/method/zip/zip.xml +12 -0
- package/dist/app/demo/global.css +3 -0
- package/dist/app/demo/res/icon.svg +1 -0
- package/dist/app/demo/res/img.jpg +0 -0
- package/dist/app/demo/res/r-1.svg +1 -0
- package/dist/app/demo/res/r-2.svg +1 -0
- package/dist/app/demo/res/sql.svg +1 -0
- package/dist/app/demo/res/txt.svg +1 -0
- package/dist/app/demo/res/zip.svg +1 -0
- package/dist/app/task/config.json +29 -0
- package/dist/app/task/form/bar/bar.js +299 -0
- package/dist/app/task/form/bar/bar.xml +47 -0
- package/dist/app/task/form/desktop/desktop.xml +1 -0
- package/dist/app/task/locale/en.json +11 -0
- package/dist/app/task/locale/ja.json +11 -0
- package/dist/app/task/locale/sc.json +11 -0
- package/dist/app/task/locale/tc.json +11 -0
- package/dist/clickgo.js +41 -0
- package/dist/clickgo.ts +51 -0
- 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 -0
- package/dist/icon.png +0 -0
- package/dist/index.js +88 -0
- package/dist/index.ts +92 -0
- package/dist/lib/control.js +365 -0
- package/dist/lib/control.ts +428 -0
- package/dist/lib/core.js +668 -0
- package/dist/lib/core.ts +732 -0
- package/dist/lib/dom.js +1471 -0
- package/dist/lib/dom.ts +1785 -0
- package/dist/lib/form.js +2101 -0
- package/dist/lib/form.ts +2496 -0
- package/dist/lib/fs.js +849 -0
- package/dist/lib/fs.ts +995 -0
- package/dist/lib/native.js +138 -0
- package/dist/lib/native.ts +219 -0
- package/dist/lib/task.js +686 -0
- package/dist/lib/task.ts +842 -0
- package/dist/lib/theme.js +159 -0
- package/dist/lib/theme.ts +196 -0
- package/dist/lib/tool.js +501 -0
- package/dist/lib/tool.ts +620 -0
- package/dist/lib/zip.js +352 -0
- package/dist/lib/zip.ts +434 -0
- package/dist/theme/familiar.cgt +0 -0
- package/package.json +27 -0
- package/types/dev.d.ts +30 -0
- package/types/index.d.ts +673 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2022 Han Guoshuai <zohegs@gmail.com>
|
|
3
|
+
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import * as types from '../../types';
|
|
17
|
+
import * as core from './core';
|
|
18
|
+
import * as zip from './zip';
|
|
19
|
+
import * as tool from './tool';
|
|
20
|
+
import * as task from './task';
|
|
21
|
+
import * as dom from './dom';
|
|
22
|
+
import * as form from './form';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* --- 将 cgc 文件 blob 转换为 control 对象 ---
|
|
26
|
+
* @param blob 文件 blob
|
|
27
|
+
*/
|
|
28
|
+
export async function read(blob: Blob): Promise<false | types.TControl> {
|
|
29
|
+
const z = await zip.get(blob);
|
|
30
|
+
if (!z) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/** --- 要返回的 control pkg 对象 --- */
|
|
34
|
+
const controlPkg: types.TControl = {};
|
|
35
|
+
/** --- 已处理的控件 --- */
|
|
36
|
+
let controlProcessed = 0;
|
|
37
|
+
/** --- 控件包中的控件根目录列表 --- */
|
|
38
|
+
const controls = z.readDir();
|
|
39
|
+
// --- 开始处理 ---
|
|
40
|
+
await new Promise<void>(function(resolve) {
|
|
41
|
+
/** --- 一个 control item 处理完后就执行一次 --- */
|
|
42
|
+
const controlCb = function(): void {
|
|
43
|
+
++controlProcessed;
|
|
44
|
+
if (controlProcessed < controls.length) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// --- 加载完毕 ---
|
|
48
|
+
resolve();
|
|
49
|
+
};
|
|
50
|
+
for (const control of controls) {
|
|
51
|
+
if (control.isFile) {
|
|
52
|
+
controlCb();
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
z.getContent('/' + control.name + '/config.json').then(async function(configContent) {
|
|
56
|
+
if (!configContent) {
|
|
57
|
+
controlCb();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
/** --- 子控件的配置文件 --- */
|
|
61
|
+
const config: types.IControlConfig = JSON.parse(configContent);
|
|
62
|
+
// --- 开始读取文件 ---
|
|
63
|
+
const files: Record<string, Blob | string> = {};
|
|
64
|
+
/** --- 配置文件中的文件数量总数 --- */
|
|
65
|
+
const filesLength = Object.keys(config.files).length;
|
|
66
|
+
/** --- 已处理的文件数 --- */
|
|
67
|
+
let fileLoadedLength = 0;
|
|
68
|
+
// --- 开始加载子控件中的文件 ---
|
|
69
|
+
await new Promise<void>(function(resolve) {
|
|
70
|
+
/** --- 一个文件加载完后就执行一次 --- */
|
|
71
|
+
const loadedCb = function(): void {
|
|
72
|
+
++fileLoadedLength;
|
|
73
|
+
if (fileLoadedLength < filesLength) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// --- 加载完毕 ---
|
|
77
|
+
resolve();
|
|
78
|
+
};
|
|
79
|
+
for (const file of config.files) {
|
|
80
|
+
const mime = tool.getMimeByPath(file);
|
|
81
|
+
if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
|
|
82
|
+
z.getContent('/' + control.name + file, 'string').then(function(fab) {
|
|
83
|
+
if (!fab) {
|
|
84
|
+
loadedCb();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// --- 去除 BOM ---
|
|
88
|
+
files[file] = fab.replace(/^\ufeff/, '');
|
|
89
|
+
loadedCb();
|
|
90
|
+
}).catch(function() {
|
|
91
|
+
loadedCb();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
z.getContent('/' + control.name + file, 'arraybuffer').then(function(fab) {
|
|
96
|
+
if (!fab) {
|
|
97
|
+
loadedCb();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
files[file] = new Blob([fab], {
|
|
101
|
+
'type': mime.mime
|
|
102
|
+
});
|
|
103
|
+
loadedCb();
|
|
104
|
+
}).catch(function() {
|
|
105
|
+
loadedCb();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
controlPkg[control.name] = {
|
|
111
|
+
'type': 'control',
|
|
112
|
+
'config': config,
|
|
113
|
+
'files': files
|
|
114
|
+
};
|
|
115
|
+
controlCb();
|
|
116
|
+
}).catch(function() {
|
|
117
|
+
controlCb();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return controlPkg;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* --- 初始化获取新窗体的控件 component ---
|
|
126
|
+
* @param taskId 任务 id
|
|
127
|
+
* @param formId 窗体 id
|
|
128
|
+
* @param path 窗体路径(包内路径)
|
|
129
|
+
* @param preprocess 代码检测函数
|
|
130
|
+
* @param invoke 注入对象
|
|
131
|
+
*/
|
|
132
|
+
export async function init(
|
|
133
|
+
taskId: number,
|
|
134
|
+
formId: number,
|
|
135
|
+
path: string,
|
|
136
|
+
preprocess?: (code: string, path: string) => string,
|
|
137
|
+
invoke?: Record<string, any>
|
|
138
|
+
): Promise<false | Record<string, any>> {
|
|
139
|
+
const t = task.list[taskId];
|
|
140
|
+
if (!t) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
/** --- 要返回的控件列表 --- */
|
|
144
|
+
const components: Record<string, any> = {};
|
|
145
|
+
for (let cpath of t.app.config.controls) {
|
|
146
|
+
if (!cpath.endsWith('.cgc')) {
|
|
147
|
+
cpath += '.cgc';
|
|
148
|
+
}
|
|
149
|
+
/** --- 当前的控件包 --- */
|
|
150
|
+
const control = t.controls.loaded[cpath];
|
|
151
|
+
if (!control) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
for (const name in control) {
|
|
155
|
+
// --- 创建新的 ---
|
|
156
|
+
const item = control[name];
|
|
157
|
+
// --- 准备相关变量 ---
|
|
158
|
+
let props: any = {};
|
|
159
|
+
let data: any = {};
|
|
160
|
+
let methods: any = {};
|
|
161
|
+
let computed: any = {};
|
|
162
|
+
let watch: any = {};
|
|
163
|
+
let beforeCreate: (() => void) | undefined = undefined;
|
|
164
|
+
let created: (() => void) | undefined = undefined;
|
|
165
|
+
let beforeMount: (() => void) | undefined = undefined;
|
|
166
|
+
let mounted: (() => void) | undefined = undefined;
|
|
167
|
+
let beforeUpdate: (() => void) | undefined = undefined;
|
|
168
|
+
let updated: (() => void) | undefined = undefined;
|
|
169
|
+
let beforeUnmount: (() => void) | undefined = undefined;
|
|
170
|
+
let unmounted: (() => void) | undefined = undefined;
|
|
171
|
+
// --- 检测 layout and style ---
|
|
172
|
+
let layout = '', prep = '';
|
|
173
|
+
if (t.controls.layout[name]) {
|
|
174
|
+
// --- layout 和 style 已经加载过,无需再次解释和加载 ---
|
|
175
|
+
layout = t.controls.layout[name];
|
|
176
|
+
prep = t.controls.prep[name];
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// --- 要创建的控件的 layout ---
|
|
180
|
+
layout = item.files[item.config.layout + '.html'] as string;
|
|
181
|
+
if (layout === undefined) {
|
|
182
|
+
// --- 控件没有 layout 那肯定不能用 ---
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
// --- 给 layout 增加 data-cg-control-xxx ---
|
|
186
|
+
layout = layout.replace(/^(<[a-zA-Z0-9-]+)( |>)/, '$1 data-cg-control-' + name + '$2');
|
|
187
|
+
/** --- 样式表 --- */
|
|
188
|
+
const style = item.files[item.config.style + '.css'] as string;
|
|
189
|
+
if (style) {
|
|
190
|
+
// --- 有样式表,给样式表内的项增加唯一前缀(scope) ---
|
|
191
|
+
const r = tool.stylePrepend(style);
|
|
192
|
+
prep = r.prep;
|
|
193
|
+
dom.pushStyle(t.id, await tool.styleUrl2DataUrl(item.config.style, r.style, item.files), 'control', name);
|
|
194
|
+
}
|
|
195
|
+
// --- 给控件的 layout 的 class 增加前置 ---
|
|
196
|
+
const prepList = [
|
|
197
|
+
'cg-theme-task' + t.id.toString() + '-' + name + '_'
|
|
198
|
+
];
|
|
199
|
+
if (prep !== '') {
|
|
200
|
+
prepList.push(prep);
|
|
201
|
+
}
|
|
202
|
+
// --- 增加 class 为 tag-xxx ---
|
|
203
|
+
layout = tool.layoutAddTagClassAndReTagName(layout, false);
|
|
204
|
+
// --- 给 layout 的 class 增加前置 ---
|
|
205
|
+
layout = tool.layoutClassPrepend(layout, prepList);
|
|
206
|
+
// --- 给 cg 对象增加 :cg-focus 传递 ---
|
|
207
|
+
if (layout.includes('<cg-')) {
|
|
208
|
+
layout = tool.layoutInsertAttr(layout, ':cg-focus=\'cgFocus\'', {
|
|
209
|
+
'include': [/^cg-.+/]
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// --- 给 event 增加包裹 ---
|
|
213
|
+
layout = tool.eventsAttrWrap(layout);
|
|
214
|
+
// --- 给 touchstart 增加 .passive 防止 [Violation] Added non-passive event listener to a scroll-blocking ---
|
|
215
|
+
/*
|
|
216
|
+
layout = layout.replace(/@(touchstart|touchmove|wheel)=/g, '@$1.passive=');
|
|
217
|
+
layout = layout.replace(/@(touchstart|touchmove|wheel)\.not=/g, '@$1=');
|
|
218
|
+
*/
|
|
219
|
+
t.controls.layout[name] = layout;
|
|
220
|
+
t.controls.prep[name] = prep;
|
|
221
|
+
}
|
|
222
|
+
// --- 检测是否有 js ---
|
|
223
|
+
if (item.files[item.config.code + '.js']) {
|
|
224
|
+
item.files['/invoke/clickgo.js'] = `module.exports = invokeClickgo;`;
|
|
225
|
+
const expo = loader.require(item.config.code, item.files, {
|
|
226
|
+
'dir': '/',
|
|
227
|
+
'invoke': invoke,
|
|
228
|
+
'preprocess': preprocess,
|
|
229
|
+
'map': {
|
|
230
|
+
'clickgo': '/invoke/clickgo'
|
|
231
|
+
}
|
|
232
|
+
})[0];
|
|
233
|
+
if (expo) {
|
|
234
|
+
props = expo.props || {};
|
|
235
|
+
data = expo.data || {};
|
|
236
|
+
methods = expo.methods || {};
|
|
237
|
+
computed = expo.computed || {};
|
|
238
|
+
watch = expo.watch || {};
|
|
239
|
+
beforeCreate = expo.beforeCreate;
|
|
240
|
+
created = expo.created;
|
|
241
|
+
beforeMount = expo.beforeMount;
|
|
242
|
+
mounted = expo.mounted;
|
|
243
|
+
beforeUpdate = expo.beforeUpdate;
|
|
244
|
+
updated = expo.updated;
|
|
245
|
+
beforeUnmount = expo.beforeUnmount;
|
|
246
|
+
unmounted = expo.unmounted;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// --- 组成 props ---
|
|
250
|
+
props.cgFocus = {
|
|
251
|
+
'default': false
|
|
252
|
+
};
|
|
253
|
+
// --- 组成 data ---
|
|
254
|
+
computed.taskId = {
|
|
255
|
+
get: function(): number {
|
|
256
|
+
return taskId;
|
|
257
|
+
},
|
|
258
|
+
set: function(): void {
|
|
259
|
+
form.notify({
|
|
260
|
+
'title': 'Error',
|
|
261
|
+
'content': `The control tries to modify the system variable "taskId".\nPath: ${this.cgPath}\nControl: ${name}`,
|
|
262
|
+
'type': 'danger'
|
|
263
|
+
});
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
computed.controlName = {
|
|
268
|
+
get: function(): string {
|
|
269
|
+
return name;
|
|
270
|
+
},
|
|
271
|
+
set: function(): void {
|
|
272
|
+
form.notify({
|
|
273
|
+
'title': 'Error',
|
|
274
|
+
'content': `The control tries to modify the system variable "controlName".\nPath: ${this.cgPath}\nControl: ${name}`,
|
|
275
|
+
'type': 'danger'
|
|
276
|
+
});
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
computed.cgPrep = {
|
|
281
|
+
get: function(): string {
|
|
282
|
+
return prep;
|
|
283
|
+
},
|
|
284
|
+
set: function(): void {
|
|
285
|
+
form.notify({
|
|
286
|
+
'title': 'Error',
|
|
287
|
+
'content': `The control tries to modify the system variable "cgPrep".\nPath: ${this.cgPath}\nControl: ${name}`,
|
|
288
|
+
'type': 'danger'
|
|
289
|
+
});
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
// --- 获取目前现存的子 slots ---
|
|
294
|
+
computed.cgSlots = function(this: types.IVControl): (name?: string) => types.IVueVNode[] {
|
|
295
|
+
return (name: string = 'default'): types.IVueVNode[] => {
|
|
296
|
+
const d = this.$slots[name];
|
|
297
|
+
if (!d) {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
const slots = [];
|
|
301
|
+
const list = d();
|
|
302
|
+
for (const item of list) {
|
|
303
|
+
if (typeof item.type === 'symbol') {
|
|
304
|
+
// --- 动态的 slot,例如 v-for 产生的 slot ---
|
|
305
|
+
for (const item2 of item.children) {
|
|
306
|
+
slots.push(item2);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
slots.push(item);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return slots;
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
// --- 预设 computed ---
|
|
317
|
+
computed.cgLocale = function(this: types.IVControl): string {
|
|
318
|
+
if (task.list[this.taskId].locale.lang === '') {
|
|
319
|
+
return core.config.locale;
|
|
320
|
+
}
|
|
321
|
+
return task.list[this.taskId].locale.lang;
|
|
322
|
+
};
|
|
323
|
+
// --- 获取语言 ---
|
|
324
|
+
computed.l = function(this: types.IVControl): (
|
|
325
|
+
key: string,
|
|
326
|
+
data?: Record<string, Record<string, string>>
|
|
327
|
+
) => string {
|
|
328
|
+
return (key: string, data?: Record<string, Record<string, string>>): string => {
|
|
329
|
+
if (data) {
|
|
330
|
+
return data[this.cgLocale]?.[key] ?? data['en'][key] ?? 'LocaleError';
|
|
331
|
+
}
|
|
332
|
+
else if (this.localeData) {
|
|
333
|
+
return this.localeData[this.cgLocale]?.[key] ?? this.localeData['en'][key] ?? 'LocaleError';
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
return 'LocaleError';
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
// --- 根据 control name 查询上级序列 ---
|
|
341
|
+
computed.cgParentByName = function(this: types.IVControl): (
|
|
342
|
+
controlName: string
|
|
343
|
+
) => types.IVControl | null {
|
|
344
|
+
return (controlName: string): types.IVControl | null => {
|
|
345
|
+
let parent = this.$parent;
|
|
346
|
+
while (true) {
|
|
347
|
+
if (!parent) {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
if (parent.controlName === controlName) {
|
|
351
|
+
return parent;
|
|
352
|
+
}
|
|
353
|
+
parent = parent.$parent;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
};
|
|
357
|
+
computed.formId = {
|
|
358
|
+
get: function(): number {
|
|
359
|
+
return formId;
|
|
360
|
+
},
|
|
361
|
+
set: function(): void {
|
|
362
|
+
form.notify({
|
|
363
|
+
'title': 'Error',
|
|
364
|
+
'content': `The control tries to modify the system variable "formId".\nPath: ${this.cgPath}\nControl: ${name}`,
|
|
365
|
+
'type': 'danger'
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
computed.cgPath = {
|
|
370
|
+
get: function(): string {
|
|
371
|
+
return path;
|
|
372
|
+
},
|
|
373
|
+
set: function(): void {
|
|
374
|
+
form.notify({
|
|
375
|
+
'title': 'Error',
|
|
376
|
+
'content': `The control tries to modify the system variable "cgPath".\nPath: ${this.cgPath}\nControl: ${name}`,
|
|
377
|
+
'type': 'danger'
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
// --- layout 中 :class 的转义 ---
|
|
382
|
+
methods.cgClassPrepend = function(this: types.IVControl, cla: any): string {
|
|
383
|
+
if (typeof cla !== 'string') {
|
|
384
|
+
return cla;
|
|
385
|
+
}
|
|
386
|
+
return `cg-theme-task${this.taskId}-${this.controlName}_${cla}${this.cgPrep ? (' ' + this.cgPrep + cla) : ''}`;
|
|
387
|
+
};
|
|
388
|
+
// --- 判断当前事件可否执行 ---
|
|
389
|
+
methods.cgAllowEvent = function(
|
|
390
|
+
this: types.IVControl,
|
|
391
|
+
e: MouseEvent | TouchEvent | KeyboardEvent
|
|
392
|
+
): boolean {
|
|
393
|
+
return dom.allowEvent(e);
|
|
394
|
+
};
|
|
395
|
+
components['cg-' + name] = {
|
|
396
|
+
'template': layout,
|
|
397
|
+
'props': props,
|
|
398
|
+
'data': function() {
|
|
399
|
+
return tool.clone(data);
|
|
400
|
+
},
|
|
401
|
+
'methods': methods,
|
|
402
|
+
'computed': computed,
|
|
403
|
+
'watch': watch,
|
|
404
|
+
|
|
405
|
+
'beforeCreate': beforeCreate,
|
|
406
|
+
'created': created,
|
|
407
|
+
'beforeMount': beforeMount,
|
|
408
|
+
'mounted': async function(this: types.IVControl) {
|
|
409
|
+
await this.$nextTick();
|
|
410
|
+
mounted?.call(this);
|
|
411
|
+
},
|
|
412
|
+
'beforeUpdate': beforeUpdate,
|
|
413
|
+
'updated': async function(this: types.IVControl) {
|
|
414
|
+
await this.$nextTick();
|
|
415
|
+
updated?.call(this);
|
|
416
|
+
},
|
|
417
|
+
'beforeUnmount': function(this: types.IVControl) {
|
|
418
|
+
beforeUnmount?.call(this);
|
|
419
|
+
},
|
|
420
|
+
'unmounted': async function(this: types.IVControl) {
|
|
421
|
+
await this.$nextTick();
|
|
422
|
+
unmounted?.call(this);
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return components;
|
|
428
|
+
}
|