浏览代码

feat: 部门和物料增加同步设置

xyh 2 年之前
父节点
当前提交
8a67782e06

+ 8 - 0
packages/app/src/apis/dictionary.ts

@@ -138,3 +138,11 @@ export function getAllMaterialList(
     signal,
   });
 }
+
+/** 同步部门信息 */
+export function syncDepartment(): BaseResult {
+  return request({
+    url: `${BASE_URL}/synchronizationDepartment`,
+    method: 'GET',
+  });
+}

+ 8 - 0
packages/app/src/apis/material.ts

@@ -68,3 +68,11 @@ export function exportMatter(data: GetMatterListparams): any {
     skipError: true,
   });
 }
+
+/** 同步物料 */
+export function syncMaterial(): BaseResult {
+  return request({
+    method: 'GET',
+    url: '/dictionary/synchronizationMaterial',
+  });
+}

+ 1 - 1
packages/app/src/components/table-tools/index.tsx

@@ -121,7 +121,6 @@ const TableTools: ChildrenFC<Props> = function({
             导出
           </Button>
         )}
-        {children}
         <Button
           data-testid="save_setting_btn"
           loading={isSaveing}
@@ -130,6 +129,7 @@ const TableTools: ChildrenFC<Props> = function({
         >
           保存配置
         </Button>
+        {children}
       </Space>
     </section>
   );

+ 24 - 3
packages/app/src/pages/dictionary/table/index.tsx

@@ -1,14 +1,16 @@
 import {FC} from 'react';
 import {useDicionaryType} from '../hooks';
-import {Card} from 'antd';
+import {Button, Card, message} from 'antd';
 import {Table, TableTools} from '@components';
 import {context, pageContext, searchContext} from '../context';
 import PutModal from './modal';
-import {getDictionaryList} from '@apis';
+import {getDictionaryList, syncDepartment} from '@apis';
 import {useContextSection, useQueryTableList, useSupertube} from '@hooks';
 import {OriginalListParams, GetDictionaryListParams} from '@models';
 import StorageModal from './type-modal';
 import {useHandle} from './hooks';
+import {useMutation} from '@tanstack/react-query';
+import {Sync} from '@icon-park/react';
 
 const TableList: FC = function() {
   const type = useDicionaryType();
@@ -34,6 +36,17 @@ const TableList: FC = function() {
     {onAdd, onClose, onEditStoreClose},
   ] = useHandle(refetch);
   const isSuper = useSupertube();
+
+  const {isLoading, mutate} = useMutation({
+    mutationFn: syncDepartment,
+    onSuccess({msg}) {
+      if (msg === '200') {
+        refetch();
+        message.success('同步完成');
+      }
+    },
+  });
+
   return (
     <>
       <Card className="table-wrapper">
@@ -42,7 +55,15 @@ const TableList: FC = function() {
           onAdd={isSuper ? onAdd : void 0}
           pageContext={pageContext}
           searchContext={searchContext}
-        />
+        >
+          {type === '部门字典' && <Button
+            icon={<Sync theme="outline" className="anticon" />}
+            loading={isLoading}
+            onClick={() => mutate()}
+          >
+            同步
+          </Button>}
+        </TableTools>
 
         <Table
           columns={columns}

+ 22 - 3
packages/app/src/pages/goods/table/index.tsx

@@ -1,16 +1,18 @@
 import {Table, TableTools} from '@components';
-import {Card} from 'antd';
+import {Button, Card, message} from 'antd';
 import {FC} from 'react';
 import {useHandle} from './hooks';
 import {context, pageContext, searchContext} from '../context';
 import EditModal from './modal';
-import {exportMaterial, getDictionaryList} from '@apis';
+import {exportMaterial, getDictionaryList, syncMaterial} from '@apis';
 import {
   useContextSection,
   useQueryTableList,
   useTableExportEvent,
 } from '@hooks';
 import {DictionaryParamsType} from '@models';
+import {useMutation} from '@tanstack/react-query';
+import {Sync} from '@icon-park/react';
 
 const TableList: FC = function() {
   const params = useContextSection(context, state => state[0]);
@@ -30,6 +32,15 @@ const TableList: FC = function() {
       return {...state, type: '物料字典' as DictionaryParamsType};
     },
   });
+  const {isLoading, mutate} = useMutation({
+    mutationFn: syncMaterial,
+    onSuccess({msg}) {
+      if (msg === '200') {
+        message.success('同步完成');
+        refetch();
+      }
+    },
+  });
 
   return (
     <>
@@ -39,7 +50,15 @@ const TableList: FC = function() {
           searchContext={searchContext}
           isExporting={isExporting}
           onExport={onExport}
-        />
+        >
+          <Button
+            icon={<Sync theme="outline" className="anticon" />}
+            loading={isLoading}
+            onClick={() => mutate()}
+          >
+            同步
+          </Button>
+        </TableTools>
 
         <Table
           data-testid="goods_table"