Prechádzať zdrojové kódy

fix: ConnectModal onReload bug

lanjianrong 4 rokov pred
rodič
commit
7bfc246e9a

+ 21 - 24
src/pages/Business/Attendance/index.tsx

@@ -13,7 +13,6 @@ export enum modalType {
 const Attendance: React.FC = () => {
   const [state, setState] = useState({
     id: '',
-    modalId: '',
     attendanceList: [],
     visible: false,
     type: modalType.addobjectModal
@@ -21,8 +20,6 @@ const Attendance: React.FC = () => {
 
   const { run: tryGetRoleStaffList } = useRequest(fetchAttendanceList, {
     onSuccess: result => {
-      console.log('result', result)
-
       setState({ ...state, attendanceList: result })
     }
   })
@@ -62,33 +59,33 @@ const Attendance: React.FC = () => {
       dataIndex: 'staff',
       align: 'left',
       width: '70%',
-      render: (_, record: API.AttendanceItem) => (
-        <div>
-          {record.staff.map(item => (
-            // console.log(item.staffName)
-            <span key={item.staffId} className="zh-mg-bottom-5 zh-block">
+      render: (_, record: API.AttendanceItem) => {
+        return (
+          <div>
+            {record.staff.map(item => (
               <Tag
+                key={item.staffId}
                 closable={true}
                 onClose={() => tryunlinkAttendance({ staffId: item.staffId, id: record.id })}>
                 {item.staffName}
               </Tag>
+            ))}
+            <span
+              className="hover:text-hex-886ab5 cursor-pointer text-purple-500"
+              onClick={() =>
+                setState({
+                  ...state,
+                  id: record.id,
+                  visible: true,
+                  type: modalType.linkAttendance
+                })
+              }>
+              <Plus />
+              添加
             </span>
-          ))}
-          <span
-            className="hover:text-hex-886ab5 cursor-pointer text-purple-500"
-            onClick={() =>
-              setState({
-                ...state,
-                id: record.id,
-                visible: true,
-                type: modalType.linkAttendance
-              })
-            }>
-            <Plus />
-            添加
-          </span>
-        </div>
-      )
+          </div>
+        )
+      }
     },
     {
       title: '操作',

+ 9 - 6
src/pages/Role/System/components/ConnectModal/index.tsx

@@ -36,9 +36,12 @@ const ConnectModal: React.FC<ConnectModalProps> = ({
       }),
     {
       manual: true,
-      onSuccess: () => {
+      onSuccess: async () => {
         message.success('关联成功')
-        setVisible(false)
+        if (!show) {
+          setVisible(false)
+        }
+        await onReload()
       },
       onError: e => {
         message.error(e.message)
@@ -96,10 +99,10 @@ const ConnectModal: React.FC<ConnectModalProps> = ({
       params.id = dataId
     }
     await tryConnectStaff(params)
-    // 动态
-    if (onReload) {
-      await onReload()
-    }
+    // // 动态
+    // if (onReload) {
+    //   await onReload()
+    // }
     handleOnCancel()
   }
   return (