header-time.php 6.0 KB

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