helper.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <u-overlay :show="step > 0" @click="showHelp" opacity="0.7">
  3. <view class="width-100 height-100">
  4. <view class="opacity-06 c-g-white p-a border-round-20" :style="[helpRectStyle]"></view>
  5. <view class="p-a f-40 col-white t-bold width-100 padding-box" :style="[helpTextStyle]">{{helpText}}</view>
  6. </view>
  7. </u-overlay>
  8. </template>
  9. <script>
  10. export default {
  11. data() {
  12. return {
  13. step: 0,//第几步,0则还未开始
  14. helpRectStyle: {},
  15. helpText: '',
  16. helpTextStyle: {},
  17. options: [],
  18. }
  19. },
  20. methods: {
  21. showHelp() {//显示帮助信息
  22. this.step++//先往前走一步
  23. if (this.step > this.options.length) {//到底了,就关闭
  24. this.close()
  25. } else {//还有,则继续显示
  26. let option = this.options[this.step - 1]//取到配置
  27. this.showHelpRect(option)//显示高亮框
  28. this.showHelpText(option.text)//显示帮助文字
  29. }
  30. },
  31. showHelpRect(option) {//显示高亮框
  32. uni.createSelectorQuery().in(option.ref).select(option.selector).boundingClientRect(res => {
  33. this.helpRectStyle = {
  34. width: (res.width + 20) + 'px',
  35. height: (res.height + 20) + 'px',
  36. top: (res.top - 10) + 'px',
  37. left: (res.left - 10) + 'px',
  38. }
  39. let top = option.text.length / 16 * 35//每16个字占一行,一行35个像素
  40. top = top < 70 ? 70 : top //至少70个像素
  41. this.helpTextStyle = {
  42. top: (res.top - top) + 'px',
  43. }
  44. }).exec()
  45. },
  46. showHelpText(text) {//显示文字部分
  47. this.helpText = text
  48. },
  49. // ------- 对外的接口 --------
  50. open(options) {
  51. this.options = options
  52. this.showHelp()
  53. },
  54. close() {
  55. this.step = 0
  56. },
  57. },
  58. }
  59. </script>
  60. <style>
  61. </style>