Update form-upload.vue
This commit is contained in:
parent
5aca3ebe39
commit
0ac2f70143
@ -11,7 +11,7 @@
|
||||
<uni-icons type="close" :size="32" color="red" class="remove-icon" @click="remove(idx)"></uni-icons>
|
||||
</view>
|
||||
<view v-if="value.length < 10"
|
||||
class="upload-item border-primary mt-10 flex items-center justify-center text-primary" @click="addFile()">
|
||||
class="upload-item border-primary mt-10 flex items-center justify-center text-primary" @click="chooseType()">
|
||||
<uni-icons type="camera" :size="40" color="#0074ff"></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
@ -54,7 +54,20 @@ const files = computed(() => value.value.map(i => {
|
||||
}
|
||||
}))
|
||||
|
||||
function addFile() {
|
||||
function chooseType() {
|
||||
uni.showActionSheet({
|
||||
itemList: ['图片', 'PDF'],
|
||||
success: (res) => {
|
||||
if (res.tapIndex === 0) {
|
||||
addImage()
|
||||
} else if (res.tapIndex === 1) {
|
||||
addPdf()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function addPdf() {
|
||||
wx.chooseMessageFile({
|
||||
count: 1, // 最多选择1个文件
|
||||
type: 'all', // 所有类型文件
|
||||
@ -74,8 +87,8 @@ function addFile() {
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
if(/cancel/i.test(err.errMsg)){
|
||||
toast('用户取消选择文件')
|
||||
if (/cancel/i.test(err.errMsg)) {
|
||||
// toast('用户取消选择文件')
|
||||
} else {
|
||||
toast('上传失败')
|
||||
}
|
||||
@ -103,21 +116,28 @@ function checkFileValid(fileName, fileSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// function addImage() {
|
||||
// uni.chooseImage({
|
||||
// count: 1,
|
||||
// success: async (res) => {
|
||||
// loading();
|
||||
// const result = await upload(res.tempFilePaths[0]);
|
||||
// hideLoading();
|
||||
// if (result) {
|
||||
// change([...value.value, { url: result, type: 'image/png' }])
|
||||
// } else {
|
||||
// toast('上传失败')
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
function addImage() {
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
success: async (res) => {
|
||||
loading();
|
||||
const result = await upload(res.tempFilePaths[0]);
|
||||
hideLoading();
|
||||
if (result) {
|
||||
change([...value.value, { url: result, type: 'image/png' }])
|
||||
} else {
|
||||
toast('上传失败')
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
if (/cancel/i.test(err.errMsg)) {
|
||||
// toast('用户取消选择文件')
|
||||
} else {
|
||||
toast('上传失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function change(value) {
|
||||
emits('change', {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user