fix(table): get the selected rows of the table correctly
| | |
| | | ### 🐛 Bug Fixes |
| | | |
| | | - 修复验证码组件警告问题 |
| | | - 修复表格不能正确的获取选中行 |
| | | |
| | | ## 2.0.1 (2021-02-21) |
| | | |
| | |
| | | "stylelint-config-standard": "^20.0.0", |
| | | "stylelint-order": "^4.1.0", |
| | | "ts-node": "^9.1.1", |
| | | "typescript": "^4.2.2", |
| | | "typescript": "4.1.5", |
| | | "vite": "2.0.2", |
| | | "vite-plugin-compression": "^0.2.2", |
| | | "vite-plugin-html": "^2.0.2", |
| | |
| | | ], |
| | | setup(props, { attrs, emit, slots }) { |
| | | const tableElRef = ref<ComponentRef>(null); |
| | | const tableData = ref<Recordable[]>([]); |
| | | |
| | | const wrapRef = ref<Nullable<HTMLDivElement>>(null); |
| | | const innerPropsRef = ref<Partial<BasicTableProps>>(); |
| | |
| | | getSelectRowKeys, |
| | | deleteSelectRowByKey, |
| | | setSelectedRowKeys, |
| | | } = useRowSelection(getProps, emit); |
| | | } = useRowSelection(getProps, tableData, emit); |
| | | |
| | | const { |
| | | handleTableChange, |
| | |
| | | } = useDataSource( |
| | | getProps, |
| | | { |
| | | tableData, |
| | | getPaginationInfo, |
| | | setLoading, |
| | | setPagination, |
| | |
| | | if (!key) return; |
| | | |
| | | const isCheckbox = rowSelection.type === 'checkbox'; |
| | | |
| | | if (isCheckbox) { |
| | | if (!keys.includes(key)) { |
| | | setSelectedRowKeys([...keys, key]); |
| | |
| | | import type { BasicTableProps, FetchParams, SorterResult } from '../types/table'; |
| | | import type { PaginationProps } from '../types/pagination'; |
| | | |
| | | import { ref, unref, ComputedRef, computed, onMounted, watch, reactive } from 'vue'; |
| | | import { |
| | | ref, |
| | | unref, |
| | | ComputedRef, |
| | | computed, |
| | | onMounted, |
| | | watch, |
| | | reactive, |
| | | Ref, |
| | | watchEffect, |
| | | } from 'vue'; |
| | | |
| | | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; |
| | | |
| | |
| | | setLoading: (loading: boolean) => void; |
| | | getFieldsValue: () => Recordable; |
| | | clearSelectedRowKeys: () => void; |
| | | tableData: Ref<Recordable[]>; |
| | | } |
| | | |
| | | interface SearchState { |
| | |
| | | setLoading, |
| | | getFieldsValue, |
| | | clearSelectedRowKeys, |
| | | tableData, |
| | | }: ActionType, |
| | | emit: EmitType |
| | | ) { |
| | |
| | | // !api && dataSource && (dataSourceRef.value = dataSource); |
| | | // }); |
| | | |
| | | watchEffect(() => { |
| | | tableData.value = unref(dataSourceRef); |
| | | }); |
| | | |
| | | watch( |
| | | () => unref(propsRef).dataSource, |
| | | () => { |
| | |
| | | import type { BasicTableProps, TableRowSelection } from '../types/table'; |
| | | |
| | | import { computed, ref, unref, ComputedRef } from 'vue'; |
| | | import { computed, ref, unref, ComputedRef, Ref, toRaw } from 'vue'; |
| | | import { ROW_KEY } from '../const'; |
| | | |
| | | /* eslint-disable */ |
| | | export function useRowSelection(propsRef: ComputedRef<BasicTableProps>, emit: EmitType) { |
| | | export function useRowSelection( |
| | | propsRef: ComputedRef<BasicTableProps>, |
| | | tableData: Ref<Recordable[]>, |
| | | emit: EmitType |
| | | ) { |
| | | const selectedRowKeysRef = ref<string[]>([]); |
| | | const selectedRowRef = ref<Recordable[]>([]); |
| | | |
| | |
| | | }; |
| | | }); |
| | | |
| | | const getAutoCreateKey = computed(() => { |
| | | return unref(propsRef).autoCreateKey && !unref(propsRef).rowKey; |
| | | }); |
| | | |
| | | const getRowKey = computed(() => { |
| | | const { rowKey } = unref(propsRef); |
| | | return unref(getAutoCreateKey) ? ROW_KEY : rowKey; |
| | | }); |
| | | |
| | | function setSelectedRowKeys(rowKeys: string[]) { |
| | | selectedRowKeysRef.value = rowKeys; |
| | | |
| | | const rows = toRaw(unref(tableData)).filter((item) => |
| | | rowKeys.includes(item[unref(getRowKey) as string]) |
| | | ); |
| | | selectedRowRef.value = rows; |
| | | } |
| | | |
| | | function setSelectedRows(rows: Recordable[]) { |
| | | selectedRowRef.value = rows; |
| | | } |
| | | |
| | | function clearSelectedRowKeys() { |
| | |
| | | setSelectedRowKeys, |
| | | clearSelectedRowKeys, |
| | | deleteSelectRowByKey, |
| | | setSelectedRows, |
| | | }; |
| | | } |
| | |
| | | import type { DynamicProps } from '/@/types/utils'; |
| | | import { getDynamicProps } from '/@/utils'; |
| | | |
| | | import { ref, onUnmounted, unref, watch } from 'vue'; |
| | | import { ref, onUnmounted, unref, watch, toRaw } from 'vue'; |
| | | import { isProdMode } from '/@/utils/env'; |
| | | import { isInSetup } from '/@/utils/helper/vueHelper'; |
| | | import { error } from '/@/utils/log'; |
| | |
| | | getTableInstance().setLoading(loading); |
| | | }, |
| | | getDataSource: () => { |
| | | return getTableInstance().getDataSource(); |
| | | return toRaw(getTableInstance().getDataSource()); |
| | | }, |
| | | getColumns: ({ ignoreIndex = false }: { ignoreIndex?: boolean } = {}) => { |
| | | const columns = getTableInstance().getColumns({ ignoreIndex }) || []; |
| | | return columns; |
| | | return toRaw(columns); |
| | | }, |
| | | setColumns: (columns: BasicColumn[]) => { |
| | | getTableInstance().setColumns(columns); |
| | |
| | | getTableInstance().deleteSelectRowByKey(key); |
| | | }, |
| | | getSelectRowKeys: () => { |
| | | return getTableInstance().getSelectRowKeys(); |
| | | return toRaw(getTableInstance().getSelectRowKeys()); |
| | | }, |
| | | getSelectRows: () => { |
| | | return getTableInstance().getSelectRows(); |
| | | return toRaw(getTableInstance().getSelectRows()); |
| | | }, |
| | | clearSelectedRowKeys: () => { |
| | | getTableInstance().clearSelectedRowKeys(); |
| | |
| | | return getTableInstance().getPaginationRef(); |
| | | }, |
| | | getSize: () => { |
| | | return getTableInstance().getSize(); |
| | | return toRaw(getTableInstance().getSize()); |
| | | }, |
| | | updateTableData: (index: number, key: string, value: any) => { |
| | | return getTableInstance().updateTableData(index, key, value); |
| | | }, |
| | | getRowSelection: () => { |
| | | return getTableInstance().getRowSelection(); |
| | | return toRaw(getTableInstance().getRowSelection()); |
| | | }, |
| | | getCacheColumns: () => { |
| | | return getTableInstance().getCacheColumns(); |
| | | return toRaw(getTableInstance().getCacheColumns()); |
| | | }, |
| | | getForm: () => { |
| | | return (unref(formRef) as unknown) as FormActionType; |
| | |
| | | getTableInstance().setShowPagination(show); |
| | | }, |
| | | getShowPagination: () => { |
| | | return getTableInstance().getShowPagination(); |
| | | return toRaw(getTableInstance().getShowPagination()); |
| | | }, |
| | | }; |
| | | |
| | |
| | | dependencies: |
| | | is-typedarray "^1.0.0" |
| | | |
| | | typescript@^4.2.2: |
| | | version "4.2.2" |
| | | resolved "https://registry.npmjs.org/typescript/-/typescript-4.2.2.tgz#1450f020618f872db0ea17317d16d8da8ddb8c4c" |
| | | integrity sha512-tbb+NVrLfnsJy3M59lsDgrzWIflR4d4TIUjz+heUnHZwdF7YsrMTKoRERiIvI2lvBG95dfpLxB21WZhys1bgaQ== |
| | | typescript@4.1.5: |
| | | version "4.1.5" |
| | | resolved "https://registry.npmjs.org/typescript/-/typescript-4.1.5.tgz#123a3b214aaff3be32926f0d8f1f6e704eb89a72" |
| | | integrity sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA== |
| | | |
| | | uglify-js@^3.1.4: |
| | | version "3.12.5" |