header-time.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template id="header-time">
  2. <div flex style="padding: 0 10px;">
  3. <div flex>
  4. <div class="right-top-button" @click="cockpitUrl.router">
  5. 总裁驾驶舱
  6. </div>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. Vue.component('header-time', {
  12. name: "header-time",
  13. template: '#header-time',
  14. props: {
  15. display: {
  16. type: Number,
  17. default: null
  18. }
  19. },
  20. data() {
  21. return {
  22. time: "00:00",
  23. day: "星期几",
  24. timeSlot: "上午",
  25. localValue: this.display,
  26. date: "2021年7月23日",
  27. fBtn: 0,
  28. cockpitUrl: {
  29. router: () => {
  30. this.$navigate({r: "mall/data-census/driving-window",is_display: 2})
  31. }
  32. }
  33. }
  34. },
  35. created(){
  36. },
  37. methods: {
  38. init() {
  39. this.time = this.formatTime()
  40. requestAnimationFrame(this.init)
  41. },
  42. jumpCockpit() {// 跳转驾驶舱
  43. },
  44. formatTime() {
  45. const time = new Date()
  46. const hours = time.getHours()
  47. const minutes = time.getMinutes()
  48. return `${this.supplement(hours)}:${this.supplement(minutes)}`
  49. },
  50. formatDay() {
  51. const xq = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  52. const time = new Date()
  53. const day = time.getDay()
  54. return `${xq[day]}`
  55. },
  56. formatTimeSlot() {
  57. // 凌晨,上午,下午,晚上,半夜
  58. const formatObj = {
  59. '24-5': '凌晨',
  60. '6-9': '清晨',
  61. '9-12': '上午',
  62. '13-18': '下午',
  63. '19-23': '晚上',
  64. }
  65. const time = new Date()
  66. const hours = time.getHours()
  67. let result = '上午'
  68. for (const key in formatObj) {
  69. const min = key.split('-')[0]
  70. const max = key.split('-')[1]
  71. if (min <= hours && hours <= hours) {
  72. result = formatObj[key]
  73. continue
  74. }
  75. }
  76. return `${result}`
  77. },
  78. formatDate() {
  79. const time = new Date()
  80. const year = time.getFullYear()
  81. const month = time.getMonth()
  82. const date = time.getDate()
  83. return `${year}年${this.supplement(month+1)}月${this.supplement(date)}日`
  84. },
  85. supplement(numebr) { // 一位的时候补充为0 - 只补充整数
  86. const str = String(numebr)
  87. return str.padStart(2, 0)
  88. },
  89. updateScreenType(){
  90. this.fBtn = this.fBtn?0:1;
  91. localStorage.setItem('fullScreen',this.fBtn);
  92. this.updateScreenDom();
  93. },
  94. updateScreenDom(){
  95. // document.getElementById("_aside").setAttribute("style","display: none;",)
  96. if(this.fBtn && this.display === 2){
  97. document.getElementById("_aside").style.display = 'none';
  98. document.getElementById("_header").style.display = 'none';
  99. document.getElementById("_aside_2").style.display = 'none'
  100. this.$emit('update:display',1)
  101. // document.getElementById("_main").style.height = 'auto';
  102. } else {
  103. document.getElementById("_aside").style.display = '';
  104. document.getElementById("_header").style.display = '';
  105. document.getElementById("_aside_2").style.display = ''
  106. this.$emit('update:display',2)
  107. }
  108. setTimeout(() => {
  109. // 获取html可视区域高度:--这里需要按F5
  110. let clientHeight = `${document.documentElement.clientHeight}`;
  111. let mainHeight = clientHeight;
  112. // 动态设置元素高度:
  113. var main = document.getElementById('_main'); //获取元素存储在变量中
  114. main.style.cssText = 'height: ' + mainHeight + 'px !important';
  115. }, 200);
  116. }
  117. },
  118. mounted() {
  119. // 下面三项不需要实时更新 - 第二天不更新问题
  120. this.day = this.formatDay()
  121. this.timeSlot = this.formatTimeSlot()
  122. this.date = this.formatDate()
  123. this.frameId = requestAnimationFrame(this.init)
  124. let typeData = localStorage.getItem('fullScreen');
  125. if(typeData){
  126. this.fBtn = Number(typeData);
  127. }
  128. this.updateScreenDom();
  129. },
  130. destroyed() {
  131. cancelAnimationFrame(this.frameId)
  132. },
  133. });
  134. window.addEventListener('resize', () => {
  135. setTimeout(() => {
  136. // 获取html可视区域高度:--这里需要按F5
  137. let clientHeight = `${document.documentElement.clientHeight}`;
  138. let mainHeight = clientHeight;
  139. // 动态设置元素高度:
  140. var main = document.getElementById('_main'); //获取元素存储在变量中
  141. main.style.cssText = 'height: ' + mainHeight + 'px !important';
  142. }, 50);
  143. });
  144. </script>