yanzhen-design-vue
Version:
82 lines (81 loc) • 3.01 kB
JavaScript
import { defineComponent, computed, ref, openBlock, createElementBlock, Fragment, renderList, createBlock, unref } from "vue";
import { Empty } from "ant-design-vue";
import { useInjectInnerCascader } from "./context.mjs";
import Column from "./Column.vue.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "OptionList",
setup(__props) {
const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE;
const {
options,
searchValue,
searchOptions,
fieldNames,
onSelect,
values,
checkedValues,
halfCheckedValues
} = useInjectInnerCascader();
const checkedSet = computed(() => new Set(checkedValues.value));
const halfCheckedSet = computed(() => new Set(halfCheckedValues.value));
const activeValueCells = ref([]);
const mergedOptions = computed(() => {
if (searchValue.value) {
return searchOptions.value;
}
return options.value;
});
const optionColumns = computed(() => {
const optionList = [{ options: mergedOptions.value }];
let currentList = mergedOptions.value;
for (let i = 0; i < activeValueCells.value.length; i++) {
const activeValueCell = activeValueCells.value[i];
const currentOption = currentList.find(
(option) => option[fieldNames.value.value] === activeValueCell
);
const subOptions = currentOption == null ? void 0 : currentOption[fieldNames.value.children];
if (!(subOptions == null ? void 0 : subOptions.length)) {
break;
}
currentList = subOptions;
optionList.push({ options: subOptions });
}
return optionList;
});
const onPathOpen = (fullPath) => {
activeValueCells.value = fullPath;
};
const onPathSelect = (valuePath) => {
onSelect(valuePath);
};
const onClick = (event) => {
event.preventDefault();
};
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: "inner-cascader-menus",
onClick
}, [
optionColumns.value[0].options.length ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(optionColumns.value, (column, index) => {
return openBlock(), createBlock(Column, {
key: column[unref(fieldNames).value] || index,
options: column.options,
"prev-value-path": activeValueCells.value.slice(0, index),
"active-value": activeValueCells.value[index],
"checked-set": checkedSet.value,
"half-checked-set": halfCheckedSet.value,
onActive: onPathOpen,
onSelect: onPathSelect
}, null, 8, ["options", "prev-value-path", "active-value", "checked-set", "half-checked-set"]);
}), 128)) : (openBlock(), createBlock(unref(Empty), {
key: 1,
image: unref(simpleImage),
style: { width: "100%" }
}, null, 8, ["image"]))
]);
};
}
});
export {
_sfc_main as default
};