Header.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div id="Header">
  3. <el-row>
  4. <el-col :span="24" class="main header">
  5. <el-col :span="24" class="one">
  6. <el-col :span="8" class="left">
  7. <span @click="collapseChage">
  8. <i v-if="!collapse" class="el-icon-s-fold"></i>
  9. <i v-else class="el-icon-s-unfold"></i>
  10. </span>
  11. <span
  12. >{{ siteInfo.zhTitle }}-{{
  13. type == 'baoanpolice' ? '公安端' : type == 'baoancompany' ? '企业端' : type == 'baoanexam' ? '考试端' : type == 'baoansociety' ? '协会端' : ''
  14. }}</span
  15. >
  16. </el-col>
  17. <el-col :span="16" class="right">
  18. <el-button type="primary" size="mini" @click="headerBtn('统计')" v-if="type == 'baoanpolice'">统计</el-button>
  19. <el-button type="primary" size="mini" @click="headerBtn('统计2')" v-if="type == 'baoanpolice'">统计-模板2</el-button>
  20. <el-button type="primary" size="mini" @click="headerBtn('统计3')" v-if="type == 'baoanpolice'">统计-模板3</el-button>
  21. <el-button type="primary" size="mini" @click="headerBtn('统计4')" v-if="type == 'baoanpolice'">统计-模板4</el-button>
  22. <el-button type="primary" size="mini" @click="headerBtn('修改密码')">修改密码</el-button>
  23. <el-button size="mini" class="name"><i class="el-icon-user-solid"></i>{{ user.name || user.company || '游客' }}</el-button>
  24. <el-button type="danger" size="mini" @click="logout">退出登录</el-button>
  25. </el-col>
  26. </el-col>
  27. </el-col>
  28. </el-row>
  29. </div>
  30. </template>
  31. <script>
  32. const { siteInfo } = require('../../layout/deploy/site');
  33. import { mapState, mapMutations } from 'vuex';
  34. import bus from './bus';
  35. export default {
  36. name: 'Header',
  37. props: {},
  38. components: {},
  39. data: function() {
  40. return { collapse: false, siteInfo: siteInfo, type: '' };
  41. },
  42. created() {
  43. this.initTitle();
  44. },
  45. methods: {
  46. ...mapMutations(['deleteUser']),
  47. // 侧边栏折叠
  48. collapseChage() {
  49. this.collapse = !this.collapse;
  50. bus.$emit('collapse', this.collapse);
  51. },
  52. // 退出登录
  53. logout() {
  54. this.deleteUser();
  55. this.$router.push('/login');
  56. },
  57. initTitle() {
  58. // 不同用户类别,显示不同的名称
  59. const { options } = this.$router;
  60. if (!options) {
  61. console.warn('获取菜单:解析base错误');
  62. return;
  63. }
  64. const { base } = options;
  65. this.$set(this, `type`, base);
  66. },
  67. headerBtn(type) {
  68. this.$emit('headerBtn', type);
  69. },
  70. },
  71. computed: {
  72. ...mapState(['user']),
  73. },
  74. metaInfo() {
  75. return { title: this.$route.meta.title };
  76. },
  77. mounted() {
  78. if (document.body.clientWidth < 1500) {
  79. this.collapseChage();
  80. }
  81. },
  82. watch: {
  83. test: {
  84. deep: true,
  85. immediate: true,
  86. handler(val) {},
  87. },
  88. },
  89. };
  90. </script>
  91. <style lang="less" scoped>
  92. .main {
  93. .one {
  94. height: 60px;
  95. border-bottom: 1px solid #f1f1f1;
  96. padding: 0 10px;
  97. .left {
  98. line-height: 60px;
  99. span {
  100. display: inline-block;
  101. margin: 0 10px;
  102. font-size: 22px;
  103. color: #ffffff;
  104. font-weight: bold;
  105. font-family: cursive;
  106. }
  107. }
  108. .right {
  109. text-align: right;
  110. padding: 15px 0;
  111. .name {
  112. background-color: transparent;
  113. border: none;
  114. color: #fff;
  115. }
  116. }
  117. }
  118. }
  119. </style>