|
@@ -21,119 +21,98 @@
|
|
title="RefTable示例"
|
|
title="RefTable示例"
|
|
titleHelpMessage="使用Ref调用表格内方法"
|
|
titleHelpMessage="使用Ref调用表格内方法"
|
|
ref="tableRef"
|
|
ref="tableRef"
|
|
- :api="api"
|
|
|
|
|
|
+ :api="demoListApi"
|
|
:columns="columns"
|
|
:columns="columns"
|
|
rowKey="id"
|
|
rowKey="id"
|
|
:rowSelection="{ type: 'checkbox' }"
|
|
:rowSelection="{ type: 'checkbox' }"
|
|
/>
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
-<script lang="ts">
|
|
|
|
- import { defineComponent, ref, unref } from 'vue';
|
|
|
|
- import { BasicTable, TableActionType } from '/@/components/Table';
|
|
|
|
|
|
+<script lang="ts" setup>
|
|
|
|
+ import { ref, unref } from 'vue';
|
|
|
|
+ import { BasicTable, TableActionType } from '@/components/Table';
|
|
import { getBasicColumns, getBasicShortColumns } from './tableData';
|
|
import { getBasicColumns, getBasicShortColumns } from './tableData';
|
|
- import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
|
- import { demoListApi } from '/@/api/demo/table';
|
|
|
|
|
|
+ import { useMessage } from '@/hooks/web/useMessage';
|
|
|
|
+ import { demoListApi } from '@/api/demo/table';
|
|
import { type Nullable } from '@vben/types';
|
|
import { type Nullable } from '@vben/types';
|
|
|
|
|
|
- export default defineComponent({
|
|
|
|
- components: { BasicTable },
|
|
|
|
- setup() {
|
|
|
|
- const tableRef = ref<Nullable<TableActionType>>(null);
|
|
|
|
- const { createMessage } = useMessage();
|
|
|
|
|
|
+ const tableRef = ref<Nullable<TableActionType>>(null);
|
|
|
|
+ const { createMessage } = useMessage();
|
|
|
|
|
|
- function getTableAction() {
|
|
|
|
- const tableAction = unref(tableRef);
|
|
|
|
- if (!tableAction) {
|
|
|
|
- throw new Error('tableAction is null');
|
|
|
|
- }
|
|
|
|
- return tableAction;
|
|
|
|
- }
|
|
|
|
- function changeLoading() {
|
|
|
|
- getTableAction().setLoading(true);
|
|
|
|
- setTimeout(() => {
|
|
|
|
- getTableAction().setLoading(false);
|
|
|
|
- }, 1000);
|
|
|
|
- }
|
|
|
|
- function changeColumns() {
|
|
|
|
- getTableAction().setProps({
|
|
|
|
- columns: getBasicShortColumns(),
|
|
|
|
- rowSelection: {
|
|
|
|
- type: 'checkbox',
|
|
|
|
- },
|
|
|
|
- showIndexColumn: true,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- function reloadTable() {
|
|
|
|
- getTableAction().setProps({
|
|
|
|
- columns: getBasicColumns(),
|
|
|
|
- rowSelection: {
|
|
|
|
- type: 'checkbox',
|
|
|
|
- },
|
|
|
|
- showIndexColumn: true,
|
|
|
|
- });
|
|
|
|
|
|
+ const columns = getBasicColumns();
|
|
|
|
|
|
- getTableAction().reload({
|
|
|
|
- page: 1,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- function getColumn() {
|
|
|
|
- createMessage.info('请在控制台查看!');
|
|
|
|
- console.log(getTableAction().getColumns());
|
|
|
|
- }
|
|
|
|
|
|
+ function getTableAction() {
|
|
|
|
+ const tableAction = unref(tableRef);
|
|
|
|
+ if (!tableAction) {
|
|
|
|
+ throw new Error('tableAction is null');
|
|
|
|
+ }
|
|
|
|
+ return tableAction;
|
|
|
|
+ }
|
|
|
|
+ function changeLoading() {
|
|
|
|
+ getTableAction().setLoading(true);
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ getTableAction().setLoading(false);
|
|
|
|
+ }, 1000);
|
|
|
|
+ }
|
|
|
|
+ function changeColumns() {
|
|
|
|
+ getTableAction().setProps({
|
|
|
|
+ columns: getBasicShortColumns(),
|
|
|
|
+ rowSelection: {
|
|
|
|
+ type: 'checkbox',
|
|
|
|
+ },
|
|
|
|
+ showIndexColumn: true,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ function reloadTable() {
|
|
|
|
+ getTableAction().setProps({
|
|
|
|
+ columns: getBasicColumns(),
|
|
|
|
+ rowSelection: {
|
|
|
|
+ type: 'checkbox',
|
|
|
|
+ },
|
|
|
|
+ showIndexColumn: true,
|
|
|
|
+ });
|
|
|
|
|
|
- function getTableData() {
|
|
|
|
- createMessage.info('请在控制台查看!');
|
|
|
|
- console.log(getTableAction().getDataSource());
|
|
|
|
- }
|
|
|
|
- function getTableRawData() {
|
|
|
|
- createMessage.info('请在控制台查看!');
|
|
|
|
- console.log(getTableAction().getRawDataSource());
|
|
|
|
- }
|
|
|
|
|
|
+ getTableAction().reload({
|
|
|
|
+ page: 1,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ function getColumn() {
|
|
|
|
+ createMessage.info('请在控制台查看!');
|
|
|
|
+ console.log(getTableAction().getColumns());
|
|
|
|
+ }
|
|
|
|
|
|
- function getPagination() {
|
|
|
|
- createMessage.info('请在控制台查看!');
|
|
|
|
- console.log(getTableAction().getPaginationRef());
|
|
|
|
- }
|
|
|
|
|
|
+ function getTableData() {
|
|
|
|
+ createMessage.info('请在控制台查看!');
|
|
|
|
+ console.log(getTableAction().getDataSource());
|
|
|
|
+ }
|
|
|
|
+ function getTableRawData() {
|
|
|
|
+ createMessage.info('请在控制台查看!');
|
|
|
|
+ console.log(getTableAction().getRawDataSource());
|
|
|
|
+ }
|
|
|
|
|
|
- function setPaginationInfo() {
|
|
|
|
- getTableAction().setPagination({
|
|
|
|
- current: 2,
|
|
|
|
- });
|
|
|
|
- getTableAction().reload();
|
|
|
|
- }
|
|
|
|
- function getSelectRowList() {
|
|
|
|
- createMessage.info('请在控制台查看!');
|
|
|
|
- console.log(getTableAction().getSelectRows());
|
|
|
|
- }
|
|
|
|
- function getSelectRowKeyList() {
|
|
|
|
- createMessage.info('请在控制台查看!');
|
|
|
|
- console.log(getTableAction().getSelectRowKeys());
|
|
|
|
- }
|
|
|
|
- function setSelectedRowKeyList() {
|
|
|
|
- getTableAction().setSelectedRowKeys(['0', '1', '2']);
|
|
|
|
- }
|
|
|
|
- function clearSelect() {
|
|
|
|
- getTableAction().clearSelectedRowKeys();
|
|
|
|
- }
|
|
|
|
|
|
+ function getPagination() {
|
|
|
|
+ createMessage.info('请在控制台查看!');
|
|
|
|
+ console.log(getTableAction().getPaginationRef());
|
|
|
|
+ }
|
|
|
|
|
|
- return {
|
|
|
|
- tableRef,
|
|
|
|
- api: demoListApi,
|
|
|
|
- columns: getBasicColumns(),
|
|
|
|
- changeLoading,
|
|
|
|
- changeColumns,
|
|
|
|
- reloadTable,
|
|
|
|
- getColumn,
|
|
|
|
- getTableData,
|
|
|
|
- getTableRawData,
|
|
|
|
- getPagination,
|
|
|
|
- setPaginationInfo,
|
|
|
|
- getSelectRowList,
|
|
|
|
- getSelectRowKeyList,
|
|
|
|
- setSelectedRowKeyList,
|
|
|
|
- clearSelect,
|
|
|
|
- };
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
|
|
+ function setPaginationInfo() {
|
|
|
|
+ getTableAction().setPagination({
|
|
|
|
+ current: 2,
|
|
|
|
+ });
|
|
|
|
+ getTableAction().reload();
|
|
|
|
+ }
|
|
|
|
+ function getSelectRowList() {
|
|
|
|
+ createMessage.info('请在控制台查看!');
|
|
|
|
+ console.log(getTableAction().getSelectRows());
|
|
|
|
+ }
|
|
|
|
+ function getSelectRowKeyList() {
|
|
|
|
+ createMessage.info('请在控制台查看!');
|
|
|
|
+ console.log(getTableAction().getSelectRowKeys());
|
|
|
|
+ }
|
|
|
|
+ function setSelectedRowKeyList() {
|
|
|
|
+ getTableAction().setSelectedRowKeys(['0', '1', '2']);
|
|
|
|
+ }
|
|
|
|
+ function clearSelect() {
|
|
|
|
+ getTableAction().clearSelectedRowKeys();
|
|
|
|
+ }
|
|
</script>
|
|
</script>
|