Files
yusheng-h5/component/uploadImage.vue

109 lines
2.7 KiB
Vue
Raw Normal View History

2025-08-11 11:06:07 +08:00
<template>
<uni-file-picker ref="filePicker" return-type="array" :limit="1" v-model="fileList" fileMediatype="image" mode="grid" :auto-upload="false" @select="select"
@progress="progress" @success="success" @fail="fail"></uni-file-picker>
</template>
<script>
2025-10-23 16:04:28 +08:00
// import config from '@/until/config.js';
2025-08-11 11:06:07 +08:00
export default {
data() {
return {
2025-10-23 16:04:28 +08:00
httpUrl: 'https://vespa.qxyushen.top',
2025-08-11 11:06:07 +08:00
fileList: []
}
},
watch:{
fileList(val){
this.$emit('changeImageList',this.fileList)
}
},
2025-10-23 16:04:28 +08:00
// onLoad() {
// this.httpUrl = config.BASE_URL
// },
2025-08-11 11:06:07 +08:00
methods: {
// 选择文件回调
select(e) {
this.tempFiles = e.tempFiles // 临时存储选择的文件
if (!this.tempFiles || this.tempFiles.length === 0) {
uni.showToast({
title: '请先选择文件',
icon: 'none'
})
return
}
// 遍历所有选择的文件
this.tempFiles.forEach(file => {
this.uploadFile(file)
})
// const platform = uni.getSystemInfoSync().platform;
// if (platform === 'ios') {
// this.tempFiles = e.tempFiles // 临时存储选择的文件
// if (!this.tempFiles || this.tempFiles.length === 0) {
// uni.showToast({
// title: '请先选择文件',
// icon: 'none'
// })
// return
// }
// // 遍历所有选择的文件
// this.tempFiles.forEach(file => {
// this.uploadFile(file)
// })
// } else if (platform === 'android') {
// // alert(e)
// // console.log('安卓android安卓android安卓android安卓android安卓android安卓android安卓android安卓android安卓android安卓android安卓android安卓android')
// uni.chooseImage({
// success: (chooseImageRes) => {
// const tempFilePaths = chooseImageRes.tempFilePaths;
// // alert(tempFilePaths[0])
// // debugger
// this.uploadFile(tempFilePaths[0])
// }
// });
// }
},
uploadFile(file) {
uni.uploadFile({
2025-10-23 16:04:28 +08:00
url: `${this.httpUrl}/adminapi/UploadFile/file_upload`,
2025-08-11 11:06:07 +08:00
filePath: file.path,
name: 'files',
success: (uploadRes) => {
const {code,data} = JSON.parse(uploadRes.data)
if(code) {
this.fileList.push({
tempFile: data,
tempFilePath: data.url,
res: JSON.parse(uploadRes.data)
})
// console.log(this.fileList)
this.$emit('changeImageList',this.fileList)
}
}
})
},
// 上传成功回调
success(e) {
console.log('上传成功', e)
},
// 上传失败回调
fail(e) {
console.log('上传失败', e)
},
// 上传进度回调
progress(e) {
console.log('上传进度', e)
},
clearImage(){
this.fileList = []
}
}
}
</script>
<style>
</style>