navigationBarView.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="navigationBarView">
  3. <view class="back-btn" @click="back">
  4. <image class="arrow-bg" :src="require('../static/images/icon-back-bg.png')"></image>
  5. <!-- <text>返回</text> -->
  6. </view>
  7. <view class="countdown" v-if="maxTimer">{{timer}}s</view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props: {
  13. maxTimer: {
  14. type: Number
  15. }
  16. },
  17. data() {
  18. return {
  19. timer: 60,
  20. navTimer: ''
  21. };
  22. },
  23. created() {
  24. console.log(1)
  25. if (this.maxTimer) {
  26. this.timer = this.maxTimer;
  27. this.countdown()
  28. }
  29. },
  30. beforeDestroy() {
  31. clearInterval(this.navTimer)
  32. },
  33. methods: {
  34. countdown() {
  35. const $this = this;
  36. clearInterval(this.navTimer);
  37. this.navTimer = setInterval(function() {
  38. // console.log($this.timer)
  39. $this.timer = $this.timer - 1;
  40. if ($this.timer == 0) {
  41. clearInterval($this.navTimer);
  42. uni.navigateBack();
  43. return;
  44. }
  45. }, 1000)
  46. },
  47. back() {
  48. uni.navigateBack();
  49. },
  50. clearTimer() {
  51. clearInterval(this.navTimer);
  52. }
  53. }
  54. }
  55. </script>
  56. <style lang="scss">
  57. .navigationBarView {
  58. position: relative;
  59. display: flex;
  60. align-items: center;
  61. justify-content: space-between;
  62. width: 100vw;
  63. padding-top: 5.4vw;
  64. z-index: 1;
  65. .back-btn {
  66. position: relative;
  67. display: flex;
  68. align-items: center;
  69. // justify-content: center;
  70. width: 39.8vw;
  71. height: 12.5vw;
  72. border-radius: 0 12.5vw 12.5vw 0;
  73. .arrow-bg {
  74. position: absolute;
  75. top: 0;
  76. left: 0;
  77. width: 39.8vw;
  78. height: 12.5vw;
  79. }
  80. .arrow {
  81. width: 2.5vw;
  82. height: 4.2vw;
  83. margin-right: 1.7vw;
  84. }
  85. text {
  86. position: relative;
  87. margin-left: 10.4vw;
  88. color: #FFFFFF;
  89. font-size: 5vw;
  90. }
  91. }
  92. .countdown {
  93. color: #1994D7;
  94. margin-right: 3.3vw;
  95. font-size: 5vw;
  96. font-weight: 600;
  97. }
  98. }
  99. </style>