Просмотр исходного кода

init(overwrite): overwrite模块

vian 5 лет назад
Родитель
Сommit
9293c0442d

+ 1 - 0
overwrite/.eslintignore

@@ -0,0 +1 @@
+/dist

+ 41 - 0
overwrite/.eslintrc.js

@@ -0,0 +1,41 @@
+module.exports = {
+  env: {
+    browser: true,
+    es2021: true,
+    node: true,
+  },
+  extends: ['airbnb-base', 'plugin:@typescript-eslint/recommended', 'prettier'],
+  parser: '@typescript-eslint/parser',
+  parserOptions: {
+    ecmaVersion: 12,
+    sourceType: 'module',
+  },
+  plugins: ['@typescript-eslint', 'prettier'],
+  rules: {
+    'prettier/prettier': 'error',
+    'import/extensions': [
+      'error',
+      {
+        js: 'never',
+        jsx: 'never',
+        ts: 'never',
+        tsx: 'never',
+        json: 'always',
+      },
+    ],
+    'import/no-unresolved': 'off',
+    '@typescript-eslint/no-empty-function': 'off',
+    '@typescript-eslint/no-explicit-any': 'off',
+    'class-methods-use-this': 'off',
+    'no-unused-expressions': [
+      'error',
+      {
+        allowShortCircuit: true,
+      },
+    ],
+    'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
+    'no-restricted-syntax': 'off',
+    'no-shadow': 'off',
+    '@typescript-eslint/no-shadow': 'error',
+  },
+};

+ 22 - 0
overwrite/.gitignore

@@ -0,0 +1,22 @@
+.DS_Store
+node_modules
+dist
+
+# local env files
+.env.local
+.env.*.local
+
+# Log files
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+
+# Editor directories and files
+.idea
+.vscode
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?

+ 6 - 0
overwrite/.huskyrc.js

@@ -0,0 +1,6 @@
+module.exports = {
+  hooks: {
+    'pre-commit': 'lint-staged',
+    'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
+  },
+};

+ 19 - 0
overwrite/README.md

@@ -0,0 +1,19 @@
+# overwrite
+
+本项目是 wise-cost 项目,费用定额相同方法不同实现逻辑的解决方案。
+
+### 安装
+
+`$ npm i -S @sc/overwrite`
+
+### 打包
+
+`$ npm run build`
+
+### 基本用法
+
+```
+const overwrite = getOverWrite('');
+```
+
+具体接口请参考声明文件。

+ 29 - 0
overwrite/commitlint.config.js

@@ -0,0 +1,29 @@
+module.exports = {
+  ignores: [commit => commit.includes('init')],
+  extends: ['@commitlint/config-conventional'],
+  rules: {
+    'body-leading-blank': [2, 'always'],
+    'footer-leading-blank': [1, 'always'],
+    'header-max-length': [2, 'always', 108],
+    'subject-empty': [2, 'never'],
+    'type-empty': [2, 'never'],
+    'type-enum': [
+      2,
+      'always',
+      [
+        'feat', // 新增功能、变更需求
+        'fix', // 修复bug
+        'perf', // 优化性能
+        'refactor', // 代码重构
+        'style', // 代码格式(不影响功能,例如空格、分号等格式修正)
+        'docs', // 文档变更
+        'test', // 测试
+        'ci', // 更改持续集成软件的配置文件和package中的scripts命令,例如scopes: Travis, Circle等
+        'chore', // 变更构建流程或辅助工具(依赖更新/脚手架配置修改/webpack、gulp、npm等)
+        'revert', // 代码回退
+        'types', // ts类型定义文件更改
+        'wip', // work in process开发中
+      ],
+    ],
+  },
+};

+ 9 - 0
overwrite/lint-staged.config.js

@@ -0,0 +1,9 @@
+module.exports = {
+  '*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'],
+  '{!(package)*.json,*.code-snippets,.!(browserslist)*rc}': [
+    'prettier --write--parser json',
+  ],
+  'package.json': ['prettier --write'],
+  '*.vue': ['prettier --write'],
+  '*.md': ['prettier --write'],
+};

+ 53 - 0
overwrite/package.json

