App.vue
11 KB
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
<template>
<a-config-provider :locale="locale" :theme="themeJson" :transformCellText="transformCellText">
<a-layout class="admin-layout">
<a-layout-header class="header">
<a-flex justify="space-between">
<div class="logo">
<img src="/assets/images/logo.png"/>
<h3>优加二手车</h3>
<breadcrumb-bar></breadcrumb-bar>
</div>
<div>
<a-dropdown class="select-dropdown">
<a-space>
<a-avatar v-if="this.authenticity&&this.authenticity.avatar" :src="this.authenticity.avatar" :size="32"/>
<a-avatar v-else :size="32" title="用户头像">
<template #icon>
<UserOutlined/>
</template>
</a-avatar>
<span class="user-name" style="cursor: pointer">{{ loginUserName }}</span>
<DownOutlined/>
</a-space>
<template #overlay>
<a-menu>
<a-menu-item key="0">
<router-link to="/security/profile">
<UserOutlined class="mr-8"/>
个人中心
</router-link>
</a-menu-item>
<a-menu-item key="4">
<a @click="logout" rel="noopener noreferrer">
<LogoutOutlined class="mr-8"/>
退出
</a>
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</div>
</a-flex>
</a-layout-header>
<a-layout>
<a-layout-sider class="menu-sidebar" v-model:collapsed="collapsed" theme="light" :trigger="null" width="200" collapsible>
<a-menu v-model:selectedKeys="selectedKeys" v-model:openKeys="openKeys" mode="inline" theme="light" class="main-menu">
<a-menu-item key="dashboard">
<template #icon>
<img v-if="selectedKeys.includes('dashboard')" src="/assets/icons/home_on.png" alt="" class="menu-item-icon">
<img v-else src="/assets/icons/home_on.png" alt="" class="menu-item-icon">
</template>
<router-link to="/dashboard">
首页
</router-link>
</a-menu-item>
<privilege-menu :privileges="privileges" :open-keys="openKeys"></privilege-menu>
<a-menu-item key="profile">
<template #icon>
<img v-if="selectedKeys.includes('profile')" src="/assets/icons/profile_on.png" alt="" class="menu-item-icon">
<img v-else src="/assets/icons/profile_on.png" alt="" class="menu-item-icon">
</template>
<router-link to="/security/profile">
个人中心
</router-link>
</a-menu-item>
</a-menu>
<div style="position: absolute;right: -10px;top:260px;box-shadow: 0px 4px 8px #00000019;border: 1px solid #E1E3E6FF;padding:2px 6px 4px 6px;border-radius: 14px;">
<RightOutlined v-if="collapsed" class="trigger" @click="() => (collapsed = !collapsed)" style="font-size: 10px;color: #777C85;"/>
<LeftOutlined v-else class="trigger" @click="() => (collapsed = !collapsed)" style="font-size: 10px;color: #777C85;"/>
</div>
</a-layout-sider>
<a-layout-content class="inner-main">
<div class="main" :class="{greyBg:(this.$route.path==='/dashboard'||this.$route.path.includes('/finance/dashboard'))}">
<router-view/>
</div>
</a-layout-content>
</a-layout>
</a-layout>
</a-config-provider>
</template>
<script lang="ts">
import {Component, Vue} from "vue-facing-decorator";
import {
BarChartOutlined,
CodepenCircleOutlined,
CommentOutlined,
ContainerOutlined,
CustomerServiceOutlined,
DatabaseOutlined, DownOutlined, ExclamationCircleOutlined,
FileDoneOutlined,
FileOutlined,
HomeOutlined,
LaptopOutlined, LeftCircleOutlined, LeftOutlined, LogoutOutlined,
MessageOutlined,
NotificationOutlined,
QuestionCircleOutlined, RightCircleOutlined, RightOutlined,
SearchOutlined,
SettingOutlined,
TeamOutlined,
UserOutlined
} from '@ant-design/icons-vue';
import 'dayjs/locale/zh-cn';
import zhCN from 'ant-design-vue/es/locale/zh_CN';
import lightTheme from '@/assets/style/theme/light';
import {Privilege} from "lib/src/core/security/Privilege";
import BreadcrumbBar from "@/components/BreadcrumbBar.vue";
import {Getter} from "vuex-facing-decorator";
import PrivilegeMenu from "@/views/PrivilegeMenu.vue";
import {createVNode} from "vue";
import {message, Modal} from "ant-design-vue";
import Authenticity from "lib/src/core/security/Authenticity";
@Component({
components: {
BreadcrumbBar, PrivilegeMenu, LeftCircleOutlined,
RightCircleOutlined, RightOutlined, LeftOutlined,
UserOutlined, LaptopOutlined, SearchOutlined, FileOutlined, ContainerOutlined, NotificationOutlined, DatabaseOutlined,
FileDoneOutlined, CodepenCircleOutlined, SettingOutlined, QuestionCircleOutlined, TeamOutlined, BarChartOutlined,
MessageOutlined, CustomerServiceOutlined, CommentOutlined, HomeOutlined, LogoutOutlined, DownOutlined
}
})
export default class App extends Vue {
locale = zhCN;
themeJson: any = lightTheme;
selectedKeys = ['dashboard'];
openKeys = [];
collapsed = false;
theme = '';
body;
loginUserName = "";
// 底部菜单权限
privileges: Privilege[] = [];
authenticity: Authenticity = null;
@Getter("security/getPrivileges") getPrivileges;
// 全局组件配置:针对 Table 列设置默认渲染
transformCellText = ({text}) => {
// 空值判断逻辑(和之前一致,覆盖所有空值场景)
const isEmpty =
text === undefined ||
text === null ||
text === '' ||
(typeof text === 'string' && text.trim() === '') ||
(Array.isArray(text) && text.length === 0) ||
(typeof text === 'object' && text !== null && Object.keys(text).length === 0);
return isEmpty ? '-' : text;
}
created(): void {
// this.$router.replace('/dashboard');
this.authenticity = this.$auth.getAuthentication();
this.loginUserName = this.$auth.getAuthentication().fullName;
// 底部菜单权限
this.privileges = this.getPrivileges;
// 初始化菜单选中状态
this.initMenuSelected();
}
mounted(): void {
// 监听路由变化
this.$router.afterEach(() => {
this.initMenuSelected();
});
}
/**
* 初始化菜单选中状态
*/
initMenuSelected(): void {
const currentPath = this.$route.path;
const menuKey = this.findMenuKeyByPath(this.privileges, currentPath);
if (menuKey) {
this.selectedKeys = [menuKey];
} else if (currentPath === '/dashboard') {
this.selectedKeys = ['dashboard'];
} else if (currentPath === '/security/profile') {
this.selectedKeys = ['profile'];
}
}
/**
* 根据路由路径查找对应的菜单键
* @param privileges 权限菜单列表
* @param path 当前路由路径
* @returns 对应的菜单键
*/
findMenuKeyByPath(privileges: any[], path: string): string | null {
for (const item of privileges) {
if (item.value === path) {
return item.code;
}
if (item.children && item.children.length > 0) {
const foundKey = this.findMenuKeyByPath(item.children, path);
if (foundKey) {
return foundKey;
}
}
}
return null;
}
logout() {
Modal.confirm({
title: '提示',
icon: createVNode(ExclamationCircleOutlined),
content: createVNode('p', {}, '你确认退出吗?'),
okText: '确定',
cancelText: '取消',
onOk: () => {
this.signOut();
},
onCancel: () => {
console.log('Cancel');
},
});
}
/**
* 退出登录
*/
signOut(): void {
this.$auth.logout();
localStorage.removeItem("Authorization");
localStorage.removeItem("token");
message.success('你已经成功退出');
window.location.href = '/admin/logout';
}
}
</script>
<style lang="less" scoped>
.admin-layout {
padding: 0;
margin: 0 auto;
height: 100vh;
.header {
height: 56px;
line-height: 56px;
//background: linear-gradient(120deg, #2452B5 0%, #83aef5 100%);
background-color: #fff;
padding: 0 24px;
border-bottom: 1px solid #F2F4F7;
.logo {
display: flex;
align-items: center;
img {
width: 48px;
height: 24px;
margin-left: 8px;
margin-right: 8px;
}
h3 {
font-family: "Microsoft YaHei", "SimHei", "Heiti SC", sans-serif;
font-size: 20px;
font-weight: 600;
color: #0D162A !important;
}
}
.user-name {
color: #000;
}
}
.menu-sidebar {
//height: calc(100vh - 70px);
height: 100%;
//background: #2755c2;
background-color: #F7F8F9;
.main-menu {
height: calc(100vh - 90px);
//border-right: 0;
overflow: hidden auto;
background-color: rgba(247, 248, 249, 1);
}
::v-deep(.ul-height) {
height: calc(100vh - 96px) !important;
overflow: hidden auto;
&::-webkit-scrollbar {
display: none;
}
}
}
.greyBg {
background: #F7F8F9FF !important;
}
.menu-item-icon {
width: 18px;
}
}
</style>