Skip to content

Commit

Permalink
perf: 优化dict性能
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Mar 24, 2023
1 parent c04b6e0 commit 39a5f1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
33 changes: 23 additions & 10 deletions packages/fast-crud/src/components/crud/fs-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ export default defineComponent({
editable: {
type: Object
},

loading: {
type: Boolean,
default: false
},
request: {}
} as any,
emits: ["row-handle", "value-change", "pagination-change", "filter-change", "sort-change", "data-change"],
Expand Down Expand Up @@ -357,6 +362,12 @@ export default defineComponent({
});

const renderMode = ui.table.renderMode;
const dataSource = computed(() => {
return {
[ui.table.data]: props.data
};
});

if (renderMode === "slot") {
const computedTableSlots = computed(() => {
return buildTableSlots({ props, ui, renderRowHandle, renderCellComponent } as BuildTableColumnsOption);
Expand All @@ -367,15 +378,20 @@ export default defineComponent({
if (props.show === false) {
return;
}
const dataSource = {
[ui.table.data]: props.data
};

const tableRender = (
<tableComp ref={tableRef} {...ctx.attrs} {...events} {...dataSource} v-slots={computedTableSlots.value} />
<tableComp
ref={tableRef}
{...ctx.attrs}
loading={props.loading}
{...events}
{...dataSource.value}
v-slots={computedTableSlots.value}
/>
);
if (typeof ui.table.vLoading === "string") {
const loading = resolveDirective(ui.table.vLoading);
return withDirectives(tableRender, [[loading, ctx.attrs.loading]]);
return withDirectives(tableRender, [[loading, props.loading]]);
}
return tableRender;
};
Expand All @@ -397,17 +413,14 @@ export default defineComponent({
if (props.show === false) {
return;
}

const dataSource = {
[ui.table.data]: props.data
};
return (
<tableComp
ref={tableRef}
loading={props.loading}
{...ctx.attrs}
{...events}
columns={computedColumns.value}
{...dataSource}
{...dataSource.value}
v-slots={props.slots}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/fast-crud/src/use/use-dict-define.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from "lodash-es";
import { useMerge } from "./use-merge";
import logger from "../utils/util.log";
import { reactive, UnwrapRef } from "vue";
import { reactive, shallowReactive, UnwrapRef } from "vue";
import LRU from "lru-cache";
import { UnwrapNestedRefs } from "vue";

Expand Down Expand Up @@ -410,7 +410,7 @@ export class Dict<T = any> extends UnMergeable implements DictOptions<T> {
* @param config
*/
export function dict<T = any>(config: DictOptions<T>): UnwrapNestedRefs<Dict<any>> {
const ret = reactive(new Dict(config));
const ret = shallowReactive(new Dict(config));
if (!ret.prototype && ret.immediate) {
ret.loadDict();
}
Expand Down

0 comments on commit 39a5f1d

Please sign in to comment.