Front.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div>
  3. <div class="front-notice"><i class="el-icon-bell" style="margin-right: 2px"></i>公告:{{ top }}</div>
  4. <!--头部-->
  5. <div class="front-header">
  6. <div class="front-header-left">
  7. <img src="@/assets/imgs/logo.png" alt="">
  8. <div class="title">项目前台</div>
  9. </div>
  10. <div class="front-header-center">
  11. <div class="front-header-nav">
  12. <el-menu :default-active="$route.path" mode="horizontal" router>
  13. <el-menu-item index="/front/home">首页</el-menu-item>
  14. <el-menu-item index="/front/person">个人中心</el-menu-item>
  15. </el-menu>
  16. </div>
  17. </div>
  18. <div class="front-header-right">
  19. <div v-if="!user.username">
  20. <el-button @click="$router.push('/login')">登录</el-button>
  21. <el-button @click="$router.push('/register')">注册</el-button>
  22. </div>
  23. <div v-else>
  24. <el-dropdown>
  25. <div class="front-header-dropdown">
  26. <img :src="user.avatar" alt="">
  27. <div style="margin-left: 10px">
  28. <span>{{ user.name }}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
  29. </div>
  30. </div>
  31. <el-dropdown-menu slot="dropdown">
  32. <el-dropdown-item>
  33. <div style="text-decoration: none" @click="logout">退出</div>
  34. </el-dropdown-item>
  35. </el-dropdown-menu>
  36. </el-dropdown>
  37. </div>
  38. </div>
  39. </div>
  40. <!--主体-->
  41. <div class="main-body">
  42. <router-view ref="child" @update:user="updateUser" />
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. name: "FrontLayout",
  49. components:{
  50. },
  51. data () {
  52. return {
  53. top: '',
  54. notice: [],
  55. user: JSON.parse(localStorage.getItem("xm-user") || '{}'),
  56. }
  57. },
  58. mounted() {
  59. this.loadNotice()
  60. },
  61. methods: {
  62. loadNotice() {
  63. this.$request.get('/notice/selectAll').then(res => {
  64. this.notice = res.data
  65. let i = 0
  66. if (this.notice && this.notice.length) {
  67. this.top = this.notice[0].content
  68. setInterval(() => {
  69. this.top = this.notice[i].content
  70. i++
  71. if (i === this.notice.length) {
  72. i = 0
  73. }
  74. }, 2500)
  75. }
  76. })
  77. },
  78. updateUser() {
  79. this.user = JSON.parse(localStorage.getItem('xm-user') || '{}') // 重新获取下用户的最新信息
  80. },
  81. // 退出登录
  82. logout() {
  83. localStorage.removeItem("xm-user");
  84. this.$router.push("/login");
  85. },
  86. }
  87. }
  88. </script>
  89. <style scoped>
  90. @import "@/assets/css/front.css";
  91. </style>