tdesign-mobile-vue
Version:
tdesign-mobile-vue
275 lines (271 loc) • 11.9 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, h, computed, createVNode } from 'vue';
import get from 'lodash/get';
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';
import baseTableProps from './base-table-props.js';
import config from '../config.js';
import useClassName from './hooks/useClassName.js';
import useStyle, { formatCSSUnit } from './hooks/useStyle.js';
import { Loading } from '../loading/index.js';
import { useConfig } from '../config-provider/useConfig.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import '../hooks/useClass.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../loading/icon/spinner.js';
import '../loading/props.js';
import '../shared/dom.js';
import '../loading/plugin.js';
import 'lodash/merge';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import '../_common/js/global-config/mobile/default-config.js';
import '../_common/js/global-config/mobile/locale/zh_CN.js';
import '../_chunks/dep-d5364bc4.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-eb734424.js';
import 'dayjs';
import '../shared/component.js';
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(col.cell)) {
return col.cell(h, params);
}
if (context.slots[col.colKey]) {
return context.slots[col.colKey](params);
}
if (isString(col.cell) && (_context$slots = context.slots) !== null && _context$slots !== void 0 && _context$slots[col.cell]) {
return context.slots[col.cell](params);
}
var r = get(row, col.colKey);
if (![void 0, "", null].includes(r)) return r;
if (cellEmptyContent) {
return isFunction(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(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.js.map