Header.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div id="app-header">
  3. <span class="title">采空区信息化管理系统</span>
  4. <div class="time">{{ time }}</div>
  5. <div class="user"><el-icon><User /></el-icon><span class="welcome">欢迎您,{{ user?.accountName||'***' }}</span></div>
  6. </div>
  7. </template>
  8. <script>
  9. import {parseTime} from '@/utils'
  10. import { mapState } from 'pinia'
  11. import { useStore } from '@/store/modules/user'
  12. import {getUserProfile} from '@/api/system'
  13. export default {
  14. name:'AppHeader',
  15. data(){
  16. return{
  17. time:parseTime(new Date(),'{y}.{m}.{d} {h}:{i}:{s}'),
  18. timer:null
  19. }
  20. },
  21. computed: {
  22. ...mapState(useStore,{
  23. "user":'user'
  24. })
  25. },
  26. created(){
  27. this.init()
  28. },
  29. methods:{
  30. init(){
  31. this.timer=setInterval(()=>{
  32. this.getnow()
  33. },1000)
  34. this.saveUserInfo()
  35. },
  36. getnow(){
  37. this.time = parseTime(new Date(),'{y}.{m}.{d} {h}:{i}:{s}')
  38. },
  39. saveUserInfo(){
  40. const store=useStore()
  41. getUserProfile().then((res)=>{
  42. store.$patch({
  43. user:res.data
  44. })
  45. localStorage.setItem('user',JSON.stringify(res.data))
  46. })
  47. },
  48. },
  49. destroyed() {
  50. if(this.timer){
  51. clearInterval(this.timer)
  52. }
  53. },
  54. }
  55. </script>
  56. <style lang="scss" scoped>
  57. #app-header{
  58. height: 8.89vh;
  59. background-image: url(@/assets/images/header.png);
  60. background-repeat: no-repeat;
  61. background-size: 100% 100%;
  62. color: #fff;
  63. text-align: center;
  64. line-height:8vh;
  65. position: relative;
  66. .title{
  67. font-size: 36.6px;
  68. font-family: 'YouSheBiaoTiHei';
  69. letter-spacing: 4px;
  70. }
  71. .time{
  72. color: #32C5FF;
  73. font-size: 18px;
  74. position: absolute;
  75. left: 20px;
  76. bottom: -1.5vh;
  77. }
  78. .user{
  79. color: #32C5FF;
  80. font-size: 18px;
  81. position: absolute;
  82. right: 20px;
  83. bottom: -1.5vh;
  84. display: flex;
  85. justify-content: center;
  86. align-items: center;
  87. .welcome{
  88. text-indent: 5px;
  89. }
  90. }
  91. }
  92. </style>