You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
5.3 KiB
Vue

1 month ago
<template>
1 month ago
<div class="layout">
1 month ago
<!-- 固定导航栏 -->
1 month ago
<nav class="navbar">
1 month ago
<div class="logo">
<img src="~/assets/img/KEP001.svg" class="logo-img" />
<span class="log-text">KE Platform</span>
</div>
<ul class="nav-links" ref="el">
<li v-for="item in navItems" :key="item.path">
<NuxtLink :to="item.path" :class="{ active: activeTab === item.path }">
{{ item.name }}
</NuxtLink>
</li>
</ul>
1 month ago
1 month ago
<!-- <div class="user-info">{{ user }}</div> -->
<div class="div-area">
当前工区<el-select v-model="selectedAreaData" placeholder="请选择" class="workArea">
<el-option v-for="item in areaData" :key="item.AreaID" :label="item.AreaName" :value="item.AreaID" />
</el-select>
&nbsp;
当前用户
<el-dropdown @command="handleUser">
<el-button link style="font-size: 20px;" :type="userBtnType">{{ userName }}
<i class="el-icon-arrow-down el-icon--right"></i>
</el-button>
<template v-slot:dropdown>
<el-dropdown-menu>
<el-dropdown-item command="logout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
1 month ago
</nav>
1 month ago
<!-- 内容区域 - 会根据当前路由自动变化 -->
1 month ago
<div class="content">
1 month ago
<slot />
1 month ago
</div>
</div>
1 month ago
</template>
<script setup>
1 month ago
import { useAuthStore } from "~/stores/user";
1 month ago
import { ref, onMounted, onBeforeUnmount } from "vue";
import { useRoute } from "vue-router";
import { getWorkArea, setWorkArea } from "~/services/workAreaService";
import { useCurrentTabStore } from "~/stores/currentTabStore";
import { emitter } from "~/utils/eventBus";
const authStore = useAuthStore();
// authStore.initializeAuth();
const useTabStore = useCurrentTabStore();
const route = useRoute();
const activeTab = ref("/");
const areaData = ref(null);
const selectedAreaData = ref('');
const userName = ref('未登录');
const userBtnType = computed(() => { userName.value === '未登录' ? 'success' : 'danger' });
const navItems = ref([
{ name: "工区管理", path: "/" },
{ name: "数据管理", path: "/dataManage" },
{ name: "井位智能推荐", path: "/smartWellRecommend" },
{ name: "参数图形绘制", path: "/drawParamGdi" },
{ name: "井段数据分析", path: "/wellDataAnalysis" },
{ name: "水平井", path: "/horizontalWell" },
{ name: "微地震云图", path: "/microEarthQuake" },
1 month ago
1 month ago
]);
// 监听路由变化更新激活状态
watchEffect(() => {
activeTab.value = route.path;
useTabStore.changeTab(route.path);
1 month ago
console.log("当前路径:", route.path);
1 month ago
});
const handleUser = ((val) => {
switch (val) {
case 'logout':
authStore.logout();
navigateTo('/login');
break;
}
});
watch(selectedAreaData, async (newVal) => {
if (newVal) {
await setData();
}
}, { immediate: true });
onMounted(() => {
1 month ago
emitter.on('addWorkArea', () => {
1 month ago
getData();
});
getData();
1 month ago
const userStr = localStorage.getItem("userInfo");
const user = userStr ? JSON.parse(userStr) : null;
console.log("当前用户信息", user);
if (user) {
userName.value = user.UserName;
}
1 month ago
});
onBeforeUnmount(() => {
1 month ago
emitter.off('addWorkArea');
1 month ago
})
const getData = async () => {
const response = await getWorkArea();
1 month ago
console.log(response);
1 month ago
if (response.Count > 0) {
areaData.value = response.Data;
1 month ago
const savedAreaData = localStorage.getItem('workarea');
1 month ago
if (savedAreaData) {
selectedAreaData.value = savedAreaData;
} else {
selectedAreaData.value = areaData.value[0].AreaID;
await setData();
}
}
};
const setData = async () => {
1 month ago
if (!selectedAreaData) {
1 month ago
return;
}
const response = await setWorkArea(selectedAreaData.value);
1 month ago
console.log("设置工区", response);
1 month ago
if (response.Code === 1) {
1 month ago
localStorage.setItem("workarea", selectedAreaData.value);
1 month ago
}
}
</script>
<style scoped>
.layout {
1 month ago
height: 100vh;
1 month ago
min-height: 700px;
min-width: 1366px;
width: 100%;
margin: 0;
padding: 0;
1 month ago
display: flex;
flex-direction: column;
1 month ago
}
.navbar {
1 month ago
position: fixed;
top: 0;
left: 0;
1 month ago
width: 100%;
min-width: 1366px;
display: flex;
align-items: center;
1 month ago
padding: 1rem;
1 month ago
background: #ffffff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
z-index: 1000;
1 month ago
min-height: 60px;
1 month ago
/* 设置最小高度防止内容过小时高度塌陷 */
1 month ago
height: 60px;
1 month ago
/* justify-content: space-around; */
}
.logo {
font-weight: bold;
1 month ago
margin-right: 1rem;
1 month ago
display: flex;
justify-content: center;
flex-direction: column;
}
.logo-img {
width: 80px;
height: 30px;
}
.log-text {
font-size: 13px;
}
.nav-links {
display: flex;
list-style: none;
1 month ago
gap: 1.5rem;
1 month ago
}
.nav-links a {
text-decoration: none;
color: #333;
padding: 0.5rem;
transition: color 0.3s;
}
.nav-links a:hover {
color: #42b983;
}
.nav-links a.active {
color: #42b983;
border-bottom: 2px solid #42b983;
font-weight: bold;
}
.user-info {
flex-grow: 1;
justify-content: flex-end;
}
.content {
1 month ago
margin-top: 65px;
/* 导航栏高度 + 额外间距 */
/* padding-top: 20px; */
flex-grow: 1;
overflow: hidden;
1 month ago
height: 100%;
width: 100%;
}
.div-area {
justify-content: flex-end;
margin-left: auto;
1 month ago
margin-right: 50px;
1 month ago
}
.workArea {
width: 100px;
z-index: 1001;
margin-right: 10px;
}
</style>