xydata-tools 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.
package/README.md
CHANGED
|
@@ -114,13 +114,21 @@ export default Demo;
|
|
|
114
114
|
import React from 'react';
|
|
115
115
|
import { DownloadFile } from 'xydata-tools';
|
|
116
116
|
|
|
117
|
+
// 文件名一定需要加上后缀
|
|
117
118
|
const Demo = () => {
|
|
118
119
|
const [form] = Form.useForm();
|
|
119
120
|
|
|
120
121
|
return <DownloadFile
|
|
121
122
|
shape="round"
|
|
122
123
|
type="link"
|
|
123
|
-
queryOption={{
|
|
124
|
+
queryOption={{
|
|
125
|
+
url: "/api/tb/exportTbExcel",
|
|
126
|
+
params: { peopleType: 0 },
|
|
127
|
+
customField: {
|
|
128
|
+
url: "exportFileUrl",
|
|
129
|
+
fileName: "exportFileName",
|
|
130
|
+
}
|
|
131
|
+
}}
|
|
124
132
|
/>
|
|
125
133
|
};
|
|
126
134
|
|
|
@@ -131,7 +139,14 @@ export default Demo;
|
|
|
131
139
|
| 参数名 | 类型 | 描述 | 默认值 |
|
|
132
140
|
| --- | --- | --- | --- |
|
|
133
141
|
| text | String / ReactNode | 按钮内容 | 下载按钮 |
|
|
134
|
-
| queryOption | Object | 下载设置 |
|
|
142
|
+
| queryOption | Object | 下载设置 | |
|
|
143
|
+
| queryOption.url | String | 接口地址 | |
|
|
144
|
+
| queryOption.method | String | GET/POST | |
|
|
145
|
+
| queryOption.fileName | String | 文件名称 | |
|
|
146
|
+
| queryOption.params | Object | 请求参数 | |
|
|
147
|
+
| queryOption.customField | String | 自定义返回接口返回的文件名和地址(返回json适用),如返回值为res.data.exportFileName时,customField: { url:'exportFileUrl'fileName:'exportFileName'} | |
|
|
148
|
+
| queryOption.onError | Function | 接口异常回调 | |
|
|
149
|
+
| queryOption.downloadType | String | 下载类型,类型pure意为传入的是一个下载地址(oss链接),而不是一个下载接口(/api) | |
|
|
135
150
|
| 其他 | - | - | 兼容Antd.Button所有原生参数 |
|
|
136
151
|
|
|
137
152
|
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}function _regeneratorRuntime(){"use strict";_regeneratorRuntime=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,r,e){t[r]=e.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var i=r&&r.prototype instanceof m?r:m,a=Object.create(i.prototype),c=new A(n||[]);return o(a,"_invoke",{value:S(t,e,c)}),a}function s(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=f;var y="suspendedStart",h="suspendedYield",p="executing",v="completed",d={};function m(){}function g(){}function b(){}var w={};l(w,a,(function(){return this}));var _=Object.getPrototypeOf,j=_&&_(_(k([])));j&&j!==e&&n.call(j,a)&&(w=j);var O=b.prototype=m.prototype=Object.create(w);function x(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function L(t,r){function e(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==_typeof(f)&&n.call(f,"__await")?r.resolve(f.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new r((function(r,o){e(t,n,r,o)}))}return i=i?i.then(o,o):o()}})}function S(r,e,n){var o=y;return function(i,a){if(o===p)throw new Error("Generator is already running");if(o===v){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=E(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===y)throw o=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=p;var l=s(r,e,n);if("normal"===l.type){if(o=n.done?v:h,l.arg===d)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(o=v,n.method="throw",n.arg=l.arg)}}}function E(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,E(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=s(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function P(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function T(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function k(r){if(r||""===r){var e=r[a];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,i=function e(){for(;++o<r.length;)if(n.call(r,o))return e.value=r[o],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(_typeof(r)+" is not iterable")}return g.prototype=b,o(O,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:g,configurable:!0}),g.displayName=l(b,u,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===g||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,u,"GeneratorFunction")),t.prototype=Object.create(O),t},r.awrap=function(t){return{__await:t}},x(L.prototype),l(L.prototype,c,(function(){return this})),r.AsyncIterator=L,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new L(f(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(O),l(O,u,"Generator"),l(O,a,(function(){return this})),l(O,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=k,A.prototype={constructor:A,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function o(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(u&&l){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),T(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;T(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:k(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},r}function asyncGeneratorStep(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(t){return function(){var r=this,e=arguments;return new Promise((function(n,o){var i=t.apply(r,e);function a(t){asyncGeneratorStep(i,n,o,a,c,"next",t)}function c(t){asyncGeneratorStep(i,n,o,a,c,"throw",t)}a(void 0)}))}}function ownKeys(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function _objectSpread(t){for(var r=1;r<arguments.length;r++){var e=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(e),!0).forEach((function(r){_defineProperty(t,r,e[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):ownKeys(Object(e)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}))}return t}function _defineProperty(t,r,e){return(r=_toPropertyKey(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function _toPropertyKey(t){var r=_toPrimitive(t,"string");return"symbol"==_typeof(r)?r:String(r)}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function _slicedToArray(t,r){return _arrayWithHoles(t)||_iterableToArrayLimit(t,r)||_unsupportedIterableToArray(t,r)||_nonIterableRest()}function _nonIterableRest(){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 _unsupportedIterableToArray(t,r){if(t){if("string"==typeof t)return _arrayLikeToArray(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_arrayLikeToArray(t,r):void 0}}function _arrayLikeToArray(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function _iterableToArrayLimit(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i,a,c=[],u=!0,l=!1;try{if(i=(e=e.call(t)).next,0===r){if(Object(e)!==e)return;u=!1}else for(;!(u=(n=i.call(e)).done)&&(c.push(n.value),c.length!==r);u=!0);}catch(t){l=!0,o=t}finally{try{if(!u&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(l)throw o}}return c}}function _arrayWithHoles(t){if(Array.isArray(t))return t}import{Button,message}from"antd";import React,{useState}from"react";import DownloadFileTool from"../../utils/downloadFile";
|
|
2
2
|
/**
|
|
3
3
|
* @preserve
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* 附件下载组件
|
|
6
6
|
* @params 同Antd.Button参数
|
|
7
7
|
* @param { String | ReactNode } text 按钮内容,可传入string|ReactNode
|
|
8
|
-
* @param { Object } queryOption
|
|
8
|
+
* @param { Object } queryOption 对象,
|
|
9
|
+
* 可传入url{ string },methods{ string }(GET/POST),fileName{ string },params{ Object },
|
|
10
|
+
* 自定义返回接口返回的文件名和地址,如:res.data.exportFileName
|
|
11
|
+
* customField {
|
|
12
|
+
* url:'exportFileUrl',
|
|
13
|
+
* fileName:'exportFileName',
|
|
14
|
+
* }
|
|
15
|
+
* @param { Funtion } onError // 接口异常回调
|
|
9
16
|
*/import{jsx as _jsx}from"react/jsx-runtime";var DownloadFile=function(t){var r,e=_slicedToArray(useState(!1),2),n=e[0],o=e[1],i=_objectSpread({loading:n,onClick:(r=_asyncToGenerator(_regeneratorRuntime().mark((function r(){var e;return _regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(null===(e=t.queryOption)||void 0===e||!e.url){r.next=7;break}return o(!0),r.next=4,DownloadFileTool(t.queryOption||{});case 4:o(!1),r.next=8;break;case 7:console.error("请传入下载参数");case 8:case"end":return r.stop()}}),r)}))),function(){return r.apply(this,arguments)})},t);return _jsx(Button,_objectSpread(_objectSpread({},i),{},{children:t.text||"下载按钮"}))};export default DownloadFile;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var _templateObject;function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach((function(r){_defineProperty(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(e){var r=_toPrimitive(e,"string");return"symbol"==_typeof(r)?r:String(r)}function _toPrimitive(e,r){if("object"!=_typeof(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,r||"default");if("object"!=_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_unsupportedIterableToArray(e,r)||_nonIterableRest()}function _nonIterableRest(){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 _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}function _iterableToArrayLimit(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var o,n,i,a,l=[],s=!0,u=!1;try{if(i=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;s=!1}else for(;!(s=(o=i.call(t)).done)&&(l.push(o.value),l.length!==r);s=!0);}catch(e){u=!0,n=e}finally{try{if(!s&&null!=t.return&&(a=t.return(),Object(a)!==a))return}finally{if(u)throw n}}return l}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _taggedTemplateLiteral(e,r){return r||(r=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(r)}}))}import{getSessionStorage}from"../../utils/token.js";import{ProFormUploadButton,ProFormUploadDragger}from"@ant-design/pro-components";import{ConfigProvider,message,Upload,Image}from"antd";import React,{useState}from"react";import zhCN from"antd/es/locale/zh_CN";import styled from"styled-components";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";var StyleBox=styled.div(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n .readonly {\n .ant-upload {\n display: none;\n }\n }\n"]))),UploadFile=function(e){var r,t=_slicedToArray(useState(!1),2),o=t[0],n=t[1],i=_slicedToArray(useState({visible:!1,fileList:[],currentId:null}),2),a=i[0],l=i[1],s=e.uploadOptions,u=void 0===s?{}:s,c=e.formItemOptions,p=void 0===c?{}:c,
|
|
1
|
+
function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var _templateObject;function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach((function(r){_defineProperty(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _toPropertyKey(e){var r=_toPrimitive(e,"string");return"symbol"==_typeof(r)?r:String(r)}function _toPrimitive(e,r){if("object"!=_typeof(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,r||"default");if("object"!=_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_unsupportedIterableToArray(e,r)||_nonIterableRest()}function _nonIterableRest(){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 _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}function _iterableToArrayLimit(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var o,n,i,a,l=[],s=!0,u=!1;try{if(i=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;s=!1}else for(;!(s=(o=i.call(t)).done)&&(l.push(o.value),l.length!==r);s=!0);}catch(e){u=!0,n=e}finally{try{if(!s&&null!=t.return&&(a=t.return(),Object(a)!==a))return}finally{if(u)throw n}}return l}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _taggedTemplateLiteral(e,r){return r||(r=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(r)}}))}import{getSessionStorage}from"../../utils/token.js";import{ProFormUploadButton,ProFormUploadDragger}from"@ant-design/pro-components";import{ConfigProvider,message,Upload,Image}from"antd";import React,{useState}from"react";import zhCN from"antd/es/locale/zh_CN";import styled from"styled-components";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";var StyleBox=styled.div(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n .readonly {\n .ant-upload {\n display: none;\n }\n }\n"]))),UploadFile=function(e){var r,t=_slicedToArray(useState(!1),2),o=t[0],n=t[1],i=_slicedToArray(useState({visible:!1,fileList:[],currentId:null}),2),a=i[0],l=i[1],s=e.uploadOptions,u=void 0===s?{}:s,c=e.formItemOptions,p=void 0===c?{}:c,f=e.buttonOptions,d=void 0===f?{}:f,y=e.checkFile,m=e.onChange,b=e.form,v=_objectSpread({label:e.label||"",name:e.name||"file",rules:e.rules||[],style:e.label?{}:{margin:0}},p),_=getSessionStorage("service"),g=_objectSpread({name:"file",accept:e.accept,action:e.action||"/api/".concat(_,"/file/upload/v3?type=openFile"),multiple:e.multiple||!1,headers:{Authorization:"Bearer "+getSessionStorage("Token"),SID:SID,service:_||"unknow"},beforeUpload:function(e){return h(e)},onPreview:function(r){return S(r,e.name)},showUploadList:"boolean"==typeof e.showUploadList?e.showUploadList:_objectSpread({showRemoveIcon:!e.readonly},e.showUploadList),onChange:function(e){m&&m(e),n(!0),"uploading"!==e.file.status&&n(!1)}},u),j=g.listType?g.listType:e.listType||"text",S=function(e,r){["picture","picture-card"].includes(j)?l(b?{fileList:b.getFieldValue(r),currentId:e.uid,visible:!0}:{fileList:[e],currentId:e.uid,visible:!0}):window.open(e.url)},h=function(e){var r=y||{},t=r.suffixs,o=r.maxSize;if(t){var n,i=null===(n=e.name)||void 0===n||null===(n=n.split("."))||void 0===n?void 0:n.splice(-1)[0];if(!t.includes(i.toLocaleLowerCase()))return message.error("不支持".concat(e.name,"该种格式文件")),Upload.LIST_IGNORE}return o>0&&e.size/1024>o?(message.error("请选择小于".concat(o/1024,"MB的文件!")),Upload.LIST_IGNORE):Promise.resolve(e)},O=_objectSpread(_objectSpread({},e),{},{onChange:function(){},listType:j,formItemProps:v,fieldProps:g});return _jsx(ConfigProvider,{locale:zhCN,children:_jsxs(StyleBox,{children:[_jsx("div",{className:e.readonly?"readonly":"",children:"dragger"===j?_jsx(ProFormUploadDragger,_objectSpread({},O)):_jsx(ProFormUploadButton,_objectSpread(_objectSpread({},O),{},{buttonProps:_objectSpread({loading:o},d)}))}),_jsx(Image.PreviewGroup,{preview:{visible:a.visible,current:(r=a.fileList.findIndex((function(e){return e.uid===a.currentId})),r>-1?r:0),onVisibleChange:function(e){l(_objectSpread(_objectSpread({},a),{},{visible:e}))}},children:a.fileList.map((function(e,r){var t;return _jsx(Image,{style:{display:"none"},src:(null==e||null===(t=e.response)||void 0===t||null===(t=t.data)||void 0===t?void 0:t.pathUrl)||(null==e?void 0:e.url)||(null==e?void 0:e.thumbUrl)},r)}))})]})})};
|
|
2
2
|
/**
|
|
3
3
|
* @preserve
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _regeneratorRuntime(){"use strict";_regeneratorRuntime=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var a=e&&e.prototype instanceof g?e:g,i=Object.create(a.prototype),c=new G(n||[]);return o(i,"_invoke",{value:k(t,r,c)}),i}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",y="executing",d="completed",v={};function g(){}function m(){}function w(){}var b={};s(b,i,(function(){return this}));var x=Object.getPrototypeOf,L=x&&x(x(
|
|
1
|
+
function _regeneratorRuntime(){"use strict";_regeneratorRuntime=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var a=e&&e.prototype instanceof g?e:g,i=Object.create(a.prototype),c=new G(n||[]);return o(i,"_invoke",{value:k(t,r,c)}),i}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",y="executing",d="completed",v={};function g(){}function m(){}function w(){}var b={};s(b,i,(function(){return this}));var x=Object.getPrototypeOf,L=x&&x(x(N([])));L&&L!==r&&n.call(L,i)&&(b=L);var S=w.prototype=g.prototype=Object.create(b);function _(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function E(t,e){function r(o,a,i,c){var u=l(t[o],t,a);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==_typeof(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,i,c)}),(function(t){r("throw",t,i,c)})):e.resolve(f).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,c)}))}c(u.arg)}var a;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return a=a?a.then(o,o):o()}})}function k(e,r,n){var o=h;return function(a,i){if(o===y)throw new Error("Generator is already running");if(o===d){if("throw"===a)throw i;return{value:t,done:!0}}for(n.method=a,n.arg=i;;){var c=n.delegate;if(c){var u=O(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?d:p,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=d,n.method="throw",n.arg=s.arg)}}}function O(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,O(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var a=l(o,e.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,v;var i=a.arg;return i?i.done?(r[e.resultName]=i.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function j(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function G(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function N(e){if(e||""===e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(_typeof(e)+" is not iterable")}return m.prototype=w,o(S,"constructor",{value:w,configurable:!0}),o(w,"constructor",{value:m,configurable:!0}),m.displayName=s(w,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,s(t,u,"GeneratorFunction")),t.prototype=Object.create(S),t},e.awrap=function(t){return{__await:t}},_(E.prototype),s(E.prototype,c,(function(){return this})),e.AsyncIterator=E,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new E(f(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},_(S),s(S,u,"Generator"),s(S,i,(function(){return this})),s(S,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=N,G.prototype={constructor:G,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],c=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:N(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}function asyncGeneratorStep(t,e,r,n,o,a,i){try{var c=t[a](i),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){asyncGeneratorStep(a,n,o,i,c,"next",t)}function c(t){asyncGeneratorStep(a,n,o,i,c,"throw",t)}i(void 0)}))}}import{getSessionStorage}from"./token";import{message}from"antd";import qs from"querystring";var DownloadFile=function(){var t=_asyncToGenerator(_regeneratorRuntime().mark((function t(e){var r,n,o,a,i,c,u,s,f,l,h,p,y,d,v,g,m,w,b,x,L,S;return _regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(S=function(t,e){if(window.navigator.msSaveOrOpenBlob)navigator.msSaveBlob(t,e);else{var r=document.createElement("a"),n=document.querySelector("body");r.href=window.URL.createObjectURL(t),r.download=e||t.fileName||"file_".concat(Date.now()),r.style.display="none",n.appendChild(r),r.click(),n.removeChild(r),window.URL.revokeObjectURL(r.href)}},L=function(t){return new Promise((function(e){var r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="blob",r.onload=function(){200===r.status&&e(r.response)},r.send()}))},r=e.url,n=e.method,o=void 0===n?"POST":n,a=e.fileName,i=void 0===a?"":a,c=e.params,u=void 0===c?{}:c,s=e.customField,f=void 0===s?{url:"url",fileName:"fileName"}:s,l=e.onError,"pure"!==e.downloadType){t.next=9;break}return t.next=6,L(r);case 6:return h=t.sent,S(h,i),t.abrupt("return");case 9:return p="GET"===o&&Object.keys(u).length>0?r+"?"+qs.stringify(u):r,t.next=12,fetch(p,{method:o,headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(getSessionStorage("Token")),OrgId:getSessionStorage("orgId"),UserId:getSessionStorage("userId"),service:getSessionStorage("service")||"unknow",SID:SID},body:"POST"===o?JSON.stringify(u):null});case 12:if(y=t.sent,null==(d=y.headers.get("Content-Type"))||!d.startsWith("application/json")){t.next=41;break}return t.next=17,y.json();case 17:if("000000"!==(v=t.sent).rspCode){t.next=38;break}if(g="",m=i,"string"!=typeof v.data){t.next=25;break}g=v.data,t.next=32;break;case 25:if("object"!==_typeof(v.data)){t.next=30;break}v.data[f.url]?g=v.data[f.url]:message.error("无法获取下载链接"),v.data[f.fileName]&&(m=v.data[f.fileName]),t.next=32;break;case 30:return message.error("无法获取下载链接"),t.abrupt("return");case 32:return t.next=34,L(g);case 34:w=t.sent,S(w,m),t.next=39;break;case 38:l?l(v):message.error(v.rspMsg);case 39:t.next=52;break;case 41:if(null==d||!d.startsWith("text/json")){t.next=48;break}return t.next=44,y.json();case 44:b=t.sent,message.error((null==b?void 0:b.rspMsg)||"接口异常"),t.next=52;break;case 48:return t.next=50,y.blob();case 50:x=t.sent,S(x,i);case 52:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();export default DownloadFile;
|