From d0ba44b0dc6104e43233679860192ecefe093a05 Mon Sep 17 00:00:00 2001 From: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Date: Wed, 1 Nov 2023 17:34:28 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4InputFile=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?,=20=E5=A2=9E=E5=8A=A0=E5=A4=9A=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E7=A4=BA=E4=BE=8B=20(#8566)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-CN/components/form/input-file.md | 42 +++++++++++++++++++ mock/cfc/mock/upload/random.js | 31 ++++++++++++++ .../amis-ui/scss/components/form/_file.scss | 1 + .../amis/src/renderers/Form/InputFile.tsx | 2 +- 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 mock/cfc/mock/upload/random.js diff --git a/docs/zh-CN/components/form/input-file.md b/docs/zh-CN/components/form/input-file.md index b2f1d270b..19b69beb2 100755 --- a/docs/zh-CN/components/form/input-file.md +++ b/docs/zh-CN/components/form/input-file.md @@ -302,6 +302,48 @@ order: 21 } ``` +## 上传文件列表 + +```schema: scope="body" +{ + "type": "form", + "api": "/api/mock2/form/saveForm", + "debug": true, + "data": { + "files": [ + { + "id":"2ba48d02d349", + "value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md", + "url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md", + "filename":"file1.md", + "name":"file1.md", + "state":"uploaded" + }, + { + "id":"14723e0bc640", + "value":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md", + "url":"http://amis.bj.bcebos.com/amis/2017-11/1510713111265/fis3-react.md", + "filename":"file2.md", + "name":"file2.md", + "state":"uploaded" + } + ] + }, + "body": [ + { + "type": "input-file", + "name": "files", + "label": false, + "mode": "horizontal", + "accept": "*", + "receiver": "/api/mock2/upload/random", + "multiple": true, + "joinValues": false + } + ] +} +``` + ## 属性表 除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置 diff --git a/mock/cfc/mock/upload/random.js b/mock/cfc/mock/upload/random.js new file mode 100644 index 000000000..cb13cc5c6 --- /dev/null +++ b/mock/cfc/mock/upload/random.js @@ -0,0 +1,31 @@ +/** 测试上传,随机成功 */ +module.exports = function(req, res) { + const pool = [1,2,3,4,5,6,7,8,9,10]; + let result = pool.slice(); + + for( let i = 0; i < pool.length; i++) { + let k = Math.floor(Math.random() * (pool.length - i) + i); + [result[i], result[k]] = [result[k], result[i]]; + } + + const randomNum = result[0]; + + if (randomNum > 5) { + return res.json({ + status: 0, + msg: '上传成功', + data: { + "value": `http://amis.bj.bcebos.com/amis/random/${randomNum}`, + "url": `http://amis.bj.bcebos.com/amis/random/${randomNum}`, + "filename": `random${randomNum}.js` + } + }); + } + else { + return res.json({ + status: 500, + msg: '上传失败', + data: null + }); + } +} diff --git a/packages/amis-ui/scss/components/form/_file.scss b/packages/amis-ui/scss/components/form/_file.scss index e7abe2f7f..a724707cc 100644 --- a/packages/amis-ui/scss/components/form/_file.scss +++ b/packages/amis-ui/scss/components/form/_file.scss @@ -300,6 +300,7 @@ > a { cursor: pointer; + font-size: var(--fontSizeSm); } } } diff --git a/packages/amis/src/renderers/Form/InputFile.tsx b/packages/amis/src/renderers/Form/InputFile.tsx index 2778cbe97..49a18a6a1 100644 --- a/packages/amis/src/renderers/Form/InputFile.tsx +++ b/packages/amis/src/renderers/Form/InputFile.tsx @@ -1497,7 +1497,7 @@ export default class FileControl extends React.Component { return (