index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div class="l-flex--row c-navbar">
  3. <breadcrumb class="l-flex__auto c-sibling-item" />
  4. <div
  5. v-if="isSuperAdmin"
  6. class="l-flex__none c-sibling-item farthest has-active"
  7. @click="onChangeTenant"
  8. >
  9. {{ tenantName }}
  10. </div>
  11. <upload-dashboard
  12. v-if="isOperator"
  13. class="l-flex__none c-sibling-item farthest"
  14. />
  15. <el-dropdown
  16. class="l-flex__none c-sibling-item farthest c-navbar__user u-color--blue u-font-size--sm has-active"
  17. trigger="click"
  18. @command="onCommand"
  19. >
  20. <div class="l-flex--row">
  21. <img
  22. v-if="avatar"
  23. class="c-navbar__avatar"
  24. :src="avatar"
  25. >
  26. <span class="c-sibling-item">{{ name }}</span>
  27. <i class="c-sibling-item near el-icon-arrow-down" />
  28. </div>
  29. <el-dropdown-menu slot="dropdown">
  30. <el-dropdown-item command="profile">个人设置</el-dropdown-item>
  31. <el-dropdown-item
  32. command="logout"
  33. divided
  34. >
  35. 退出登录
  36. </el-dropdown-item>
  37. </el-dropdown-menu>
  38. </el-dropdown>
  39. <radio-table-dialog
  40. ref="tenantDialog"
  41. :title="title"
  42. :schema="tenantSchema"
  43. append-to-body
  44. @confirm="onChoosenTenant"
  45. />
  46. <el-drawer
  47. title="个人设置"
  48. :visible.sync="drawer"
  49. direction="rtl"
  50. :size="480"
  51. :with-header="false"
  52. :destroy-on-close="true"
  53. append-to-body
  54. >
  55. <profile
  56. class="l-flex__fill"
  57. @close="drawer = false"
  58. />
  59. </el-drawer>
  60. </div>
  61. </template>
  62. <script>
  63. import { mapGetters } from 'vuex'
  64. import {
  65. getPlatformTenants,
  66. resetDepartmentCache
  67. } from '@/api/user'
  68. import Breadcrumb from './Breadcrumb'
  69. import UploadDashboard from './UploadDashboard'
  70. import Profile from './Profile'
  71. export default {
  72. name: 'Navbar',
  73. components: {
  74. Profile,
  75. Breadcrumb,
  76. UploadDashboard
  77. },
  78. data () {
  79. return {
  80. drawer: false,
  81. tenantSchema: {
  82. condition: { name: '' },
  83. list: getPlatformTenants,
  84. filters: [
  85. { key: 'name', type: 'search', placeholder: '标识' }
  86. ],
  87. cols: [
  88. { prop: 'remark', label: '名称' },
  89. { prop: 'name', label: '标识' }
  90. ]
  91. }
  92. }
  93. },
  94. computed: {
  95. ...mapGetters([
  96. 'avatar',
  97. 'name',
  98. 'isSuperAdmin',
  99. 'isOperator',
  100. 'tenantId',
  101. 'tenantName'
  102. ]),
  103. title () {
  104. return `租户切换(${this.tenantName})`
  105. }
  106. },
  107. methods: {
  108. onCommand (command) {
  109. switch (command) {
  110. case 'profile':
  111. // this.$router.push({ name: 'profile' })
  112. this.drawer = true
  113. break
  114. case 'logout':
  115. this.$store.dispatch('user/logout')
  116. break
  117. default:
  118. break
  119. }
  120. },
  121. onChangeTenant () {
  122. this.$refs.tenantDialog.show({ id: this.tenantId, name: this.tenantName })
  123. },
  124. onChoosenTenant ({ value, done }) {
  125. if (value.path !== this.tenant) {
  126. resetDepartmentCache()
  127. this.$store.commit('user/SET_TENANT', value)
  128. }
  129. done()
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .c-navbar {
  136. position: relative;
  137. height: $height--md;
  138. padding: 0 $padding--xl;
  139. background-color: #fff;
  140. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  141. overflow: hidden;
  142. z-index: 1;
  143. &__info {
  144. background: url("~@/assets/icon_inform.png") 0 0 / 100% 100% no-repeat;
  145. }
  146. &__user.hover-effect {
  147. cursor: pointer;
  148. transition: background 0.3s;
  149. &:hover {
  150. background: rgba(0, 0, 0, 0.025);
  151. }
  152. }
  153. &__avatar {
  154. width: 40px;
  155. height: 40px;
  156. border-radius: 50%;
  157. }
  158. .el-icon-arrow-down {
  159. font-weight: bolder;
  160. }
  161. }
  162. </style>