增加功能

This commit is contained in:
duxp 2023-09-20 13:47:58 +08:00
parent 2cacf47305
commit b556f340e9
3 changed files with 65 additions and 13 deletions

View File

@ -129,10 +129,9 @@ Page({
callback(false); callback(false);
} }
}, },
//上传数据 //上传文件数据
handleUploadFile(e){ handleUploadFile(e){
const { file } = e.detail; const { file } = e.detail;
console.log(file,'file');
let _fileList = this.data.fileList; let _fileList = this.data.fileList;
_fileList.push({ _fileList.push({
name:file.name, name:file.name,
@ -144,6 +143,47 @@ Page({
}) })
}, },
//上传图片数据
handleUploadImg(){
let _this = this;
wx.chooseMedia({
count:3,
mediaType:['image','video'],
sourceType:['album', 'camera'],
maxDuration:60, //视频拍摄时长3s-60s
success(res){
let _isUpload = false;
res.tempFiles.forEach(item => {
if(item.size > 10485760){
_isUpload = true;
}
});
if(_isUpload){
wx.showToast({
title:'图片或视频不能大于10MB',
icon:'none',
duration:1500
})
return false;
}
let _filesArr = res.tempFiles;
let _fileList = _this.data.fileList;
_filesArr.forEach(item => {
let _lastNum = item.tempFilePath.lastIndexOf('/')+1;
let _name =item.tempFilePath.substr(_lastNum,item.tempFilePath.length);
_fileList.push({
name:_name,
url:item.tempFilePath,
index:_fileList.length
})
})
_this.setData({
fileList:_fileList
})
}
})
},
//预览文件 //预览文件
handlePreView(e){ handlePreView(e){
let _url = e.currentTarget.dataset.url; let _url = e.currentTarget.dataset.url;
@ -247,15 +287,20 @@ Page({
duration:1500 duration:1500
}); });
setTimeout(function () { setTimeout(function () {
_this.setData({ if(_this.data.isRadio){
"searchForm.target":'', wx.navigateBack();
"searchForm.targetId":'', }else{
targetOpt:[], _this.setData({
mainActiveIndex:0, "searchForm.target":'',
activeId:null, "searchForm.targetId":'',
detailData:null, targetOpt:[],
fileList:[] mainActiveIndex:0,
}) activeId:null,
detailData:null,
fileList:[]
})
_this.loadTargetData({type:_this.data.searchForm.type});
}
},1500) },1500)
}else{ }else{
wx.showToast({ wx.showToast({

View File

@ -41,8 +41,15 @@
bind:before-read="handleBeforeUpload" bind:before-read="handleBeforeUpload"
bind:after-read="handleUploadFile" bind:after-read="handleUploadFile"
> >
<van-button icon="plus" size="small" type="info">上传附件</van-button> <van-button icon="orders-o" size="small" type="info">上传附件</van-button>
</van-uploader> </van-uploader>
<van-button
icon="photo-o"
size="small"
type="info"
style="margin-left:10px"
bindtap="handleUploadImg"
>上传图片</van-button>
</view> </view>
</view> </view>
<view class="file_list"> <view class="file_list">

View File

@ -52,5 +52,5 @@
"ignore": [], "ignore": [],
"include": [] "include": []
}, },
"appid": "wx34ec155189941298" "appid": "wxe692498cf5fe6b82"
} }