|
@@ -2,42 +2,71 @@
|
|
* 头部菜单
|
|
* 头部菜单
|
|
*/
|
|
*/
|
|
<template>
|
|
<template>
|
|
-<div class="header-menu">
|
|
|
|
- <el-menu class="el-menu-demo" mode="horizontal" background-color="#334157" text-color="#fff" active-text-color="#fff">
|
|
|
|
- <el-button class="buttonimg">
|
|
|
|
- <img class="showimg" :src="collapsed?imgsq:imgshow" @click="toggle(collapsed)">
|
|
|
|
- </el-button>
|
|
|
|
- <el-submenu index="2" class="submenu">
|
|
|
|
- <!-- <template slot="title">{{user.userRealName}}</template> -->
|
|
|
|
- <template slot="title">
|
|
|
|
- <span>
|
|
|
|
- <img :src="user.avatar" alt="" class="img-avatar">
|
|
|
|
|
|
+ <div class="header-menu">
|
|
|
|
+ <el-menu
|
|
|
|
+ class="el-menu-demo"
|
|
|
|
+ mode="horizontal"
|
|
|
|
+ background-color="#334157"
|
|
|
|
+ text-color="#fff"
|
|
|
|
+ active-text-color="#fff"
|
|
|
|
+ >
|
|
|
|
+ <el-button class="buttonimg">
|
|
|
|
+ <img class="showimg" :src="collapsed?imgsq:imgshow" @click="toggle(collapsed)" />
|
|
|
|
+ </el-button>
|
|
|
|
+ <el-submenu index="2" class="submenu">
|
|
|
|
+ <!-- <template slot="title">{{user.userRealName}}</template> -->
|
|
|
|
+ <template slot="title">
|
|
|
|
+ <span>
|
|
|
|
+ <img :src="user.avatar" alt class="img-avatar" />
|
|
</span>
|
|
</span>
|
|
- {{user.username}}
|
|
|
|
|
|
+ {{user.username}}
|
|
</template>
|
|
</template>
|
|
- <el-menu-item @click="handleSetInfo()" index="2-2">个人中心</el-menu-item>
|
|
|
|
- <el-menu-item @click="exit()" index="2-3">退出</el-menu-item>
|
|
|
|
- </el-submenu>
|
|
|
|
- </el-menu>
|
|
|
|
- <el-dialog title="个人中心" :visible.sync="updateFormVisible" width="30%" @click="closeDialog">
|
|
|
|
- <el-form label-width="120px" :model="updateForm" :rules="rules" ref="updateForm" label-position="top">
|
|
|
|
|
|
+ <el-menu-item @click="handleSetInfo()" index="2-2">个人中心</el-menu-item>
|
|
|
|
+ <el-menu-item @click="exit()" index="2-3">退出</el-menu-item>
|
|
|
|
+ </el-submenu>
|
|
|
|
+ </el-menu>
|
|
|
|
+ <el-dialog title="个人中心" :visible.sync="updateFormVisible" width="30%" @click="closeDialog">
|
|
|
|
+ <el-form
|
|
|
|
+ label-width="120px"
|
|
|
|
+ :model="updateForm"
|
|
|
|
+ :rules="rules"
|
|
|
|
+ ref="updateForm"
|
|
|
|
+ label-position="top"
|
|
|
|
+ >
|
|
<el-form-item label="设置头像" prop="expires">
|
|
<el-form-item label="设置头像" prop="expires">
|
|
- <img :src="updateForm.avatar" alt="" style="border-radius:50%;width:80px">
|
|
|
|
|
|
+ <div class="avatar-box">
|
|
|
|
+ <img :src="updateForm.avatar" alt style="border-radius:50%;width:80px" />
|
|
|
|
+ <span class="txt-edit-avatar" @click="toggleShow">更换头像</span>
|
|
|
|
+ <my-upload
|
|
|
|
+ field="img"
|
|
|
|
+ @crop-success="cropSuccess"
|
|
|
|
+ v-model="show"
|
|
|
|
+ :width="200"
|
|
|
|
+ :height="200"
|
|
|
|
+ img-format="jpg"
|
|
|
|
+ :size="size"
|
|
|
|
+ ></my-upload>
|
|
|
|
+ <img :src="avatar" />
|
|
|
|
+ </div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
<el-form-item label="修改账号" prop="expires">
|
|
<el-form-item label="修改账号" prop="expires">
|
|
- <el-input v-model="updateForm.account" :disabled="updateForm.setaccount === 0" auto-complete="off" placeholder="请输入新账号"></el-input>
|
|
|
|
|
|
+ <el-input
|
|
|
|
+ v-model="updateForm.account"
|
|
|
|
+ :disabled="updateForm.setaccount === 0"
|
|
|
|
+ auto-complete="off"
|
|
|
|
+ placeholder="请输入新账号"
|
|
|
|
+ ></el-input>
|
|
<p class="error-tip">当前用户可修改账号次数为 0</p>
|
|
<p class="error-tip">当前用户可修改账号次数为 0</p>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
<el-form-item label="设置新密码" prop="password">
|
|
<el-form-item label="设置新密码" prop="password">
|
|
- <el-input type="password" v-model="updateForm.password" label="请输入新密码"></el-input>
|
|
|
|
|
|
+ <el-input type="password" v-model="updateForm.password" label="请输入新密码"></el-input>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
<el-form-item label="确认新密码" prop="password">
|
|
<el-form-item label="确认新密码" prop="password">
|
|
- <el-input type="password" v-model="psw" label="请确认新密码"></el-input>
|
|
|
|
|
|
+ <el-input type="password" v-model="psw" label="请确认新密码"></el-input>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
-
|
|
|
|
</el-form>
|
|
</el-form>
|
|
<div slot="footer" class="dialog-footer">
|
|
<div slot="footer" class="dialog-footer">
|
|
- <el-button @click="closeDialog">取消</el-button>
|
|
|
|
|
|
+ <el-button @click="closeDialog">取消</el-button>
|
|
<el-button
|
|
<el-button
|
|
type="primary"
|
|
type="primary"
|
|
:loading="loading"
|
|
:loading="loading"
|
|
@@ -46,92 +75,119 @@
|
|
>保存</el-button>
|
|
>保存</el-button>
|
|
</div>
|
|
</div>
|
|
</el-dialog>
|
|
</el-dialog>
|
|
-</div>
|
|
|
|
|
|
+ </div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
-import { updateSelf } from '../api/basisMG'
|
|
|
|
|
|
+import "babel-polyfill";
|
|
|
|
+import myUpload from "vue-image-crop-upload";
|
|
|
|
+import { updateSelf, uploadBase64 } from "../api/basisMG";
|
|
export default {
|
|
export default {
|
|
- name: 'navcon',
|
|
|
|
|
|
+ name: "navcon",
|
|
|
|
+ components: {
|
|
|
|
+ "my-upload": myUpload
|
|
|
|
+ },
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- updateFormVisible:false,
|
|
|
|
- updateForm:{},
|
|
|
|
- psw:"",
|
|
|
|
|
|
+ avatar: "", //用于存储剪切完图片的base64Data和显示回调图片
|
|
|
|
+ show: false, //剪切框显示和隐藏的flag
|
|
|
|
+ size: 2.1,
|
|
|
|
+ updateFormVisible: false,
|
|
|
|
+ updateForm: {},
|
|
|
|
+ loading: false,
|
|
|
|
+ psw: "",
|
|
collapsed: true,
|
|
collapsed: true,
|
|
- imgshow: require('../assets/img/show.png'),
|
|
|
|
- imgsq: require('../assets/img/sq.png'),
|
|
|
|
|
|
+ imgshow: require("../assets/img/show.png"),
|
|
|
|
+ imgsq: require("../assets/img/sq.png"),
|
|
user: {},
|
|
user: {},
|
|
// rules表单验证
|
|
// rules表单验证
|
|
rules: {
|
|
rules: {
|
|
password: [
|
|
password: [
|
|
{ required: false, message: "请输入新密码", trigger: "blur" }
|
|
{ required: false, message: "请输入新密码", trigger: "blur" }
|
|
]
|
|
]
|
|
- },
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ };
|
|
},
|
|
},
|
|
// 创建完毕状态(里面是操作)
|
|
// 创建完毕状态(里面是操作)
|
|
created() {
|
|
created() {
|
|
- this.user = JSON.parse(localStorage.getItem('user'))
|
|
|
|
- this.updateForm = this.user
|
|
|
|
|
|
+ this.user = JSON.parse(localStorage.getItem("user"));
|
|
|
|
+ this.updateForm = this.user;
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- handleSetInfo(){
|
|
|
|
- this.updateForm.password = ''
|
|
|
|
- this.updateFormVisible = true
|
|
|
|
|
|
+ //控制剪切框的显示和隐藏
|
|
|
|
+ toggleShow() {
|
|
|
|
+ this.show = !this.show;
|
|
|
|
+ },
|
|
|
|
+ //剪切成功后的回调函数
|
|
|
|
+ cropSuccess(imgDataUrl) {
|
|
|
|
+ uploadBase64(imgDataUrl).then(res => {
|
|
|
|
+ if(!res.error){
|
|
|
|
+ this.updateForm.avatar = res.result.data;
|
|
|
|
+ }else{
|
|
|
|
+ this.$message.error('上传失败')
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ handleSetInfo() {
|
|
|
|
+ this.updateForm.password = "";
|
|
|
|
+ this.updateFormVisible = true;
|
|
|
|
+ },
|
|
|
|
+ closeDialog() {
|
|
|
|
+ this.updateFormVisible = false;
|
|
},
|
|
},
|
|
// 退出登录
|
|
// 退出登录
|
|
exit() {
|
|
exit() {
|
|
- this.$confirm('退出登录, 是否继续?', '提示', {
|
|
|
|
- confirmButtonText: '确定',
|
|
|
|
- cancelButtonText: '取消',
|
|
|
|
- type: 'warning'
|
|
|
|
|
|
+ this.$confirm("退出登录, 是否继续?", "提示", {
|
|
|
|
+ confirmButtonText: "确定",
|
|
|
|
+ cancelButtonText: "取消",
|
|
|
|
+ type: "warning"
|
|
})
|
|
})
|
|
.then(() => {
|
|
.then(() => {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- this.$store.commit('logout', 'false')
|
|
|
|
- this.$router.push({ path: '/login' })
|
|
|
|
|
|
+ this.$store.commit("logout", "false");
|
|
|
|
+ this.$router.push({ path: "/login" });
|
|
this.$message({
|
|
this.$message({
|
|
- type: 'success',
|
|
|
|
- message: '已退出登录!'
|
|
|
|
- })
|
|
|
|
- }, 1000)
|
|
|
|
|
|
+ type: "success",
|
|
|
|
+ message: "已退出登录!"
|
|
|
|
+ });
|
|
|
|
+ }, 1000);
|
|
})
|
|
})
|
|
.catch(() => {
|
|
.catch(() => {
|
|
this.$message({
|
|
this.$message({
|
|
- type: 'info',
|
|
|
|
- message: '已取消'
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
|
|
+ type: "info",
|
|
|
|
+ message: "已取消"
|
|
|
|
+ });
|
|
|
|
+ });
|
|
},
|
|
},
|
|
// 更新授权信息
|
|
// 更新授权信息
|
|
submitUpdateForm(editData) {
|
|
submitUpdateForm(editData) {
|
|
this.$refs[editData].validate(valid => {
|
|
this.$refs[editData].validate(valid => {
|
|
if (valid) {
|
|
if (valid) {
|
|
- if(this.updateForm.password === this.psw){
|
|
|
|
- updateSelf(this.updateForm)
|
|
|
|
- .then(res => {
|
|
|
|
- this.updateFormVisible = false;
|
|
|
|
- this.loading = false;
|
|
|
|
- if (!res.error) {
|
|
|
|
- this.$message({
|
|
|
|
- type: "success",
|
|
|
|
- message: "更新成功"
|
|
|
|
- });
|
|
|
|
- localStorage.setItem('user',JSON.stringify(this.updateForm))
|
|
|
|
- } else {
|
|
|
|
- this.$message({
|
|
|
|
- type: "info",
|
|
|
|
- message: res.error.message
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .catch(err => {
|
|
|
|
- this.updateFormVisible = false;
|
|
|
|
- this.loading = false;
|
|
|
|
- this.$message.error("更新失败,请稍后再试!");
|
|
|
|
- });
|
|
|
|
- }else{
|
|
|
|
|
|
+ if (this.updateForm.password === this.psw) {
|
|
|
|
+ updateSelf(this.updateForm)
|
|
|
|
+ .then(res => {
|
|
|
|
+ this.updateFormVisible = false;
|
|
|
|
+ this.loading = false;
|
|
|
|
+ if (!res.error) {
|
|
|
|
+ this.$message({
|
|
|
|
+ type: "success",
|
|
|
|
+ message: "更新成功"
|
|
|
|
+ });
|
|
|
|
+ localStorage.setItem("user", JSON.stringify(this.updateForm));
|
|
|
|
+ } else {
|
|
|
|
+ this.$message({
|
|
|
|
+ type: "info",
|
|
|
|
+ message: res.error.message
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch(err => {
|
|
|
|
+ this.updateFormVisible = false;
|
|
|
|
+ this.loading = false;
|
|
|
|
+ this.$message.error("更新失败,请稍后再试!");
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
this.$message.error("两次密码输入不一致");
|
|
this.$message.error("两次密码输入不一致");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -141,18 +197,18 @@ export default {
|
|
},
|
|
},
|
|
// 切换显示
|
|
// 切换显示
|
|
toggle(showtype) {
|
|
toggle(showtype) {
|
|
- this.collapsed = !showtype
|
|
|
|
- this.$root.Bus.$emit('toggle', this.collapsed)
|
|
|
|
|
|
+ this.collapsed = !showtype;
|
|
|
|
+ this.$root.Bus.$emit("toggle", this.collapsed);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+};
|
|
</script>
|
|
</script>
|
|
<style scoped>
|
|
<style scoped>
|
|
.el-menu-vertical-demo:not(.el-menu--collapse) {
|
|
.el-menu-vertical-demo:not(.el-menu--collapse) {
|
|
border: none;
|
|
border: none;
|
|
}
|
|
}
|
|
|
|
|
|
-.header-menu /deep/ .el-submenu__title{
|
|
|
|
|
|
+.header-menu /deep/ .el-submenu__title {
|
|
border: none !important;
|
|
border: none !important;
|
|
}
|
|
}
|
|
.submenu {
|
|
.submenu {
|
|
@@ -173,7 +229,7 @@ export default {
|
|
.showimg:active {
|
|
.showimg:active {
|
|
border: none;
|
|
border: none;
|
|
}
|
|
}
|
|
-.img-avatar{
|
|
|
|
|
|
+.img-avatar {
|
|
width: 35px;
|
|
width: 35px;
|
|
height: 35px;
|
|
height: 35px;
|
|
border-radius: 50%;
|
|
border-radius: 50%;
|
|
@@ -181,9 +237,41 @@ export default {
|
|
margin-bottom: 5px;
|
|
margin-bottom: 5px;
|
|
}
|
|
}
|
|
|
|
|
|
-.error-tip{
|
|
|
|
|
|
+.error-tip {
|
|
font-size: 12px;
|
|
font-size: 12px;
|
|
color: rgb(236, 104, 104);
|
|
color: rgb(236, 104, 104);
|
|
margin-left: 10px;
|
|
margin-left: 10px;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+.avatar-box {
|
|
|
|
+ position: relative;
|
|
|
|
+ width: 80px;
|
|
|
|
+ height: 80px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.txt-edit-avatar {
|
|
|
|
+ visibility: hidden;
|
|
|
|
+ width: 100%;
|
|
|
|
+ height: 100%;
|
|
|
|
+ position: absolute;
|
|
|
|
+ color: white;
|
|
|
|
+ text-align: center;
|
|
|
|
+ line-height: 80px;
|
|
|
|
+ left: 0;
|
|
|
|
+ top: 0;
|
|
|
|
+ background: rgb(121, 120, 120);
|
|
|
|
+ opacity: 0.7;
|
|
|
|
+ border-radius: 50%;
|
|
|
|
+ cursor: pointer;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.avatar-box:hover .txt-edit-avatar {
|
|
|
|
+ visibility: visible;
|
|
|
|
+ color:#fff;
|
|
|
|
+}
|
|
|
|
+.btn {
|
|
|
|
+ background-color: indianred;
|
|
|
|
+ padding: 7px 12px;
|
|
|
|
+ color: white;
|
|
|
|
+}
|
|
</style>
|
|
</style>
|