(msg: Command)
| 68 | * 每次函数调用返回后,this.form_ctrls.get_top()的栈顶对应的表单为当前活跃表单 |
| 69 | * */ |
| 70 | handle_message(msg: Command) { |
| 71 | let old_ctrls = this.form_ctrls.get_top(); |
| 72 | let old_ctrl = old_ctrls && old_ctrls[old_ctrls.length - 1]; |
| 73 | let target_ctrls = this.form_ctrls.get_value(msg.task_id); |
| 74 | if (target_ctrls === undefined) { |
| 75 | this.form_ctrls.push(msg.task_id, []); |
| 76 | target_ctrls = this.form_ctrls.get_value(msg.task_id); |
| 77 | } |
| 78 | |
| 79 | // 创建表单 |
| 80 | if (msg.command in make_set(['input', 'input_group'])) { |
| 81 | let ctrl = new FormController(this.session, msg.task_id, msg.spec); |
| 82 | target_ctrls.push(ctrl); |
| 83 | this.container_elem.append(ctrl.create_element()); |
| 84 | ctrl.after_add_to_dom(); |
| 85 | this._activate_form(msg.task_id, old_ctrl); |
| 86 | } else if (msg.command in make_set(['update_input'])) { |
| 87 | // 更新表单 |
| 88 | if (target_ctrls.length === 0) { |
| 89 | return console.error('No form to current message. task_id:%s', msg.task_id); |
| 90 | } |
| 91 | target_ctrls[target_ctrls.length - 1].dispatch_ctrl_message(msg.spec); |
| 92 | // 表单前置 removed |
| 93 | // this._activate_form(msg.task_id, old_ctrl); |
| 94 | } else if (msg.command === 'destroy_form') { |
| 95 | if (target_ctrls.length === 0) { |
| 96 | return console.error('No form to current message. task_id:%s', msg.task_id); |
| 97 | } |
| 98 | let deleted = target_ctrls.pop() as FormController; |
| 99 | if (target_ctrls.length === 0) |
| 100 | this.form_ctrls.remove(msg.task_id); |
| 101 | |
| 102 | // 销毁的是当前显示的form |
| 103 | if (old_ctrls === target_ctrls) { |
| 104 | deleted.element.hide(100, () => { |
| 105 | deleted.element.remove(); |
| 106 | close_input(); |
| 107 | |
| 108 | let t = this.form_ctrls.get_top(); |
| 109 | if (t) t[t.length - 1].element.show(state.ShowDuration, () => { |
| 110 | this._after_show_form() |
| 111 | }); |
| 112 | }); |
| 113 | } else { |
| 114 | deleted.element.remove(); |
| 115 | close_input(); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 |
nothing calls this directly
no test coverage detected