data(){
return{
imgList:[],
imgArr:"",
pingjiaSrc:this.adminIp + "content/image/pingjia.png",
}
},
methods:{
ChooseImage() {
var _this = this;
uni.chooseImage({
count: 4, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择和拍照
success: (res) => {
var tempFilePaths = res.tempFilePaths;
if (_this.imgList.length+tempFilePaths.length > _this.imgMaxNum) {
uni.showToast({
title: '超过上传图片的最大数量',
icon: 'none'
})
} else {
if (_this.imgList.length != 0) {
_this.imgList = _this.imgList.concat(res.tempFilePaths);
} else {
_this.imgList = res.tempFilePaths;
}
for (var i = 0; i < tempFilePaths.length; i++) {
let timestamp = new Date().getTime();
let enMsg = hex_md5('@' + hex_md5('@' + timestamp + '~') + '~');
uni.uploadFile({
url: this.adminIp + 'Interface/Interface/UploadImg',//上传的服务器地址
filePath: tempFilePaths[i],
method: 'POST',
name: "file",
formData: {
timestamp:timestamp,
enMsg:enMsg
},
success: res => {
let img = JSON.parse(res.data).data
_this.imgArr +=img + ","
console.log("上传图片",_this.imgArr);
}
});
}
}
}
});
},
//查看图片
lookImg: function(val) {
const urls = this.imgList
const current = val
uni.previewImage({
urls,
current
})
},
delect(index){
uni.showModal({
title: "提示",
content: "是否要删除该图片",
success: (res) => {
if (res.confirm) {
this.imgList.splice(index, 1)
}
}
})
},
loadFile(url) {
uni.downloadFile({
url: url,
success: (res) => {
if (res.statusCode === 200) {
uni.openDocument({
filePath: res.tempFilePath,
// 如果文件名包含中文,建议使用escape(res.tempFilePath)转码,防止ios和安卓客户端导致的差异
success: function(res) {
console.log('打开文档成功');
}
});
}
}
});
}