UNPKG

tdesign-mobile-vue

Version:
324 lines (320 loc) 13.9 kB
/** * tdesign v1.7.0 * (c) 2024 TDesign Group * @license MIT */ import { _ as _defineProperty } from '../_chunks/dep-219bb5a7.mjs'; import { defineComponent, ref, h, computed, createVNode } from 'vue'; import { g as get_1 } from '../_chunks/dep-4f59c35d.mjs'; import { i as isFunction_1 } from '../_chunks/dep-91d696ea.mjs'; import { i as isString_1 } from '../_chunks/dep-6303c50c.mjs'; import baseTableProps from './base-table-props.mjs'; import config from '../config.mjs'; import useClassName from './hooks/useClassName.mjs'; import useStyle, { formatCSSUnit } from './hooks/useStyle.mjs'; import { Loading } from '../loading/index.mjs'; import { u as useConfig } from '../_chunks/dep-b9b8ead5.mjs'; import { useTNodeJSX } from '../hooks/tnode.mjs'; import '../_chunks/dep-620d73f7.mjs'; import '../_chunks/dep-8bf3054e.mjs'; import '../_chunks/dep-c51d4905.mjs'; import '../_chunks/dep-019e292f.mjs'; import '../_chunks/dep-32364550.mjs'; import '../_chunks/dep-a836a38c.mjs'; import '../_chunks/dep-3d249f65.mjs'; import '../_chunks/dep-9b2de386.mjs'; import '../_chunks/dep-89951f45.mjs'; import '../_chunks/dep-08bc7a4c.mjs'; import '../_chunks/dep-6bc862af.mjs'; import '../_chunks/dep-e6c129ab.mjs'; import '../_chunks/dep-4931819d.mjs'; import '../_chunks/dep-8140c29b.mjs'; import '../_chunks/dep-0d52e58f.mjs'; import '../hooks/useClass.mjs'; import '../loading/loading.mjs'; import '../loading/icon/gradient.mjs'; import '../_common/js/loading/circle-adapter.mjs'; import '../_common/js/utils/set-style.mjs'; import '../_common/js/utils/helper.mjs'; import '../_chunks/dep-f0f403be.mjs'; import '../_chunks/dep-8d37dbf8.mjs'; import '../_chunks/dep-8ece47c6.mjs'; import '../_chunks/dep-cd74809c.mjs'; import '../_chunks/dep-74a5dff9.mjs'; import '../_chunks/dep-1bbfa76e.mjs'; import '../_chunks/dep-52fdc8e1.mjs'; import '../loading/icon/spinner.mjs'; import '../loading/props.mjs'; import '../shared/dom.mjs'; import '../shared/index.mjs'; import '../shared/functions.mjs'; import '../shared/util.mjs'; import '../shared/component.mjs'; import '../shared/constants.mjs'; import '../shared/render.mjs'; import '../_chunks/dep-60cadef8.mjs'; import '../_chunks/dep-0ea7bbde.mjs'; import '../_chunks/dep-b437ef0b.mjs'; import '../shared/render-tnode.mjs'; import '../shared/useToggle/index.mjs'; import '../shared/useCountDown/index.mjs'; import '../_chunks/dep-80e4de18.mjs'; import '@vueuse/core'; import '../shared/useCountDown/utils.mjs'; import '../shared/useDefault/index.mjs'; import '../shared/useChildSlots/index.mjs'; import '../shared/useVModel/index.mjs'; import '../_chunks/dep-6917b9bc.mjs'; import '../shared/useTouch/index.mjs'; import '../shared/useScrollParent/index.mjs'; import '../shared/useExpose/index.mjs'; import '../shared/useTest/index.mjs'; import '../shared/useClickAway/index.mjs'; import '../shared/useGesture/index.mjs'; import '@use-gesture/vanilla'; import '../shared/hover.mjs'; import './style/css.mjs'; import '../loading/type.mjs'; import '../loading/plugin.mjs'; import '../_chunks/dep-ac139980.mjs'; import '../_chunks/dep-d2161895.mjs'; import '../_chunks/dep-10f4d030.mjs'; import '../_chunks/dep-8ee6f5cd.mjs'; import '../_chunks/dep-e57d46f3.mjs'; import '../_chunks/dep-4f44985d.mjs'; import '../_chunks/dep-b84be35c.mjs'; import '../_chunks/dep-933f3a85.mjs'; import '../_chunks/dep-154c1925.mjs'; import '../_chunks/dep-ba131d9c.mjs'; import '../_chunks/dep-007f294e.mjs'; import '../_common/js/global-config/mobile/default-config.mjs'; import '../_common/js/global-config/mobile/locale/zh_CN.mjs'; import '../_chunks/dep-161f0c44.mjs'; import '../_chunks/dep-5fd0eaa4.mjs'; import '../_chunks/dep-3c59bf72.mjs'; import '../hooks/render-tnode.mjs'; import '../_chunks/dep-40507aac.mjs'; import '../_chunks/dep-2bce42ea.mjs'; import '../_chunks/dep-6c53a3e4.mjs'; import '../config-provider/type.mjs'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var prefix = config.prefix; var BaseTable = defineComponent({ name: "".concat(prefix, "-base-table"), props: baseTableProps, emits: ["cell-click", "row-click", "scroll"], setup: function setup(props, context) { var tableRef = ref(); var tableContentRef = ref(); var theadRef = ref(); var tableElmRef = ref(); var renderTNodeJSX = useTNodeJSX(); var _useClassName = useClassName(), classPrefix = _useClassName.classPrefix, tableLayoutClasses = _useClassName.tableLayoutClasses, tableHeaderClasses = _useClassName.tableHeaderClasses, tableBaseClass = _useClassName.tableBaseClass, tdAlignClasses = _useClassName.tdAlignClasses, tdEllipsisClass = _useClassName.tdEllipsisClass; var _useConfig = useConfig("table"), globalConfig = _useConfig.globalConfig; var defaultLoadingContent = h(Loading, _objectSpread({}, props.loadingProps)); var _useStyle = useStyle(props), tableClasses = _useStyle.tableClasses, tableContentStyles = _useStyle.tableContentStyles, tableElementStyles = _useStyle.tableElementStyles; var defaultColWidth = props.tableLayout === "fixed" ? "80px" : void 0; var theadClasses = computed(function () { return [tableHeaderClasses.header, _defineProperty(_defineProperty({}, tableHeaderClasses.fixed, Boolean(props.maxHeight || props.height)), tableBaseClass.bordered, props.bordered)]; }); var tbodyClasses = computed(function () { return [tableBaseClass.body]; }); var ellipsisClasses = computed(function () { return ["".concat(classPrefix, "-table__ellipsis"), "".concat(classPrefix, "-text-ellipsis")]; }); var handleRowClick = function handleRowClick(row, rowIndex, e) { var _props$onRowClick; (_props$onRowClick = props.onRowClick) === null || _props$onRowClick === void 0 || _props$onRowClick.call(props, { row: row, index: rowIndex, e: e }); }; var handleCellClick = function handleCellClick(row, col, rowIndex, colIndex, e) { var _props$onCellClick; if (col.stopPropagation) { e.stopPropagation(); } (_props$onCellClick = props.onCellClick) === null || _props$onCellClick === void 0 || _props$onCellClick.call(props, { row: row, col: col, rowIndex: rowIndex, colIndex: colIndex, e: e }); }; var dynamicBaseTableClasses = computed(function () { return [tableClasses.value]; }); var tableElmClasses = computed(function () { return [[tableLayoutClasses[props.tableLayout || "fixed"]]]; }); var renderCell = function renderCell(params, cellEmptyContent) { var _context$slots; var col = params.col, row = params.row, rowIndex = params.rowIndex; if (col.colKey === "serial-number") { return rowIndex + 1; } if (isFunction_1(col.cell)) { return col.cell(h, params); } if (context.slots[col.colKey]) { return context.slots[col.colKey](params); } if (isString_1(col.cell) && (_context$slots = context.slots) !== null && _context$slots !== void 0 && _context$slots[col.cell]) { return context.slots[col.cell](params); } var r = get_1(row, col.colKey); if (![void 0, "", null].includes(r)) return r; if (cellEmptyContent) { return isFunction_1(cellEmptyContent) ? cellEmptyContent(h, params) : cellEmptyContent; } if (context.slots.cellEmptyContent) return context.slots.cellEmptyContent(params); if (context.slots["cell-empty-content"]) return context.slots["cell-empty-content"](params); return r; }; var loadingClasses = computed(function () { return ["".concat(classPrefix, "-table__loading--full")]; }); var onInnerVirtualScroll = function onInnerVirtualScroll(e) { var _props$onScroll; (_props$onScroll = props.onScroll) === null || _props$onScroll === void 0 || _props$onScroll.call(props, { params: e }); }; var tdClassName = function tdClassName(td_item) { var className = ""; if (td_item.ellipsis) { className = tdEllipsisClass; } if (td_item.align && td_item.align !== "left") { className = "".concat(className, " ").concat(tdAlignClasses["".concat(td_item.align)]); } return className; }; var colStyle = function colStyle(col_item) { return { width: "".concat(formatCSSUnit(col_item.width || defaultColWidth)), minWidth: "".concat(!formatCSSUnit(col_item.width || defaultColWidth) && !col_item.minWidth && props.tableLayout === "fixed" ? "80px" : formatCSSUnit(col_item.minWidth)) }; }; var thClassName = function thClassName(item_th) { var className = ""; if (item_th.colKey) { className = "".concat(classPrefix, "-table__th-").concat(item_th.colKey); } if (item_th.ellipsisTitle || item_th.ellipsis) { className = "".concat(className, " ").concat(tdEllipsisClass); } if (item_th.align && item_th.align !== "left") { className = "".concat(className, " ").concat(tdAlignClasses["".concat(item_th.align)]); } return className; }; var renderTitle = function renderTitle(item_th, index) { if (isFunction_1(item_th === null || item_th === void 0 ? void 0 : item_th.title)) { return item_th === null || item_th === void 0 ? void 0 : item_th.title(h, { col: item_th, colIndex: index }); } return item_th === null || item_th === void 0 ? void 0 : item_th.title; }; var renderTableBody = function renderTableBody() { var _props$data, _props$data2; var renderContentEmpty = renderTNodeJSX("empty") || globalConfig.value.empty; if (!((_props$data = props.data) !== null && _props$data !== void 0 && _props$data.length) && renderContentEmpty) { var _props$columns; return createVNode("tr", { "class": tableBaseClass.emptyRow }, [createVNode("td", { "colspan": (_props$columns = props.columns) === null || _props$columns === void 0 ? void 0 : _props$columns.length }, [createVNode("div", { "class": tableBaseClass.empty }, [renderContentEmpty])])]); } if ((_props$data2 = props.data) !== null && _props$data2 !== void 0 && _props$data2.length) { var _props$data3; return (_props$data3 = props.data) === null || _props$data3 === void 0 ? void 0 : _props$data3.map(function (tr_item, tr_index) { var _props$columns2; return createVNode("tr", { "key": tr_index, "onClick": function onClick($event) { handleRowClick(tr_item, tr_index, $event); } }, [(_props$columns2 = props.columns) === null || _props$columns2 === void 0 ? void 0 : _props$columns2.map(function (td_item, td_index) { return createVNode("td", { "key": td_index, "class": tdClassName(td_item), "onClick": function onClick($event) { handleCellClick(tr_item, td_item, tr_index, td_index, $event); } }, [createVNode("div", { "class": td_item.ellipsis && ellipsisClasses.value }, [renderCell({ row: tr_item, col: td_item, rowIndex: tr_index, colIndex: td_index }, props.cellEmptyContent)])]); })]); }); } }; return function () { var _props$columns3, _props$columns4; var renderLoading = renderTNodeJSX("loading", { defaultNode: defaultLoadingContent }); return createVNode("div", { "ref": tableRef, "class": dynamicBaseTableClasses.value, "style": "position: relative" }, [createVNode("div", { "ref": tableContentRef, "class": tableBaseClass.content, "style": tableContentStyles.value, "onScroll": onInnerVirtualScroll }, [createVNode("table", { "ref": tableElmRef, "class": tableElmClasses.value, "style": tableElementStyles.value }, [createVNode("colgroup", null, [(_props$columns3 = props.columns) === null || _props$columns3 === void 0 ? void 0 : _props$columns3.map(function (col_item) { return createVNode("col", { "key": col_item.colKey, "style": colStyle(col_item) }, null); })]), props.showHeader && createVNode("thead", { "ref": theadRef, "class": theadClasses.value }, [createVNode("tr", null, [(_props$columns4 = props.columns) === null || _props$columns4 === void 0 ? void 0 : _props$columns4.map(function (item_th, index_th) { return createVNode("th", { "key": index_th, "class": thClassName(item_th) }, [createVNode("div", { "class": (item_th.ellipsisTitle || item_th.ellipsis) && ellipsisClasses.value }, [renderTitle(item_th, index_th)])]); })])]), createVNode("tbody", { "class": tbodyClasses.value }, [renderTableBody()])]), renderLoading && createVNode("div", { "class": loadingClasses.value }, [renderLoading])])]); }; } }); export { BaseTable as default }; //# sourceMappingURL=base-table.mjs.map