Skip to content

Commit 99eab74

Browse files
author
xuqingkai
committed
feat: ✨ Upload上传组件新增支持successStatus属性
用于指定接口响应的成功状态(statusCode)值,方便开发者自行控制接口成功状态
1 parent 4e9e19e commit 99eab74

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

docs/component/upload.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ function handleChange({ files }) {
514514
| compressed | 是否压缩视频,当 accept 为 video \| media 时生效 | boolean | - | true | 1.3.0 |
515515
| maxDuration | 拍摄视频最长拍摄时间,当 accept 为 video \| media 时生效,单位秒 | Number | - | 60 | 1.3.0 |
516516
| camera | 使用前置或者后置相机,当 accept 为 video \| media 时生效 | UploadCameraType | **front** | **back** | 1.3.0 |
517+
| successStatus | 接口响应的成功状态(statusCode)值 | number | - | 200 | $LOWEST_VERSION$ |
518+
517519

518520
## accept 的合法值
519521

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ export const uploadProps = {
273273
* 默认值:'back'
274274
*/
275275
camera: makeStringProp<UploadCameraType>('back'),
276+
/**
277+
* 预览图片的mode属性
278+
*/
279+
imageMode: makeStringProp<ImageMode>('aspectFit'),
280+
/**
281+
* 接口响应的成功状态(statusCode)值
282+
*/
283+
successStatus: makeNumberProp(200),
276284
/**
277285
* 自定义上传按钮样式
278286
* 类型:string
@@ -282,11 +290,7 @@ export const uploadProps = {
282290
* 自定义预览图片列表样式
283291
* 类型:string
284292
*/
285-
customPreviewClass: makeStringProp(''),
286-
/**
287-
* 预览图片的mode属性
288-
*/
289-
imageMode: makeStringProp<ImageMode>('aspectFit')
293+
customPreviewClass: makeStringProp('')
290294
}
291295

292296
export type UploadProps = ExtractPropTypes<typeof uploadProps>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default {
9090

9191
<script lang="ts" setup>
9292
import { computed, ref, watch } from 'vue'
93-
import { context, getType, isEqual, isImageUrl, isVideoUrl, isFunction } from '../common/util'
93+
import { context, getType, isEqual, isImageUrl, isVideoUrl, isFunction, isDef } from '../common/util'
9494
import { chooseFile } from './utils'
9595
import { useTranslate } from '../composables/useTranslate'
9696
import { uploadProps, type UploadFileItem, type ChooseFile } from './types'
@@ -319,6 +319,7 @@ function handleProgress(res: Record<string, any>, file: UploadFileItem) {
319319
*/
320320
function handleUpload(file: UploadFileItem, formData: Record<string, any>) {
321321
const { action, name, header = {}, accept } = props
322+
const statusCode = isDef(props.successStatus) ? props.successStatus : 200
322323
const uploadTask = uni.uploadFile({
323324
url: action,
324325
header,
@@ -328,7 +329,7 @@ function handleUpload(file: UploadFileItem, formData: Record<string, any>) {
328329
formData,
329330
filePath: file.url,
330331
success(res) {
331-
if (res.statusCode === 200) {
332+
if (res.statusCode === statusCode) {
332333
// 上传成功进行文件列表拼接
333334
handleSuccess(res, file, formData)
334335
} else {

0 commit comments

Comments
 (0)