cptLib.ts 976 B

12345678910111213141516171819202122232425262728293031
  1. // 补充库标识
  2. export const cptLibKey = 'complementaryLib';
  3. /**
  4. * 判断库ID是否是补充的库ID
  5. * @param libID 库ID
  6. */
  7. export const isCptLib = (libID: number | string): boolean => {
  8. return /[\da-zA-Z-]{36}/.test(String(libID));
  9. };
  10. /**
  11. * 获取补充人材机库ID,根据拥有者ID、费用定额ID拼接
  12. * @param ownerID 拥有者ID
  13. * @param compilationID 费用定额ID
  14. */
  15. export const getCptLibID = (ownerID: string, compilationID: string): string => {
  16. return `${cptLibKey}@${ownerID}@${compilationID}`;
  17. };
  18. /**
  19. * 从补充人材机库ID中 提取 拥有者、费用定额ID
  20. * @param cptLibID 补充库ID
  21. */
  22. export const getInfoFromCptLibID = (cptLibID: number | string): { ownerID: string; compilationID: string } => {
  23. const [key, ownerID, compilationID] = String(cptLibID).split('@');
  24. if (!key || key !== cptLibKey || !ownerID || !compilationID) {
  25. return { ownerID: '', compilationID: '' };
  26. }
  27. return { ownerID, compilationID };
  28. };