Update form-upload.vue

This commit is contained in:
huxuejian 2026-04-21 14:51:10 +08:00
parent 5aca3ebe39
commit 0ac2f70143

View File

@ -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', //
@ -74,8 +87,8 @@ 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', {