@@ -17,6 +17,14 @@ import HtmlToJson from './html2json.js';
17
17
/**
18
18
* 配置及公有属性
19
19
**/
20
+ var realWindowWidth = 0 ;
21
+ var realWindowHeight = 0 ;
22
+ wx . getSystemInfo ( {
23
+ success : function ( res ) {
24
+ realWindowWidth = res . windowWidth
25
+ realWindowHeight = res . windowHeight
26
+ }
27
+ } )
20
28
/**
21
29
* 主函数入口区
22
30
**/
@@ -76,12 +84,21 @@ function calMoreImageInfo(e, idx, that, bindName) {
76
84
var temImages = temData . images ;
77
85
//因为无法获取view宽度 需要自定义padding进行计算,稍后处理
78
86
var recal = wxAutoImageCal ( e . detail . width , e . detail . height , that , bindName ) ;
79
- temImages [ idx ] . width = recal . imageWidth ;
80
- temImages [ idx ] . height = recal . imageheight ;
81
- temData . images = temImages ;
82
- var bindData = { } ;
83
- bindData [ bindName ] = temData ;
84
- that . setData ( bindData ) ;
87
+ // temImages[idx].width = recal.imageWidth;
88
+ // temImages[idx].height = recal.imageheight;
89
+ // temData.images = temImages;
90
+ // var bindData = {};
91
+ // bindData[bindName] = temData;
92
+ // that.setData(bindData);
93
+ var index = temImages [ idx ] . index
94
+ var key = `${ bindName } `
95
+ for ( var i of index . split ( '.' ) ) key += `.nodes[${ i } ]`
96
+ var keyW = key + '.width'
97
+ var keyH = key + '.height'
98
+ that . setData ( {
99
+ [ keyW ] : recal . imageWidth ,
100
+ [ keyH ] : recal . imageheight ,
101
+ } )
85
102
}
86
103
87
104
// 计算视觉优先的图片宽高
@@ -90,26 +107,22 @@ function wxAutoImageCal(originalWidth, originalHeight,that,bindName) {
90
107
var windowWidth = 0 , windowHeight = 0 ;
91
108
var autoWidth = 0 , autoHeight = 0 ;
92
109
var results = { } ;
93
- wx . getSystemInfo ( {
94
- success : function ( res ) {
95
- var padding = that . data [ bindName ] . view . imagePadding ;
96
- windowWidth = res . windowWidth - 2 * padding ;
97
- windowHeight = res . windowHeight ;
98
- //判断按照那种方式进行缩放
99
- console . log ( "windowWidth" + windowWidth ) ;
100
- if ( originalWidth > windowWidth ) { //在图片width大于手机屏幕width时候
101
- autoWidth = windowWidth ;
102
- console . log ( "autoWidth" + autoWidth ) ;
103
- autoHeight = ( autoWidth * originalHeight ) / originalWidth ;
104
- console . log ( "autoHeight" + autoHeight ) ;
105
- results . imageWidth = autoWidth ;
106
- results . imageheight = autoHeight ;
107
- } else { //否则展示原来的数据
108
- results . imageWidth = originalWidth ;
109
- results . imageheight = originalHeight ;
110
- }
111
- }
112
- } )
110
+ var padding = that . data [ bindName ] . view . imagePadding ;
111
+ windowWidth = realWindowWidth - 2 * padding ;
112
+ windowHeight = realWindowHeight ;
113
+ //判断按照那种方式进行缩放
114
+ // console.log("windowWidth" + windowWidth);
115
+ if ( originalWidth > windowWidth ) { //在图片width大于手机屏幕width时候
116
+ autoWidth = windowWidth ;
117
+ // console.log("autoWidth" + autoWidth);
118
+ autoHeight = ( autoWidth * originalHeight ) / originalWidth ;
119
+ // console.log("autoHeight" + autoHeight);
120
+ results . imageWidth = autoWidth ;
121
+ results . imageheight = autoHeight ;
122
+ } else { //否则展示原来的数据
123
+ results . imageWidth = originalWidth ;
124
+ results . imageheight = originalHeight ;
125
+ }
113
126
return results ;
114
127
}
115
128
0 commit comments