header.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="header">
  3. <div class="header-left">
  4. <img src="@/assets/imgs/OA/zdww.png" alt="" />
  5. <p
  6. >{{ titleName }}
  7. <!-- <span v-if="menuUlShow">|</span> {{ headerTitleName }} -->
  8. </p>
  9. </div>
  10. <!-- <div class="header-right">
  11. <ul class="menuUl" v-if="menuUlShow">
  12. <li v-for="(item, index) in reactiveData.routes" :key="index" v-show="item.alwaysShow">
  13. <router-link :to="'/oaSystem/' + pathBossName + '/' + item.path">
  14. <span>{{ item.name }}</span>
  15. </router-link>
  16. </li>
  17. </ul>
  18. <div class="header-user">
  19. <ElDropdown class="custom-hover" :class="prefixCls" trigger="click">
  20. <div class="flex items-center">
  21. <ElAvatar
  22. :src="avatar"
  23. alt=""
  24. class="w-[calc(var(--logo-height)-25px)] rounded-[50%]"
  25. />
  26. <span class="pl-[5px] c-white ml-5px text-14px <lg:hidden">
  27. {{ userName }}
  28. </span>
  29. </div>
  30. <template #dropdown>
  31. <ElDropdownMenu>
  32. <ElDropdownItem>
  33. <Icon icon="ep:tools" />
  34. <div @click="toProfile">{{ t('common.profile') }}</div>
  35. </ElDropdownItem>
  36. <ElDropdownItem divided @click="loginOut">
  37. <Icon icon="ep:switch-button" />
  38. <div>{{ t('common.loginOut') }}</div>
  39. </ElDropdownItem>
  40. </ElDropdownMenu>
  41. </template>
  42. </ElDropdown>
  43. </div>
  44. </div> -->
  45. </div>
  46. </template>
  47. <script setup lang="ts">
  48. import { useRouter } from 'vue-router'
  49. import { ElMessageBox } from 'element-plus'
  50. import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
  51. import { useDesign } from '@/hooks/web/useDesign'
  52. import avatarImg from '@/assets/imgs/avatar.gif'
  53. import { useUserStore } from '@/store/modules/user'
  54. import { useTagsViewStore } from '@/store/modules/tagsView'
  55. import { useAppStore } from '@/store/modules/app'
  56. defineOptions({ name: 'Header' })
  57. const { t } = useI18n()
  58. const { wsCache } = useCache()
  59. const { push, replace } = useRouter()
  60. const userStore = useUserStore()
  61. const appStore = useAppStore()
  62. const tagsViewStore = useTagsViewStore()
  63. const { getPrefixCls } = useDesign()
  64. const prefixCls = getPrefixCls('user-info')
  65. const user = wsCache.get(CACHE_KEY.USER)
  66. const avatar = user.user.avatar ? user.user.avatar : avatarImg
  67. const userName = user.user.nickname ? user.user.nickname : 'Admin'
  68. const titleName = ref(appStore.title)
  69. const loginOut = () => {
  70. ElMessageBox.confirm(t('common.loginOutMessage'), t('common.reminder'), {
  71. confirmButtonText: t('common.ok'),
  72. cancelButtonText: t('common.cancel'),
  73. type: 'warning'
  74. })
  75. .then(async () => {
  76. await userStore.loginOut()
  77. tagsViewStore.delAllViews()
  78. replace('/login?redirect=/index')
  79. })
  80. .catch(() => {})
  81. }
  82. const toProfile = async () => {
  83. push('/user/profile')
  84. }
  85. const reactiveData: any = reactive({
  86. routes: []
  87. })
  88. const menuUlShow = ref(false) // 菜单列表是否显示,是首页就不显示
  89. const headerTitleName: any = ref('') // 标题名称
  90. const router = useRouter()
  91. const pathBossName = ref('')
  92. const initMenus = async () => {
  93. const uid = router.currentRoute.value
  94. let locals: any = localStorage.getItem('roleRouters')
  95. let roleRouters = JSON.parse(JSON.parse(locals).v)[0].children
  96. if (uid.path == '/oaSystem/home' || uid.path.indexOf('projectDetail') != -1) {
  97. menuUlShow.value = false
  98. reactiveData.routes = roleRouters
  99. } else {
  100. menuUlShow.value = true
  101. let childName = uid.name
  102. let childArr = roleRouters.slice(1, roleRouters.length)
  103. await childFun(childName, childArr)
  104. }
  105. }
  106. const childFun = async (name: any, arr: any) => {
  107. reactiveData.routes = []
  108. for (let i = 0; i < arr.length; i++) {
  109. if (arr[i].children != null && arr[i].children) {
  110. for (let j = 0; j < arr[i].children.length; j++) {
  111. if (arr[i].children[j].path == name) {
  112. pathBossName.value = arr[i].path
  113. headerTitleName.value = arr[i].name
  114. reactiveData.routes = arr[i].children
  115. }
  116. }
  117. } else {
  118. if (arr[i].path == name) {
  119. headerTitleName.value = arr[i].name
  120. }
  121. }
  122. }
  123. }
  124. watch(() => {
  125. initMenus()
  126. })
  127. /** 初始化 **/
  128. onMounted(() => {
  129. initMenus()
  130. })
  131. </script>
  132. <style lang="scss" scoped>
  133. .header {
  134. width: calc(100%);
  135. height: 112px;
  136. // background: #183868;
  137. display: flex;
  138. align-items: center;
  139. justify-content: space-between;
  140. box-sizing: border-box;
  141. .header-left {
  142. display: flex;
  143. align-items: center;
  144. img {
  145. width: 48px;
  146. height: 48px;
  147. margin-right: 15px;
  148. }
  149. p {
  150. font-size: 34px;
  151. color: #333f56;
  152. font-family: AlibabaPuHuiTiB;
  153. }
  154. }
  155. .header-right {
  156. display: flex;
  157. align-items: center;
  158. height: 100%;
  159. .menuUl {
  160. display: flex;
  161. align-items: center;
  162. height: 100%;
  163. margin: 0;
  164. border-right: 1px solid #45638e;
  165. li {
  166. width: 136px;
  167. list-style: none;
  168. height: 100%;
  169. a {
  170. width: 100%;
  171. height: 100%;
  172. display: block;
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. text-decoration: none;
  177. span {
  178. color: #fff;
  179. font-size: 16px;
  180. }
  181. }
  182. .router-link-active {
  183. background-color: #4e6e9e;
  184. }
  185. }
  186. }
  187. .header-user {
  188. margin-left: 25px;
  189. }
  190. }
  191. }
  192. .custom-hover {
  193. background-color: transparent;
  194. }
  195. </style>