smh-timer.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="count_down">
  3. <text>{{minutes1}}</text>
  4. <text>{{minutes}}</text>
  5. <text>:</text>
  6. <text>{{second1}}</text>
  7. <text>{{second}}</text>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. name: "timer",
  13. props: {
  14. auto: {
  15. type: Boolean,
  16. default: true
  17. }
  18. },
  19. watch: {
  20. Number: function(val) {
  21. this.countDown1 = this.Number
  22. this.countDown(this.Number)
  23. this.$emit('timing', this.Number)
  24. }
  25. },
  26. created() {
  27. if (this.auto) {
  28. this.interval = setInterval(() => {
  29. this.Number++
  30. }, 1000)
  31. }
  32. },
  33. data() {
  34. return {
  35. Number: 0,
  36. minutes: 0,
  37. minutes1: 0,
  38. second: 0,
  39. second1: 0,
  40. countDown1: 0,
  41. interval: null
  42. };
  43. },
  44. methods: {
  45. reset() {
  46. clearInterval(this.interval)
  47. this.Number = 0
  48. this.minutes = 0
  49. this.minutes1 = 0
  50. this.second = 0
  51. this.second1 = 0
  52. this.countDown1 = 0
  53. this.interval = setInterval(() => {
  54. this.Number++
  55. }, 1000)
  56. },
  57. start() {
  58. this.interval = setInterval(() => {
  59. this.Number++
  60. }, 1000)
  61. },
  62. clear() {
  63. clearInterval(this.interval)
  64. },
  65. countDown(countDown) {
  66. if (countDown > 59) {
  67. let d = parseInt(countDown / 60)
  68. let minute = d.toString().split('')
  69. if (minute.length == 1) {
  70. this.minutes = minute[0]
  71. this.minutes1 = 0
  72. } else {
  73. this.minutes1 = minute[0]
  74. this.minutes = minute[1]
  75. }
  76. let dd = countDown % 60
  77. let numbers = dd.toString().split('')
  78. if (numbers.length == 1) {
  79. this.second1 = 0
  80. this.second = numbers[0]
  81. } else {
  82. this.second1 = numbers[0]
  83. this.second = numbers[1]
  84. }
  85. } else {
  86. this.minutes = 0
  87. this.minutes1 = 0
  88. let numbers = countDown.toString().split('')
  89. if (numbers.length == 1) {
  90. this.second = numbers[0]
  91. this.second1 = 0
  92. } else {
  93. this.second1 = numbers[0]
  94. this.second = numbers[1]
  95. }
  96. }
  97. },
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .count_down {
  103. display: flex;
  104. align-items: center;
  105. // margin-bottom: 60rpx;
  106. justify-content: center;
  107. margin-left:5rpx ;
  108. text {
  109. display: block;
  110. color: #346EF6;
  111. margin-right: 6rpx;
  112. font-size: 30rpx;
  113. // font-weight: bold;
  114. }
  115. .maohao {
  116. padding: 0 10rpx;
  117. font-size: 30rpx;
  118. font-weight: bold;
  119. }
  120. }
  121. </style>