Explorar o código

feat: 完善修改密码功能,更新相关API和用户管理界面交互

laiqi hai 11 meses
pai
achega
92c642332c

+ 4 - 1
apps/web-ele/src/api/account/index.ts

@@ -53,7 +53,10 @@ export async function addAccountApi(data: AccountEntity) {
  * 账号信息_编辑
  */
 export async function editAccountApi(data: AccountEntity) {
-  return requestClient.post<any>('/api/up?pagevalue=71', { ...data });
+  return requestClient.post<any>('/api/up?pagevalue=71', {
+    'accountid.value': data.accountid,
+    ...data,
+  });
 }
 
 /**

+ 32 - 1
apps/web-ele/src/layouts/basic.vue

@@ -15,11 +15,18 @@ import {
 } from '@vben/layouts';
 import { preferences } from '@vben/preferences';
 import { useAccessStore, useUserStore } from '@vben/stores';
+
+import { ElMessageBox } from 'element-plus';
 // import { openWindow } from '@vben/utils';
 
 // import { $t } from '#/locales';
 import { useAuthStore } from '#/store';
 import LoginForm from '#/views/_core/authentication/login.vue';
+import ChangePasswordForm from '#/views/system-manage/user-manage/change-password-form.vue';
+
+const changePasswordFormRef = ref<InstanceType<
+  typeof ChangePasswordForm
+> | null>(null);
 
 const notifications = ref<NotificationItem[]>([
   // {
@@ -60,10 +67,18 @@ const showDot = computed(() =>
   notifications.value.some((item) => !item.isRead),
 );
 
+function handleChangePassword() {
+  if (userStore.userInfo?.accountid) {
+    changePasswordFormRef.value?.openModal({
+      accountid: userStore.userInfo.accountid,
+    });
+  }
+}
+
 const menus = computed(() => [
   {
     handler: () => {
-      // ...
+      handleChangePassword();
     },
     icon: MdiOnepassword,
     text: '修改密码',
@@ -135,6 +150,21 @@ watch(
     immediate: true,
   },
 );
+
+// 修改密码完成后回调
+const handleFinish = () => {
+  ElMessageBox.confirm('密码修改成功,请重新登录', '提示', {
+    confirmButtonText: '重新登录',
+    cancelButtonText: '取消',
+    type: 'success',
+  })
+    .then(async () => {
+      await handleLogout();
+    })
+    .catch(() => {
+      // catch cancel action
+    });
+};
 </script>
 
 <template>
@@ -169,4 +199,5 @@ watch(
       <LockScreen :avatar @to-login="handleLogout" />
     </template>
   </BasicLayout>
+  <ChangePasswordForm ref="changePasswordFormRef" @finish="handleFinish" />
 </template>

+ 5 - 5
apps/web-ele/src/views/system-manage/user-manage/change-password-form.vue

@@ -33,14 +33,14 @@ const schema: VbenFormSchema[] = [
     fieldName: 'confirmPassword',
     label: '确认密码',
     rules: z.string().min(1, '请再次输入新密码'),
-    componentProps: ({ form }) => ({
+    componentProps: {
       type: 'password',
       placeholder: '请再次输入新密码',
       showPassword: true,
       onBlur: () => {
-        form.validateField('accountpwd');
+        baseFormApi.validateField('accountpwd');
       },
-    }),
+    },
   },
 ];
 
@@ -78,9 +78,9 @@ const [Modal, modalApi] = useVbenModal({
 
     try {
       await editAccountApi({
-        'accountid.value': data.value.row.accountid,
+        accountid: data.value.row.accountid,
         accountpwd: md5(values.accountpwd),
-      } as any);
+      } as AccountEntity);
 
       ElMessage.success('密码修改成功!');
       emit('finish');

+ 6 - 1
apps/web-ele/src/views/system-manage/user-manage/index.vue

@@ -285,7 +285,12 @@ function handleFinish() {
         >
           <el-button
             round
-            @click="() => handleChangePassword(row)"
+            @click="
+              () =>
+                handleChangePassword({
+                  accountid: row.accountid,
+                })
+            "
             :icon="MdiPasswordVerified"
             class="!p-2"
           />