clock.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div class="header-left">
  3. <!-- 时间-->
  4. <div class="date">
  5. <div class="day m-r-10">
  6. <span>{{today}}</span>
  7. <span>{{time}}</span>
  8. </div>
  9. <div class="week m-r-10">{{weekC}}</div>
  10. <!-- <div class="line m-r-10"></div>
  11. <div class="day m-r-10">
  12. <span>{{weatherInfo.weather}} {{weatherInfo.wind}}</span>
  13. <span>{{weatherInfo.fireTit}} {{weatherInfo.fireLevel}}</span>
  14. </div> -->
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. let aDate = new Date();
  20. let month = aDate.getMonth() < 9 ? "0" + (aDate.getMonth() + 1) : aDate.getMonth() + 1;
  21. let date = aDate.getDate() <= 9 ? "0" + aDate.getDate() : aDate.getDate();
  22. let day = aDate.getDay();
  23. let weekCh = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六");
  24. let weekEn = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
  25. "Saturday");
  26. export default {
  27. created() {
  28. // this.$watch("open", function(newValue, oldValue) {
  29. // this.outOpen();
  30. // })
  31. },
  32. data() {
  33. return {
  34. // 右上时钟
  35. today: aDate.getFullYear() + "." + month + "." + date,
  36. weekE: weekEn[day].toUpperCase(),
  37. weekC: weekCh[day],
  38. time: aDate.toTimeString().substring(0, 8),
  39. // 天气
  40. weatherInfo:{
  41. weather:'阴',
  42. wind:'东北风',
  43. fireTit:'火险等级',
  44. fireLevel:'一级'
  45. }
  46. }
  47. },
  48. mounted() {
  49. this.init();
  50. },
  51. methods: {
  52. init() {
  53. // 右上时钟
  54. this.interval = setInterval(() => {
  55. let aDate = new Date();
  56. let month = aDate.getMonth() < 9 ? "0" + (aDate.getMonth() + 1) : aDate.getMonth() + 1;
  57. let date = aDate.getDate() <= 9 ? "0" + aDate.getDate() : aDate.getDate();
  58. let day = aDate.getDay();
  59. let weekCh = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六");
  60. let weekEn = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
  61. "Saturday");
  62. this.today = aDate.getFullYear() + "." + month + "." + date;
  63. this.weekC = weekCh[day];
  64. this.weekE = weekEn[day].toUpperCase();
  65. this.time = aDate.toTimeString().substring(0, 8);
  66. // console.log(this.today, this.weekC, this.weekE ,this.time);
  67. }, 1000)
  68. },
  69. },
  70. beforeDestroy() {
  71. // 右上时钟
  72. clearInterval(this.interval);
  73. },
  74. }
  75. </script>
  76. <style rel="stylesheet/scss" lang="scss" scoped>
  77. @import '@/assets/styles/base.scss';
  78. .header-left {
  79. height: 5vh;
  80. position: absolute;
  81. left: 10px;
  82. display: flex;
  83. font-size: 1rem;
  84. align-items: center;
  85. color: $inBlue;
  86. .date {
  87. flex: 1;
  88. display: flex;
  89. align-items: center;
  90. .day {
  91. display: flex;
  92. flex-direction: column;
  93. font-size: 14px;
  94. }
  95. .day span:nth-child(2) {
  96. font-size: 10px;
  97. text-align: right;
  98. }
  99. .week {
  100. font-size: 13px;
  101. writing-mode: tb-rl;
  102. }
  103. .time {
  104. font-size: 2rem;
  105. }
  106. .line {
  107. width: 1px;
  108. height: 1.5rem;
  109. background: $inBlue;
  110. margin: 0 .4rem;
  111. }
  112. }
  113. }
  114. </style>