kefu.js 986 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // components/kefu/kefu.js
  2. let height = 0;
  3. let width = 0;
  4. let per = 0;
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. top: {
  11. type: Number,
  12. value: 345
  13. }
  14. },
  15. /**
  16. * 组件的初始数据
  17. */
  18. data: {
  19. x: 0,
  20. y: 0,
  21. show: false,
  22. SDKVersion: 0
  23. },
  24. ready() {
  25. /**
  26. * 设置初始值
  27. * 将160rpx 140rpx 转成相应的px
  28. * 获取SDK版本做兼容
  29. */
  30. wx.getSystemInfo({
  31. success: (res) => {
  32. per = 750 / res.windowWidth;
  33. height = res.windowHeight * per;
  34. width = res.windowWidth * per;
  35. this.setData({
  36. x: width - 188,
  37. y: height - this.data.top,
  38. show: true,
  39. per,
  40. SDKVersion: res.SDKVersion.split('.').join('') - 0
  41. })
  42. },
  43. })
  44. },
  45. /**
  46. * 组件的方法列表
  47. */
  48. methods: {
  49. // 根据手指触摸位置实时设置图标位置
  50. touch(e) {
  51. const touch = e.touches[0];
  52. let x = touch.clientX * per - 70;
  53. let y = touch.clientY * per - 84;
  54. this.setData({
  55. x,
  56. y
  57. })
  58. }
  59. }
  60. })