@knockout-js/layout 0.1.4 → 0.1.5-beta.1

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.
Files changed (27) hide show
  1. package/es2017/components/upload-file/index.d.ts +13 -17
  2. package/es2017/components/upload-file/index.js.map +1 -1
  3. package/es2017/components/upload-file/locale/en_US.js +3 -1
  4. package/es2017/components/upload-file/locale/en_US.js.map +1 -1
  5. package/es2017/components/upload-file/locale/zh_CN.js +3 -1
  6. package/es2017/components/upload-file/locale/zh_CN.js.map +1 -1
  7. package/es2017/components/upload-file/uploadAvatar.d.ts +1 -1
  8. package/es2017/components/upload-file/uploadAvatar.js +33 -47
  9. package/es2017/components/upload-file/uploadAvatar.js.map +1 -1
  10. package/es2017/components/upload-file/uploadMultiple.js +107 -142
  11. package/es2017/components/upload-file/uploadMultiple.js.map +1 -1
  12. package/es2017/components/upload-file/uploadTemp.js +66 -74
  13. package/es2017/components/upload-file/uploadTemp.js.map +1 -1
  14. package/esm/components/upload-file/index.d.ts +13 -17
  15. package/esm/components/upload-file/index.js.map +1 -1
  16. package/esm/components/upload-file/locale/en_US.js +3 -1
  17. package/esm/components/upload-file/locale/en_US.js.map +1 -1
  18. package/esm/components/upload-file/locale/zh_CN.js +3 -1
  19. package/esm/components/upload-file/locale/zh_CN.js.map +1 -1
  20. package/esm/components/upload-file/uploadAvatar.d.ts +1 -1
  21. package/esm/components/upload-file/uploadAvatar.js +55 -94
  22. package/esm/components/upload-file/uploadAvatar.js.map +1 -1
  23. package/esm/components/upload-file/uploadMultiple.js +173 -233
  24. package/esm/components/upload-file/uploadMultiple.js.map +1 -1
  25. package/esm/components/upload-file/uploadTemp.js +121 -149
  26. package/esm/components/upload-file/uploadTemp.js.map +1 -1
  27. package/package.json +2 -2
@@ -2,89 +2,51 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@ice/jsx-runt
2
2
  import { UploadOutlined } from "@ant-design/icons";
3
3
  import { Button, Modal, Popconfirm, Space, Typography, Upload, message } from "antd";
4
4
  import { useEffect, useRef, useState } from "react";
5
- import { useAppCode, useTenantId } from "../provider/index";
6
5
  import { useLocale } from "../locale/index";
7
6
  import styles from "./index.module.css";
