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>
|
<uni-icons type="close" :size="32" color="red" class="remove-icon" @click="remove(idx)"></uni-icons>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="value.length < 10"
|
<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>
|
<uni-icons type="camera" :size="40" color="#0074ff"></uni-icons>
|
||||||
</view>
|
</view>
|
||||||
</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({
|
wx.chooseMessageFile({
|
||||||
count: 1, // 最多选择1个文件
|
count: 1, // 最多选择1个文件
|
||||||
type: 'all', // 所有类型文件
|
type: 'all', // 所有类型文件
|
||||||
@ -75,7 +88,7 @@ function addFile() {
|
|||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
if (/cancel/i.test(err.errMsg)) {
|
if (/cancel/i.test(err.errMsg)) {
|
||||||
toast('用户取消选择文件')
|
// toast('用户取消选择文件')
|
||||||
} else {
|
} else {
|
||||||
toast('上传失败')
|
toast('上传失败')
|
||||||
}
|
}
|
||||||
@ -103,21 +116,28 @@ function checkFileValid(fileName, fileSize) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// function addImage() {
|
function addImage() {
|
||||||
// uni.chooseImage({
|
uni.chooseImage({
|
||||||
// count: 1,
|
count: 1,
|
||||||
// success: async (res) => {
|
success: async (res) => {
|
||||||
// loading();
|
loading();
|
||||||
// const result = await upload(res.tempFilePaths[0]);
|
const result = await upload(res.tempFilePaths[0]);
|
||||||
// hideLoading();
|
hideLoading();
|
||||||
// if (result) {
|
if (result) {
|
||||||
// change([...value.value, { url: result, type: 'image/png' }])
|
change([...value.value, { url: result, type: 'image/png' }])
|
||||||
// } else {
|
} else {
|
||||||
// toast('上传失败')
|
toast('上传失败')
|
||||||
// }
|
}
|
||||||
// }
|
},
|
||||||
// })
|
fail: (err) => {
|
||||||
// }
|
if (/cancel/i.test(err.errMsg)) {
|
||||||
|
// toast('用户取消选择文件')
|
||||||
|
} else {
|
||||||
|
toast('上传失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function change(value) {
|
function change(value) {
|
||||||
emits('change', {
|
emits('change', {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user