2 Commits 1a88686d44 ... 5291a9fb12

Author SHA1 Message Date
  chenghanbin 5291a9fb12 Merge branch 'dev' of http://101.36.160.140:21044/portal-site-vue-qinghai/portal-site-web into dev-chb 4 months ago
  chenghanbin a8ff05f716 优化政务公开菜单样式显示 4 months ago
3 changed files with 177 additions and 209 deletions
  1. 0 128
      src/style/zwgk/menuModule.less
  2. 113 0
      src/style/zwgk/menuStyle.less
  3. 64 81
      src/views/zwgk/modules/menuModule.vue

+ 0 - 128
src/style/zwgk/menuModule.less

@@ -1,128 +0,0 @@
1
-.page {
2
-  background: #fff !important;
3
-
4
-  .featureBox {
5
-    width: 240px;
6
-    float: left;
7
-    border-radius: 5px 5px 0 0;
8
-
9
-    .el-menu {
10
-      border: none;
11
-
12
-      .el-menu-item-group {
13
-        height: 70px;
14
-        text-align: center;
15
-        margin-bottom: 15px;
16
-        background: #2c66a4;
17
-
18
-        .title {
19
-          color: #fff;
20
-          font-size: 26px;
21
-          line-height: 35px;
22
-          font-weight: bold;
23
-        }
24
-      }
25
-
26
-      .el-menu-item {
27
-        height: 80px;
28
-        font-size: 23px;
29
-        border-radius: 6px;
30
-        margin-bottom: 15px;
31
-        background: #f2f2f2;
32
-        border: 1px solid #ddd;
33
-
34
-        &:hover {
35
-          background: #1b68c0;
36
-
37
-          .muneName {
38
-            color: #fff;
39
-          }
40
-        }
41
-
42
-        img {
43
-          width: 40px;
44
-          float: left;
45
-          margin-top: 6px;
46
-          margin-left: 20px;
47
-          padding-right: 20px;
48
-        }
49
-
50
-        .muneName {
51
-          width: 110px;
52
-          display: block;
53
-          font-size: 23px;
54
-          color: #1c68c0;
55
-          line-height: 28px;
56
-          white-space: normal;
57
-          word-wrap: break-word;
58
-        }
59
-      }
60
-
61
-      .is-active {
62
-        background: #1b68c0;
63
-
64
-        .muneName {
65
-          color: #fff;
66
-        }
67
-      }
68
-
69
-      .menuBox {
70
-        font-size: 23px;
71
-
72
-        margin-bottom: 15px;
73
-
74
-        .el-sub-menu__title {
75
-          color: #fff;
76
-          height: 80px !important;
77
-          border-radius: 6px;
78
-          background: #f2f2f2;
79
-          border: 1px solid #ddd;
80
-        }
81
-
82
-        .el-menu-item {
83
-          width: 100%;
84
-          margin: 10px 0;
85
-          background: #FAFAFA;
86
-
87
-          .muneName {
88
-            width: 100%;
89
-          }
90
-
91
-          &:hover {
92
-            color: #fff;
93
-            background: #1b68c0;
94
-          }
95
-        }
96
-
97
-        .el-sub-menu__title {
98
-          height: 70px;
99
-          color: #1c68c0;
100
-          &:hover {
101
-            color: #fff;
102
-            background: #1b68c0;
103
-          }
104
-          .el-icon {
105
-            font-size: 22px;
106
-          }
107
-        }
108
-
109
-        img {
110
-          width: 40px;
111
-          float: left;
112
-          margin-top: 6px;
113
-          margin-left: 20px;
114
-          padding-right: 20px;
115
-        }
116
-
117
-        span {
118
-          width: 110px;
119
-          display: block;
120
-          font-size: 23px;
121
-          line-height: 28px;
122
-          white-space: normal;
123
-          word-wrap: break-word;
124
-        }
125
-      }
126
-    }
127
-  }
128
-}

+ 113 - 0
src/style/zwgk/menuStyle.less

