chore: 解决 ESLint no-undef 规则校验问题和 basicTable 组件的类型问题,替换popover组件的 visible 属性。 (#3033)
* chore: 关闭eslint的no-undef规则校验 * chore(VFormDesign): 替换表单设计组件的modal是否可见属性 * chore(BasicTable): emit传参类型问题 * chore(Table): 调整函数参数类型 * chore: 调整expandedRowKeys数据类型 * chore(Table): 完善TableRowSelection接口类型 * chore(Table): 完善useRowSelection 文件的类型问题 * chore(useColumns): key赋值的类型问题 * chore(useDataSource): setTableData的类型问题 * chore: 替换rowKeys类型为 (string|number)[] * fix(edit-cell): 修复edit table Popover 传参问题 * fix(Table): handleItem函数进行绑定key dataIndex可能为数组,造成类型错误提示
This commit is contained in:
parent
bf2f6390ad
commit
d3fd22dbbd
|
|
@ -1,4 +1,7 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
extends: ['@vben'],
|
extends: ['@vben'],
|
||||||
|
rules: {
|
||||||
|
'no-undef': 'off',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -76,15 +76,7 @@
|
||||||
import { isFunction } from '/@/utils/is';
|
import { isFunction } from '/@/utils/is';
|
||||||
import { warn } from '/@/utils/log';
|
import { warn } from '/@/utils/log';
|
||||||
|
|
||||||
export default defineComponent({
|
const events = [
|
||||||
name: 'BasicTable',
|
|
||||||
components: {
|
|
||||||
Table,
|
|
||||||
BasicForm,
|
|
||||||
HeaderCell,
|
|
||||||
},
|
|
||||||
props: basicProps,
|
|
||||||
emits: [
|
|
||||||
'fetch-success',
|
'fetch-success',
|
||||||
'fetch-error',
|
'fetch-error',
|
||||||
'selection-change',
|
'selection-change',
|
||||||
|
|
@ -101,7 +93,17 @@
|
||||||
'expanded-rows-change',
|
'expanded-rows-change',
|
||||||
'change',
|
'change',
|
||||||
'columns-change',
|
'columns-change',
|
||||||
],
|
];
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'BasicTable',
|
||||||
|
components: {
|
||||||
|
Table,
|
||||||
|
BasicForm,
|
||||||
|
HeaderCell,
|
||||||
|
},
|
||||||
|
props: basicProps,
|
||||||
|
emits: events,
|
||||||
setup(props, { attrs, emit, slots, expose }) {
|
setup(props, { attrs, emit, slots, expose }) {
|
||||||
const tableElRef = ref(null);
|
const tableElRef = ref(null);
|
||||||
const tableData = ref([]);
|
const tableData = ref([]);
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ export const CellComponent: FunctionalComponent = (
|
||||||
Popover,
|
Popover,
|
||||||
{
|
{
|
||||||
overlayClassName: 'edit-cell-rule-popover',
|
overlayClassName: 'edit-cell-rule-popover',
|
||||||
visible: !!popoverVisible,
|
open: !!popoverVisible,
|
||||||
...(getPopupContainer ? { getPopupContainer } : {}),
|
...(getPopupContainer ? { getPopupContainer } : {}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ function handleItem(item: BasicColumn, ellipsis: boolean) {
|
||||||
item.align = item.align || DEFAULT_ALIGN;
|
item.align = item.align || DEFAULT_ALIGN;
|
||||||
if (ellipsis) {
|
if (ellipsis) {
|
||||||
if (!key) {
|
if (!key) {
|
||||||
item.key = dataIndex;
|
item.key = typeof dataIndex == 'object' ? dataIndex.join('-') : dataIndex;
|
||||||
}
|
}
|
||||||
if (!isBoolean(item.ellipsis)) {
|
if (!isBoolean(item.ellipsis)) {
|
||||||
Object.assign(item, {
|
Object.assign(item, {
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ export function useDataSource(
|
||||||
|
|
||||||
function insertTableDataRecord(
|
function insertTableDataRecord(
|
||||||
record: Recordable | Recordable[],
|
record: Recordable | Recordable[],
|
||||||
index: number,
|
index?: number,
|
||||||
): Recordable[] | undefined {
|
): Recordable[] | undefined {
|
||||||
// if (!dataSourceRef.value || dataSourceRef.value.length == 0) return;
|
// if (!dataSourceRef.value || dataSourceRef.value.length == 0) return;
|
||||||
index = index ?? dataSourceRef.value?.length;
|
index = index ?? dataSourceRef.value?.length;
|
||||||
|
|
@ -349,7 +349,7 @@ export function useDataSource(
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTableData<T = Recordable>(values: T[]) {
|
function setTableData<T = Recordable>(values: T[]) {
|
||||||
dataSourceRef.value = values;
|
dataSourceRef.value = values as Recordable[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDataSource<T = Recordable>() {
|
function getDataSource<T = Recordable>() {
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@ import { computed, ComputedRef, nextTick, Ref, ref, toRaw, unref, watch } from '
|
||||||
import { ROW_KEY } from '../const';
|
import { ROW_KEY } from '../const';
|
||||||
import { omit } from 'lodash-es';
|
import { omit } from 'lodash-es';
|
||||||
import { findNodeAll } from '/@/utils/helper/treeHelper';
|
import { findNodeAll } from '/@/utils/helper/treeHelper';
|
||||||
|
import type { Key } from 'ant-design-vue/lib/table/interface';
|
||||||
|
|
||||||
export function useRowSelection(
|
export function useRowSelection(
|
||||||
propsRef: ComputedRef<BasicTableProps>,
|
propsRef: ComputedRef<BasicTableProps>,
|
||||||
tableData: Ref<Recordable[]>,
|
tableData: Ref<Recordable[]>,
|
||||||
emit: EmitType,
|
emit: EmitType,
|
||||||
) {
|
) {
|
||||||
const selectedRowKeysRef = ref<string[]>([]);
|
const selectedRowKeysRef = ref<Key[]>([]);
|
||||||
const selectedRowRef = ref<Recordable[]>([]);
|
const selectedRowRef = ref<Recordable[]>([]);
|
||||||
|
|
||||||
const getRowSelectionRef = computed((): TableRowSelection | null => {
|
const getRowSelectionRef = computed((): TableRowSelection | null => {
|
||||||
|
|
@ -21,7 +22,7 @@ export function useRowSelection(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectedRowKeys: unref(selectedRowKeysRef),
|
selectedRowKeys: unref(selectedRowKeysRef),
|
||||||
onChange: (selectedRowKeys: string[]) => {
|
onChange: (selectedRowKeys: Key[]) => {
|
||||||
setSelectedRowKeys(selectedRowKeys);
|
setSelectedRowKeys(selectedRowKeys);
|
||||||
},
|
},
|
||||||
...omit(rowSelection, ['onChange']),
|
...omit(rowSelection, ['onChange']),
|
||||||
|
|
@ -30,7 +31,7 @@ export function useRowSelection(
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => unref(propsRef).rowSelection?.selectedRowKeys,
|
() => unref(propsRef).rowSelection?.selectedRowKeys,
|
||||||
(v: string[]) => {
|
(v?: Key[]) => {
|
||||||
setSelectedRowKeys(v);
|
setSelectedRowKeys(v);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -62,8 +63,8 @@ export function useRowSelection(
|
||||||
return unref(getAutoCreateKey) ? ROW_KEY : rowKey;
|
return unref(getAutoCreateKey) ? ROW_KEY : rowKey;
|
||||||
});
|
});
|
||||||
|
|
||||||
function setSelectedRowKeys(rowKeys: string[]) {
|
function setSelectedRowKeys(rowKeys?: Key[]) {
|
||||||
selectedRowKeysRef.value = rowKeys;
|
selectedRowKeysRef.value = rowKeys || [];
|
||||||
const allSelectedRows = findNodeAll(
|
const allSelectedRows = findNodeAll(
|
||||||
toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))),
|
toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))),
|
||||||
(item) => rowKeys?.includes(item[unref(getRowKey) as string]),
|
(item) => rowKeys?.includes(item[unref(getRowKey) as string]),
|
||||||
|
|
@ -72,7 +73,7 @@ export function useRowSelection(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const trueSelectedRows: any[] = [];
|
const trueSelectedRows: any[] = [];
|
||||||
rowKeys?.forEach((key: string) => {
|
rowKeys?.forEach((key: Key) => {
|
||||||
const found = allSelectedRows.find((item) => item[unref(getRowKey) as string] === key);
|
const found = allSelectedRows.find((item) => item[unref(getRowKey) as string] === key);
|
||||||
found && trueSelectedRows.push(found);
|
found && trueSelectedRows.push(found);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { getDynamicProps } from '/@/utils';
|
||||||
import { ref, onUnmounted, unref, watch, toRaw } from 'vue';
|
import { ref, onUnmounted, unref, watch, toRaw } from 'vue';
|
||||||
import { isProdMode } from '/@/utils/env';
|
import { isProdMode } from '/@/utils/env';
|
||||||
import { error } from '/@/utils/log';
|
import { error } from '/@/utils/log';
|
||||||
|
import type { Key } from 'ant-design-vue/lib/table/interface';
|
||||||
|
|
||||||
type Props = Partial<DynamicProps<BasicTableProps>>;
|
type Props = Partial<DynamicProps<BasicTableProps>>;
|
||||||
|
|
||||||
|
|
@ -92,7 +93,7 @@ export function useTable(tableProps?: Props): [
|
||||||
const columns = getTableInstance().getColumns({ ignoreIndex }) || [];
|
const columns = getTableInstance().getColumns({ ignoreIndex }) || [];
|
||||||
return toRaw(columns);
|
return toRaw(columns);
|
||||||
},
|
},
|
||||||
setColumns: (columns: BasicColumn[]) => {
|
setColumns: (columns: BasicColumn[] | string[]) => {
|
||||||
getTableInstance().setColumns(columns);
|
getTableInstance().setColumns(columns);
|
||||||
},
|
},
|
||||||
setTableData: (values: any[]) => {
|
setTableData: (values: any[]) => {
|
||||||
|
|
@ -113,7 +114,7 @@ export function useTable(tableProps?: Props): [
|
||||||
clearSelectedRowKeys: () => {
|
clearSelectedRowKeys: () => {
|
||||||
getTableInstance().clearSelectedRowKeys();
|
getTableInstance().clearSelectedRowKeys();
|
||||||
},
|
},
|
||||||
setSelectedRowKeys: (keys: string[] | number[]) => {
|
setSelectedRowKeys: (keys: (string | number)[]) => {
|
||||||
getTableInstance().setSelectedRowKeys(keys);
|
getTableInstance().setSelectedRowKeys(keys);
|
||||||
},
|
},
|
||||||
getPaginationRef: () => {
|
getPaginationRef: () => {
|
||||||
|
|
@ -155,7 +156,7 @@ export function useTable(tableProps?: Props): [
|
||||||
expandAll: () => {
|
expandAll: () => {
|
||||||
getTableInstance().expandAll();
|
getTableInstance().expandAll();
|
||||||
},
|
},
|
||||||
expandRows: (keys: string[]) => {
|
expandRows: (keys: Key[]) => {
|
||||||
getTableInstance().expandRows(keys);
|
getTableInstance().expandRows(keys);
|
||||||
},
|
},
|
||||||
collapseAll: () => {
|
collapseAll: () => {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ export function useTableExpand(
|
||||||
tableData: Ref<Recordable[]>,
|
tableData: Ref<Recordable[]>,
|
||||||
emit: EmitType,
|
emit: EmitType,
|
||||||
) {
|
) {
|
||||||
const expandedRowKeys = ref<string[]>([]);
|
const expandedRowKeys = ref<(string | number)[]>([]);
|
||||||
|
|
||||||
const getAutoCreateKey = computed(() => {
|
const getAutoCreateKey = computed(() => {
|
||||||
return unref(propsRef).autoCreateKey && !unref(propsRef).rowKey;
|
return unref(propsRef).autoCreateKey && !unref(propsRef).rowKey;
|
||||||
|
|
@ -37,7 +37,7 @@ export function useTableExpand(
|
||||||
expandedRowKeys.value = keys;
|
expandedRowKeys.value = keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
function expandRows(keys: string[]) {
|
function expandRows(keys: (string | number)[]) {
|
||||||
// use row ID expands the specified table row
|
// use row ID expands the specified table row
|
||||||
const { isTreeTable } = unref(propsRef);
|
const { isTreeTable } = unref(propsRef);
|
||||||
if (!isTreeTable) return;
|
if (!isTreeTable) return;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
import type { VNodeChild } from 'vue';
|
import type { VNodeChild } from 'vue';
|
||||||
import type { PaginationProps } from './pagination';
|
import type { PaginationProps } from './pagination';
|
||||||
import type { FormProps } from '/@/components/Form';
|
import type { FormProps } from '/@/components/Form';
|
||||||
import type { TableRowSelection as ITableRowSelection } from 'ant-design-vue/lib/table/interface';
|
import type {
|
||||||
|
TableRowSelection as ITableRowSelection,
|
||||||
|
Key,
|
||||||
|
} from 'ant-design-vue/lib/table/interface';
|
||||||
import type { ColumnProps } from 'ant-design-vue/lib/table';
|
import type { ColumnProps } from 'ant-design-vue/lib/table';
|
||||||
|
|
||||||
import { ComponentType } from './componentType';
|
import { ComponentType } from './componentType';
|
||||||
|
|
@ -19,7 +22,7 @@ export interface TableRowSelection<T = any> extends ITableRowSelection {
|
||||||
* Callback executed when selected rows change
|
* Callback executed when selected rows change
|
||||||
* @type Function
|
* @type Function
|
||||||
*/
|
*/
|
||||||
onChange?: (selectedRowKeys: string[] | number[], selectedRows: T[]) => any;
|
onChange?: (selectedRowKeys: Key[], selectedRows: T[]) => any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback executed when select/deselect one row
|
* Callback executed when select/deselect one row
|
||||||
|
|
@ -37,7 +40,7 @@ export interface TableRowSelection<T = any> extends ITableRowSelection {
|
||||||
* Callback executed when row selection is inverted
|
* Callback executed when row selection is inverted
|
||||||
* @type Function
|
* @type Function
|
||||||
*/
|
*/
|
||||||
onSelectInvert?: (selectedRows: string[] | number[]) => any;
|
onSelectInvert?: (selectedRows: Key[]) => any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableCustomRecord<T> {
|
export interface TableCustomRecord<T> {
|
||||||
|
|
@ -88,7 +91,7 @@ export interface TableActionType {
|
||||||
getSelectRows: <T = Recordable>() => T[];
|
getSelectRows: <T = Recordable>() => T[];
|
||||||
clearSelectedRowKeys: () => void;
|
clearSelectedRowKeys: () => void;
|
||||||
expandAll: () => void;
|
expandAll: () => void;
|
||||||
expandRows: (keys: string[] | number[]) => void;
|
expandRows: (keys: (string | number)[]) => void;
|
||||||
collapseAll: () => void;
|
collapseAll: () => void;
|
||||||
scrollTo: (pos: string) => void; // pos: id | "top" | "bottom"
|
scrollTo: (pos: string) => void; // pos: id | "top" | "bottom"
|
||||||
getSelectRowKeys: () => string[];
|
getSelectRowKeys: () => string[];
|
||||||
|
|
@ -106,7 +109,7 @@ export interface TableActionType {
|
||||||
setLoading: (loading: boolean) => void;
|
setLoading: (loading: boolean) => void;
|
||||||
setProps: (props: Partial<BasicTableProps>) => void;
|
setProps: (props: Partial<BasicTableProps>) => void;
|
||||||
redoHeight: () => void;
|
redoHeight: () => void;
|
||||||
setSelectedRowKeys: (rowKeys: string[] | number[]) => void;
|
setSelectedRowKeys: (rowKeys: Key[]) => void;
|
||||||
getPaginationRef: () => PaginationProps | boolean;
|
getPaginationRef: () => PaginationProps | boolean;
|
||||||
getSize: () => SizeType;
|
getSize: () => SizeType;
|
||||||
getRowSelection: () => TableRowSelection<Recordable>;
|
getRowSelection: () => TableRowSelection<Recordable>;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<Modal
|
<Modal
|
||||||
title="代码"
|
title="代码"
|
||||||
:footer="null"
|
:footer="null"
|
||||||
:visible="visible"
|
:open="visible"
|
||||||
@cancel="visible = false"
|
@cancel="visible = false"
|
||||||
wrapClassName="v-code-modal"
|
wrapClassName="v-code-modal"
|
||||||
style="top: 20px"
|
style="top: 20px"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<template>
|
<template>
|
||||||
<Modal
|
<Modal
|
||||||
title="JSON数据"
|
title="JSON数据"
|
||||||
:visible="visible"
|
:open="visible"
|
||||||
@ok="handleImportJson"
|
@ok="handleImportJson"
|
||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
cancelText="关闭"
|
cancelText="关闭"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<Modal
|
<Modal
|
||||||
title="JSON数据"
|
title="JSON数据"
|
||||||
:footer="null"
|
:footer="null"
|
||||||
:visible="visible"
|
:open="visible"
|
||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
:destroyOnClose="true"
|
:destroyOnClose="true"
|
||||||
wrapClassName="v-code-modal"
|
wrapClassName="v-code-modal"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<template>
|
<template>
|
||||||
<Modal
|
<Modal
|
||||||
title="预览(支持布局)"
|
title="预览(支持布局)"
|
||||||
:visible="visible"
|
:open="visible"
|
||||||
@ok="handleGetData"
|
@ok="handleGetData"
|
||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
okText="获取数据"
|
okText="获取数据"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<template>
|
<template>
|
||||||
<Modal
|
<Modal
|
||||||
title="预览(不支持布局)"
|
title="预览(不支持布局)"
|
||||||
:visible="state.visible"
|
:open="state.visible"
|
||||||
@ok="handleGetData"
|
@ok="handleGetData"
|
||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
okText="获取数据"
|
okText="获取数据"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue