Skip to content

Commit

Permalink
第一版自定义脚本支持
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Dec 31, 2020
1 parent 5bae77c commit 979895c
Show file tree
Hide file tree
Showing 7 changed files with 385 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"args": [
"--input",
"../xresconv-conf/sample.xml",
"--custom-selector",
"--custom-button",
"./doc/custom-selector.json"
],
"cwd": "${workspaceRoot}",
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
> electron-packer -> 15.2.0
> popper.js 替换为 @popperjs/core
2. 增加命令行选项 ```--custom-selector <json文件名>``` 用于增加自定义选择器
2. 增加命令行选项 ```--custom-selector/--custom-button <json文件名>``` 用于增加自定义选择器
3. 允许事件可勾选是否执行
4. 转表前事件和转表后事件增加允许在面板中设置开启货关闭,新属性如下:

Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ xresconv-gui

+ ```--input <文件名>``` : 指定初始的转表清单文件。
+ ```--debug``` : 开启debug模式并启动开发人员工具。
+ ```--custom-selector <json文件名>``` : 增加自定义选择器,允许多个
+ ```--custom-selector/--custom-button <json文件名>``` : 增加自定义选择器,允许多个

### 自定义选择器规则

Expand Down Expand Up @@ -68,6 +68,7 @@ xresconv-gui
+ ```reload``` : 重新加载自定义按钮
+ ```select_all``` : 全部选中
+ ```unselect_all``` : 全部反选
+ ```script: <脚本名字>``` : 执行脚本,**脚本名字**```//root/gui/script``` 节点的 ```name``` 属性。

示例
------
Expand Down Expand Up @@ -109,9 +110,16 @@ xresconv-gui
type="text/javascript" timeout="超时时间(毫秒,默认: 30000)" description="转表结束后的事件回调函数,事件执行结束必须调用done()函数,以触发进行下一步">
// 事件代码脚本
</on_after_convert>
<script name="自定义脚本" type="text/javascript" timeout="超时时间(毫秒,默认: 30000)">
// 同上
alert_warning("自定义脚本,可用于自定义按钮");
resolve();
</script>
</gui>
```

> 注: 事件的 ```name``````checked``````mutable``` 和自定义脚本的```<script></script>``` 标签需要版本 **>=2.3.0**
**set_name** 事件系统中,可用的接口如下:

```javascript
Expand Down Expand Up @@ -151,6 +159,25 @@ xresconv-gui
}
```

在自定义脚本 **script** 中,可用的接口如下:

```javascript
{
work_dir: "执行xresloader的工作目录",
xresloader_path: "xresloader目录",
global_options: {"全局选项": "VALUE"},
selected_nodes: ["选中要执行转表的节点集合"],
selected_items: ["选中要执行转表的item对象集合,数据结构同上面的 item_data"], // 版本 >= 2.2.3
alert_warning: function(content, title, options) {}, // 警告弹框, options 结构是 {yes: 点击是按钮回调, no: 点击否按钮回调, on_close: 关闭后回调}
alert_error: function(content, title) {}, // 错误弹框
log_info: function (content) {}, // 打印info日志
log_error: function (content) {}, // 打印error日志
resolve: function (value) {}, // 通知上层执行结束,相当于Promise的resolve
reject: function(reason) {}, // 通知上层执行失败,相当于Promise的reject
require: function (name) {} // 相当于 nodejs的 require(name) 用于导入nodejs 模块
}
```

开发使用说明
======

Expand Down
6 changes: 6 additions & 0 deletions doc/custom-selector.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
"reload"
],
"style": "outline-dark"
}, {
"name": "执行自定义脚本",
"action": [
"script: 自定义脚本"
],
"style": "outline-dark"
}]
4 changes: 4 additions & 0 deletions src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
min-height: 320px;
}

.conv_pre_error {
color: darkred;
}

#conv_list_file {
display: none;
}
Expand Down
Loading

0 comments on commit 979895c

Please sign in to comment.