1、微信端上传图片
uploadImgWx(){
var that = this;
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var localIds = res.localIds;
var realLocalIds = localIds.toString().split(',');
for(var i=0;i< realLocalIds.length;i++){
that.imgLiList2.push(realLocalIds[i]);
wx.getLocalImgData({
localId: realLocalIds[i],
success: function (res) {
var localData = res.localData;
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if(isAndroid){
var resultStr = localData.replace(/[\r\n]/g, "");
that.imgUrlEqp.push(resultStr);
}else{
that.imgUrlEqp.push(localData.split(',')[1])
}
}
})
}
}
})
}
2、PC上传图片
uploadImgPc(e){
var that = this;
var files = e.target.files;
var file = files[0];
if (!/\/(?:jpeg|jpg|png)/i.test(file.type)) {
return;
}
var reader = new FileReader();
reader.onload = function (e) {
var resultBe = e.target.result;
that.imgliList2.push(resultBe);
var result = resultBe.split(",")[1];
that.imgUrlEqp.push(result);
}
reader.readAsDataURL(file);
}
3、上传到服务器
sureUploadImg(){
var that = this;
if(that.imgUrlEqp.length == 0){
loadData("show","请先上传图片!",true);
return false;
}else{
$.ajax({
url: tmsUrl + "/wx/save/orderItemImage?token="+that.logininf.token+"&timeStamp="+that.logininf.timeStamp+"&orderItemId="+that.omOrderItemId,
type: "post",
data: JSON.stringify(that.imgUrlEqp),
contentType: 'application/json',
success: function(data) {
loadData("show","保存成功!",true);
that.imgliList2 = [];
that.imgUrlEqp = [];
that.imgliList = [];
for(var i=0;i<data.result.length;i++){
var item = data.result[i];
that.imgliList.push({
src: ImgWebsite+item.extValue,
extId: item.omExtId
})
}
},
error: function(){
loadData("show","上传图片失败,请稍后再试!",true)
}
})
}
}
4、微信端图片展示
5、PC端图片展示