Cjmsheader.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="Cjmsheader">
  3. <div class="time">{{nowdate}}&nbsp;&nbsp;{{nowtime}}</div>
  4. <div class="header">
  5. <p>延吉市数字应急自然灾害综合风险监管平台</p>
  6. </div>
  7. <div class="yj-name">张三</div>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'Cjmsheader',
  13. data(){
  14. return {
  15. nowdate : '', //日期
  16. nowtime : '', //时间
  17. newTimer : '', //定时器
  18. }
  19. },
  20. props: {
  21. },
  22. mounted () {
  23. this.timerOneScondRun(); //执行日期函数
  24. clearInterval(this.newTimer); //清除定时器
  25. // 定时获取时间
  26. this.newTimer = setInterval(this.timerOneScondRun, 1000);
  27. },
  28. beforeRouteLeave(to,from,next){
  29. // 离开组件时停掉定时器,节省内存
  30. clearInterval(this.newTimer);
  31. next();
  32. },
  33. methods: {
  34. //获取时间
  35. timerOneScondRun() {
  36. let date = new Date();
  37. // 日期格式 2022年05月31日
  38. this.nowdate =
  39. date.getFullYear() +
  40. "/" +
  41. (date.getMonth() + 1 >= 10
  42. ? date.getMonth() + 1
  43. : "0" + (date.getMonth() + 1)) +
  44. "/" +
  45. (date.getDate() >= 10 ? date.getDate() : "0" + date.getDate());
  46. // 时间格式 12:11:27
  47. this.nowtime =
  48. date.getHours() +
  49. ":" +
  50. (date.getMinutes() >= 10
  51. ? date.getMinutes()
  52. : "0" + date.getMinutes()) +
  53. ":" +
  54. (date.getSeconds() >= 10 ? date.getSeconds() : "0" + date.getSeconds());
  55. },
  56. }
  57. }
  58. </script>
  59. <!-- Add "scoped" attribute to limit CSS to this component only -->
  60. <style scoped>
  61. .header{
  62. position: absolute;
  63. background: url("../assets/images/yj-cjmstopbg.png") no-repeat center;
  64. width: 100%;
  65. height: 108px;
  66. top:0px;
  67. left: 0px;
  68. z-index: 4;
  69. }
  70. .header p{
  71. color: #fff;
  72. line-height: 70px;
  73. font-family: "myfont";
  74. font-size: 36px;
  75. letter-spacing: 1px;
  76. text-align: center;
  77. }
  78. .time{
  79. text-align: center;
  80. font-family: "黑体";
  81. font-size: 16px;
  82. color: #fff;
  83. font-style: italic;
  84. position: absolute;
  85. left:25px;
  86. top:6px;
  87. z-index: 9;
  88. }
  89. .yj-name{
  90. position: absolute;
  91. cursor: pointer;
  92. padding-left: 72px;
  93. height: 26px;
  94. line-height: 26px;
  95. right: 25px;
  96. top: 4px;
  97. color: #fff;
  98. z-index: 9;
  99. font-size: 16px;
  100. background: url("../assets/images/yj-name.png") no-repeat center;
  101. }
  102. </style>