Skip to content

Commit

Permalink
perf: 优化翻页性能
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Mar 24, 2023
1 parent 39a5f1d commit d0a1db7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
10 changes: 8 additions & 2 deletions packages/fast-crud/src/components/fs-crud.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
ref="tableRef"
class="fs-crud-table"
v-bind="computedTable"
:loading="table.loading"
:row-handle="rowHandle"
:data="data"
:cell-slots="computedCellSlots"
Expand Down Expand Up @@ -114,7 +115,7 @@ import { useMerge } from "../use/use-merge";
import utilLog from "../utils/util.log";
import { SetSearchFormDataProps } from "../d";
import { useUi } from "../use";
import { utils } from "../utils";
const { merge } = useMerge();
function useProviders(props: any, ctx: SetupContext) {
Expand Down Expand Up @@ -296,13 +297,18 @@ function useTable(props: any, ctx: SetupContext) {
const toolbarRef = ref();
const containerRef = ref();
const { maxHeightRef, computeBodyHeight } = useFixedHeight(props, ctx, { tableRef, containerRef });

const tablePropRef = toRef(props, "table");
const computedTable = computed(() => {
console.log("computed table");
// antdv naive 高度自适应, 如果用户有配置scroll,则优先使用用户配置的
let fixedHeight = {};
if (maxHeightRef?.value != null) {
fixedHeight = ui.table.buildMaxHeight(maxHeightRef.value);
}
return _.merge(fixedHeight, { ...ctx.attrs, ...props.table });
const pAttrs = utils.dash.omit(tablePropRef, "loading");

return _.merge(fixedHeight, { ...ctx.attrs, ...pAttrs });
});

const computedToolbar = toRef(props, "toolbar");
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-crud/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import defaultCrudOptions from "./use/default-crud-options";
import utils from "./utils/index";
import { utils } from "./utils/index";
import types from "./types/index";
import * as components from "./components";
import { FsFormWrapper } from "./components";
Expand Down
8 changes: 6 additions & 2 deletions packages/fast-crud/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import trace from "./util.trace";
import vite from "./util.vite";
import store from "./util.store";
import { deepdash } from "./deepdash";
import dash from "./util.dash";
export * from "./util.log";

export default {
export const utils = {
logger,
strings,
trace,
vite,
store,
deepdash
deepdash,
dash
};

export default utils;
23 changes: 23 additions & 0 deletions packages/fast-crud/src/utils/util.dash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Ref } from "vue";

export default {
/**
* 重构object,但忽略某些字段
* @param ref
* @param skips
*/
omit(ref: Ref, ...skips: string[]): any {
const keys = Object.keys(ref.value);
const pAttrs: any = {};
for (const key of keys) {
if (key === "loading") {
continue;
}
if (skips.indexOf(key) >= 0) {
continue;
}
pAttrs[key] = ref.value[key];
}
return pAttrs;
}
};

0 comments on commit d0a1db7

Please sign in to comment.