董国庆
6 天以前 3f0d4c3df5d21e48da5d4ec658d9bcf54ec10319
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<template>
  <div class="sticky top0 layout">
    <div class="header relative" style="align-items: flex-end">
      <div @click="$router.push('/home')" class="title">
        <img src="@/assets/logo.png" alt="" />
        <span> 射洪市 两客一危 监管平台 </span>
      </div>
      <div></div>
      
    </div>
    <div style="display: flex;justify-content: space-between;">
      <div class="menu w100 bgColor1">
        <template v-for="(item, index) in routesList">
          <template v-if="!item.meta || !item.meta.title">
          <template v-for="(item2, index2) in item.children">
            <div
              v-if="!item2.meta.hide"
              :key="index2"
              @click="pushPath(item2.path)"
              class="flex a-center j-center h100 br--18 w--160 menuItemHover pointer"
              :class="item2.path == $route.path && 'bgColor2'"
            >
              <img
                v-if="item2.meta.icon"
                :src="require(`@/assets/routerIcon/${item2.meta.icon}.png`)"
                class="w--40 h--40 mr--12 shrink0"
              />
              <div class="color1">
                {{ item2.meta.title }}
              </div>
            </div>
          </template>
        </template>
        <div
          v-else
          :key="index"
          :class="$route.path.includes('systemManage') && 'bgColor2'"
          class="h100 w--160 br--18 menuItemHover dropdown"
          @mouseenter="routerDropdown(true)"
          @mouseleave="routerDropdown(false)"
        >
          <div class="flex a-center j-center h100">
            <img
              :src="require(`@/assets/routerIcon/${item.meta.icon}.png`)"
              class="w--40 h--40 mr--12 shrink0"
            />
            <div class="color1">
              {{ item.meta.title }}
            </div>
          </div>
          <div v-if="routerIsOpen" class="dropdown-menu positionTwo">
            <template v-for="(item2, index2) in item.children">
              <div
                v-if="!item2.meta.hide"
                :key="index2"
                @click="pushPath(item.path + '/' + item2.path)"
                class="dropdown-item flex a-center"
              >
                {{ item2.meta.title }}
              </div>
            </template>
          </div>
        </div>
      </template>
      </div>
      <div class="flex a-center" 
      style="background: #3367ce;justify-content: space-between;padding:0 60px 0 30px;">
        <div class="flex a-center" style="padding-right: 20px;">
          <el-tooltip
            :content="$store.state.userInfo.nickName"
            placement="bottom"
            effect="light"
            :show-after="0"
            :hide-after="2000"
          >
            <img
              src="@/assets/header/photo.png"
              class="w--32 h--32 shrink0 mr--10"
              style="border-radius: 50%"
            />
          </el-tooltip>
        </div>
        <div
          class="dropdown"
          @mouseenter="toggleDropdown(true)"
          @mouseleave="toggleDropdown(false)"
        >
          <img src="@/assets/header/more.png" class="w--16 h--16" />
          <div v-if="isOpen" class="dropdown-menu">
            <div
              @click="clickItem(item)"
              class="dropdown-item"
              v-for="item in menuItems"
              :key="item.text"
            >
              <i :class="item.icon"></i> {{ item.text }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="main">
      <router-view></router-view>
    </div>
    <ResetPassword
      v-if="passwordVisible"
      :row="row"
      :dialogVisible="passwordVisible"
      @close="(passwordVisible = false), (row = {})"
      @confirm="passwordConfirm"
    />
  </div>
</template>
 
<script>
import routes from "@/router/router";
import { mapMutations } from "vuex";
import ResetPassword from "@/view/systemManage/user/components/resetPassWord.vue";
import { updatePwd } from "@/view/systemManage/user/service";
import { getRoleInfo } from "../view/systemManage/role/service";
export default {
  components: {
    ResetPassword,
  },
  data() {
    return {
      routesList: [],
      isOpen: false,
      routerIsOpen: false,
      menuItems: [{ text: "密码设置" }, { text: "退出登录" }],
      passwordVisible: false,
      row: {},
      showNickname: false,
    };
  },
  created() {
    console.log(this.$store.state.permissions,this.$router.options.routes);
    
    if (localStorage.getItem("userInfo")) {
      this.routesList = this.filterRoutes(this.$router.options.routes)
    } else {
      this.routesList = routes;
    }
  },
  methods: {
    ...mapMutations(["clearToken"]),
    // 过滤路由函数
    filterRoutes(routes) {
      const permissions = this.$store.state.permissions || [];
      return routes.filter((route) => {
        // 如果路由有children,递归过滤
        if (route.children && route.children.length > 0) {
          const filteredChildren = this.filterRoutes(route.children);
          route.children = filteredChildren;
 
          // 如果过滤后children为空,且父路由有menuId需要权限,则过滤掉该路由
          if (
            filteredChildren.length === 0 &&
            route.meta &&
            route.meta.menuId &&
            !permissions.includes(route.meta.menuId)
          ) {
            return false;
          }
          // 如果过滤后children不为空,保留该父路由
          if (filteredChildren.length > 0) {
            return true;
          }
        }
 
        // 处理没有children的路由
        // 1. 如果路由没有menuId,保留
        if (!route.meta || !route.meta.menuId) {
          return true;
        }
        // 2. 如果路由有menuId,检查权限
        return permissions.includes(route.meta.menuId);
      });
    },
    passwordConfirm(form) {
      updatePwd(form).then(() => {
        this.row = {};
        this.passwordVisible = false;
        this.msgsuccess("修改密码成功");
      });
    },
    clickItem(item) {
      switch (item.text) {
        case "密码设置":
          this.row = this.$store.state.userInfo;
          this.passwordVisible = true;
          break;
        case "退出登录":
          this.clearToken();
          window.location.replace(`/`);
          break;
        default:
          break;
      }
    },
    pushPath(path) {
      this.$router.push(path);
      if (this.routerIsOpen) this.routerIsOpen = false;
    },
    toggleDropdown(state) {
      this.isOpen = state;
    },
    routerDropdown(state) {
      this.routerIsOpen = state;
    },
  },
};
</script>
 
<style lang="less" scoped>
.layout {
  display: flex;
  flex-direction: column;
  height: 100%;
 
  .main {
    flex: 1;
    overflow: auto;
  }
}
 
.bgColor1 {
  background-color: #3367ce;
}
 
.bgColor2 {
  background: #2b5ab6;
}
 
.color1 {
  color: #fff;
}
 
.color2 {
  // color: rgba(0, 0, 0, .6);
  color: #fff;
}
 
.header {
  height: 80px;
  background: #3367ce;
  background-image: url("../assets/title.png");
  background-size: 100% 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
 
  .title {
    display: flex;
    justify-content: center;
    font-weight: 600;
    font-size: 30px;
    align-items: center;
    position: absolute;
    top: 48%;
    left: 48.5%;
    transform: translate(-50%, -50%);
    // color: rgba(0, 0, 0, .8);
    color: #fff;
 
    img {
      width: 50px;
      height: 50px;
      margin-right: 25px;
    }
 
    span {
      letter-spacing: 4px;
      text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3); // 新增字体阴影
    }
  }
}
 
.menu {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 220px;
}
 
.menuItemHover {
  flex: 1;
  max-width: 160px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
}
 
.menuItemHover:hover {
  border-radius: 18px;
  background: #2b5ab6;
}
 
.dropdown {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
 
.positionTwo {
  transform: unset !important;
  width: 160px !important;
}
 
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  transform: translateX(-50%);
  background: white;
  border: 1px solid #ccc;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  border-radius: 8px;
}
 
.dropdown-item {
  padding: 8px 16px;
  white-space: nowrap;
  /* 防止文本换行 */
}
 
.dropdown-item:hover {
  background-color: #f0f0f0;
  /* 添加 hover 效果 */
}
</style>