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('打開文檔成功');
}
});
}
}
});
}