You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
3.5 KiB

3 months ago
  1. <template>
  2. <!-- 小程序顶部提示 -->
  3. <view>
  4. <view class="tip_box" :class="{ anScale: isAm }" v-if="showTip"
  5. :style="{ top: isCustom ? boxTop + 'px' : '0px' }">
  6. <view class="arrow" :style="{ 'margin-right': arrowMargin + 'px', borderBottomColor: bgColor }"></view>
  7. <view class="container" :style="{'margin-right': cotainerMargin + 'px',backgroundColor: bgColor,borderRadius: borderR + 'px',}">
  8. <!-- 提示文字 -->
  9. <view class="tips" :style="{ color: fontObj.color, fontSize: fontObj.fontSize, fontWeight: fontObj.fontWeight }">
  10. {{ text }}</view>
  11. <view class="close" @tap="tipHidden">
  12. <text class="iconfont icon-cha3" v-if="closeColor"></text>
  13. <text class="iconfont icon-cha3" style="color:#fff;" v-else></text>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. showTip: false,
  24. boxTop: 0,
  25. arrowMargin: 0,
  26. cotainerMargin: 0,
  27. screenWidth: 0,
  28. };
  29. },
  30. props: {
  31. /* 是否是自定义头部 */
  32. isCustom: {
  33. type: Boolean,
  34. default: false,
  35. },
  36. /* 背景颜色 */
  37. bgColor: {
  38. type: String,
  39. default: "#ffffff",
  40. },
  41. /* 提示文字 */
  42. text: {
  43. type: String,
  44. default: "添加到我的小程序",
  45. },
  46. /* 提示文字样式 */
  47. fontObj: {
  48. type: Object,
  49. default: function() {
  50. return {
  51. color: "#202020",
  52. fontSize: "12px",
  53. fontWeight: "0",
  54. };
  55. },
  56. },
  57. /* 圆角大小 px*/
  58. borderR: {
  59. type: Number,
  60. default: 5,
  61. },
  62. /* 延时出现 */
  63. delay: {
  64. type: Number,
  65. default: 2000,
  66. },
  67. /* 关闭btn黑白两色 或者自行添加 */
  68. closeColor: {
  69. type: Boolean,
  70. default: true,
  71. },
  72. /* 动画效果 */
  73. isAm: {
  74. type: Boolean,
  75. default: true,
  76. },
  77. },
  78. methods: {
  79. tipHidden: function() {
  80. uni.setStorageSync("my_tips_2020", "true");
  81. this.showTip = false;
  82. },
  83. timeOut() {
  84. this.tipHidden();
  85. this.showTip = true;
  86. // setTimeout(() => {
  87. // setTimeout(() => {
  88. // this.tipHidden();
  89. // }, this.delay + 2000);
  90. // }, this.delay);
  91. },
  92. init() {
  93. if (uni.getStorageSync("my_tips_2020")) return;
  94. let rect = uni.getMenuButtonBoundingClientRect();
  95. let screenWidth = uni.getSystemInfoSync().screenWidth;
  96. this.boxTop = rect.bottom;
  97. this.arrowMargin = rect.width * 0.75 + 4;
  98. this.cotainerMargin = screenWidth - rect.right;
  99. this.timeOut();
  100. },
  101. },
  102. onReady() {
  103. this.init();
  104. },
  105. };
  106. </script>
  107. <style lang="scss" scoped>
  108. @keyframes anScale {
  109. from {
  110. -webkit-transform: scale3d(0.96, 0.96, 0.96);
  111. transform: scale3d(0.96, 0.96, 0.96);
  112. }
  113. 50% {
  114. -webkit-transform: scale3d(1, 1, 1);
  115. transform: scale3d(1, 1, 1);
  116. }
  117. to {
  118. -webkit-transform: scale3d(0.96, 0.96, 0.96);
  119. transform: scale3d(0.96, 0.96, 0.96);
  120. }
  121. }
  122. .anScale {
  123. animation: anScale 1s linear infinite;
  124. }
  125. .tip_box {
  126. width: 70%;
  127. position: fixed;
  128. top: 0;
  129. right: 0;
  130. z-index: 100;
  131. display: flex;
  132. justify-content: flex-end;
  133. align-items: flex-end;
  134. flex-direction: column;
  135. .arrow {
  136. width: 0;
  137. height: 0;
  138. border: 10rpx solid;
  139. border-color: transparent;
  140. }
  141. .container {
  142. display: flex;
  143. align-items: center;
  144. justify-content: center;
  145. padding: 16rpx 24rpx;
  146. .tips {
  147. flex: 1;
  148. padding-right: 12rpx;
  149. }
  150. .close {
  151. height: 30rpx;
  152. width: 30rpx;
  153. font-size: 20rpx;
  154. line-height: 30rpx;
  155. color: #999;
  156. .closeImg {
  157. height: 100%;
  158. width: 100%;
  159. }
  160. }
  161. }
  162. }
  163. </style>