|
@@ -1,9 +1,8 @@
|
|
|
-import {state} from '../state'
|
|
|
import {b64toBlob} from "../utils";
|
|
|
|
|
|
/*
|
|
|
* 当前限制
|
|
|
-* 若外层为layout类的Widget,则内层Widget在get_element中绑定的事件将会失效
|
|
|
+* 若Widget被作为其他Widget的子项时,该Widget中绑定的事件将会失效
|
|
|
* */
|
|
|
|
|
|
export interface Widget {
|
|
@@ -55,34 +54,23 @@ let Html = {
|
|
|
let Buttons = {
|
|
|
handle_type: 'buttons',
|
|
|
get_element: function (spec: any) {
|
|
|
- const btns_tpl = `<div>{{#buttons}}
|
|
|
- <button onclick="WebIO.DisplayAreaButtonOnClick(this, '{{callback_id}}')" class="btn {{#color}}btn-{{color}}{{/color}}{{#small}} btn-sm{{/small}}">{{label}}</button>
|
|
|
+ const btns_tpl = `<div>{{#buttons}}
|
|
|
+ <button class="btn {{#color}}btn-{{color}}{{/color}}{{#small}} btn-sm{{/small}}">{{label}}</button>
|
|
|
{{/buttons}}</div>`;
|
|
|
spec.color = spec.link ? "link" : "primary";
|
|
|
let html = Mustache.render(btns_tpl, spec);
|
|
|
- let elem = $(html);
|
|
|
+ let elem = $(html);
|
|
|
|
|
|
let btns = elem.find('button');
|
|
|
- for(let idx =0; idx< spec.buttons.length; idx++)
|
|
|
- btns.eq(idx).val(JSON.stringify(spec.buttons[idx].value));
|
|
|
+ for (let idx = 0; idx < spec.buttons.length; idx++) {
|
|
|
+ // note: 若Buttons被作为其他Widget的子项时,Buttons中绑定的事件将会失效,所以使用onclick attr设置点击事件
|
|
|
+ btns.eq(idx).attr('onclick', `WebIO.pushData(${JSON.stringify(spec.buttons[idx].value)}, "${spec.callback_id}")`);
|
|
|
+ }
|
|
|
|
|
|
return elem;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 显示区按钮点击回调函数
|
|
|
-export function DisplayAreaButtonOnClick(this_ele: HTMLElement, callback_id: string) {
|
|
|
- if (state.CurrentSession === null)
|
|
|
- return console.error("can't invoke DisplayAreaButtonOnClick when WebIOController is not instantiated");
|
|
|
-
|
|
|
- let val = $(this_ele).val() as string;
|
|
|
- state.CurrentSession.send_message({
|
|
|
- event: "callback",
|
|
|
- task_id: callback_id,
|
|
|
- data: JSON.parse(val)
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
// 已废弃。为了向下兼容而保留
|
|
|
let File = {
|
|
|
handle_type: 'file',
|