|
楼主 |
发表于 2017-5-2 14:40:47
|
显示全部楼层
搞了好几回都没有搞定,于是专门针对微信用:justep.Browser.isWeChat判断修改。1、attachmentsimple在微信里点击预览的功能禁用,找到“\model\UI2\system\components\justep\attachment\attachmentSimple.js”修改previewOrRemoveItem 如下:- previewOrRemoveItem : function($object){
- var realFileName = $object.realFileName.get();
- var storeFileName = $object.storeFileName.get();
- var ownerID = this.getOwnerID($object);
- if(this.$state.get() == 'upload'){
- if(!justep.Browser.isWeChat){
- this.downloadFile(realFileName,storeFileName,ownerID);
- }
- }else if(this.$state.get() == 'remove'){
- this.deleteFile(storeFileName,ownerID);
- }
- },
复制代码 2、然后把缩略图的?图标修改成已经上传的图片预览,还是这个文件,找到:getPictureUrl修改后运行dist:
- getPictureUrl : function($object){
- var realFileName = encodeURIComponent($object.realFileName.get());
- var storeFileName = $object.storeFileName.get();
- var ownerID = this.getOwnerID($object);
- var operateType = "browse";
- var imgFileType = ".jpg,.jpeg,.jpe,.png,.gif,.tiff,.tif,.svg,.svgz,.svg";
- var url = "";
- if(imgFileType.indexOf((String(/\.[^\.]+$/.exec(realFileName)).toLowerCase())) >= 0){
- url = this.getFileUrl(realFileName,storeFileName,ownerID,operateType);
复制代码
3、由于上次图片真实name不对,带有%之类的符号(http://xxx.com/baas/mfxxl/attach ... 05-02&realFileName=image%253A263173&operateType=browse&from=singlemessage)。于是自己显示缩略图,新建一个image,增加“id=image3”并使用canvas绘制大的缩略图并显示:
- if(justep.Browser.isWeChat){
- var Img = new Image();
- var canvas = document.createElement('canvas');
- var ctx = canvas.getContext('2d');
- var maxWidth = 800;
- var maxHeight = 800;
- var quality = 0.85;
- Img.onload = function() {
- if (Img.width>maxWidth || Img.height>maxHeight) {
- var bili = Math.max(Img.width/maxWidth, Img.height/maxHeight);
- canvas.width = Img.width/bili;
- canvas.height = Img.height/bili;
- }else{
- canvas.width = Img.width;
- canvas.height = Img.height;
- }
- ctx.drawImage(Img, 0, 0, Img.width, Img.height, 0, 0, canvas.width, canvas.height);
- canvas.toDataURL('image/jpeg', quality);
- var dataUrl = canvas.toDataURL('image/jpeg', quality);
- console.log(dataUrl);
- var img3 = document.getElementById('image3');
- img3.src = dataUrl;
- uploader.submit();
- };
- Img.src = _URL.createObjectURL(file);
- }
复制代码
目前只有这样,等新版本发布后再改回来啦!
谢谢梁老师的指导,可以结贴!
|
|