@jecloud/func
Version:
JECloud 功能库
1 lines • 9.8 kB
JavaScript
var e=this&&this.__assign||function(){return e=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},e.apply(this,arguments)};import{encode as t,isEmpty as o,createDeferred as n,isFunction as r}from"@jecloud/utils";import{nextTick as i,reactive as a,toRaw as c}from"vue";import{doSave as s,doRemove as u,doTreeSave as d,doTreeRemove as l,doTreeMove as f,doUpdateList as v,doTreeUpdateList as p,checkFieldUnique as m,getBean as g}from"../../../data/api/common";import{Modal as h}from"@jecloud/ui";import{FuncRefEnum as b,FuncTypeEnum as C,FuncButtonTypeEnum as F}from"../../../data/enum";import{getTreeDefaultValues as w,doTreeSave as A,doTreeUpdate as I,doTreeRemove as R}from"./tree-action";import{doGridSave as T,doGridRemove as D,doGridUpdate as $}from"./grid-action";import{doFormAudit as y}from"./custom-action";import E from"../../../select-window";import{doFuncFieldUpdate as B}from"./func-field-action";import{doEvents4Sync as j}from"../event-action";import{disableRemove4Workflow as k}from"../../../func-workflow/use-workflow-perm";import{showExportForm as P}from"../../../func-data/src/hooks/plugin/use-export-button";export function useBaseAction(e){return{doExport:V.bind(this,e),doInsert:O.bind(this,e),doInsert4Grid:N.bind(this,e),doInsert4Multi:M.bind(this,e),doSave:_.bind(this,e),doRemove:G.bind(this,e),doUpdateList:U.bind(this,e),doEdit:L.bind(this,e),doBack:q.bind(this,e),doTreeMove:W.bind(this,e),doTreeTransfer:H.bind(this,e),getDefaultValues:getDefaultValues.bind(this,e),checkFieldUnique:z.bind(this,e),doFormAudit:y.bind(this,e)}}function V(e,t){void 0===t&&(t={}),P({$func:e,options:t})}function _(o){var n=o.store,r=o.getFuncData,i=o.getViewRef,a=r(),u=i(b.FUNC_FORM).value,l=a.info,f=l.tableCode,v=l.pkCode,p=l.productCode,m=l.funcCode,g=l.funcType,F=l.funcAction,w=a.fields.codeGenFieldInfo,R=g===C.TREE,D=c(n.activeBean),y=D[v];return u.validate().then((function(){return(R?d:s)({params:e({funcCode:m,tableCode:f,pkCode:v,codeGenFieldInfo:t(w)},D),pkValue:y,pd:p,action:F}).then((function(e){var t=e.dynaBean;return B({$func:o,bean:t}),e})).then((function(e){var t=e.dynaBean,r=e.node;if(y)I({$func:o,nodes:[r]}),n.commitActiveBean(t),$({$func:o,records:[t]});else{A({$func:o,node:r}),n.setActiveBean(t);var i=T({$func:o,record:t});n.setActiveRow(i)}h.notice(y?"保存成功!":"添加成功!","success")})).catch((function(e){var t;h.alert(null!==(t=null==e?void 0:e.message)&&void 0!==t?t:"请求出错了,请查看控制台!","error"),console.error(e)}))})).catch((function(e){console.log("表单验证未通过:",e)}))}function G(e,t){void 0===t&&(t={});var r=t.row,i=e.getFuncData,a=e.getViewRef,c=i().info,s=c.productCode,d=c.tableCode,f=c.funcAction,v=c.funcCode,p=c.funcType,m=c.enableWorkflow,g=a(b.FUNC_GRID).value,F=g.store,w=r?[r]:g.getSelectedRecords();if(o(w))return h.message("请选择要删除的数据!"),Promise.resolve();if(k({rows:w,enableWorkflow:m}))return h.alert("流程已启动不能被删除...","warning"),Promise.resolve();var A=n();return h.confirm("确定删除选中的【"+w.length+"】条数据吗",(function(){var t,o=[];(w.forEach((function(e){F.isInsertRecord(e)||o.push(F.getRecordId(e))})),o.length)?t=(p===C.TREE?l:u)({params:{tableCode:d,funcCode:v,ids:o.join(",")},pd:s,action:f}):t=Promise.resolve();t.then((function(){var t=w.map((function(e){return F.getRecordId(e)}));D({$func:e,ids:t}),R({$func:e,ids:t}),h.notice(w.length+" 条记录被删除","success"),A.resolve()})).catch((function(e){var t;h.alert(null!==(t=null==e?void 0:e.message)&&void 0!==t?t:"请求出错了,请查看控制台!","error"),console.error(e),A.reject()}))})),A.promise}function U(e,n){void 0===n&&(n={});var r=n.row,i=n.showMessage,a=void 0===i||i,s=e.getFuncData,u=(0,e.getViewRef)(b.FUNC_GRID).value,d=s(),l=d.info,f=l.productCode,m=l.tableCode,g=l.funcCode,F=l.funcType,w=l.funcAction,A=d.fields.codeGenFieldInfo,R=u.store,T=R.getChanges(r,!0);if(o(T))return a&&h.message("暂无数据变动,无需修改..."),Promise.resolve();var D=[],y=[];T.forEach((function(e){var t={},o=e._record,n=R.idProperty;R.isInsertRecord(o)?t=c(o):(Object.keys(e).forEach((function(o){t[o]=e[o].newValue})),t[n]=R.getRecordId(o)),delete t._record,D.push(t),y.push(o)}));var E=F===C.TREE,B=E?p:v;return u.validate(y).then((function(e){return o(e)?Promise.resolve():Promise.reject(e)})).then((function(){return B({params:{tableCode:m,funcCode:g,strData:t(D),codeGenFieldInfo:t(A)},pd:f,action:w}).then((function(t){var o=t.dynaBeans,n=t.nodes;a&&h.notice("保存成功!","success"),$({$func:e,records:o}),E&&I({$func:e,nodes:n})})).catch((function(e){var t;h.alert(null!==(t=null==e?void 0:e.message)&&void 0!==t?t:"请求出错了,请查看控制台!","error"),console.error(e)}))})).catch((function(e){return console.log("列表校验失败:",e),Promise.reject(e)}))}function O(e,t){void 0===t&&(t={});var o=e.getFuncData(),n=e.parentFunc;if(n&&!n.store.getBeanId())return void h.alert("请先保存主功能数据!",h.status.warning);var r=getDefaultValues(e,{buttonCode:F.GRID_INSERT_BUTTON});return t.bean&&Object.assign(r,t.bean),"FIRSTADD"===o.info.insertType?N(e,{records:[r]}):x(e,{bean:a(r)})}function x(e,t){var o=t.bean,n=e.getFuncForm();return null==n||n.clearValidate(),e.store.setActiveBean(o),e.action.viewAction.setActiveItem(b.FUNC_EDIT),i()}function N(e,t){void 0===t&&(t={});var o=t.records,n=void 0===o?[]:o,r=e.getFuncGrid(),i=[];return n.length&&(i=r.store.insert(n),r.setActiveRow(i[0])),Promise.resolve({insertRecords:i})}function S(e,o){void 0===o&&(o={});var n=o.records,r=void 0===n?[]:n,i=e.getFuncGrid(),a=e.getFuncData(),c=a.info,s=c.productCode,u=c.tableCode,d=c.funcCode,l=c.funcType,f=c.funcAction,m=a.fields.codeGenFieldInfo;if(r.length){var g=i.store.insert(r)[0],b=l===C.TREE;(b?p:v)({params:{tableCode:u,funcCode:d,strData:t([g]),codeGenFieldInfo:t(m)},pd:s,action:f}).then((function(t){t.dynaBeans;var o=t.nodes;return b&&A({$func:e,node:o[0]}),i.store.commitRecord(g),i.setActiveRow(g),Promise.resolve()})).catch((function(e){var t;return h.alert(null!==(t=null==e?void 0:e.message)&&void 0!==t?t:"请求出错了,请查看控制台!","error"),console.error(e),Promise.resolve()}))}}function M(t,o){if(void 0===o&&(o={}),o.type&&o.configInfo){var r=n();return E.show(e(e({title:"批量添加",multiple:!0},o),{callback:function(o){var n=o.rows,i=o.config,a=getDefaultValues(t,{buttonCode:F.GRID_INSERT_BATCH_BUTTON}),c=[];n.forEach((function(t){var o,n={};null===(o=i.sourceFields)||void 0===o||o.forEach((function(e,o){n[i.targetFields[o]]=t[e]})),c.push(e(e({},a),n))})),r.resolve(e({records:c},o))}})),r.promise}return Promise.reject("请配置批量添加的信息")}function L(e,t){void 0===t&&(t={});var o=e.getFuncGrid(),n=t.row||o.getSelectedRecords()[0];if(n){var r=Promise.resolve(),i=e.getFuncData().info,a=i.productCode,c=i.tableCode,s=i.funcCode,u=i.funcAction,d=i.pkCode;return n[d]&&(r=g({params:{tableCode:c,funcCode:s,pkValue:n[d]},action:u,pd:a})),e.store.setActiveRow(n),r.then((function(t){var o=e.getFuncForm();null==o||o.clearValidate(),e.store.setActiveBean(t),e.action.viewAction.setActiveItem(b.FUNC_EDIT)}))}h.alert("请选择要操作的数据!",h.status.warning)}function q(e){var t=e.store.getBeanChanges(),r=e.getFuncForm();if(o(t))return e.action.viewAction.setActiveItem(b.FUNC_DATA),i();var a=n(),c=function(){null==r||r.clearValidate(),e.store.resetActiveBean(),e.action.viewAction.setActiveItem(b.FUNC_DATA),a.resolve()};return h.dialog({content:"数据有改动,未保存,确定返回吗?",status:h.status.question,buttons:[{text:"确定返回",type:"primary",handler:c},{text:"保存返回",handler:function(){r.validate().then((function(){_(e).then(c)}))}},{text:"取消"}]}),a}function W(e,t){var o=t.id,n=t.toId,r=t.place,i=e.getFuncData().info,a=i.productCode,c=i.tableCode,s=i.funcCode,u=i.funcAction,d=e.getFuncGrid();return f({params:{id:o,toId:n,place:r,tableCode:c,funcCode:s},action:u,pd:a}).then((function(){h.notice("转移成功!","success"),d.store.reload()}))}function H(e,t){var o=t.row,r=n(),i=e.getFuncTree(),a=function(t){var n=t.$plugin,a=t.$modal,c=t.place,s=n.value.getSelectedRecords()[0];s?s.nodePath.startsWith(o.nodePath)?(h.alert("不允许转移到自身节点以及子节点!"),r.reject()):W(e,{id:o.id,toId:s.id,place:c}).then((function(){a.close(),i.store.reload(),r.resolve()})):(h.alert("请选择需要转移的节点!"),r.reject())};return E.showTree({title:"移动到选中节点",store:i.store,autoLoad:!1,buttons:[{text:"上面",type:"primary",bgColor:"#02a863",closable:!1,handler:function(e){var t=e.$modal,o=e.$plugin;a({$modal:t,$plugin:o,place:"above"})}},{text:"下面",type:"primary",bgColor:"#02a863",closable:!1,handler:function(e){var t=e.$modal,o=e.$plugin;a({$modal:t,$plugin:o,place:"below"})}},{text:"里面",type:"primary",closable:!1,handler:function(e){var t=e.$modal,o=e.$plugin;a({$modal:t,$plugin:o,place:"inside"})}},{text:"取消",handler:function(){r.reject()}}]}),r.promise}function z(e,n){void 0===n&&(n=[]);var r=e.getFuncData().info,i=r.productCode,a=r.funcCode,c=r.funcAction,s=r.pkCode;if(o(n))return Promise.resolve(!0);var u=e.store.activeBean[s];return m({params:{funcCode:a,strData:t(n),pkValue:u},action:c,pd:i}).then((function(e){return e.success}))}export function getDefaultValues(e,t){void 0===t&&(t={});var o=e.getFuncData(),n=e.store.getDefaults().values,i=w({$func:e});Object.assign(n,i);var a=e.store.initBean;if(a)if(r(a)){var c=a({$func:e,defaultValues:n});c&&Object.assign(n,c)}else Object.assign(n,a);var s=o.info.gridEvents["transform-default-values"];if(s){var u=t.buttonCode,d=j({$func:e,eventOptions:{values:n,buttonCode:u},code:s});d&&(n=d)}return n}