浏览代码

修改密码修改方式 支持普通修改

Co-authored-by: Copilot <copilot@github.com>
hurx 12 小时之前
父节点
当前提交
0c74157417

+ 11 - 0
src/api/pc/enterprise/index.ts

@@ -35,6 +35,17 @@ export function changePwd(data: any) {
   });
 }
 
+/**
+ * 修改密码  普通
+ */
+export function normalChangePwd(data: any) {
+  return request({
+    url: '/system/psSysUser/normalChangePwd', // 密码修改
+    method: 'put',
+    data: data
+  });
+}
+
 // ==================== 收货地址管理 ====================
 
 /**

+ 84 - 0
src/views/enterprise/securitySetting/index.vue

@@ -32,6 +32,17 @@
         </div>
         <el-button type="danger" @click="handleModifyPassword">修改</el-button>
       </div>
+      <!-- 修改密码(普通) -->
+      <div class="setting-card">
+        <div class="setting-icon">
+          <el-icon :size="20" color="#fff"><Grid /></el-icon>
+        </div>
+        <div class="setting-content">
+          <div class="setting-title">修改密码(普通)</div>
+          <div class="setting-desc">适用于记得原密码时,直接更新登录密码</div>
+        </div>
+        <el-button type="danger" @click="handleChangePassword">修改</el-button>
+      </div>
 
       <!-- 安全手机 -->
       <div class="setting-card">
@@ -65,6 +76,25 @@
       </template>
     </el-dialog>
 
+    <!-- 普通修改密码弹窗 -->
+    <el-dialog v-model="normalPasswordDialogVisible" title="修改密码" width="450px">
+      <el-form ref="normalPasswordFormRef" :model="normalPasswordForm" :rules="normalPasswordRules" label-width="100px">
+        <el-form-item label="当前密码" prop="oldPassword">
+          <el-input v-model="normalPasswordForm.oldPassword" type="password" show-password placeholder="请输入当前密码" />
+        </el-form-item>
+        <el-form-item label="新密码" prop="newPassword">
+          <el-input v-model="normalPasswordForm.newPassword" type="password" show-password placeholder="请输入新密码" />
+        </el-form-item>
+        <el-form-item label="确认密码" prop="confirmPassword">
+          <el-input v-model="normalPasswordForm.confirmPassword" type="password" show-password placeholder="请确认新密码" />
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <el-button @click="normalPasswordDialogVisible = false">取消</el-button>
+        <el-button type="danger" @click="handleSaveNormalPassword">确认</el-button>
+      </template>
+    </el-dialog>
+
     <!-- 修改手机弹窗 -->
     <el-dialog v-model="phoneDialogVisible" title="修改安全手机" width="450px">
       <el-form ref="phoneFormRef" :model="phoneForm" :rules="phoneRules" label-width="100px">
@@ -93,6 +123,7 @@ import { ref, reactive } from 'vue';
 import { useRouter } from 'vue-router';
 import { ArrowLeft, OfficeBuilding, Grid } from '@element-plus/icons-vue';
 import { ElMessage } from 'element-plus';
+import { changePwd, normalChangePwd } from '@/api/pc/enterprise/index';
 import { getCurrentUserInfo, updateComStaff } from '@/api/pc/organization/index';
 
 const router = useRouter();
@@ -104,6 +135,11 @@ const passwordDialogVisible = ref(false);
 const passwordFormRef = ref();
 const passwordForm = reactive({ oldPassword: '', newPassword: '', confirmPassword: '' });
 
+// 普通修改密码弹窗相关
+const normalPasswordDialogVisible = ref(false);
+const normalPasswordFormRef = ref();
+const normalPasswordForm = reactive({ oldPassword: '', newPassword: '', confirmPassword: '' });
+
 const validateConfirmPassword = (_rule: any, value: string, callback: any) => {
   if (value !== passwordForm.newPassword) {
     callback(new Error('两次输入的密码不一致'));
@@ -112,6 +148,14 @@ const validateConfirmPassword = (_rule: any, value: string, callback: any) => {
   }
 };
 
+const validateNormalConfirmPassword = (_rule: any, value: string, callback: any) => {
+  if (value !== normalPasswordForm.newPassword) {
+    callback(new Error('两次输入的密码不一致'));
+  } else {
+    callback();
+  }
+};
+
 const passwordRules = {
   oldPassword: [{ required: true, message: '请输入原密码', trigger: 'blur' }],
   newPassword: [
@@ -124,6 +168,18 @@ const passwordRules = {
   ]
 };
 
+const normalPasswordRules = {
+  oldPassword: [{ required: true, message: '请输入当前密码', trigger: 'blur' }],
+  newPassword: [
+    { required: true, message: '请输入新密码', trigger: 'blur' },
+    { min: 6, max: 20, message: '密码长度为6-20位', trigger: 'blur' }
+  ],
+  confirmPassword: [
+    { required: true, message: '请确认新密码', trigger: 'blur' },
+    { validator: validateNormalConfirmPassword, trigger: 'blur' }
+  ]
+};
+
 const phoneDialogVisible = ref(false);
 const phoneFormRef = ref();
 const phoneForm = reactive({ phone: '', code: '' });
@@ -148,6 +204,34 @@ const handleModifyPassword = () => {
     }
   });
 };
+const handleChangePassword = () => {
+  normalPasswordDialogVisible.value = true;
+};
+
+const handleSaveNormalPassword = async () => {
+  const valid = await normalPasswordFormRef.value?.validate();
+  if (!valid) return;
+
+  try {
+    const submitData = {
+      oldPassword: normalPasswordForm.oldPassword,
+      password: normalPasswordForm.newPassword,
+      confirmPassword: normalPasswordForm.confirmPassword
+    };
+
+    const res: any = await normalChangePwd(submitData);
+    if (res.code === 200) {
+      ElMessage.success('密码修改成功');
+    }
+  } catch (error) {
+    // console.error('修改密码失败:', error);
+  }
+  normalPasswordDialogVisible.value = false;
+  normalPasswordForm.oldPassword = '';
+  normalPasswordForm.newPassword = '';
+  normalPasswordForm.confirmPassword = '';
+};
+
 const getCurrentUser = async () => {
   const res = await getCurrentUserInfo();
   companyData.contactName = res.data.contactName;

+ 2 - 0
src/views/enterprise/securitySetting/resetPassword.vue

@@ -118,6 +118,7 @@ const step1Rules = {
 // 步骤2表单
 const step2FormRef = ref();
 const step2Form = reactive({
+  phonenumber: route.query.phone as any,
   newPassword: '',
   confirmPassword: ''
 });
@@ -201,6 +202,7 @@ const handleSubmit = async () => {
   try {
     const submitData = {
       phone: step1Form.phone,
+      phonenumber: step1Form.phone,
       code: step1Form.code,
       password: step2Form.newPassword,
       confirmPassword: step2Form.confirmPassword