header.vue
9.56 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
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
337
338
339
340
<template>
<div class="head_container">
<div class="title_wrap">
<el-row>
<el-col :span="7">
<router-link to="/">
<div class="logo_wrap">
<img src="./../assets/images/home/108.png" alt="logo" style="height: 100%" class="mr10"/>
<span>宁夏企业信用信息平台</span>
<div v-show="false">{{ route.path }}</div>
</div>
</router-link>
</el-col>
<el-col :span="11" :offset="2">
<el-menu :default-active="state.activeMenu" mode="horizontal" :ellipsis="false"
class="menu_warp selectNone"
background-color="#2a5f93"
text-color="#fff"
active-text-color="#2969E7"
style="border-bottom: 0"
:router="true"
>
<div class="menu_dh">
<template v-for="(item, index) in state.menuList">
<el-sub-menu :index="item.index" v-if="item.children" @click="handleSelect(item)">
<template #title>{{ item.title }}</template>
<template v-for="(child, childIndex) in item.children">
<el-menu-item :key="'menu'+childIndex" :index="child.index" :route="{path: child.path}" v-if="child.isShow">
{{ child.title }}
</el-menu-item>
</template>
</el-sub-menu>
<el-menu-item v-else :index="item.index" :key="'menu'+index" :route="{path: item.path}">
{{ item.title }}
</el-menu-item>
</template>
</div>
</el-menu>
</el-col>
<el-col :span="4" style="display: flex;justify-content: flex-end;align-items: center;">
<el-dropdown class="user_wrap" size="large" v-if="state.isLogin">
<div style="display: flex; align-items: center; color: #2969E7">
<el-icon style="font-size: 20px;">
<component :is="'Avatar'"></component>
</el-icon>
<span style="margin: 0 10px 0 5px; font-size: 20px;">{{ state.userInfo && state.userInfo.loginName }}</span>
<el-icon>
<component :is="'ArrowDown'"></component>
</el-icon>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="router.push('/personCenter')">个人中心</el-dropdown-item>
<el-dropdown-item @click="state.open = true">修改密码</el-dropdown-item>
<el-dropdown-item @click="loginOut" divided>退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<template v-else>
<el-button plain type="primary" @click="router.push('/login')">登录/注册</el-button>
</template>
</el-col>
</el-row>
</div>
<el-dialog :title="state.title" v-model="state.open" width="500px" append-to-body destroy-on-close :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
<el-form ref="queryForm" :model="state.rulesForm" :rules="queryRules" label-position="left" label-width="80px" @close="handleClose">
<el-form-item label="新密码" prop="newPwd">
<el-input type="password" show-password v-model.trim="state.rulesForm.newPwd"
placeholder="请输入新密码"></el-input>
</el-form-item>
<el-form-item label="确认密码" prop="confirmNewPwd">
<el-input type="password" show-password v-model.trim="state.rulesForm.confirmNewPwd"
placeholder="请输入确认密码"></el-input>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose(false)" v-if="state.modifyPsdPage !== 1">取消</el-button>
<el-button type="primary" @click="handleSubmit('isSubmit')" :loading="state['isSubmit']">确定</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import getImage from "../assets/getImage";
import {loginMain} from './../store/index'
import {storeToRefs} from 'pinia';
let loginAct = loginMain()
let {getStoreToken, getUserInfo} = storeToRefs(loginAct)
import * as api from "./../interface/api"
import router from "./../router/index"
import {getToken} from "../utils/auth.ts";
import {FormRules} from "element-plus";
import {RouteLocationMatched} from "vue-router";
const route = useRoute();
let title: any = ref("");
const handleSelect = (d) => {
if(d.index==4) {
router.push("/product")
}
}
let state: any = reactive({
activeMenu: '-1',
menuList: [{
title: "首页",
path: "/",
index: '0'
}, {
title: "企业数据库",
index: '1',
path: "/",
}, {
title: "风险预警",
index: '2' ,
path: "/",
}, {
title: "攻击分析",
index: '3',
path: "/",
}, {
title: "信用报告",
index: '4',
path: "/",
}],
userInfo: getUserInfo.value,
title: '修改密码',
open: false,
rulesForm: {
newPwd: undefined,
confirmNewPwd: undefined,
},
isLogin: false,
modifyPsdPage: null,
})
/*{
title: "风险动态监控列表",
path: "/monitorList",
index: '3'*/
const matchNewOldPwd = (rule: any, value: any, callback: any) => {
if (!value) {
return callback(new Error('确认密码不能为空'))
}
setTimeout(() => {
if (state.rulesForm.newPwd !== state.rulesForm.confirmNewPwd) {
callback(new Error('新密码与确认密码不一致'))
} else {
callback()
}
}, 100)
}
let queryRules = reactive<FormRules>({
newPwd: [
{required: true, message: "新密码不能为空", trigger: ["blur", "change"]}
],
confirmNewPwd: [
{required: true, message: "确认密码不能为空", trigger: ["blur", "change"]},
{validator: matchNewOldPwd, trigger: ["blur", "change"]},
]
})
let loginOut = () => {
api.loginOut().then(() => {
ElMessage.success("退出登录")
loginAct.removeUserInfo()
router.push("/login")
})
}
let queryForm = ref(null)
let handleClose = () => {
queryForm.value.resetFields()
state.open = false
}
let handleSubmit = (status: string) => {
queryForm.value.validate((valid: boolean, fields: Object) => {
if (valid) {
state[status] = true
api.updatePwd({password: state.rulesForm.newPwd}).then(res => {
ElMessage.success("修改成功")
state.userInfo.modifyPsdPage = 0
localStorage.setItem("userInfo", JSON.stringify(state.userInfo))
handleClose()
}).finally(()=> {
state[status] = false
})
}
})
}
let frontMenu = getToken() ? JSON.parse(localStorage.getItem('userInfo')).frontMenu : []
let isHaveMenu = (value: string) => {
let isHave = !getToken()
if (frontMenu && JSON.stringify(frontMenu) !== "{}") {
frontMenu.some((item: object)=> {
if (item && item.url === value) {
isHave = true
}
})
}
return isHave
}
let isShowModifyPwd = () => {
if (getToken()) {
state.modifyPsdPage = JSON.parse(localStorage.getItem('userInfo')).modifyPsdPage
if (state.modifyPsdPage === 1) {
state.open = true
}
}
}
watchEffect(() => {
let matched = route.matched.filter((item: RouteLocationMatched) => {
return item.meta && item.meta.title;
})
if (matched[0]) {
state.activeMenu = "-1"
title = matched[0].meta.title
state.menuList.some((item: object) => {
if (item.title == title) {
state.activeMenu = item.index
}
})
}
})
onMounted(()=> {
state.isLogin = !!getToken()
isShowModifyPwd()
state.menuList.forEach((item: object)=> {
if (item.children) {
item.children.forEach((child: object)=> {
if (child.path === '/enterpriseRelations'
|| child.path === '/specialSearch'
|| child.path === '/verificationSearch'
|| child.path === '/investSearch'
|| child.path === '/financeSearch'
|| child.path === '/negativeSearch'
|| child.path === '/litigationSearch'
|| child.path === '/receiptDetail'
|| child.path === '/commerceDetail'
|| child.path === '/industryDetail'
|| child.path === '/scienceDetail'
|| child.path === '/receipt/search'
|| child.path === '/tenderingDetail'
) {
child["isShow"] = true
} else {
child["isShow"] = isHaveMenu(child.path)
}
})
}
})
})
</script>
<style scoped>
.head_container {
background-color: #2a5f93;
position: relative;
width: 100%;
min-width: 1200px;
border-bottom: 1px #E6E6E6 solid;
}
.title_wrap {
position: relative;
width: 80%;
margin: 0 auto;
min-width: 1200px;
}
.logo_wrap {
height: 30px;
margin-top: 15px;
margin-right: 100px;
cursor: pointer;
line-height: 30px;
display: flex;
color: #fff;
font-size: 18px;
}
.menu_warp {
display: flex;
flex-grow: 1;
}
.menu_dh {
display: flex;
flex-grow: 1;
justify-content: space-around;
}
.user_wrap {
color: #fff;
cursor: pointer;
display: flex;
justify-content: flex-end;
line-height: 60px;
}
:deep(.el-sub-menu) {
display: flex;
align-items: center;
}
:deep(.menu_warp .el-menu-item) {
height: 60px;
font-size: 18px;
}
:deep(.el-sub-menu__title) {
font-size: 18px;
}
:deep(.menu_warp.el-menu--horizontal .el-menu-item:hover) {
background-color: #2a5f93;
color: #3265FF;
}
:deep(.menu_warp.el-menu--horizontal .el-menu-item.is-active) {
background-color: #2a5f93;
}
:deep(.el-sub-menu__title:hover) {
background-color: #2a5f93;
}
</style>