hongluan-business-ui
Version:
Hongluan Business Component Library for Vue 3
99 lines (95 loc) • 2.86 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
const Utils = {
getKey(item, opt) {
return item.prop ? opt[item.prop.value] : opt.value;
},
getLabel(item, opt) {
return item.prop ? opt[item.prop.label] : opt.label;
},
getSelectedOptionLabels(item) {
const result = [];
item.value.forEach((v) => {
result.push(this.getSelectedOptionLabel(item, v));
});
return result;
},
getSelectedOptionLabel(item, val) {
const valOpt = item.options.find((opt) => this.getKey(item, opt) === val);
return valOpt ? this.getLabel(item, valOpt) : "";
},
getSelectedOptionsLabel(item, vals) {
return vals.map((val) => this.getSelectedOptionLabel(item, val));
},
getDisplayStr(display, separator = "-") {
let val = "";
if (typeof display === "string") {
val = display;
} else if (Array.isArray(display)) {
val = display.join(separator);
} else {
val = JSON.stringify(display);
}
return val;
},
getDisplayItems(searchItems) {
const result = [];
const nonSlotItems = searchItems.filter((i) => i.type !== "slot");
nonSlotItems.filter((i) => !i.display).filter((i) => Array.isArray(i.value) ? i.value.length : i.value).forEach((item) => {
if (/range|dates/.test(item.type) || item["is-range"]) {
result.push({
display: this.getDisplayStr(item.value),
value: item.value,
name: item.name,
type: item.type
});
} else if (item.type === "select") {
let display;
if (Array.isArray(item.value)) {
display = this.getDisplayStr(this.getSelectedOptionsLabel(item, item.value), "\uFF0C");
} else {
display = this.getSelectedOptionLabel(item, item.value);
}
result.push({
display,
value: item.value,
name: item.name,
type: item.type
});
} else {
result.push({
display: this.getDisplayStr(item.value),
value: item.value,
name: item.name,
type: item.type
});
}
});
nonSlotItems.filter((i) => i.display).forEach((item) => {
const label = typeof item.display === "function" ? item.display.call(item) : null;
if (label) {
result.push({
display: label,
value: item.value,
name: item.name,
type: item.type
});
}
});
return result;
},
syncDisplaySearchItems(displayItems, searchItems) {
searchItems.forEach((si) => {
const foundItem = displayItems.find((di) => di.name === si.name);
if (!foundItem) {
if (Array.isArray(si.value)) {
si.value = [];
} else {
si.value = "";
}
}
});
}
};
exports.Utils = Utils;
//# sourceMappingURL=utils.js.map