Skip to content

Commit

Permalink
perf: 优化free模式,支持默认不激活
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Dec 19, 2023
1 parent deca066 commit aeaf0a6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/fast-admin/fs-admin-antdv
2 changes: 1 addition & 1 deletion packages/fast-admin/fs-admin-element
2 changes: 1 addition & 1 deletion packages/fast-admin/fs-admin-naive-ui
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ export default defineComponent({
}
}
async function onSubmit() {
if (props.editableOpts?.mode === "free") {
await props.editableCell.persist();
return;
}
await props.editableCell.save();
}
function onCancel() {
props.editableCell.cancel();
}

const showAction: ComputedRef<boolean> = computed(() => {
return props.editableOpts?.mode === "cell" && props.editableCell.showAction !== false;
console.log(props.editableOpts?.mode, props.editableOpts.showAction, props.editableCell.showAction);
return (
(props.editableOpts?.mode === "cell" || props.editableOpts?.mode === "free") &&
props.editableCell.showAction !== false
);
});
const isDirty: ComputedRef<boolean> = computed(() => {
return props.editableCell.isChanged && props.editableCell.isChanged();
Expand Down Expand Up @@ -109,7 +117,7 @@ export default defineComponent({
return <fs-cell ref={"targetRef"} item={props.item} scope={props.scope} {...ctx.attrs} />;
}
const editableCell: EditableCell = props.editableCell;
const trigger = props.editableOpts.mode === "cell" ? props.editableOpts?.activeTrigger : false;
const trigger = showAction.value ? props.editableOpts?.activeTrigger : false;
return (
<fs-editable
ref={"editableRef"}
Expand Down
15 changes: 9 additions & 6 deletions packages/fast-crud/src/components/crud/editable/use-editable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export function useEditable(props: any, ctx: any, tableRef: any): { editable: Ed
const updateCell: any = computed(() => {
return col.editable?.updateCell || options.value.updateCell;
});
const showAction: any = computed(() => {
return col.editable?.showAction || options.value.showAction;
});
const cell: EditableCell = reactive({
mode: editableId < 0 ? "add" : "edit",
oldValue: undefined,
Expand All @@ -139,7 +142,7 @@ export function useEditable(props: any, ctx: any, tableRef: any): { editable: Ed
activeTrigger: options.value.activeTrigger,
column: col,
updateCell,
showAction: true,
showAction,
isEditable: () => {
let disabled = col?.editable?.disabled;
if (disabled instanceof Function) {
Expand Down Expand Up @@ -172,11 +175,11 @@ export function useEditable(props: any, ctx: any, tableRef: any): { editable: Ed
cancelAll();
}
}
if (opts.showAction != null) {
cell.showAction = opts.showAction;
} else {
cell.showAction = null;
}
// if (opts.showAction != null) {
// cell.showAction = opts.showAction;
// } else {
// cell.showAction = null;
// }
cell.isEditing = true;

cell.oldValue = getValue(key);
Expand Down
1 change: 1 addition & 0 deletions packages/fast-crud/src/d/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ export type TableColumnEditableProps = {
disabled?: boolean | TableColumnEditableDisabledFunc;
updateCell?: EditableUpdateCellRequest;
updateColumn?: EditableUpdateColumnRequest;
showAction?: boolean;
};

export type ConditionalRenderProps = {
Expand Down

0 comments on commit aeaf0a6

Please sign in to comment.