ly-front/src/views/contentData/headerTop/index.vue

363 lines
9.6 KiB
Vue
Raw Normal View History

2025-03-31 15:26:29 +00:00
<template>
<div class="header">
<div class="header-left">
2025-05-19 07:07:43 +00:00
<div class="header-logo"></div>
2025-03-31 15:26:29 +00:00
</div>
<div class="header-main">
<div class="textTile">
<img src="@/assets/img/title.svg" alt="" />
</div>
</div>
<div class="header-menu">
2025-04-02 14:51:32 +00:00
<div class="menuItem" v-if="isAdmins">
2025-03-31 15:26:29 +00:00
<div
class="menuFor"
v-for="(item, index) in menuList"
:key="index"
@click="handleMenuClick(item)"
>
<div class="itemIcon">
2025-04-05 10:58:49 +00:00
<el-tooltip
class="item"
effect="dark"
:content="item.name"
placement="bottom"
>
<img
:src="activeId === item.id ? item.iconActive : item.icon"
:alt="item.name"
/>
</el-tooltip>
2025-03-31 15:26:29 +00:00
</div>
</div>
</div>
<div class="menuItemQuanping">
<div
class="menuFor"
v-for="(item, index) in quanping"
:key="index"
2025-04-02 14:54:13 +00:00
@click="handlefdClick(item)"
2025-03-31 15:26:29 +00:00
>
<div class="itemIcon">
2025-04-05 10:58:49 +00:00
<el-tooltip
class="item"
effect="dark"
:content="item.name"
placement="bottom"
>
<img :src="item.icon" :alt="item.name" />
</el-tooltip>
2025-03-31 15:26:29 +00:00
</div>
</div>
</div>
<div class="user">
<el-dropdown trigger="click">
<img :size="30" src="@/assets/img/menu/iconUser.png" />
<el-dropdown-menu slot="dropdown">
2025-08-20 14:13:54 +00:00
<el-dropdown-item>{{ userName }}</el-dropdown-item>
2025-03-31 15:26:29 +00:00
<el-dropdown-item @click.native="passClick">
修改密码
</el-dropdown-item>
<el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<div class="time">
<div class="top">
<div class="time_date">{{ currentTime }}</div>
<div class="weather">
<img src="@/assets/img/menu/tianqi.png" alt="" />
<div class="weather_text">
{{ homeView.weather?.now.temperature + "°C" }}
</div>
</div>
</div>
<div class="date">{{ currentDate }}</div>
</div>
</div>
<el-dialog
:title="title"
:visible.sync="showDialog"
:before-close="handleClose"
append-to-body
>
<!-- 对话框组件 -->
<component :is="currentDialog"></component>
</el-dialog>
<el-dialog
:title="titleDialog"
:visible.sync="dialog"
:before-close="handleClose"
append-to-body
class="el-dialog-center"
>
<my-form
:formNewList="formDrawerList"
:fromItem="fromItem"
dialogImageUrl
@determine="determine"
@handleClose="handleClose"
labelWidth="120px"
>
</my-form>
</el-dialog>
</div>
</template>
<script>
// 导入各个对话框组件
import PermissionDialog from "../../menuData/PermissionDialog.vue"; // ID: 1
import DeviceDialog from "../../menuData/DeviceDialog.vue"; // ID: 2
import LogDialog from "../../menuData/LogDialog.vue"; // ID: 3
import AlertDialog from "../../menuData/AlertDialog.vue"; // ID: 5
import PositionDialog from "../../menuData/PositionDialog.vue"; // ID: 6
import AnalysisDialog from "../../menuData/AnalysisDialog.vue"; // ID: 7
2025-04-12 15:15:32 +00:00
import WhitListDialog from "../../menuData/WhitListDialog.vue"; // ID: 8
2025-03-31 15:26:29 +00:00
import { userUpdatepwd } from "@/api/user.js";
export default {
name: "header-top",
components: {
PermissionDialog,
DeviceDialog,
LogDialog,
AlertDialog,
PositionDialog,
2025-04-12 15:15:32 +00:00
AnalysisDialog,
WhitListDialog
2025-03-31 15:26:29 +00:00
},
props: {
homeData: {
type: Object,
default: () => ({})
}
},
data() {
return {
menuList: [
{
id: 1,
name: "人员",
icon: require("@/assets/img/menu/xitongquanxian.png"),
iconActive: require("@/assets/img/menu/xitongquanxian-hove.png")
},
{
id: 2,
name: "设备",
icon: require("@/assets/img/menu/shebei.png"),
iconActive: require("@/assets/img/menu/shebei-hove.png")
},
{
id: 3,
name: "日志",
icon: require("@/assets/img/menu/rizhi.png"),
iconActive: require("@/assets/img/menu/rizhi-hove.png")
},
{
id: 4,
name: "首页",
icon: require("@/assets/img/menu/tongji.png"),
iconActive: require("@/assets/img/menu/tongji-hove.png")
},
{
id: 5,
name: "预警",
icon: require("@/assets/img/menu/yujing.png"),
iconActive: require("@/assets/img/menu/yujing-hove.png")
},
{
id: 6,
2025-04-01 16:12:21 +00:00
name: "防区",
2025-03-31 15:26:29 +00:00
icon: require("@/assets/img/menu/zhendi.png"),
iconActive: require("@/assets/img/menu/zhendi-hove.png")
},
{
id: 7,
name: "统计分析",
2025-03-31 15:58:22 +00:00
icon: require("@/assets/img/menu/tjfx.png"),
iconActive: require("@/assets/img/menu/tjfx-hove.png")
2025-04-12 15:15:32 +00:00
},
{
id: 8,
name: "白名单",
2025-04-13 08:23:44 +00:00
icon: require("@/assets/img/menu/bmd.png"),
iconActive: require("@/assets/img/menu/bmd-hove.png")
2025-03-31 15:26:29 +00:00
}
],
quanping: [
{
id: 8,
name: "全屏",
icon: require("@/assets/img/menu/quanping.png"),
iconActive: require("@/assets/img/menu/quanping.png")
}
],
activeId: 4,
currentTime: "",
currentDate: "",
currentDialog: "",
showDialog: false,
title: "",
titleDialog: "",
homeView: {
weather: {
now: {
temperature: 0
}
}
},
formDrawerList: [
{
label: "原密码",
type: "input",
model: "oldPwd",
rules: [{ required: true, message: "请输入原密码" }],
showPassword: true
},
{
label: "新密码",
type: "input",
model: "newPwd",
rules: [{ required: true, message: "请输入新密码" }],
showPassword: true
}
],
fromItem: {},
2025-04-02 14:38:27 +00:00
dialog: false,
2025-08-20 14:13:54 +00:00
isAdmins: false,
userName: ""
2025-03-31 15:26:29 +00:00
};
},
2025-04-02 14:51:32 +00:00
created() {},
2025-03-31 15:26:29 +00:00
watch: {
homeData: {
handler(newVal) {
this.homeView = newVal;
},
deep: true
}
},
mounted() {
2025-04-02 14:51:32 +00:00
this.isAdmins = JSON.parse(localStorage.getItem("isAdmin"));
2025-03-31 15:26:29 +00:00
this.updateTime();
setInterval(this.updateTime, 1000); // 每秒更新一次时间
2025-08-20 14:13:54 +00:00
this.userName = localStorage.getItem("userName");
2025-03-31 15:26:29 +00:00
},
methods: {
updateTime() {
const now = new Date();
this.currentTime = now.toLocaleTimeString(); // 获取当前时间,格式为本地时间格式
this.currentDate = now.toLocaleDateString(); // 获取当前日期,格式为本地日期格式
},
passClick() {
this.fromItem = {};
this.titleDialog = "修改密码";
// 修改密码的逻辑
this.dialog = true;
console.log("修改密码");
},
logout() {
// 退出登录的逻辑
localStorage.removeItem("setToken");
localStorage.removeItem("userId");
localStorage.removeItem("userName");
localStorage.removeItem("isAdmin");
this.$router.push("/login");
},
// 确定按钮
determine(value) {
let params = {};
params = value;
params.id = localStorage.getItem("userId");
userUpdatepwd(params).then((res) => {
if (res.code === 0) {
this.$message.success("修改成功");
}
});
this.dialog = false;
},
2025-04-02 14:54:13 +00:00
handlefdClick(value) {
if (document.fullscreenElement) {
document
.exitFullscreen()
.then(() => {
console.log("退出全屏模式");
})
.catch((err) => {
console.error(`退出全屏模式失败: ${err.message}`);
});
} else {
document.documentElement
.requestFullscreen()
.then(() => {
console.log("进入全屏模式");
})
.catch((err) => {
console.error(`进入全屏模式失败: ${err.message}`);
});
}
},
2025-03-31 15:26:29 +00:00
handleMenuClick(value) {
this.activeId = value.id; // 点击时更新激活的ID
this.title = value.name; // 点击时更新对话框标题
// 根据ID决定显示哪个对话框
switch (value.id) {
case 1:
this.currentDialog = "PermissionDialog";
this.showDialog = true;
break;
case 2:
this.currentDialog = "DeviceDialog";
this.showDialog = true;
break;
case 3:
this.currentDialog = "LogDialog";
this.showDialog = true;
break;
2025-04-12 15:15:32 +00:00
case 4:
this.showDialog = false;
break;
2025-03-31 15:26:29 +00:00
case 5:
this.currentDialog = "AlertDialog";
this.showDialog = true;
break;
case 6:
this.currentDialog = "PositionDialog";
this.showDialog = true;
break;
case 7:
this.currentDialog = "AnalysisDialog";
this.showDialog = true;
break;
case 8:
2025-04-12 15:15:32 +00:00
this.currentDialog = "WhitListDialog";
this.showDialog = true;
2025-03-31 15:26:29 +00:00
break;
}
},
handleClose() {
// 关闭对话框时清空激活的ID
this.activeId = 4;
this.showDialog = false;
this.dialog = false;
}
}
};
</script>
<style scoped>
.logo {
font-size: 20px;
font-weight: bold;
}
.time {
font-size: 14px;
}
.actions span {
margin-left: 10px;
cursor: pointer;
}
</style>