UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

624 lines (623 loc) 20.9 kB
import { getCustomClass as St, withInstall as bt } from "../common/index.esm.js"; import { createVNode as g, defineComponent as It, ref as p, computed as C, onMounted as Bt, nextTick as Dt, onUnmounted as Ot, watch as de, createTextVNode as Ft } from "vue"; import { useResizeObserver as Rt } from "@vueuse/core"; import { isUndefined as S } from "lodash-es"; import { LocaleService as Se } from "../locale/index.esm.js"; import { getHierarchyRow as xt, useIdentify as Gt, useGroupData as Ht, useFilter as jt, useHierarchy as Vt, useLoading as Nt, useDataView as Pt, useSelection as kt, useSelectHierarchyItem as _t, usePagination as zt, useDataViewContainerStyle as Mt, useCommandColumn as Tt, useSettingColumn as At, useColumn as Lt, useSort as Et, useGroupColumn as Wt, useRow as Ut, useEdit as qt, useVisualDataBound as Yt, useVisualDataCell as $t, useVisualDataRow as Jt, useVisualData as Kt, useCellPosition as Qt, useSidebar as Xt, useVirtualScroll as Zt, useFitColumn as ea, useFilterHistory as ta, useColumnFilter as aa, useDragColumn as la, getColumnHeader as na, getSidebar as oa, getDisableMask as ia, getHorizontalScrollbar as ua, getVerticalScrollbar as sa, getEmpty as ra, getPagination as da, getSummary as ca } from "../data-view/index.esm.js"; const Sa = { /** 启用分页 */ enable: { type: Boolean, default: !1 }, /** 当前页码 */ index: { type: Number, default: 1 }, /** 分页交互模式 */ mode: { type: String, default: "server" }, /** 显示页码输入框 */ showGoto: { type: Boolean, default: !1 }, /** 显示页码 */ showIndex: { type: Boolean, default: !0 }, /** 显示每页记录数 */ showLimits: { type: Boolean, default: !1 }, /** 显示分页汇总信息 */ showPageInfo: { type: Boolean, default: !0 }, /** 默认每页记录数 */ size: { type: Number, default: 20 }, /** 可选择的没有记录数据 */ sizeLimits: { type: Array, default: [10, 20, 30, 50, 100] }, /** 总记录数 */ total: { type: Number, default: 0 } }, ba = { /** 启用排序 */ enable: { type: Boolean, default: !1 }, /** 排序字段集合 */ fields: { type: Array, default: [] }, /** 排序交互模式 */ mode: { type: String, default: "client" }, /** 多列排序 */ multiSort: { type: Boolean, default: !1 } }, Ia = { /** 自定义分组合计内容 */ customGroupRow: { type: Function, default: () => { } }, /** 自定义分组行样式 */ customGroupRowStyle: { type: Function, default: () => { } }, /** 自行分组合计行样式 */ customSummaryStyle: { type: Function, default: () => { } }, /** 启用行数据分组 */ enable: { type: Boolean, default: !1 }, /** 分组行合并列数 */ groupColSpan: { type: Number, default: 1 }, /** 行数据分组字段;多字段分组以英文逗号分隔 */ groupFields: { type: Array, default: [] }, /** 在DataGrid中显示被分组的列 */ showGroupedColumn: { type: Boolean, default: !0 }, /** 显示分组面板 */ showGroupPanel: { type: Boolean, default: !1 }, /** 启用合计行 */ showSummary: { type: Boolean, default: !1 }, /** 显示合计行位置; */ summaryPosition: { type: String, default: "separate" } }, Ba = { /** 启用筛选 */ enable: { type: Boolean, default: !1 }, /** DataGrid筛选风格 */ filterStyle: { type: String, default: "filter-column" }, /** 筛选交互模式 */ mode: { type: String, default: "server" }, /** 显示过滤条件工具条 */ showSummary: { type: Boolean, default: !0 } }, Da = { /** 允许折行显示列标题 */ wrapHeadings: { type: Boolean, default: !1 } }, Oa = { /** 自定义行样式 */ customRowStyle: { type: Function, default: () => { } }, /** 禁止行选中表达式 */ disable: { type: Function, default: () => { } }, /** 默认行高度为 29px */ height: { type: Number, default: 28 }, /** 鼠标滑过行效果 */ showHovering: { type: Boolean, default: !0 }, /** 禁止数据折行 */ wrapContent: { type: Boolean, default: !1 } }, Fa = { /** 显示合计信息 */ enable: { type: Boolean, default: !1 }, /** 合计行自定义样式,对启用合计行模板无效 */ customSummaryStyle: { type: Function, default: () => { } }, /** 分组合计字段 */ groupFields: { type: Array, default: [] }, /** 合计交互模式 */ mode: { type: String, default: "client" }, /** 合计行显示位置, top: 顶部 bottom: 底部, both: 顶部与底部同时显示 */ position: { type: String, default: "bottom" } }, Ra = { /** 自动列宽。设为true后,所有列将填满表格并不会出现横向滚动条。 */ fitColumns: { type: Boolean, default: !1 }, /** 自动适配列宽度模式 */ fitMode: { type: String, default: "average" }, groups: { type: Array, defaut: [] }, /** 允许拖动表头改变列显示顺序 */ reorderColumn: { type: Boolean, default: !1 }, /** 允许拖动改变列宽度 */ resizeColumn: { type: Boolean, default: !0 }, /** 双击表头列自适应内容宽度 */ resizeColumnOnDoubleClick: { type: Boolean, default: !0 } }, xa = { /** 编辑时选中文本 */ selectOnEditing: { type: Boolean, default: !1 }, /** 编辑模式; row:整行编辑,cell: 单元格编辑 */ editMode: { type: String, default: "cell" } }, Ga = { /** show loading */ show: { type: Boolean, default: !1 }, /** message on display when loading */ message: { type: String, default: `${Se.getLocaleValue("datagrid.loadingMessage")}...` } }, fa = { /** 自定义样式 */ customClass: { type: String, default: "" }, /** 排序配置 */ sort: { type: Object }, /** 筛选配置 */ filter: { type: Object }, /** 自动勾选子节点 */ autoCheckChildren: { type: Boolean, default: !1 }, /** 列集合 */ columns: { type: Array, default: [] }, /** 列配置 */ columnOption: { type: Object }, /** 命令列配置选项 */ commandOption: { type: Object, default: { enable: !1, commands: [] } }, /** 被绑定数据 */ data: { type: Array, default: [] }, /** 禁用组件 */ disabled: { type: Boolean, default: !1 }, /** 用于控制节点禁用状态的字段 */ disabledField: { type: String, default: "disabled" }, /** 用于显示信息的字段 */ displayField: { type: String, default: "name" }, /** 允许编辑 */ editable: { type: Boolean, default: !1 }, /** 编辑配置 */ editOption: { type: Object, default: { selectOnEditing: !1, editMode: "cell" } }, /** 适配父组件尺寸 */ fit: { type: Boolean, default: !1 }, /** 列标题配置 */ header: { type: Object }, /** 高度 */ height: { type: Number, default: -1 }, /** 层级关系配置对象 */ hierarchy: { type: Object, default: { cascadeOption: { autoCancelParent: !0, autoCheckChildren: !1, autoCheckParent: !1, selectionRange: "All" }, parentIdField: "parent" } }, /** DataGrid组件唯一标识 */ id: { type: String, default: "" }, /** 被绑定数据的标识字段 */ idField: { type: String, default: "id", require: !0 }, /** async loading data */ loadData: { type: Function }, // 是否展示 loading loading: { type: Boolean, default: !1 }, /** 最小高度 */ minHeight: { type: Number, default: 300 }, /** 最小宽度 */ minWidth: { type: Number, default: 400 }, /** 新建数据 */ newDataItem: { type: Function, default: () => { } }, /** 分页配置 */ pagination: { type: Object, default: { enable: !1, size: -1 } }, /** 行号配置 */ rowNumber: { type: Object, default: { enable: !0, width: 32, heading: Se.getLocaleValue("datagrid.lineNumberTitle") } }, /** 行配置 */ rowOption: { type: Object, default: { wrapContent: !1 } }, /** 选择配置 */ selection: { type: Object, default: { enableSelectRow: !0, multiSelect: !1, multiSelectMode: "DependOnCheck", showCheckbox: !1, showSelectAll: !1, showSelection: !1 } }, /** 已选数据标识 */ selectionValues: { type: Array, default: [] }, /** 显示边框 */ showBorder: { type: Boolean, default: !1 }, /** 显示列头 */ showHeader: { type: Boolean, default: !0 }, /** 显示横向行分割线 */ showHorizontalLines: { type: Boolean, default: !0 }, /** 显示节点连接线 */ showLines: { type: Boolean, default: !1 }, /** 显示配置按钮 */ showOptions: { type: Boolean, default: !1 }, /** 显示滚动条 */ showScrollBar: { type: String, default: "auto" }, /** 显示设置按钮 */ showSetting: { type: Boolean, default: !1 }, /** 显示条纹 */ showStripe: { type: Boolean, default: !0 }, /** 显示树节点图标 */ showTreeNodeIcons: { type: Boolean, default: !1 }, /** 显示纵向列分割线 */ showVerticallLines: { type: Boolean, default: !1 }, /** 树节点图标数据 */ treeNodeIconsData: { type: [Object, String], default: {} }, /** 宽度 */ width: { type: Number, default: -1 }, /** 启用虚拟渲染 */ virtualized: { type: Boolean, default: !1 }, /** 空数据模板 */ emptyTemplate: { type: Object }, /** 合计配置 */ summary: { type: Object, default: { // 默认合计行开启后,后面不展示值,所以默认不开启 enable: !1, groupFields: ["numericField1", "numericField2"] } } }; function ma(t, c, ce, k, b, v, y, I, _, n, B, z, j, o, V, J, M) { const { calculateCellPositionInRow: T } = v, { columnContext: h, hasLeftFixedColumn: A, hasRightFixedColumn: K } = y, { gridDataStyle: Q, leftFixedGridDataStyle: l, rightFixedGridDataStyle: X } = o, { renderDataRow: i } = xt(t, c, h, M, I, _, n, B, z, j, o, V, J), x = [i]; function N(d, ee) { const te = T(d); return M.value.filter((D) => D.visible !== !1).map((D, W) => x[D.type](D, te, ee, W)); } function L() { return g("div", { ref: k, class: "fv-grid-content-left-fixed" }, [g("div", { class: "fv-grid-data", style: l.value }, [N(h.value.leftColumns.filter((d) => d.visible), "left")])]); } function Z() { return g("div", { ref: ce, class: "fv-grid-content-primary" }, [g("div", { class: "fv-grid-data", style: Q.value }, [N(h.value.primaryColumns.filter((d) => d.visible), "primary")])]); } function w() { return g("div", { ref: b, class: "fv-grid-content-right-fixed" }, [g("div", { class: "fv-grid-data", style: X.value }, [N(h.value.rightColumns.filter((d) => d.visible), "right")])]); } function E() { const d = []; return A.value && d.push(L()), d.push(Z()), K.value && d.push(w()), d; } return { renderDataArea: E }; } const ya = /* @__PURE__ */ It({ name: "FTreeGrid", props: fa, emits: ["selectionChange", "clickRow", "expandNode", "unSelectItem", "dblclickNode", "doubleClickRow", "unSelectItem", "selectItem", "filterChanged", "sortChanged"], setup(t, c) { var he, Ce; const k = ((he = t.rowOption) == null ? void 0 : he.height) || 28, b = p(20), v = p(t.columns), y = Gt(t), { idField: I } = y, _ = p(), n = p(), B = p(), z = p(), j = p(), o = p([]), V = p(!1), J = p(((Ce = t.rowOption) == null ? void 0 : Ce.wrapContent) || !1), M = Ht(t, y), T = jt(t, c), h = Vt(t), { collapseField: A } = h, { showLoading: K, renderLoading: Q } = Nt(t, _), l = Pt(t, /* @__PURE__ */ new Map(), T, h, y), { dataView: X } = l, i = kt(t, l, y, o, c), { showSelection: x, selectedValues: N } = i, L = _t(t, o, l, y, i, c), Z = C(() => t.disabled), w = C(() => t.virtualized ? Math.min(l.dataView.value.length, b.value) : l.dataView.value.length), E = zt(t, l), { shouldRenderPagination: d } = E, { containerStyleObject: ee } = Mt(t), te = Tt(t), { applyCommands: D } = te; D(v); const { applyColumnSetting: W, removeColumnSetting: be } = At(t); t.showSetting && W(v); const P = Lt(t, c), ae = Et(t), { applyColumnSorter: fe, columnContext: U, updateColumnRenderContext: Ie } = P; fe(l, ae); const le = Wt(t, U), G = Ut(t, c, i, y), H = qt(t, c, y, G, o), ne = Yt(t), Be = $t(t, H, ne), De = Jt(t, l, H, h, y, ne, Be), oe = Kt(t, v, l, w, 0, De), { getVisualData: q } = oe, Oe = Qt(t, U), ie = Xt(t, i), { sidebarWidth: Fe } = ie, f = Zt(t, l, o, U, oe, w, 0, Fe), { onWheel: Re, dataGridWidth: me, viewPortHeight: ye, viewPortWidth: Y, resetScroll: ue, updateVisibleRowsOnLatestVisibleScope: xe } = f, ve = ea(t, U, n, Y, le), { calculateColumnsSize: $ } = ve, ge = ta(), Ge = aa(n, j, l, ge, f), He = la(t, c, P, l, le, M, f), je = C(() => { const e = { "fv-grid": !0, "fv-grid-bordered": t.showBorder, "fv-grid-horizontal-bordered": t.showHorizontalLines, "fv-datagrid-strip": t.showStripe }; return St(e, t.customClass); }), Ve = C(() => ({ "fv-grid-content": !0, "fv-grid-content-hover": V.value, "fv-grid-wrap-content": J.value })), { renderDataArea: Ne } = ma(t, c, B, z, j, Oe, P, l, H, h, G, i, L, f, oe, ne, o), { renderGridHeader: Pe, renderGridColumnResizeOverlay: ke, shouldShowHeader: _e } = na(t, c, n, z, j, P, l, He, Ge, T, ge, ve, le, i, ie, ae, f, Y, o), { renderDataGridSidebar: ze } = oa(t, G, i, ie, f), { renderDisableMask: Me } = ia(), { renderHorizontalScrollbar: Te } = ua(t, n, f), { renderVerticalScrollbar: Ae } = sa(t, n, f); function Le() { var e, a, u; if (n.value && n.value.clientHeight > 0 && ((e = n.value) == null ? void 0 : e.clientWidth) > 0) { const r = Math.ceil(n.value.clientHeight / k); r > b.value && (b.value = r, xe()), ye.value = ((a = B.value) == null ? void 0 : a.clientHeight) || 0, me.value = ((u = n.value) == null ? void 0 : u.clientWidth) || 0, $(); } } Bt(() => { n.value && (b.value = Math.max(Math.ceil(n.value.clientHeight / k), b.value), o.value = q(0, w.value + 0 - 1), Rt(n.value, Le), $(), Dt(() => { n.value && (me.value = n.value.clientWidth), B.value && (Y.value = B.value.clientWidth, ye.value = B.value.clientHeight); })), K.value && Q(); }), Ot(() => { }), de(Y, () => { n.value && $(); }); function Ee(e) { l.collapseTo(e), l.reOrderVisibleIndex(), ue(); } function We(e) { l.expandTo(e), l.reOrderVisibleIndex(), ue(); } function se() { const e = i.getSelectionRow(); return e ? e.dataIndex - 1 : -1; } function Ue() { const e = se(); l.insertNewDataItem(e), o.value = q(0, w.value + 0 - 1); } function qe() { const e = se(); l.insertNewChildDataItem(e), o.value = q(0, w.value + 0 - 1); } function Ye(e, a) { const u = o.value.find((m) => m.raw[I.value] === a), r = u ? u.dataIndex - 1 : -1; l.insertNewChildDataItems(e, r); } function $e() { const e = se(), a = L.getNextSelectableHierarchyItemId(e); l.removeHierarchyDataItem(e), o.value = q(0, w.value + 0 - 1), a && i.selectItemById(a); } function Je(e) { H.onEditingRow(e); } function Ke(e) { H.acceptEditingRow(e); } function Qe(e) { H.cancelEditingRow(e); } function re(e) { e && (v.value = e, D(v), Ie(v.value), fe(l, ae), $()); } de(() => t.columns, (e) => { re(e); }); function Xe(e, a) { e && (l.load(e), l.reOrderVisibleIndex(), a != null && a.keepScrollPosition ? f.scrollTo(f.offsetY.value) : ue()); } function Ze(e) { i.selectItemById(e); } function et(e) { const a = o.value.find((u) => u.raw[y.idField.value] === e); a && G.clickRowItem(a); } function tt(e) { G.activeRowById(e); } function at(e) { i.selectItemByIds(e); } function lt() { return i.getSelectedItems(); } function pe() { i.clearSelection(); } const nt = C(() => !o.value || !o.value.length), { renderEmpty: ot } = ra(t, c); function it() { return i.getSelectionRow(); } function ut(e) { i.unSelectItemByIds(e); } function st() { return i.currentSelectedDataId.value; } function rt(e, a, u) { const r = X.value.find((m) => m[I.value] === e); if (r) { if (Object.keys(r).forEach((s) => { Object.prototype.hasOwnProperty.call(a, s) && (r[s] = a[s]); }), u) { const { collapseField: s, disabledField: O, checkedField: F, visibleField: R } = u; s && !S(a[s]) && (r.__fv_collapse__ = a[s]), F && !S(a[F]) && (r.__fv_checked__ = a[F]), O && !S(a[O]) && (r.__fv_disabled__ = a[O]), R && !S(a[R]) && (r.__fv_visible__ = a[R]); } const m = o.value.find((s) => s.raw[I.value] === e), we = o.value.findIndex((s) => s.raw[I.value] === e); if (m) { if (m.raw = r, Object.keys(m.data).forEach((s) => { m.data[s].updateData(r); }), u) { const { collapseField: s, disabledField: O, checkedField: F, visibleField: R } = u; s && !S(a[s]) && (m.collapse = a[s]), F && !S(a[F]) && (m.checked = a[F]), O && !S(a[O]) && (m.disabled = a[O]), R && !S(a[R]) && (m.visible = a[R]); } o.value = [...o.value.slice(0, we), m, ...o.value.slice(we + 1)], l.updateSummary(); } } } function dt(e) { return Object.prototype.hasOwnProperty.call(e, "raw") ? l.hasRealChildren(e.raw) : l.hasRealChildren(e); } function ct(e) { const a = l.dataView.value.find((u) => u[I.value] === e); return a ? a[A.value] : ""; } function ft() { return A.value; } de(() => t.showSetting, (e, a) => { e !== a && (e ? W(v) : be(v), re(v.value)); }); function mt(e) { return o.value.filter((a) => e.includes(a.raw[t.idField])); } function yt(e) { const a = y.idField.value, u = o.value.find((r) => r.raw[a] === e); u && G.selectRow(u); } function vt() { i.keepSelectingOnPaging.value || pe(), l.updateVisibleDataSummary(o.value); } c.expose({ activeRowById: tt, addNewDataItem: Ue, addNewChildDataItem: qe, addChildrenToNode: Ye, collapseTo: Ee, expandTo: We, removeDataItem: $e, editDataItem: Je, acceptDataItem: Ke, cancelDataItem: Qe, updateColumns: re, updateDataSource: Xe, selectItemById: Ze, selectItemByIds: at, getSelectedItems: lt, clearSelection: pe, getSelectionRow: it, clickRowItemById: et, unSelectItemByIds: ut, getCurrentRowId: st, reassignRowData: rt, hasChildren: dt, getCollapseField: ft, getCollapseStatusById: ct, getVisibleDataByIds: mt, selectRowById: yt, updateDerivedData: vt }); const gt = C(() => { const e = {}; return f.shouldShowHorizontalScrollbar.value && (e.paddingBottom = "10px"), f.shouldShowVirticalScrollbar.value && (e.paddingRight = "10px"), e; }), pt = C(() => ({ ...ee.value, borderRadius: "5px" })); da(t, c, l, f, E, i); const ht = C(() => ({ "d-flex": !0, "justify-content-between": d.value && x.value, "justify-content-end": d.value && !x.value, "position-relative": !0 })), Ct = C(() => ({ "d-flex": !0, "align-items-center": !0 })), { renderDataGridSummary: wt } = ca(t, l, P); return () => g("div", { ref: _, class: je.value, style: pt.value, onWheel: Re }, [n.value && _e.value && Pe(), g("div", { ref: n, class: Ve.value, onMouseover: () => V.value = !0, onMouseleave: () => V.value = !1, style: gt.value }, [n.value && ze(o), n.value && Ne(), n.value && nt.value && ot(), n.value && Te(), n.value && Ae()]), n.value && wt(), x.value && g("div", { class: ht.value }, [x.value && g("div", { class: Ct.value }, [g("div", null, ["已选:" + N.value.length, Ft(" 条")])])]), ke(), Z.value && Me()]); } }), Ha = bt(ya); export { ya as FTreeGrid, Ra as columnOptions, Ha as default, xa as editOptions, Ba as filterOptions, Ia as groupOptions, Da as headerOptions, Ga as loadingOptions, Sa as paginationOptions, Oa as rowOptions, ba as sortOptions, Fa as summaryOptions, fa as treeGridProps };