@@ -0,0 +1,113 @@
1
+.page {
2
+  background: #fff !important;
3
+
4
+  .featureBox {
5
+    width: 240px;
6
+    float: left;
7
+    border-radius: 5px 5px 0 0;
8
+
9
+    ::v-deep(.el-menu) {
10
+      border: none;
11
+      background: transparent;
12
+
13
+      .el-menu-item {
14
+        height: 80px;
15
+        font-size: 23px;
16
+        border-radius: 6px;
17
+        margin-bottom: 15px;
18
+        background: #f2f2f2;
19
+        border: 1px solid #ddd;
20
+
21
+        img {
22
+          width: 40px;
23
+          float: left;
24
+          margin-top: 6px;
25
+          margin-left: 20px;
26
+          padding-right: 20px;
27
+        }
28
+
29
+        .muneName {
30
+          width: 110px;
31
+          display: block;
32
+          font-size: 23px;
33
+          color: #1c68c0;
34
+          line-height: 28px;
35
+          white-space: normal;
36
+          word-wrap: break-word;
37
+        }
38
+
39
+        &.is-active {
40
+          background: #1b68c0;
41
+
42
+          .muneName {
43
+            color: #fff;
44
+          }
45
+        }
46
+      }
47
+
48
+      //  二级菜单样式
49
+      .el-sub-menu {
50
+        margin-bottom: 14px;
51
+
52
+        .el-sub-menu__title {
53
+          height: 80px;
54
+          font-size: 23px;
55
+          border-radius: 6px;
56
+          background: #f2f2f2;
57
+          border: 1px solid #ddd;
58
+
59
+          img {
60
+            width: 40px;
61
+            float: left;
62
+            margin-top: 6px;
63
+            margin-left: 20px;
64
+            padding-right: 20px;
65
+          }
66
+
67
+          .muneName {
68
+            width: 110px;
69
+            display: block;
70
+            font-size: 23px;
71
+            color: #1c68c0;
72
+            line-height: 28px;
73
+            white-space: normal;
74
+            word-wrap: break-word;
75
+          }
76
+        }
77
+
78
+        .el-menu {
79
+          .el-menu-item-group {
80
+            .el-menu-item-group__title {
81
+              padding: 3px 0 3px 0;
82
+            }
83
+
84
+            .el-menu-item {
85
+              margin: 0;
86
+              color: #1c68c0;
87
+              font-size: 20px;
88
+              white-space: normal;
89
+              word-wrap: break-word;
90
+
91
+              &.is-active {
92
+                color: #fff;
93
+                background: #1b68c0;
94
+              }
95
+            }
96
+          }
97
+        }
98
+
99
+        &.is-active {
100
+          background: transparent;
101
+
102
+          .el-sub-menu__title {
103
+            background: #1b68c0;
104
+
105
+            .muneName {
106
+              color: #fff;
107
+            }
108
+          }
109
+        }
110
+      }
111
+    }
112
+  }
113
+}

+ 64 - 81
src/views/zwgk/modules/menuModule.vue

@@ -1,91 +1,63 @@
1
 <template>
1
 <template>
2
   <div class="featureBox">
2
   <div class="featureBox">
3
-    <el-menu
4
-      :collapse="isCollapse"
5
-      :default-active="activeMenu"
6
-      class="el-menu-vertical-demo dark-mode"
7
-    >
8
-      <template v-for="item in menuList" :key="item.key">
9
-        <el-sub-menu
10
-          class="menuBox"
11
-          :index="item.path"
12
-          v-if="item.children"
13
-          @mouseenter="
14
-            (el) => {
15
-              moveToMenu(el, item.icon);
16
-            }
17
-          "
18
-          @mouseleave="
19
-            (el) => {
20
-              leaveToMenu(el, item.icon);
21
-            }
22
-          "
3
+    <el-menu :default-active="activeMenu">
4
+      <template v-for="menu in menuList">
5
+        <!-- 只有一级菜单 -->
6
+        <el-menu-item
7
+          v-if="!menu.children"
8
+          :index="menu.path"
9
+          @click="jumpRoute(menu)"
23
         >
10
         >
