UNPKG

@fe6/water-pro

Version:

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

166 lines (146 loc) 5.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useTable = useTable; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _tslib = require("tslib"); var _vue = require("vue"); var _use = require("../../../_util/use"); var _env = require("../../../_util/env"); var _warning = _interopRequireDefault(require("../../../_util/warning")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** @format */ function useTable(tableProps) { var _this = this; var tableRef = (0, _vue.ref)(null); var loadedRef = (0, _vue.ref)(false); var formRef = (0, _vue.ref)(null); function register(instance, formInstance) { (0, _env.isProdMode)() && (0, _vue.onUnmounted)(function () { tableRef.value = null; loadedRef.value = null; }); if ((0, _vue.unref)(loadedRef) && (0, _env.isProdMode)() && instance === (0, _vue.unref)(tableRef)) { return; } tableRef.value = instance; formRef.value = formInstance; tableProps && instance.setProps((0, _use.getDynamicProps)(tableProps)); loadedRef.value = true; (0, _vue.watch)(function () { return tableProps; }, function () { tableProps && instance.setProps((0, _use.getDynamicProps)(tableProps)); }, { immediate: true, deep: true }); } function getTableInstance() { var table = (0, _vue.unref)(tableRef); if (!table) { (0, _warning.default)('The table instance has not been obtained yet, please make sure the table is presented when performing the table operation!'); } return table; } var methods = { reload: function reload(opt) { return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator.default.mark(function _callee() { return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: getTableInstance().reload(opt); case 1: case "end": return _context.stop(); } } }, _callee); })); }, setProps: function setProps(props) { getTableInstance().setProps(props); }, redoHeight: function redoHeight() { getTableInstance().redoHeight(); }, setLoading: function setLoading(loading) { getTableInstance().setLoading(loading); }, getDataSource: function getDataSource() { return (0, _vue.toRaw)(getTableInstance().getDataSource()); }, getColumns: function getColumns() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$ignoreIndex = _ref.ignoreIndex, ignoreIndex = _ref$ignoreIndex === void 0 ? false : _ref$ignoreIndex; var columns = getTableInstance().getColumns({ ignoreIndex: ignoreIndex }) || []; return (0, _vue.toRaw)(columns); }, setColumns: function setColumns(columns) { getTableInstance().setColumns(columns); }, setTableData: function setTableData(values) { return getTableInstance().setTableData(values); }, setPagination: function setPagination(info) { return getTableInstance().setPagination(info); }, deleteSelectRowByKey: function deleteSelectRowByKey(key) { getTableInstance().deleteSelectRowByKey(key); }, getSelectRowKeys: function getSelectRowKeys() { return (0, _vue.toRaw)(getTableInstance().getSelectRowKeys()); }, getSelectRows: function getSelectRows() { return (0, _vue.toRaw)(getTableInstance().getSelectRows()); }, clearSelectedRowKeys: function clearSelectedRowKeys() { getTableInstance().clearSelectedRowKeys(); }, setSelectedRowKeys: function setSelectedRowKeys(keys) { getTableInstance().setSelectedRowKeys(keys); }, getPaginationRef: function getPaginationRef() { return getTableInstance().getPaginationRef(); }, getSize: function getSize() { return (0, _vue.toRaw)(getTableInstance().getSize()); }, updateTableData: function updateTableData(index, key, value) { return getTableInstance().updateTableData(index, key, value); }, getRowSelection: function getRowSelection() { return (0, _vue.toRaw)(getTableInstance().getRowSelection()); }, getCacheColumns: function getCacheColumns() { return (0, _vue.toRaw)(getTableInstance().getCacheColumns()); }, getForm: function getForm() { return (0, _vue.unref)(formRef); }, setShowPagination: function setShowPagination(show) { return (0, _tslib.__awaiter)(_this, void 0, void 0, /*#__PURE__*/_regenerator.default.mark(function _callee2() { return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: getTableInstance().setShowPagination(show); case 1: case "end": return _context2.stop(); } } }, _callee2); })); }, getShowPagination: function getShowPagination() { return (0, _vue.toRaw)(getTableInstance().getShowPagination()); } }; return [register, methods]; }