Browse Source

perf(smart-table): 完善表格尺寸配置

shizhongming 2 years ago
parent
commit
88e82bacaa
  1. 26
      src/components/SmartTable/src/SmartTable.tsx
  2. 36
      src/components/SmartTable/src/components/SmartTableSizeSetting.tsx
  3. 1
      src/components/SmartTable/src/hooks/useSmartTableColumnConfig.ts
  4. 7
      src/components/SmartTable/src/hooks/useSmartTableContext.ts
  5. 11
      src/components/SmartTable/src/types/SmartTableType.ts
  6. 2
      src/modules/smart-system/views/parameter/SysParameterListView.vue

26
src/components/SmartTable/src/SmartTable.tsx

@ -1,4 +1,9 @@
import type { SmartTableProps, TableActionType } from './types/SmartTableType'; import type {
SmartTableInnerActionType,
SmartTableInnerRegisterActionType,
SmartTableProps,
TableActionType,
} from './types/SmartTableType';
import type { VxeGridInstance } from 'vxe-table'; import type { VxeGridInstance } from 'vxe-table';
import { computed, defineComponent, provide, Ref, ref, unref } from 'vue'; import { computed, defineComponent, provide, Ref, ref, unref } from 'vue';
@ -60,6 +65,12 @@ export default defineComponent({
innerPropsRef.value = { ...unref(innerPropsRef), ...props }; innerPropsRef.value = { ...unref(innerPropsRef), ...props };
}; };
const tableInnerAction: SmartTableInnerRegisterActionType = {
registerInnerAction: (action: SmartTableInnerActionType) => {
Object.assign(tableInnerAction, action);
},
};
// -------------- 分页 --------------------------- // -------------- 分页 ---------------------------
const { const {
getPaginationInfo, getPaginationInfo,
@ -163,6 +174,11 @@ export default defineComponent({
*/ */
const { setColumnSortConfig, computedColumnSort } = useSmartTableColumnConfig(getTableInstance); const { setColumnSortConfig, computedColumnSort } = useSmartTableColumnConfig(getTableInstance);
// const { computedTableSize } = useSmartTableSizeSetting(
// getTableInstance,
// tableInnerAction,
// props.size,
// );
// ------------- toolbar配置 ---------------------- // ------------- toolbar配置 ----------------------
const { getToolbarConfigInfo } = useTableToolbarConfig(getTableProps, t, { const { getToolbarConfigInfo } = useTableToolbarConfig(getTableProps, t, {
@ -230,6 +246,7 @@ export default defineComponent({
...unref(getTableEvents), ...unref(getTableEvents),
...unref(computedTableClassStyle), ...unref(computedTableClassStyle),
onPageChange: handlePageChange, onPageChange: handlePageChange,
// size: unref(computedTableSize),
}; };
}); });
@ -297,7 +314,12 @@ export default defineComponent({
}); });
}); });
createTableContext({ ...tableAction, wrapRef, getBindValues: getTableBindValues }); createTableContext({
...tableAction,
wrapRef,
getBindValues: getTableBindValues,
tableInnerAction,
});
emit('register', tableAction, searchFormAction, getAddEditForm); emit('register', tableAction, searchFormAction, getAddEditForm);

36
src/components/SmartTable/src/components/SmartTableSizeSetting.tsx

