Forráskód Böngészése

feat: add modufy passwoed

wangyuan 2 éve
szülő
commit
acad6fe490
2 módosított fájl, 74 hozzáadás és 2 törlés
  1. 9 0
      ittpc/src/request/request.js
  2. 65 2
      ittpc/src/views/modules/main.vue

+ 9 - 0
ittpc/src/request/request.js

@@ -44,6 +44,9 @@ const setRegionConfigURL = BASE_API + '/set/region/config/v1'
 // 图片上传
 export const userUploadHeadImg = BASE_API + '/user/upload/headImg/v1'
 
+//修改密码
+const pwdResetPwdURL = BASE_API + '/pwd/reset/pwd/v1'
+
 export const pwdLogin = (data) => {
   return request.post(pwdLoginURL, data)
 }
@@ -95,3 +98,9 @@ export const editRegion = (data) => {
 export const setRegionConfig = (data) => {
   return request.post(setRegionConfigURL, data)
 }
+
+export const pwdResetPwd = (data) => {
+  return request.post(pwdResetPwdURL, data)
+}
+
+

+ 65 - 2
ittpc/src/views/modules/main.vue

@@ -9,6 +9,7 @@
         <div class="header-right userinfo">
           <!-- <div class="headimg"></div> -->
           <div class="username">{{userName}}</div>
+          <el-button type="text" @click="handleModifyPwd">修改密码</el-button>
           <el-button type="text" @click="handleLogout">退出</el-button>
         </div>
       </el-header>
@@ -46,16 +47,46 @@
         </el-main>
       </el-container>
     </el-container>
+    <el-dialog title="修改密码" :visible.sync="dialogFormVisible" width="600px" @close="close">
+      <el-form :model="form" size="small" :rules="rules" ref="form">
+        <el-form-item label="新密码" prop="password" :label-width="formLabelWidth">
+          <el-input v-model="form.password" placeholder="请输入新密码"></el-input>
+        </el-form-item>
+        <el-form-item label="原密码" prop="oldPassword" :label-width="formLabelWidth">
+          <el-input v-model="form.oldPassword" placeholder="请输入原密码"></el-input>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button size="small" @click="dialogFormVisible = false">取 消</el-button>
+        <el-button size="small" type="primary" @click="submitPwd" :loading="loading">确 定</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
 <script>
+import { pwdResetPwd } from '@/request/request'
 export default {
   name: 'Main',
   data() {
     return {
       defaultActive: '/main/user',
-      userName: ''
+      userName: '',
+      form: {
+        password: '',
+        oldPassword: ''
+      },
+      formLabelWidth: '80px',
+      dialogFormVisible: false,
+      loading: false,
+      rules: {
+        password: [
+          { required: true, message: '请输入新密码', trigger: 'change' }
+        ],
+        oldPassword: [
+          { required: true, message: '请输入原密码', trigger: 'change' }
+        ]
+      },
     };
   },
   watch: {
@@ -79,10 +110,42 @@ export default {
       console.log(index);
     },
     handleLogout () {
-      this.$confirm('确定退出吗?').then( _=> {
+      this.$confirm('确定退出吗?','提示').then( _=> {
         sessionStorage.clear()
         this.$router.replace('/login')
       }).catch(_ => {});
+    },
+    close () {
+      this.form.password = ''
+      this.form.oldPassword = ''
+      this.$refs['form'].clearValidate()
+    },
+    handleModifyPwd () {
+      this.dialogFormVisible = true
+    },
+    submitPwd () {
+      this.$refs['form'].validate((valid) => {
+        if (valid) {
+          let data = {
+            password: this.form.password,
+            oldPassword: this.form.oldPassword
+          }
+          this.loading = true
+          pwdResetPwd(data).then(res => {
+            this.dialogFormVisible = false
+            this.loading = false
+            this.$message({
+              message: '密码修改成功',
+              type: 'success'
+            })
+          }).catch(e => {
+            this.loading = false
+            console.log(e);
+          })
+        } else {
+          return false;
+        }
+      });
     }
   }
 };