123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <template>
- <div class="header">
- <div class="header-left">
- <img src="@/assets/imgs/OA/zdww.png" alt="" />
- <p
- >{{ titleName }}
- <!-- <span v-if="menuUlShow">|</span> {{ headerTitleName }} -->
- </p>
- </div>
- <!-- <div class="header-right">
- <ul class="menuUl" v-if="menuUlShow">
- <li v-for="(item, index) in reactiveData.routes" :key="index" v-show="item.alwaysShow">
- <router-link :to="'/oaSystem/' + pathBossName + '/' + item.path">
- <span>{{ item.name }}</span>
- </router-link>
- </li>
- </ul>
- <div class="header-user">
- <ElDropdown class="custom-hover" :class="prefixCls" trigger="click">
- <div class="flex items-center">
- <ElAvatar
- :src="avatar"
- alt=""
- class="w-[calc(var(--logo-height)-25px)] rounded-[50%]"
- />
- <span class="pl-[5px] c-white ml-5px text-14px <lg:hidden">
- {{ userName }}
- </span>
- </div>
- <template #dropdown>
- <ElDropdownMenu>
- <ElDropdownItem>
- <Icon icon="ep:tools" />
- <div @click="toProfile">{{ t('common.profile') }}</div>
- </ElDropdownItem>
- <ElDropdownItem divided @click="loginOut">
- <Icon icon="ep:switch-button" />
- <div>{{ t('common.loginOut') }}</div>
- </ElDropdownItem>
- </ElDropdownMenu>
- </template>
- </ElDropdown>
- </div>
- </div> -->
- </div>
- </template>
- <script setup lang="ts">
- import { useRouter } from 'vue-router'
- import { ElMessageBox } from 'element-plus'
- import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
- import { useDesign } from '@/hooks/web/useDesign'
- import avatarImg from '@/assets/imgs/avatar.gif'
- import { useUserStore } from '@/store/modules/user'
- import { useTagsViewStore } from '@/store/modules/tagsView'
- import { useAppStore } from '@/store/modules/app'
- defineOptions({ name: 'Header' })
- const { t } = useI18n()
- const { wsCache } = useCache()
- const { push, replace } = useRouter()
- const userStore = useUserStore()
- const appStore = useAppStore()
- const tagsViewStore = useTagsViewStore()
- const { getPrefixCls } = useDesign()
- const prefixCls = getPrefixCls('user-info')
- const user = wsCache.get(CACHE_KEY.USER)
- const avatar = user.user.avatar ? user.user.avatar : avatarImg
- const userName = user.user.nickname ? user.user.nickname : 'Admin'
- const titleName = ref(appStore.title)
- const loginOut = () => {
- ElMessageBox.confirm(t('common.loginOutMessage'), t('common.reminder'), {
- confirmButtonText: t('common.ok'),
- cancelButtonText: t('common.cancel'),
- type: 'warning'
- })
- .then(async () => {
- await userStore.loginOut()
- tagsViewStore.delAllViews()
- replace('/login?redirect=/index')
- })
- .catch(() => {})
- }
- const toProfile = async () => {
- push('/user/profile')
- }
- const reactiveData: any = reactive({
- routes: []
- })
- const menuUlShow = ref(false) // 菜单列表是否显示,是首页就不显示
- const headerTitleName: any = ref('') // 标题名称
- const router = useRouter()
- const pathBossName = ref('')
- const initMenus = async () => {
- const uid = router.currentRoute.value
- let locals: any = localStorage.getItem('roleRouters')
- let roleRouters = JSON.parse(JSON.parse(locals).v)[0].children
- if (uid.path == '/oaSystem/home' || uid.path.indexOf('projectDetail') != -1) {
- menuUlShow.value = false
- reactiveData.routes = roleRouters
- } else {
- menuUlShow.value = true
- let childName = uid.name
- let childArr = roleRouters.slice(1, roleRouters.length)
- await childFun(childName, childArr)
- }
- }
- const childFun = async (name: any, arr: any) => {
- reactiveData.routes = []
- for (let i = 0; i < arr.length; i++) {
- if (arr[i].children != null && arr[i].children) {
- for (let j = 0; j < arr[i].children.length; j++) {
- if (arr[i].children[j].path == name) {
- pathBossName.value = arr[i].path
- headerTitleName.value = arr[i].name
- reactiveData.routes = arr[i].children
- }
- }
- } else {
- if (arr[i].path == name) {
- headerTitleName.value = arr[i].name
- }
- }
- }
- }
- watch(() => {
- initMenus()
- })
- /** 初始化 **/
- onMounted(() => {
- initMenus()
- })
- </script>
- <style lang="scss" scoped>
- .header {
- width: calc(100%);
- height: 112px;
- // background: #183868;
- display: flex;
- align-items: center;
- justify-content: space-between;
- box-sizing: border-box;
- .header-left {
- display: flex;
- align-items: center;
- img {
- width: 48px;
- height: 48px;
- margin-right: 15px;
- }
- p {
- font-size: 34px;
- color: #333f56;
- font-family: AlibabaPuHuiTiB;
- }
- }
- .header-right {
- display: flex;
- align-items: center;
- height: 100%;
- .menuUl {
- display: flex;
- align-items: center;
- height: 100%;
- margin: 0;
- border-right: 1px solid #45638e;
- li {
- width: 136px;
- list-style: none;
- height: 100%;
- a {
- width: 100%;
- height: 100%;
- display: block;
- display: flex;
- align-items: center;
- justify-content: center;
- text-decoration: none;
- span {
- color: #fff;
- font-size: 16px;
- }
- }
- .router-link-active {
- background-color: #4e6e9e;
- }
- }
- }
- .header-user {
- margin-left: 25px;
- }
- }
- }
- .custom-hover {
- background-color: transparent;
- }
- </style>
|