UNPKG

@fe6/water-pro

Version:

An enterprise-class UI design language and Vue-based implementation

387 lines (329 loc) 16.6 kB
var _components; import { withDirectives as _withDirectives, vShow as _vShow, createVNode as _createVNode, resolveDirective as _resolveDirective } from "vue"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } import _regeneratorRuntime from "@babel/runtime/regenerator"; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import { __awaiter } from "tslib"; import { defineComponent, ref, computed, unref, onMounted, nextTick } from 'vue'; import { omit, isFunction } from 'lodash-es'; import { isNull, isUndefined } from '@fe6/shared'; import Table from '../../table'; import { FormPro, useForm } from '../../form-pro'; import useConfigInject from '../../_util/hooks/useConfigInject'; import { useSortable } from '../../_util/hooks/use-sortable'; import { usePagination } from './hooks/use-pagination'; import { useColumns } from './hooks/use-columns'; import { useDataSource } from './hooks/use-data-source'; import { useLoading } from './hooks/use-loading'; import { useRowSelection } from './hooks/use-row-selection'; import { useTableScroll } from './hooks/use-table-scroll'; import { useCustomRow } from './hooks/use-custom-row'; import { useTableStyle } from './hooks/use-table-style'; import { useTableHeader } from './hooks/use-table-header'; import { createTableContext } from './hooks/use-table-context'; import { useTableFooter } from './hooks/use-table-footer'; import { useTableForm } from './hooks/use-table-form'; import { useExpose } from './hooks/use-expose'; import { basicProps } from './props'; import expandIcon from './components/expand-icon'; import HeaderCell from './components/header-cell'; import Card from '../../card'; export default defineComponent({ name: 'ATablePro', components: (_components = { Table: Table }, _defineProperty(_components, FormPro.name, FormPro), _defineProperty(_components, "HeaderCell", HeaderCell), _components), props: basicProps, emits: ['fetch-success', 'fetch-error', 'fetch-finally', 'selection-change', 'register', 'row-click', 'row-dbClick', 'row-contextmenu', 'row-mouseenter', 'row-mouseleave', 'edit-end', 'edit-cancel', 'edit-row-end', 'edit-change', 'drag-end'], setup: function setup(props, _ref) { var _this = this; var attrs = _ref.attrs, emit = _ref.emit, slots = _ref.slots; var _useConfigInject = useConfigInject('table-pro', props), prefixClsNew = _useConfigInject.prefixCls; var tableElRef = ref(null); var tableData = ref([]); var wrapRef = ref(null); var innerPropsRef = ref(); var _useForm = useForm(), _useForm2 = _slicedToArray(_useForm, 2), registerForm = _useForm2[0], formActions = _useForm2[1]; var getProps = computed(function () { return _extends(_extends({}, props), unref(innerPropsRef)); }); var _useLoading = useLoading(getProps), getLoading = _useLoading.getLoading, setLoading = _useLoading.setLoading; var _usePagination = usePagination(getProps), getPaginationInfo = _usePagination.getPaginationInfo, getPagination = _usePagination.getPagination, setPagination = _usePagination.setPagination, setShowPagination = _usePagination.setShowPagination, getShowPagination = _usePagination.getShowPagination; var _useRowSelection = useRowSelection(getProps, tableData, emit), getRowSelection = _useRowSelection.getRowSelection, getRowSelectionRef = _useRowSelection.getRowSelectionRef, getSelectRows = _useRowSelection.getSelectRows, clearSelectedRowKeys = _useRowSelection.clearSelectedRowKeys, getSelectRowKeys = _useRowSelection.getSelectRowKeys, deleteSelectRowByKey = _useRowSelection.deleteSelectRowByKey, setSelectedRowKeys = _useRowSelection.setSelectedRowKeys; var _useDataSource = useDataSource(getProps, { tableData: tableData, getPaginationInfo: getPaginationInfo, setLoading: setLoading, setPagination: setPagination, getFieldsValue: formActions.getFieldsValue, clearSelectedRowKeys: clearSelectedRowKeys }, emit), handleTableChange = _useDataSource.handleTableChange, getDataSourceRef = _useDataSource.getDataSourceRef, getDataSource = _useDataSource.getDataSource, setTableData = _useDataSource.setTableData, fetch = _useDataSource.fetch, getRowKey = _useDataSource.getRowKey, reload = _useDataSource.reload, getAutoCreateKey = _useDataSource.getAutoCreateKey, updateTableData = _useDataSource.updateTableData; var _useColumns = useColumns(getProps, getPaginationInfo), getViewColumns = _useColumns.getViewColumns, getColumns = _useColumns.getColumns, setCacheColumnsByField = _useColumns.setCacheColumnsByField, setColumns = _useColumns.setColumns, getColumnsRef = _useColumns.getColumnsRef, getCacheColumns = _useColumns.getCacheColumns; var _useTableScroll = useTableScroll(getProps, tableElRef, getColumnsRef, getRowSelectionRef, getDataSourceRef), getScrollRef = _useTableScroll.getScrollRef, redoHeight = _useTableScroll.redoHeight; var _useCustomRow = useCustomRow(getProps, { setSelectedRowKeys: setSelectedRowKeys, getSelectRowKeys: getSelectRowKeys, clearSelectedRowKeys: clearSelectedRowKeys, getAutoCreateKey: getAutoCreateKey, emit: emit }), customRow = _useCustomRow.customRow; var _useTableStyle = useTableStyle(getProps, prefixClsNew.value), getRowClassName = _useTableStyle.getRowClassName; var _useTableHeader = useTableHeader(getProps, slots), getHeaderProps = _useTableHeader.getHeaderProps; var _useTableFooter = useTableFooter(getProps, getScrollRef, tableElRef, getDataSourceRef), getFooterProps = _useTableFooter.getFooterProps; var _useTableForm = useTableForm(getProps, slots, fetch), getFormProps = _useTableForm.getFormProps, replaceFormSlotKey = _useTableForm.replaceFormSlotKey, getFormSlotKeys = _useTableForm.getFormSlotKeys, handleSearchInfoChange = _useTableForm.handleSearchInfoChange; var getBindValues = computed(function () { var propsData = _extends(_extends(_extends(_extends(_extends({ size: 'middle' }, attrs), { customRow: customRow, expandIcon: expandIcon() }), unref(getProps)), unref(getHeaderProps)), { scroll: unref(getScrollRef), loading: unref(getLoading), tableLayout: 'fixed', rowSelection: unref(getRowSelectionRef), rowKey: unref(getRowKey), columns: unref(getViewColumns), pagination: unref(getPaginationInfo), dataSource: unref(getDataSourceRef), footer: unref(getFooterProps) }); if (slots.expandedRowRender) { propsData = omit(propsData, 'scroll'); } propsData = omit(propsData, 'class'); return propsData; }); var getEmptyDataIsShowTable = computed(function () { var _unref = unref(getProps), emptyDataIsShowTable = _unref.emptyDataIsShowTable, useSearchForm = _unref.useSearchForm; if (emptyDataIsShowTable || !useSearchForm) { return true; } return !!unref(getDataSourceRef).length; }); var initDragTable = function initDragTable() { return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var columnListEl, _useSortable, initSortable; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return nextTick(); case 2: columnListEl = unref(tableElRef).$el; if (columnListEl) { _context.next = 5; break; } return _context.abrupt("return"); case 5: _useSortable = useSortable(columnListEl.querySelector('.ant-table-tbody'), _extends({ onEnd: function onEnd(evt) { var oldIndex = evt.oldIndex, newIndex = evt.newIndex; if (isUndefined(oldIndex) && isNull(oldIndex) || isUndefined(newIndex) && isNull(newIndex) || oldIndex === newIndex) { return; } // Sort column // Sort column var oldIndexNumber = oldIndex; var newIndexNumber = newIndex; emit('drag-end', oldIndexNumber, newIndexNumber, evt); } }, unref(getProps).dragOtions)), initSortable = _useSortable.initSortable; initSortable(); case 7: case "end": return _context.stop(); } } }, _callee); })); }; function setProps(props) { innerPropsRef.value = _extends(_extends({}, unref(innerPropsRef)), props); if (innerPropsRef.value.draggable) { initDragTable(); } } var tableAction = { reload: reload, getSelectRows: getSelectRows, clearSelectedRowKeys: clearSelectedRowKeys, getSelectRowKeys: getSelectRowKeys, deleteSelectRowByKey: deleteSelectRowByKey, setPagination: setPagination, setTableData: setTableData, redoHeight: redoHeight, setSelectedRowKeys: setSelectedRowKeys, setColumns: setColumns, setLoading: setLoading, getLoading: unref(getLoading), getDataSource: getDataSource, setProps: setProps, getRowSelection: getRowSelection, getPaginationRef: getPagination, getColumns: getColumns, getCacheColumns: getCacheColumns, emit: emit, updateTableData: updateTableData, setShowPagination: setShowPagination, getShowPagination: getShowPagination, setCacheColumnsByField: setCacheColumnsByField, getSize: function getSize() { return unref(getBindValues).size; } }; createTableContext(_extends(_extends({}, tableAction), { wrapRef: wrapRef, getBindValues: getBindValues })); useExpose(tableAction); emit('register', tableAction, formActions); onMounted(function () { if (props.draggable) { initDragTable(); } }); return { tableElRef: tableElRef, getBindValues: getBindValues, getLoading: getLoading, registerForm: registerForm, handleSearchInfoChange: handleSearchInfoChange, getEmptyDataIsShowTable: getEmptyDataIsShowTable, handleTableChange: handleTableChange, getRowClassName: getRowClassName, clearSelectedRowKeys: clearSelectedRowKeys, wrapRef: wrapRef, tableAction: tableAction, redoHeight: redoHeight, getFormProps: getFormProps, replaceFormSlotKey: replaceFormSlotKey, getFormSlotKeys: getFormSlotKeys, prefixClsNew: prefixClsNew, columns: getViewColumns }; }, methods: { moreDisplayCancelSelect: function moreDisplayCancelSelect() { this.clearSelectedRowKeys(); } }, render: function render() { var _ref2; var formNode = null; if (this.getBindValues.useSearchForm) { formNode = _createVNode(FormPro, _objectSpread(_objectSpread({ "submit-on-reset": true }, this.getFormProps), {}, { "submit-button-options": { loading: this.getLoading }, "reset-button-options": { loading: this.getLoading }, "table-action": this.tableAction, "label-align": this.formLabelALigin, "label-col": this.formLabelCol, "wrapper-col": this.formWrapperCol, "onRegister": this.registerForm, "onSubmit": this.handleSearchInfoChange, "onAdvancedChange": this.redoHeight }), this.$slots); } var tableSlots = _extends({}, this.$slots); this.columns.forEach(function (column) { tableSlots["header-".concat(column.dataIndex)] = function () { return [_createVNode(HeaderCell, { "column": column }, null)]; }; }); var tableNode = _withDirectives(_createVNode(Table, _objectSpread(_objectSpread({ "ref": "tableElRef" }, this.getBindValues), {}, { "row-class-name": this.getRowClassName, "onChange": this.handleTableChange, "onMoreDisplayCancelSelect": this.moreDisplayCancelSelect }), tableSlots), [[_vShow, this.getEmptyDataIsShowTable]]); if (this.cardable) { var slotsCard = omit(this.$slots, ['cardTitle']); var cardProps = {}; if (this.cardTitle) { cardProps.title = this.cardTitle; } if (isFunction(this.$slots.cardTitle)) { slotsCard.title = this.$slots.cardTitle; delete cardProps.title; } var _tableNode = function () { return tableNode; }(); tableNode = _createVNode(Card, cardProps, _objectSpread({ default: function _default() { return [_tableNode]; } }, slotsCard)); } return _createVNode("div", { "ref": "wrapRef", "class": [this.prefixClsNew, this.$attrs.class, (_ref2 = {}, _defineProperty(_ref2, "".concat(this.prefixClsNew, "-cardable"), this.cardable), _defineProperty(_ref2, "".concat(this.prefixClsNew, "-form-container"), this.getBindValues.useSearchForm), _defineProperty(_ref2, "".concat(this.prefixClsNew, "--inset"), this.getBindValues.inset), _defineProperty(_ref2, "".concat(this.prefixClsNew, "--drag"), this.getBindValues.draggable), _ref2)] }, [formNode, tableNode]); } });