From 9fa972a4d7f555729ac0974883cb7a132abbe5ec Mon Sep 17 00:00:00 2001 From: CRM8000 Date: Sat, 26 Aug 2023 07:50:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88=20-=20?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=88=B0SLN0000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/PSI/SLN0000/Solution/EditForm.js | 211 +++++++++++ .../Scripts/PSI/SLN0000/Solution/MainForm.js | 337 ++++++++++++++++++ 2 files changed, 548 insertions(+) create mode 100644 web/Public/Scripts/PSI/SLN0000/Solution/EditForm.js create mode 100644 web/Public/Scripts/PSI/SLN0000/Solution/MainForm.js diff --git a/web/Public/Scripts/PSI/SLN0000/Solution/EditForm.js b/web/Public/Scripts/PSI/SLN0000/Solution/EditForm.js new file mode 100644 index 00000000..7489ffb4 --- /dev/null +++ b/web/Public/Scripts/PSI/SLN0000/Solution/EditForm.js @@ -0,0 +1,211 @@ +/** + * 新增或编辑解决方案 + * + * @author PSI + * @copyright 2015 - present + * @license GPL v3 + */ +PCL.define("PSI.SLN0000.Solution.EditForm", { + extend: "PSI.AFX.Form.EditForm", + + /** + * 初始化组件 + * + * @override + */ + initComponent() { + const me = this; + const entity = me.getEntity(); + + const t = entity == null ? "新建解决方案" : "编辑解决方案"; + + const logoHtml = me.genLogoHtml(entity, t); + const width1 = 300; + PCL.apply(me, { + header: { + title: me.formatTitle(PSI.Const.PROD_NAME), + height: 40 + }, + width: 650, + height: 240, + layout: "border", + items: [{ + region: "north", + border: 0, + height: 70, + html: logoHtml + }, { + region: "center", + border: 0, + id: "PSI_Solution_EditForm_editForm", + xtype: "form", + layout: { + type: "table", + columns: 2, + tableAttrs: PSI.Const.TABLE_LAYOUT, + }, + height: "100%", + bodyPadding: 5, + defaultType: 'textfield', + fieldDefaults: { + labelWidth: 40, + labelAlign: "right", + labelSeparator: "", + msgTarget: 'side', + width: width1, + }, + items: [{ + xtype: "hidden", + name: "id", + value: entity === null ? null : entity.get("id") + }, { + id: "PSI_Solution_EditForm_editCode", + fieldLabel: "编码", + allowBlank: false, + blankText: "没有输入编码", + beforeLabelTextTpl: PSI.Const.REQUIRED, + name: "code", + value: entity === null ? null : entity.get("code"), + listeners: { + specialkey: { + fn: me.__onEditSpecialKey, + scope: me + } + }, + }, { + id: "PSI_Solution_EditForm_editName", + fieldLabel: "名称", + allowBlank: false, + blankText: "没有输入名称", + beforeLabelTextTpl: PSI.Const.REQUIRED, + name: "name", + value: entity === null ? null : entity.get("name"), + listeners: { + specialkey: { + fn: me._onLastEditSpecialKey, + scope: me + } + }, + }], + buttons: [{ + text: "确定", + ...PSI.Const.BTN_STYLE, + formBind: true, + iconCls: "PSI-button-ok", + handler: me._onOK, + scope: me + }, { + text: "取消", + ...PSI.Const.BTN_STYLE, + handler() { + const info = entity == null ? "新建解决方案" : "编辑解决方案"; + + me.confirm(`请确认是否取消:${info}?`, () => { + me.close(); + }); + }, + scope: me + }] + }], + listeners: { + show: { + fn: me._onWndShow, + scope: me + }, + close: { + fn: me._onWndClose, + scope: me + } + } + }); + + me.callParent(arguments); + + me.editName = PCL.getCmp("PSI_Solution_EditForm_editName"); + me.editCode = PCL.getCmp("PSI_Solution_EditForm_editCode"); + + me.editForm = PCL.getCmp("PSI_Solution_EditForm_editForm"); + + me.__editorList = [me.editCode, me.editName]; + }, + + /** + * @private + */ + _onWndClose() { + const me = this; + + PCL.get(window).un('beforeunload', me.__onWindowBeforeUnload); + }, + + /** + * @private + */ + _onWndShow() { + const me = this; + + PCL.get(window).on('beforeunload', me.__onWindowBeforeUnload); + + me.setFocusAndCursorPosToLast(me.editCode); + + const entity = me.getEntity(); + if (entity === null) { + return; + } + + const el = me.getEl() || PCL.getBody(); + el.mask("数据加载中..."); + me.ajax({ + url: me.URL("Home/Solution/solutionInfo"), + params: { + id: entity.get("id") + }, + callback(options, success, response) { + el.unmask(); + if (success) { + const { code, name } = me.decodeJSON(response.responseText); + me.editCode.setValue(code); + me.editName.setValue(name); + } + } + }); + }, + + /** + * @private + */ + _onOK() { + const me = this; + const f = me.editForm; + const el = f.getEl(); + el.mask("数据保存中..."); + f.submit({ + url: me.URL("Home/Solution/editSolution"), + method: "POST", + success(form, action) { + el.unmask(); + me.close(); + me.getParentForm().refreshMainGrid(action.result.id); + me.tip("操作成功", true); + }, + failure(form, action) { + el.unmask(); + me.showInfo(action.result.msg, () => { + me.setFocusAndCursorPosToLast(me.editCode); + }); + } + }); + }, + + /** + * @private + */ + _onLastEditSpecialKey(field, e) { + const me = this; + if (e.getKey() == e.ENTER) { + if (me.editForm.getForm().isValid()) { + me._onOK(); + } + } + } +}); diff --git a/web/Public/Scripts/PSI/SLN0000/Solution/MainForm.js b/web/Public/Scripts/PSI/SLN0000/Solution/MainForm.js new file mode 100644 index 00000000..7406508d --- /dev/null +++ b/web/Public/Scripts/PSI/SLN0000/Solution/MainForm.js @@ -0,0 +1,337 @@ +/** + * 解决方案 - 主界面 + * + * @author PSI + * @copyright 2015 - present + * @license GPL v3 + */ + +PCL.define("PSI.SLN0000.Solution.MainForm", { + + extend: "PSI.AFX.Form.MainForm", + + /** + * 初始化组件 + * + * @override + */ + initComponent() { + const me = this; + + PCL.apply(me, { + tbar: [{ + iconCls: "PSI-tb-new", + ...PSI.Const.BTN_STYLE, + text: "新建解决方案", + handler: me._onAdd, + scope: me + }, { + text: "编辑解决方案", + ...PSI.Const.BTN_STYLE, + handler: me._onEdit, + scope: me + }, { + text: "删除解决方案", + ...PSI.Const.BTN_STYLE, + handler: me._onDelete, + scope: me + }, "-", + { + text: "设置默认解决方案", + ...PSI.Const.BTN_STYLE, + handler: me._onDefault, + scope: me + }, "-", { + iconCls: "PSI-tb-help", + ...PSI.Const.BTN_STYLE, + text: "指南", + handler() { + me.focus(); + window.open(me.URL("Home/Help/index?t=solution")); + } + }, "-", { + iconCls: "PSI-tb-close", + ...PSI.Const.BTN_STYLE, + text: "关闭", + handler() { + me.closeWindow(); + } + }].concat(me.getShortcutCmp()), + items: [{ + region: "north", + height: 55, + border: 0, + bodyPadding: "0 20 0 20", + html: "

解决方案

  通过不同的解决方案实现业务个性化定制", + }, { + region: "center", + xtype: "panel", + layout: "fit", + border: 0, + bodyPadding: "0 20 5 15", + items: [me.getMainGrid()] + }] + }); + + me.callParent(arguments); + + me.refreshMainGrid(); + }, + + /** + * 快捷访问 + * + * @private + */ + getShortcutCmp() { + return ["->", + { + cls: "PSI-Shortcut-Cmp", + labelWidth: 0, + emptyText: "快捷访问", + xtype: "psi_mainmenushortcutfield", + width: 90 + } + ]; + }, + + /** + * @private + */ + getMainGrid() { + const me = this; + + if (me._mainGrid) { + return me._mainGrid; + } + + const modelName = "PSIModel.PSI.Solution.MainForm.SolutionModel"; + + PCL.define(modelName, { + extend: "PCL.data.Model", + fields: ["id", "code", "name", "isDefault"] + }); + + me._mainGrid = PCL.create("PCL.grid.Panel", { + cls: "PSI-FC", + viewConfig: { + enableTextSelection: true + }, + border: 1, + columnLines: true, + columns: { + defaults: { + menuDisabled: true, + sortable: false + }, + items: [PCL.create("PCL.grid.RowNumberer", { + text: "#", + align: "right", + width: 60 + }), { + header: "编码", + dataIndex: "code", + width: 140, + }, { + header: "解决方案名称", + dataIndex: "name", + width: 400, + }, { + header: "默认解决方案", + dataIndex: "isDefault", + width: 100, + align: "center" + }] + }, + store: PCL.create("PCL.data.Store", { + model: modelName, + autoLoad: false, + data: [] + }), + listeners: { + itemdblclick: { + fn: me._onEdit, + scope: me + } + }, + }); + + return me._mainGrid; + }, + + /** + * 新建解决方案 + * + * @private + */ + _onAdd() { + const me = this; + + const form = PCL.create("PSI.Solution.EditForm", { + renderTo: PSI.Const.RENDER_TO(), + parentForm: me + }); + form.show(); + }, + + /** + * 编辑解决方案 + * + * @private + */ + _onEdit() { + const me = this; + + const item = me.getMainGrid().getSelectionModel().getSelection(); + if (item === null || item.length !== 1) { + me.showInfo("请选择要编辑的解决方案"); + return; + } + + const solution = item[0]; + + const form = PCL.create("PSI.Solution.EditForm", { + renderTo: PSI.Const.RENDER_TO(), + entity: solution, + parentForm: me + }); + form.show(); + }, + + /** + * 删除解决方案 + * + * @private + */ + _onDelete() { + const me = this; + + const item = me.getMainGrid().getSelectionModel().getSelection(); + if (item === null || item.length !== 1) { + me.showInfo("请选择要删除的解决方案"); + return; + } + + const solution = item[0]; + + const store = me.getMainGrid().getStore(); + let index = store.findExact("id", solution.get("id")); + index--; + const preItem = store.getAt(index); + let preId = null; + if (preItem) { + preId = preItem.get("id"); + } + + const funcConfirm = () => { + PCL.getBody().mask("正在删除中..."); + const r = { + url: me.URL("Home/Solution/deleteSolution"), + params: { + id: solution.get("id") + }, + callback(options, success, response) { + PCL.getBody().unmask(); + + if (success) { + const data = me.decodeJSON(response.responseText); + if (data.success) { + me.tip("成功完成删除操作", true); + me.refreshMainGrid(preId); + } else { + me.showInfo(data.msg); + } + } + } + }; + + me.ajax(r); + }; + + const info = `请确认是否删除解决方案 ${solution.get("name")} ?`; + me.confirm(info, funcConfirm); + }, + + /** + * @private + */ + refreshMainGrid(id) { + const me = this; + + const grid = me.getMainGrid(); + const el = grid.getEl() || PCL.getBody(); + el.mask(PSI.Const.LOADING); + const r = { + url: me.URL("Home/Solution/solutionList"), + callback(options, success, response) { + const store = grid.getStore(); + + store.removeAll(); + + if (success) { + const data = me.decodeJSON(response.responseText); + store.add(data); + + if (store.getCount() > 0) { + if (id) { + const r = store.findExact("id", id); + if (r != -1) { + grid.getSelectionModel().select(r); + } + } else { + grid.getSelectionModel().select(0); + } + } + } + + el.unmask(); + } + }; + + me.ajax(r); + }, + + /** + * @private + */ + _onDefault() { + const me = this; + + const item = me.getMainGrid().getSelectionModel().getSelection(); + if (item === null || item.length !== 1) { + me.showInfo("请选择解决方案"); + return; + } + + const solution = item[0]; + const id = solution.get("id"); + + const funcConfirm = () => { + PCL.getBody().mask("正在操作中..."); + const r = { + url: me.URL("Home/Solution/setDefault"), + params: { + id + }, + callback(options, success, response) { + PCL.getBody().unmask(); + + if (success) { + const data = me.decodeJSON(response.responseText); + if (data.success) { + me.tip("成功完成操作", true); + me.refreshMainGrid(id); + } else { + me.showInfo(data.msg); + } + } + } + }; + + me.ajax(r); + }; + + const info = `请确认是否把解决方案 ${solution.get("name")} 设置为默认解决方案?`; + me.confirm(info, funcConfirm); + } +});