villianjs-pro 1.0.20 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _iterable_to_array_limit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return g.next=verb(0),g["throw"]=verb(1),g["return"]=verb(2),typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}}import{useMemo,useEffect,useState,useRef,useCallback}from"react";import React from"react";import{Badge,Row,Col,Card,Alert,theme,Descriptions,Progress,Spin}from"antd";import{ProTable}from"../../ProTable";import{Modal}from"../../Modal";import{CheckCircleOutlined,CloseCircleOutlined,ExclamationCircleOutlined,LoadingOutlined}from"@ant-design/icons";import{formatDate}from"../utils/date";import{getContainerStyle,getStatCardStyle,getStatNumberStyle,getStatLabelStyle,getRowNumberStyle}from"../utils/styles";import{useLocale}from"../../locale";import{useImportContextOptional}from"../context/import-context";var useToken=theme.useToken;export var ImportDetailDialog=function(param){var open=param.open,onOpenChange=param.onOpenChange,record=param.record,errorColumns=param.errorColumns,queryImportErrors=param.queryImportErrors,errorTableProps=param.errorTableProps,contentRender=param.contentRender,propsQueryProgress=param.queryProgress,propsPollInterval=param.pollInterval;var _messages_imports_detail_processingDescription;var token=useToken().token;var messages=useLocale().messages;var context=useImportContextOptional();var queryProgress=propsQueryProgress!==null&&propsQueryProgress!==void 0?propsQueryProgress:context===null||context===void 0?void 0:context.queryProgress;var _ref;var pollInterval=(_ref=propsPollInterval!==null&&propsPollInterval!==void 0?propsPollInterval:context===null||context===void 0?void 0:context.pollInterval)!==null&&_ref!==void 0?_ref:2e3;var _useState=_sliced_to_array(useState(null),2),currentProgress=_useState[0],setCurrentProgress=_useState[1];var _useState1=_sliced_to_array(useState(record.status),2),currentStatus=_useState1[0],setCurrentStatus=_useState1[1];var _useState2=_sliced_to_array(useState(record),2),currentRecord=_useState2[0],setCurrentRecord=_useState2[1];var pollingRef=useRef(null);var isUnmountedRef=useRef(false);useEffect(function(){setCurrentRecord(record);setCurrentStatus(record.status)},[record]);var queryProgressRef=useRef(queryProgress);var recordIdRef=useRef(record.id);var currentStatusRef=useRef(currentStatus);useEffect(function(){queryProgressRef.current=queryProgress;recordIdRef.current=record.id;currentStatusRef.current=currentStatus},[queryProgress,record.id,currentStatus]);var fetchProgress=useCallback(function(){return _async_to_generator(function(){var progress,error;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(isUnmountedRef.current||!queryProgressRef.current||currentStatusRef.current!=="processing"){return[2]}_state.label=1;case 1:_state.trys.push([1,3,,4]);return[4,queryProgressRef.current(recordIdRef.current)];case 2:progress=_state.sent();if(isUnmountedRef.current)return[2];setCurrentProgress(progress);if(progress.status!==currentStatusRef.current){setCurrentStatus(progress.status);setCurrentRecord(function(prev){var _progress_success,_progress_failed,_progress_total;return _object_spread_props(_object_spread({},prev),{status:progress.status,success:(_progress_success=progress.success)!==null&&_progress_success!==void 0?_progress_success:prev.success,failed:(_progress_failed=progress.failed)!==null&&_progress_failed!==void 0?_progress_failed:prev.failed,total:(_progress_total=progress.total)!==null&&_progress_total!==void 0?_progress_total:prev.total})})}else{setCurrentRecord(function(prev){var _progress_success,_progress_failed,_progress_total;return _object_spread_props(_object_spread({},prev),{success:(_progress_success=progress.success)!==null&&_progress_success!==void 0?_progress_success:prev.success,failed:(_progress_failed=progress.failed)!==null&&_progress_failed!==void 0?_progress_failed:prev.failed,total:(_progress_total=progress.total)!==null&&_progress_total!==void 0?_progress_total:prev.total})})}if(progress.status==="completed"||progress.status==="failed"){if(pollingRef.current){clearInterval(pollingRef.current);pollingRef.current=null}}return[3,4];case 3:error=_state.sent();console.error("查询导入进度失败:",error);return[3,4];case 4:return[2]}})})()},[]);useEffect(function(){if(!open){if(pollingRef.current){clearInterval(pollingRef.current);pollingRef.current=null}isUnmountedRef.current=true;return}isUnmountedRef.current=false;if(currentStatus==="processing"&&queryProgress){fetchProgress();pollingRef.current=setInterval(function(){fetchProgress()},pollInterval)}return function(){if(pollingRef.current){clearInterval(pollingRef.current);pollingRef.current=null}isUnmountedRef.current=true}},[open,currentStatus,queryProgress,pollInterval,fetchProgress]);var formattedCreatedAt=useMemo(function(){if(!record.createdAt)return"";try{var date=new Date(record.createdAt);if(isNaN(date.getTime())){return record.createdAt}return formatDate(date,"YYYY-MM-DD HH:mm:ss")}catch(e){return record.createdAt}},[record.createdAt]);var containerStyle=useMemo(function(){return getContainerStyle(token)},[token]);var statCardStyle=useMemo(function(){return getStatCardStyle(token)},[token]);var statNumberStyle=useMemo(function(){return getStatNumberStyle(token)},[token]);var statLabelStyle=useMemo(function(){return getStatLabelStyle(token)},[token]);var defaultErrorColumns=useMemo(function(){return[{title:messages.imports.detail.errorColumns.rowNumber,dataIndex:"row_number",key:"row_number",width:120,valueType:"digit",render:function(_,recordItem){return React.createElement("span",{style:getRowNumberStyle(token)},messages.imports.detail.rowNumberText.replace("{rowNumber}",String(recordItem.row_number)))}},{title:messages.imports.detail.errorColumns.errorType,dataIndex:"error_type",key:"error_type",width:160,valueType:"text"},{title:messages.imports.detail.errorColumns.errorMessage,dataIndex:"error_message",key:"error_message",valueType:"text",ellipsis:true},{title:messages.imports.detail.errorColumns.errorId,dataIndex:"id",key:"id",width:220,valueType:"text",copyable:true}]},[messages]);var finalErrorColumns=useMemo(function(){if(errorColumns&&errorColumns.length>0){return errorColumns}return defaultErrorColumns},[errorColumns,defaultErrorColumns]);var errorRequest=useMemo(function(){if(!queryImportErrors){return function(){return _async_to_generator(function(){return _ts_generator(this,function(_state){return[2,{data:[],success:true,total:0}]})})()}}return function(params){return _async_to_generator(function(){var result,error;return _ts_generator(this,function(_state){switch(_state.label){case 0:_state.trys.push([0,2,,3]);return[4,queryImportErrors(_object_spread({importId:currentRecord.id},params))];case 1:result=_state.sent();return[2,{data:result.list||[],success:true,total:result.total||0}];case 2:error=_state.sent();console.error(messages.imports.detail.queryFailed,error);return[2,{data:[],success:false,total:0}];case 3:return[2]}})})()}},[queryImportErrors,currentRecord.id,messages]);var progressPercent=useMemo(function(){if(currentProgress){return Math.round(currentProgress.progress||0)}if(currentRecord.total>0){return Math.round((currentRecord.success+currentRecord.failed)/currentRecord.total*100)}return 0},[currentProgress,currentRecord]);var headerNode=React.createElement(React.Fragment,null,React.createElement(Descriptions,{column:3,size:"small",labelStyle:{fontSize:token.fontSizeSM,color:token.colorTextSecondary},contentStyle:{fontSize:token.fontSizeSM,color:token.colorText}},React.createElement(Descriptions.Item,{label:messages.imports.detail.labels.importId,span:3},React.createElement("span",{style:{fontFamily:"monospace",fontWeight:token.fontWeightStrong}},currentRecord.id)),React.createElement(Descriptions.Item,{label:messages.imports.detail.labels.currentStatus,span:1},React.createElement("div",null,currentStatus==="completed"&&React.createElement(Badge,{status:"success",text:messages.imports.detail.status.completed}),currentStatus==="failed"&&React.createElement(Badge,{status:"error",text:messages.imports.detail.status.failed}),currentStatus==="processing"&&React.createElement(Badge,{status:"processing",text:messages.imports.detail.status.processing}))),React.createElement(Descriptions.Item,{label:messages.imports.detail.labels.importTime,span:2},React.createElement("span",{style:{fontWeight:token.fontWeightStrong}},formattedCreatedAt))),currentStatus==="processing"&&React.createElement("div",{style:{padding:token.padding,background:token.colorInfoBg,borderRadius:token.borderRadius,marginBottom:token.margin,border:"1px solid ".concat(token.colorInfoBorder)}},React.createElement("div",{style:{display:"flex",alignItems:"center",gap:token.marginSM,marginBottom:token.marginSM}},React.createElement(Spin,{indicator:React.createElement(LoadingOutlined,{style:{fontSize:token.fontSizeLG,color:token.colorInfo},spin:true})}),React.createElement("div",{style:{flex:1}},React.createElement("div",{style:{fontSize:token.fontSize,fontWeight:token.fontWeightStrong,color:token.colorText,marginBottom:token.marginXXS}},messages.imports.detail.processingTitle||"正在处理导入任务..."),React.createElement("div",{style:{fontSize:token.fontSizeSM,color:token.colorTextSecondary}},((_messages_imports_detail_processingDescription=messages.imports.detail.processingDescription)===null||_messages_imports_detail_processingDescription===void 0?void 0:_messages_imports_detail_processingDescription.replace("{current}",String(currentRecord.success+currentRecord.failed)).replace("{total}",String(currentRecord.total)))||"已处理 ".concat(currentRecord.success+currentRecord.failed," / ").concat(currentRecord.total," 条数据")))),React.createElement(Progress,{percent:progressPercent,strokeColor:token.colorInfo,showInfo:true})),React.createElement(Row,{gutter:token.margin,style:{marginInline:0}},React.createElement(Col,{span:8},React.createElement(Card,{variant:"outlined",styles:{body:_object_spread_props(_object_spread({},statCardStyle),{background:token.colorBgContainer})}},React.createElement("p",{style:_object_spread_props(_object_spread({},statNumberStyle),{color:token.colorText})},currentRecord.total),React.createElement("p",{style:statLabelStyle},messages.imports.detail.stats.total))),React.createElement(Col,{span:8},React.createElement(Card,{variant:"outlined",styles:{body:_object_spread_props(_object_spread({},statCardStyle),{background:token.colorSuccessBg,borderColor:token.colorSuccessBorder})}},React.createElement("p",{style:_object_spread_props(_object_spread({},statNumberStyle),{color:token.colorSuccess})},currentRecord.success),React.createElement("p",{style:_object_spread_props(_object_spread({},statLabelStyle),{color:token.colorSuccessText})},messages.imports.detail.stats.success))),React.createElement(Col,{span:8},React.createElement(Card,{variant:"outlined",styles:{body:_object_spread_props(_object_spread({},statCardStyle),{background:token.colorErrorBg,borderColor:token.colorErrorBorder})}},React.createElement("p",{style:_object_spread_props(_object_spread({},statNumberStyle),{color:token.colorError})},currentRecord.failed),React.createElement("p",{style:_object_spread_props(_object_spread({},statLabelStyle),{color:token.colorErrorText})},messages.imports.detail.stats.failed)))));var failedTableNode=currentRecord.failed>0&&queryImportErrors&&currentStatus!=="processing"?React.createElement("div",null,React.createElement("div",{style:{display:"flex",alignItems:"center",gap:token.marginXS,marginBottom:token.marginSM}},React.createElement(ExclamationCircleOutlined,{style:{color:token.colorError}}),React.createElement("h3",{style:{fontSize:token.fontSize,fontWeight:token.fontWeightStrong,color:token.colorText,margin:0}},messages.imports.detail.failedDataTitle)),React.createElement(ProTable,_object_spread({rowKey:"id",columns:finalErrorColumns,request:errorRequest,search:false,pagination:{defaultPageSize:10,showSizeChanger:true,showQuickJumper:true},size:"small",showCreateBtn:false,showBatchRemoveBtn:false,showViewBtn:false,showUpdateBtn:false,showRemoveBtn:false,rowButtonItems:[],scroll:{x:800}},errorTableProps))):null;var bodyContent=contentRender?contentRender({record:currentRecord,defaultHeader:headerNode,defaultFailedTable:failedTableNode}):React.createElement(React.Fragment,null,headerNode,failedTableNode,currentStatus==="completed"&&currentRecord.failed===0&&React.createElement(Alert,{message:messages.imports.detail.successAlert,type:"success",icon:React.createElement(CheckCircleOutlined,null)}),currentStatus==="failed"&&React.createElement(Alert,{message:messages.imports.detail.failedAlert.message,description:messages.imports.detail.failedAlert.description,type:"error",icon:React.createElement(CloseCircleOutlined,null)}));return React.createElement(Modal,{title:messages.imports.detail.title,open:open,onCancel:function(){return onOpenChange(false)},footer:null,width:1e3,centered:false,destroyOnHidden:true,styles:{body:{maxHeight:"90vh",overflowY:"auto"}}},React.createElement("div",{style:containerStyle},bodyContent))};
1
+ function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _iterable_to_array_limit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return g.next=verb(0),g["throw"]=verb(1),g["return"]=verb(2),typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}}import{useMemo,useEffect,useState,useRef,useCallback}from"react";import React from"react";import{Tag,Row,Col,Card,Alert,theme,Descriptions,Progress,Spin}from"antd";import{ProTable}from"../../ProTable";import{Modal}from"../../Modal";import{CheckCircleOutlined,CloseCircleOutlined,ExclamationCircleOutlined,LoadingOutlined}from"@ant-design/icons";import{formatDate}from"../utils/date";import{getContainerStyle,getStatCardStyle,getStatNumberStyle,getStatLabelStyle,getRowNumberStyle}from"../utils/styles";import{useLocale}from"../../locale";import{useImportContextOptional}from"../context/import-context";var useToken=theme.useToken;export var ImportDetailDialog=function(param){var open=param.open,onOpenChange=param.onOpenChange,record=param.record,errorColumns=param.errorColumns,queryImportErrors=param.queryImportErrors,errorTableProps=param.errorTableProps,contentRender=param.contentRender,propsQueryProgress=param.queryProgress,propsPollInterval=param.pollInterval;var _messages_imports_detail_processingDescription;var token=useToken().token;var messages=useLocale().messages;var context=useImportContextOptional();var queryProgress=propsQueryProgress!==null&&propsQueryProgress!==void 0?propsQueryProgress:context===null||context===void 0?void 0:context.queryProgress;var _ref;var pollInterval=(_ref=propsPollInterval!==null&&propsPollInterval!==void 0?propsPollInterval:context===null||context===void 0?void 0:context.pollInterval)!==null&&_ref!==void 0?_ref:2e3;var _useState=_sliced_to_array(useState(null),2),currentProgress=_useState[0],setCurrentProgress=_useState[1];var _useState1=_sliced_to_array(useState(record.status),2),currentStatus=_useState1[0],setCurrentStatus=_useState1[1];var _useState2=_sliced_to_array(useState(record),2),currentRecord=_useState2[0],setCurrentRecord=_useState2[1];var pollingRef=useRef(null);var isUnmountedRef=useRef(false);useEffect(function(){setCurrentRecord(record);setCurrentStatus(record.status)},[record]);var queryProgressRef=useRef(queryProgress);var recordIdRef=useRef(record.id);var currentStatusRef=useRef(currentStatus);useEffect(function(){queryProgressRef.current=queryProgress;recordIdRef.current=record.id;currentStatusRef.current=currentStatus},[queryProgress,record.id,currentStatus]);var fetchProgress=useCallback(function(){return _async_to_generator(function(){var progress,error;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(isUnmountedRef.current||!queryProgressRef.current||currentStatusRef.current!=="processing"){return[2]}_state.label=1;case 1:_state.trys.push([1,3,,4]);return[4,queryProgressRef.current(recordIdRef.current)];case 2:progress=_state.sent();if(isUnmountedRef.current)return[2];setCurrentProgress(progress);if(progress.status!==currentStatusRef.current){setCurrentStatus(progress.status);setCurrentRecord(function(prev){var _progress_success,_progress_failed,_progress_total;return _object_spread_props(_object_spread({},prev),{status:progress.status,success:(_progress_success=progress.success)!==null&&_progress_success!==void 0?_progress_success:prev.success,failed:(_progress_failed=progress.failed)!==null&&_progress_failed!==void 0?_progress_failed:prev.failed,total:(_progress_total=progress.total)!==null&&_progress_total!==void 0?_progress_total:prev.total})})}else{setCurrentRecord(function(prev){var _progress_success,_progress_failed,_progress_total;return _object_spread_props(_object_spread({},prev),{success:(_progress_success=progress.success)!==null&&_progress_success!==void 0?_progress_success:prev.success,failed:(_progress_failed=progress.failed)!==null&&_progress_failed!==void 0?_progress_failed:prev.failed,total:(_progress_total=progress.total)!==null&&_progress_total!==void 0?_progress_total:prev.total})})}if(progress.status==="completed"||progress.status==="failed"){if(pollingRef.current){clearInterval(pollingRef.current);pollingRef.current=null}}return[3,4];case 3:error=_state.sent();console.error("查询导入进度失败:",error);return[3,4];case 4:return[2]}})})()},[]);useEffect(function(){if(!open){if(pollingRef.current){clearInterval(pollingRef.current);pollingRef.current=null}isUnmountedRef.current=true;return}isUnmountedRef.current=false;if(currentStatus==="processing"&&queryProgress){fetchProgress();pollingRef.current=setInterval(function(){fetchProgress()},pollInterval)}return function(){if(pollingRef.current){clearInterval(pollingRef.current);pollingRef.current=null}isUnmountedRef.current=true}},[open,currentStatus,queryProgress,pollInterval,fetchProgress]);var formattedCreatedAt=useMemo(function(){if(!record.createdAt)return"";try{var date=new Date(record.createdAt);if(isNaN(date.getTime())){return record.createdAt}return formatDate(date,"YYYY-MM-DD HH:mm:ss")}catch(e){return record.createdAt}},[record.createdAt]);var containerStyle=useMemo(function(){return getContainerStyle(token)},[token]);var statCardStyle=useMemo(function(){return getStatCardStyle(token)},[token]);var statNumberStyle=useMemo(function(){return getStatNumberStyle(token)},[token]);var statLabelStyle=useMemo(function(){return getStatLabelStyle(token)},[token]);var successRate=useMemo(function(){if(currentRecord.total===0)return"0.0";return(currentRecord.success/currentRecord.total*100).toFixed(1)},[currentRecord.success,currentRecord.total]);var defaultErrorColumns=useMemo(function(){return[{title:messages.imports.detail.errorColumns.rowNumber,dataIndex:"row_number",key:"row_number",width:120,valueType:"digit",render:function(_,recordItem){return React.createElement("span",{style:getRowNumberStyle(token)},messages.imports.detail.rowNumberText.replace("{rowNumber}",String(recordItem.row_number)))}},{title:messages.imports.detail.errorColumns.errorType,dataIndex:"error_type",key:"error_type",width:160,valueType:"text"},{title:messages.imports.detail.errorColumns.errorMessage,dataIndex:"error_message",key:"error_message",valueType:"text",ellipsis:true},{title:messages.imports.detail.errorColumns.errorId,dataIndex:"id",key:"id",width:220,valueType:"text",copyable:true}]},[messages]);var finalErrorColumns=useMemo(function(){if(errorColumns&&errorColumns.length>0){return errorColumns}return defaultErrorColumns},[errorColumns,defaultErrorColumns]);var errorRequest=useMemo(function(){if(!queryImportErrors){return function(){return _async_to_generator(function(){return _ts_generator(this,function(_state){return[2,{data:[],success:true,total:0}]})})()}}return function(params){return _async_to_generator(function(){var result,error;return _ts_generator(this,function(_state){switch(_state.label){case 0:_state.trys.push([0,2,,3]);return[4,queryImportErrors(_object_spread({importId:currentRecord.id},params))];case 1:result=_state.sent();return[2,{data:result.list||[],success:true,total:result.total||0}];case 2:error=_state.sent();console.error(messages.imports.detail.queryFailed,error);return[2,{data:[],success:false,total:0}];case 3:return[2]}})})()}},[queryImportErrors,currentRecord.id,messages]);var progressPercent=useMemo(function(){if(currentProgress){return Math.round(currentProgress.progress||0)}if(currentRecord.total>0){return Math.round((currentRecord.success+currentRecord.failed)/currentRecord.total*100)}return 0},[currentProgress,currentRecord]);var headerNode=React.createElement(React.Fragment,null,React.createElement(Descriptions,{column:3,size:"small",labelStyle:{fontSize:token.fontSizeSM,color:token.colorTextSecondary},contentStyle:{fontSize:token.fontSizeSM,color:token.colorText}},React.createElement(Descriptions.Item,{label:messages.imports.detail.labels.importId,span:3},React.createElement("span",{style:{fontFamily:"monospace",fontWeight:token.fontWeightStrong}},currentRecord.id)),React.createElement(Descriptions.Item,{label:messages.imports.detail.labels.currentStatus,span:1},React.createElement("div",null,currentStatus==="completed"&&React.createElement(Tag,{color:"success"},messages.imports.detail.status.completed),currentStatus==="failed"&&React.createElement(Tag,{color:"error"},messages.imports.detail.status.failed),currentStatus==="processing"&&React.createElement(Tag,{color:"processing"},messages.imports.detail.status.processing))),React.createElement(Descriptions.Item,{label:messages.imports.detail.labels.importTime,span:2},React.createElement("span",{style:{fontWeight:token.fontWeightStrong}},formattedCreatedAt))),currentStatus==="processing"&&React.createElement("div",{style:{padding:token.padding,background:token.colorInfoBg,borderRadius:token.borderRadius,marginBottom:token.margin,border:"1px solid ".concat(token.colorInfoBorder)}},React.createElement("div",{style:{display:"flex",alignItems:"center",gap:token.marginSM,marginBottom:token.marginSM}},React.createElement(Spin,{indicator:React.createElement(LoadingOutlined,{style:{fontSize:token.fontSizeLG,color:token.colorInfo},spin:true})}),React.createElement("div",{style:{flex:1}},React.createElement("div",{style:{fontSize:token.fontSize,fontWeight:token.fontWeightStrong,color:token.colorText,marginBottom:token.marginXXS}},messages.imports.detail.processingTitle||"正在处理导入任务..."),React.createElement("div",{style:{fontSize:token.fontSizeSM,color:token.colorTextSecondary}},((_messages_imports_detail_processingDescription=messages.imports.detail.processingDescription)===null||_messages_imports_detail_processingDescription===void 0?void 0:_messages_imports_detail_processingDescription.replace("{current}",String(currentRecord.success+currentRecord.failed)).replace("{total}",String(currentRecord.total)))||"已处理 ".concat(currentRecord.success+currentRecord.failed," / ").concat(currentRecord.total," 条数据")))),React.createElement(Progress,{percent:progressPercent,strokeColor:token.colorInfo,showInfo:true})),React.createElement(Row,{gutter:token.margin,style:{marginInline:0}},React.createElement(Col,{span:6},React.createElement(Card,{variant:"outlined",styles:{body:_object_spread_props(_object_spread({},statCardStyle),{background:token.colorBgContainer})}},React.createElement("p",{style:_object_spread_props(_object_spread({},statNumberStyle),{color:token.colorText})},currentRecord.total),React.createElement("p",{style:statLabelStyle},messages.imports.detail.stats.total))),React.createElement(Col,{span:6},React.createElement(Card,{variant:"outlined",styles:{body:_object_spread_props(_object_spread({},statCardStyle),{background:token.colorSuccessBg,borderColor:token.colorSuccessBorder})}},React.createElement("p",{style:_object_spread_props(_object_spread({},statNumberStyle),{color:token.colorSuccess})},currentRecord.success),React.createElement("p",{style:_object_spread_props(_object_spread({},statLabelStyle),{color:token.colorSuccessText})},messages.imports.detail.stats.success))),React.createElement(Col,{span:6},React.createElement(Card,{variant:"outlined",styles:{body:_object_spread_props(_object_spread({},statCardStyle),{background:token.colorErrorBg,borderColor:token.colorErrorBorder})}},React.createElement("p",{style:_object_spread_props(_object_spread({},statNumberStyle),{color:token.colorError})},currentRecord.failed),React.createElement("p",{style:_object_spread_props(_object_spread({},statLabelStyle),{color:token.colorErrorText})},messages.imports.detail.stats.failed))),React.createElement(Col,{span:6},React.createElement(Card,{variant:"outlined",styles:{body:_object_spread_props(_object_spread({},statCardStyle),{background:token.colorInfoBg,borderColor:token.colorInfoBorder})}},React.createElement("p",{style:_object_spread_props(_object_spread({},statNumberStyle),{color:token.colorInfo})},successRate,"%"),React.createElement("p",{style:_object_spread_props(_object_spread({},statLabelStyle),{color:token.colorInfoText})},messages.imports.importResult.successRate||"成功率")))));var failedTableNode=currentRecord.failed>0&&queryImportErrors&&currentStatus!=="processing"?React.createElement("div",null,React.createElement(ProTable,_object_spread({rowKey:"id",columns:finalErrorColumns,request:errorRequest,search:false,pagination:{defaultPageSize:10,showSizeChanger:true,showQuickJumper:true},size:"small",showCreateBtn:false,showBatchRemoveBtn:false,showViewBtn:false,showUpdateBtn:false,showRemoveBtn:false,rowButtonItems:[],headerButtonItems:[{key:"title",label:messages.imports.detail.failedDataTitle,icon:React.createElement(ExclamationCircleOutlined,{style:{color:token.colorError}}),isCustom:true,component:React.createElement("div",{style:{display:"flex",alignItems:"center",gap:8}},React.createElement(ExclamationCircleOutlined,{style:{color:token.colorError}}),React.createElement("h3",{style:{fontSize:14,fontWeight:600,color:token.colorText,margin:0}},messages.imports.detail.failedDataTitle))}],scroll:{x:800}},errorTableProps))):null;var bodyContent=contentRender?contentRender({record:currentRecord,defaultHeader:headerNode,defaultFailedTable:failedTableNode}):React.createElement(React.Fragment,null,headerNode,failedTableNode,currentStatus==="completed"&&currentRecord.failed===0&&React.createElement(Alert,{message:messages.imports.detail.successAlert,type:"success",icon:React.createElement(CheckCircleOutlined,null)}),currentStatus==="failed"&&React.createElement(Alert,{message:messages.imports.detail.failedAlert.message,description:messages.imports.detail.failedAlert.description,type:"error",icon:React.createElement(CloseCircleOutlined,null)}));return React.createElement(Modal,{title:messages.imports.detail.title,open:open,onCancel:function(){return onOpenChange(false)},footer:null,width:1e3,centered:false,destroyOnHidden:true,styles:{body:{maxHeight:"90vh",overflowY:"auto"}}},React.createElement("div",{style:containerStyle},bodyContent))};
@@ -1,6 +1,6 @@
1
1
  import { type FC } from "react";
