cuxml 2.0.0 → 2.1.0
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/converter.js +13 -0
- package/src/templates.js +28 -8
package/package.json
CHANGED
package/src/converter.js
CHANGED
|
@@ -205,6 +205,19 @@ class XMLConverter {
|
|
|
205
205
|
fs.appendFileSync(outputPath, func.code + '\n', 'utf-8');
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
|
+
|
|
209
|
+
// 添加导出语句
|
|
210
|
+
const exportStatement = `
|
|
211
|
+
// 导出所有回调函数(如果不需要导出,可以注释掉以下语句)
|
|
212
|
+
module.exports = {
|
|
213
|
+
${functions.map(func => ` ${func.name},`).join('\n')}
|
|
214
|
+
};
|
|
215
|
+
`;
|
|
216
|
+
|
|
217
|
+
// 检查是否已经有导出语句
|
|
218
|
+
if (!existingContent.includes('module.exports = {')) {
|
|
219
|
+
fs.appendFileSync(outputPath, exportStatement, 'utf-8');
|
|
220
|
+
}
|
|
208
221
|
}
|
|
209
222
|
|
|
210
223
|
/**
|
package/src/templates.js
CHANGED
|
@@ -9,23 +9,43 @@
|
|
|
9
9
|
* @returns {string} 生成的函数代码
|
|
10
10
|
*/
|
|
11
11
|
function generateCallbackTemplate(functionName, controls = []) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// 如果控件数量为 0 或 1,生成简化版本的函数
|
|
13
|
+
if (controls.length <= 1) {
|
|
14
|
+
return `/**
|
|
15
|
+
* @param {RibbonUI} control 控件对象,代表一个菜单控件元素对象(如 button、group 等)
|
|
16
|
+
* @note
|
|
17
|
+
* - 这是控件的回调函数,不应该在其他 JS 文件中调用这个函数
|
|
18
|
+
* - 尽量立即完成,避免写长耗时代码。
|
|
19
|
+
*
|
|
20
|
+
* 生成时间: ${new Date().toLocaleString()}
|
|
21
|
+
*/
|
|
22
|
+
function ${functionName}(control) {
|
|
23
|
+
|
|
24
|
+
// code here
|
|
25
|
+
|
|
26
|
+
// 避免 UI 报错,总是返回 true
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 多个控件使用时,生成 switch case 结构
|
|
33
|
+
const cases = controls.map(control => {
|
|
34
|
+
return ` // xmlPath: ${control.xmlPath}\n case "${control.id}":\n // TODO: 实现控件逻辑\n break;`;
|
|
14
35
|
});
|
|
15
36
|
|
|
16
37
|
return `/**
|
|
17
|
-
* @param {RibbonUI}
|
|
38
|
+
* @param {RibbonUI} control 控件对象,代表一个菜单控件元素对象(如 button、group 等)
|
|
18
39
|
* @note
|
|
19
40
|
* - 这是控件的回调函数,不应该在其他 JS 文件中调用这个函数
|
|
20
|
-
* -
|
|
21
|
-
* - 回调函数应该是异步的,避免写长耗时同步代码,否则可能导致 UI 卡死
|
|
41
|
+
* - 尽量立即完成,避免写长耗时代码。
|
|
22
42
|
*
|
|
23
43
|
* 生成时间: ${new Date().toLocaleString()}
|
|
24
44
|
*/
|
|
25
|
-
function ${functionName}(
|
|
45
|
+
function ${functionName}(control) {
|
|
26
46
|
|
|
27
|
-
// 通过
|
|
28
|
-
switch (
|
|
47
|
+
// 通过 control.Id 来判断当前元素
|
|
48
|
+
switch (control.Id) {
|
|
29
49
|
${cases.join('\n')}
|
|
30
50
|
default:
|
|
31
51
|
break;
|