mpDevBubble.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view
  3. v-if="isMp && options && options.status && options.bubble.status"
  4. class="mpDevBubble"
  5. :style="{
  6. left: `${tagConfig.x}px`,
  7. top: `${tagConfig.y}px`,
  8. 'background-color': options.bubble.bgColor,
  9. 'box-shadow': `0px 0px 6px ${options.bubble.bgColor}`,
  10. }"
  11. @touchstart.stop="touchstart"
  12. @touchmove.stop="touchmove"
  13. @touchend.stop="touchend"
  14. >
  15. <text
  16. class="mpDevBubbleText"
  17. :style="{
  18. color: options.bubble.color,
  19. 'font-size': '20rpx',
  20. }"
  21. >
  22. {{ options.bubble.text }}
  23. </text>
  24. </view>
  25. </template>
  26. <script>
  27. import devOptions from "../libs/devOptions";
  28. let options = devOptions.getOptions();
  29. let sysInfo = uni.getSystemInfoSync();
  30. let tagConfig = uni.getStorageSync("devTools_tagConfig");
  31. if (!tagConfig) {
  32. tagConfig = {};
  33. }
  34. tagConfig = Object.assign(
  35. {
  36. x: sysInfo.screenWidth - 150,
  37. y: sysInfo.screenHeight - 240,
  38. },
  39. tagConfig
  40. );
  41. // 拖动范围限制
  42. let dragLimit = {
  43. min: { x: 0, y: 0 },
  44. max: {
  45. x: sysInfo.screenWidth - 70,
  46. y: sysInfo.screenHeight - 24,
  47. },
  48. };
  49. tagConfig.x = Math.min(Math.max(tagConfig.x, dragLimit.min.x), dragLimit.max.x);
  50. tagConfig.y = Math.min(Math.max(tagConfig.y, dragLimit.min.y), dragLimit.max.y);
  51. let isTouch = false;
  52. let touchStartPoint = {
  53. clientX: 0,
  54. clientY: 0,
  55. tagX: tagConfig.x,
  56. tagY: tagConfig.y,
  57. hasMove: false,
  58. };
  59. let isMp = false;
  60. // #ifdef MP
  61. isMp = true;
  62. // #endif
  63. export default {
  64. data() {
  65. return {
  66. isMp,
  67. /**
  68. * 标签参数
  69. */
  70. options,
  71. /**
  72. * 标签坐标信息配置
  73. */
  74. tagConfig,
  75. };
  76. },
  77. mounted() {
  78. // console.log("调试开始zzzzzzzzzzzzzzzz");
  79. },
  80. methods: {
  81. touchstart(e) {
  82. if (isTouch) return;
  83. if (e.preventDefault) {
  84. e.preventDefault();
  85. }
  86. let clientX = e.touches[0].clientX;
  87. let clientY = e.touches[0].clientY;
  88. touchStartPoint.clientX = clientX;
  89. touchStartPoint.clientY = clientY;
  90. touchStartPoint.tagX = tagConfig.x;
  91. touchStartPoint.tagY = tagConfig.y;
  92. touchStartPoint.hasMove = false;
  93. isTouch = true;
  94. },
  95. touchmove(e) {
  96. if (!isTouch) return;
  97. if (e.preventDefault) {
  98. e.preventDefault();
  99. }
  100. let clientX = e.touches[0].clientX;
  101. let clientY = e.touches[0].clientY;
  102. touchStartPoint.hasMove = true;
  103. let offsetX = touchStartPoint.clientX - clientX;
  104. let offsetY = touchStartPoint.clientY - clientY;
  105. let tx = touchStartPoint.tagX - offsetX;
  106. let ty = touchStartPoint.tagY - offsetY;
  107. tx = Math.min(Math.max(tx, dragLimit.min.x), dragLimit.max.x);
  108. ty = Math.min(Math.max(ty, dragLimit.min.y), dragLimit.max.y);
  109. tagConfig.x = tx;
  110. tagConfig.y = ty;
  111. this.tagConfig.x = tx;
  112. this.tagConfig.y = ty;
  113. },
  114. touchend(e) {
  115. if (!isTouch) return;
  116. if (e.preventDefault) {
  117. e.preventDefault();
  118. }
  119. isTouch = false;
  120. uni.setStorageSync("devTools_tagConfig", tagConfig);
  121. if (!touchStartPoint.hasMove) {
  122. let pages = getCurrentPages();
  123. let route = options.route.substring(1, options.route.length - 2);
  124. if (pages[pages.length - 1].route == route) {
  125. // 已经处于debug页面,不响应点击事件
  126. return;
  127. }
  128. this.$devTools.show();
  129. }
  130. },
  131. },
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. .mpDevBubble {
  136. box-sizing: border-box;
  137. position: fixed;
  138. z-index: 9999999;
  139. width: 70px;
  140. height: 24px;
  141. display: flex;
  142. flex-direction: column;
  143. align-items: center;
  144. justify-content: center;
  145. padding: 4px;
  146. border-radius: 6px;
  147. font-size: 10px;
  148. }
  149. </style>