countDown.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <!-- 时间倒计时 -->
  3. <view class="time" :style="justifyLeft">
  4. <text class="" v-if="tipText">{{ tipText }}</text>
  5. <text class="styleAll p6" v-if="isDay === true" :style="{background:bgColor.bgColor,color:bgColor.Color}">{{ day }}{{bgColor.isDay?'天':''}}</text>
  6. <text class="timeTxt" v-if="dayText" :style="{width:bgColor.timeTxtwidth,color:bgColor.bgColor}">{{ dayText }}</text>
  7. <text class="styleAll" :class='isCol?"timeCol":""' :style="{background:bgColor.bgColor,color:bgColor.Color,width:bgColor.width}">{{ hour }}</text>
  8. <text class="timeTxt" v-if="hourText" :class='isCol?"whit":""' :style="{width:bgColor.timeTxtwidth,color:bgColor.bgColor}">{{ hourText }}</text>
  9. <text class="styleAll" :class='isCol?"timeCol":""' :style="{background:bgColor.bgColor,color:bgColor.Color,width:bgColor.width}">{{ minute }}</text>
  10. <text class="timeTxt" v-if="minuteText" :class='isCol?"whit":""' :style="{width:bgColor.timeTxtwidth,color:bgColor.bgColor}">{{ minuteText }}</text>
  11. <text class="styleAll" :class='isCol?"timeCol":""' :style="{background:bgColor.bgColor,color:bgColor.Color,width:bgColor.width}">{{ second }}</text>
  12. <text class="timeTxt" v-if="secondText">{{ secondText }}</text>
  13. </view>
  14. </template>
  15. <script>
  16. // +----------------------------------------------------------------------
  17. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  18. // +----------------------------------------------------------------------
  19. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  20. // +----------------------------------------------------------------------
  21. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  22. // +----------------------------------------------------------------------
  23. // | Author: CRMEB Team <admin@crmeb.com>
  24. // +----------------------------------------------------------------------
  25. export default {
  26. name: "countDown",
  27. props: {
  28. justifyLeft: {
  29. type: String,
  30. default: ""
  31. },
  32. //距离开始提示文字
  33. tipText: {
  34. type: String,
  35. default: "倒计时"
  36. },
  37. dayText: {
  38. type: String,
  39. default: "天"
  40. },
  41. hourText: {
  42. type: String,
  43. default: "时"
  44. },
  45. minuteText: {
  46. type: String,
  47. default: "分"
  48. },
  49. secondText: {
  50. type: String,
  51. default: "秒"
  52. },
  53. datatime: {
  54. type: Number,
  55. default: 0
  56. },
  57. isDay: {
  58. type: Boolean,
  59. default: true
  60. },
  61. isCol: {
  62. type: Boolean,
  63. default: false
  64. },
  65. bgColor: {
  66. type: Object,
  67. default: null
  68. }
  69. },
  70. data: function() {
  71. return {
  72. day: "00",
  73. hour: "00",
  74. minute: "00",
  75. second: "00"
  76. };
  77. },
  78. created: function() {
  79. this.show_time();
  80. },
  81. mounted: function() {},
  82. methods: {
  83. show_time: function() {
  84. let that = this;
  85. function runTime() {
  86. //时间函数
  87. let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差;
  88. let day = 0,
  89. hour = 0,
  90. minute = 0,
  91. second = 0;
  92. if (intDiff > 0) {
  93. //转换时间
  94. if (that.isDay === true) {
  95. day = Math.floor(intDiff / (60 * 60 * 24));
  96. } else {
  97. day = 0;
  98. }
  99. hour = Math.floor(intDiff / (60 * 60)) - day * 24;
  100. minute = Math.floor(intDiff / 60) - day * 24 * 60 - hour * 60;
  101. second =
  102. Math.floor(intDiff) -
  103. day * 24 * 60 * 60 -
  104. hour * 60 * 60 -
  105. minute * 60;
  106. if (hour <= 9) hour = "0" + hour;
  107. if (minute <= 9) minute = "0" + minute;
  108. if (second <= 9) second = "0" + second;
  109. that.day = day;
  110. that.hour = hour;
  111. that.minute = minute;
  112. that.second = second;
  113. } else {
  114. that.day = "00";
  115. that.hour = "00";
  116. that.minute = "00";
  117. that.second = "00";
  118. }
  119. }
  120. runTime();
  121. setInterval(runTime, 1000);
  122. }
  123. }
  124. };
  125. </script>
  126. <style scoped>
  127. .p6{
  128. padding: 0 8rpx;
  129. }
  130. .styleAll{
  131. /* color: #fff; */
  132. font-size: 24rpx;
  133. height: 36rpx;
  134. line-height: 36rpx;
  135. border-radius: 6rpx;
  136. text-align: center;
  137. /* padding: 0 6rpx; */
  138. }
  139. .timeTxt{
  140. text-align: center;
  141. /* width: 16rpx; */
  142. height: 36rpx;
  143. line-height: 36rpx;
  144. display: inline-block;
  145. }
  146. .whit{
  147. color: #fff !important;
  148. }
  149. .time {
  150. display: flex;
  151. justify-content: center;
  152. }
  153. .red {
  154. color: #fc4141;
  155. margin: 0 4rpx;
  156. }
  157. .timeCol {
  158. /* width: 40rpx;
  159. height: 40rpx;
  160. line-height: 40rpx;
  161. text-align:center;
  162. border-radius: 6px;
  163. background: #fff;
  164. font-size: 24rpx; */
  165. color: #E93323;
  166. }
  167. </style>