Tasks-C4BAw-yJ.js 9.3 KB

1
  1. import{p as W,s as R,V as H,X as k,y as $,a3 as Y,f as l,O as I,T as Q,z as X,D as G,Q as J}from"./index-DT8qTvyx.js";var q={exports:{}};(function(A,u){Object.defineProperty(u,"__esModule",{value:!0});function r(t){return typeof t=="object"&&!("toString"in t)?Object.prototype.toString.call(t).slice(8,-1):t}var a=typeof process=="object"&&!0;function s(t,e){if(!t)throw a?new Error("Invariant failed"):new Error(e())}u.invariant=s;var c=Object.prototype.hasOwnProperty,y=Array.prototype.splice,T=Object.prototype.toString;function m(t){return T.call(t).slice(8,-1)}var v=Object.assign||function(t,e){return E(e).forEach(function(i){c.call(e,i)&&(t[i]=e[i])}),t},E=typeof Object.getOwnPropertySymbols=="function"?function(t){return Object.keys(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.keys(t)};function p(t){return Array.isArray(t)?v(t.constructor(t.length),t):m(t)==="Map"?new Map(t):m(t)==="Set"?new Set(t):t&&typeof t=="object"?v(Object.create(Object.getPrototypeOf(t)),t):t}var C=function(){function t(){this.commands=v({},S),this.update=this.update.bind(this),this.update.extend=this.extend=this.extend.bind(this),this.update.isEquals=function(e,i){return e===i},this.update.newContext=function(){return new t().update}}return Object.defineProperty(t.prototype,"isEquals",{get:function(){return this.update.isEquals},set:function(e){this.update.isEquals=e},enumerable:!0,configurable:!0}),t.prototype.extend=function(e,i){this.commands[e]=i},t.prototype.update=function(e,i){var n=this,o=typeof i=="function"?{$apply:i}:i;Array.isArray(e)&&Array.isArray(o)||s(!Array.isArray(o),function(){return"update(): You provided an invalid spec to update(). The spec may not contain an array except as the value of $set, $push, $unshift, $splice or any custom command allowing an array value."}),s(typeof o=="object"&&o!==null,function(){return"update(): You provided an invalid spec to update(). The spec and every included key path must be plain objects containing one of the "+("following commands: "+Object.keys(n.commands).join(", ")+".")});var f=e;return E(o).forEach(function(h){if(c.call(n.commands,h)){var U=e===f;f=n.commands[h](o[h],f,o,e),U&&n.isEquals(f,e)&&(f=e)}else{var L=m(e)==="Map"?n.update(e.get(h),o[h]):n.update(e[h],o[h]),z=m(f)==="Map"?f.get(h):f[h];(!n.isEquals(L,z)||typeof L>"u"&&!c.call(e,h))&&(f===e&&(f=p(e)),m(f)==="Map"?f.set(h,L):f[h]=L)}}),f},t}();u.Context=C;var S={$push:function(t,e,i){return b(e,i,"$push"),t.length?e.concat(t):e},$unshift:function(t,e,i){return b(e,i,"$unshift"),t.length?t.concat(e):e},$splice:function(t,e,i,n){return _(e,i),t.forEach(function(o){N(o),e===n&&o.length&&(e=p(n)),y.apply(e,o)}),e},$set:function(t,e,i){return B(i),t},$toggle:function(t,e){g(t,"$toggle");var i=t.length?p(e):e;return t.forEach(function(n){i[n]=!e[n]}),i},$unset:function(t,e,i,n){return g(t,"$unset"),t.forEach(function(o){Object.hasOwnProperty.call(e,o)&&(e===n&&(e=p(n)),delete e[o])}),e},$add:function(t,e,i,n){return w(e,"$add"),g(t,"$add"),m(e)==="Map"?t.forEach(function(o){var f=o[0],h=o[1];e===n&&e.get(f)!==h&&(e=p(n)),e.set(f,h)}):t.forEach(function(o){e===n&&!e.has(o)&&(e=p(n)),e.add(o)}),e},$remove:function(t,e,i,n){return w(e,"$remove"),g(t,"$remove"),t.forEach(function(o){e===n&&e.has(o)&&(e=p(n)),e.delete(o)}),e},$merge:function(t,e,i,n){return P(e,t),E(t).forEach(function(o){t[o]!==e[o]&&(e===n&&(e=p(n)),e[o]=t[o])}),e},$apply:function(t,e){return M(t),t(e)}},d=new C;u.isEquals=d.update.isEquals,u.extend=d.extend,u.default=d.update,u.default.default=A.exports=v(u.default,u);function b(t,e,i){s(Array.isArray(t),function(){return"update(): expected target of "+r(i)+" to be an array; got "+r(t)+"."}),g(e[i],i)}function g(t,e){s(Array.isArray(t),function(){return"update(): expected spec of "+r(e)+" to be an array; got "+r(t)+". Did you forget to wrap your parameter in an array?"})}function _(t,e){s(Array.isArray(t),function(){return"Expected $splice target to be an array; got "+r(t)}),N(e.$splice)}function N(t){s(Array.isArray(t),function(){return"update(): expected spec of $splice to be an array of arrays; got "+r(t)+". Did you forget to wrap your parameters in an array?"})}function M(t){s(typeof t=="function",function(){return"update(): expected spec of $apply to be a function; got "+r(t)+"."})}function B(t){s(Object.keys(t).length===1,function(){return"Cannot have more than one key in an object with $set"})}function P(t,e){s(e&&typeof e=="object",function(){return"update(): $merge expects a spec of type 'object'; got "+r(e)}),s(t&&typeof t=="object",function(){return"update(): $merge expects a target of type 'object'; got "+r(t)})}function w(t,e){var i=m(t);s(i==="Map"||i==="Set",function(){return"update(): "+r(e)+" expects a target of type Set or Map; got "+r(i)})}})(q,q.exports);var Z=q.exports;const D=W(Z);var x=function(A){R(u,A);function u(r){var a=A.call(this,r)||this;return a.state={items:r.items?r.items.concat():[]},a.handleLoaded=a.handleLoaded.bind(a),a.tick=a.tick.bind(a),a}return u.prototype.componentDidMount=function(){this.tick(!!this.props.checkApi)},u.prototype.componentDidUpdate=function(r){var a=this.props;r.items!==a.items?this.setState({items:a.items?a.items.concat():[]}):H(r.checkApi,a.checkApi,r.data,a.data)&&this.tick(!0)},u.prototype.componentWillUnmount=function(){clearTimeout(this.timer)},u.prototype.reload=function(){this.tick(!0)},u.prototype.tick=function(r){var a=this;r===void 0&&(r=!1);var s=this.props,c=s.loadingStatusCode,y=s.data,T=s.interval,m=s.checkApi,v=s.env,E=this.state.items;if(clearTimeout(this.timer),!(!r&&!E.some(function(p){return p.status===c}))){if(T&&!k(m))return v.alert("checkApi 没有设置, 不能及时获取任务状态");k(m,y)&&v&&v.fetcher(m,y).then(this.handleLoaded).catch(function(p){return a.setState({error:p})})}},u.prototype.handleLoaded=function(r){if(!Array.isArray(r.data))return this.props.env.alert("返回格式不正确, 期望 response.data 为数组, 包含每个 task 的状态信息");this.setState({items:r.data});var a=this.props.interval;clearTimeout(this.timer),this.timer=setTimeout(this.tick,a)},u.prototype.submitTask=function(r,a,s){var c=this;s===void 0&&(s=!1);var y=this.props,T=y.submitApi,m=y.reSubmitApi,v=y.loadingStatusCode,E=y.errorStatusCode,p=y.data,C=y.env;if(!s&&!k(T))return C.alert("submitApi 没有配置");if(s&&!k(m))return C.alert("reSubmitApi 没有配置");this.setState(D(this.state,{items:{$splice:[[a,1,$($({},r),{status:v})]]}}));var S=s?m:T;k(S,p)&&C&&C.fetcher(S,Y(p,r)).then(function(d){if(d&&d.data){if(Array.isArray(d.data))c.handleLoaded(d);else{S&&S.replaceData;var b=c.state.items.map(function(g){return g.key===d.data.key?$($({},S.replaceData?{}:g),d.data):g});c.handleLoaded($($({},d),{data:b}))}return}clearTimeout(c.timer),c.timer=setTimeout(c.tick,4)}).catch(function(d){return c.setState(D(c.state,{items:{$splice:[[a,1,$($({},r),{status:E,remark:d.message||d})]]}}))})},u.prototype.render=function(){var r=this,a=this.props,s=a.classnames,c=a.className,y=a.style,T=a.tableClassName,m=a.taskNameLabel,v=a.operationLabel,E=a.statusLabel,p=a.remarkLabel,C=a.btnText,S=a.retryBtnText,d=a.btnClassName,b=a.retryBtnClassName,g=a.statusLabelMap,_=a.statusTextMap,N=a.readyStatusCode,M=a.loadingStatusCode,B=a.canRetryStatusCode,P=a.translate,w=a.render,t=a.loadingConfig,e=this.state.items,i=this.state.error;return l.createElement("div",{className:s("Table-content",c),style:y},l.createElement("table",{className:s("Table-table",T)},l.createElement("thead",null,l.createElement("tr",null,l.createElement("th",null,m),l.createElement("th",null,P(v)),l.createElement("th",null,E),l.createElement("th",null,p))),l.createElement("tbody",null,i?l.createElement("tr",null,l.createElement("td",{colSpan:4},l.createElement("div",{className:"text-danger"},i))):e.map(function(n,o){return l.createElement("tr",{key:o},l.createElement("td",null,l.createElement("span",{className:s("word-break")},n.label)),l.createElement("td",null,n.status==M?l.createElement(I,{loadingConfig:t,show:!0,icon:"reload",spinnerClassName:s("Task-spinner")}):n.status==B?l.createElement("a",{onClick:function(){return r.submitTask(n,o,!0)},className:s("Button","Button--danger","Button--size-md",b||d)},S||C):l.createElement("a",{onClick:function(){return r.submitTask(n,o)},className:s("Button","Button--default","Button--size-md",d,{disabled:n.status!==N})},C)),l.createElement("td",null,l.createElement("span",{className:s("label",g&&g[n.status||0])},_&&_[n.status||0])),l.createElement("td",null,n.remark?w("".concat(o,"/remark"),n.remark):null))}))))},u.defaultProps={className:"",tableClassName:"",taskNameLabel:"任务名称",operationLabel:"Table.operation",statusLabel:"状态",remarkLabel:"备注说明",btnText:"上线",retryBtnText:"重试",btnClassName:"",retryBtnClassName:"",statusLabelMap:["label-warning","label-info","label-info","label-danger","label-success","label-danger"],statusTextMap:["未开始","就绪","进行中","出错","已完成","出错"],initialStatusCode:0,readyStatusCode:1,loadingStatusCode:2,errorStatusCode:3,finishStatusCode:4,canRetryStatusCode:5,interval:3e3},u}(l.Component),K=function(A){R(u,A);function u(r,a){var s=A.call(this,r)||this,c=a;return c.registerComponent(s),s}return u.prototype.componentWillUnmount=function(){A.prototype.componentWillUnmount.call(this);var r=this.context;r.unRegisterComponent(this)},u.contextType=Q,u=X([G({type:"tasks"}),J("design:paramtypes",[Object,Object])],u),u}(x);export{K as TaskRenderer,x as default};