Przeglądaj źródła

feat(第三方平台): 对接重置密码接口

xieyonghong 3 lat temu
rodzic
commit
cd6dbce8c1

+ 4 - 5
src/pages/system/Platforms/index.tsx

@@ -20,7 +20,7 @@ export default () => {
   const [param, setParam] = useState({});
   const [saveVisible, setSaveVisible] = useState(false);
   const [passwordVisible, setPasswordVisible] = useState(false);
-  const [editData, setEditData] = useState<ActionType | undefined>(undefined);
+  const [editData, setEditData] = useState<any | undefined>(undefined);
 
   const { permission } = PermissionButton.usePermission('system/Platforms');
 
@@ -93,7 +93,7 @@ export default () => {
       valueType: 'option',
       align: 'center',
       width: 200,
-      render: (_, record) => [
+      render: (_, record: any) => [
         <PermissionButton
           key={'update'}
           type={'link'}
@@ -144,6 +144,7 @@ export default () => {
             title: '重置密码',
           }}
           onClick={() => {
+            setEditData({ id: record.userId });
             setPasswordVisible(true);
           }}
         >
@@ -224,9 +225,7 @@ export default () => {
         onCancel={() => {
           setPasswordVisible(false);
         }}
-        onReload={() => {
-          actionRef.current?.reload();
-        }}
+        data={editData}
       />
     </PageContainer>
   );

+ 27 - 13
src/pages/system/Platforms/password.tsx

@@ -2,7 +2,7 @@ import { createForm } from '@formily/core';
 import { createSchemaField } from '@formily/react';
 import { Form, FormGrid, FormItem, Password } from '@formily/antd';
 import { message, Modal } from 'antd';
-import { useMemo, useState } from 'react';
+import { useCallback, useMemo, useState } from 'react';
 import type { ISchema } from '@formily/json-schema';
 import { service } from '@/pages/system/Platforms/index';
 
@@ -29,9 +29,8 @@ export default (props: SaveProps) => {
     () =>
       createForm({
         validateFirst: true,
-        initialValues: props.data || { oath2: true },
       }),
-    [props.data],
+    [],
   );
 
   const schema: ISchema = {
@@ -45,6 +44,7 @@ export default (props: SaveProps) => {
         'x-component': 'Password',
         'x-component-props': {
           placeholder: '请输入密码',
+          checkStrength: true,
         },
         'x-decorator-props': {
           gridSpan: 1,
@@ -62,8 +62,26 @@ export default (props: SaveProps) => {
         ],
         'x-validator': [
           {
-            max: 64,
-            message: '最多可输入64个字符',
+            triggerType: 'onBlur',
+            validator: (value: string) => {
+              return new Promise((resolve) => {
+                service
+                  .validateField('password', value)
+                  .then((resp) => {
+                    if (resp.status === 200) {
+                      if (resp.result.passed) {
+                        resolve('');
+                      } else {
+                        resolve(resp.result.reason);
+                      }
+                    }
+                    resolve('');
+                  })
+                  .catch(() => {
+                    return '验证失败!';
+                  });
+              });
+            },
           },
           {
             required: true,
@@ -79,6 +97,7 @@ export default (props: SaveProps) => {
         'x-component': 'Password',
         'x-component-props': {
           placeholder: '请再次输入密码',
+          checkStrength: true,
         },
         'x-decorator-props': {
           gridSpan: 1,
@@ -123,23 +142,18 @@ export default (props: SaveProps) => {
     }
   };
 
-  const saveData = async () => {
-    // setLoading(true)
+  const saveData = useCallback(async () => {
     const data: any = await form.submit();
-    console.log(data);
     if (data) {
       setLoading(true);
-      const resp = await service.update(data);
+      const resp = await service.passwordReset(props.data.id, data.password);
       setLoading(false);
       if (resp.status === 200) {
-        if (props.onReload) {
-          props.onReload();
-        }
         modalClose();
         message.success('操作成功');
       }
     }
-  };
+  }, [props.data]);
 
   return (
     <Modal

+ 6 - 0
src/pages/system/Platforms/service.ts

@@ -19,6 +19,12 @@ class Service extends BaseService<platformsType> {
       method: 'POST',
       data: name,
     });
+
+  passwordReset = (id: string, data: any) =>
+    request(`/${SystemConst.API_BASE}/user/${id}/password/_reset`, {
+      method: 'POST',
+      data,
+    });
 }
 
 export default Service;