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

feat(util): 清单项目特征,工作内容前后统一获取

zhangweicheng 5 лет назад
Родитель
Сommit
36ee47d25e
3 измененных файлов с 62 добавлено и 3 удалено
  1. 2 2
      util/package.json
  2. 59 1
      util/src/bill.ts
  3. 1 0
      util/src/index.ts

+ 2 - 2
util/package.json

@@ -1,7 +1,7 @@
 {
 {
   "name": "@sc/util",
   "name": "@sc/util",
-  "version": "1.0.0",
-  "description": "4舍5入算法,防止浮点数计算不精确问题",
+  "version": "1.0.1",
+  "description": "共用的工具包",
   "main": "./dist/index.cjs.js",
   "main": "./dist/index.cjs.js",
   "module": "./dist/index.esm.js",
   "module": "./dist/index.esm.js",
   "browser": "./dist/index.min.js",
   "browser": "./dist/index.min.js",

+ 59 - 1
util/src/bill.ts

@@ -1,10 +1,23 @@
-import { IJobContent, IItemCharacter } from '@sc/types';
+import {
+  IJobContent,
+  IItemCharacter,
+  IStdBill,
+  IStdJobContent,
+  IStdItemCharacter,
+} from '@sc/types';
 
 
 interface IJobsAndCharacterText {
 interface IJobsAndCharacterText {
   jobContentText: string;
   jobContentText: string;
   itemCharacterText: string;
   itemCharacterText: string;
 }
 }
 
 
+interface IJobContentMap {
+  [id: string]: IStdJobContent;
+}
+interface IItemCharacterMap {
+  [id: string]: IStdItemCharacter;
+}
+
 export interface IJobAndCharacter extends IJobsAndCharacterText {
 export interface IJobAndCharacter extends IJobsAndCharacterText {
   jobContents: IJobContent[];
   jobContents: IJobContent[];
   itemCharacters: IItemCharacter[];
   itemCharacters: IItemCharacter[];
@@ -32,3 +45,48 @@ export const getJobsAndCharacterText = (
   itemCharacterText = textArray.join('\n');
   itemCharacterText = textArray.join('\n');
   return { jobContentText, itemCharacterText };
   return { jobContentText, itemCharacterText };
 };
 };
+
+export const getJobContents = (
+  stdBill: IStdBill,
+  stdJobContenMap: IJobContentMap
+): IJobContent[] => {
+  const jobs: IJobContent[] = [];
+  let i = 1;
+  for (const j of stdBill.jobs) {
+    const job = stdJobContenMap[j.id];
+    if (job) {
+      jobs.push({ serialNo: i + 1, content: job.content, isChecked: true });
+      i += 1;
+    }
+  }
+
+  return jobs;
+};
+
+export const getItemCharacters = (
+  stdBill: IStdBill,
+  itemCharacterMap: IItemCharacterMap
+): IItemCharacter[] => {
+  const characters: IItemCharacter[] = [];
+  let i = 1;
+  for (const item of stdBill.items) {
+    const character = itemCharacterMap[item.id];
+    if (character) {
+      const newItem: IItemCharacter = {
+        serialNo: i + 1,
+        character: character.content,
+        eigenvalue: [],
+        isChecked: false,
+      };
+      const eigenvalues = character.itemValue;
+      for (let j = 0; j < eigenvalues.length; j += 1) {
+        const newValue = { value: eigenvalues[j].value, isSelected: false };
+        newItem.eigenvalue.push(newValue);
+      }
+      characters.push(newItem);
+      i += 1;
+    }
+  }
+
+  return characters;
+};

+ 1 - 0
util/src/index.ts

@@ -1 +1,2 @@
 export * from './math';
 export * from './math';
+export * from './bill';