@pisell/pisellos
Version:
一个可扩展的前端模块化SDK框架,支持插件系统
107 lines (105 loc) • 3.55 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/solution/BookingByStep/utils/capacity.ts
var capacity_exports = {};
__export(capacity_exports, {
checkResourceCanUseByCapacity: () => checkResourceCanUseByCapacity,
checkSubResourcesCapacity: () => checkSubResourcesCapacity,
formatDefaultCapacitys: () => formatDefaultCapacitys,
getCapacityInfoByCartItem: () => getCapacityInfoByCartItem,
getSumCapacity: () => getSumCapacity
});
module.exports = __toCommonJS(capacity_exports);
var formatDefaultCapacitys = ({
capacity,
product_bundle
}) => {
if ((capacity == null ? void 0 : capacity.type) === "package") {
return (product_bundle || []).map((d) => {
const id = d.bundle_product_id;
const item = ((capacity == null ? void 0 : capacity.package) || []).find(
(item2) => item2.product_id === id
);
return {
id,
value: item ? d.num || 0 : 0,
name: (item == null ? void 0 : item.name) || (d == null ? void 0 : d.title)
};
});
}
if ((capacity == null ? void 0 : capacity.type) === "custom") {
return ((capacity == null ? void 0 : capacity.custom) || []).map((d) => {
return {
id: d.id,
value: d.min,
name: d.name
};
});
}
return [{ id: 0, value: 1, name: "" }];
};
var getSumCapacity = ({ capacity }) => {
let sum = 0;
for (let item of capacity || []) {
sum += item.value;
}
return sum;
};
function getCapacityInfoByCartItem(targetCartItem) {
var _a;
const formatCapacity = formatDefaultCapacitys({
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
product_bundle: targetCartItem._origin.product.product_bundle
});
const currentCapacity = getSumCapacity({ capacity: formatCapacity });
return {
formatCapacity,
currentCapacity
};
}
var checkSubResourcesCapacity = (resource) => {
if (resource.children && resource.children.length) {
let countCapacity = resource.capacity;
resource.children.forEach((child, index) => {
if (index === resource.children.length - 1) {
child.capacity = countCapacity;
return;
}
if (child.capacity <= countCapacity) {
countCapacity -= child.capacity;
} else {
child.capacity = countCapacity;
countCapacity = 0;
}
});
}
};
var checkResourceCanUseByCapacity = (currentCapacity, requiredCapacity, maxCapacity) => {
if (currentCapacity < 0 || requiredCapacity < 0 || maxCapacity <= 0) {
return false;
}
return currentCapacity + requiredCapacity <= maxCapacity;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
checkResourceCanUseByCapacity,
checkSubResourcesCapacity,
formatDefaultCapacitys,
getCapacityInfoByCartItem,
getSumCapacity
});