8
- import { formatFileSize, randomId } from "../_util/index";
9
- import { getFiles, getFilesRaw, updateFiles } from "@knockout-js/api";
7
+ import { formatFileSize } from "../_util/index";
8
+ import { getFileRaw, getFileUrl, getStorageUrl, parseStorageData, uploadFile } from "@knockout-js/api";
10
9
  export default ((props)=>{
11
10
  var _props_accept;
12
- var _props_bucket, _props_appCode, _props_tenantId;
13
- const bucket = (_props_bucket = props.bucket) !== null && _props_bucket !== void 0 ? _props_bucket : 'local', appCode = (_props_appCode = props.appCode) !== null && _props_appCode !== void 0 ? _props_appCode : useAppCode(), tenantId = (_props_tenantId = props.tenantId) !== null && _props_tenantId !== void 0 ? _props_tenantId : useTenantId(), locale = useLocale("UploadFile"), [messageApi] = message.useMessage(), [loading, setLoading] = useState(false), iframeRef = useRef(null), [name, setName] = useState(), [urlSrc, setUrlSrc] = useState(), [modal, setModal] = useState({
11
+ const locale = useLocale("UploadFile"), [messageApi] = message.useMessage(), [loading, setLoading] = useState(false), iframeRef = useRef(null), [name, setName] = useState(), [urlSrc, setUrlSrc] = useState(), [modal, setModal] = useState({
14
12
  show: false
15
13
  });
16
- const getUploadKey = (file)=>{
17
- const suffix = file.name.split('.').pop(), keys = [];
18
- if (props.forceDirectory && props.directory) {
19
- keys.push(props.directory);
20
- } else {
21
- if (appCode) {
22
- keys.push(appCode);
23
- }
24
- if (tenantId) {
25
- keys.push(tenantId);
26
- }
27
- if (props.directory) {
28
- keys.push(props.directory);
29
- }
30
- }
31
- keys.push(`${randomId(16)}.${suffix}`);
32
- return `/${keys.join('/')}`.replace('//', '/');
33
- }, beforeUpload = async (file)=>{
34
- const maxSize = props.maxSize || 1024 * 1024 * 5;
35
- if (file.size > maxSize) {
36
- messageApi.error(`${locale.fileSizeTip}: ${formatFileSize(maxSize)}`);
37
- return false;
38
- }
39
- await updateFile(file);
40
- return false;
41
- }, updateFile = async (file)=>{
42
- const key = getUploadKey(file);
43
- setLoading(true);
44
- if (bucket === 'local') {
45
- try {
46
- const result = await updateFiles({
47
- key,
48
- bucket,
49
- file
50
- });
51
- if (result) {
52
- var _props_onChange, _props_onChangePath;
53
- (_props_onChange = props.onChange) === null || _props_onChange === void 0 ? void 0 : _props_onChange.call(props, result);
54
- (_props_onChangePath = props.onChangePath) === null || _props_onChangePath === void 0 ? void 0 : _props_onChangePath.call(props, key);
55
- }
56
- } catch (error) {}
57
- }
58
- setLoading(false);
59
- }, getValueFile = async ()=>{
14
+ const getValueFile = async ()=>{
60
15
  if (props.value) {
61
- const result = await getFiles(props.value);
62
- if (result === null || result === void 0 ? void 0 : result.id) {
16
+ const result = await parseStorageData(props.value, {
17
+ inBrowser: false,
18
+ endpoint: props.endpoint,
19
+ bucket: props.bucket
20
+ });
21
+ if (result) {
63
22
  setName(result.name);
23
+ setUrlSrc(result.url);
64
24
  }
65
- if (bucket === 'local') {
66
- const result = await getFilesRaw(props.value, 'url');
67
- if (typeof result === 'string') {
68
- setUrlSrc(result);
69
- }
70
- }
71
- } else {
72
- setUrlSrc(undefined);
73
25
  }
74
26
  }, updateContent = async ()=>{
75
27
  if (props.value) {
76
- const result = await getFilesRaw(props.value);
77
- if (result && typeof result != 'string') {
78
- const r = new FileReader();
79
- r.readAsText(result, 'utf-8');
80
- r.onload = ()=>{
81
- var _iframeRef_current, _iframeRef_current1;
82
- if ((_iframeRef_current = iframeRef.current) === null || _iframeRef_current === void 0 ? void 0 : _iframeRef_current.contentWindow) {
83
- iframeRef.current.contentWindow.document.write(r.result);
84
- } else if ((_iframeRef_current1 = iframeRef.current) === null || _iframeRef_current1 === void 0 ? void 0 : _iframeRef_current1.contentDocument) {
85
- iframeRef.current.contentDocument.write(r.result);
86
- }
87
- };
28
+ const dataRes = await parseStorageData(props.value);
29
+ if (dataRes) {
30
+ const result = await getFileRaw(dataRes.path, {
31
+ endpoint: props.endpoint,
32
+ bucket: props.bucket
33
+ });
34
+ if (result) {
35
+ var _result_Body;
36
+ const content = await ((_result_Body = result.Body) === null || _result_Body === void 0 ? void 0 : _result_Body.transformToString('utf-8'));
37
+ const r = new FileReader();
38
+ r.readAsText(new Blob([
39
+ content !== null && content !== void 0 ? content : ''
40
+ ]), 'utf-8');
41
+ r.onload = ()=>{
42
+ var _iframeRef_current, _iframeRef_current1;
43
+ if ((_iframeRef_current = iframeRef.current) === null || _iframeRef_current === void 0 ? void 0 : _iframeRef_current.contentWindow) {
44
+ iframeRef.current.contentWindow.document.write(`<pre>${r.result}</pre>`);
45
+ } else if ((_iframeRef_current1 = iframeRef.current) === null || _iframeRef_current1 === void 0 ? void 0 : _iframeRef_current1.contentDocument) {
46
+ iframeRef.current.contentDocument.write(`<pre>${r.result}</pre>`);
47
+ }
48
+ };
49
+ }
88
50
  }
89
51
  }
90
52
  };
@@ -107,7 +69,37 @@ export default ((props)=>{
107
69
  /*#__PURE__*/ _jsx(Upload, {
108
70
  accept: props.accept,
109
71
  showUploadList: false,
110
- beforeUpload: beforeUpload,
72
+ beforeUpload: async (file)=>{
73
+ const maxSize = props.maxSize || 1024 * 1024 * 5;
74
+ if (file.size > maxSize) {
75
+ messageApi.error(`${locale.fileSizeTip}: ${formatFileSize(maxSize)}`);
76
+ return false;
77
+ }
78
+ setLoading(true);
79
+ const result = await uploadFile(file, props.directory, {
80
+ endpoint: props.endpoint,
81
+ bucket: props.bucket,
82
+ useFileName: props.useFileName,
83
+ custromFileName: props.custromFileName
84
+ });
85
+ if (result === null || result === void 0 ? void 0 : result.path) {
86
+ var _props_onChange;
87
+ const storageUlr = await getStorageUrl(result.path, {
88
+ endpoint: props.endpoint,
89
+ bucket: props.bucket
90
+ }), url = await getFileUrl(result.path, {
91
+ endpoint: props.endpoint,
92
+ bucket: props.bucket
93
+ });
94
+ setName(file.name);
95
+ setUrlSrc(url);
96
+ (_props_onChange = props.onChange) === null || _props_onChange === void 0 ? void 0 : _props_onChange.call(props, storageUlr);
97
+ } else {
98
+ messageApi.error(locale.errorUpload);
99
+ }
100
+ setLoading(false);
101
+ return false;
102
+ },
111
103
  children: /*#__PURE__*/ _jsx(Button, {
112
104
  loading: loading,
113
105
  icon: /*#__PURE__*/ _jsx(UploadOutlined, {
@@ -143,15 +135,15 @@ export default ((props)=>{
143
135
  target: "_blank",
144
136
  href: urlSrc,
145
137
  download: name,
138
+ rel: "noopener noreferrer",
146
139
  children: locale.tempDown
147
140
  }),
148
141
  props.showDelBtn ? /*#__PURE__*/ _jsx(Popconfirm, {
149
142
  title: locale.del,
150
143
  description: locale.confirmDel,
151
144
  onConfirm: ()=>{
152
- var _props_onChange, _props_onChangePath;
145
+ var _props_onChange;
153
146
  (_props_onChange = props.onChange) === null || _props_onChange === void 0 ? void 0 : _props_onChange.call(props);
154
- (_props_onChangePath = props.onChangePath) === null || _props_onChangePath === void 0 ? void 0 : _props_onChangePath.call(props);
155
147
  },
156
148
  okText: "Yes",
157
149
  cancelText: "No",
@@ -1 +1 @@
1
- {"version":3,"sources":[".\\src\\components\\upload-file\\uploadTemp.tsx"],"sourcesContent":["import { UploadOutlined } from \"@ant-design/icons\";\r\nimport { Button, Modal, Popconfirm, Space, Typography, Upload, message } from \"antd\"\r\nimport { RcFile } from \"antd/es/upload\";\r\nimport { useEffect, useRef, useState } from \"react\";\r\nimport { useAppCode, useTenantId } from \"../provider\";\r\nimport { UploadFileProps } from \".\";\r\nimport { useLocale } from \"../locale\";\r\nimport styles from \"./index.module.css\";\r\nimport { formatFileSize, randomId } from \"../_util\";\r\nimport { getFiles, getFilesRaw, updateFiles } from \"@knockout-js/api\";\r\n\r\nexport default (props: UploadFileProps<string> & {\r\n /**\r\n * 显示删除按钮\r\n */\r\n showDelBtn?: boolean;\r\n}) => {\r\n const\r\n bucket = props.bucket ?? 'local',\r\n appCode = props.appCode ?? useAppCode(),\r\n tenantId = props.tenantId ?? useTenantId(),\r\n locale = useLocale(\"UploadFile\"),\r\n [messageApi] = message.useMessage(),\r\n [loading, setLoading] = useState(false),\r\n iframeRef = useRef<HTMLIFrameElement>(null),\r\n [name, setName] = useState<string>(),\r\n [urlSrc, setUrlSrc] = useState<string>(),\r\n [modal, setModal] = useState<{\r\n show: boolean,\r\n }>({\r\n show: false,\r\n });\r\n\r\n const\r\n getUploadKey = (file: RcFile) => {\r\n const suffix = file.name.split('.').pop(),\r\n keys: string[] = [];\r\n if (props.forceDirectory && props.directory) {\r\n keys.push(props.directory)\r\n } else {\r\n if (appCode) {\r\n keys.push(appCode)\r\n }\r\n if (tenantId) {\r\n keys.push(tenantId)\r\n }\r\n if (props.directory) {\r\n keys.push(props.directory)\r\n }\r\n }\r\n keys.push(`${randomId(16)}.${suffix}`);\r\n return `/${keys.join('/')}`.replace('//', '/');\r\n },\r\n beforeUpload = async (file: RcFile) => {\r\n const maxSize = props.maxSize || (1024 * 1024 * 5);\r\n\r\n if (file.size > maxSize) {\r\n messageApi.error(`${locale.fileSizeTip}: ${formatFileSize(maxSize)}`);\r\n return false;\r\n }\r\n\r\n await updateFile(file);\r\n return false;\r\n },\r\n updateFile = async (file: RcFile) => {\r\n const key = getUploadKey(file);\r\n setLoading(true);\r\n if (bucket === 'local') {\r\n try {\r\n const result = await updateFiles({\r\n key,\r\n bucket,\r\n file,\r\n })\r\n if (result) {\r\n props.onChange?.(result)\r\n props.onChangePath?.(key);\r\n }\r\n } catch (error) {\r\n\r\n }\r\n }\r\n setLoading(false)\r\n },\r\n getValueFile = async () => {\r\n if (props.value) {\r\n const result = await getFiles(props.value);\r\n if (result?.id) {\r\n setName(result.name)\r\n }\r\n if (bucket === 'local') {\r\n const result = await getFilesRaw(props.value, 'url');\r\n if (typeof result === 'string') {\r\n setUrlSrc(result)\r\n }\r\n }\r\n } else {\r\n setUrlSrc(undefined)\r\n }\r\n },\r\n updateContent = async () => {\r\n if (props.value) {\r\n const result = await getFilesRaw(props.value)\r\n if (result && typeof result != 'string') {\r\n const r = new FileReader()\r\n r.readAsText(result, 'utf-8')\r\n r.onload = () => {\r\n if (iframeRef.current?.contentWindow) {\r\n iframeRef.current.contentWindow.document.write(r.result as string)\r\n } else if (iframeRef.current?.contentDocument) {\r\n iframeRef.current.contentDocument.write(r.result as string)\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n useEffect(() => {\r\n getValueFile();\r\n }, [props.value]);\r\n\r\n useEffect(() => {\r\n if (modal.show) {\r\n updateContent();\r\n }\r\n }, [modal.show]);\r\n\r\n return <>\r\n <Space>\r\n <Upload\r\n accept={props.accept}\r\n showUploadList={false}\r\n beforeUpload={beforeUpload}\r\n >\r\n <Button loading={loading} icon={<UploadOutlined rev={undefined} />}>{locale.fileUpload}</Button>\r\n </Upload>\r\n <Typography.Text type=\"secondary\">\r\n {`${locale.supportExtension}: ${props.accept?.split(',.').join('、').replace('.', '')}`}\r\n </Typography.Text>\r\n </Space>\r\n {props.value ? <>\r\n <div style={{ height: \"8px\" }}></div>\r\n <Space >\r\n <a onClick={() => {\r\n setModal({ show: true })\r\n }}\r\n >{locale.tempViewer}</a>\r\n <a target=\"_blank\" href={urlSrc} download={name}>{locale.tempDown}</a>\r\n {props.showDelBtn ? <Popconfirm\r\n title={locale.del}\r\n description={locale.confirmDel}\r\n onConfirm={() => {\r\n props.onChange?.()\r\n props.onChangePath?.();\r\n }}\r\n okText=\"Yes\"\r\n cancelText=\"No\"\r\n >\r\n <a className={styles.delText}>{locale.del}</a>\r\n </Popconfirm> : <></>}\r\n </Space>\r\n <Modal\r\n title={locale.tempViewer}\r\n open={modal.show}\r\n destroyOnClose\r\n footer={null}\r\n width={800}\r\n onCancel={() => {\r\n setModal({ show: false })\r\n }}\r\n >\r\n <iframe className={styles.modalIframe} ref={iframeRef}></iframe>\r\n </Modal>\r\n </> : <></>}\r\n </>\r\n}\r\n"],"names":["UploadOutlined","Button","Modal","Popconfirm","Space","Typography","Upload","message","useEffect","useRef","useState","useAppCode","useTenantId","useLocale","styles","formatFileSize","randomId","getFiles","getFilesRaw","updateFiles","props","bucket","appCode","tenantId","locale","messageApi","useMessage","loading","setLoading","iframeRef","name","setName","urlSrc","setUrlSrc","modal","setModal","show","getUploadKey","file","suffix","split","pop","keys","forceDirectory","directory","push","join","replace","beforeUpload","maxSize","size","error","fileSizeTip","updateFile","key","result","onChange","onChangePath","getValueFile","value","id","undefined","updateContent","r","FileReader","readAsText","onload","current","contentWindow","document","write","contentDocument","accept","showUploadList","icon","rev","fileUpload","Text","type","supportExtension","div","style","height","a","onClick","tempViewer","target","href","download","tempDown","showDelBtn","title","del","description","confirmDel","onConfirm","okText","cancelText","className","delText","open","destroyOnClose","footer","width","onCancel","iframe","modalIframe","ref"],"mappings":";AAAA,SAASA,cAAc,QAAQ,oBAAoB;AACnD,SAASC,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAM;AAEpF,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AACpD,SAASC,UAAU,EAAEC,WAAW,QAAQ,oBAAc;AAEtD,SAASC,SAAS,QAAQ,kBAAY;AACtC,OAAOC,YAAY,qBAAqB;AACxC,SAASC,cAAc,EAAEC,QAAQ,QAAQ,iBAAW;AACpD,SAASC,QAAQ,EAAEC,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AAEtE,eAAe,CAAA,CAACC,QAKV;QAyHkCA;QAvH3BA,eACCA,gBACCA;IAHb,MACEC,SAASD,CAAAA,gBAAAA,MAAMC,MAAM,cAAZD,2BAAAA,gBAAgB,OAAO,EAChCE,UAAUF,CAAAA,iBAAAA,MAAME,OAAO,cAAbF,4BAAAA,iBAAiBT,YAAY,EACvCY,WAAWH,CAAAA,kBAAAA,MAAMG,QAAQ,cAAdH,6BAAAA,kBAAkBR,aAAa,EAC1CY,SAASX,UAAU,eACnB,CAACY,WAAW,GAAGlB,QAAQmB,UAAU,IACjC,CAACC,SAASC,WA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AU;gCAC9BC,WAAW,IAAM;wCACf3E,iBACAA;oCADAA,CAAAA,kBAAAA,MAAMoC,QAAQ,cAAdpC,6BAAAA,KAAAA,IAAAA,gBAAAA,KAAAA;oCACAA,CAAAA,sBAAAA,MAAMqC,YAAY,cAAlBrC,iCAAAA,KAAAA,IAAAA,oBAAAA,KAAAA;gCACF;gCACA4E,QAAO;gCACPC,YAAW;0CAEX,cAAA,KAACd;oCAAEe,WAAWpF,OAAOqF,OAAO;8CAAG3E,OAAOoE,GAAG;;+CAC3B,mBAAK;;;kCAEvB,KAAC1F;wBACCyF,OAAOnE,OAAO6D,UAAU;wBACxBe,MAAMlE,MAAME,IAAI;wBAChBiE,cAAc;wBACdC,QAAQ,IAAI;wBACZC,OAAO;wBACPC,UAAU,IAAM;4BACdrE,SAAS;gCAAEC,MAAM,KAAK;4BAAC;wBACzB;kCAEA,cAAA,KAACqE;4BAAOP,WAAWpF,OAAO4F,WAAW;4BAAEC,KAAK9E;;;;+BAE1C,mBAAK;;;AAEf,CAAA,EAAC"}
1
+ {"version":3,"sources":[".\\src\\components\\upload-file\\uploadTemp.tsx"],"sourcesContent":["import { UploadOutlined } from \"@ant-design/icons\";\r\nimport { Button, Modal, Popconfirm, Space, Typography, Upload, message } from \"antd\"\r\nimport { RcFile } from \"antd/es/upload\";\r\nimport { useEffect, useRef, useState } from \"react\";\r\nimport { UploadFileProps } from \".\";\r\nimport { useLocale } from \"../locale\";\r\nimport styles from \"./index.module.css\";\r\nimport { formatFileSize } from \"../_util\";\r\nimport { getFileRaw, getFileUrl, getStorageUrl, parseStorageData, uploadFile } from \"@knockout-js/api\";\r\n\r\nexport default (props: UploadFileProps<string> & {\r\n /**\r\n * 显示删除按钮\r\n */\r\n showDelBtn?: boolean;\r\n}) => {\r\n const\r\n locale = useLocale(\"UploadFile\"),\r\n [messageApi] = message.useMessage(),\r\n [loading, setLoading] = useState(false),\r\n iframeRef = useRef<HTMLIFrameElement>(null),\r\n [name, setName] = useState<string>(),\r\n [urlSrc, setUrlSrc] = useState<string>(),\r\n [modal, setModal] = useState<{\r\n show: boolean,\r\n }>({\r\n show: false,\r\n });\r\n\r\n const\r\n getValueFile = async () => {\r\n if (props.value) {\r\n const result = await parseStorageData(props.value, {\r\n inBrowser: false,\r\n endpoint: props.endpoint,\r\n bucket: props.bucket\r\n });\r\n if (result) {\r\n setName(result.name)\r\n setUrlSrc(result.url)\r\n }\r\n }\r\n },\r\n updateContent = async () => {\r\n if (props.value) {\r\n const dataRes = await parseStorageData(props.value)\r\n if (dataRes) {\r\n const result = await getFileRaw(dataRes.path, {\r\n endpoint: props.endpoint,\r\n bucket: props.bucket\r\n })\r\n if (result) {\r\n const content = await result.Body?.transformToString('utf-8')\r\n const r = new FileReader()\r\n r.readAsText(new Blob([content ?? '']), 'utf-8')\r\n r.onload = () => {\r\n if (iframeRef.current?.contentWindow) {\r\n iframeRef.current.contentWindow.document.write(`<pre>${r.result}</pre>`)\r\n } else if (iframeRef.current?.contentDocument) {\r\n iframeRef.current.contentDocument.write(`<pre>${r.result}</pre>`)\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n useEffect(() => {\r\n getValueFile();\r\n }, [props.value]);\r\n\r\n useEffect(() => {\r\n if (modal.show) {\r\n updateContent();\r\n }\r\n }, [modal.show]);\r\n\r\n return <>\r\n <Space>\r\n <Upload\r\n accept={props.accept}\r\n showUploadList={false}\r\n beforeUpload={async (file: RcFile) => {\r\n const maxSize = props.maxSize || (1024 * 1024 * 5);\r\n\r\n if (file.size > maxSize) {\r\n messageApi.error(`${locale.fileSizeTip}: ${formatFileSize(maxSize)}`);\r\n return false;\r\n }\r\n setLoading(true);\r\n const result = await uploadFile(file, props.directory, {\r\n endpoint: props.endpoint,\r\n bucket: props.bucket,\r\n useFileName: props.useFileName,\r\n custromFileName: props.custromFileName,\r\n });\r\n if (result?.path) {\r\n const storageUlr = await getStorageUrl(result.path, {\r\n endpoint: props.endpoint,\r\n bucket: props.bucket\r\n }),\r\n url = await getFileUrl(result.path, {\r\n endpoint: props.endpoint,\r\n bucket: props.bucket\r\n })\r\n setName(file.name)\r\n setUrlSrc(url)\r\n props.onChange?.(storageUlr)\r\n } else {\r\n messageApi.error(locale.errorUpload);\r\n }\r\n setLoading(false);\r\n return false;\r\n }}\r\n >\r\n <Button loading={loading} icon={<UploadOutlined rev={undefined} />}>{locale.fileUpload}</Button>\r\n </Upload>\r\n <Typography.Text type=\"secondary\">\r\n {`${locale.supportExtension}: ${props.accept?.split(',.').join('、').replace('.', '')}`}\r\n </Typography.Text>\r\n </Space>\r\n {props.value ? <>\r\n <div style={{ height: \"8px\" }}></div>\r\n <Space >\r\n <a onClick={() => {\r\n setModal({ show: true })\r\n }}\r\n >{locale.tempViewer}</a>\r\n <a target=\"_blank\" href={urlSrc} download={name} rel=\"noopener noreferrer\">{locale.tempDown}</a>\r\n {props.showDelBtn ? <Popconfirm\r\n title={locale.del}\r\n description={locale.confirmDel}\r\n onConfirm={() => {\r\n props.onChange?.()\r\n }}\r\n okText=\"Yes\"\r\n cancelText=\"No\"\r\n >\r\n <a className={styles.delText}>{locale.del}</a>\r\n </Popconfirm> : <></>}\r\n </Space>\r\n <Modal\r\n title={locale.tempViewer}\r\n open={modal.show}\r\n destroyOnClose\r\n footer={null}\r\n width={800}\r\n onCancel={() => {\r\n setModal({ show: false })\r\n }}\r\n >\r\n <iframe className={styles.modalIframe} ref={iframeRef}></iframe>\r\n </Modal>\r\n </> : <></>}\r\n </>\r\n}\r\n"],"names":["UploadOutlined","Button","Modal","Popconfirm","Space","Typography","Upload","message","useEffect","useRef","useState","useLocale","styles","formatFileSize","getFileRaw","getFileUrl","getStorageUrl","parseStorageData","uploadFile","props","locale","messageApi","useMessage","loading","setLoading","iframeRef","name","setName","urlSrc","setUrlSrc","modal","setModal","show","getValueFile","value","result","inBrowser","endpoint","bucket","url","updateContent","dataRes","path","content","Body","transformToString","r","FileReader","readAsText","Blob","onload","current","contentWindow","document","write","contentDocument","accept","showUploadList","beforeUpload","file","maxSize","size","error","fileSizeTip","directory","useFileName","custromFileName","storageUlr","onChange","errorUpload","icon","rev","undefined","fileUpload","Text","type","supportExtension","split","join","replace","div","style","height","a","onClick","tempViewer","target","href","download","rel","tempDown","showDelBtn","title","del","description","confirmDel","onConfirm","okText","cancelText","className","delText","open","destroyOnClose","footer","width","onCancel","iframe","modalIframe","ref"],"mappings":";AAAA,SAASA,cAAc,QAAQ,oBAAoB;AACnD,SAASC,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAM;AAEpF,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEpD,SAASC,SAAS,QAAQ,kBAAY;AACtC,OAAOC,YAAY,qBAAqB;AACxC,SAASC,cAAc,QAAQ,iBAAW;AAC1C,SAASC,UAAU,EAAEC,UAAU,EAAEC,aAAa,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,mBAAmB;AAEvG,eAAe,CAAA,CAACC,QAKV;QAuGkCA;IAtGtC,MACEC,SAAST,UAAU,eACnB,CAACU,WAAW,GAAGd,QAAQe,UAAU,IACjC,CAACC,SAASC,WAAW,GAAGd,SAAS,KAAK,GACtCe,YAAYhB,OAA0B,IAAI,GAC1C,CAACiB,MAAMC,QAAQ,GAAGjB,YAClB,CAACkB,QAAQC,UAAU,GAAGnB,YACtB,CAACoB,OAAOC,SAAS,GAAGrB,SAEjB;QACDsB,MAAM,KAAK;IACb;IAEF,MACEC,eAAe,UAAY;QACzB,IAAId,MAAMe,KAAK,EAAE;YACf,MAAMC,SAAS,MAAMlB,iBAAiBE,MAAMe,KAAK,EAAE;gBACjDE,WAAW,KAAK;gBAChBC,UAAUlB,MAAMkB,QAAQ;gBACxBC,QAAQnB,MAAMmB,MAAM;YACtB;YACA,IAAIH,QAAQ;gBACVR,QAAQQ,OAAOT,IAAI;gBACnBG,UAAUM,OAAOI,GAAG;YACtB,CAA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EAAC"}
@@ -5,6 +5,8 @@ export type UploadFileLocale = {
5
5
  clickOrDragUpload: string;
6
6
  supportExtension: string;
7
7
  errSupportExtension: string;
8
+ errorUpload: string;
9
+ errorDel: string;
8
10
  fileUpload: string;
9
11
  tempViewer: string;
10
12
  tempDown: string;
@@ -15,23 +17,23 @@ export interface UploadFileProps<T> {
15
17
  */
16
18
  bucket?: string;
17
19
  /**
18
- * 应用code
20
+ * endpoint
19
21
  */
20
- appCode?: string;
22
+ endpoint?: string;
21
23
  /**
22
- * tenantId
24
+ * 目录格式 xxx/xx
23
25
  */
24
- tenantId?: string;
26
+ directory: string;
25
27
  /**
26
- * 目录格式 xxx/ss
28
+ * 使用file.name当作文件名
27
29
  */
28
- directory?: string;
30
+ useFileName?: boolean;
29
31
  /**
30
- * 强制使用目录当前缀
32
+ * 使用这个值当作文件名时不包含后缀 custromFileName='fileName'
31
33
  */
32
- forceDirectory?: boolean;
34
+ custromFileName?: string;
33
35
  /**
34
- * 限制文件大小
36
+ * 限制文件大小 默认5M
35
37
  */
36
38
  maxSize?: number;
37
39
  /**
@@ -39,19 +41,13 @@ export interface UploadFileProps<T> {
39
41
  */
40
42
  accept?: string;
41
43
  /**
42
- * 文件 id
44
+ * 使用url
43
45
  */
44
46
  value?: T;
45
47
  /**
46
- * 返回文件id
48
+ * 返回存储数据库的url
47
49
  * @param value
48
50
  * @returns
49
51
  */
50
52
  onChange?: (value?: T) => void;
51
- /**
52
- * 返回文件path
53
- * @param path
54
- * @returns
55
- */
56
- onChangePath?: (path?: T) => void;
57
53
  }
@@ -1 +1 @@
1
- {"version":3,"sources":[".\\src\\components\\upload-file\\index.ts"],"sourcesContent":["export type UploadFileLocale = {\r\n // 文件大小必须小于:\r\n fileSizeTip: string;\r\n del: string;\r\n confirmDel: string;\r\n // 点击或拖拽文件上传\r\n clickOrDragUpload: string;\r\n // 支持扩展名\r\n supportExtension: string;\r\n errSupportExtension: string;\r\n fileUpload: string;\r\n tempViewer: string;\r\n tempDown: string;\r\n}\r\n\r\nexport interface UploadFileProps<T> {\r\n /**\r\n * bucket\r\n */\r\n bucket?: string;\r\n /**\r\n * 应用code\r\n */\r\n appCode?: string;\r\n /**\r\n * tenantId\r\n */\r\n tenantId?: string;\r\n /**\r\n * 目录格式 xxx/ss\r\n */\r\n directory?: string;\r\n /**\r\n * 强制使用目录当前缀\r\n */\r\n forceDirectory?: boolean;\r\n /**\r\n * 限制文件大小\r\n */\r\n maxSize?: number;\r\n /**\r\n * 限制弹框选择\r\n */\r\n accept?: string;\r\n /**\r\n * 文件 id\r\n */\r\n value?: T;\r\n /**\r\n * 返回文件id\r\n * @param value\r\n * @returns\r\n */\r\n onChange?: (value?: T) => void;\r\n /**\r\n * 返回文件path\r\n * @param path\r\n * @returns\r\n */\r\n onChangePath?: (path?: T) => void;\r\n}\r\n"],"names":[],"mappings":"AAAA,WA4DC"}
1
+ {"version":3,"sources":[".\\src\\components\\upload-file\\index.ts"],"sourcesContent":["export type UploadFileLocale = {\r\n // 文件大小必须小于:\r\n fileSizeTip: string;\r\n del: string;\r\n confirmDel: string;\r\n // 点击或拖拽文件上传\r\n clickOrDragUpload: string;\r\n // 支持扩展名\r\n supportExtension: string;\r\n errSupportExtension: string;\r\n errorUpload: string;\r\n errorDel: string;\r\n fileUpload: string;\r\n tempViewer: string;\r\n tempDown: string;\r\n}\r\n\r\nexport interface UploadFileProps<T> {\r\n /**\r\n * bucket\r\n */\r\n bucket?: string;\r\n /**\r\n * endpoint\r\n */\r\n endpoint?: string;\r\n /**\r\n * 目录格式 xxx/xx\r\n */\r\n directory: string;\r\n /**\r\n * 使用file.name当作文件名\r\n */\r\n useFileName?: boolean;\r\n /**\r\n * 使用这个值当作文件名时不包含后缀 custromFileName='fileName'\r\n */\r\n custromFileName?: string;\r\n /**\r\n * 限制文件大小 默认5M\r\n */\r\n maxSize?: number;\r\n /**\r\n * 限制弹框选择\r\n */\r\n accept?: string;\r\n /**\r\n * 使用url\r\n */\r\n value?: T;\r\n /**\r\n * 返回存储数据库的url\r\n * @param value\r\n * @returns\r\n */\r\n onChange?: (value?: T) => void;\r\n\r\n}\r\n"],"names":[],"mappings":"AAAA,WAyDC"}
@@ -7,7 +7,9 @@ var locale = {
7
7
  errSupportExtension: "Only the extension name is supported",
8
8
  fileUpload: "File upload",
9
9
  tempViewer: "Template preview",
10
- tempDown: "Template download"
10
+ tempDown: "Template download",
11
+ errorUpload: "If the upload is abnormal, contact the administrator",
12
+ errorDel: "If the deletion is abnormal, contact the administrator"
11
13
  };
12
14
  export default locale;
13
15
 
@@ -1 +1 @@
1
- {"version":3,"sources":[".\\src\\components\\upload-file\\locale\\en_US.ts"],"sourcesContent":["import { UploadFileLocale } from \"../index\";\r\n\r\nconst locale: UploadFileLocale = {\r\n fileSizeTip: \"The file size cannot be less than\",\r\n del: \"delete\",\r\n confirmDel: \"Confirm deletion\",\r\n clickOrDragUpload: \"Click or drag the file to upload\",\r\n supportExtension: \"Support extension\",\r\n errSupportExtension: \"Only the extension name is supported\",\r\n fileUpload: \"File upload\",\r\n tempViewer: \"Template preview\",\r\n tempDown: \"Template download\",\r\n};\r\n\r\nexport default locale\r\n"],"names":["locale","fileSizeTip","del","confirmDel","clickOrDragUpload","supportExtension","errSupportExtension","fileUpload","tempViewer","tempDown"],"mappings":"AAEA,IAAMA,SAA2B;IAC/BC,aAAa;IACbC,KAAK;IACLC,YAAY;IACZC,mBAAmB;IACnBC,kBAAkB;IAClBC,qBAAqB;IACrBC,YAAY;IACZC,YAAY;IACZC,UAAU;AACZ;AAEA,eAAeT,OAAM"}
1
+ {"version":3,"sources":[".\\src\\components\\upload-file\\locale\\en_US.ts"],"sourcesContent":["import { UploadFileLocale } from \"../index\";\r\n\r\nconst locale: UploadFileLocale = {\r\n fileSizeTip: \"The file size cannot be less than\",\r\n del: \"delete\",\r\n confirmDel: \"Confirm deletion\",\r\n clickOrDragUpload: \"Click or drag the file to upload\",\r\n supportExtension: \"Support extension\",\r\n errSupportExtension: \"Only the extension name is supported\",\r\n fileUpload: \"File upload\",\r\n tempViewer: \"Template preview\",\r\n tempDown: \"Template download\",\r\n errorUpload: 'If the upload is abnormal, contact the administrator',\r\n errorDel: 'If the deletion is abnormal, contact the administrator',\r\n};\r\n\r\nexport default locale\r\n"],"names":["locale","fileSizeTip","del","confirmDel","clickOrDragUpload","supportExtension","errSupportExtension","fileUpload","tempViewer","tempDown","errorUpload","errorDel"],"mappings":"AAEA,IAAMA,SAA2B;IAC/BC,aAAa;IACbC,KAAK;IACLC,YAAY;IACZC,mBAAmB;IACnBC,kBAAkB;IAClBC,qBAAqB;IACrBC,YAAY;IACZC,YAAY;IACZC,UAAU;IACVC,aAAa;IACbC,UAAU;AACZ;AAEA,eAAeX,OAAM"}
@@ -7,7 +7,9 @@ var locale = {
7
7
  errSupportExtension: "只支持扩展名",
8
8
  fileUpload: "文件上传",
9
9
  tempViewer: "模板预览",
10
- tempDown: "模板下载"
10
+ tempDown: "模板下载",
11
+ errorUpload: "上传异常,请联系管理员",
12
+ errorDel: "删除异常,请联系管理员"
11
13
  };
12
14
  export default locale;
13
15
 
@@ -1 +1 @@
1
- {"version":3,"sources":[".\\src\\components\\upload-file\\locale\\zh_CN.ts"],"sourcesContent":["import { UploadFileLocale } from \"../index\";\r\n\r\nconst locale: UploadFileLocale = {\r\n fileSizeTip: \"文件大小不能小于\",\r\n del: \"删除\",\r\n confirmDel: \"确认删除\",\r\n clickOrDragUpload: \"点击或拖拽文件上传\",\r\n supportExtension: \"支持扩展名\",\r\n errSupportExtension: \"只支持扩展名\",\r\n fileUpload: \"文件上传\",\r\n tempViewer: \"模板预览\",\r\n tempDown: \"模板下载\",\r\n};\r\n\r\nexport default locale\r\n"],"names":["locale","fileSizeTip","del","confirmDel","clickOrDragUpload","supportExtension","errSupportExtension","fileUpload","tempViewer","tempDown"],"mappings":"AAEA,IAAMA,SAA2B;IAC/BC,aAAa;IACbC,KAAK;IACLC,YAAY;IACZC,mBAAmB;IACnBC,kBAAkB;IAClBC,qBAAqB;IACrBC,YAAY;IACZC,YAAY;IACZC,UAAU;AACZ;AAEA,eAAeT,OAAM"}
1
+ {"version":3,"sources":[".\\src\\components\\upload-file\\locale\\zh_CN.ts"],"sourcesContent":["import { UploadFileLocale } from \"../index\";\r\n\r\nconst locale: UploadFileLocale = {\r\n fileSizeTip: \"文件大小不能小于\",\r\n del: \"删除\",\r\n confirmDel: \"确认删除\",\r\n clickOrDragUpload: \"点击或拖拽文件上传\",\r\n supportExtension: \"支持扩展名\",\r\n errSupportExtension: \"只支持扩展名\",\r\n fileUpload: \"文件上传\",\r\n tempViewer: \"模板预览\",\r\n tempDown: \"模板下载\",\r\n errorUpload: '上传异常,请联系管理员',\r\n errorDel: '删除异常,请联系管理员',\r\n};\r\n\r\nexport default locale\r\n"],"names":["locale","fileSizeTip","del","confirmDel","clickOrDragUpload","supportExtension","errSupportExtension","fileUpload","tempViewer","tempDown","errorUpload","errorDel"],"mappings":"AAEA,IAAMA,SAA2B;IAC/BC,aAAa;IACbC,KAAK;IACLC,YAAY;IACZC,mBAAmB;IACnBC,kBAAkB;IAClBC,qBAAqB;IACrBC,YAAY;IACZC,YAAY;IACZC,UAAU;IACVC,aAAa;IACbC,UAAU;AACZ;AAEA,eAAeX,OAAM"}
@@ -1,3 +1,3 @@
1
- import { UploadFileProps } from ".";
1
+ import { UploadFileProps } from "./index";
2
2
  declare const _default: (props: UploadFileProps<string>) => import("react/jsx-runtime").JSX.Element;
3
3
  export default _default;
@@ -5,119 +5,41 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@ice/jsx-runt
5
5
  import { PlusOutlined } from "@ant-design/icons";
6
6
  import { Spin, Upload, message } from "antd";
7
7
  import { useEffect, useState } from "react";
8
- import { useAppCode, useTenantId } from "../provider/index";
9
8
  import { useLocale } from "../locale/index";
10
- import { formatFileSize, randomId } from "../_util/index";
11
- import { getFilesRaw, updateFiles } from "@knockout-js/api";
9
+ import { formatFileSize } from "../_util/index";
10
+ import { parseStorageUrl, getStorageUrl, uploadFile, getFileUrl } from "@knockout-js/api";
12
11
  export default function(props) {
13
- var _props_bucket, _props_appCode, _props_tenantId;
14
- var bucket = (_props_bucket = props.bucket) !== null && _props_bucket !== void 0 ? _props_bucket : "local", appCode = (_props_appCode = props.appCode) !== null && _props_appCode !== void 0 ? _props_appCode : useAppCode(), tenantId = (_props_tenantId = props.tenantId) !== null && _props_tenantId !== void 0 ? _props_tenantId : useTenantId(), locale = useLocale("UploadFile"), _message_useMessage = _sliced_to_array(message.useMessage(), 1), messageApi = _message_useMessage[0], _useState = _sliced_to_array(useState(false), 2), loading = _useState[0], setLoading = _useState[1], _useState1 = _sliced_to_array(useState(), 2), imgsrc = _useState1[0], setImgsrc = _useState1[1];
15
- var getUploadKey = function(file) {
16
- var suffix = file.name.split(".").pop(), keys = [];
17
- if (props.forceDirectory && props.directory) {
18
- keys.push(props.directory);
19
- } else {
20
- if (appCode) {
21
- keys.push(appCode);
22
- }
23
- if (tenantId) {
24
- keys.push(tenantId);
25
- }
26
- if (props.directory) {
27
- keys.push(props.directory);
28
- }
29
- }
30
- keys.push("".concat(randomId(16), ".").concat(suffix));
31
- return "/".concat(keys.join("/")).replace("//", "/");
32
- }, updateFile = function() {
33
- var _ref = _async_to_generator(function(file) {
34
- var key, result, _props_onChange, _props_onChangePath, error;
35
- return _ts_generator(this, function(_state) {
36
- switch(_state.label){
37
- case 0:
38
- key = getUploadKey(file);
39
- setLoading(true);
40
- if (!(bucket === "local")) return [
41
- 3,
42
- 4
43
- ];
44
- _state.label = 1;
45
- case 1:
46
- _state.trys.push([
47
- 1,
48
- 3,
49
- ,
50
- 4
51
- ]);
52
- return [
53
- 4,
54
- updateFiles({
55
- key: key,
56
- bucket: bucket,
57
- file: file
58
- })
59
- ];
60
- case 2:
61
- result = _state.sent();
62
- if (result) {
63
- ;
64
- (_props_onChange = props.onChange) === null || _props_onChange === void 0 ? void 0 : _props_onChange.call(props, result);
65
- (_props_onChangePath = props.onChangePath) === null || _props_onChangePath === void 0 ? void 0 : _props_onChangePath.call(props, key);
66
- }
67
- return [
68
- 3,
69
- 4
70
- ];
71
- case 3:
72
- error = _state.sent();
73
- return [
74
- 3,
75
- 4
76
- ];
77
- case 4:
78
- setLoading(false);
79
- return [
80
- 2
81
- ];
82
- }
83
- });
84
- });
85
- return function updateFile(file) {
86
- return _ref.apply(this, arguments);
87
- };
88
- }(), getValueFile = function() {
12
+ var locale = useLocale("UploadFile"), _message_useMessage = _sliced_to_array(message.useMessage(), 1), messageApi = _message_useMessage[0], _useState = _sliced_to_array(useState(false), 2), loading = _useState[0], setLoading = _useState[1], _useState1 = _sliced_to_array(useState(), 2), imgsrc = _useState1[0], setImgsrc = _useState1[1];
13
+ var getValueFile = function() {
89
14
  var _ref = _async_to_generator(function() {
90
15
  var result;
91
16
  return _ts_generator(this, function(_state) {
92
17
  switch(_state.label){
93
18
  case 0:
94
19
  if (!props.value) return [
95
- 3,
96
- 3
97
- ];
98
- if (!(bucket === "local")) return [
99
20
  3,
100
21
  2
101
22
  ];
102
23
  return [
103
24
  4,
104
- getFilesRaw(props.value, "url")
25
+ parseStorageUrl(props.value, {
26
+ endpoint: props.endpoint,
27
+ bucket: props.bucket
28
+ })
105
29
  ];
106
30
  case 1:
107
31
  result = _state.sent();
108
- if (typeof result === "string") {
32
+ if (result) {
109
33
  setImgsrc(result);
110
34
  }
111
- _state.label = 2;
112
- case 2:
113
35
  return [
114
36
  3,
115
- 4
37
+ 3
116
38
  ];
117
- case 3:
39
+ case 2:
118
40
  setImgsrc(undefined);
119
- _state.label = 4;
120
- case 4:
41
+ _state.label = 3;
42
+ case 3:
121
43
  return [
122
44
  2
123
45
  ];
@@ -145,7 +67,7 @@ export default function(props) {
145
67
  showUploadList: false,
146
68
  beforeUpload: function() {
147
69
  var _ref = _async_to_generator(function(file) {
148
- var maxSize;
70
+ var maxSize, result, _props_onChange, storageUrl, url;
149
71
  return _ts_generator(this, function(_state) {
150
72
  switch(_state.label){
151
73
  case 0:
@@ -157,12 +79,51 @@ export default function(props) {
157
79
  false
158
80
  ];
159
81
  }
82
+ setLoading(true);
160
83
  return [
161
84
  4,
162
- updateFile(file)
85
+ uploadFile(file, props.directory, {
86
+ endpoint: props.endpoint,
87
+ bucket: props.bucket,
88
+ useFileName: props.useFileName,
89
+ custromFileName: props.custromFileName
90
+ })
163
91
  ];
164
92
  case 1:
165
- _state.sent();
93
+ result = _state.sent();
94
+ if (!(result === null || result === void 0 ? void 0 : result.path)) return [
95
+ 3,
96
+ 4
97
+ ];
98
+ return [
99
+ 4,
100
+ getStorageUrl(result.path, {
101
+ endpoint: props.endpoint,
102
+ bucket: props.bucket
103
+ })
104
+ ];
105
+ case 2:
106
+ storageUrl = _state.sent();
107
+ return [
108
+ 4,
109
+ getFileUrl(result.path, {
110
+ endpoint: props.endpoint,
111
+ bucket: props.bucket
112
+ })
113
+ ];
114
+ case 3:
115
+ url = _state.sent();
116
+ (_props_onChange = props.onChange) === null || _props_onChange === void 0 ? void 0 : _props_onChange.call(props, storageUrl);
117
+ setImgsrc(url);
118
+ return [
119
+ 3,
120
+ 5
121
+ ];
122
+ case 4:
123
+ messageApi.error(locale.errorUpload);
124
+ _state.label = 5;
125
+ case 5:
126
+ setLoading(false);
166
127
  return [
167
128
  2,
168
129
  false
@@ -1 +1 @@
1
- {"version":3,"sources":[".\\src\\components\\upload-file\\uploadAvatar.tsx"],"sourcesContent":["import { PlusOutlined } from \"@ant-design/icons\";\r\nimport { Spin, Upload, message } from \"antd\"\r\nimport { RcFile } from \"antd/es/upload\";\r\nimport { useEffect, useState } from \"react\";\r\nimport { useAppCode, useTenantId } from \"../provider\";\r\nimport { UploadFileProps } from \".\";\r\nimport { useLocale } from \"../locale\";\r\nimport { formatFileSize, randomId } from \"../_util\";\r\nimport { getFilesRaw, updateFiles } from \"@knockout-js/api\";\r\n\r\nexport default (props: UploadFileProps<string>) => {\r\n const\r\n bucket = props.bucket ?? 'local',\r\n appCode = props.appCode ?? useAppCode(),\r\n tenantId = props.tenantId ?? useTenantId(),\r\n locale = useLocale(\"UploadFile\"),\r\n [messageApi] = message.useMessage(),\r\n [loading, setLoading] = useState(false),\r\n [imgsrc, setImgsrc] = useState<string>();\r\n\r\n const\r\n getUploadKey = (file: RcFile) => {\r\n const suffix = file.name.split('.').pop(),\r\n keys: string[] = [];\r\n if (props.forceDirectory && props.directory) {\r\n keys.push(props.directory)\r\n } else {\r\n if (appCode) {\r\n keys.push(appCode)\r\n }\r\n if (tenantId) {\r\n keys.push(tenantId)\r\n }\r\n if (props.directory) {\r\n keys.push(props.directory)\r\n }\r\n }\r\n keys.push(`${randomId(16)}.${suffix}`);\r\n return `/${keys.join('/')}`.replace('//', '/');\r\n },\r\n updateFile = async (file: RcFile) => {\r\n const key = getUploadKey(file);\r\n setLoading(true);\r\n if (bucket === 'local') {\r\n try {\r\n const result = await updateFiles({\r\n key,\r\n bucket,\r\n file,\r\n })\r\n if (result) {\r\n props.onChange?.(result)\r\n props.onChangePath?.(key);\r\n }\r\n } catch (error) {\r\n\r\n }\r\n }\r\n setLoading(false)\r\n },\r\n getValueFile = async () => {\r\n if (props.value) {\r\n if (bucket === 'local') {\r\n const result = await getFilesRaw(props.value, 'url');\r\n if (typeof result === 'string') {\r\n setImgsrc(result)\r\n }\r\n }\r\n } else {\r\n setImgsrc(undefined)\r\n }\r\n }\r\n\r\n useEffect(() => {\r\n getValueFile()\r\n }, [props.value])\r\n\r\n return <div style={{ display: \"inline-block\" }}>\r\n <Spin spinning={loading} >\r\n <Upload\r\n accept={props.accept}\r\n listType=\"picture-card\"\r\n showUploadList={false}\r\n beforeUpload={async (file) => {\r\n const maxSize = props.maxSize || (1024 * 1024 * 5);\r\n\r\n if (file.size > maxSize) {\r\n messageApi.error(`${locale.fileSizeTip}: ${formatFileSize(maxSize)}`);\r\n return false;\r\n }\r\n\r\n await updateFile(file);\r\n return false;\r\n }}\r\n >\r\n {\r\n imgsrc ? <img\r\n src={imgsrc} alt=\"avatar\" style={{ width: '100%' }}\r\n /> : <>\r\n <PlusOutlined rev={undefined} />\r\n <div style={{ marginTop: 8 }}></div>\r\n </>\r\n }\r\n </Upload>\r\n </Spin>\r\n </div>\r\n}\r\n"],"names":["PlusOutlined","Spin","Upload","message","useEffect","useState","useAppCode","useTenantId","useLocale","formatFileSize","randomId","getFilesRaw","updateFiles","props","bucket","appCode","tenantId","locale","useMessage","messageApi","loading","setLoading","imgsrc","setImgsrc","getUploadKey","file","suffix","name","split","pop","keys","forceDirectory","directory","push","join","replace","updateFile","key","result","error","onChange","onChangePath","getValueFile","value","undefined","div","style","display","spinning","accept","listType","showUploadList","beforeUpload","maxSize","size","fileSizeTip","img","src","alt","width","rev","marginTop"],"mappings":";;;;AAAA,SAASA,YAAY,QAAQ,oBAAoB;AACjD,SAASC,IAAI,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAM;AAE5C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAC5C,SAASC,UAAU,EAAEC,WAAW,QAAQ,oBAAc;AAEtD,SAASC,SAAS,QAAQ,kBAAY;AACtC,SAASC,cAAc,EAAEC,QAAQ,QAAQ,iBAAW;AACpD,SAASC,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AAE5D,eAAe,SAACC,OAAmC;QAEtCA,eACCA,gBACCA;IAHb,IACEC,SAASD,CAAAA,gBAAAA,MAAMC,MAAM,cAAZD,2BAAAA,gBAAgB,OAAO,EAChCE,UAAUF,CAAAA,iBAAAA,MAAME,OAAO,cAAbF,4BAAAA,iBAAiBP,YAAY,EACvCU,WAAWH,CAAAA,kBAAAA,MAAMG,QAAQ,cAAdH,6BAAAA,kBAAkBN,aAAa,EAC1CU,SAAST,UAAU,eACJL,uCAAAA,QAAQe,UAAU,QAAhCC,aAAchB,wBACSE,6BAAAA,SAAS,KAAK,OAArCe,UAAuBf,cAAdgB,aAAchB,cACFA,8BAAAA,gBAArBiB,SAAqBjB,eAAbkB,YAAalB;IAExB,IACEmB,eAAe,SAACC,MAAiB;QAC/B,I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WAAW,OAAM,GAAjBA;;;;wBACa;;4BAAMH,YAAYE,MAAM8B,KAAK,EAAE;;;wBAAxCL,SAAS;wBACf,IAAI,OAAOA,WAAW,UAAU;4BAC9Bf,UAAUe;wBACZ,CAAC;;;;;;;;wBAGHf,UAAUqB;;;;;;;;QAEd;wBAXAF;;;;IAaFtC,UAAU,WAAM;QACdsC;IACF,GAAG;QAAC7B,MAAM8B,KAAK;KAAC;IAEhB,qBAAO,KAACE;QAAIC,OAAO;YAAEC,SAAS;QAAe;kBAC3C,cAAA,KAAC9C;YAAK+C,UAAU5B;sBACd,cAAA,KAAClB;gBACC+C,QAAQpC,MAAMoC,MAAM;gBACpBC,UAAS;gBACTC,gBAAgB,KAAK;gBACrBC,YAAY;+BAAE,oBAAA,SAAO3B,MAAS;4BACtB4B;;;;oCAAAA,UAAUxC,MAAMwC,OAAO,IAAK,OAAO,OAAO;oCAEhD,IAAI5B,KAAK6B,IAAI,GAAGD,SAAS;wCACvBlC,WAAWoB,KAAK,CAAC,AAAC,GAAyB9B,OAAvBQ,OAAOsC,WAAW,EAAC,MAA4B,OAAxB9C,eAAe4C;wCAC1D;;4CAAO,KAAK;;oCACd,CAAC;oCAED;;wCAAMjB,WAAWX;;;oCAAjB;oCACA;;wCAAO,KAAK;;;;oBACd;oCAVqBA;;;;0BAanBH,uBAAS,KAACkC;oBACRC,KAAKnC;oBAAQoC,KAAI;oBAASZ,OAAO;wBAAEa,OAAO;oBAAO;mCAC9C;;sCACH,KAAC3D;4BAAa4D,KAAKhB;;sCACnB,KAACC;4BAAIC,OAAO;gCAAEe,WAAW;4BAAE;;;kBAC1B;;;;AAKb,EAAC"}
1
+ {"version":3,"sources":[".\\src\\components\\upload-file\\uploadAvatar.tsx"],"sourcesContent":["import { PlusOutlined } from \"@ant-design/icons\";\r\nimport { Spin, Upload, message } from \"antd\"\r\nimport { useEffect, useState } from \"react\";\r\nimport { UploadFileProps } from \"./index\";\r\nimport { useLocale } from \"../locale\";\r\nimport { formatFileSize } from \"../_util\";\r\nimport { parseStorageUrl, getStorageUrl, uploadFile, getFileUrl } from \"@knockout-js/api\";\r\n\r\nexport default (props: UploadFileProps<string>) => {\r\n const locale = useLocale(\"UploadFile\"),\r\n [messageApi] = message.useMessage(),\r\n [loading, setLoading] = useState(false),\r\n [imgsrc, setImgsrc] = useState<string>();\r\n\r\n const getValueFile = async () => {\r\n if (props.value) {\r\n const result = await parseStorageUrl(props.value, {\r\n endpoint: props.endpoint,\r\n bucket: props.bucket\r\n });\r\n if (result) {\r\n setImgsrc(result)\r\n }\r\n } else {\r\n setImgsrc(undefined)\r\n }\r\n }\r\n\r\n useEffect(() => {\r\n getValueFile()\r\n }, [props.value])\r\n\r\n return <div style={{ display: \"inline-block\" }}>\r\n <Spin spinning={loading} >\r\n <Upload\r\n accept={props.accept}\r\n listType=\"picture-card\"\r\n showUploadList={false}\r\n beforeUpload={async (file) => {\r\n const maxSize = props.maxSize || (1024 * 1024 * 5);\r\n\r\n if (file.size > maxSize) {\r\n messageApi.error(`${locale.fileSizeTip}: ${formatFileSize(maxSize)}`);\r\n return false;\r\n }\r\n setLoading(true);\r\n const result = await uploadFile(file, props.directory, {\r\n endpoint: props.endpoint,\r\n bucket: props.bucket,\r\n useFileName: props.useFileName,\r\n custromFileName: props.custromFileName,\r\n });\r\n\r\n if (result?.path) {\r\n const storageUrl = await getStorageUrl(result.path, {\r\n endpoint: props.endpoint,\r\n bucket: props.bucket,\r\n });\r\n const url = await getFileUrl(result.path, {\r\n endpoint: props.endpoint,\r\n bucket: props.bucket\r\n })\r\n props.onChange?.(storageUrl);\r\n setImgsrc(url)\r\n } else {\r\n messageApi.error(locale.errorUpload);\r\n }\r\n setLoading(false)\r\n return false;\r\n }}\r\n >\r\n {\r\n imgsrc ? <img\r\n src={imgsrc} alt=\"avatar\" style={{ width: '100%' }}\r\n /> : <>\r\n <PlusOutlined rev={undefined} />\r\n <div style={{ marginTop: 8 }}></div>\r\n </>\r\n }\r\n </Upload>\r\n </Spin>\r\n </div>\r\n}\r\n"],"names":["PlusOutlined","Spin","Upload","message","useEffect","useState","useLocale","formatFileSize","parseStorageUrl","getStorageUrl","uploadFile","getFileUrl","props","locale","useMessage","messageApi","loading","setLoading","imgsrc","setImgsrc","getValueFile","result","value","endpoint","bucket","undefined","div","style","display","spinning","accept","listType","showUploadList","beforeUpload","file","maxSize","storageUrl","url","size","error","fileSizeTip","directory","useFileName","custromFileName","path","onChange","errorUpload","img","src","alt","width","rev","marginTop"],"mappings":";;;;AAAA,SAASA,YAAY,QAAQ,oBAAoB;AACjD,SAASC,IAAI,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAM;AAC5C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAE5C,SAASC,SAAS,QAAQ,kBAAY;AACtC,SAASC,cAAc,QAAQ,iBAAW;AAC1C,SAASC,eAAe,EAAEC,aAAa,EAAEC,UAAU,EAAEC,UAAU,QAAQ,mBAAmB;AAE1F,eAAe,SAACC,OAAmC;IACjD,IAAMC,SAASP,UAAU,eACRH,uCAAAA,QAAQW,UAAU,QAAhCC,aAAcZ,wBACSE,6BAAAA,SAAS,KAAK,OAArCW,UAAuBX,cAAdY,aAAcZ,cACFA,8BAAAA,gBAArBa,SAAqBb,eAAbc,YAAad;IAExB,IAAMe;mBAAe,oBAAA,WAAY;gBAEvBC;;;;6BADJT,MAAMU,KAAK,EAAXV;;;;wBACa;;4BAAMJ,gBAAgBI,MAAMU,KAAK,EAAE;gCAChDC,UAAUX,MAAMW,QAAQ;gCACxBC,QAAQZ,MAAMY,MAAM;4BACtB;;;wBAHMH,SAAS;wBAIf,IAAIA,QAAQ;4BACVF,UAAUE;wBACZ,CAAC;;;;;;wBAEDF,UAAUM;;;;;;;;QAEd;wBAZML;;;;IAcNhB,UAAU,WAAM;QACdgB;IACF,GAAG;QAACR,MAAMU,KAAK;KAAC;IAEhB,qBAAO,KAACI;QAAIC,OAAO;YAAEC,SAAS;QAAe;kBAC3C,cAAA,KAAC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