index.vue 4.8 KB

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