Wizard-BWc28b7s.js 19 KB

1
  1. import{s as G,X as T,di as j,bJ as M,dj as J,a3 as N,am as Q,V as $,E as D,G as E,y as w,av as I,f as x,dk as H,aG as K,aH as X,O as Y,z as O,P as k,Q as c,aM as Z,T as q,D as ee,d0 as te,cn as ae,K as V,a5 as B,dl as z}from"./index-DT8qTvyx.js";var ne=function(A){G(r,A);function r(){var t=A!==null&&A.apply(this,arguments)||this;return t.initalValues={},t.state={currentStep:-1,completeStep:-1,rawSteps:[]},t}return r.prototype.componentDidMount=function(){var t=this,e=this.props,a=e.initApi,n=e.initFetch,s=e.initAsyncApi,o=e.initFinishedField,p=e.store,h=e.messages,l=h.fetchSuccess,u=h.fetchFailed;e.onInit,T(a,p.data,n)?p.fetchInitData(a,p.data,{successMessage:l,errorMessage:u,onSuccess:function(){if(!(!T(s,p.data)||p.data[o||"finished"]))return j(function(){return p.checkRemote(s,p.data)},function(i){return i&&i[o||"finished"]},function(i){return t.asyncCancel=i})}}).then(function(i){t.handleFetchInitEvent(i);var m={currentStep:typeof t.props.startStep=="string"?M(J(t.props.startStep,N(t.props.data,(i==null?void 0:i.data)||{})),1):1};return i&&i.data&&(typeof i.data.step=="number"||typeof i.data.step=="string"&&/^\d+$/.test(i.data.step))&&(m.currentStep=M(i.data.step,1)),t.setState(m,function(){i&&i.data&&(i.data.submiting||i.data.submited)&&t.checkSubmit()}),i}):this.setState({currentStep:typeof this.props.startStep=="string"?M(J(this.props.startStep,this.props.data),1):1}),this.normalizeSteps(p.data)},r.prototype.componentDidUpdate=function(t){var e=this.props,a=e.store,n=e.fetchSuccess,s=e.fetchFailed;(!Q(t.steps,e.steps)||!Q(t.data,e.data))&&this.normalizeSteps(e.data),$(t.initApi,e.initApi,t.data,e.data)&&a.fetchData(e.initApi,a.data,{successMessage:n,errorMessage:s})},r.prototype.componentWillUnmount=function(){this.asyncCancel&&this.asyncCancel()},r.prototype.dispatchEvent=function(t,e){var a;return D(this,void 0,void 0,function(){var n,s,o,p;return E(this,function(h){switch(h.label){case 0:return n=this.props,s=n.dispatchEvent,o=n.data,[4,s(t,e?N(o,e):o)];case 1:return p=h.sent(),[2,(a=p==null?void 0:p.prevented)!==null&&a!==void 0?a:!1]}})})},r.prototype.handleFetchInitEvent=function(t){var e;return D(this,void 0,void 0,function(){var a,n,s;return E(this,function(o){switch(o.label){case 0:return a=this.props,n=a.onInit,s=a.store,[4,this.dispatchEvent("inited",w(w({},s.data),{responseData:t.ok?(e=s.data)!==null&&e!==void 0?e:{}:t,responseStatus:(t==null?void 0:t.status)===void 0?s.error?1:0:t==null?void 0:t.status,responseMsg:s.msg}))];case 1:return o.sent()&&n&&n(s.data),[2]}})})},r.prototype.normalizeSteps=function(t){return D(this,void 0,void 0,function(){var e,a,n,s,o,p,h;return E(this,function(l){switch(l.label){case 0:e=this.props,a=e.steps,n=e.translate,s=[],o=a.length,p=0,l.label=1;case 1:return p<o?[4,ae(a[p].hiddenOn,t)]:[3,4];case 2:h=l.sent(),!h&&s.push(a[p]),l.label=3;case 3:return p++,[3,1];case 4:return this.setState({rawSteps:s.map(function(u,i){return w(w({},u),{hiddenOn:"",title:u.title||u.label||n("Steps.step",{index:i+1})})})}),[2]}})})},r.prototype.gotoStep=function(t){return D(this,void 0,void 0,function(){var e;return E(this,function(a){switch(a.label){case 0:return e=this.state.rawSteps,t=Math.max(Math.min(e.length,t),1),t==this.state.currentStep?[3,2]:[4,this.dispatchEvent("stepChange",{step:t})];case 1:if(a.sent())return[2];this.setState({currentStep:t,completeStep:Math.max(this.state.completeStep,t-1)}),a.label=2;case 2:return[2]}})})},r.prototype.formRef=function(t){if(t){for(;t&&t.getWrappedInstance;)t=t.getWrappedInstance();this.form=t}else this.form=void 0},r.prototype.submitToTarget=function(t,e){throw new Error("Please implements this!")},r.prototype.reloadTarget=function(t,e){throw new Error("Please implements this!")},r.prototype.reload=function(t,e,a,n,s){return D(this,void 0,void 0,function(){var o,p,h,l,u,i,m,f,d,v,g=this;return E(this,function(C){switch(C.label){case 0:return e?[2,this.receive(e,void 0,s)]:(o=this.props,p=o.initApi,h=o.initAsyncApi,l=o.initFinishedField,u=o.store,i=o.messages,m=i.fetchSuccess,f=i.fetchFailed,T(p,u.data)&&this.state.currentStep===1?[4,u.fetchInitData(p,u.data,{successMessage:m,errorMessage:f,onSuccess:function(){if(!(!T(h,u.data)||u.data[l||"finished"]))return j(function(){return u.checkRemote(h,u.data)},function(F){return F&&F[l||"finished"]},function(F){return g.asyncCancel=F})}})]:[3,2]);case 1:d=C.sent(),v={currentStep:1},d&&d.data&&(typeof d.data.step=="number"||typeof d.data.step=="string"&&/^\d+$/.test(d.data.step))&&(v.currentStep=M(d.data.step,1)),this.setState(v,function(){d&&d.data&&(d.data.submiting||d.data.submited)&&g.checkSubmit()}),C.label=2;case 2:return[2,u.data]}})})},r.prototype.receive=function(t,e,a){var n=this.props.store;return n.updateData(t,void 0,a),this.reload()},r.prototype.domRef=function(t){this.dom=t},r.prototype.getPopOverContainer=function(){return this.dom},r.prototype.checkSubmit=function(){var t,e=this,a=this.props,n=a.store,s=a.asyncApi,o=a.finishedField,p=a.env,h=this.state.rawSteps,l=h[this.state.currentStep-1],u=l&&l.asyncApi||this.state.currentStep===h.length&&s;!l||!T(u,n.data)||(n.markSaving(!0),n.updateData((t={},t[o||"finished"]=!1,t)),j(function(){return n.checkRemote(u,n.data)},function(i){return i&&i[o||"finished"]},function(i){return e.asyncCancel=i}).then(function(){n.markSaving(!1),e.gotoStep(e.state.currentStep+1)}).catch(function(i){!u.silent&&p.notify("error",i.message),n.markSaving(!1)}))},r.prototype.handleAction=function(t,e,a,n,s){var o=this;n===void 0&&(n=!1);var p=this.props,h=p.onAction,l=p.store,u=p.env,i=this.state.rawSteps;if(e.actionType==="next"||e.type==="submit"||e.actionType==="step-submit")this.form.doAction(w(w({},e),{actionType:"submit"}),a);else if(e.actionType==="prev")this.gotoStep(this.state.currentStep-1);else if(e.type==="reset")this.form.reset();else{if(e.actionType==="dialog")return l.setCurrentAction(e,this.props.resolveDefinitions),new Promise(function(f){l.openDialog(a,void 0,function(d,v){var g;(g=e.callback)===null||g===void 0||g.call(e,d,v),f({confirmed:d,value:v})},s||o.context)});if(e.actionType==="ajax")return e.api?l.saveRemote(e.api,a,{successMessage:e.messages&&e.messages.success,errorMessage:e.messages&&e.messages.failed}).then(function(){return D(o,void 0,void 0,function(){var f,d,v;return E(this,function(g){switch(g.label){case 0:return this.form&&this.form.isValidated()&&this.form.validate(!0),f=e.feedback,f&&B(f,l.data)?[4,this.openFeedback(f,l.data)]:[3,2];case 1:if(d=g.sent(),f.skipRestOnCancel&&!d)throw new z;if(f.skipRestOnConfirm&&d)throw new z;g.label=2;case 2:return v=e.redirect&&V(e.redirect,l.data),v&&u.jumpTo(v,e,l.data),e.reload&&this.reloadTarget(I(e.reload,l.data),l.data),[2]}})})}).catch(function(f){}):u.alert("当 actionType 为 ajax 时,请设置 api 属性");if(e.actionType==="reload")e.target&&this.reloadTarget(I(e.target,a),a);else if(e.actionType==="goto-step"){var m=a.step;m!==void 0&&m<=i.length&&m>=0&&this.gotoStep(a.step)}else e.actionType==="submit"?this.finalSubmit():h&&h(t,e,a,n,s||this.context)}},r.prototype.handleQuery=function(t){if(this.props.initApi){if(t!=null&&t.hasOwnProperty("orderBy")&&!$(this.props.initApi,this.props.initApi,this.props.store.data,N(this.props.store.data,t)))return!1;this.receive(t);return}return this.props.onQuery?this.props.onQuery(t):!1},r.prototype.openFeedback=function(t,e){var a=this;return new Promise(function(n){var s=a.props.store;s.setCurrentAction({type:"button",actionType:"dialog",dialog:t},a.props.resolveDefinitions),s.openDialog(e,void 0,function(o){n(o)},a.context)})},r.prototype.handleChange=function(t){return D(this,void 0,void 0,function(){var e,a,n;return E(this,function(s){switch(s.label){case 0:return e=this.props.store,a=e.data,n=w(w({},a),t),[4,this.dispatchEvent("change",n)];case 1:return s.sent()?[2]:(e.updateData(t),[2])}})})},r.prototype.handleInit=function(t){var e=this.state.currentStep;this.initalValues[e]=this.initalValues[e]||t;var a=this.props.store;a.updateData(t)},r.prototype.handleReset=function(t){var e=this.props.store,a=this.initalValues[this.state.currentStep],n={};Object.keys(t).forEach(function(s){n[s]=a.hasOwnProperty(s)?a[s]:void 0}),e.updateData(n)},r.prototype.finalSubmit=function(t,e){return t===void 0&&(t={}),e===void 0&&(e={type:"submit"}),D(this,void 0,void 0,function(){var a,n,s,o,p,h,l,u,i,m,f,d,v,g,C,F,b=this;return E(this,function(_){switch(_.label){case 0:return a=this.props,n=a.store,s=a.api,o=a.asyncApi,p=a.finishedField,h=a.target,l=a.redirect,u=a.reload,i=a.env,m=a.onFinished,f=this.state.rawSteps,[4,this.dispatchEvent("finished",n.data)];case 1:if(_.sent())return[2];if(d=f[this.state.currentStep-1],n.updateData(t),h)this.submitToTarget(I(h,n.data),n.data),this.setState({completeStep:f.length});else if(e.api||d.api||s)v=e.asyncApi||d.asyncApi||o,T(v,n.data)&&n.updateData((F={},F[p||"finished"]=!1,F)),g=this.form?this.form.props.store:n,n.markSaving(!0),g.saveRemote(e.api||d.api||s,n.data,{onSuccess:function(y){return D(b,void 0,void 0,function(){var S,R,P=this;return E(this,function(W){switch(W.label){case 0:return[4,this.dispatchEvent("submitSucc",N(this.props.data,{result:y}))];case 1:return S=W.sent(),!T(v,n.data)||n.data[p||"finished"]?[2,{cbResult:null,dispatcher:S}]:(R=j(function(){return n.checkRemote(v,n.data)},function(L){return L&&L[p||"finished"]},function(L){return P.asyncCancel=L}),[2,{cbResult:R,dispatcher:S}])}})})},onFailed:function(y){return D(b,void 0,void 0,function(){var S;return E(this,function(R){switch(R.label){case 0:return n.markSaving(!1),[4,this.dispatchEvent("submitFail",N(this.props.data,{error:y}))];case 1:return S=R.sent(),[2,{dispatcher:S}]}})})}}).then(function(y){return D(b,void 0,void 0,function(){var S,R,P;return E(this,function(W){switch(W.label){case 0:return S=e.feedback,S&&B(S,y)?[4,this.openFeedback(S,y)]:[3,2];case 1:if(R=W.sent(),S.skipRestOnCancel&&!R)throw new z;if(S.skipRestOnConfirm&&R)throw new z;W.label=2;case 2:if(this.setState({completeStep:f.length}),n.updateData(w(w({},n.data),y)),n.markSaving(!1),y&&typeof y.step=="number")this.gotoStep(y.step);else if(m&&m(y,e)===!1)return[2,y];return P=(e.redirect||d.redirect||l)&&V(e.redirect||d.redirect||l,n.data),P?i.jumpTo(P,e,n.data):(e.reload||d.reload||u)&&this.reloadTarget(I(e.reload||d.reload||u,n.data),n.data),[2,y]}})})}).catch(function(y){});else{if(this.setState({completeStep:f.length}),m&&m(n.data,e)===!1)return[2];C=(e.redirect||d.redirect||l)&&V(e.redirect||d.redirect||l,n.data),C?i.jumpTo(C,e,n.data):(e.reload||d.reload||u)&&this.reloadTarget(I(e.reload||d.reload||u,n.data),n.data)}return[2]}})})},r.prototype.handleSubmit=function(t,e){var a,n=this,s=this.props,o=s.store,p=s.finishedField,h=this.state.rawSteps;if(this.state.currentStep<h.length){var l=h[this.state.currentStep-1];o.updateData(t);var u=e.asyncApi||l.asyncApi;T(u,o.data)&&o.updateData((a={},a[p||"finished"]=!1,a)),T(e.api||l.api,o.data)?o.saveRemote(e.api||l.api,o.data,{onSuccess:function(){if(n.dispatchEvent("stepSubmitSucc"),!(!T(u,o.data)||o.data[p||"finished"]))return j(function(){return o.checkRemote(u,o.data)},function(i){return i&&i[p||"finished"]},function(i){return n.asyncCancel=i})},onFailed:function(i){n.dispatchEvent("stepSubmitFail",{error:i}),i.status===422&&i.errors&&n.form&&n.form.props.store.setFormItemErrors(i.errors)}}).then(function(i){return D(n,void 0,void 0,function(){var m,f;return E(this,function(d){switch(d.label){case 0:return m=e.feedback,m&&B(m,i)?[4,this.openFeedback(m,i)]:[3,2];case 1:if(f=d.sent(),m.skipRestOnCancel&&!f)throw new z;if(m.skipRestOnConfirm&&f)throw new z;d.label=2;case 2:return this.gotoStep(i&&typeof i.step=="number"?i.step:this.state.currentStep+1),[2]}})})}).catch(function(i){n.dispatchEvent("stepSubmitFail",{error:i})}):this.gotoStep(this.state.currentStep+1)}else this.finalSubmit(t,e);return!1},r.prototype.handleDialogConfirm=function(t,e,a){var n=this.props.store;e.mergeData&&t.length===1&&t[0]&&a[0].props.type==="form"&&n.updateData(t[0]),n.closeDialog(!0,t)},r.prototype.handleDialogClose=function(t){t===void 0&&(t=!1);var e=this.props.store;e.closeDialog(t)},r.prototype.handleJumpStep=function(t,e){var a=this.props.store,n=this.state.currentStep,s=U(e,t,n,a.data);s&&this.gotoStep(t+1)},r.prototype.renderSteps=function(){var t=this.props,e=t.mode,a=t.classPrefix,n=t.classnames,s=t.stepsClassName,o=this.state,p=o.currentStep,h=o.rawSteps;return x.createElement("div",{className:n("".concat(a,"-Wizard-steps"),s),id:"form-wizard"},Array.isArray(h)&&h.length?x.createElement(H,{steps:h,mode:e,current:p-1,onClickStep:this.handleJumpStep}):null)},r.prototype.renderActions=function(){var t=this,e=this.props,a=e.store,n=e.readOnly,s=e.disabled,o=e.actionClassName,p=e.actionPrevLabel,h=e.actionNextLabel,l=e.actionNextSaveLabel,u=e.actionFinishLabel,i=e.render,m=e.translate;e.classnames;var f=e.testIdBuilder,d=this.state.rawSteps;if(!Array.isArray(d))return null;var v=this.state.currentStep,g=d[v],C=d[v-2],F=a.loading,b=d[v-1];if(!b)return null;var _=C?U(C,v-2,v,a.data):!1;return b.actions&&Array.isArray(b.actions)?b.actions.length?x.createElement(x.Fragment,null,b.actions.map(function(y,S){return i("action/".concat(S),y,{key:S,data:N(t.props.data,{currentStep:v}),onAction:t.handleAction,disabled:y.disabled||F||s||y.actionType==="prev"&&!_||y.actionType==="next"&&n&&(!!b.api||!g)})})):null:x.createElement(x.Fragment,null,i("prev-btn",{type:"button",label:m(p),actionType:"prev",className:o,hiddenOn:"${currentStep === 1}",id:f==null?void 0:f.getChild("button-prev").getTestIdValue()},{disabled:F||!_||s,onAction:this.handleAction,data:N(this.props.data,{currentStep:v})}),i("next-btn",{type:"button",label:g?b.api?m(l):m(h):m(u),actionType:"next",primary:!g||!!b.api,className:o,level:"primary",id:f==null?void 0:f.getChild("button-next").getTestIdValue()},{disabled:F||s||n&&(!!b.api||!g),onAction:this.handleAction}))},r.prototype.renderFooter=function(){var t=this.renderActions();if(!t)return t;var e=this.props,a=e.classnames,n=e.affixFooter,s=e.footerClassName,o=e.wrapWithPanel;return x.createElement("div",{role:"wizard-footer",className:a("Wizard-footer",o?"Panel-footer":"",n&&o?"Panel-fixedBottom":"",s)},t)},r.prototype.renderWizard=function(){var t=this.props,e=t.className,a=t.steps,n=t.style,s=t.render,o=t.store,p=t.classPrefix,h=t.classnames,l=t.popOverContainer,u=t.mode,i=t.translate,m=t.loadingConfig,f=t.stepClassName,d=t.bodyClassName,v=t.wrapWithPanel,g=this.state,C=g.rawSteps,F=g.currentStep,b=Array.isArray(C)&&C.length>0?C:Array.isArray(a)?K([],X(a),!1).map(function(y){return delete y.hiddenOn,y}):null,_=Array.isArray(b)?b[F-1]:null;return x.createElement("div",{ref:this.domRef,className:h(v?"".concat(p,"Panel ").concat(p,"Panel--default"):"","".concat(p,"Wizard ").concat(p,"Wizard--").concat(u),e),style:n},x.createElement("div",{className:h("".concat(p,"Wizard-step"),f)},this.renderSteps(),x.createElement("div",{role:"wizard-body",className:h("".concat(p,"Wizard-stepContent clearfix"),d)},_?s("body",w(w({},_),{type:"form",wrapWithPanel:!1,api:null}),{key:this.state.currentStep,ref:this.formRef,onInit:this.handleInit,onReset:this.handleReset,onSubmit:this.handleSubmit,onAction:this.handleAction,onQuery:this.handleQuery,disabled:o.loading,popOverContainer:l||this.getPopOverContainer,onChange:this.handleChange,formStore:void 0}):F===-1?i("loading"):x.createElement("p",{className:"text-danger"},i("Wizard.configError"))),this.renderFooter()),s("dialog",w(w({},o.action&&o.action.dialog),{type:"dialog"}),{key:"dialog",data:o.dialogData,onConfirm:this.handleDialogConfirm,onClose:this.handleDialogClose,show:o.dialogOpen}),x.createElement(Y,{loadingConfig:m,size:"lg",overlay:!0,key:"info",show:o.loading}))},r.prototype.render=function(){return this.renderWizard()},r.defaultProps={mode:"horizontal",readOnly:!1,messages:{},actionClassName:"",actionPrevLabel:"Wizard.prev",actionNextLabel:"Wizard.next",actionNextSaveLabel:"Wizard.saveAndNext",actionFinishLabel:"Wizard.finish",startStep:"1",wrapWithPanel:!0},r.propsList=["steps","mode","messages","actionClassName","actionPrevLabel","actionNextLabel","actionNextSaveLabel","actionFinishLabel","onFinished","affixFooter","startStep"],O([k,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",void 0)],r.prototype,"formRef",null),O([k,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",void 0)],r.prototype,"domRef",null),O([k,c("design:type",Function),c("design:paramtypes",[]),c("design:returntype",void 0)],r.prototype,"getPopOverContainer",null),O([k,c("design:type",Function),c("design:paramtypes",[Object,Object,Object,Boolean,Object]),c("design:returntype",void 0)],r.prototype,"handleAction",null),O([k,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",void 0)],r.prototype,"handleQuery",null),O([k,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",Promise)],r.prototype,"handleChange",null),O([k,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",void 0)],r.prototype,"handleInit",null),O([k,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",void 0)],r.prototype,"handleReset",null),O([k,c("design:type",Function),c("design:paramtypes",[Object,Object]),c("design:returntype",void 0)],r.prototype,"handleSubmit",null),O([k,c("design:type",Function),c("design:paramtypes",[Array,Object,Array]),c("design:returntype",void 0)],r.prototype,"handleDialogConfirm",null),O([k,c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",void 0)],r.prototype,"handleDialogClose",null),O([k,c("design:type",Function),c("design:paramtypes",[Number,Object]),c("design:returntype",void 0)],r.prototype,"handleJumpStep",null),r}(x.Component);function U(A,r,t,e){var a=!1;return A&&A.hasOwnProperty("jumpable")?a=A.jumpable:A&&A.jumpableOn?a=Z(A.jumpableOn,N(e,{currentStep:t})):a=r+1<t,a}var re=function(A){G(r,A);function r(t,e){var a=A.call(this,t)||this,n=e;return n.registerComponent(a),a}return r.prototype.componentWillUnmount=function(){var t=this.context;t.unRegisterComponent(this),A.prototype.componentWillUnmount.call(this)},r.prototype.doAction=function(t,e,a){return this.handleAction(void 0,t,e)},r.prototype.submitToTarget=function(t,e){var a=this.context;a.send(t,e)},r.prototype.reloadTarget=function(t,e){var a=this.context;a.reload(t,e)},r.prototype.handleDialogConfirm=function(t,e,a){A.prototype.handleDialogConfirm.call(this,t,e,a);var n=this.props.store,s=this.context;e.reload?s.reload(e.reload,n.data):n.action&&n.action.reload&&s.reload(n.action.reload,n.data)},r.prototype.setData=function(t,e){return this.props.store.updateData(t,void 0,e)},r.prototype.getData=function(){var t=this.props.store;return t.data},r.contextType=q,O([k,c("design:type",Function),c("design:paramtypes",[Array,Object,Array]),c("design:returntype",void 0)],r.prototype,"handleDialogConfirm",null),r=O([ee({type:"wizard",storeType:te.name,isolateScope:!0}),c("design:paramtypes",[Object,Object])],r),r}(ne);export{re as WizardRenderer,ne as default};