11
+          <img :src="getImgUrl(menu)" :alt="menu.name" />
12
+          <span class="muneName">{{ menu.name }}</span>
13
+        </el-menu-item>
14
+        <!-- 有二级菜单 -->
15
+        <el-sub-menu v-else :index="menu.path">
24
           <template #title>
16
           <template #title>
25
-            <img :src="getUrl(item.icon)" alt="" />
26
-            <span>{{ item.name }}</span>
17
+            <img :src="getImgUrl(menu)" :alt="menu.name" />
18
+            <span class="muneName">{{ menu.name }}</span>
27
           </template>
19
           </template>
28
-          <el-menu-item
29
-            :index="son.path"
30
-            v-for="son in item.children"
31
-            @click="jumpModule(son.path)"
20
+          <el-menu-item-group
21
+            v-for="menuSub in menu.children"
22
+            :key="menuSub.path"
32
           >
23
           >
33
-            <template #title>
34
-              <span class="muneName">{{ son.name }}</span>
35
-            </template>
36
-          </el-menu-item>
24
+            <el-menu-item :index="menuSub.path" @click="jumpRoute(menuSub)">{{
25
+              menuSub.name
26
+            }}</el-menu-item>
27
+          </el-menu-item-group>
37
         </el-sub-menu>
28
         </el-sub-menu>
38
-
39
-        <el-menu-item
40
-          v-else
41
-          :index="item.path"
42
-          @mouseenter="
43
-            (el) => {
44
-              moveToMenu(el, item.icon);
45
-            }
46
-          "
47
-          @mouseleave="
48
-            (el) => {
49
-              leaveToMenu(el, item.icon);
50
-            }
51
-          "
52
-          @click="jumpModule(item.path)"
53
-        >
54
-          <img :src="getUrl(item.icon)" alt="" />
55
-          <template #title>
56
-            <span class="muneName">{{ item.name }}</span>
57
-          </template>
58
-        </el-menu-item>
59
       </template>
29
       </template>
60
-      <slot />
61
     </el-menu>
30
     </el-menu>
62
   </div>
31
   </div>
63
 </template>
32
 </template>
64
 <script setup>
33
 <script setup>
65
 import { ref, watch, reactive } from "vue";
34
 import { ref, watch, reactive } from "vue";
66
 import { useRouter } from "vue-router";
35
 import { useRouter } from "vue-router";
67
-import "@/style/zwgk/menuModule.less";
68
 
36
 
69
 const router = useRouter();
37
 const router = useRouter();
70
 const activeMenu = ref("zfxxgkzn");
38
 const activeMenu = ref("zfxxgkzn");
71
 
39
 
72
 const menuList = reactive([
40
 const menuList = reactive([
73
   {
41
   {
42
+    active: true,
74
     path: "zfxxgkzn",
43
     path: "zfxxgkzn",
75
     icon: "zfxxgkzn",
44
     icon: "zfxxgkzn",
76
     name: "政府信息公开指南",
45
     name: "政府信息公开指南",
77
   },
46
   },
78
   {
47
   {
48
+    active: false,
79
     path: "zfxxgkzd",
49
     path: "zfxxgkzd",
80
     icon: "zfxxgkzd",
50
     icon: "zfxxgkzd",
81
     name: "政府信息公开制度",
51
     name: "政府信息公开制度",
82
   },
52
   },
83
   {
53
   {
54
+    active: false,
84
     path: "zfxxgknb",
55
     path: "zfxxgknb",
85
     icon: "zfxxgknb",
56
     icon: "zfxxgknb",
86
     name: "政府信息公开年报",
57
     name: "政府信息公开年报",
87
   },
58
   },
88
   {
59
   {
60
+    active: false,
89
     path: "fdgknr",
61
     path: "fdgknr",
90
     icon: "fdgknr",
62
     icon: "fdgknr",
91
     name: "法定公开内容",
63
     name: "法定公开内容",
@@ -125,65 +97,76 @@ const menuList = reactive([
125
     ],
97
     ],
126
   },
98
   },
127
   {
99
   {
100
+    active: false,
128
     path: "zcwj",
101
     path: "zcwj",
129
     icon: "zcwj",
102
     icon: "zcwj",
130
     name: "政策文件",
103
     name: "政策文件",
131
   },
104
   },
132
   {
105
   {
106
+    active: false,
133
     path: "zcjd",
107
     path: "zcjd",
134
     icon: "zcjd",
108
     icon: "zcjd",
135
     name: "政策解读",
109
     name: "政策解读",
136
   },
110
   },
137
   {
111
   {
112
+    active: false,
138
     path: "xzgfxwj",
113
     path: "xzgfxwj",
139
     icon: "xzgfxwj",
114
     icon: "xzgfxwj",
140
     name: "行政规范性文件",
115
     name: "行政规范性文件",
141
   },
116
   },
142
   {
117
   {
118
+    active: false,
143
     path: "ysqgk",
119
     path: "ysqgk",
144
     icon: "ysqgk",
120
     icon: "ysqgk",
145
     name: "依申请公开",
121
     name: "依申请公开",
146
   },
122
   },
147
   {
123
   {
124
+    active: false,
148
     path: "zfwzgznb",
125
     path: "zfwzgznb",
149
     icon: "zfwzgznb",
126
     icon: "zfwzgznb",
150
     name: "政府网站工作年报",
127
     name: "政府网站工作年报",
151
   },
128
   },
152
 ]);
129
 ]);
