소스 검색

refactor(overwrite): 用模块管理类的成员属性

vian 4 년 전
부모
커밋
8b7e6794d7

+ 1 - 0
overwrite/.eslintrc.js

@@ -27,6 +27,7 @@ module.exports = {
     '@typescript-eslint/no-empty-function': 'off',
     '@typescript-eslint/no-empty-function': 'off',
     '@typescript-eslint/no-explicit-any': 'off',
     '@typescript-eslint/no-explicit-any': 'off',
     'class-methods-use-this': 'off',
     'class-methods-use-this': 'off',
+    'import/prefer-default-export': 'off',
     'no-unused-expressions': [
     'no-unused-expressions': [
       'error',
       'error',
       {
       {

+ 0 - 75
overwrite/src/base.ts

@@ -1,75 +0,0 @@
-import { CoeType, GljType, IRationCoe } from '@sc/types';
-import { v1 } from 'uuid';
-
-export default class BaseOverwrite {
-  // 可用的人材机类型(目前只有人材机库有限制)
-  gljTypes: GljType[] = [
-    GljType.LABOUR,
-    GljType.GENERAL_MATERIAL,
-    GljType.CONCRETE,
-    GljType.MORTAR,
-    GljType.MIX_RATIO,
-    GljType.COMMERCIAL_CONCRETE,
-    GljType.COMMERCIAL_MORTAR,
-    GljType.OTHER_MATERIAL,
-    GljType.GENERAL_MACHINE,
-    GljType.MACHINE_LABOUR,
-    GljType.INSTRUMENT,
-    GljType.FUEL_POWER_FEE,
-    GljType.DEPRECIATION_FEE,
-    GljType.INSPECTION_FEE,
-    GljType.MAINTENANCE,
-    GljType.DISMANTLING_FREIGHT_FEE,
-    GljType.VERIFICATION_FEE,
-    GljType.OTHER_FEE,
-    GljType.OTHER_MACHINE_USED,
-    GljType.MAIN_MATERIAL,
-    GljType.EQUIPMENT,
-    GljType.MANAGEMENT_FEE,
-    GljType.PROFIT,
-    GljType.GENERAL_RISK_FEE,
-  ];
-
-  // 根据人材机类型,获取可含有的组成物类型,空数组即为该人材机不可含有组成物
-  getComponentTypes(type: GljType): GljType[] {
-    if ([GljType.CONCRETE, GljType.MORTAR, GljType.MIX_RATIO].includes(type)) {
-      return [GljType.GENERAL_MATERIAL];
-    }
-    if ([GljType.GENERAL_MACHINE, GljType.INSTRUMENT].includes(type)) {
-      return [
-        GljType.MACHINE_COMPOSITION,
-        GljType.MACHINE_LABOUR,
-        GljType.FUEL_POWER_FEE,
-        GljType.DEPRECIATION_FEE,
-        GljType.INSPECTION_FEE,
-        GljType.MAINTENANCE,
-        GljType.DISMANTLING_FREIGHT_FEE,
-        GljType.VERIFICATION_FEE,
-        GljType.OTHER_FEE,
-      ];
-    }
-    if (GljType.MAIN_MATERIAL === type) {
-      return [GljType.MAIN_MATERIAL];
-    }
-    return [];
-  }
-
-  // 获取自定义系数
-  getCustomerCoe(): IRationCoe {
-    return {
-      ID: v1(),
-      stdID: -1,
-      name: '自定义系数',
-      content: '人工×1,材料×1,机械×1,主材×1,设备×1',
-      isAdjust: true,
-      coes: [
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.RATION },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.LABOUR },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MATERIAL },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MACHINE },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MAIN },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.EQUIPMENT },
-      ],
-    };
-  }
-}

+ 13 - 0
overwrite/src/base/base.ts

@@ -0,0 +1,13 @@
+import { gljTypes } from './constant';
+import { getComponentTypes, getCustomerCoe } from './glj';
+
+export default class BaseOverwrite {
+  // 可用的人材机类型(目前只有人材机库有限制)
+  gljTypes = gljTypes;
+
+  // 根据人材机类型,获取可含有的组成物类型,空数组即为该人材机不可含有组成物
+  getComponentTypes = getComponentTypes;
+
+  // 获取自定义系数
+  getCustomerCoe = getCustomerCoe;
+}

+ 29 - 0
overwrite/src/base/constant.ts

@@ -0,0 +1,29 @@
+import { GljType } from '@sc/types';
+
+// 可用的人材机类型(目前只有人材机库有限制)
+export const gljTypes: GljType[] = [
+  GljType.LABOUR,
+  GljType.GENERAL_MATERIAL,
+  GljType.CONCRETE,
+  GljType.MORTAR,
+  GljType.MIX_RATIO,
+  GljType.COMMERCIAL_CONCRETE,
+  GljType.COMMERCIAL_MORTAR,
+  GljType.OTHER_MATERIAL,
+  GljType.GENERAL_MACHINE,
+  GljType.MACHINE_LABOUR,
+  GljType.INSTRUMENT,
+  GljType.FUEL_POWER_FEE,
+  GljType.DEPRECIATION_FEE,
+  GljType.INSPECTION_FEE,
+  GljType.MAINTENANCE,
+  GljType.DISMANTLING_FREIGHT_FEE,
+  GljType.VERIFICATION_FEE,
+  GljType.OTHER_FEE,
+  GljType.OTHER_MACHINE_USED,
+  GljType.MAIN_MATERIAL,
+  GljType.EQUIPMENT,
+  GljType.MANAGEMENT_FEE,
+  GljType.PROFIT,
+  GljType.GENERAL_RISK_FEE,
+];

