From 463e0a7aee6f6f1ca61c2e18f88e5db4b30d9c4d Mon Sep 17 00:00:00 2001 From: haoziqaq <357229046@qq.com> Date: Thu, 14 Apr 2022 23:52:27 +0800 Subject: [PATCH] fix(ui/uploader): fix #426 --- .../__snapshots__/index.spec.js.snap | 16 +++-- packages/varlet-ui/src/uploader/Uploader.vue | 19 +++-- .../__snapshots__/index.spec.js.snap | 70 +++++++++++++------ packages/varlet-ui/src/uploader/uploader.less | 3 +- 4 files changed, 75 insertions(+), 33 deletions(-) diff --git a/packages/varlet-ui/src/form/__tests__/__snapshots__/index.spec.js.snap b/packages/varlet-ui/src/form/__tests__/__snapshots__/index.spec.js.snap index c6f9c2d7d69..f907da1024b 100644 --- a/packages/varlet-ui/src/form/__tests__/__snapshots__/index.spec.js.snap +++ b/packages/varlet-ui/src/form/__tests__/__snapshots__/index.spec.js.snap @@ -557,7 +557,9 @@ exports[`test form with switch 3`] = ` exports[`test form with uploader 1`] = ` "
-
+
+
+
@@ -576,7 +578,9 @@ exports[`test form with uploader 1`] = ` exports[`test form with uploader 2`] = ` "
-
+
+
+
@@ -595,7 +599,9 @@ exports[`test form with uploader 2`] = ` exports[`test form with uploader 3`] = ` "
-
+
+
+
至少上传一个
@@ -617,7 +623,9 @@ exports[`test form with uploader 3`] = ` exports[`test form with uploader 4`] = ` "
-
+
+
+
diff --git a/packages/varlet-ui/src/uploader/Uploader.vue b/packages/varlet-ui/src/uploader/Uploader.vue index 02a8ce20066..2ca2f637e72 100644 --- a/packages/varlet-ui/src/uploader/Uploader.vue +++ b/packages/varlet-ui/src/uploader/Uploader.vue @@ -20,16 +20,16 @@ >
- +
@@ -75,7 +75,7 @@ import VarIcon from '../icon' import VarPopup from '../popup' import ImagePreview from '../image-preview' import Ripple from '../ripple' -import { defineComponent, nextTick, reactive, computed, watch, ref, getCurrentInstance } from 'vue' +import { defineComponent, nextTick, reactive, computed, watch, ref } from 'vue' import { props } from './props' import { isNumber, isHTMLSupportImage, isHTMLSupportVideo, toNumber, isString } from '../utils/shared' import { call, useValidation, createNamespace } from '../utils/components' @@ -111,7 +111,7 @@ export default defineComponent({ }, props, setup(props) { - const id: Ref = ref(`var-uploader-${getCurrentInstance()!.uid}`) + const input: Ref = ref(null) const showPreview: Ref = ref(false) const currentPreview: Ref = ref(null) const maxlengthText: ComputedRef = computed(() => { @@ -141,6 +141,10 @@ export default defineComponent({ return modelValue }) + const triggerAction = () => { + input.value!.click() + } + const preview = (varFile: VarFile) => { const { disabled, readonly, previewed } = props @@ -322,7 +326,7 @@ export default defineComponent({ return { n, classes, - id, + input, files, showPreview, currentPreview, @@ -333,6 +337,7 @@ export default defineComponent({ formDisabled: form?.disabled, formReadonly: form?.readonly, preview, + triggerAction, handleChange, handleRemove, getSuccess, diff --git a/packages/varlet-ui/src/uploader/__tests__/__snapshots__/index.spec.js.snap b/packages/varlet-ui/src/uploader/__tests__/__snapshots__/index.spec.js.snap index bb3487b53b7..8e243d43aa2 100644 --- a/packages/varlet-ui/src/uploader/__tests__/__snapshots__/index.spec.js.snap +++ b/packages/varlet-ui/src/uploader/__tests__/__snapshots__/index.spec.js.snap @@ -2,7 +2,9 @@ exports[`test uploader disabled 1`] = ` "
-
+
+
+
@@ -25,7 +27,8 @@ exports[`test uploader disabled 2`] = `
-
+
+
@@ -44,7 +47,9 @@ exports[`test uploader disabled 2`] = ` exports[`test uploader example 1`] = ` "
基本使用
-
+
+
+
@@ -69,7 +74,8 @@ exports[`test uploader example 1`] = `
https://www.runoob.com/try/demo_source/mov_bbb.mp4
-
+
+
@@ -100,7 +106,8 @@ exports[`test uploader example 1`] = `
https://varlet.gitee.io/varlet-ui/cat.jpg
-
+ +
@@ -116,7 +123,9 @@ exports[`test uploader example 1`] = `
文件数量限制
-
+
+
+
@@ -134,7 +143,9 @@ exports[`test uploader example 1`] = `
文件大小限制
-
+
+
+
@@ -149,7 +160,9 @@ exports[`test uploader example 1`] = `
上传预处理
-
+
+
+
@@ -164,7 +177,9 @@ exports[`test uploader example 1`] = `
禁用
-
+
+
+
@@ -179,7 +194,9 @@ exports[`test uploader example 1`] = `
只读
-
+
+
+
@@ -199,7 +216,8 @@ exports[`test uploader example 1`] = `
https://varlet.gitee.io/varlet-ui/cat.jpg
-
+
+
@@ -215,10 +233,12 @@ exports[`test uploader example 1`] = `
自定义上传样式
-
+
+ @@ -238,7 +258,8 @@ exports[`test uploader example 1`] = `
https://varlet.gitee.io/varlet-ui/cat.jpg
- + +
@@ -259,10 +280,12 @@ exports[`test uploader example 1`] = `
-
+
+
@@ -282,7 +305,9 @@ exports[`test uploader example 1`] = ` exports[`test uploader hide file list 1`] = ` "
-
+
+
+
@@ -299,7 +324,9 @@ exports[`test uploader hide file list 1`] = ` exports[`test uploader length over maxlength in multiple mode 1`] = ` "
-
+
+
+
@@ -319,7 +346,9 @@ exports[`test uploader length over maxlength in multiple mode 1`] = ` exports[`test uploader validation 1`] = ` "
-
+
+
+
您至少上传一个
@@ -345,7 +374,8 @@ exports[`test uploader validation 2`] = `
-
+
+
diff --git a/packages/varlet-ui/src/uploader/uploader.less b/packages/varlet-ui/src/uploader/uploader.less index 1dd29c136f0..5e235a845b6 100644 --- a/packages/varlet-ui/src/uploader/uploader.less +++ b/packages/varlet-ui/src/uploader/uploader.less @@ -170,10 +170,9 @@ &__action-input { display: block; - z-index: 1; width: 0; height: 0; - opacity: 0; + visibility: hidden; } &__preview[var-uploader-cover] {