把codeFloating的属性放在一个data object中

code
Ge Hao 8 years ago
parent 206f7f3516
commit 2d3f85249b
  1. 44
      pages/show_product/show_product.js
  2. 4
      pages/show_product/show_product.wxml

@ -12,18 +12,20 @@ Page({
accountType: '', accountType: '',
from_share: false, from_share: false,
codeFloatingData: {}, codeFloating: {
codeFloatingStyle: { data: {},
width: 100, style: {
height: 100 width: 100,
}, height: 100
codeFloatingState: 'small', },
codeFloatingPos: { pos: {
left: 650, left: 650,
top: 650 top: 650
}, },
codeFloatingUrl: '', state: 'small',
codeFloatingImgStyle: '' url: '',
imgStyle: ''
}
}, },
onShareAppMessage: function () { onShareAppMessage: function () {
@ -83,7 +85,7 @@ Page({
var reqPath = {path: `pages/show_product/show_product?id=${this.data.product.id}&share=1`} var reqPath = {path: `pages/show_product/show_product?id=${this.data.product.id}&share=1`}
productUtil.getProductPageQrCode(reqPath, function(resp){ productUtil.getProductPageQrCode(reqPath, function(resp){
that.setData({codeFloatingUrl: resp.data.url}) that.setData({'codeFloating.url': resp.data.url})
}) })
}, },
@ -148,7 +150,7 @@ Page({
changeCodeState: function (e) { changeCodeState: function (e) {
var ratio = 750 / this.data.windowWidth var ratio = 750 / this.data.windowWidth
var eleStyle = this.data.codeFloatingStyle var eleStyle = this.data.codeFloating.style
var pos = e.touches[0] var pos = e.touches[0]
var eleLeft = pos.clientX - eleStyle.width / ratio / 2 var eleLeft = pos.clientX - eleStyle.width / ratio / 2
@ -173,8 +175,8 @@ Page({
}) })
animation.left(`${eleLeft}rpx`).top(`${eleTop}rpx`).step() animation.left(`${eleLeft}rpx`).top(`${eleTop}rpx`).step()
this.setData({ this.setData({
codeFloatingData: animation.export(), 'codeFloating.data': animation.export(),
codeFloatingPos: {left: eleLeft, top: eleTop} 'codeFloating.pos': {left: eleLeft, top: eleTop}
}) })
}, },
@ -185,21 +187,21 @@ Page({
}) })
var state, width var state, width
if (this.data.codeFloatingState == "small") { if (this.data.codeFloating.state == "small") {
width = "750rpx" width = "750rpx"
state = 'big' state = 'big'
animation.left(0).top('100rpx').width(width).height(width).step() animation.left(0).top('100rpx').width(width).height(width).step()
} else { } else {
width = "100rpx" width = "100rpx"
let pos = this.data.codeFloatingPos let pos = this.data.codeFloating.pos
state = 'small' state = 'small'
animation.left(`${pos.left}rpx`).top(`${pos.top}rpx`).width(width).height(width).step() animation.left(`${pos.left}rpx`).top(`${pos.top}rpx`).width(width).height(width).step()
} }
this.setData({ this.setData({
codeFloatingData: animation.export(), 'codeFloating.data': animation.export(),
codeFloatingState: state, 'codeFloating.state': state,
codeFloatingImgStyle: `width: ${width}; height: ${width};` 'codeFloating.imgStyle': `width: ${width}; height: ${width};`
}) })
} }
}) })

@ -37,6 +37,6 @@
</view> </view>
</view> </view>
<view id="codeFloating" catchtouchmove="changeCodeState" catchtap="catchScaleCode" animation="{{codeFloatingData}}"> <view id="codeFloating" catchtouchmove="changeCodeState" catchtap="catchScaleCode" animation="{{'codeFloating.data'}}">
<image src="{{codeFloatingUrl || '../../images/1.png'}}" style="{{codeFloatingImgStyle}}"></image> <image src="{{codeFloating.url}}" style="{{codeFloating.imgStyle}}"></image>
</view> </view>
Loading…
Cancel
Save