用的是官方组件
<view class="c-add-li">
<text class="c-title">上传附件</text>
<uni-file-picker
v-model="infos.pathList"
file-mediatype="all"
@select="select"
@progress="progress"
@success="success"
@fail="fail"
:auto-upload='false'
>
<button>选择文件</button>
</uni-file-picker>
</view>
// 上传
select(e){
let that = this
uni.showLoading({
title: "图片上传中"
});
const tempFilePaths = e.tempFilePaths;
for (var i in tempFilePaths) {//多文件
uni.uploadFile({
url: app.globalData.baseURL + 'api/mobile/attachment/upload', //上传接口
header: {
'X-Auth-Token': app.globalData.token
},
filePath: tempFilePaths[i],
name: 'surface',
success: (uploadFileRes) => {
uni.hideLoading();
const back = JSON.parse(uploadFileRes.data);
if (uploadFileRes.statusCode == 200) {
that.infos.pathList.push(back.data);
} else {
uni.showToast(back.msg)
}
},
fail: () => {
uni.hideLoading();
uni.showToast("图片上传失败,请联系开发!")
},
complete: function() {
uni.hideLoading();
}
});
}
},
// 获取上传进度
progress(e){
console.log('上传进度:',e)
},
// 上传成功
success(e){
console.log('上传成功')
},
// 上传失败
fail(e){
console.log('上传失败:',e)
},
一个简易的复制到剪切板下载
download(item){
let that = this;
uni.setClipboardData({
data: app.globalData.baseURL + item.webPath,
success: function() {
uni.showModal({
content: '下载链接已保存到粘贴板,请打开浏览器后粘贴到地址栏下载文件',
showCancel: false,
fail() {
uni.showToast({
title: '复制失败',
duration: 2000,
icon: 'none'
});
}
})
}
});
},