Ver código fonte

fix: bug#7509

xieyonghong 3 anos atrás
pai
commit
55f18ea560

+ 6 - 0
src/pages/system/Menu/Detail/index.tsx

@@ -15,6 +15,7 @@ export default () => {
   const intl = useIntl();
   const [tabKey, setTabKey] = useState('detail');
   const [pId, setPid] = useState<string | null>(null);
+  const [sortIndex, setSortIndex] = useState<string | null>(null);
   const location = useLocation<LocationType>();
   const params: any = new URLSearchParams(location.search);
   const param = useParams<{ id?: string }>();
@@ -32,12 +33,16 @@ export default () => {
   const queryDetail = (editId?: string) => {
     const id = editId || param.id;
     const _pId = params.get('pId');
+    const _sortIndex = params.get('sortIndex');
     if (id && id !== ':id') {
       queryData(id);
     }
     if (_pId) {
       setPid(_pId);
     }
+    if (_sortIndex) {
+      setSortIndex(_sortIndex);
+    }
   };
 
   useEffect(() => {
@@ -74,6 +79,7 @@ export default () => {
           data={{
             ...data,
             parentId: pId,
+            sortIndex: sortIndex,
           }}
           basePath={params.get('basePath')}
           onLoad={queryDetail}

+ 40 - 41
src/pages/system/Menu/index.tsx

@@ -45,6 +45,7 @@ export default observer(() => {
   const history = useHistory();
   const { permission } = PermissionButton.usePermission('system/Menu');
   const { initialState } = useModel('@@initialState');
+  const lastIndex = useRef(0);
 
   const deleteItem = async (id: string) => {
     const response: any = await service.remove(id);
@@ -65,12 +66,26 @@ export default observer(() => {
    * @param pId
    * @param basePath
    */
-  const pageJump = (id?: string, pId?: string, basePath?: string) => {
+  const pageJump = (id?: string, pId?: string, basePath?: string, record?: MenuItem) => {
+    const params = new URLSearchParams();
+    params.set('pId', pId || '');
+    params.set('basePath', basePath || '');
+    // 新增
+    if (!id) {
+      if (record) {
+        // 新增子级,并且有子级的情况下
+        if (record.children && record.children.length) {
+          params.set('sortIndex', record.children[record.children.length - 1].sortIndex + 1 + '');
+        } else {
+          params.set('sortIndex', '1');
+        }
+      } else {
+        params.set('sortIndex', lastIndex.current + '');
+      }
+    }
     // 跳转详情
     history.push(
-      `${getMenuPathByParams(MENUS_CODE['system/Menu/Detail'], id)}?pId=${pId || ''}&basePath=${
-        basePath || ''
-      }`,
+      `${getMenuPathByParams(MENUS_CODE['system/Menu/Detail'], id)}?${params.toString()}`,
     );
   };
 
@@ -150,7 +165,7 @@ export default observer(() => {
           key="view"
           style={{ padding: 0 }}
           onClick={() => {
-            pageJump(record.id, record.parentId || '');
+            pageJump(record.id, record.parentId || '', '', record);
           }}
         >
           <Tooltip
@@ -178,7 +193,7 @@ export default observer(() => {
               parentId: record.id,
             };
             // State.visible = true;
-            pageJump('', record.id, record.url);
+            pageJump('', record.id, record.url, record);
           }}
         >
           <PlusCircleOutlined />
@@ -287,41 +302,25 @@ export default observer(() => {
               },
             ],
           };
-          if (params.terms && params.length !== 0) {
-            const response = await service.queryMenuThree({
-              ...params,
-              terms: [...param.terms, item],
-              sorts: [{ name: 'sortIndex', order: 'asc' }],
-              paging: false,
-            });
-            return {
-              code: response.message,
-              result: {
-                data: response.result,
-                pageIndex: 0,
-                pageSize: 0,
-                total: 0,
-              },
-              status: response.status,
-            };
-          } else {
-            const response = await service.queryMenuThree({
-              ...params,
-              terms: [item],
-              sorts: [{ name: 'sortIndex', order: 'asc' }],
-              paging: false,
-            });
-            return {
-              code: response.message,
-              result: {
-                data: response.result,
-                pageIndex: 0,
-                pageSize: 0,
-                total: 0,
-              },
-              status: response.status,
-            };
-          }
+          const response = await service.queryMenuThree({
+            ...params,
+            terms: params.terms && params.length !== 0 ? [...param.terms, item] : [item],
+            sorts: [{ name: 'sortIndex', order: 'asc' }],
+            paging: false,
+          });
+          const lastItem = response.result[response.result.length - 1];
+
+          lastIndex.current = lastItem ? lastItem.sortIndex + 1 : 1;
+          return {
+            code: response.message,
+            result: {
+              data: response.result,
+              pageIndex: 0,
+              pageSize: 0,
+              total: 0,
+            },
+            status: response.status,
+          };
         }}
         headerTitle={[
           <PermissionButton