index.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. Component({
  2. properties: {
  3. statusList: {
  4. type: Array,
  5. value: []
  6. },
  7. dataset: { type: Object },
  8. },
  9. data: {
  10. dashedCounts: []
  11. },
  12. lifetimes: {
  13. ready() {
  14. this.calcAllDashes();
  15. }
  16. },
  17. methods: {
  18. onBodyModel(event:any) {
  19. // console.log(event,"bind:tap=onBodyModel")
  20. const position = event.mark?.position
  21. if (position) this.triggerEvent('position', { position });
  22. },
  23. calcAllDashes() {
  24. const query = wx.createSelectorQuery().in(this);
  25. const dashedCounts: any[] = [];
  26. const itemCount = this.data.statusList.length;
  27. const systemInfo = wx.getSystemInfoSync();
  28. const rpx2px = systemInfo.windowWidth / 750;
  29. for (let i = 0; i < itemCount; i++) {
  30. query.select(`#item-${i}`).boundingClientRect();
  31. }
  32. query.exec(rects => {
  33. if (rects) {
  34. // if(rects.length > 0 && rects[0] && rects[0].height){
  35. // rects[0].height = rects[0].height + 30;
  36. // }
  37. // console.log("rects", rects);
  38. rects.forEach((rect:any, i:number) => {
  39. // rect[0].height = rect[0].height + 30;
  40. // console.log("rect1111", rect);
  41. if (rect) {
  42. // 换算成 rpx
  43. const heightRpx = rect.height / rpx2px;
  44. // 14rpx为圆圈高度
  45. const lineHeight = heightRpx - 14;
  46. const dashHeight = 10;
  47. const gap = 4;
  48. let count = Math.floor(lineHeight / (dashHeight + gap));
  49. // console.log("count", count);
  50. if (count < 1) count = 1;
  51. dashedCounts[i] = Array.from({length: count}, (_, j) => j);
  52. }
  53. else {
  54. dashedCounts[i] = Array.from({length: 10}, (_, j) => j);
  55. }
  56. });
  57. this.setData({ dashedCounts });
  58. }
  59. });
  60. }
  61. },
  62. observers: {
  63. 'statusList': function() {
  64. this.calcAllDashes();
  65. }
  66. }
  67. })