153
-function jumpModule(path) {
154
-  activeMenu.value = path;
155
-  router.push("/zwgk/" + path);
156
-}
157
-function getUrl(name) {
158
-  if (name == activeMenu.value) {
159
-    name = name + "s";
160
-  }
161
-  return new URL(`../../../assets/hdjl/${name}.png`, import.meta.url).href;
162
-}
163
-// 鼠标移入菜单
164
-function moveToMenu(el, url) {
165
-  let urls = url + "s";
166
-  // 找到当前菜单项中的 img 元素
167
-  let imgElement = el.target.querySelector("img");
168
-  if (imgElement) {
169
-    imgElement.src = imgElement.src.replace(url, urls);
170
-  }
130
+// 路由跳转
131
+function jumpRoute(data) {
132
+  activeMenu.value = data.path;
133
+  router.push("/zwgk/" + data.path);
171
 }
134
 }
172
-// 鼠标移出菜单
173
-function leaveToMenu(el, url) {
174
-  let urls = url + "s";
175
-  // 找到当前菜单项中的 img 元素
176
-  let imgElement = el.target.querySelector("img");
177
-  if (imgElement) {
178
-    imgElement.src = imgElement.src.replace(urls, url);
135
+// 获取图片地址
136
+function getImgUrl(data) {
137
+  let url = "";
138
+  if (data.active) {
139
+    url = data.icon + "s";
140
+  } else {
141
+    url = data.icon;
179
   }
142
   }
143
+  return new URL(`../../../assets/hdjl/${url}.png`, import.meta.url).href;
180
 }
144
 }
181
-
145
+// 监听 选中的菜单对应的图标高亮
146
+watch(
147
+  () => activeMenu.value,
148
+  (newValue) => {
149
+    let hasSlash = newValue.includes("/");
150
+    let menuPath = hasSlash ? "fdgknr" : newValue;
151
+    menuList.forEach((item) => {
152
+      if (menuPath == item.path) {
153
+        item.active = true;
154
+      } else {
155
+        item.active = false;
156
+      }
157
+    });
158
+  },
159
+  { immediate: true }
160
+);
161
+// 监听路由
182
 watch(
162
 watch(
183
-  () => router.currentRoute.value.name,
163
+  () => router.currentRoute.value.path,
184
   (newValue) => {
164
   (newValue) => {
185
-    activeMenu.value = newValue == "zwgk" ? "zfxxgkzn" : newValue;
165
+    activeMenu.value = newValue.replace("/zwgk/", "");
186
   },
166
   },
187
   { immediate: true }
167
   { immediate: true }
188
 );
168
 );
189
 </script>
169
 </script>
170
+<style lang="less" scoped>
171
+@import url(@/style/zwgk/menuStyle.less);
172
+</style>