// components/kefu/kefu.js let height = 0; let width = 0; let per = 0; Component({ /** * 组件的属性列表 */ properties: { top: { type: Number, value: 345 } }, /** * 组件的初始数据 */ data: { x: 0, y: 0, show: false, SDKVersion: 0 }, ready() { /** * 设置初始值 * 将160rpx 140rpx 转成相应的px * 获取SDK版本做兼容 */ wx.getSystemInfo({ success: (res) => { per = 750 / res.windowWidth; height = res.windowHeight * per; width = res.windowWidth * per; this.setData({ x: width - 188, y: height - this.data.top, show: true, per, SDKVersion: res.SDKVersion.split('.').join('') - 0 }) }, }) }, /** * 组件的方法列表 */ methods: { // 根据手指触摸位置实时设置图标位置 touch(e) { const touch = e.touches[0]; let x = touch.clientX * per - 70; let y = touch.clientY * per - 84; this.setData({ x, y }) } } })