You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.4 KiB
86 lines
2.4 KiB
const math = require('../../utils/math') //导入模块
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
properties: {
|
|
imageList:{
|
|
type: Array,
|
|
value: []
|
|
},
|
|
clickable:{
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
square:{
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
listed:{
|
|
type: Boolean,
|
|
value: false
|
|
}
|
|
},
|
|
data: {
|
|
column: 3,
|
|
height: 115,
|
|
width: 115,
|
|
windowWidth: 345,
|
|
heightList: []
|
|
},
|
|
observers: {
|
|
'imageList': function () {
|
|
if(this.data.imageList.length == 4){
|
|
this.setData({column: 2})
|
|
} else if(this.data.imageList.length >= 5){
|
|
this.setData({column: 3})
|
|
} else if(this.data.imageList.length >= 2){
|
|
this.setData({column: 3})
|
|
} else if(this.data.imageList.length >= 1){
|
|
this.setData({column: 1})
|
|
} else {
|
|
this.setData({column: 0})
|
|
}
|
|
}
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
let grap = app.globalData.windowWidth * (60 / 750)
|
|
this.setData({ windowWidth : app.globalData.windowWidth - grap })
|
|
}
|
|
},
|
|
methods: {
|
|
onImageLoad: function(e){
|
|
if(this.data.listed){
|
|
var index = e.currentTarget.dataset.index
|
|
var radio = math.divide(e.detail.height, e.detail.width)
|
|
var height = parseInt(math.times(this.data.windowWidth, radio))
|
|
this.setData({ ['heightList[' + index + ']']: height })
|
|
} else {
|
|
var radio = math.divide(e.detail.height, e.detail.width)
|
|
if(radio == 1){
|
|
this.setData({ width: 128, height: 128 })
|
|
} else if(radio < 0.3){// 太宽了,
|
|
this.setData({ width: 200, height: parseInt(math.times(200, radio)) })
|
|
} else if(radio < 1 && radio >= 0.3) {// 宽了,
|
|
this.setData({ width: 150, height: parseInt(math.times(150, radio)) })
|
|
} else if( radio > 1 && radio <= 3) {// 高了,
|
|
this.setData({ width: parseInt(math.divide(150, radio)), height: 150 })
|
|
} else if(radio > 3){
|
|
this.setData({ width: parseInt(math.divide(180, radio)), height: 180 })
|
|
}
|
|
}
|
|
},
|
|
viewImage: function(e){
|
|
if(!this.data.clickable){
|
|
return
|
|
}
|
|
var index = e.currentTarget.dataset.index
|
|
wx.previewImage({ urls: this.data.imageList, current: this.data.imageList[index] })
|
|
}
|
|
}
|
|
})
|