From 961f65215d4479f912b392b73a7d7857985398ef Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Wed, 9 Oct 2024 22:20:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0/?= =?UTF-8?q?=E5=9B=9E=E6=98=BE=E6=94=AF=E6=8C=81=E7=BB=91=E5=AE=9Astring?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/upload/src/helper.ts | 1 - .../components/upload/src/image-upload.vue | 30 ++++++++++++++----- .../views/演示使用自行删除/upload/index.vue | 14 +++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/apps/web-antd/src/components/upload/src/helper.ts b/apps/web-antd/src/components/upload/src/helper.ts index 77db9509..7c7c0078 100644 --- a/apps/web-antd/src/components/upload/src/helper.ts +++ b/apps/web-antd/src/components/upload/src/helper.ts @@ -1,5 +1,4 @@ export function checkFileType(file: File, accepts: string[]) { - console.log(file.name, accepts); let reg; if (!accepts || accepts.length === 0) { reg = /.(?:jpg|jpeg|png|gif|webp)$/i; diff --git a/apps/web-antd/src/components/upload/src/image-upload.vue b/apps/web-antd/src/components/upload/src/image-upload.vue index cb30e8f2..88e08481 100644 --- a/apps/web-antd/src/components/upload/src/image-upload.vue +++ b/apps/web-antd/src/components/upload/src/image-upload.vue @@ -40,7 +40,7 @@ const props = withDefaults( // support xxx.xxx.xx // 返回的字段 默认url resultField?: 'fileName' | 'ossId' | 'url' | string; - value?: string[]; + value?: string | string[]; }>(), { value: () => [], @@ -81,14 +81,18 @@ watch( isInnerOperate.value = false; return; } - let value: string[] = []; + let value: string | string[] = []; if (v) { - if (isArray(v)) { - value = v; - } else { - value.push(v); + const _fileList: string[] = []; + if (isString(v)) { + _fileList.push(v); } - fileList.value = value.map((item, i) => { + if (isArray(v)) { + _fileList.push(...v); + } + // 直接赋值 可能为string | string[] + value = v; + fileList.value = _fileList.map((item, i) => { if (item && isString(item)) { return { uid: `${-i}`, @@ -205,9 +209,21 @@ function getValue() { if (item?.response && props?.resultField) { return item?.response?.[props.resultField]; } + // 适用于已经有图片 回显的情况 会默认在init处理为{url: 'xx'} + if (item?.url) { + return item.url; + } // 注意这里取的key为 url return item?.response?.url; }); + // 只有一张图片 默认绑定string而非string[] + if (props.maxNumber === 1 && list.length === 1) { + return list[0]; + } + // 只有一张图片 && 删除图片时 可自行修改 + if (props.maxNumber === 1 && list.length === 0) { + return ''; + } return list; } diff --git a/apps/web-antd/src/views/演示使用自行删除/upload/index.vue b/apps/web-antd/src/views/演示使用自行删除/upload/index.vue index 237c5c02..3508e431 100644 --- a/apps/web-antd/src/views/演示使用自行删除/upload/index.vue +++ b/apps/web-antd/src/views/演示使用自行删除/upload/index.vue @@ -16,10 +16,24 @@ const fieldOptions = [ { label: '链接地址', value: 'url' }, ]; const fileAccept = ['txt', 'excel', 'word', 'pdf']; + +const signleImage = ref('');