s-count-down.vue 3.8 KB

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