<template>
<header class="header" :class="[!expandHeader && 'hidden']">
<div class="box"> <!--wrapper flex justify-between-->
<div class="left">
<h1 class="logo-wrap" :title="title">
<router-link to="/">
<img v-if="expandHeader" src="@/assets/logo.png" class="logo" :alt="title"/>
<img v-else src="@/assets/logo-icon.png" class="logo" :alt="title"/>
</router-link>
</h1>
<el-menu
:default-active="routerPath"
class="menu-wrap"
:collapse="!expandHeader"
@open="handleOpen"
@close="handleClose"
>
<el-menu-item v-for="(item, index) in menuData" :index="item.path" :key="index" @click="goPage(item)">
<SvgIcon v-if="item.iconName" :name="item.iconName" size="16"/>
<SvgRender v-if="item.icon" :url="item.icon" size="16"/>
<!-- <img :src="getPreview(item.icon)" />-->
<template #title>{{ item.name }}</template>
</el-menu-item>
</el-menu>
<div class="recently-list" v-if="expandHeader && recentlyList.length">
<h3>使用记录</h3>
<ul class="scrollbar">
<li v-for="(item, i) in recentlyList" :key="item.appId + i" @click="goDetail(item, '访问记录')">
<p :title="item.appName">
<el-image :src="getPreview(item.appIconUrl)" fit="cover" :size="24" lazy>
<template #error><div class="image-slot"><img :src="defaultAvatarUrl" /></div></template>
</el-image>
<strong class="single-line">{{item.appName}}</strong>
</p>
<el-dropdown>
<el-icon @click.stop=""><MoreFilled /></el-icon>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @mousedown.native="handleDelete(item)">删除</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</li>
</ul>
</div>
</div>
<div class="right flex">
<el-dropdown v-if="userInfo.email">
<div class="avatar" :title="userInfo.email">
<el-image :src="avatarUrl">
<template #error><img :src="defaultAvatarUrl" /></template>
</el-image>
<p v-if="expandHeader">{{userInfo.userName}}</p>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @mousedown.native="onLogout">
<el-icon class="arrow"><SwitchButton/></el-icon> 退出</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<el-button type="primary" class="add-btn" id="refTour3" @click="goPA"><el-icon color="#ffffff"><Plus/></el-icon><span v-if="expandHeader">创建应用</span></el-button>
</div>
</div>
<div class="action-arrow" @click="handleExpandHeader">
<img src="@/assets/icons/nav-arrow-left.png"/>
</div>
</header>
</template>
<script>
import {Search, Plus, CaretBottom, SwitchButton, MoreFilled} from '@element-plus/icons-vue'
import SvgRender from '@/components/SvgRender'
import {getUserInfo, sendData} from '@/utils/api'
import {logoutSSO} from '@/utils/auth'
import {goPA, isUrl} from '@/utils'
import { mapState, mapActions } from 'pinia'
import { useStore } from '@/stores'
import ubs from '@/utils/ubs'
import localStore from 'store'
export default {
name: 'AppHeader',
components: {Search, Plus, CaretBottom, SwitchButton, MoreFilled, SvgRender},
data() {
return {
title:'AI应用集市',
searchVal: '',
menuActive: '1',
menuData: [
{name: '首页', path: '/', iconName: 'nav-home'},
{name: '优秀案例', path: '/case', iconName: 'nav-case'},
{name: '创新大赛', path: '/contest', iconName: 'nav-contest'},
{name: '社区讨论', url: 'http://wk-bbs-web-test6-8080.msxf.msxfyun.test/', iconName: 'nav-bbs'},
{name: '学习资料', url: 'http://wk-bbs-web-test6-8080.msxf.msxfyun.test/', iconName: 'nav-study'},
]
}
},
computed: {
...mapState(useStore, ['getPreview','userInfo', 'avatarUrl', 'defaultAvatarUrl', 'params', 'expandHeader', 'recentlyList']),
showInput() {
return this.params.searchKW || this.$route.path.includes('/search')
},
showSearch() {
return this.$route.name === 'home'
},
routerPath() {
console.log('routerPath---:',this.$route.path)
return this.$route.path
},
},
created() {
let winWidth = document.documentElement.clientWidth
if(!this.userInfo?.email) {
getUserInfo((userInfo) => {
if(winWidth < 1288) { // 小屏自动收起
let openTourData = localStore.get('openTourData')
let email = userInfo.email
console.log('email---:', email, openTourData)
// 功能指引-已显示-自动收起
if(openTourData && openTourData[email]){
this.setExpandHeader(false)
}
}
ubs.initUbs(userInfo, () => {
console.log('ubs---初始完成')
this.$bus.emit('initUBS')
})
})
}
this.getMenuData()
this.getUserAvatarUrl()
this.getRecentlyUsed()
},
methods: {
...mapActions(useStore, ['getUserAvatarUrl', 'setExpandHeader','getPreview', 'getRecentlyUsed']),
goPA(){
ubs.ubsData({module: '创建应用区域', $element_name: '创建应用'})
goPA()
},
goPage(item) {
// 处理外部链接
console.log('item----:', item, this.routerPath)
const { url, isIframe } = item
if (isUrl(item.path)) {
return window.open(item.path)
}
item.path && this.$router.push(item.path)
},
handleOpen(key, keyPath) {
console.log(key, keyPath)
},
handleClose() {},
getMenuData(item){
this.$request({url: `/frontend/appManage/listFrontMenu`, method: 'GET'}).then(res => {
if(res.code === '1') {
this.menuData = res.data
}
})
},
handleDelete(item){
this.$request({url: `/frontend/appManage/deleteRecentlyUsed/${item.appId}`, method: 'POST'}).then(res => {
if(res.code === '1') {
this.$message.success('删除成功!')
this.getRecentlyUsed()
}
})
},
handleExpandHeader(){
this.setExpandHeader(!this.expandHeader)
},
goDetail(item, module) {
sendData('app_click', item.appId)
ubs.ubsData({module, $element_name: item.appName})
if(location.pathname.includes('/application/')){
this.$router.replace({path: `/application/${item.appId}`})
} else {
this.$router.push({path: `/application/${item.appId}`})
}
},
onLogout() {
logoutSSO()
},
handleOver() {
this.$nextTick(() => {
this.$refs.searchInput && this.$refs.searchInput.focus()
})
},
handleSearch() {
this.$bus.emit('search', this.params.searchKW)
this.$nextTick(() => {
this.$refs.searchInput && this.$refs.searchInput.focus()
})
}
},
}
</script>
<style scoped lang="scss">
@use "@/styles/header";
</style>
这里menu点击菜单的一个外部链接,不需要此时菜单时激活状态,怎么修改