@@ -40,6 +40,10 @@ Component({
40
40
multipleMode : {
41
41
type : String ,
42
42
value : 'aspectFill' ,
43
+ } ,
44
+ key : {
45
+ type : String ,
46
+ value : 'url'
43
47
}
44
48
} ,
45
49
@@ -48,28 +52,32 @@ Component({
48
52
*/
49
53
data : {
50
54
// 传值方式是新方式还是旧方式
51
- newOrOld : null ,
55
+ newType : true ,
52
56
// 单图短边大小
53
57
shortSideValue : 0 ,
58
+ // 图片排列几行
59
+ row : 0 ,
60
+ // 图片排列几列
61
+ colum : 0 ,
54
62
} ,
55
63
56
64
/**
57
65
* 组件的生命周期
58
66
*/
59
67
lifetimes : {
60
- attached : function ( ) {
68
+ attached ( ) {
61
69
// 在组件实例进入页面节点树时执行
62
70
63
71
//判断传入urls长度
64
72
if ( this . data . urls . length > 9 ) {
65
- const urls = this . data . urls . slice ( 0 , 9 ) ;
73
+ const urls = this . data . urls . slice ( 0 , 9 )
66
74
this . setData ( {
67
75
urls
68
- } ) ;
76
+ } )
69
77
console . warn ( '超过9张图片!' ) ;
70
78
}
71
79
72
- this . preview ( ) ;
80
+ this . preview ( )
73
81
74
82
} ,
75
83
} ,
@@ -79,29 +87,27 @@ Component({
79
87
*/
80
88
methods : {
81
89
// 判断传入的urls是字符串列表(old模式)还是对象列表(new模式)
82
- judgeNewOrOld : function ( ) {
90
+ judgeType ( ) {
83
91
const urls = this . data . urls ;
84
92
if ( urls . length != 0 ) {
85
- if ( typeof ( urls [ 0 ] ) != 'object' ) {
86
- return 'old' ;
93
+ if ( typeof ( urls [ 0 ] ) !== 'object' ) {
94
+ return false ;
87
95
}
88
- return 'new' ;
89
96
}
90
- return 'new' ;
97
+ return true ;
91
98
} ,
92
99
93
100
//判断照片是横屏还是竖屏并计算短边的长度
94
101
//如不指定短边的长度,短边会默认显示image组件的长度
95
102
horizontalOrVertical : function ( src ) {
96
- let that = this ;
97
103
wx . getImageInfo ( {
98
104
src : src ,
99
- success ( res ) {
105
+ success : ( res ) => {
100
106
const longSide = res . width >= res . height ? res . width : res . height ;
101
107
const shortSide = res . width >= res . height ? res . height : res . width ;
102
- that . setData ( {
103
- horizontal_screen : res . width >= res . height ? true : false ,
104
- shortSideValue : shortSide * that . data . singleSize / longSide
108
+ this . setData ( {
109
+ horizontalScreen : res . width >= res . height ? true : false ,
110
+ shortSideValue : shortSide * this . data . singleSize / longSide
105
111
} ) ;
106
112
}
107
113
} ) ;
@@ -110,16 +116,16 @@ Component({
110
116
// 显示图片
111
117
preview : function ( ) {
112
118
// 判断传入模式
113
- const newOrOld = this . judgeNewOrOld ( ) ;
119
+ const newType = this . judgeType ( ) ;
114
120
this . setData ( {
115
- newOrOld
121
+ newType
116
122
} ) ;
117
-
118
123
//显示图片
119
124
const urls = this . data . urls ;
125
+ const key = this . data . key
120
126
121
127
if ( urls . length == 1 ) {
122
- this . horizontalOrVertical ( newOrOld == 'new' ? urls [ 0 ] . url : urls [ 0 ] ) ;
128
+ this . horizontalOrVertical ( newType ? urls [ 0 ] [ key ] : urls [ 0 ] ) ;
123
129
}
124
130
} ,
125
131
@@ -128,17 +134,17 @@ Component({
128
134
const urls = this . data . urls ;
129
135
let tempFilePath = '' ;
130
136
let previewImageList = [ ] ;
131
- const newOrOld = this . data . newOrOld ;
137
+ const newType = this . data . newType ;
138
+ const key = this . data . key
132
139
133
- if ( newOrOld == 'old' ) {
134
- tempFilePath = urls [ index ] ;
135
- previewImageList = urls ;
136
-
137
- } else {
138
- tempFilePath = urls [ index ] . url ;
140
+ if ( newType ) {
141
+ tempFilePath = urls [ index ] [ key ] ;
139
142
for ( let i = 0 ; i < urls . length ; i ++ ) {
140
- previewImageList . push ( urls [ i ] . url ) ;
143
+ previewImageList . push ( urls [ i ] [ key ] ) ;
141
144
}
145
+ } else {
146
+ tempFilePath = urls [ index ] ;
147
+ previewImageList = urls ;
142
148
}
143
149
144
150
let detail = {
0 commit comments