Skip to content

Commit acf3f99

Browse files
jasper-opsMoonofweisheng
authored andcommitted
feat: ✨ upload组件增加mode属性传递给预览image
Closes: #203
1 parent 1398982 commit acf3f99

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

docs/component/upload.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
`action` 设置图片上传的地址;
1414

1515
```html
16-
<wd-upload :file-list="fileList" :action="action" @change="handleChange"></wd-upload>
16+
<wd-upload :file-list="fileList1" image-mode="aspectFill" :action="action" @change="handleChange1"></wd-upload>
1717
```
1818

1919
```typescript
@@ -214,7 +214,7 @@ function handleChange({ files }) {
214214
- `formData` 待处理的`formData`
215215
- `resolve` 函数,用于告知组件是否组装`formData`成功,`resolve(formData)` 表示组装成功。
216216

217-
217+
218218

219219
```html
220220
<wd-upload :file-list="files" :action="host" :build-form-data="buildFormData" @change="handleChange"></wd-upload>
@@ -290,8 +290,8 @@ const buildFormData = ({ file, formData, resolve }) => {
290290
const key = `20231120/${imageName}` // 图片上传到oss的路径(拼接你的文件夹和文件名)
291291
const qAk = 'your qAk'
292292
const qSignAlgorithm = 'your qSignAlgorithm'
293-
const qKeyTime = 'your qKeyTime'
294-
const qSignature = 'your qSignature'
293+
const qKeyTime = 'your qKeyTime'
294+
const qSignature = 'your qSignature'
295295
const success_action_status = '200' // 将上传成功状态码设置为200
296296
formData = {
297297
...formData,
@@ -395,6 +395,7 @@ const fileList = ref<any[]>([
395395
| loading-size | [加载中图标尺寸](/component/loading) | string | - | 24px | - |
396396
| use-default-slot | 开启默认唤起项插槽 | boolean | - | false | - |
397397
| status-key | file 数据结构中,status 对应的 key | string | - | status | - |
398+
| image-mode | 预览图片的mode属性 | ImageMode | - | aspectFit | - |
398399

399400
## file 数据结构
400401

src/pages/upload/Index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<wd-message-box></wd-message-box>
77
<wd-toast id="wd-toast"></wd-toast>
88
<demo-block title="基本用法">
9-
<wd-upload :file-list="fileList1" :action="action" @change="handleChange1"></wd-upload>
9+
<wd-upload :file-list="fileList1" image-mode="aspectFill" :action="action" @change="handleChange1"></wd-upload>
1010
</demo-block>
1111
<demo-block title="多选上传">
1212
<wd-upload :file-list="fileList2" multiple :action="action" @change="handleChange2"></wd-upload>
@@ -57,7 +57,7 @@ import { ref } from 'vue'
5757
const action: string = 'https://ftf.jd.com/api/uploadImg'
5858
const fileList1 = ref<any[]>([
5959
{
60-
url: 'https://img12.360buyimg.com//n0/jfs/t1/29118/6/4823/55969/5c35c16bE7c262192/c9fdecec4b419355.jpg'
60+
url: 'https://img.yzcdn.cn/vant/cat.jpeg'
6161
}
6262
])
6363
const fileList2 = ref<any[]>([

src/uni_modules/wot-design-uni/components/wd-upload/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ExtractPropTypes, PropType } from 'vue'
22
import { baseProps, makeArrayProp, makeBooleanProp, makeNumberProp, makeStringProp } from '../common/props'
33
import type { LoadingType } from '../wd-loading/types'
4+
import type { ImageMode } from '../wd-img/types'
45

56
export interface ChooseFileOption {
67
multiple: boolean
@@ -217,7 +218,11 @@ export const uploadProps = {
217218
*/
218219
loadingSize: makeStringProp('24px'),
219220
customEvokeClass: makeStringProp(''),
220-
customPreviewClass: makeStringProp('')
221+
customPreviewClass: makeStringProp(''),
222+
/**
223+
* 预览图片的mode属性
224+
*/
225+
imageMode: makeStringProp<ImageMode>('aspectFit')
221226
}
222227

223228
export type UploadProps = ExtractPropTypes<typeof uploadProps>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<view :class="['wd-upload__preview', customPreviewClass]" v-for="(file, index) in uploadFiles" :key="index">
55
<!-- 成功时展示图片 -->
66
<view class="wd-upload__status-content">
7-
<image :src="file.url" mode="aspectFit" class="wd-upload__picture" @click="onPreviewImage(index)" />
7+
<image :src="file.url" :mode="imageMode" class="wd-upload__picture" @click="onPreviewImage(index)" />
88
</view>
99

1010
<view v-if="file.status !== 'success'" class="wd-upload__mask wd-upload__status-content">

0 commit comments

Comments
 (0)