You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
318 lines
9.0 KiB
318 lines
9.0 KiB
<template> |
|
<div class="header"> |
|
<a class="logo" @click="toIndex"> |
|
<img src="@/assets/img/logo.png" alt=""> |
|
</a> |
|
<div class="inner"> |
|
<div style="height: 64px;"></div> |
|
<navbar ref="nav" @hideSetting="hideSetting"></navbar> |
|
<div class="action" v-if="token"> |
|
<img v-if="showSetting" class="icon m-r-20" src="../../assets/img/setting.png" alt="" @click="toManager"> |
|
<el-dropdown class="user-wrap" @command="userCommand"> |
|
<div class="user"> |
|
<el-avatar :size="40" :src="avatar"></el-avatar> |
|
<span class="username">{{ userName }}</span> |
|
</div> |
|
<el-dropdown-menu slot="dropdown"> |
|
<el-dropdown-item command="person" v-if="!isCustomer">个人资料</el-dropdown-item> |
|
<template v-else> |
|
<el-dropdown-item command="resetPw">修改密码</el-dropdown-item> |
|
<el-dropdown-item command="myDownload">我的下载</el-dropdown-item> |
|
</template> |
|
<el-dropdown-item command="logout">退出登录</el-dropdown-item> |
|
</el-dropdown-menu> |
|
</el-dropdown> |
|
</div> |
|
<div class="login" v-else-if="!isLogin" @click="toLogin"> |
|
<img src="@/assets/img/user.png" alt=""> |
|
<span>登录</span> |
|
</div> |
|
</div> |
|
|
|
<el-dialog title="修改密码" :visible.sync="passwordVisible" :close-on-click-modal="false" :append-to-body="true" |
|
@close="closePassword" width="30%"> |
|
<el-form ref="passwordForm" label-width="82px"> |
|
<el-form-item label="原密码"> |
|
<el-input type="password" v-model="passwordForm.password" placeholder="请输入原密码"></el-input> |
|
</el-form-item> |
|
<el-form-item label="新密码"> |
|
<el-input type="password" v-model="passwordForm.newPassword" placeholder="请输入新密码" |
|
@keyup.enter.native="editPassword"></el-input> |
|
</el-form-item> |
|
<el-form-item label="确认新密码"> |
|
<el-input type="password" v-model="passwordForm.reNewPassword" placeholder="请确认新密码" |
|
@keyup.enter.native="editPassword"></el-input> |
|
</el-form-item> |
|
</el-form> |
|
<span slot="footer" class="dialog-footer"> |
|
<el-button size="small" @click="passwordVisible = false">取 消</el-button> |
|
<el-button size="small" type="primary" @click="editPassword">确 定</el-button> |
|
</span> |
|
</el-dialog> |
|
</div> |
|
</template> |
|
<script> |
|
import navbar from '../navbar' |
|
import { mapState, mapMutations, mapActions } from 'vuex' |
|
import Setting from '@/setting' |
|
import util from '@/libs/util' |
|
export default { |
|
data () { |
|
return { |
|
token: util.local.get(Setting.tokenKey), |
|
isLogin: this.$route.path == '/login', |
|
customer: this.$route.query.customer, |
|
showSetting: true, |
|
id: '', |
|
schoolName: '', |
|
passwordVisible: false, |
|
passwordForm: { |
|
password: '', |
|
newPassword: '', |
|
reNewPassword: '' |
|
} |
|
}; |
|
}, |
|
components: { navbar }, |
|
computed: { |
|
...mapState('user', [ |
|
'avatar', 'schoolId', 'isCustomer', 'userName', 'logView' |
|
]), |
|
...mapState('auth', [ |
|
'routes' |
|
]) |
|
}, |
|
mounted () { |
|
// 如果是客户,则存到store里去,因为客户是没有用户信息的,上面要根据这个值来判断显示与否 |
|
if (this.customer) { |
|
let customer = atob(decodeURI(this.customer)) == 'false' ? false : true |
|
this.setCustomer(customer) |
|
} |
|
// 如果是管理员,并且已经进入到了后台,那么就要把进入后台的图标给隐藏 |
|
let mg = this.$route.query.mg |
|
if (mg && atob(decodeURI(mg)) === 'true') { |
|
this.showSetting = false |
|
const userName = this.$route.query.userName |
|
userName && this.setInfo({ |
|
userName |
|
}) |
|
} |
|
// 如果登录了,并且非客户,才调用用户信息的接口。客户是没有用户信息的,但是能进入后台(如果有权限菜单) |
|
setTimeout(() => { |
|
this.token && !this.isCustomer && this.getUserInfo() |
|
}, 1000) |
|
}, |
|
methods: { |
|
...mapActions('user', [ |
|
'setInfo', 'logout', 'setManager', 'setCustomer' |
|
]), |
|
// 获取个人信息 |
|
getUserInfo () { |
|
this.$get(this.api.userInfo).then(res => { |
|
let userInfo = res.userInfo ? res.userInfo : {} |
|
let userAccount = res.userAccount |
|
this.id = userAccount.id |
|
this.schoolName = res.schoolName |
|
this.setInfo({ |
|
avatar: userInfo.userAvatars, |
|
userName: userInfo.userName |
|
}) |
|
}).catch(err => { }) |
|
}, |
|
hideSetting () { |
|
this.showSetting = false |
|
}, |
|
toIndex () { |
|
// 如果是在首页,直接刷新页面,否则,跳转到首页,并且重置进入后台的图标 |
|
if (this.$route.path === '/index/list') { |
|
location.reload() |
|
} else { |
|
this.$refs.nav.toIndex() |
|
this.showSetting = true |
|
} |
|
}, |
|
toLogin () { |
|
window.open(this.$router.resolve('/login').href) |
|
}, |
|
// 跳转到管理员后台 |
|
toManager () { |
|
let routes = this.routes |
|
if (routes.length) { |
|
let route = this.$router.resolve({ |
|
path: this.routes[0].name, |
|
query: { |
|
mg: btoa(true), // 后台的标识 |
|
schoolId: btoa(this.schoolId), |
|
customer: btoa(this.isCustomer), // 客户标识 |
|
userName: this.userName |
|
} |
|
}) |
|
window.open(route.href) // 后台要打开新标签页 |
|
} else { |
|
// 如果接口返回的后台角色权限为空,则表示没有给该角色开放任何模块权限,直接提示用户未开放 |
|
util.warningMsg('该角色未开放模块,请联系管理员') |
|
} |
|
}, |
|
userCommand (command) { |
|
if (command == 'person') { |
|
this.$router.push('/setting/person').catch(err => { }) |
|
} else if (command == 'resetPw') { |
|
this.showPassword() |
|
} else if (command == 'myDownload') { |
|
this.$router.push('/setting/download').catch(err => { }) |
|
} else { |
|
this.logout() |
|
} |
|
}, |
|
showPassword () { |
|
this.passwordVisible = true |
|
}, |
|
editPassword () { |
|
if (!this.passwordForm.password) return util.warningMsg('请输入原密码') |
|
if (!this.passwordForm.newPassword) return util.warningMsg('请输入新密码') |
|
if (!this.passwordForm.reNewPassword) return util.warningMsg('请确认新密码') |
|
if (this.passwordForm.newPassword.length < 6 || this.passwordForm.reNewPassword.length < 6) return util.warningMsg('请输入6位数以上的密码') |
|
if (this.passwordForm.newPassword !== this.passwordForm.reNewPassword) return util.warningMsg('输入的新密码不一致,请重新确认') |
|
if (this.passwordForm.password === this.passwordForm.newPassword) return util.warningMsg('原密码跟新密码不能一致') |
|
|
|
let data = this.passwordForm |
|
data.accountId = this.id |
|
this.$post(this.api.examinePassword, data).then(res => { |
|
util.successMsg('修改成功') |
|
this.passwordVisible = false |
|
}).catch(err => { }) |
|
}, |
|
closePassword () { |
|
this.passwordForm = { |
|
password: '', |
|
newPassword: '', |
|
reNewPassword: '' |
|
} |
|
}, |
|
}, |
|
}; |
|
</script> |
|
<style lang="scss" scoped> |
|
$height: 64px; |
|
|
|
.header { |
|
z-index: 10; |
|
position: fixed; |
|
top: 0; |
|
left: 0; |
|
width: 100%; |
|
height: $height; |
|
background-color: #fff; |
|
box-shadow: 0px 0px 6px 0px rgba(178, 178, 178, 0.32); |
|
|
|
.inner { |
|
display: flex; |
|
justify-content: space-between; |
|
align-items: center; |
|
min-width: $min-width; |
|
padding: 0 80px 0 10px; |
|
margin: 0 auto; |
|
} |
|
|
|
.logo { |
|
position: absolute; |
|
top: 0; |
|
left: 80px; |
|
font-size: 28px; |
|
color: #568DF2; |
|
line-height: $height; |
|
cursor: pointer; |
|
} |
|
|
|
.search { |
|
z-index: 2; |
|
position: absolute; |
|
top: 0; |
|
left: 70%; |
|
transform: translate(-50%); |
|
display: flex; |
|
justify-content: space-between; |
|
align-items: center; |
|
width: 300px; |
|
height: $height; |
|
padding: 7px 20px; |
|
margin: 0 auto; |
|
background-color: #fff; |
|
|
|
input { |
|
width: 195px; |
|
margin-left: 10px; |
|
font-size: 14px; |
|
color: #333; |
|
background-color: transparent; |
|
border: 0; |
|
|
|
&::-webkit-input-placeholder { |
|
color: #999 |
|
} |
|
|
|
&::-moz-placeholder { |
|
color: #999 |
|
} |
|
|
|
&:-moz-placeholder { |
|
color: #999 |
|
} |
|
|
|
&:focus { |
|
outline: none; |
|
} |
|
} |
|
|
|
.remove { |
|
cursor: pointer; |
|
} |
|
|
|
.search-icon { |
|
width: 18px; |
|
} |
|
} |
|
|
|
.action { |
|
display: inline-flex; |
|
align-items: center; |
|
|
|
.icon { |
|
cursor: pointer; |
|
} |
|
|
|
.user-wrap { |
|
display: inline-flex; |
|
align-items: center; |
|
|
|
.user { |
|
display: inline-flex; |
|
align-items: center; |
|
cursor: pointer; |
|
|
|
.username { |
|
margin-left: 10px; |
|
color: #000; |
|
font-size: 16px; |
|
} |
|
} |
|
} |
|
} |
|
|
|
.login { |
|
display: inline-flex; |
|
align-items: center; |
|
cursor: pointer; |
|
|
|
&:hover { |
|
opacity: .9; |
|
} |
|
|
|
span { |
|
margin-left: 5px; |
|
color: #666; |
|
font-size: 14px; |
|
} |
|
} |
|
} |
|
</style> |