index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!--
  2. * @Author: WangQiBiao
  3. * @Date: 2019-09-25 09:19:42
  4. * @LastEditors: WangQiBiao
  5. * @LastEditTime: 2019-09-26 17:49:53
  6. * @Description: 头部
  7. -->
  8. <template>
  9. <div class="title">
  10. <div class="lf">让物业管理更简单</div>
  11. <div class="cent">绘享云</div>
  12. <div class="lr">
  13. <span class="time">{{time}}</span>
  14. <span class="date">{{date}}</span>
  15. <span class="day">{{day}}</span>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. data () {
  22. return {
  23. time: '00:00:00',
  24. date: '0000/00/00',
  25. day: '星期',
  26. timerFn: null
  27. }
  28. },
  29. mounted () {
  30. this.setTimeTrainingRotation()
  31. },
  32. beforeDestroy () {
  33. clearTimeout(this.timerFn)
  34. },
  35. methods: {
  36. fillZero (value) {
  37. if (value < 10) {
  38. return '0' + value
  39. }
  40. return value
  41. },
  42. /**
  43. * 日期
  44. */
  45. getDateValue () {
  46. const _now = new Date()
  47. const year = _now.getFullYear()
  48. const month = this.fillZero(_now.getMonth() + 1)
  49. const date = _now.getDate()
  50. this.date = year + '/' + month + '/' + date
  51. },
  52. /**
  53. * 时间
  54. */
  55. getTimeValue () {
  56. clearTimeout(this.timerFn)
  57. const _now = new Date()
  58. const hours = this.fillZero(_now.getHours())
  59. const minutes = this.fillZero(_now.getMinutes())
  60. const seconds = this.fillZero(_now.getSeconds())
  61. this.time = hours + ':' + minutes + ':' + seconds
  62. },
  63. /**
  64. * 星期
  65. */
  66. getDayValue () {
  67. const _now = new Date()
  68. const DAY_NUM = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  69. this.day = DAY_NUM[_now.getDay()]
  70. },
  71. /**
  72. * 轮训时间
  73. */
  74. setTimeTrainingRotation () {
  75. this.getDateValue()
  76. this.getTimeValue()
  77. this.getDayValue()
  78. this.timerFn = setTimeout(() => {
  79. this.setTimeTrainingRotation()
  80. }, 1000)
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. @import './index.scss';
  87. </style>