time.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view>
  3. <view class="flex alcenter">
  4. <text class="order-t" :class="size" :style="{background:bgColor,color:color}">{{showT.h}}</text><text class="ft12 ftw600 plr5">:</text>
  5. <text class="order-t" :class="size" :style="{background:bgColor,color:color}">{{showT.m}}</text><text class="ft12 ftw600 plr5">:</text>
  6. <text class="order-t" :class="size" :style="{background:bgColor,color:color}">{{showT.s}}</text>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import helper from '@/static/js/helper.js';
  12. export default{
  13. props:{
  14. t:{
  15. type:Number,
  16. default:0,
  17. },
  18. size:{
  19. type:String,
  20. default:''
  21. },
  22. bgColor:{
  23. type:String,
  24. default:'#2E2F33'
  25. },
  26. color:{
  27. type:String,
  28. default:'#ffffff'
  29. }
  30. },
  31. data(){
  32. return {
  33. myT:0,
  34. timer:null,
  35. }
  36. },
  37. computed:{
  38. showT(){
  39. let myT = this.myT;
  40. return helper.djsFull(myT);
  41. }
  42. },
  43. created(){
  44. this.myT = this.t;
  45. this.djs();
  46. },
  47. destroyed(){
  48. if(this.timer != null){
  49. clearInterval(this.timer);
  50. }
  51. },
  52. methods:{
  53. djs(){
  54. if(this.timer){
  55. clearInterval(this.timer);
  56. }
  57. this.timer = setInterval(()=>{
  58. if(this.myT == 0){
  59. clearInterval(this.timer);
  60. }else{
  61. this.myT = this.myT - 1;
  62. }
  63. },1000);
  64. }
  65. }
  66. }
  67. </script>
  68. <style>
  69. .order-t{
  70. width:48rpx;
  71. height:48rpx;
  72. background:#FFFFFF;
  73. text-align: center;
  74. line-height: 48rpx;
  75. font-size:28rpx;
  76. font-weight: 500;
  77. color: #000000;
  78. border-radius: 8rpx;
  79. }
  80. .order-t.small{
  81. width: 40rpx;
  82. height: 40rpx;
  83. font-size: 24rpx;
  84. line-height: 40rpx;
  85. }
  86. </style>