@ -1,7 +1,7 @@
import type { SmartTableToolbarSizeSetting } from '@/components/SmartTable'; import type { SmartTableToolbarSizeSetting } from '@/components/SmartTable';
import type { VxeButtonProps } from 'vxe-table'; import type { SizeType, VxeButtonProps } from 'vxe-table';
import { defineComponent, h } from 'vue'; import { defineComponent, h, onMounted } from 'vue';
import { Menu, Dropdown } from 'ant-design-vue'; import { Menu, Dropdown } from 'ant-design-vue';
import { ColumnHeightOutlined } from '@ant-design/icons-vue'; import { ColumnHeightOutlined } from '@ant-design/icons-vue';
@ -9,6 +9,12 @@ import { t as vxeI18n } from 'vxe-table';
import { useTableContext } from '../hooks/useSmartTableContext'; import { useTableContext } from '../hooks/useSmartTableContext';
const SMART_TABLE_SIZE_SETTING = 'SMART_TABLE_SIZE_SETTING';
const getTableSize = (tableId: string) => {
return JSON.parse(localStorage.getItem(SMART_TABLE_SIZE_SETTING) || '{}')[tableId];
};
export default defineComponent({ export default defineComponent({
name: 'SmartTableSizeSetting', name: 'SmartTableSizeSetting',
props: { props: {
@ -23,7 +29,33 @@ export default defineComponent({
tableContext.setProps({ tableContext.setProps({
size: e.key, size: e.key,
}); });
setTableSize(e.key);
}; };
const setTableSize = (size: SizeType) => {
const tableId = tableContext.getTableInstance()?.id;
if (!tableId) {
return;
}
const allConfig = JSON.parse(localStorage.getItem(SMART_TABLE_SIZE_SETTING) || '{}') || {};
allConfig[tableId] = size;
localStorage.setItem(SMART_TABLE_SIZE_SETTING, JSON.stringify(allConfig));
};
onMounted(() => {
const tableId = tableContext.getTableInstance()?.id;
if (!tableId) {
return;
}
if (tableContext.getTableInstance()?.customConfig?.storage !== true) {
return;
}
const size = getTableSize(tableId);
if (size) {
tableContext.setProps({
size,
});
}
});
return { return {
handleChangeSize, handleChangeSize,
}; };

1
src/components/SmartTable/src/hooks/useSmartTableColumnConfig.ts

@ -20,6 +20,7 @@ export const useSmartTableColumnConfig = (getTableInstance: () => VxeGridInstanc
return field; return field;
}) })
.filter((item) => item !== undefined && item !== null); .filter((item) => item !== undefined && item !== null);
// TODO:使用统一缓存
const allConfig = const allConfig =
JSON.parse(localStorage.getItem(SMART_TABLE_CUSTOM_COLUMN_SORT) || '{}') || {}; JSON.parse(localStorage.getItem(SMART_TABLE_CUSTOM_COLUMN_SORT) || '{}') || {};
allConfig[tableId] = columns; allConfig[tableId] = columns;

7
src/components/SmartTable/src/hooks/useSmartTableContext.ts

@ -1,4 +1,8 @@
import type { SmartTableProps, TableActionType } from '../types/SmartTableType'; import type {
SmartTableInnerActionType,
SmartTableProps,
TableActionType,
} from '../types/SmartTableType';
import type { ComputedRef, Ref } from 'vue'; import type { ComputedRef, Ref } from 'vue';
import { inject, provide } from 'vue'; import { inject, provide } from 'vue';
@ -7,6 +11,7 @@ const key = Symbol('smart-table');
type Instance = TableActionType & { type Instance = TableActionType & {
wrapRef: Ref<Nullable<HTMLElement>>; wrapRef: Ref<Nullable<HTMLElement>>;
getBindValues: ComputedRef<Recordable>; getBindValues: ComputedRef<Recordable>;
tableInnerAction: SmartTableInnerActionType;
}; };
type RetInstance = Omit<Instance, 'getBindValues'> & { type RetInstance = Omit<Instance, 'getBindValues'> & {

11
src/components/SmartTable/src/types/SmartTableType.ts

@ -162,3 +162,14 @@ export interface TableActionType {
useYnByCheckbox: (useYn: boolean) => Promise<boolean | undefined>; useYnByCheckbox: (useYn: boolean) => Promise<boolean | undefined>;
useYnByRow: (row: any | any[], useYn: boolean) => Promise<boolean | undefined>; useYnByRow: (row: any | any[], useYn: boolean) => Promise<boolean | undefined>;
} }
/**
*
*/
export interface SmartTableInnerActionType {
// nothing
}
export interface SmartTableInnerRegisterActionType extends SmartTableInnerActionType {
registerInnerAction: (action: SmartTableInnerActionType) => void;
}

2
src/modules/smart-system/views/parameter/SysParameterListView.vue

@ -51,6 +51,7 @@
}; };
const [registerTable, { editByRowModal, deleteByRow }] = useSmartTable({ const [registerTable, { editByRowModal, deleteByRow }] = useSmartTable({
id: 'smart-system-sysParameter',
columns: getTableColumns(), columns: getTableColumns(),
height: 'auto', height: 'auto',
pagerConfig: true, pagerConfig: true,
@ -60,6 +61,7 @@
columnConfig: { columnConfig: {
resizable: true, resizable: true,
}, },
customConfig: { storage: true },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true, isHover: true,

Loading…
Cancel
Save