guhongwei 4 years ago
parent
commit
ec54c65c88

+ 20 - 6
src/layout/layout-part/heads.vue

@@ -26,13 +26,14 @@
       <bind @bindDown="bindDown"></bind>
     </el-dialog>
     <el-dialog title="修改密码" :visible.sync="passwdDia" width="30%" :before-close="handleClose">
-      <passwdDias></passwdDias>
+      <passwdDias :form="form" @submitForm="submitForm"></passwdDias>
     </el-dialog>
   </div>
 </template>
 
 <script>
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: login } = createNamespacedHelpers('login');
 import bind from './parts/bind.vue';
 import passwdDias from './parts/passwdDia.vue';
 export default {
@@ -54,13 +55,12 @@ export default {
       bindDia: false,
       // 修改密码
       passwdDia: false,
+      form: {},
     };
   },
-  created() {
-    console.log('denglu');
-    console.log(this.user);
-  },
+  created() {},
   methods: {
+    ...login({ loginUpdate: 'update', logout: 'logout' }),
     // 绑定微信
     bindBtn() {
       this.bindDia = true;
@@ -69,9 +69,23 @@ export default {
     passwdBtn() {
       this.passwdDia = true;
     },
+    // 修改密码提交
+    submitForm({ data }) {
+      data.id = this.user.id;
+      let res = this.loginUpdate(data);
+      if (this.$checkRes(res)) {
+        this.passwdDia = false;
+        this.$message({
+          message: '修改密码成功',
+          type: 'success',
+        });
+        this.logoutBtn();
+      }
+    },
     // 退出登录
     logoutBtn() {
-      alert('退出登录');
+      this.logout();
+      location.reload();
     },
     // 绑定微信关闭
     bindDown() {

+ 4 - 8
src/layout/layout-part/parts/passwdDia.vue

@@ -23,7 +23,9 @@ import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions: login } = createNamespacedHelpers('login');
 export default {
   name: 'passwdDia',
-  props: {},
+  props: {
+    form: null,
+  },
   components: {},
   data: function() {
     return {
@@ -31,20 +33,14 @@ export default {
         oldpasswd: [{ required: true, message: '请输入旧密码', trigger: 'blur' }],
         newpasswd: [{ required: true, message: '请输入新密码', trigger: 'blur' }],
       },
-      form: {},
     };
   },
   created() {},
   methods: {
-    ...login({ loginUpdate: 'update' }),
     submitForm(formName) {
       this.$refs[formName].validate(async valid => {
         if (valid) {
-          this.form.id = this.user.id;
-          let res = this.loginUpdate(this.form);
-          if (this.$checkRes(res)) {
-            this.$router.push('/login');
-          }
+          this.$emit('submitForm', { data: this.form });
         } else {
           console.log('error submit!!');
           return false;

+ 4 - 2
src/store/user/mutations.js

@@ -16,6 +16,8 @@ export const setUser = (state, payload) => {
 };
 
 export const deleteUser = (state, payload) => {
-  state.user = {};
-  localStorage.removeItem('user');
+  console.log(state);
+  console.log('nasifd');
+  // state.user = {};
+  // localStorage.removeItem('token');
 };