+ 45 - 0
overwrite/src/base/glj.ts

@@ -0,0 +1,45 @@
+import { CoeType, GljType, IRationCoe } from '@sc/types';
+import { v1 } from 'uuid';
+
+// 根据人材机类型,获取可含有的组成物类型,空数组即为该人材机不可含有组成物
+export const getComponentTypes = (type: GljType): GljType[] => {
+  if ([GljType.CONCRETE, GljType.MORTAR, GljType.MIX_RATIO].includes(type)) {
+    return [GljType.GENERAL_MATERIAL];
+  }
+  if ([GljType.GENERAL_MACHINE, GljType.INSTRUMENT].includes(type)) {
+    return [
+      GljType.MACHINE_COMPOSITION,
+      GljType.MACHINE_LABOUR,
+      GljType.FUEL_POWER_FEE,
+      GljType.DEPRECIATION_FEE,
+      GljType.INSPECTION_FEE,
+      GljType.MAINTENANCE,
+      GljType.DISMANTLING_FREIGHT_FEE,
+      GljType.VERIFICATION_FEE,
+      GljType.OTHER_FEE,
+    ];
+  }
+  if (GljType.MAIN_MATERIAL === type) {
+    return [GljType.MAIN_MATERIAL];
+  }
+  return [];
+};
+
+// 获取自定义系数
+export const getCustomerCoe = (): IRationCoe => {
+  return {
+    ID: v1(),
+    stdID: -1,
+    name: '自定义系数',
+    content: '人工×1,材料×1,机械×1,主材×1,设备×1',
+    isAdjust: true,
+    coes: [
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.RATION },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.LABOUR },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MATERIAL },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MACHINE },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MAIN },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.EQUIPMENT },
+    ],
+  };
+};

+ 0 - 23
overwrite/src/chongQing2018.ts

@@ -1,23 +0,0 @@
-import { CoeType, IRationCoe } from '@sc/types';
-import { v1 } from 'uuid';
-import BaseOverwrite from './base';
-
-export default class ChongQing2018 extends BaseOverwrite {
-  getCustomerCoe(): IRationCoe {
-    return {
-      ID: v1(),
-      stdID: -1,
-      name: '自定义系数',
-      content: '人工×1,材料×1,施工机具×1,主材×1,设备×1',
-      isAdjust: true,
-      coes: [
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.RATION },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.LABOUR },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MATERIAL },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.TOOL },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MAIN },
-        { amount: '1', operator: '*', gljCode: '', coeType: CoeType.EQUIPMENT },
-      ],
-    };
-  }
-}

+ 6 - 0
overwrite/src/chongqing-2018/chongQing2018.ts

@@ -0,0 +1,6 @@
+import BaseOverwrite from '../base/base';
+import { getCustomerCoe } from './glj';
+
+export default class ChongQing2018 extends BaseOverwrite {
+  getCustomerCoe = getCustomerCoe;
+}

+ 21 - 0
overwrite/src/chongqing-2018/glj.ts

@@ -0,0 +1,21 @@
+import { CoeType, IRationCoe } from '@sc/types';
+import { v1 } from 'uuid';
+
+// 获取自定义系数
+export const getCustomerCoe = (): IRationCoe => {
+  return {
+    ID: v1(),
+    stdID: -1,
+    name: '自定义系数',
+    content: '人工×1,材料×1,施工机具×1,主材×1,设备×1',
+    isAdjust: true,
+    coes: [
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.RATION },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.LABOUR },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MATERIAL },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.TOOL },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.MAIN },
+      { amount: '1', operator: '*', gljCode: '', coeType: CoeType.EQUIPMENT },
+    ],
+  };
+};

+ 13 - 11
overwrite/src/index.ts

@@ -1,15 +1,17 @@
-import BaseOverwrite from './base';
-import ChongQing2018 from './chongQing2018';
+import BaseOverwrite from './base/base';
+import ChongQing2018 from './chongqing-2018/chongQing2018';
 
 
-// 根据费用定额ID,获取overwrite实例
+// 费用定额ID 与 overwrite实例 映射
+const overwriteMap: Record<string, BaseOverwrite> = {
+  '5b52b027fd3bb0000b257cf8': new ChongQing2018(),
+};
+
+const baseOverwrite = new BaseOverwrite();
+
+// 根据费用定额ID,获取overwrite单例
 export function getOverwrite(compilationID?: string): BaseOverwrite {
 export function getOverwrite(compilationID?: string): BaseOverwrite {
-  switch (compilationID) {
-    case '5b52b027fd3bb0000b257cf8':
-      return new ChongQing2018();
-    default:
-      return new BaseOverwrite();
-  }
+  return (compilationID && overwriteMap[compilationID]) || baseOverwrite;
 }
 }
 
 
-export * from './base';
-export * from './chongQing2018';
+export * from './base/base';
+export * from './chongqing-2018/chongQing2018';