面板部件逻辑脚本
在面板部件逻辑中,可在脚本代码中根据部件数据实现复杂的业务逻辑。如加载数据前添加或删除请求参数,或者数据保存成功后通知另一视图刷新。部件逻辑支持绑定的事件请参考组件中对应部件的事件描述。
参数
名称 | 类型 | 描述 |
---|---|---|
triggerControlName | string | 触发部件名称,仅面板部件触发时存在 |
triggerEventName | string | 事件名称,仅面板部件触发时存在 |
triggerEvent | IApiData | 触发部件参数,仅面板部件触发时存在 |
panelItemName | string | 面板项名称,仅非面板部件触发时存在 |
panelItemEventName | string | 面板项事件名称,仅非面板部件触发时存在 |
document | Document | 当前文档对象 |
selector | (className: string) => HTMLCollectionOf<Element> | 元素选择器 |
env | IEnvironment | 当前环境对象 |
appSession | IApiData | 当前应用会话对象 |
topViewSession | IApiData | 当前顶级视图会话对象 |
viewSession | IApiData | 当前视图会话对象 |
context | IApiContext | 当前视图上下文 |
viewParam | IApiParams | 当前视图参数 |
data | IApiData[] | 当前业务数据 |
app | IApiAppHubController | 当前应用 |
topView | IApiViewController | 当前顶级视图 |
parentView | IApiViewController | undefined | 当前父视图 |
view | IApiViewController | 当前视图 |
parent | IApiViewController | undefined | 当前父视图 |
util | { message: IApiMessageUtil, notification: IApiNotificationUtil,modal: IApiModalUtil,confirm: IApiConfirmUtil,openView: IApiOpenViewUtil} | 工具集 |
ctrl | IApiControlController | undefined | 当前部件 |
调用示例
部件加载前(onBeforeLoad)添加请求参数
typescript
viewParam.queryconds=["n_title_like", "n_identifier_like", "n_description_like"];
部件初始化(onCreated)时默认不显示容器
typescript
view.layoutPanel.panelItems.send_comment_container.state.visible = false;
视图加载成功后(onLoadSuccess)判断面板项是否该隐藏
typescript
if (view.layoutPanel.panelItems.mdctrl.control.state.items.length == 0) {
view.layoutPanel.panelItems.mdctrl.state.visible = false;
}
视图保存成功后发送实体更新消息
typescript
ibiz.mc.command.update.send({ srfdecodename: "library" });
部件加载成功后(onLoadSuccess)通知相同实体刷新
ibiz.mc.command.update.send({ srfdecodename: 'work_item'})
搜索表单加载草稿前(onBeforeLoadDraft)设置默认值
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth();
const day = currentDate.getDate();
const n_tjsj_gt1 = `${currentYear}-${currentMonth}-${day}`;
const n_tjsj_lt1 = `${currentYear}-${currentMonth + 1}-${day}`;
const n_ywfl_eq = 'JXJS';
const n_sjfwlx_eq1 = 'YEAR';
Object.assign(viewParam, {
n_ywfl_eq,
n_tjsj_gt1,
n_tjsj_lt1,
n_sjfwlx_eq1,
})
监听视图下所有部件选中事件打开视图
if (triggerEventName && triggerEventName === 'onSelectionChange') {
view.call('Edit', {
context: view.context,
params: view.params,
data: triggerEvent.data,
view,
ctrl: triggerEvent.ctrl,
});
}