UNPKG

tav-ui

Version:
148 lines (143 loc) 4.49 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var basic = require('../../../../utils/basic2.js'); var log = require('../../../../utils/log2.js'); const isProdMode = () => true; function useTable(tableProps) { const tableRef = vue.ref(null); const loadedRef = vue.ref(false); const formRef = vue.ref(null); let stopWatch; function register(instance, formInstance) { isProdMode() && vue.onUnmounted(() => { tableRef.value = null; loadedRef.value = null; }); if (vue.unref(loadedRef) && isProdMode() && instance === vue.unref(tableRef)) return; tableRef.value = instance; formRef.value = formInstance; tableProps && instance.setProps(basic.getDynamicProps(tableProps)); loadedRef.value = true; stopWatch?.(); stopWatch = vue.watch(() => tableProps, () => { tableProps && instance.setProps(basic.getDynamicProps(tableProps)); }, { immediate: true, deep: true }); } function getTableInstance() { const table = vue.unref(tableRef); if (!table) { log.error("The table instance has not been obtained yet, please make sure the table is presented when performing the table operation!"); } return table; } const methods = { reload: async (opt) => { return await getTableInstance().reload(opt); }, setProps: (props) => { getTableInstance().setProps(props); }, redoHeight: () => { getTableInstance().redoHeight(); }, setLoading: (loading) => { getTableInstance().setLoading(loading); }, setMasking: (loading) => { getTableInstance().setMasking(loading); }, getDataSource: () => { return getTableInstance().getDataSource(); }, getRawDataSource: () => { return getTableInstance().getRawDataSource(); }, getColumns: ({ ignoreIndex = false } = {}) => { const columns = getTableInstance().getColumns({ ignoreIndex }) || []; return vue.toRaw(columns); }, setColumns: (columns) => { getTableInstance().setColumns(columns); }, setTableData: (values) => { return getTableInstance().setTableData(values); }, setPagination: (info) => { return getTableInstance().setPagination(info); }, deleteSelectRowByKey: (key) => { getTableInstance().deleteSelectRowByKey(key); }, getSelectRowKeys: () => { return vue.toRaw(getTableInstance().getSelectRowKeys()); }, getSelectRows: () => { return vue.toRaw(getTableInstance().getSelectRows()); }, clearSelectedRowKeys: () => { getTableInstance().clearSelectedRowKeys(); }, setSelectedRowKeys: (keys) => { getTableInstance().setSelectedRowKeys(keys); }, getPaginationRef: () => { return getTableInstance().getPaginationRef(); }, getSize: () => { return vue.toRaw(getTableInstance().getSize()); }, updateTableData: (index, key, value) => { return getTableInstance().updateTableData(index, key, value); }, deleteTableDataRecord: (rowKey) => { return getTableInstance().deleteTableDataRecord(rowKey); }, insertTableDataRecord: (record, index) => { return getTableInstance().insertTableDataRecord(record, index); }, updateTableDataRecord: (rowKey, record) => { return getTableInstance().updateTableDataRecord(rowKey, record); }, findTableDataRecord: (rowKey) => { return getTableInstance().findTableDataRecord(rowKey); }, getRowSelection: () => { return vue.toRaw(getTableInstance().getRowSelection()); }, getCacheColumns: () => { return vue.toRaw(getTableInstance().getCacheColumns()); }, getForm: () => { return vue.unref(formRef); }, setShowPagination: async (show) => { getTableInstance().setShowPagination(show); }, getShowPagination: () => { return vue.toRaw(getTableInstance().getShowPagination()); }, expandAll: () => { getTableInstance().expandAll(); }, expandRows: (keys, cover) => { getTableInstance().expandRows(keys, cover); }, collapseAll: () => { getTableInstance().collapseAll(); }, scrollTo: (pos) => { getTableInstance().scrollTo(pos); }, getFilterForm: () => { return getTableInstance().getFilterForm(); } }; return [register, methods]; } exports.useTable = useTable; //# sourceMappingURL=useTable2.js.map