|
楼主 |
发表于 2016-7-8 16:31:48
|
显示全部楼层
我用的是attachmentSimple组,我们原本想实现的是这样一个功能,在Bx5中保存图片,在wex5中读取图片。解决思路是在图片字段更改后,将图片转换为Base84保存下来,在wex5中用一个图片标签的src直接关联该Base84字段,就可以实现图片的浏览。具体代码:1.值改变事件
Model.prototype.mainDataValueChanged = function(event) {
//debugger;
if (event.col == 'fGoodImg1'&&event.value !='[]') {
var data = this.comp('mainData');
var row = data.getCurrentRow();
var jsonList = eval("(" + row.val('fGoodImg1') + ")");
var ownerID = row.getID();
var realFileName = jsonList[0]["realFileName"];
var storeFileName = jsonList[0]["storeFileName"];
var operateType = "preview";
//debugger;
var imageUrl = this.comp("attachmentSimple1").getFileUrl(realFileName, storeFileName, ownerID, operateType);
data.setValue('fGoodImg', imageUrl, row);
data.setValue('fGoodImgUrl', imageUrl, row);
console.log('imageUrl', imageUrl);
this.convertImgToBase64(imageUrl, function(base64Img) {
// alert(base64Img);
// $("#image5").attr('src',base64Img);
data.setValue('fGoodImgBS64', base64Img, row);
});
}
if(event.col == 'fGoodImg1'&&event.value =='[]'){
var data = this.comp('mainData');
var row = data.getCurrentRow();
data.setValue('fGoodImg', '', row);
data.setValue('fGoodImgUrl', '', row);
data.setValue('fGoodImgBS64', '', row);
}
};
2.将图片转换为Base64
Model.prototype.convertImgToBase64 = function(url, callback, outputFormat) {
var canvas = document.createElement('CANVAS');
var ctx = canvas.getContext('2d');
var img = new Image;
img.crossOrigin = 'Anonymous';
img.onload = function() {
canvas.height = img.height;
canvas.width = img.width;
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL(outputFormat || 'image/png');
callback.call(this, dataURL);
// Clean up
canvas = null;
};
img.src = url;
};
已结解决了,可以结贴了。
|
|