index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="time" :class="{themeColor : isView, bgTheme: isTheme}" :style="justifyLeft+viewColor+'background-color:'+ bgColor +';color:'+ colors +';background-image:url('+bgImage+');'">
  3. <text class="red" v-if="tipText">{{ tipText }}</text>
  4. <text class="styleAll" v-if="isDay === true">{{ day }}</text>
  5. <text class="timeTxt red" v-if="dayText">{{ dayText }}</text>
  6. <text class="styleAll">{{ hour }}</text>
  7. <text class="timeTxt red" v-if="hourText">{{ hourText }}</text>
  8. <text class="styleAll">{{ minute }}</text>
  9. <text class="timeTxt red" v-if="minuteText">{{ minuteText }}</text>
  10. <text class="styleAll">{{ second }}</text>
  11. <text class="timeTxt red" v-if="secondText">{{ secondText }}</text>
  12. </view>
  13. </template>
  14. <script>
  15. // +----------------------------------------------------------------------
  16. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  17. // +----------------------------------------------------------------------
  18. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  19. // +----------------------------------------------------------------------
  20. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  21. // +----------------------------------------------------------------------
  22. // | Author: CRMEB Team <admin@crmeb.com>
  23. // +----------------------------------------------------------------------
  24. import { mapGetters } from "vuex";
  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. id:{
  62. type: String | Number,
  63. default: ""
  64. },
  65. bgColor:{
  66. type: String,
  67. default: ""
  68. },
  69. colors:{
  70. type: String,
  71. default: ""
  72. },
  73. bgImage: {
  74. type: String,
  75. default: ""
  76. },
  77. isView: {
  78. type: Boolean,
  79. default: false
  80. },
  81. isTheme: {
  82. type: Boolean,
  83. default: false
  84. },
  85. },
  86. data: function() {
  87. return {
  88. day: "00",
  89. hour: "00",
  90. minute: "00",
  91. second: "00"
  92. };
  93. },
  94. computed:{
  95. ...mapGetters(['viewColor']),
  96. },
  97. created: function() {
  98. this.show_time();
  99. },
  100. mounted: function() {},
  101. methods: {
  102. show_time: function() {
  103. let that = this;
  104. function runTime() {
  105. //时间函数
  106. let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差;
  107. let day = 0,
  108. hour = 0,
  109. minute = 0,
  110. second = 0;
  111. if (intDiff > 0) {
  112. //转换时间
  113. if (that.isDay === true) {
  114. day = Math.floor(intDiff / (60 * 60 * 24));
  115. } else {
  116. day = 0;
  117. }
  118. hour = Math.floor(intDiff / (60 * 60)) - day * 24;
  119. minute = Math.floor(intDiff / 60) - day * 24 * 60 - hour * 60;
  120. second =
  121. Math.floor(intDiff) -
  122. day * 24 * 60 * 60 -
  123. hour * 60 * 60 -
  124. minute * 60;
  125. if (hour <= 9) hour = "0" + hour;
  126. if (minute <= 9) minute = "0" + minute;
  127. if (second <= 9) second = "0" + second;
  128. that.day = day;
  129. that.hour = hour;
  130. that.minute = minute;
  131. that.second = second;
  132. } else {
  133. that.day = "00";
  134. that.hour = "00";
  135. that.minute = "00";
  136. that.second = "00";
  137. that.$emit('getProduct');
  138. uni.$emit('endTime',that.id)
  139. clearInterval(runTime)
  140. }
  141. }
  142. runTime();
  143. setInterval(runTime, 1000);
  144. }
  145. }
  146. };
  147. </script>
  148. <style lang="scss" scoped>
  149. .styleAll {
  150. padding: 0 6rpx;
  151. }
  152. .red{
  153. margin: 0 4rpx;
  154. }
  155. .themeColor .red{
  156. color: var(--view-theme);
  157. }
  158. .bgTheme .styleAll{
  159. background-color: var(--view-theme);
  160. color: #ffffff;
  161. font-size: 22rpx;
  162. display: flex;
  163. align-items: center;
  164. justify-content: center;
  165. }
  166. .time{
  167. display: flex;
  168. justify-content: center;
  169. font-size: 20rpx;
  170. }
  171. </style>