Skip to content

Commit

Permalink
fix(table-select): 修复element版本中选中记录上点击删除按钮,清空所有value后,报异常的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Oct 25, 2023
1 parent 6530c29 commit 5d95b40
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
34 changes: 18 additions & 16 deletions packages/fast-crud/src/components/crud/fs-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,6 @@ export default defineComponent({
// eslint-disable-next-line vue/no-setup-props-destructure
const initialForm = _.cloneDeep(props.initialForm);
// eslint-disable-next-line vue/no-setup-props-destructure
const scope: Ref<FormScopeContext> = ref({
row: initialForm,
form,
index: props.index,
mode: props.mode,
attrs: ctx.attrs,
getComponentRef
} as FormScopeContext);
function getContextFn() {
return scope.value;
}
// eslint-disable-next-line vue/no-setup-props-destructure
_.each(props.columns, (item) => {
if (item.value != null && item.value instanceof AsyncComputeValue) {
Expand All @@ -288,6 +274,23 @@ export default defineComponent({
}
}
});
const scope: Ref<FormScopeContext> = computed(() => {
return {
initialForm,
row: form,
form,
index: props.index,
mode: props.mode || "add",
attrs: ctx.attrs,
getComponentRef
} as FormScopeContext;
});
function getContextFn() {
return scope.value;
}
//form.valueBuilder
function doValueBuilder(form: any) {
if (form == null) {
Expand Down Expand Up @@ -335,7 +338,6 @@ export default defineComponent({
const groupActiveKey = ref([]);
// eslint-disable-next-line vue/no-setup-props-destructure
_.forEach(props.group?.groups, (groupItem, key) => {
if (groupItem.collapsed !== true) {
groupActiveKey.value.push(key);
Expand Down Expand Up @@ -414,7 +416,7 @@ export default defineComponent({
return formRef.value;
}
function createInitialForm() {
return _.cloneDeep(props.initialForm || {});
return _.cloneDeep(initialForm || {});
}
async function reset() {
// ui.form.resetWrap(formRef.value, { form, initialForm: createInitialForm() });
Expand Down
4 changes: 2 additions & 2 deletions packages/fast-crud/src/components/extends/fs-table-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type FsTableSelectProps = {
*/
dict: Dict;
/**
* 选择框配置
* 选择框 fs-dict-select配置
*/
select?: any;
Expand All @@ -71,7 +71,7 @@ type FsTableSelectProps = {
dialog?: any;
/**
* 当前选中值 values-format配置
* 当前选中值 fs-values-format组件 配置
*/
valuesFormat?: any;
Expand Down
7 changes: 7 additions & 0 deletions packages/fast-crud/src/d/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export type ComponentRenderContext = {
} & ScopeContext;

export type FormScopeContext = {
/**
* 初始form数据
*/
initialForm: any;
/**
* 属性
*/
attrs: any;
/**
* 提交成功后的response
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/ui-antdv4/src/antdv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export class Antdv implements UiInterface {
vLoading: false,
buildSelectionBinding(req) {
const selectedRowKeys = req.selectedRowKeys;
const onChange = (changed: any[]) => {
const onChange = (changed: any[] = []) => {
req.onSelectedKeysChanged(changed);
};
let type = "radio";
Expand Down
6 changes: 5 additions & 1 deletion packages/ui/ui-element/src/element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class Element implements UiInterface {
}

if (req.multiple) {
const onSelectionChange = (changedRows: any[]) => {
const onSelectionChange = (changedRows: any[] = []) => {
const rowKey = req.getRowKey();
let selectedKeys = changedRows.map((item: any) => item[rowKey]);
if (req.crossPage) {
Expand Down Expand Up @@ -503,6 +503,10 @@ export class Element implements UiInterface {
} else {
//单选
const onCurrentChange = (changed: any) => {
if (changed == null) {
req.onSelectedKeysChanged([]);
return;
}
const rowKey = req.getRowKey();
const selectedKeys = [changed[rowKey]];
req.onSelectedKeysChanged(selectedKeys);
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/ui-naive/src/naive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export class Naive implements UiInterface {
req.tableRef.value.scrollTo({ top: req.top });
},
buildSelectionBinding(req) {
const onSelectionChange = (changed: any) => {
const onSelectionChange = (changed: any = []) => {
req.onSelectedKeysChanged(changed);
};

Expand Down

0 comments on commit 5d95b40

Please sign in to comment.