2
2
  import { type ModalProps } from "../../Modal";
3
- import type { UploadConfig, UploadResult, QueryImportProgress, ImportProgressStepRender, UploadStepConfig, CancelImport } from "../types";
3
+ import type { UploadConfig, UploadResult, QueryImportProgress, ImportProgressStepRender, UploadStepConfig, CancelImport, CancelUpload } from "../types";
4
4
  export type CustomModalProps = Omit<ModalProps, "open" | "onOpenChange" | "footer" | "onCancel">;
5
5
  export interface ImportModalProps {
6
6
  title: string;
@@ -11,6 +11,7 @@ export interface ImportModalProps {
11
11
  onDownloadTemplate?: () => Promise<void> | void;
12
12
  queryProgress?: QueryImportProgress;
13
13
  cancelImport?: CancelImport;
14
+ cancelUpload?: CancelUpload;
14
15
  pollInterval?: number;
15
16
  modalProps?: CustomModalProps;
16
17
  importProgressStepRender?: ImportProgressStepRender;
@@ -1 +1 @@
1
- function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _iterable_to_array_limit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return g.next=verb(0),g["throw"]=verb(1),g["return"]=verb(2),typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}}import{useState,useMemo,useEffect,useCallback,memo,useRef}from"react";import{message}from"antd";import React from"react";import{Modal}from"../../Modal";import{UploadStep}from"./upload-step";import{UploadProgressStep}from"./upload-progress-step";import{ImportProgressStep}from"./import-progress-step";import{ImportResultStep}from"./import-result-step";import{handleImportError,validateUploadResult}from"../utils/error-handler";import{useImportContextOptional}from"../context/import-context";import{useLocale}from"../../locale";export var ImportModal=memo(function(param){var title=param.title,open=param.open,onClose=param.onClose,propsOnFileSelect=param.onFileSelect,propsOnDownloadTemplate=param.onDownloadTemplate,propsQueryProgress=param.queryProgress,propsCancelImport=param.cancelImport,propsPollInterval=param.pollInterval,modalProps=param.modalProps,propsTaskKey=param.taskKey,propsImportProgressStepRender=param.importProgressStepRender,propsTips=param.tips,propsUploadStepConfig=param.uploadStepConfig;var context=useImportContextOptional();var _ref;var taskKey=(_ref=propsTaskKey!==null&&propsTaskKey!==void 0?propsTaskKey:context===null||context===void 0?void 0:context.taskKey)!==null&&_ref!==void 0?_ref:"id";var queryProgress=propsQueryProgress!==null&&propsQueryProgress!==void 0?propsQueryProgress:context===null||context===void 0?void 0:context.queryProgress;var cancelImport=propsCancelImport!==null&&propsCancelImport!==void 0?propsCancelImport:context===null||context===void 0?void 0:context.cancelImport;var importProgressStepRender=propsImportProgressStepRender!==null&&propsImportProgressStepRender!==void 0?propsImportProgressStepRender:context===null||context===void 0?void 0:context.importProgressStepRender;var onDownloadTemplate=propsOnDownloadTemplate!==null&&propsOnDownloadTemplate!==void 0?propsOnDownloadTemplate:context===null||context===void 0?void 0:context.onDownloadTemplate;var onFileSelect=propsOnFileSelect!==null&&propsOnFileSelect!==void 0?propsOnFileSelect:context===null||context===void 0?void 0:context.onFileSelect;var tips=propsTips!==null&&propsTips!==void 0?propsTips:context===null||context===void 0?void 0:context.tips;var uploadStepConfig=propsUploadStepConfig!==null&&propsUploadStepConfig!==void 0?propsUploadStepConfig:context===null||context===void 0?void 0:context.uploadStepConfig;var pollInterval=propsPollInterval!==null&&propsPollInterval!==void 0?propsPollInterval:context===null||context===void 0?void 0:context.pollInterval;var _useState=_sliced_to_array(useState("upload"),2),step=_useState[0],setStep=_useState[1];var _useState1=_sliced_to_array(useState(null),2),importId=_useState1[0],setImportId=_useState1[1];var _useState2=_sliced_to_array(useState(null),2),uploadResult=_useState2[0],setUploadResult=_useState2[1];var _useState3=_sliced_to_array(useState(0),2),uploadProgress=_useState3[0],setUploadProgress=_useState3[1];var _useState4=_sliced_to_array(useState(null),2),importResult=_useState4[0],setImportResult=_useState4[1];var uploadAbortControllerRef=useRef(null);var messages=useLocale().messages;useEffect(function(){if(!open){var timer=setTimeout(function(){setStep("upload");setUploadProgress(0);setImportId(null);setUploadResult(null);setImportResult(null);if(uploadAbortControllerRef.current){uploadAbortControllerRef.current.abort();uploadAbortControllerRef.current=null}},300);return function(){return clearTimeout(timer)}}return undefined},[open]);var handleFileSelect=useCallback(function(file){return _async_to_generator(function(){var abortController,uploadConfig,result,error,_uploadAbortControllerRef_current,errorMessage;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!onFileSelect){throw new Error(messages.imports.errors.uploadMethodNotSet)}_state.label=1;case 1:_state.trys.push([1,3,,4]);setStep("uploading");setUploadProgress(0);abortController=new AbortController;uploadAbortControllerRef.current=abortController;uploadConfig={headers:{"Content-Type":"multipart/form-data"},abortController:abortController,onUploadProgress:function(event){if(event.total){var percent=Math.round(event.loaded/event.total*100);setUploadProgress(percent)}}};return[4,onFileSelect(file,uploadConfig)];case 2:result=_state.sent();if(abortController.signal.aborted){setStep("upload");setUploadProgress(0);uploadAbortControllerRef.current=null;return[2]}if(validateUploadResult(result,taskKey)){setImportId(result[taskKey]);setUploadResult(result);uploadAbortControllerRef.current=null;setStep("importing")}else{throw new Error(messages.imports.errors.uploadFailed)}return[3,4];case 3:error=_state.sent();if((error===null||error===void 0?void 0:error.name)==="AbortError"||((_uploadAbortControllerRef_current=uploadAbortControllerRef.current)===null||_uploadAbortControllerRef_current===void 0?void 0:_uploadAbortControllerRef_current.signal.aborted)){setStep("upload");setUploadProgress(0);uploadAbortControllerRef.current=null;return[2]}setStep("upload");setUploadProgress(0);uploadAbortControllerRef.current=null;errorMessage=handleImportError(error,messages.imports.errors.uploadError);message.error(errorMessage);throw error;case 4:return[2]}})})()},[onFileSelect,taskKey,messages]);var handleCancelUpload=useCallback(function(){if(uploadAbortControllerRef.current){uploadAbortControllerRef.current.abort();uploadAbortControllerRef.current=null}setStep("upload");setUploadProgress(0)},[]);var handleImportComplete=useCallback(function(result){setImportResult(result);setStep("result")},[]);var handleClose=useCallback(function(){onClose()},[onClose]);var handleOpenChange=useCallback(function(visible){if(!visible){handleClose()}},[handleClose]);var stepTitleMap={upload:messages.imports.stepTitles.upload,uploading:messages.imports.stepTitles.uploading,importing:messages.imports.stepTitles.importing,result:messages.imports.stepTitles.result};var currentTitle=useMemo(function(){return stepTitleMap[step]||title},[step,title]);return React.createElement(Modal.CustomModal,_object_spread({title:currentTitle,open:open,onOpenChange:handleOpenChange,footer:false,onCancel:handleClose,maskClosable:false,width:600},modalProps),step==="upload"&&React.createElement(UploadStep,{onFileSelect:handleFileSelect,onDownloadTemplate:onDownloadTemplate,tips:tips,config:uploadStepConfig}),step==="uploading"&&React.createElement(UploadProgressStep,{progress:uploadProgress,onCancel:handleCancelUpload}),step==="importing"&&importId&&React.createElement(ImportProgressStep,{importId:importId,uploadResult:uploadResult||undefined,onComplete:handleImportComplete,onClose:handleClose,queryProgress:queryProgress,cancelImport:cancelImport,pollInterval:pollInterval,importProgressStepRender:importProgressStepRender}),step==="result"&&importResult&&React.createElement(ImportResultStep,{result:importResult,onClose:handleClose}))});ImportModal.displayName="ImportModal";
1
+ function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _iterable_to_array_limit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return g.next=verb(0),g["throw"]=verb(1),g["return"]=verb(2),typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}}import{useState,useMemo,useEffect,useCallback,memo}from"react";import{message}from"antd";import React from"react";import{Modal}from"../../Modal";import{UploadStep}from"./upload-step";import{UploadProgressStep}from"./upload-progress-step";import{ImportProgressStep}from"./import-progress-step";import{ImportResultStep}from"./import-result-step";import{handleImportError,validateUploadResult}from"../utils/error-handler";import{useImportContextOptional}from"../context/import-context";import{useLocale}from"../../locale";export var ImportModal=memo(function(param){var title=param.title,open=param.open,onClose=param.onClose,propsOnFileSelect=param.onFileSelect,propsOnDownloadTemplate=param.onDownloadTemplate,propsQueryProgress=param.queryProgress,propsCancelImport=param.cancelImport,propsCancelUpload=param.cancelUpload,propsPollInterval=param.pollInterval,modalProps=param.modalProps,propsTaskKey=param.taskKey,propsImportProgressStepRender=param.importProgressStepRender,propsTips=param.tips,propsUploadStepConfig=param.uploadStepConfig;var context=useImportContextOptional();var _ref;var taskKey=(_ref=propsTaskKey!==null&&propsTaskKey!==void 0?propsTaskKey:context===null||context===void 0?void 0:context.taskKey)!==null&&_ref!==void 0?_ref:"id";var queryProgress=propsQueryProgress!==null&&propsQueryProgress!==void 0?propsQueryProgress:context===null||context===void 0?void 0:context.queryProgress;var cancelImport=propsCancelImport!==null&&propsCancelImport!==void 0?propsCancelImport:context===null||context===void 0?void 0:context.cancelImport;var cancelUpload=propsCancelUpload!==null&&propsCancelUpload!==void 0?propsCancelUpload:context===null||context===void 0?void 0:context.cancelUpload;var importProgressStepRender=propsImportProgressStepRender!==null&&propsImportProgressStepRender!==void 0?propsImportProgressStepRender:context===null||context===void 0?void 0:context.importProgressStepRender;var onDownloadTemplate=propsOnDownloadTemplate!==null&&propsOnDownloadTemplate!==void 0?propsOnDownloadTemplate:context===null||context===void 0?void 0:context.onDownloadTemplate;var onFileSelect=propsOnFileSelect!==null&&propsOnFileSelect!==void 0?propsOnFileSelect:context===null||context===void 0?void 0:context.onFileSelect;var tips=propsTips!==null&&propsTips!==void 0?propsTips:context===null||context===void 0?void 0:context.tips;var uploadStepConfig=propsUploadStepConfig!==null&&propsUploadStepConfig!==void 0?propsUploadStepConfig:context===null||context===void 0?void 0:context.uploadStepConfig;var pollInterval=propsPollInterval!==null&&propsPollInterval!==void 0?propsPollInterval:context===null||context===void 0?void 0:context.pollInterval;var _useState=_sliced_to_array(useState("upload"),2),step=_useState[0],setStep=_useState[1];var _useState1=_sliced_to_array(useState(null),2),importId=_useState1[0],setImportId=_useState1[1];var _useState2=_sliced_to_array(useState(null),2),uploadResult=_useState2[0],setUploadResult=_useState2[1];var _useState3=_sliced_to_array(useState(0),2),uploadProgress=_useState3[0],setUploadProgress=_useState3[1];var _useState4=_sliced_to_array(useState(null),2),importResult=_useState4[0],setImportResult=_useState4[1];var messages=useLocale().messages;useEffect(function(){if(!open){var timer=setTimeout(function(){setStep("upload");setUploadProgress(0);setImportId(null);setUploadResult(null);setImportResult(null)},300);return function(){return clearTimeout(timer)}}return undefined},[open]);var handleFileSelect=useCallback(function(file){return _async_to_generator(function(){var uploadConfig,result,error,errorMessage;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!onFileSelect){throw new Error(messages.imports.errors.uploadMethodNotSet)}_state.label=1;case 1:_state.trys.push([1,3,,4]);setStep("uploading");setUploadProgress(0);uploadConfig={headers:{"Content-Type":"multipart/form-data"},onUploadProgress:function(event){if(event.total){var percent=Math.round(event.loaded/event.total*100);setUploadProgress(percent)}}};return[4,onFileSelect(file,uploadConfig)];case 2:result=_state.sent();if(validateUploadResult(result,taskKey)){setImportId(result[taskKey]);setUploadResult(result);setStep("importing")}else{throw new Error(messages.imports.errors.uploadFailed)}return[3,4];case 3:error=_state.sent();setStep("upload");setUploadProgress(0);errorMessage=handleImportError(error,messages.imports.errors.uploadError);message.error(errorMessage);throw error;case 4:return[2]}})})()},[onFileSelect,taskKey,messages]);var handleCancelUpload=useCallback(function(){return _async_to_generator(function(){var shouldCancel,error;return _ts_generator(this,function(_state){switch(_state.label){case 0:if(!cancelUpload){return[2]}_state.label=1;case 1:_state.trys.push([1,3,,4]);return[4,cancelUpload()];case 2:shouldCancel=_state.sent();if(shouldCancel){setStep("upload");setUploadProgress(0)}return[3,4];case 3:error=_state.sent();console.error("取消上传失败:",error);return[3,4];case 4:return[2]}})})()},[cancelUpload]);var handleImportComplete=useCallback(function(result){setImportResult(result);setStep("result")},[]);var handleClose=useCallback(function(){onClose()},[onClose]);var handleOpenChange=useCallback(function(visible){if(!visible){handleClose()}},[handleClose]);var stepTitleMap={upload:messages.imports.stepTitles.upload,uploading:messages.imports.stepTitles.uploading,importing:messages.imports.stepTitles.importing,result:messages.imports.stepTitles.result};var currentTitle=useMemo(function(){return stepTitleMap[step]||title},[step,title]);return React.createElement(Modal.CustomModal,_object_spread({title:currentTitle,open:open,onOpenChange:handleOpenChange,footer:false,onCancel:handleClose,maskClosable:false,width:600},modalProps),step==="upload"&&React.createElement(UploadStep,{onFileSelect:handleFileSelect,onDownloadTemplate:onDownloadTemplate,tips:tips,config:uploadStepConfig}),step==="uploading"&&React.createElement(UploadProgressStep,{progress:uploadProgress,onCancel:cancelUpload?handleCancelUpload:undefined}),step==="importing"&&importId&&React.createElement(ImportProgressStep,{importId:importId,uploadResult:uploadResult||undefined,onComplete:handleImportComplete,onClose:handleClose,queryProgress:queryProgress,cancelImport:cancelImport,pollInterval:pollInterval,importProgressStepRender:importProgressStepRender}),step==="result"&&importResult&&React.createElement(ImportResultStep,{result:importResult,onClose:handleClose}))});ImportModal.displayName="ImportModal";
@@ -1,5 +1,5 @@
1
1
  import type { FC, ReactNode } from 'react';
