Skip to content

Commit ef6433d

Browse files
committed
feat: ✨ Upload新增preview-cover插槽
1 parent f8a5240 commit ef6433d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

docs/component/upload.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,25 @@ const customUpload: UploadMethod = (file, formData, options) => {
567567
}
568568
```
569569

570+
571+
## 自定义预览样式
572+
573+
使用 `preview-cover` 插槽可以自定义覆盖在预览区域上方的内容
574+
575+
```html
576+
<wd-upload v-model:file-list="fileList" accept="image" image-mode="aspectFill">
577+
<template #preview-cover="{ file }">
578+
<view class="preview-cover">{{ file.name }}</view>
579+
</template>
580+
</wd-upload>
581+
<style>
582+
.preview-cover {
583+
margin-top: 10rpx;
584+
text-align: center;
585+
}
586+
</style>
587+
```
588+
570589
## Attributes
571590

572591
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
@@ -630,6 +649,7 @@ const customUpload: UploadMethod = (file, formData, options) => {
630649
| name | 说明 | 最低版本 |
631650
| ------- | ---------------- | -------- |
632651
| default | 上传唤起插槽样式 | - |
652+
| preview-cover | 自定义覆盖在预览区域上方的内容 | - |
633653

634654
## Events
635655

src/pages/upload/Index.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@
7373
<demo-block title="自定义上传方法">
7474
<wd-upload v-model:file-list="fileList15" :upload-method="customUpload"></wd-upload>
7575
</demo-block>
76+
77+
<demo-block title="自定义预览样式">
78+
<wd-upload v-model:file-list="fileList16" accept="image" image-mode="aspectFill">
79+
<template #preview-cover="{ file }">
80+
<view class="preview-cover">{{ file.name }}</view>
81+
</template>
82+
</wd-upload>
83+
</demo-block>
7684
</page-wraper>
7785
</template>
7886
<script lang="ts" setup>
@@ -106,6 +114,12 @@ const fileList12 = ref<UploadFile[]>([])
106114
const fileList13 = ref<UploadFile[]>([])
107115
const fileList14 = ref<UploadFile[]>([])
108116
const fileList15 = ref<UploadFile[]>([])
117+
const fileList16 = ref<UploadFile[]>([
118+
{
119+
url: 'https://registry.npmmirror.com/wot-design-uni-assets/*/files/panda.jpg',
120+
name: 'panda'
121+
}
122+
])
109123
110124
const upload14 = ref<UploadInstance>()
111125
@@ -292,4 +306,9 @@ const customUpload: UploadMethod = (file, formData, options) => {
292306
})
293307
}
294308
</script>
295-
<style lang="scss" scoped></style>
309+
<style lang="scss" scoped>
310+
.preview-cover {
311+
margin-top: 10rpx;
312+
text-align: center;
313+
}
314+
</style>

src/uni_modules/wot-design-uni/components/wd-upload/wd-upload.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
custom-class="wd-upload__close"
6565
@click="removeFile(index)"
6666
></wd-icon>
67+
<!-- 自定义预览样式 -->
68+
<slot name="preview-cover" v-if="$slots['preview-cover']" :file="file"></slot>
6769
</view>
6870

6971
<block v-if="showUpload">

0 commit comments

Comments
 (0)