UNPKG

hongluan-ui

Version:
288 lines (285 loc) 9.77 kB
import { defineComponent, getCurrentInstance, ref, computed, watch, resolveComponent, resolveDirective, openBlock, createBlock, withCtx, createElementBlock, createElementVNode, createVNode, Fragment, renderList, createTextVNode, toDisplayString, normalizeClass, withDirectives, renderSlot } from 'vue'; import { HlCheckbox } from '../../checkbox/index.mjs'; import { HlCheckboxGroup } from '../../checkbox-group/index.mjs'; import { HlIcon } from '../../icon/index.mjs'; import '../../system-icon/index.mjs'; import '../../../directives/index.mjs'; import '../../../hooks/index.mjs'; import { HlTooltip } from '../../tooltip/index.mjs'; import { HlButton } from '../../button/index.mjs'; import { HlScrollbar } from '../../scrollbar/index.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import SystemFilter from '../../system-icon/src/filter.mjs'; import ClickOutside from '../../../directives/click-outside/index.mjs'; import { useLocale } from '../../../hooks/use-locale/index.mjs'; const _sfc_main = defineComponent({ name: "TableFilterPanel", components: { HlCheckbox, HlCheckboxGroup, HlScrollbar, HlTooltip, HlIcon, HlButton, SystemFilter }, directives: { ClickOutside }, props: { placement: { type: String, default: "bottom-start" }, store: { type: Object }, column: { type: Object }, upDataColumn: { type: Function } }, setup(props) { const instance = getCurrentInstance(); const { t } = useLocale(); const parent = instance == null ? void 0 : instance.parent; if (!parent.filterPanels.value[props.column.id]) { parent.filterPanels.value[props.column.id] = instance; } const tooltipVisible = ref(false); const tooltip = ref(null); const filters = computed(() => { return props.column && props.column.filters; }); const filterClassName = computed(() => { if (props.column.filterClassName) { return `popover popover-table-filter ${props.column.filterClassName}`; } return "popover popover-table-filter"; }); const filterValue = computed({ get: () => { var _a; return (((_a = props.column) == null ? void 0 : _a.filteredValue) || [])[0]; }, set: (value) => { if (filteredValue.value) { if (typeof value !== "undefined" && value !== null) { filteredValue.value.splice(0, 1, value); } else { filteredValue.value.splice(0, 1); } } } }); const filteredValue = computed({ get() { if (props.column) { return props.column.filteredValue || []; } return []; }, set(value) { if (props.column) { props.upDataColumn("filteredValue", value); } } }); const multiple = computed(() => { if (props.column) { return props.column.filterMultiple; } return true; }); const isActive = (filter) => { return filter.value === filterValue.value; }; const hidden = () => { tooltipVisible.value = false; }; const showFilterPanel = (e) => { e.stopPropagation(); tooltipVisible.value = !tooltipVisible.value; }; const hideFilterPanel = () => { tooltipVisible.value = false; }; const handleConfirm = () => { confirmFilter(filteredValue.value); hidden(); }; const handleReset = () => { filteredValue.value = []; confirmFilter(filteredValue.value); hidden(); }; const handleSelect = (_filterValue) => { filterValue.value = _filterValue; if (typeof _filterValue !== "undefined" && _filterValue !== null) { confirmFilter(filteredValue.value); } else { confirmFilter([]); } hidden(); }; const confirmFilter = (filteredValue2) => { props.store.commit("filterChange", { column: props.column, values: filteredValue2 }); props.store.updateAllSelected(); }; watch(tooltipVisible, (value) => { if (props.column) { props.upDataColumn("filterOpened", value); } }, { immediate: true }); const popperPaneRef = computed(() => { var _a, _b; return (_b = (_a = tooltip.value) == null ? void 0 : _a.popperRef) == null ? void 0 : _b.contentRef; }); return { tooltipVisible, multiple, filteredValue, filterValue, filters, filterClassName, handleConfirm, handleReset, handleSelect, isActive, t, showFilterPanel, hideFilterPanel, popperPaneRef, tooltip }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_hl_checkbox = resolveComponent("hl-checkbox"); const _component_hl_checkbox_group = resolveComponent("hl-checkbox-group"); const _component_hl_scrollbar = resolveComponent("hl-scrollbar"); const _component_hl_button = resolveComponent("hl-button"); const _component_system_filter = resolveComponent("system-filter"); const _component_hl_icon = resolveComponent("hl-icon"); const _component_hl_tooltip = resolveComponent("hl-tooltip"); const _directive_click_outside = resolveDirective("click-outside"); return openBlock(), createBlock(_component_hl_tooltip, { ref: "tooltip", visible: _ctx.tooltipVisible, offset: 0, placement: _ctx.placement, "show-arrow": false, "stop-popper-mouse-event": false, teleported: "", effect: "light", pure: "", "popper-class": _ctx.filterClassName, persistent: "" }, { content: withCtx(() => [ _ctx.multiple ? (openBlock(), createElementBlock("div", { key: 0 }, [ createElementVNode("div", { class: "table-filter-content" }, [ createVNode(_component_hl_scrollbar, { "wrap-class": "table-filter-wrap" }, { default: withCtx(() => [ createVNode(_component_hl_checkbox_group, { modelValue: _ctx.filteredValue, "onUpdate:modelValue": ($event) => _ctx.filteredValue = $event, class: "table-filter-checkbox-group" }, { default: withCtx(() => [ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.filters, (filter) => { return openBlock(), createBlock(_component_hl_checkbox, { key: filter.value, label: filter.value }, { default: withCtx(() => [ createTextVNode(toDisplayString(filter.text), 1) ]), _: 2 }, 1032, ["label"]); }), 128)) ]), _: 1 }, 8, ["modelValue", "onUpdate:modelValue"]) ]), _: 1 }) ]), createElementVNode("div", { class: "table-filter-bottom" }, [ createVNode(_component_hl_button, { class: normalizeClass({ "is-disabled": _ctx.filteredValue.length === 0 }), disabled: _ctx.filteredValue.length === 0, onClick: _ctx.handleConfirm }, { default: withCtx(() => [ createTextVNode(toDisplayString(_ctx.t("hl.table.confirmFilter")), 1) ]), _: 1 }, 8, ["class", "disabled", "onClick"]), createVNode(_component_hl_button, { type: "button", onClick: _ctx.handleReset }, { default: withCtx(() => [ createTextVNode(toDisplayString(_ctx.t("hl.table.resetFilter")), 1) ]), _: 1 }, 8, ["onClick"]) ]) ])) : (openBlock(), createElementBlock("ul", { key: 1, class: "table-filter-list" }, [ createElementVNode("li", { class: normalizeClass([ "table-filter-list-item", { "is-active": _ctx.filterValue === void 0 || _ctx.filterValue === null } ]), onClick: ($event) => _ctx.handleSelect(null) }, toDisplayString(_ctx.t("hl.table.clearFilter")), 11, ["onClick"]), (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.filters, (filter) => { return openBlock(), createElementBlock("li", { key: filter.value, class: normalizeClass(["table-filter-list-item", _ctx.isActive(filter) ? "is-active" : ""]), label: filter.value, onClick: ($event) => _ctx.handleSelect(filter.value) }, toDisplayString(filter.text), 11, ["label", "onClick"]); }), 128)) ])) ]), default: withCtx(() => [ withDirectives((openBlock(), createElementBlock("span", { class: normalizeClass([ `table-filter-trigger`, `none-outline`, _ctx.column.filterOpened ? "opened" : "" ]), onClick: _ctx.showFilterPanel }, [ createVNode(_component_hl_icon, null, { default: withCtx(() => [ renderSlot(_ctx.$slots, "filter-icon", { filterOpened: _ctx.column.filterOpened }, () => [ createVNode(_component_system_filter) ]) ]), _: 3 }) ], 10, ["onClick"])), [ [_directive_click_outside, _ctx.hideFilterPanel, _ctx.popperPaneRef] ]) ]), _: 3 }, 8, ["visible", "placement", "popper-class"]); } var FilterPanel = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { FilterPanel as default }; //# sourceMappingURL=filter-panel.mjs.map