From 0e33a0b64f2f65ff7344e1bd940504d07ba64d89 Mon Sep 17 00:00:00 2001
From: huliang <1539398430@qq.com>
Date: Thu, 13 Nov 2025 17:23:47 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B7=A1=E6=AA=A2=E4=BB=BB?=
=?UTF-8?q?=E5=8B=99=E8=88=87=E5=B7=A1=E6=AA=A2=E8=A8=AD=E5=AE=9A=E5=88=9D?=
=?UTF-8?q?=E9=A0=81=E9=9D=A2=EF=BC=8C=E8=AA=BF=E6=95=B4=E5=81=B4=E9=82=8A?=
=?UTF-8?q?=E6=AC=84=E8=88=87=E9=BA=B5=E5=8C=85=E5=B1=91=E7=B5=84=E4=BB=B6?=
=?UTF-8?q?=E7=9A=84=E8=B7=AF=E7=94=B1=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/Common/Breadcrumb.vue | 103 ++++++---------------------
src/components/Sidebar.vue | 21 +++---
src/constants/menuConfig.js | 35 ++-------
src/router/index.js | 53 ++++++--------
src/views/PatrolMission.vue | 9 +++
src/views/PatrolSetting.vue | 30 ++++++++
6 files changed, 94 insertions(+), 157 deletions(-)
create mode 100644 src/views/PatrolMission.vue
create mode 100644 src/views/PatrolSetting.vue
diff --git a/src/components/Common/Breadcrumb.vue b/src/components/Common/Breadcrumb.vue
index aed7848..8ce3339 100644
--- a/src/components/Common/Breadcrumb.vue
+++ b/src/components/Common/Breadcrumb.vue
@@ -8,17 +8,10 @@
- {{
- item.title || item.name
- }}
- {{ item.title || item.name }}
+ {{ item.title }}
@@ -28,84 +21,30 @@ import { computed } from "vue";
import { useRoute } from "vue-router";
import { menuConfig } from "../../constants/menuConfig.js";
-// 更簡潔的選單查找與麵包屑組裝
-function findMenuItem(route) {
- for (const menu of menuConfig) {
- for (const child of menu.children) {
- // 靜態路由、名稱
- if (child.routeName === route.name || child.path === route.path) {
- return { parent: menu, item: child };
- }
- // 動態路由(如 /plant/:id)
- if (
- child.routeName === "PlantInfo" &&
- route.path &&
- route.path.startsWith("/plant/")
- ) {
- return { parent: menu, item: child };
+const route = useRoute();
+
+function findBreadcrumbs(menu, route, path = []) {
+ for (const item of menu) {
+ const currentPath = [...path, { title: item.title, name: item.routeName || null }];
+ if (item.routeName === route.name) {
+ if (item.params) {
+ const paramsMatch = Object.keys(item.params).every(key => item.params[key] == route.params[key]);
+ if (paramsMatch) {
+ return currentPath;
+ }
+ } else {
+ return currentPath;
}
}
+ if (item.children) {
+ const result = findBreadcrumbs(item.children, route, currentPath);
+ if (result) return result;
+ }
}
return null;
}
-function buildBreadcrumb(route) {
- const match = findMenuItem(route);
- if (!match) return [];
- const crumbs = [
- {
- name: match.parent.title,
- title: match.parent.title,
- path: null,
- meta: { title: match.parent.title },
- },
- ];
- let itemTitle = match.item.title;
- if (route.name === "PlantInfo" && route.params.id) {
- const plantNames = {
- "1": "四磺子坪",
- "2": "宜蘭大清水",
- "3": "宜蘭小清水",
- };
- itemTitle = plantNames[route.params.id] || match.item.title;
- }
- crumbs.push({
- name: itemTitle,
- title: itemTitle,
- path: match.item.path,
- meta: { title: itemTitle },
- });
- return crumbs;
-}
-
-const route = useRoute();
-
const breadcrumbs = computed(() => {
- const menuBreadcrumbs = buildBreadcrumb(route);
- if (menuBreadcrumbs.length > 0) {
- return menuBreadcrumbs;
- }
- const matchedRoutes = route.matched.filter((r) => r.meta && r.meta.title);
- if (matchedRoutes.length === 0) {
- return [];
- }
- const currentRoute = matchedRoutes[matchedRoutes.length - 1];
- if (currentRoute.meta.parentTitle) {
- return [
- {
- title: currentRoute.meta.parentTitle,
- path: null,
- },
- {
- title: currentRoute.meta.title,
- path: currentRoute.path,
- },
- ];
- }
- return matchedRoutes.map((r) => ({
- title: r.meta.title,
- name: r.name,
- path: r.path,
- }));
+ return findBreadcrumbs(menuConfig, route) || [];
});
diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue
index 94db2c8..fb1c03c 100644
--- a/src/components/Sidebar.vue
+++ b/src/components/Sidebar.vue
@@ -16,7 +16,7 @@
結元能源
-
+
@@ -26,8 +26,8 @@
{{ item.title }}
@@ -73,12 +73,9 @@ const getIconComponent = (iconName) => {
// 處理選單點擊
const handleMenuClick = (item) => {
- if (item.path) {
- if (item.routeName && item.params) {
- router.push({ name: item.routeName, params: item.params });
- } else {
- router.push(item.path);
- }
+ if (item.routeName) {
+ router.push({ name: item.routeName, params: item.params || {} });
+ return;
}
};
@@ -87,12 +84,12 @@ const activeMenuIndex = computed(() => {
// 嘗試根據當前路由匹配選單項
for (const menu of menuConfig) {
for (const item of menu.children) {
- if (item.routeName === route.name || item.path === route.path) {
- return item.path || item.id;
+ if (item.routeName === route.name) {
+ return item.title;
}
}
}
- return route.name || route.path;
+ return '';
});
diff --git a/src/constants/menuConfig.js b/src/constants/menuConfig.js
index 23ace5c..2d31046 100644
--- a/src/constants/menuConfig.js
+++ b/src/constants/menuConfig.js
@@ -1,129 +1,102 @@
export const menuConfig = [
{
- id: 'overview',
title: '總覽',
icon: 'Location',
children: [
{
- id: 'PlantsMap',
title: '地圖總覽',
- path: '/plantsMap',
routeName: 'PlantsMap'
},
{
- id: 'PlantsOverview',
title: '電廠總覽',
- path: '/plants',
routeName: 'PlantsOverview'
}
]
},
{
- id: 'factory-info',
title: '電廠資訊',
icon: 'Postcard',
children: [
{
- id: 'plant-1',
title: '四磺子坪',
- path: '/plant/1',
routeName: 'PlantInfo',
params: { id: 1 }
},
{
- id: 'plant-2',
title: '宜蘭大清水',
- path: '/plant/2',
routeName: 'PlantInfo',
params: { id: 2 }
},
{
- id: 'plant-3',
title: '宜蘭小清水',
- path: '/plant/3',
routeName: 'PlantInfo',
params: { id: 3 }
}
]
},
{
- id: 'inspection',
title: '巡檢系統',
icon: 'DocumentChecked',
children: [
{
- id: 'inspection-task',
- title: '巡檢任務'
+ title: '巡檢任務',
+ routeName: 'PatrolMission',
},
{
- id: 'inspection-setting',
- title: '巡檢設定'
+ title: '巡檢設定',
+ routeName: 'PatrolSetting',
}
]
},
{
- id: 'report',
title: '報表查詢',
icon: 'DataLine',
children: [
{
- id: 'PlantsReport',
title: '電廠報表',
- path: '/plantsReport',
routeName: 'PlantsReport'
}
]
},
{
- id: 'alert',
title: '即時告警',
icon: 'Bell',
children: [
{
- id: 'alert-event',
title: '異常事件查詢'
}
]
},
{
- id: 'material',
title: '備料管理',
icon: 'MessageBox',
children: [
{
- id: 'material-item',
title: '備品料件管理'
},
{
- id: 'material-location',
title: '倉庫櫃位管理'
}
]
},
{
- id: 'security',
title: '智慧安防',
icon: 'VideoCamera',
children: [
{
- id: 'security-system',
title: '安防系統'
}
]
},
{
- id: 'system',
title: '系統設定',
icon: 'Setting',
children: [
{
- id: 'system-factory',
title: '電廠設定',
- path: '/plantSetting',
routeName: 'PlantSetting'
},
{
- id: 'system-account',
title: '帳號設定'
}
]
diff --git a/src/router/index.js b/src/router/index.js
index 64dcf0f..b5c8e84 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,62 +1,51 @@
import { createRouter, createWebHashHistory } from "vue-router";
import Home from "../views/Home.vue";
import PlantsOverview from "../views/PlantsOverview.vue";
+import PatrolMission from "../views/PatrolMission.vue";
+import PatrolSetting from "../views/PatrolSetting.vue";
import PlantReport from "../views/PlantReport.vue";
import PlantInfo from "../views/PlantInfo.vue";
import PlantSetting from "../views/PlantSetting.vue";
const routes = [
+ {
+ path: "/",
+ redirect: "/plantsMap"
+ },
{
path: "/plantsMap",
name: "PlantsMap",
- component: Home,
- meta: {
- title: "地圖總覽",
- icon: "Location",
- menuGroup: "overview",
- parentTitle: "總覽",
- },
+ component: Home
},
{
path: "/plants",
name: "PlantsOverview",
- component: PlantsOverview,
- meta: {
- title: "電廠總覽",
- icon: "Postcard",
- menuGroup: "overview",
- parentTitle: "總覽"
- },
+ component: PlantsOverview
},
{
path: "/plant/:id",
name: "PlantInfo",
- component: PlantInfo,
- meta: {
- title: "電廠詳細",
- menuGroup: "factory-info",
- parentTitle: "電廠資訊",
- },
+ component: PlantInfo
+ },
+ {
+ path: "/patrolMission",
+ name: "PatrolMission",
+ component: PatrolMission
+ },
+ {
+ path: "/patrolSetting",
+ name: "PatrolSetting",
+ component: PatrolSetting
},
{
path: "/plantsReport",
name: "PlantsReport",
- component: PlantReport,
- meta: {
- title: "電廠報表",
- menuGroup: "report",
- parentTitle: "報表查詢",
- },
+ component: PlantReport
},
{
path: "/plantSetting",
name: "PlantSetting",
- component: PlantSetting,
- meta: {
- title: "電廠設定",
- menuGroup: "report",
- parentTitle: "系統設定",
- },
+ component: PlantSetting
}
];
diff --git a/src/views/PatrolMission.vue b/src/views/PatrolMission.vue
new file mode 100644
index 0000000..50f7c97
--- /dev/null
+++ b/src/views/PatrolMission.vue
@@ -0,0 +1,9 @@
+
+
+
+
+
+
diff --git a/src/views/PatrolSetting.vue b/src/views/PatrolSetting.vue
new file mode 100644
index 0000000..de05712
--- /dev/null
+++ b/src/views/PatrolSetting.vue
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+