guide.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view v-show="show" class="main" @touchmove.stop>
  3. <view class="rect-shadow"
  4. :style="{'width':width+'px','height':height+'px','left':left+'px',top:top+'px','border-radius': noticeArray[currentIndex].radius?noticeArray[currentIndex].radius+'rpx':'' }">
  5. </view>
  6. <template v-if="noticeArray[currentIndex].type == 'left' ">
  7. <view class="show-message_left" :style="{'top': top +'px', 'right': winWidth-right+width+20+'px' }">
  8. <view style="padding: 12rpx 18rpx;">{{showMessage}}</view>
  9. </view>
  10. </template>
  11. <template v-if="noticeArray[currentIndex].type == 'top' ">
  12. <view :class="left<(winWidth/2)?'show-message_top_left':'show-message_top_right'"
  13. :style="{'top': (top-height-topMsgHeght+30) +'px', 'left': left<(winWidth/2)?left+'px':'' , 'right': left>(winWidth/2)?(winWidth-right)+'px':'' }">
  14. <view style="padding: 12rpx 18rpx;">{{showMessage}}</view>
  15. </view>
  16. </template>
  17. <template v-if="noticeArray[currentIndex].type == 'right' ">
  18. <view class="show-message_right" :style="{'top': top +'px', 'left': (left+width+20) +'px' }">
  19. <view style="padding: 12rpx 18rpx;">{{showMessage}}</view>
  20. </view>
  21. </template>
  22. <template v-if="noticeArray[currentIndex].type == 'bottom' ">
  23. <view :class="left<(winWidth/2)?'show-message_bottom_left':'show-message_bottom_right'"
  24. :style="{'top': (top+height+15) +'px', 'left': left<(winWidth/2)?left+'px':'' , 'right': left>(winWidth/2)?(winWidth-right) +'px':'' }">
  25. <view style="padding: 12rpx 18rpx;">{{showMessage}}</view>
  26. </view>
  27. </template>
  28. <view class="cover-wrap">
  29. <view class="guide-next" @tap="click"
  30. :style="{color: '#000000'}">{{nextText}}</view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. name: "guide",
  37. props: {
  38. show: {
  39. type: Boolean,
  40. default: false
  41. },
  42. left: {
  43. type: [Number, String],
  44. default: ''
  45. },
  46. right: {
  47. type: [Number, String],
  48. default: ''
  49. },
  50. top: {
  51. type: [Number, String],
  52. default: ''
  53. },
  54. width: {
  55. type: [Number, String],
  56. default: ''
  57. },
  58. height: {
  59. type: [Number, String],
  60. default: ''
  61. },
  62. showMessage: {
  63. type: String,
  64. default: ''
  65. },
  66. currentIndex: {
  67. type: Number,
  68. default: 0
  69. },
  70. noticeArray: {
  71. type: Array,
  72. default: []
  73. }
  74. },
  75. data() {
  76. return {
  77. topMsgHeght: 0,
  78. winWidth: 0,
  79. nextText: '下一步' // 知道了,关闭说明
  80. }
  81. },
  82. watch: {
  83. show(n) {},
  84. currentIndex(value) {
  85. if (value != this.noticeArray.length && this.noticeArray[value].type == 'top') {
  86. const className = this.left < (this.winWidth / 2) ? '.show-message_top_left' :
  87. '.show-message_top_right'
  88. const query = uni.createSelectorQuery().in(this);
  89. query.select(className).boundingClientRect(data => {
  90. // 29px 为一行语句的高度
  91. this.topMsgHeght = data.height - 29
  92. }).exec();
  93. }
  94. if (value == this.noticeArray.length - 1) {
  95. this.nextText = '我知道啦'
  96. }
  97. }
  98. },
  99. methods: {
  100. click() {
  101. this.$emit('click');
  102. },
  103. // 清除页面所有定时器
  104. clearTimeAll() {
  105. clearTimeout(this.stt01);
  106. }
  107. },
  108. created() {
  109. this.stt01 = setTimeout(() => {
  110. uni.getSystemInfo({
  111. success: (res) => {
  112. this.winWidth = res.windowWidth;
  113. }
  114. });
  115. }, 60)
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. .main {
  121. position: fixed;
  122. top: 0;
  123. left: 0;
  124. right: 0;
  125. bottom: 0;
  126. z-index: 99999;
  127. }
  128. .rect-shadow {
  129. position: absolute;
  130. border-radius: 12px;
  131. box-shadow: 0 0 0 3000px rgba(0, 0, 0, 0.5);
  132. pointer-events: none;
  133. }
  134. .show-message_left,
  135. .show-message_top_left,
  136. .show-message_top_right,
  137. .show-message_right,
  138. .show-message_bottom_left,
  139. .show-message_bottom_right {
  140. position: absolute;
  141. border-radius: 12rpx;
  142. background-color: rgba(0, 0, 0, .5);
  143. text-align: center;
  144. pointer-events: none;
  145. color: #fff;
  146. font-size: 24rpx;
  147. max-width: 50%;
  148. text-align: left;
  149. }
  150. .show-message_left::after {
  151. content: '';
  152. border-left: 12rpx solid rgba(0, 0, 0, .5);
  153. border-top: 12rpx solid transparent;
  154. border-right: 12rpx solid transparent;
  155. border-bottom: 12rpx solid transparent;
  156. width: 0;
  157. height: 0;
  158. position: absolute;
  159. top: 25%;
  160. right: -22rpx;
  161. }
  162. .show-message_top_left::after,
  163. .show-message_top_right::after {
  164. content: '';
  165. border-left: 12rpx solid transparent;
  166. border-top: 12rpx solid rgba(0, 0, 0, .5);
  167. border-right: 12rpx solid transparent;
  168. border-bottom: 12rpx solid transparent;
  169. width: 0;
  170. height: 0;
  171. position: absolute;
  172. top: 100%;
  173. }
  174. .show-message_top_left::after {
  175. left: 20%;
  176. }
  177. .show-message_top_right::after {
  178. right: 20%;
  179. }
  180. .show-message_right::after {
  181. content: '';
  182. border-left: 12rpx solid transparent;
  183. border-top: 12rpx solid transparent;
  184. border-right: 12rpx solid rgba(0, 0, 0, .5);
  185. border-bottom: 12rpx solid transparent;
  186. width: 0;
  187. height: 0;
  188. position: absolute;
  189. top: 25%;
  190. left: -24rpx;
  191. }
  192. .show-message_bottom_left::after,
  193. .show-message_bottom_right::after {
  194. content: '';
  195. border-left: 12rpx solid transparent;
  196. border-top: 12rpx solid transparent;
  197. border-right: 12rpx solid transparent;
  198. border-bottom: 12rpx solid rgba(0, 0, 0, .5);
  199. width: 0;
  200. height: 0;
  201. position: absolute;
  202. top: -22rpx;
  203. }
  204. .show-message_bottom_left::after {
  205. left: 20%;
  206. }
  207. .show-message_bottom_right::after {
  208. right: 20%;
  209. }
  210. .cover-wrap {
  211. width: 100vw;
  212. height: 100vh;
  213. top: 0;
  214. left: 0;
  215. position: absolute;
  216. .guide-next {
  217. // padding: 0 40rpx;
  218. padding: 16rpx 32rpx;
  219. height: 40rpx;
  220. background-color: #FFFFFF;
  221. text-align: center;
  222. font-size: 28rpx;
  223. border-radius: 38rpx;
  224. position: absolute;
  225. bottom: 60rpx;
  226. left: 50%;
  227. transform: translate(-50%, 0);
  228. }
  229. }
  230. </style>