2021-06-07 18:35:16 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="cn-header">
|
|
|
|
|
|
<!--导航面包屑-->
|
2021-08-13 09:39:02 +08:00
|
|
|
|
<div class="header__left">
|
|
|
|
|
|
<span @click="shrink" class="shrink-button" :class="{'shrink-button--collapse': isShrink}"><i class="cn-icon cn-icon-expand"></i></span>
|
2022-04-26 14:00:16 +08:00
|
|
|
|
<el-breadcrumb class="header__left-breadcrumb" separator="/">
|
|
|
|
|
|
<el-breadcrumb-item class="header__left-breadcrumb-item" :title="item" v-for="item in breadcrumb" :key="item">
|
2021-08-13 09:39:02 +08:00
|
|
|
|
{{item}}
|
|
|
|
|
|
</el-breadcrumb-item>
|
2021-08-12 18:11:38 +08:00
|
|
|
|
</el-breadcrumb>
|
2021-08-13 09:39:02 +08:00
|
|
|
|
<el-select
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
v-model="from"
|
|
|
|
|
|
v-if="showEntityTypeSelector"
|
2021-09-24 19:24:25 +08:00
|
|
|
|
style="padding-left: 25px; width: 140px;"
|
|
|
|
|
|
class="entity-selector"
|
2021-08-13 09:39:02 +08:00
|
|
|
|
>
|
2021-09-24 19:24:25 +08:00
|
|
|
|
<el-option v-for="(value, key) in entityType" :label="value" :key="key" :value="key">
|
|
|
|
|
|
<template v-if="value === entityType.ip"><i style="color: #23BF9A;" class="cn-icon cn-icon-ip"></i></template>
|
|
|
|
|
|
<template v-else-if="value === entityType.domain"><i style="color: #23BF9A;" class="cn-icon cn-icon-domain"></i></template>
|
2022-03-18 17:42:02 +08:00
|
|
|
|
<template v-else-if="value === entityType.app"><i style="color: #23BF9A;" class="cn-icon cn-icon-app2"></i></template>
|
2021-09-24 19:24:25 +08:00
|
|
|
|
{{value}}
|
|
|
|
|
|
</el-option>
|
|
|
|
|
|
<template #prefix>
|
|
|
|
|
|
<i style="color: #23BF9A;" class="cn-icon" :class="`cn-icon-${from}`"></i>
|
|
|
|
|
|
</template>
|
2021-08-13 09:39:02 +08:00
|
|
|
|
</el-select>
|
2021-08-12 18:11:38 +08:00
|
|
|
|
</div>
|
2021-06-07 18:35:16 +08:00
|
|
|
|
<!--个人操作-->
|
|
|
|
|
|
<div class="personal">
|
|
|
|
|
|
<el-dropdown>
|
2021-08-13 09:39:02 +08:00
|
|
|
|
<div class="header-menu--item"><i class="cn-icon cn-icon-language"></i></div>
|
2021-06-07 18:35:16 +08:00
|
|
|
|
<template #dropdown>
|
|
|
|
|
|
<el-dropdown-menu>
|
|
|
|
|
|
<el-dropdown-item>
|
|
|
|
|
|
<div id="header-to-english" :style="language === 'en'?'color:#0091ff':''" @click="changeLocal('en')">English</div>
|
|
|
|
|
|
</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item>
|
|
|
|
|
|
<div id="header-to-chinese" :style="language === 'cn'?'color:#0091ff':''" @click="changeLocal('cn')">中文</div>
|
|
|
|
|
|
</el-dropdown-item>
|
|
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
|
<el-dropdown>
|
|
|
|
|
|
<div class='login-user header-menu--item'>{{username}} <i class="cn-icon cn-icon-arrow-down"></i></div>
|
|
|
|
|
|
<template #dropdown>
|
2021-08-13 09:39:02 +08:00
|
|
|
|
<el-dropdown-menu>
|
2021-06-07 18:35:16 +08:00
|
|
|
|
<el-dropdown-item>
|
2021-08-27 11:24:51 +08:00
|
|
|
|
<div id="header-to-changepin" @click="showPinDialog">{{$t('overall.changePassword')}}</div>
|
2021-06-07 18:35:16 +08:00
|
|
|
|
</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item>
|
2021-08-26 17:14:51 +08:00
|
|
|
|
<div id="header-to-logout" @click="logout">{{$t('overall.logout')}}</div>
|
2021-06-07 18:35:16 +08:00
|
|
|
|
</el-dropdown-item>
|
|
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
|
</div>
|
2021-08-26 17:14:51 +08:00
|
|
|
|
<el-dialog v-model="showChangePin"
|
2021-08-24 17:36:27 +08:00
|
|
|
|
width="30%"
|
|
|
|
|
|
:before-close="handleClose">
|
|
|
|
|
|
<el-form :rules="changePassFormRules" :model="changePassForm" ref="changePassForm">
|
|
|
|
|
|
<el-row :gutter="20">
|
|
|
|
|
|
<el-col :span="24">
|
2021-08-26 17:14:51 +08:00
|
|
|
|
<el-form-item :label="$t('overall.currentPassword')" prop="oldPwd">
|
|
|
|
|
|
<el-input v-model="changePassForm.oldPwd" type="password"></el-input>
|
2021-08-24 17:36:27 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="24">
|
2021-08-26 17:14:51 +08:00
|
|
|
|
<el-form-item :label="$t('overall.newPassword')" prop="newPwd">
|
|
|
|
|
|
<el-input v-model="changePassForm.newPwd" type="password"></el-input>
|
2021-08-24 17:36:27 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="24">
|
2021-08-26 17:14:51 +08:00
|
|
|
|
<el-form-item :label="$t('overall.confirmNewPassword')" prop="newPwd2">
|
|
|
|
|
|
<el-input v-model="changePassForm.newPwd2" type="password"></el-input>
|
2021-08-24 17:36:27 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<template #footer>
|
2021-08-26 17:14:51 +08:00
|
|
|
|
<span class="dialog-footer">
|
|
|
|
|
|
<el-button @click="showChangePin = false">{{$t('overall.cancel')}}</el-button>
|
|
|
|
|
|
<el-button type="primary" @click="submit">{{$t('overall.update')}}</el-button>
|
|
|
|
|
|
</span>
|
2021-08-24 17:36:27 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
2021-06-07 18:35:16 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-08-12 18:11:38 +08:00
|
|
|
|
import { useRoute } from 'vue-router'
|
2021-08-24 17:36:27 +08:00
|
|
|
|
import { get, put } from '@/utils/http'
|
2021-08-13 09:39:02 +08:00
|
|
|
|
import { entityType, storageKey } from '@/utils/constants'
|
2022-04-14 15:52:07 +08:00
|
|
|
|
import { api } from '@/utils/api'
|
2021-09-15 12:19:13 +08:00
|
|
|
|
|
2021-06-07 18:35:16 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'Header',
|
|
|
|
|
|
data () {
|
2021-08-26 17:14:51 +08:00
|
|
|
|
const passwordComparison = (rule, value, callback) => {
|
|
|
|
|
|
if (value !== this.changePassForm.newPwd) {
|
|
|
|
|
|
callback(new Error(this.$t('validate.passwordConsistent')))
|
2021-08-24 17:36:27 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
callback()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-06-07 18:35:16 +08:00
|
|
|
|
return {
|
2022-06-22 14:05:11 +08:00
|
|
|
|
username: localStorage.getItem(storageKey.username),
|
2022-04-14 15:52:07 +08:00
|
|
|
|
language: localStorage.getItem(storageKey.language) ? localStorage.getItem(storageKey.language) : 'en',
|
2021-08-12 18:11:38 +08:00
|
|
|
|
showChangePin: false,
|
2021-08-24 17:36:27 +08:00
|
|
|
|
from: '', // entity类型
|
|
|
|
|
|
changePassForm: {
|
2021-08-26 17:14:51 +08:00
|
|
|
|
oldPwd: '',
|
|
|
|
|
|
newPwd: '',
|
|
|
|
|
|
newPwd2: ''
|
2021-08-24 17:36:27 +08:00
|
|
|
|
},
|
|
|
|
|
|
changePassFormRules: {
|
2021-08-26 17:14:51 +08:00
|
|
|
|
oldPwd: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }],
|
|
|
|
|
|
newPwd: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }],
|
|
|
|
|
|
newPwd2: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }, { validator: passwordComparison, trigger: 'blur' }]
|
2021-08-24 17:36:27 +08:00
|
|
|
|
}
|
2021-08-12 18:11:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
breadcrumb () {
|
2022-03-01 23:24:25 +08:00
|
|
|
|
const breadcrumbMap = []
|
|
|
|
|
|
this.$store.getters.menuList.forEach(menu => {
|
|
|
|
|
|
if (this.$_.isEmpty(menu.children) && menu.route) {
|
|
|
|
|
|
breadcrumbMap.push({ name: this.$t(menu.i18n), path: menu.route })
|
|
|
|
|
|
} else if (!this.$_.isEmpty(menu.children)) {
|
|
|
|
|
|
menu.children.forEach(child => {
|
|
|
|
|
|
breadcrumbMap.push({ name: child.i18n ? this.$t(child.i18n) : child.name, parentName: menu.i18n ? this.$t(menu.i18n) : menu.name, path: child.route })
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
const breadcrumb = breadcrumbMap.find(b => this.path === b.path)
|
2021-09-15 12:19:13 +08:00
|
|
|
|
return breadcrumb ? [breadcrumb.parentName, breadcrumb.name] : []
|
2021-08-12 18:11:38 +08:00
|
|
|
|
},
|
|
|
|
|
|
path () {
|
|
|
|
|
|
const { path } = useRoute()
|
|
|
|
|
|
return path
|
2021-08-13 09:39:02 +08:00
|
|
|
|
},
|
|
|
|
|
|
showEntityTypeSelector () {
|
|
|
|
|
|
return this.$store.getters.getShowEntityTypeSelector
|
|
|
|
|
|
},
|
|
|
|
|
|
isShrink () {
|
|
|
|
|
|
return this.$store.getters.getIsShrink
|
|
|
|
|
|
},
|
2021-08-13 18:57:49 +08:00
|
|
|
|
storeFrom () {
|
|
|
|
|
|
return this.$store.getters.from
|
2021-08-13 09:39:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
from (n) {
|
|
|
|
|
|
this.$store.commit('entityTypeChange', n)
|
|
|
|
|
|
},
|
2021-08-13 18:57:49 +08:00
|
|
|
|
storeFrom (n) {
|
|
|
|
|
|
if (this.from !== n) {
|
|
|
|
|
|
this.from = n
|
|
|
|
|
|
}
|
2021-08-13 09:39:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted () {
|
|
|
|
|
|
this.from = Object.keys(this.entityType)[0]
|
|
|
|
|
|
},
|
|
|
|
|
|
setup () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
entityType // 所有entity类型,用于header下拉框选择
|
2021-06-07 18:35:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2021-08-24 17:36:27 +08:00
|
|
|
|
handleClose () {
|
|
|
|
|
|
this.showChangePin = false
|
|
|
|
|
|
},
|
2021-06-07 18:35:16 +08:00
|
|
|
|
changeLocal (lang) {
|
2022-04-14 15:52:07 +08:00
|
|
|
|
if (lang !== localStorage.getItem(storageKey.language)) {
|
|
|
|
|
|
localStorage.setItem(storageKey.language, lang)
|
2021-06-07 18:35:16 +08:00
|
|
|
|
window.location.reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
showPinDialog () {
|
|
|
|
|
|
this.showChangePin = true
|
|
|
|
|
|
},
|
|
|
|
|
|
logout () {
|
2022-05-19 18:26:51 +08:00
|
|
|
|
sessionStorage.removeItem(storageKey.tokenExpireCurrentPath)
|
2022-01-03 22:46:22 +08:00
|
|
|
|
localStorage.removeItem(storageKey.token)
|
2022-04-14 15:52:07 +08:00
|
|
|
|
get(api.logout)
|
2021-06-07 18:35:16 +08:00
|
|
|
|
},
|
|
|
|
|
|
refreshLang () {
|
2022-04-14 15:52:07 +08:00
|
|
|
|
this.language = localStorage.getItem(storageKey.language)
|
2021-06-07 18:35:16 +08:00
|
|
|
|
this.$i18n.locale = this.language
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
window.location.reload()
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
shrink () {
|
2021-08-13 09:39:02 +08:00
|
|
|
|
this.$store.commit('isShrink', !this.isShrink)
|
2021-08-24 17:36:27 +08:00
|
|
|
|
},
|
|
|
|
|
|
submit () {
|
|
|
|
|
|
this.$refs.changePassForm.validate((valid) => {
|
|
|
|
|
|
if (valid) {
|
2022-04-14 15:52:07 +08:00
|
|
|
|
put(api.pin, { oldPin: this.changePassForm.oldPwd, newPin: this.changePassForm.newPwd }).then(res => {
|
2021-08-24 17:36:27 +08:00
|
|
|
|
if (res.code === 200) {
|
2021-08-26 17:14:51 +08:00
|
|
|
|
this.$message.success('Success')
|
2021-08-24 17:36:27 +08:00
|
|
|
|
this.showChangePin = false
|
2021-08-26 17:14:51 +08:00
|
|
|
|
} else if (res.code === 518005) {
|
|
|
|
|
|
this.$message.error('密码错误')
|
2021-08-24 17:36:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2021-06-07 18:35:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|