addTips.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // +----------------------------------------------------------------------
  21. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  22. // +----------------------------------------------------------------------
  23. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  24. // +----------------------------------------------------------------------
  25. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  26. // +----------------------------------------------------------------------
  27. // | Author: CRMEB Team <admin@crmeb.com>
  28. // +----------------------------------------------------------------------
  29. export default {
  30. data() {
  31. return {
  32. showTip: false,
  33. boxTop: 0,
  34. arrowMargin: 0,
  35. cotainerMargin: 0,
  36. screenWidth: 0,
  37. };
  38. },
  39. props: {
  40. /* 是否是自定义头部 */
  41. isCustom: {
  42. type: Boolean,
  43. default: false,
  44. },
  45. /* 背景颜色 */
  46. bgColor: {
  47. type: String,
  48. default: "#ffffff",
  49. },
  50. /* 提示文字 */
  51. text: {
  52. type: String,
  53. default: "添加到我的小程序",
  54. },
  55. /* 提示文字样式 */
  56. fontObj: {
  57. type: Object,
  58. default: function() {
  59. return {
  60. color: "#202020",
  61. fontSize: "12px",
  62. fontWeight: "0",
  63. };
  64. },
  65. },
  66. /* 圆角大小 px*/
  67. borderR: {
  68. type: Number,
  69. default: 5,
  70. },
  71. /* 延时出现 */
  72. delay: {
  73. type: Number,
  74. default: 2000,
  75. },
  76. /* 关闭btn黑白两色 或者自行添加 */
  77. closeColor: {
  78. type: Boolean,
  79. default: true,
  80. },
  81. /* 动画效果 */
  82. isAm: {
  83. type: Boolean,
  84. default: true,
  85. },
  86. },
  87. methods: {
  88. tipHidden: function() {
  89. uni.setStorageSync("my_tips_2020", "true");
  90. this.showTip = false;
  91. },
  92. timeOut() {
  93. this.tipHidden();
  94. this.showTip = true;
  95. },
  96. init() {
  97. if (uni.getStorageSync("my_tips_2020")) return;
  98. let rect = uni.getMenuButtonBoundingClientRect();
  99. let screenWidth = uni.getSystemInfoSync().screenWidth;
  100. this.boxTop = rect.bottom;
  101. this.arrowMargin = rect.width * 0.75 + 4;
  102. this.cotainerMargin = screenWidth - rect.right;
  103. this.timeOut();
  104. },
  105. },
  106. onReady() {
  107. this.init();
  108. },
  109. };
  110. </script>
  111. <style lang="scss" scoped>
  112. @keyframes anScale {
  113. from {
  114. -webkit-transform: scale3d(0.96, 0.96, 0.96);
  115. transform: scale3d(0.96, 0.96, 0.96);
  116. }
  117. 50% {
  118. -webkit-transform: scale3d(1, 1, 1);
  119. transform: scale3d(1, 1, 1);
  120. }
  121. to {
  122. -webkit-transform: scale3d(0.96, 0.96, 0.96);
  123. transform: scale3d(0.96, 0.96, 0.96);
  124. }
  125. }
  126. .anScale {
  127. animation: anScale 1s linear infinite;
  128. }
  129. .tip_box {
  130. width: 70%;
  131. position: fixed;
  132. top: 0;
  133. right: 0;
  134. z-index: 100;
  135. display: flex;
  136. justify-content: flex-end;
  137. align-items: flex-end;
  138. flex-direction: column;
  139. .arrow {
  140. width: 0;
  141. height: 0;
  142. border: 10rpx solid;
  143. border-color: transparent;
  144. }
  145. .container {
  146. display: flex;
  147. align-items: center;
  148. justify-content: center;
  149. padding: 16rpx 24rpx;
  150. .tips {
  151. flex: 1;
  152. padding-right: 12rpx;
  153. }
  154. .close {
  155. height: 30rpx;
  156. width: 30rpx;
  157. font-size: 20rpx;
  158. line-height: 30rpx;
  159. color: #999;
  160. .closeImg {
  161. height: 100%;
  162. width: 100%;
  163. }
  164. }
  165. }
  166. }
  167. </style>