@@ -0,0 +1,53 @@
+{
+  "name": "@sc/overwrite",
+  "version": "1.0.0",
+  "description": "wise-cost项目,费用定额相同方法不同实现逻辑的解决方案",
+  "main": "./dist/index.cjs.js",
+  "module": "./dist/index.esm.js",
+  "browser": "./dist/index.min.js",
+  "types": "./dist/index.d.ts",
+  "files": [
+    "dist",
+    "README.md"
+  ],
+  "scripts": {
+    "test": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} mocha -r ts-node/register 'tests/**/*.ts'",
+    "build": "rollup -c"
+  },
+  "keywords": [],
+  "author": "smartcost",
+  "license": "ISC",
+  "devDependencies": {
+    "@commitlint/cli": "^11.0.0",
+    "@commitlint/config-conventional": "^11.0.0",
+    "@sc/types": "^1.0.28",
+    "@types/chai": "^4.2.14",
+    "@types/mocha": "^8.0.4",
+    "@types/ms": "^0.7.31",
+    "@types/uuid": "^8.3.0",
+    "@typescript-eslint/eslint-plugin": "^4.4.1",
+    "@typescript-eslint/parser": "^4.4.1",
+    "chai": "^4.2.0",
+    "cross-env": "^7.0.2",
+    "eslint": "^7.11.0",
+    "eslint-config-airbnb-base": "^14.2.0",
+    "eslint-config-prettier": "^6.12.0",
+    "eslint-plugin-import": "^2.22.1",
+    "eslint-plugin-prettier": "^3.1.4",
+    "husky": "^4.3.0",
+    "lint-staged": "^10.5.0",
+    "mocha": "^8.2.1",
+    "prettier": "^2.1.2",
+    "rollup": "^2.30.0",
+    "rollup-plugin-commonjs": "^10.1.0",
+    "rollup-plugin-node-resolve": "^5.2.0",
+    "rollup-plugin-terser": "^7.0.2",
+    "rollup-plugin-typescript2": "^0.27.3",
+    "ts-node": "^9.0.0",
+    "tslib": "^2.0.3",
+    "typescript": "^4.0.3"
+  },
+  "dependencies": {
+    "uuid": "^8.3.2"
+  }
+}

+ 6 - 0
overwrite/prettier.config.js

@@ -0,0 +1,6 @@
+module.exports = {
+  singleQuote: true, // 单引号
+  trailingComma: 'es5', // 对象末尾以逗号结束
+  arrowParens: 'avoid', // 箭头函数只有一个参数的时候,不使用()
+  endOfLine: 'auto', // CRLF,LF都可以
+};

+ 11 - 0
overwrite/rollup.config.js

@@ -0,0 +1,11 @@
+import typescript from 'rollup-plugin-typescript2'; // 一定要是typescript2,如果使用typescript,没法自动生成.d.ts文件
+import pkg from './package.json';
+
+export default [
+  {
+    input: 'src/index.ts',
+    external: ['ms'],
+    plugins: [typescript()],
+    output: [{ file: pkg.main, format: 'cjs' }],
+  },
+];

+ 75 - 0
overwrite/src/base.ts

@@ -0,0 +1,75 @@
+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 },
+      ],
+    };
+  }
+}

+ 23 - 0
overwrite/src/chongQing2018.ts

@@ -0,0 +1,23 @@
+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 },
+      ],
+    };
+  }
+}

+ 15 - 0
overwrite/src/index.ts

@@ -0,0 +1,15 @@
+import BaseOverwrite from './base';
+import ChongQing2018 from './chongQing2018';
+
+// 根据费用定额ID,获取overwrite实例
+export function getOverwrite(compilationID?: string): BaseOverwrite {
+  switch (compilationID) {
+    case '5b52b027fd3bb0000b257cf8':
+      return new ChongQing2018();
+    default:
+      return new BaseOverwrite();
+  }
+}
+
+export * from './base';
+export * from './chongQing2018';

+ 18 - 0
overwrite/tsconfig.json

@@ -0,0 +1,18 @@
+{
+  "compilerOptions": {
+    "target": "ESNext",
+    "module": "ESNext",
+    "declaration": true,
+    "outDir": "./",
+    "strict": true,
+    "esModuleInterop": true,
+    "moduleResolution": "node",
+  },
+  "include": [
+    "src/**/*.ts",
+  ],
+  "exclude": [
+    "node_modules",
+    "test"
+  ]
+}