UNPKG

hongluan-ui

Version:
292 lines (287 loc) 10 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var index = require('../../checkbox/index.js'); var index$1 = require('../../checkbox-group/index.js'); var index$4 = require('../../icon/index.js'); require('../../system-icon/index.js'); require('../../../directives/index.js'); require('../../../hooks/index.js'); var index$3 = require('../../tooltip/index.js'); var index$5 = require('../../button/index.js'); var index$2 = require('../../scrollbar/index.js'); var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js'); var filter = require('../../system-icon/src/filter.js'); var index$6 = require('../../../directives/click-outside/index.js'); var index$7 = require('../../../hooks/use-locale/index.js'); const _sfc_main = vue.defineComponent({ name: "TableFilterPanel", components: { HlCheckbox: index.HlCheckbox, HlCheckboxGroup: index$1.HlCheckboxGroup, HlScrollbar: index$2.HlScrollbar, HlTooltip: index$3.HlTooltip, HlIcon: index$4.HlIcon, HlButton: index$5.HlButton, SystemFilter: filter["default"] }, directives: { ClickOutside: index$6["default"] }, props: { placement: { type: String, default: "bottom-start" }, store: { type: Object }, column: { type: Object }, upDataColumn: { type: Function } }, setup(props) { const instance = vue.getCurrentInstance(); const { t } = index$7.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 = vue.ref(false); const tooltip = vue.ref(null); const filters = vue.computed(() => { return props.column && props.column.filters; }); const filterClassName = vue.computed(() => { if (props.column.filterClassName) { return `popover popover-table-filter ${props.column.filterClassName}`; } return "popover popover-table-filter"; }); const filterValue = vue.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 = vue.computed({ get() { if (props.column) { return props.column.filteredValue || []; } return []; }, set(value) { if (props.column) { props.upDataColumn("filteredValue", value); } } }); const multiple = vue.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(); }; vue.watch(tooltipVisible, (value) => { if (props.column) { props.upDataColumn("filterOpened", value); } }, { immediate: true }); const popperPaneRef = vue.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 = vue.resolveComponent("hl-checkbox"); const _component_hl_checkbox_group = vue.resolveComponent("hl-checkbox-group"); const _component_hl_scrollbar = vue.resolveComponent("hl-scrollbar"); const _component_hl_button = vue.resolveComponent("hl-button"); const _component_system_filter = vue.resolveComponent("system-filter"); const _component_hl_icon = vue.resolveComponent("hl-icon"); const _component_hl_tooltip = vue.resolveComponent("hl-tooltip"); const _directive_click_outside = vue.resolveDirective("click-outside"); return vue.openBlock(), vue.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: vue.withCtx(() => [ _ctx.multiple ? (vue.openBlock(), vue.createElementBlock("div", { key: 0 }, [ vue.createElementVNode("div", { class: "table-filter-content" }, [ vue.createVNode(_component_hl_scrollbar, { "wrap-class": "table-filter-wrap" }, { default: vue.withCtx(() => [ vue.createVNode(_component_hl_checkbox_group, { modelValue: _ctx.filteredValue, "onUpdate:modelValue": ($event) => _ctx.filteredValue = $event, class: "table-filter-checkbox-group" }, { default: vue.withCtx(() => [ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.filters, (filter) => { return vue.openBlock(), vue.createBlock(_component_hl_checkbox, { key: filter.value, label: filter.value }, { default: vue.withCtx(() => [ vue.createTextVNode(vue.toDisplayString(filter.text), 1) ]), _: 2 }, 1032, ["label"]); }), 128)) ]), _: 1 }, 8, ["modelValue", "onUpdate:modelValue"]) ]), _: 1 }) ]), vue.createElementVNode("div", { class: "table-filter-bottom" }, [ vue.createVNode(_component_hl_button, { class: vue.normalizeClass({ "is-disabled": _ctx.filteredValue.length === 0 }), disabled: _ctx.filteredValue.length === 0, onClick: _ctx.handleConfirm }, { default: vue.withCtx(() => [ vue.createTextVNode(vue.toDisplayString(_ctx.t("hl.table.confirmFilter")), 1) ]), _: 1 }, 8, ["class", "disabled", "onClick"]), vue.createVNode(_component_hl_button, { type: "button", onClick: _ctx.handleReset }, { default: vue.withCtx(() => [ vue.createTextVNode(vue.toDisplayString(_ctx.t("hl.table.resetFilter")), 1) ]), _: 1 }, 8, ["onClick"]) ]) ])) : (vue.openBlock(), vue.createElementBlock("ul", { key: 1, class: "table-filter-list" }, [ vue.createElementVNode("li", { class: vue.normalizeClass([ "table-filter-list-item", { "is-active": _ctx.filterValue === void 0 || _ctx.filterValue === null } ]), onClick: ($event) => _ctx.handleSelect(null) }, vue.toDisplayString(_ctx.t("hl.table.clearFilter")), 11, ["onClick"]), (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.filters, (filter) => { return vue.openBlock(), vue.createElementBlock("li", { key: filter.value, class: vue.normalizeClass(["table-filter-list-item", _ctx.isActive(filter) ? "is-active" : ""]), label: filter.value, onClick: ($event) => _ctx.handleSelect(filter.value) }, vue.toDisplayString(filter.text), 11, ["label", "onClick"]); }), 128)) ])) ]), default: vue.withCtx(() => [ vue.withDirectives((vue.openBlock(), vue.createElementBlock("span", { class: vue.normalizeClass([ `table-filter-trigger`, `none-outline`, _ctx.column.filterOpened ? "opened" : "" ]), onClick: _ctx.showFilterPanel }, [ vue.createVNode(_component_hl_icon, null, { default: vue.withCtx(() => [ vue.renderSlot(_ctx.$slots, "filter-icon", { filterOpened: _ctx.column.filterOpened }, () => [ vue.createVNode(_component_system_filter) ]) ]), _: 3 }) ], 10, ["onClick"])), [ [_directive_click_outside, _ctx.hideFilterPanel, _ctx.popperPaneRef] ]) ]), _: 3 }, 8, ["visible", "placement", "popper-class"]); } var FilterPanel = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render]]); exports["default"] = FilterPanel; //# sourceMappingURL=filter-panel.js.map