navcon.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * 头部菜单
  3. */
  4. <template>
  5. <div class="header-menu">
  6. <el-menu class="el-menu-demo" mode="horizontal" background-color="#334157" text-color="#fff" active-text-color="#fff">
  7. <el-button class="buttonimg">
  8. <img class="showimg" :src="collapsed?imgsq:imgshow" @click="toggle(collapsed)">
  9. </el-button>
  10. <el-submenu index="2" class="submenu">
  11. <!-- <template slot="title">{{user.userRealName}}</template> -->
  12. <template slot="title">
  13. <span>
  14. <img :src="user.avatar" alt="" class="img-avatar">
  15. </span>
  16. {{user.username}}
  17. </template>
  18. <el-menu-item @click="handleSetInfo()" index="2-2">个人中心</el-menu-item>
  19. <el-menu-item @click="exit()" index="2-3">退出</el-menu-item>
  20. </el-submenu>
  21. </el-menu>
  22. <el-dialog title="个人中心" :visible.sync="updateFormVisible" width="30%" @click="closeDialog">
  23. <el-form label-width="120px" :model="updateForm" :rules="rules" ref="updateForm" label-position="top">
  24. <el-form-item label="设置头像" prop="expires">
  25. <img :src="updateForm.avatar" alt="" style="border-radius:50%;width:80px">
  26. </el-form-item>
  27. <el-form-item label="修改账号" prop="expires">
  28. <el-input v-model="updateForm.account" :disabled="updateForm.setaccount === 0" auto-complete="off" placeholder="请输入新账号"></el-input>
  29. <p class="error-tip">当前用户可修改账号次数为 0</p>
  30. </el-form-item>
  31. <el-form-item label="设置新密码" prop="password">
  32. <el-input type="password" v-model="updateForm.password" label="请输入新密码"></el-input>
  33. </el-form-item>
  34. <el-form-item label="确认新密码" prop="password">
  35. <el-input type="password" v-model="psw" label="请确认新密码"></el-input>
  36. </el-form-item>
  37. </el-form>
  38. <div slot="footer" class="dialog-footer">
  39. <el-button @click="closeDialog">取消</el-button>
  40. <el-button
  41. type="primary"
  42. :loading="loading"
  43. class="title"
  44. @click="submitUpdateForm('updateForm')"
  45. >保存</el-button>
  46. </div>
  47. </el-dialog>
  48. </div>
  49. </template>
  50. <script>
  51. import { updateSelf } from '../api/basisMG'
  52. export default {
  53. name: 'navcon',
  54. data() {
  55. return {
  56. updateFormVisible:false,
  57. updateForm:{},
  58. psw:"",
  59. collapsed: true,
  60. imgshow: require('../assets/img/show.png'),
  61. imgsq: require('../assets/img/sq.png'),
  62. user: {},
  63. // rules表单验证
  64. rules: {
  65. password: [
  66. { required: false, message: "请输入新密码", trigger: "blur" }
  67. ]
  68. },
  69. }
  70. },
  71. // 创建完毕状态(里面是操作)
  72. created() {
  73. this.user = JSON.parse(localStorage.getItem('user'))
  74. this.updateForm = this.user
  75. },
  76. methods: {
  77. handleSetInfo(){
  78. this.updateForm.password = ''
  79. this.updateFormVisible = true
  80. },
  81. // 退出登录
  82. exit() {
  83. this.$confirm('退出登录, 是否继续?', '提示', {
  84. confirmButtonText: '确定',
  85. cancelButtonText: '取消',
  86. type: 'warning'
  87. })
  88. .then(() => {
  89. setTimeout(() => {
  90. this.$store.commit('logout', 'false')
  91. this.$router.push({ path: '/login' })
  92. this.$message({
  93. type: 'success',
  94. message: '已退出登录!'
  95. })
  96. }, 1000)
  97. })
  98. .catch(() => {
  99. this.$message({
  100. type: 'info',
  101. message: '已取消'
  102. })
  103. })
  104. },
  105. // 更新授权信息
  106. submitUpdateForm(editData) {
  107. this.$refs[editData].validate(valid => {
  108. if (valid) {
  109. if(this.updateForm.password === this.psw){
  110. updateSelf(this.updateForm)
  111. .then(res => {
  112. this.updateFormVisible = false;
  113. this.loading = false;
  114. if (!res.error) {
  115. this.$message({
  116. type: "success",
  117. message: "更新成功"
  118. });
  119. localStorage.setItem('user',JSON.stringify(this.updateForm))
  120. } else {
  121. this.$message({
  122. type: "info",
  123. message: res.error.message
  124. });
  125. }
  126. })
  127. .catch(err => {
  128. this.updateFormVisible = false;
  129. this.loading = false;
  130. this.$message.error("更新失败,请稍后再试!");
  131. });
  132. }else{
  133. this.$message.error("两次密码输入不一致");
  134. }
  135. } else {
  136. return false;
  137. }
  138. });
  139. },
  140. // 切换显示
  141. toggle(showtype) {
  142. this.collapsed = !showtype
  143. this.$root.Bus.$emit('toggle', this.collapsed)
  144. }
  145. }
  146. }
  147. </script>
  148. <style scoped>
  149. .el-menu-vertical-demo:not(.el-menu--collapse) {
  150. border: none;
  151. }
  152. .header-menu /deep/ .el-submenu__title{
  153. border: none !important;
  154. }
  155. .submenu {
  156. float: right;
  157. }
  158. .buttonimg {
  159. height: 60px;
  160. background-color: transparent;
  161. border: none;
  162. }
  163. .showimg {
  164. width: 26px;
  165. height: 26px;
  166. position: absolute;
  167. top: 17px;
  168. left: 17px;
  169. }
  170. .showimg:active {
  171. border: none;
  172. }
  173. .img-avatar{
  174. width: 35px;
  175. height: 35px;
  176. border-radius: 50%;
  177. margin-right: 10px;
  178. margin-bottom: 5px;
  179. }
  180. .error-tip{
  181. font-size: 12px;
  182. color: rgb(236, 104, 104);
  183. margin-left: 10px;
  184. }
  185. </style>