Răsfoiți Sursa

[Pref 0000] 优化模型管理页面操作反馈

houzekong 3 luni în urmă
părinte
comite
3c1fd3c23c

+ 0 - 1
src/views/monitor/sealedMonitor/hooks/form.ts

@@ -12,7 +12,6 @@ export function useInitForm() {
   const rawcode = route.query.mineCode as string;
   // 给历史数据默认填充的矿码
   const hiscode = !rawcode ? first(get(dep, 'id', '').split(',')) : rawcode;
-  console.log('debug r', route, rawcode, hiscode);
 
   if (hiscode) {
     // mineStore.setDepartById(code as string);

+ 0 - 1
src/views/monitor/sealedMonitor/monitor.data.ts

@@ -4,7 +4,6 @@ import { FormSchema } from '/@/components/Table';
 import { TreeItem } from '/@/components/Tree/index';
 import { ModuleDataChart } from '/@/components/Configurable/types';
 import { h } from 'vue';
-import { Tag } from 'ant-design-vue';
 
 // 实时数据相关
 export const columns: BasicColumn[] = [

+ 16 - 55
src/views/system/algorithm/algorithm.api.ts

@@ -1,7 +1,6 @@
 import { defHttp } from '/@/utils/http/axios';
-import { isNil } from 'lodash-es';
-import { getEnfMineTree } from '/@/api/sys/menu';
-import { message } from 'ant-design-vue';
+import { isNil, map } from 'lodash-es';
+// import { getEnfMineTree } from '/@/api/sys/menu';
 
 enum Api {
   getMineData = '/province/mineData/getMineData',
@@ -30,9 +29,7 @@ export function updateCoalSeamAlarmRule(params: any) {
   return defHttp.post({ url: Api.updateCoalSeamAlarmRule, params });
 }
 export function addCoalSeamAlarmRule(params: any) {
-  return defHttp.post({ url: Api.addCoalSeamAlarmRule, params }).then(() => {
-    message.success('新增成功');
-  });
+  return defHttp.post({ url: Api.addCoalSeamAlarmRule, params });
 }
 export function deleteCoalSeamAlarmRule(params: any) {
   return defHttp.post({ url: Api.deleteCoalSeamAlarmRule, params }, { joinParamsToUrl: true });
@@ -44,9 +41,7 @@ export function getGoafDataLimit(params: any) {
   return defHttp.post({ url: Api.getGoafDataLimit, params }, { joinParamsToUrl: true });
 }
 export function addGoafDataLimit(params: any) {
-  return defHttp.post({ url: Api.addGoafDataLimit, params }).then(() => {
-    message.success('新增成功');
-  });
+  return defHttp.post({ url: Api.addGoafDataLimit, params });
 }
 export function updateGoafDataLimit(params: any) {
   return defHttp.post({ url: Api.updateGoafDataLimit, params });
@@ -55,50 +50,16 @@ export function deleteGoafDataLimit(params: any) {
   return defHttp.post({ url: Api.deleteGoafDataLimit, params }, { joinParamsToUrl: true });
 }
 
-export function getMineTree(params: { searchValue: string }) {
-  return getEnfMineTree().then((tree) => {
-    // 头一个真正的叶节点
-    let firstLeafKey;
-    // 它的父节点
-    let firstParentKey;
-
-    const transformKeys = (arr: any[]) => {
-      return arr.map((r) => {
-        const isLeaf = isNil(r.childDepart);
-
-        // 因为接口返回只有两层所以简单处理firstParentKey
-        if (isLeaf && !firstLeafKey) {
-          firstLeafKey = r.id;
-          firstParentKey = r.parentId;
-        }
-
-        return {
-          title: r.departName,
-          key: r.id,
-          isLeaf: isLeaf,
-          children: isLeaf ? undefined : transformKeys(r.childDepart),
-        };
-      });
-    };
-
-    const filterTreeNodes = (nodes: any[], value: string) => {
-      if (!value) return nodes;
-      return nodes.filter((t) => {
-        // 如果此次匹配成功,那么该节点应返回
-        if (t.title.includes(value)) {
-          return true;
-        }
-        // 如果没有则看看它的子节点是否有匹配的
-        if (t.children) {
-          return filterTreeNodes(t.children, value).length > 0;
-        }
-      });
-    };
-
-    return {
-      tree: filterTreeNodes(transformKeys(tree), params.searchValue),
-      firstLeafKey,
-      firstParentKey,
-    };
-  });
+export function patchGoafDataLimit(params: Record<string, any>) {
+  return Promise.all(
+    map(params, (item) => {
+      if (item.id) {
+        return updateGoafDataLimit(item);
+      }
+      if (!isNil(item.lowerLimit) || !isNil(item.upperLimit)) {
+        return addGoafDataLimit(item);
+      }
+      return Promise.resolve();
+    })
+  );
 }

+ 0 - 110
src/views/system/algorithm/hooks/operations.ts

@@ -1,110 +0,0 @@
-export function useOperations() {
-  const formPropsMap = new Map([
-    [
-      'coal',
-      {
-        schemas: schemasCoalAlarm,
-        submitFunc: (res) => (res.id ? updateCoalSeamAlarmRule(res) : addCoalSeamAlarmRule(res)),
-        fetchRecord({ id, mineCode }) {
-          return getCoalSeamAlarmRule({ coalSeamId: id, mineCode: mineCode }).then((r) => r[r.length - 1]);
-        },
-      },
-    ],
-    [
-      'goaf',
-      {
-        schemas: schemasGoafLimit,
-        submitFunc: (res) => (res.id ? updateGoafDataLimit(res) : addGoafDataLimit(res)),
-        fetchRecord({ id }) {
-          return getGoafDataLimit({ goafId: id }).then((r) => r[r.length - 1]);
-        },
-      },
-    ],
-  ]);
-  const modalPropsMap = new Map<string, Partial<ModalProps>>([
-    ['coal', { title: '预警参数设置', visible: true, loading: true }],
-    ['goaf', { title: '超限预警设置', visible: true, loading: true }],
-  ]);
-  const submitResolver = ref<(res: any) => Promise<void>>();
-  // 点击编辑后,获取对应的表单和弹窗配置
-  async function handleEdit(record, sign: string) {
-    if (!modalPropsMap.has(sign)) return;
-    if (!formPropsMap.has(sign)) return;
-    setModalProps(modalPropsMap.get(sign) as ModalProps);
-    const { schemas, fetchRecord, submitFunc } = formPropsMap.get(sign)!;
-    const res = await fetchRecord(record);
-    console.log('debug before resetSchema');
-    await resetSchema(schemas);
-    console.log('debug after resetSchema');
-
-    await nextTick();
-
-    console.log('debug before setFieldsValue');
-    if (res.id) {
-      await setFieldsValue(res);
-    } else {
-      await resetFields();
-    }
-    console.log('debug after setFieldsValue');
-
-    await nextTick();
-
-    console.log('debug before setFormProps');
-    // 不要使用setFormProps因为它会错误的触发submit方法
-    // await setFormProps({ submitFunc });
-    submitResolver.value = submitFunc;
-    console.log('debug after setFormProps');
-
-    setModalProps({ loading: false });
-    // await setFormProps({ model: res });
-  }
-  async function handleAdd(record, sign: string) {
-    if (!modalPropsMap.has(sign)) return;
-    if (!formPropsMap.has(sign)) return;
-    setModalProps(modalPropsMap.get(sign) as ModalProps);
-    const { schemas, submitFunc } = formPropsMap.get(sign)!;
-    await resetSchema(schemas);
-
-    await nextTick();
-
-    await resetFields();
-
-    await nextTick();
-
-    // 不要使用setFormProps因为它会错误的触发submit方法
-    // await setFormProps({ submitFunc });
-    submitResolver.value = submitFunc;
-
-    setModalProps({ loading: false });
-    // await setFormProps({ model: res });
-  }
-
-  const deletionPropsMap = new Map<string, { api: (id: string) => Promise<void> }>([
-    ['coal', { api: (id) => deleteCoalSeamAlarmRule({ id }) }],
-    ['goaf', { api: (id) => deleteGoafDataLimit({ id }) }],
-  ]);
-
-  function handleDelete(record, sign: string) {
-    if (!deletionPropsMap.has(sign)) return;
-    deletionPropsMap.get(sign)?.api(record.id);
-  }
-
-  const [registerModal, { setModalProps, closeModal }] = useModal();
-  const [registerForm, { setProps: setFormProps, resetFields, setFieldsValue, validate, submit, resetSchema }] = useForm({
-    model: {},
-    schemas: schemasCoalAlarm,
-    showResetButton: false,
-    showSubmitButton: false,
-    colon: false,
-    compact: true,
-  });
-
-  function handleSubmit() {
-    return validate().then((res) => {
-      submitResolver && submitResolver(res);
-    });
-    submit().then(() => {
-      closeModal();
-    });
-  }
-}

+ 12 - 19
src/views/system/algorithm/index.vue

@@ -101,15 +101,14 @@
     deleteGoafDataLimit,
     getCoalSeam,
     getGoafList,
-    updateGoafDataLimit,
-    addGoafDataLimit,
     updateCoalSeamAlarmRule,
     getCoalSeamAlarmRule,
     getGoafDataLimit,
+    patchGoafDataLimit,
   } from './algorithm.api';
   import { Flex } from 'ant-design-vue';
   // import { PlusOutlined } from '@ant-design/icons-vue';
-  import { forEach, isNil, last, map } from 'lodash-es';
+  import { forEach, last, isString } from 'lodash-es';
   import { message } from 'ant-design-vue';
   import { SvgIcon } from '/@/components/Icon';
 
@@ -174,18 +173,7 @@
       'goaf',
       {
         schemas: schemasGoafLimit,
-        submitFunc: (res) =>
-          Promise.all(
-            map(res, (item) => {
-              if (item.id) {
-                return updateGoafDataLimit(item);
-              }
-              if (!isNil(item.lowerLimit) || !isNil(item.upperLimit)) {
-                return addGoafDataLimit(item);
-              }
-              return Promise.resolve();
-            })
-          ),
+        submitFunc: (res) => patchGoafDataLimit(res),
         fetchRecord: (params) =>
           getGoafDataLimit(params).then((r) => {
             const result: any = {};
@@ -271,10 +259,15 @@
   function handleSubmit() {
     return validate().then((res) => {
       submitResolver.value &&
-        submitResolver.value(res).then(() => {
-          message.success('操作成功');
-          setModalProps({ visible: false });
-        });
+        submitResolver
+          .value(res)
+          .then(() => {
+            message.success('操作成功');
+            setModalProps({ visible: false });
+          })
+          .catch((e) => {
+            message.error(isString(e) ? e : '操作失败');
+          });
     });
   }
 </script>