Explorar o código

feat(wise-cost-util): 补充库通用方法

vian %!s(int64=4) %!d(string=hai) anos
pai
achega
7b80461c4b
Modificáronse 2 ficheiros con 32 adicións e 0 borrados
  1. 31 0
      wise-cost-util/src/cptLib.ts
  2. 1 0
      wise-cost-util/src/index.ts

+ 31 - 0
wise-cost-util/src/cptLib.ts

@@ -0,0 +1,31 @@
+// 补充库标识
+export const cptLibKey = 'complementaryLib';
+
+/**
+ * 判断库ID是否是补充的库ID
+ * @param libID 库ID
+ */
+export const isCptLib = (libID: number | string): boolean => {
+  return new RegExp(cptLibKey).test(String(libID));
+};
+
+/**
+ * 获取补充人材机库ID,根据拥有者ID、费用定额ID拼接
+ * @param ownerID 拥有者ID
+ * @param compilationID 费用定额ID
+ */
+export const getCptLibID = (ownerID: string, compilationID: string): string => {
+  return `${cptLibKey}@${ownerID}@${compilationID}`;
+};
+
+/**
+ * 从补充人材机库ID中 提取 拥有者、费用定额ID
+ * @param cptLibID 补充库ID
+ */
+export const getInfoFromCptLibID = (cptLibID: number | string): { ownerID: string; compilationID: string } => {
+  const [key, ownerID, compilationID] = String(cptLibID).split('@');
+  if (!key || key !== cptLibKey || !ownerID || !compilationID) {
+    return { ownerID: '', compilationID: '' };
+  }
+  return { ownerID, compilationID };
+};

+ 1 - 0
wise-cost-util/src/index.ts

@@ -1,3 +1,4 @@
 export * from './bill';
 export * from './rationAss';
 export * from './glj';
+export * from './cptLib';