2
- import type { QueryImportProgress, ImportProgressStepRender, UploadStepConfig, UploadConfig, UploadResult, QueryImportRecords, ImportRecord, CancelImport } from '../types';
2
+ import type { QueryImportProgress, ImportProgressStepRender, UploadStepConfig, UploadConfig, UploadResult, QueryImportRecords, ImportRecord, CancelImport, CancelUpload } from '../types';
3
3
  import type { ProFormColumnsType } from '../../Form/types';
4
4
  import type { ProColumns } from '@ant-design/pro-components';
5
5
  import type { ImportErrorItem, QueryImportErrors, ImportDetailContentRender } from '../types';
@@ -13,6 +13,8 @@ export interface ImportContextValue {
13
13
  queryProgress?: QueryImportProgress;
14
14
  /** 取消导入接口 */
15
15
  cancelImport?: CancelImport;
16
+ /** 取消上传接口 */
17
+ cancelUpload?: CancelUpload;
16
18
  /** 自定义进度步骤渲染函数 */
17
19
  importProgressStepRender?: ImportProgressStepRender;
18
20
  /** 下载模板回调 */
@@ -1 +1 @@
1
- import{createContext,useContext,useMemo}from"react";import React from"react";var ImportContext=createContext(null);export var ImportContextProvider=function(param){var value=param.value,children=param.children;var contextValue=useMemo(function(){return value},[value.taskKey,value.queryProgress,value.cancelImport,value.importProgressStepRender,value.onDownloadTemplate,value.onFileSelect,value.queryImportRecords,value.importRecordColumns,value.importRecordTableProps,value.queryImportErrors,value.importErrorColumns,value.importErrorTableProps,value.importDetailContentRender,value.tips,value.uploadStepConfig,value.pollInterval]);return React.createElement(ImportContext.Provider,{value:contextValue},children)};export var useImportContext=function(){var context=useContext(ImportContext);if(!context){throw new Error("useImportContext must be used within ImportContextProvider")}return context};export var useImportContextOptional=function(){return useContext(ImportContext)};
1
+ import{createContext,useContext,useMemo}from"react";import React from"react";var ImportContext=createContext(null);export var ImportContextProvider=function(param){var value=param.value,children=param.children;var contextValue=useMemo(function(){return value},[value.taskKey,value.queryProgress,value.cancelImport,value.cancelUpload,value.importProgressStepRender,value.onDownloadTemplate,value.onFileSelect,value.queryImportRecords,value.importRecordColumns,value.importRecordTableProps,value.queryImportErrors,value.importErrorColumns,value.importErrorTableProps,value.importDetailContentRender,value.tips,value.uploadStepConfig,value.pollInterval]);return React.createElement(ImportContext.Provider,{value:contextValue},children)};export var useImportContext=function(){var context=useContext(ImportContext);if(!context){throw new Error("useImportContext must be used within ImportContextProvider")}return context};export var useImportContextOptional=function(){return useContext(ImportContext)};
@@ -1,7 +1,7 @@
1
1
  import { type FC } from "react";
2
2
  import type { ButtonProps } from "../Button";
3
3
  import { type CustomModalProps } from "./components/import-modal";
4
- import type { ImportProgressStepRender, UploadConfig, UploadResult, QueryImportProgress, UploadStepConfig, CancelImport } from "./types";
4
+ import type { ImportProgressStepRender, UploadConfig, UploadResult, QueryImportProgress, UploadStepConfig, CancelImport, CancelUpload } from "./types";
5
5
  export interface ImportsProps {
6
6
  primaryText?: string;
7
7
  secondaryText?: string;
@@ -10,6 +10,7 @@ export interface ImportsProps {
10
10
  modalProps?: CustomModalProps;
11
11
  queryProgress?: QueryImportProgress;
12
12
  cancelImport?: CancelImport;
13
+ cancelUpload?: CancelUpload;
13
14
  onModalClose?: () => void;
14
15
  taskKey?: string;
15
16
  importProgressStepRender?: ImportProgressStepRender;
@@ -1 +1 @@
1
- function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _iterable_to_array_limit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}import{useState,useMemo,memo}from"react";import React from"react";import{Flex}from"antd";import{Button}from"../Button";import{CloudDownloadOutlined,HistoryOutlined}from"@ant-design/icons";import{ImportModal}from"./components/import-modal";import{ImportHistoryDialog}from"./components/import-history-dialog";import{ImportContextProvider,useImportContextOptional}from"./context/import-context";import{useLocale}from"../locale";var ImportsInner=memo(function(param){var primaryText=param.primaryText,secondaryText=param.secondaryText,primaryButtonProps=param.primaryButtonProps,secondaryButtonProps=param.secondaryButtonProps,modalProps=param.modalProps,onModalClose=param.onModalClose,taskKey=param.taskKey,importProgressStepRender=param.importProgressStepRender,onDownloadTemplate=param.onDownloadTemplate,onFileSelect=param.onFileSelect,queryProgress=param.queryProgress,cancelImport=param.cancelImport,tips=param.tips,uploadStepConfig=param.uploadStepConfig;var messages=useLocale().messages;var _useState=_sliced_to_array(useState(false),2),isModalOpen=_useState[0],setIsModalOpen=_useState[1];var _useState1=_sliced_to_array(useState(false),2),isHistoryDialogOpen=_useState1[0],setIsHistoryDialogOpen=_useState1[1];var context=useImportContextOptional();var finalPrimaryText=primaryText!==null&&primaryText!==void 0?primaryText:messages.imports.primaryText;var finalSecondaryText=secondaryText!==null&&secondaryText!==void 0?secondaryText:messages.imports.secondaryText;var handleCloseModal=function(){setIsModalOpen(false);onModalClose===null||onModalClose===void 0?void 0:onModalClose()};var handleOpenHistoryDialog=function(){setIsHistoryDialogOpen(true)};var handleCloseHistoryDialog=function(){setIsHistoryDialogOpen(false)};var _ref;var finalTaskKey=(_ref=taskKey!==null&&taskKey!==void 0?taskKey:context===null||context===void 0?void 0:context.taskKey)!==null&&_ref!==void 0?_ref:"id";var finalQueryProgress=queryProgress!==null&&queryProgress!==void 0?queryProgress:context===null||context===void 0?void 0:context.queryProgress;var finalCancelImport=cancelImport!==null&&cancelImport!==void 0?cancelImport:context===null||context===void 0?void 0:context.cancelImport;var finalImportProgressStepRender=importProgressStepRender!==null&&importProgressStepRender!==void 0?importProgressStepRender:context===null||context===void 0?void 0:context.importProgressStepRender;var finalOnDownloadTemplate=onDownloadTemplate!==null&&onDownloadTemplate!==void 0?onDownloadTemplate:context===null||context===void 0?void 0:context.onDownloadTemplate;var finalOnFileSelect=onFileSelect!==null&&onFileSelect!==void 0?onFileSelect:context===null||context===void 0?void 0:context.onFileSelect;var finalTips=tips!==null&&tips!==void 0?tips:context===null||context===void 0?void 0:context.tips;var finalUploadStepConfig=uploadStepConfig!==null&&uploadStepConfig!==void 0?uploadStepConfig:context===null||context===void 0?void 0:context.uploadStepConfig;var finalPollInterval=context===null||context===void 0?void 0:context.pollInterval;var finalQueryImportRecords=context===null||context===void 0?void 0:context.queryImportRecords;var finalImportRecordColumns=context===null||context===void 0?void 0:context.importRecordColumns;var finalImportRecordTableProps=context===null||context===void 0?void 0:context.importRecordTableProps;return React.createElement(Flex,{justify:"start",align:"center",gap:10},React.createElement(Button,_object_spread_props(_object_spread({key:"import-opt",type:"primary",icon:React.createElement(CloudDownloadOutlined,null)},primaryButtonProps),{onClick:function(){setIsModalOpen(true)}}),finalPrimaryText),React.createElement(Button,_object_spread_props(_object_spread({key:"import-record",icon:React.createElement(HistoryOutlined,null)},secondaryButtonProps),{onClick:handleOpenHistoryDialog}),finalSecondaryText),React.createElement(ImportModal,{title:finalPrimaryText,open:isModalOpen,onClose:handleCloseModal,modalProps:modalProps,taskKey:finalTaskKey,queryProgress:finalQueryProgress,cancelImport:finalCancelImport,importProgressStepRender:finalImportProgressStepRender,onDownloadTemplate:finalOnDownloadTemplate,onFileSelect:finalOnFileSelect,tips:finalTips,uploadStepConfig:finalUploadStepConfig,pollInterval:finalPollInterval}),React.createElement(ImportHistoryDialog,{open:isHistoryDialogOpen,onOpenChange:handleCloseHistoryDialog,columns:finalImportRecordColumns,queryImportRecords:finalQueryImportRecords,tableProps:finalImportRecordTableProps}))});ImportsInner.displayName="ImportsInner";export var Imports=function(props){var context=useImportContextOptional();if(context){return React.createElement(ImportsInner,props)}var contextValue=useMemo(function(){var _props_taskKey;return{taskKey:(_props_taskKey=props.taskKey)!==null&&_props_taskKey!==void 0?_props_taskKey:"id",queryProgress:props.queryProgress,cancelImport:props.cancelImport,importProgressStepRender:props.importProgressStepRender,onDownloadTemplate:props.onDownloadTemplate,onFileSelect:props.onFileSelect,tips:props.tips,uploadStepConfig:props.uploadStepConfig,pollInterval:props.pollInterval}},[props.taskKey,props.queryProgress,props.cancelImport,props.importProgressStepRender,props.onDownloadTemplate,props.onFileSelect,props.tips,props.uploadStepConfig,props.pollInterval]);return React.createElement(ImportContextProvider,{value:contextValue},React.createElement(ImportsInner,props))};
1
+ function _array_like_to_array(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _array_with_holes(arr){if(Array.isArray(arr))return arr}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _iterable_to_array_limit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"]!=null)_i["return"]()}finally{if(_d)throw _e}}return _arr}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _sliced_to_array(arr,i){return _array_with_holes(arr)||_iterable_to_array_limit(arr,i)||_unsupported_iterable_to_array(arr,i)||_non_iterable_rest()}function _unsupported_iterable_to_array(o,minLen){if(!o)return;if(typeof o==="string")return _array_like_to_array(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(o,minLen)}import{useState,useMemo,memo}from"react";import React from"react";import{Flex}from"antd";import{Button}from"../Button";import{CloudDownloadOutlined,HistoryOutlined}from"@ant-design/icons";import{ImportModal}from"./components/import-modal";import{ImportHistoryDialog}from"./components/import-history-dialog";import{ImportContextProvider,useImportContextOptional}from"./context/import-context";import{useLocale}from"../locale";var ImportsInner=memo(function(param){var primaryText=param.primaryText,secondaryText=param.secondaryText,primaryButtonProps=param.primaryButtonProps,secondaryButtonProps=param.secondaryButtonProps,modalProps=param.modalProps,onModalClose=param.onModalClose,taskKey=param.taskKey,importProgressStepRender=param.importProgressStepRender,onDownloadTemplate=param.onDownloadTemplate,onFileSelect=param.onFileSelect,queryProgress=param.queryProgress,cancelImport=param.cancelImport,cancelUpload=param.cancelUpload,tips=param.tips,uploadStepConfig=param.uploadStepConfig;var messages=useLocale().messages;var _useState=_sliced_to_array(useState(false),2),isModalOpen=_useState[0],setIsModalOpen=_useState[1];var _useState1=_sliced_to_array(useState(false),2),isHistoryDialogOpen=_useState1[0],setIsHistoryDialogOpen=_useState1[1];var context=useImportContextOptional();var finalPrimaryText=primaryText!==null&&primaryText!==void 0?primaryText:messages.imports.primaryText;var finalSecondaryText=secondaryText!==null&&secondaryText!==void 0?secondaryText:messages.imports.secondaryText;var handleCloseModal=function(){setIsModalOpen(false);onModalClose===null||onModalClose===void 0?void 0:onModalClose()};var handleOpenHistoryDialog=function(){setIsHistoryDialogOpen(true)};var handleCloseHistoryDialog=function(){setIsHistoryDialogOpen(false)};var _ref;var finalTaskKey=(_ref=taskKey!==null&&taskKey!==void 0?taskKey:context===null||context===void 0?void 0:context.taskKey)!==null&&_ref!==void 0?_ref:"id";var finalQueryProgress=queryProgress!==null&&queryProgress!==void 0?queryProgress:context===null||context===void 0?void 0:context.queryProgress;var finalCancelImport=cancelImport!==null&&cancelImport!==void 0?cancelImport:context===null||context===void 0?void 0:context.cancelImport;var finalCancelUpload=cancelUpload!==null&&cancelUpload!==void 0?cancelUpload:context===null||context===void 0?void 0:context.cancelUpload;var finalImportProgressStepRender=importProgressStepRender!==null&&importProgressStepRender!==void 0?importProgressStepRender:context===null||context===void 0?void 0:context.importProgressStepRender;var finalOnDownloadTemplate=onDownloadTemplate!==null&&onDownloadTemplate!==void 0?onDownloadTemplate:context===null||context===void 0?void 0:context.onDownloadTemplate;var finalOnFileSelect=onFileSelect!==null&&onFileSelect!==void 0?onFileSelect:context===null||context===void 0?void 0:context.onFileSelect;var finalTips=tips!==null&&tips!==void 0?tips:context===null||context===void 0?void 0:context.tips;var finalUploadStepConfig=uploadStepConfig!==null&&uploadStepConfig!==void 0?uploadStepConfig:context===null||context===void 0?void 0:context.uploadStepConfig;var finalPollInterval=context===null||context===void 0?void 0:context.pollInterval;var finalQueryImportRecords=context===null||context===void 0?void 0:context.queryImportRecords;var finalImportRecordColumns=context===null||context===void 0?void 0:context.importRecordColumns;var finalImportRecordTableProps=context===null||context===void 0?void 0:context.importRecordTableProps;return React.createElement(Flex,{justify:"start",align:"center",gap:10},React.createElement(Button,_object_spread_props(_object_spread({key:"import-opt",type:"primary",icon:React.createElement(CloudDownloadOutlined,null)},primaryButtonProps),{onClick:function(){setIsModalOpen(true)}}),finalPrimaryText),React.createElement(Button,_object_spread_props(_object_spread({key:"import-record",icon:React.createElement(HistoryOutlined,null)},secondaryButtonProps),{onClick:handleOpenHistoryDialog}),finalSecondaryText),React.createElement(ImportModal,{title:finalPrimaryText,open:isModalOpen,onClose:handleCloseModal,modalProps:modalProps,taskKey:finalTaskKey,queryProgress:finalQueryProgress,cancelImport:finalCancelImport,cancelUpload:finalCancelUpload,importProgressStepRender:finalImportProgressStepRender,onDownloadTemplate:finalOnDownloadTemplate,onFileSelect:finalOnFileSelect,tips:finalTips,uploadStepConfig:finalUploadStepConfig,pollInterval:finalPollInterval}),React.createElement(ImportHistoryDialog,{open:isHistoryDialogOpen,onOpenChange:handleCloseHistoryDialog,columns:finalImportRecordColumns,queryImportRecords:finalQueryImportRecords,tableProps:finalImportRecordTableProps}))});ImportsInner.displayName="ImportsInner";export var Imports=function(props){var context=useImportContextOptional();if(context){return React.createElement(ImportsInner,props)}var contextValue=useMemo(function(){var _props_taskKey;return{taskKey:(_props_taskKey=props.taskKey)!==null&&_props_taskKey!==void 0?_props_taskKey:"id",queryProgress:props.queryProgress,cancelImport:props.cancelImport,cancelUpload:props.cancelUpload,importProgressStepRender:props.importProgressStepRender,onDownloadTemplate:props.onDownloadTemplate,onFileSelect:props.onFileSelect,tips:props.tips,uploadStepConfig:props.uploadStepConfig,pollInterval:props.pollInterval}},[props.taskKey,props.queryProgress,props.cancelImport,props.cancelUpload,props.importProgressStepRender,props.onDownloadTemplate,props.onFileSelect,props.tips,props.uploadStepConfig,props.pollInterval]);return React.createElement(ImportContextProvider,{value:contextValue},React.createElement(ImportsInner,props))};
@@ -30,8 +30,6 @@ export interface UploadProgressEvent {
30
30
  export interface UploadConfig {
31
31
  headers?: Record<string, string>;
32
32
  onUploadProgress?: (event: UploadProgressEvent) => void;
33
- /** 取消上传的 AbortController */
34
- abortController?: AbortController;
35
33
  }
36
34
  /**
37
35
  * 上传结果
@@ -78,6 +76,11 @@ export type QueryImportProgress = (importId: string, uploadResult?: UploadResult
78
76
  * 取消导入的函数类型
79
77
  */
80
78
  export type CancelImport = (importId: string, uploadResult?: UploadResult) => Promise<void>;
79
+ /**
80
+ * 取消上传的函数类型
81
+ * 返回 true 表示取消成功,false 表示取消失败或不允许取消
82
+ */
83
+ export type CancelUpload = () => Promise<boolean>;
81
84
  export type ImportProgressStepRender = (progress: ImportProgress, uploadResult: UploadResult) => ReactNode;
82
85
  /**
83
86
  * 上传步骤配置
@@ -1 +1 @@
1
- function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}export var getContainerStyle=function(token){var compact=arguments.length>1&&arguments[1]!==void 0?arguments[1]:false;return{display:"flex",flexDirection:"column",gap:token.marginLG,padding:compact?"".concat(token.paddingSM,"px 0"):"".concat(token.padding,"px 0")}};export var getCenterContentStyle=function(token){var compact=arguments.length>1&&arguments[1]!==void 0?arguments[1]:false;return{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:compact?token.marginSM:token.margin}};export var getTextCenterStyle=function(){return{textAlign:"center"}};export var getButtonGroupStyle=function(token){return{display:"flex",gap:token.marginSM,justifyContent:"center"}};export var getCardBodyStyle=function(token){return{background:token.colorFillTertiary}};export var getTipCardStyle=function(token){return{borderRadius:token.borderRadius,background:token.colorInfoBg,padding:token.padding,fontSize:token.fontSizeSM,color:token.colorInfoText}};export var getTipTitleStyle=function(token){return{margin:"0 0 ".concat(token.marginXS,"px 0"),fontWeight:token.fontWeightStrong}};export var getTipListStyle=function(token){return{margin:0,paddingLeft:token.paddingLG,listStyle:"disc"}};export var getTipItemStyle=function(token){return{marginBottom:token.marginXXS}};export var getHiddenInputStyle=function(){return{display:"none"}};export var getDescriptionStyle=function(token){return{fontSize:token.fontSizeSM,display:"block",marginBottom:token.marginSM}};export var getTitleStyle=function(token){var size=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"medium";var sizes={small:{fontSize:token.fontSizeLG,fontWeight:token.fontWeightStrong},medium:{fontSize:token.fontSizeXL,fontWeight:token.fontWeightStrong},large:{fontSize:token.fontSizeXL*1.2,fontWeight:token.fontWeightStrong}};return _object_spread_props(_object_spread({},sizes[size]),{color:token.colorText,margin:0})};export var getSubtitleStyle=function(token){return{fontSize:token.fontSizeSM,color:token.colorTextSecondary,marginTop:token.marginXXS}};export var getProgressTextStyle=function(token){return{fontSize:token.fontSizeSM,color:token.colorTextSecondary,marginTop:token.marginXXS}};export var getAlertStyle=function(token){return{borderRadius:token.borderRadius,background:token.colorWarningBg,border:"1px solid ".concat(token.colorWarningBorder),padding:token.padding}};export var getSummaryCardStyle=function(token){return{borderRadius:token.borderRadius,background:token.colorFillTertiary,border:"1px solid ".concat(token.colorBorder),padding:token.padding}};export var getSummaryTitleStyle=function(token){return{fontSize:token.fontSize,fontWeight:token.fontWeightStrong,color:token.colorText,marginBottom:token.marginSM,marginTop:0}};export var getSummaryItemStyle=function(token){return{display:"flex",justifyContent:"space-between",fontSize:token.fontSizeSM,marginBottom:token.marginXS}};export var getIconContainerStyle=function(){return{position:"relative"}};export var getIconSmallStyle=function(token){return{position:"absolute",right:-token.marginXS,top:-token.marginXS}};export var getStatCardStyle=function(token){return{borderRadius:token.borderRadius,padding:token.padding,textAlign:"center"}};export var getStatNumberStyle=function(token){return{fontSize:token.fontSizeXL*1.2,fontWeight:token.fontWeightStrong,margin:0}};export var getStatLabelStyle=function(token){return{fontSize:token.fontSizeSM,color:token.colorTextSecondary,marginTop:token.marginXS}};export var getRowNumberStyle=function(token){return{fontFamily:"monospace",fontSize:token.fontSizeSM}};
1
+ function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}export var getContainerStyle=function(token){var compact=arguments.length>1&&arguments[1]!==void 0?arguments[1]:false;return{display:"flex",flexDirection:"column",gap:token.marginMD,padding:compact?"".concat(token.paddingSM,"px 0"):"".concat(token.padding,"px 0")}};export var getCenterContentStyle=function(token){var compact=arguments.length>1&&arguments[1]!==void 0?arguments[1]:false;return{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:compact?token.marginSM:token.margin}};export var getTextCenterStyle=function(){return{textAlign:"center"}};export var getButtonGroupStyle=function(token){return{display:"flex",gap:token.marginSM,justifyContent:"center"}};export var getCardBodyStyle=function(token){return{background:token.colorFillTertiary}};export var getTipCardStyle=function(token){return{borderRadius:token.borderRadius,background:token.colorInfoBg,padding:token.padding,fontSize:token.fontSizeSM,color:token.colorInfoText}};export var getTipTitleStyle=function(token){return{margin:"0 0 ".concat(token.marginXS,"px 0"),fontWeight:token.fontWeightStrong}};export var getTipListStyle=function(token){return{margin:0,paddingLeft:token.paddingLG,listStyle:"disc"}};export var getTipItemStyle=function(token){return{marginBottom:token.marginXXS}};export var getHiddenInputStyle=function(){return{display:"none"}};export var getDescriptionStyle=function(token){return{fontSize:token.fontSizeSM,display:"block",marginBottom:token.marginSM}};export var getTitleStyle=function(token){var size=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"medium";var sizes={small:{fontSize:token.fontSizeLG,fontWeight:token.fontWeightStrong},medium:{fontSize:token.fontSizeXL,fontWeight:token.fontWeightStrong},large:{fontSize:token.fontSizeXL*1.2,fontWeight:token.fontWeightStrong}};return _object_spread_props(_object_spread({},sizes[size]),{color:token.colorText,margin:0})};export var getSubtitleStyle=function(token){return{fontSize:token.fontSizeSM,color:token.colorTextSecondary,marginTop:token.marginXXS}};export var getProgressTextStyle=function(token){return{fontSize:token.fontSizeSM,color:token.colorTextSecondary,marginTop:token.marginXXS}};export var getAlertStyle=function(token){return{borderRadius:token.borderRadius,background:token.colorWarningBg,border:"1px solid ".concat(token.colorWarningBorder),padding:token.padding}};export var getSummaryCardStyle=function(token){return{borderRadius:token.borderRadius,background:token.colorFillTertiary,border:"1px solid ".concat(token.colorBorder),padding:token.padding}};export var getSummaryTitleStyle=function(token){return{fontSize:token.fontSize,fontWeight:token.fontWeightStrong,color:token.colorText,marginBottom:token.marginSM,marginTop:0}};export var getSummaryItemStyle=function(token){return{display:"flex",justifyContent:"space-between",fontSize:token.fontSizeSM,marginBottom:token.marginXS}};export var getIconContainerStyle=function(){return{position:"relative"}};export var getIconSmallStyle=function(token){return{position:"absolute",right:-token.marginXS,top:-token.marginXS}};export var getStatCardStyle=function(token){return{borderRadius:token.borderRadius,padding:token.padding,textAlign:"center"}};export var getStatNumberStyle=function(token){return{fontSize:token.fontSizeXL*1.2,fontWeight:token.fontWeightStrong,margin:0}};export var getStatLabelStyle=function(token){return{fontSize:token.fontSizeSM,color:token.colorTextSecondary,marginTop:token.marginXS}};export var getRowNumberStyle=function(token){return{fontFamily:"monospace",fontSize:token.fontSizeSM}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "villianjs-pro",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",