struggler-uniapp-add-tip.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view>
  3. <view class="uni-add-tips-box" v-if="showTip">
  4. <view class='uni-add-tips-content' @tap='hideTip'>
  5. <text>{{tip}}</text>
  6. </view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. const SHOW_TIP = "SHOW_TIP"
  12. export default {
  13. data() {
  14. return {
  15. showTip: false,
  16. }
  17. },
  18. mounted() {
  19. this.showTip = !uni.getStorageInfoSync().keys.includes(SHOW_TIP)
  20. // setTimeout(()=>{
  21. // this.showTip = false
  22. // },this.duration*3000)
  23. },
  24. props: {
  25. tip: {
  26. type: String,
  27. default: "点击「添加小程序」,下次访问更便捷",
  28. required: true
  29. },
  30. duration: {
  31. type: Number,
  32. default: 5,
  33. required: false
  34. }
  35. },
  36. methods: {
  37. hideTip() {
  38. uni.setStorageSync(SHOW_TIP, true)
  39. this.showTip = false
  40. }
  41. }
  42. }
  43. </script>
  44. <style lang="scss" scoped>
  45. $themeColor:#5677fc; //主题色
  46. .uni-add-tips-box {
  47. position: fixed;
  48. top: CustomBar + 20rpx;
  49. right: -20rpx;
  50. z-index: 99999;
  51. opacity: 0.8;
  52. display: flex;
  53. justify-content: flex-end;
  54. align-items: flex-end;
  55. flex-direction: column;
  56. width: 600upx;
  57. animation: opacityC 1s linear infinite;
  58. }
  59. .uni-add-tips-content::before {
  60. content: "";
  61. position: absolute;
  62. width: 0;
  63. height: 0;
  64. top: -38upx;
  65. right: 105upx;
  66. border-width: 20upx;
  67. border-style: solid;
  68. display: block;
  69. border-color: transparent transparent $themeColor transparent;
  70. }
  71. .uni-add-tips-content {
  72. border-width: 0upx;
  73. margin-top: 20upx;
  74. position: relative;
  75. background-color: $themeColor;
  76. box-shadow: 0 10upx 20upx -10upx $themeColor;
  77. border-radius: 12upx;
  78. display: flex;
  79. align-items: center;
  80. justify-content: center;
  81. padding: 18upx 20upx;
  82. margin-right: 40upx;
  83. }
  84. .uni-add-tips-content>text {
  85. color: #fff;
  86. font-size: 28upx;
  87. font-weight: 400;
  88. }
  89. @keyframes opacityC {
  90. 0% {
  91. opacity: 0.8;
  92. }
  93. 50% {
  94. opacity: 1;
  95. }
  96. }
  97. </style>