dm-vue3-ui
Version:
This Components Library will help get you started developing in Vue 3.
174 lines (173 loc) • 6.52 kB
JavaScript
import { Input, Checkbox, Button, Popover } from "ant-design-vue/es";
import { defineComponent, ref, computed, watch, openBlock, createElementBlock, createVNode, withCtx, createElementVNode, unref, createCommentVNode, Fragment, renderList, createBlock, renderSlot, toDisplayString, createTextVNode } from "vue";
import { SearchOutlined, DownOutlined } from "@ant-design/icons-vue";
import { $t } from "../../i18n/index";
const _hoisted_1 = { class: "multiple-select-filter" };
const _hoisted_2 = { class: "filter-panel" };
const _hoisted_3 = {
key: 0,
class: "search"
};
const _hoisted_4 = { class: "list" };
const _hoisted_5 = { class: "content" };
const _hoisted_6 = { class: "label" };
const _hoisted_7 = {
key: 1,
class: "no-data"
};
const _hoisted_8 = { class: "footer" };
const _hoisted_9 = { class: "trigger-container" };
const _hoisted_10 = { class: "content" };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "multiple-select",
props: {
data: { default: () => ({}) }
},
emits: ["apply"],
setup(__props, { emit: __emit }) {
const props = __props;
const emit = __emit;
const visible = ref(false);
const selectedValues = ref([]);
const filterOptions = ref(props.data.options);
const allowSearch = ref(true);
const isChecked = (value) => {
let index = selectedValues.value.findIndex((v) => v === value);
return index > -1 ? true : false;
};
const placeholder = computed(() => {
if (props.data.placeholder) {
return props.data.placeholder;
} else {
return `输入${props.data.label}`;
}
});
const visibleChange = (visible1) => {
if (!visible1) {
selectedValues.value = [];
}
visible.value = visible1;
};
const changeSelectedValues = (event, item) => {
let { checked, value } = event.target;
if (checked) {
selectedValues.value.push(item.value);
} else {
let index = selectedValues.value.findIndex((p) => p === value);
if (index != -1) {
selectedValues.value.splice(index, 1);
}
}
};
const clearSeleted = () => {
selectedValues.value = [];
};
const onSearch = (e) => {
let filterOptions1 = props.data.options.filter(
(p) => p.label.includes(e.target.value)
);
filterOptions.value = filterOptions1;
};
const apply = () => {
visible.value = false;
let data = { field: props.data.field, value: selectedValues.value };
emit("apply", data);
clearSeleted();
};
watch(
() => props.data.options,
(val) => {
filterOptions.value = val;
},
{ deep: true }
);
return (_ctx, _cache) => {
const _component_a_input = Input;
const _component_a_checkbox = Checkbox;
const _component_a_button = Button;
const _component_a_popover = Popover;
return openBlock(), createElementBlock("div", _hoisted_1, [
createVNode(_component_a_popover, {
placement: "bottomLeft",
"overlay-class-name": "multiple-select-popover",
"get-popup-container": (triggerNode) => triggerNode.parentNode,
align: { offset: [0, -5] },
trigger: "click",
onVisibleChange: visibleChange,
visible: visible.value,
"onUpdate:visible": _cache[0] || (_cache[0] = ($event) => visible.value = $event)
}, {
content: withCtx(() => [
createElementVNode("div", _hoisted_2, [
allowSearch.value ? (openBlock(), createElementBlock("div", _hoisted_3, [
createVNode(unref(SearchOutlined)),
createVNode(_component_a_input, {
bordered: false,
placeholder: unref($t)("multipleFilter.search"),
allowClear: "",
onChange: onSearch
}, null, 8, ["placeholder"])
])) : createCommentVNode("", true),
createElementVNode("div", _hoisted_4, [
filterOptions.value.length > 0 ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(filterOptions.value, (item, index) => {
return openBlock(), createBlock(_component_a_checkbox, {
key: index,
value: item.value,
class: "item",
checked: isChecked(item.value),
onChange: (event) => changeSelectedValues(event, item)
}, {
default: withCtx(() => [
createElementVNode("div", _hoisted_5, [
renderSlot(_ctx.$slots, "label", {
record: item,
index
}, () => [
createElementVNode("div", _hoisted_6, toDisplayString(item.label), 1)
])
])
]),
_: 2
}, 1032, ["value", "checked", "onChange"]);
}), 128)) : (openBlock(), createElementBlock("div", _hoisted_7, toDisplayString(unref($t)("multipleFilter.noMatch")), 1))
]),
createElementVNode("div", _hoisted_8, [
createVNode(_component_a_button, {
type: "link",
class: "clear-btn",
onClick: clearSeleted
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref($t)("multipleFilter.clear1")), 1)
]),
_: 1
}),
createVNode(_component_a_button, {
type: "primary",
class: "submit-btn",
onClick: apply,
disabled: selectedValues.value.length <= 0
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref($t)("multipleFilter.apply")), 1)
]),
_: 1
}, 8, ["disabled"])
])
])
]),
default: withCtx(() => [
createElementVNode("div", _hoisted_9, [
createElementVNode("div", _hoisted_10, toDisplayString(placeholder.value), 1),
createVNode(unref(DownOutlined))
])
]),
_: 3
}, 8, ["get-popup-container", "visible"])
]);
};
}
});
export {
_sfc_main as default
};