tanghaolin
2025-03-06 2fdfc7907920e9003c62445b6000dc3c9edd6edb
src/components/AppHeader.vue
@@ -13,26 +13,32 @@
            <!-- Navigation Menu -->
            <nav class="flex ml-8">
               <el-menu mode="horizontal" :ellipsis="false" class="border-none" router :default-active="activeRoute">
                  <el-menu-item index="/" class="!px-4">首页</el-menu-item>
                  <el-menu-item index="/certified-products" class="!px-4">认证产品</el-menu-item>
                  <el-menu-item index="/home" class="!px-4">首页</el-menu-item>
                  <el-menu-item index="/certified-products" class="!px-4">能效产品</el-menu-item>
                  <el-menu-item index="/eec-label-search" class="!px-4">证书查询</el-menu-item>
                  <el-menu-item index="/news-detail/99" class="!px-4">补贴政策</el-menu-item>
                  <el-menu-item class="!px-4" @click="linkClick('http://xpump.net/#/Index')">查泵网</el-menu-item>
                  <el-menu-item index="/select-selpara" class="!px-4" @click="linkClick">查泵网</el-menu-item>
               </el-menu>
            </nav>
            <!-- Search and User Actions -->
            <div class="flex items-center space-x-8 ml-[65px]">
               <el-input v-model="searchQuery" placeholder="找工业/找大数据" class="w-48">
               <el-input v-model="searchQuery" placeholder="查证书" class="w-48">
                  <template #suffix>
                     <el-icon><Search /></el-icon>
                     <el-icon class="cursor-pointer" @click="handleSearch"><Search /></el-icon>
                  </template>
               </el-input>
               <div class="flex items-center text-gray-600 text-sm text-nowrap">
                  <a href="#" class="hover:text-blue-500">注册</a>
                  <span class="mx-2">·</span>
                  <a href="#" class="hover:text-blue-500">登录</a>
                  <template v-if="!userInfo">
                     <a href="#" class="hover:text-blue-500">注册</a>
                     <span class="mx-2">·</span>
                     <a @click="toLogin" class="hover:text-blue-500">登录</a>
                  </template>
                  <template v-else>
                     <span class="text-blue-500 mr-2">{{ userInfo.RealName }}</span>
                     <a href="#" class="hover:text-blue-500" @click.prevent="handleLogout">退出</a>
                  </template>
               </div>
            </div>
         </div>
@@ -41,16 +47,52 @@
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
import { Search } from '@element-plus/icons-vue';
import headerLogo from '@/assets/logo/header_logo.png';
const route = useRoute();
const searchQuery = ref('');
import { Search } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
import { computed, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useLogin } from '@/stores/useLogin';
const loginStore = useLogin();
const route = useRoute();
const router = useRouter();
const searchQuery = ref('');
const handleSearch = () => {
   if (!searchQuery.value) {
      searchQuery.value = '查证书';
   }
   router.push(`/eec-label-search`);
};
const activeRoute = computed(() => route.path);
const linkClick = (url) => {
   window.open(url, '_blank');
// 获取用户信息
const userInfo = computed(() => {
   const UserInfo = loginStore.getUserInfo();
   return UserInfo ? UserInfo : null;
});
const toLogin = () => {
   router.replace({
      path: '/login',
      query: {
         redirectPath: route.fullPath,
      },
   });
};
// 处理登出
const handleLogout = () => {
   loginStore.logOut();
   ElMessage.success('已退出登录');
   router.replace({
      path: '/login',
      query: { redirectPath: route.fullPath },
   });
};
const linkClick = () => {
   router.push('/select-selpara');
};
</script>