fix: 修复明细表删除行时,会删除第一页数据的bug
This commit is contained in:
31
docs/表单二开/6_只改JS不改模版的二开.md
Normal file
31
docs/表单二开/6_只改JS不改模版的二开.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# 如何在二开中只修改脚本不修改模版
|
||||||
|
|
||||||
|
可以在继承SimpleFormSetup时,不指定模版
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script>
|
||||||
|
// 注意,这里继承的是SimpleFormSetup,使用script setup写法的组件无法继承,必须使用特别的版本
|
||||||
|
import SimpleFormSetup from '/@/components/SimpleForm/src/SimpleFormSetup.vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mixins: [SimpleFormSetup],
|
||||||
|
setup(props, ctx) {
|
||||||
|
const ret = SimpleFormSetup.setup(props, ctx);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...ret
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
formModel: {
|
||||||
|
handler: function(oldVal, newVal){
|
||||||
|
console.log('表单被改了!' + Math.random());
|
||||||
|
this.formModel.zheDie17153 = this.formModel.zhaGe15916 + this.formModel.zhaGe22645
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
这里可以通过对formModel的监控和修改完成计算、赋值操作。
|
||||||
@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
<a-table :bordered="showFormBorder" :columns="headColums.length > 0 ? headColums : columns" :data-source="addDataKey(data)" :pagination="showPagination ? { defaultPageSize: 10 } : false" :scroll="{ x: 'max-content' }">
|
<a-table :bordered="showFormBorder" :columns="headColums.length > 0 ? headColums : columns" :data-source="addDataKey(data)" :pagination="showPagination ? { defaultPageSize: 10 } : false" :scroll="{ x: 'max-content' }">
|
||||||
<template #summary>
|
<template #summary>
|
||||||
<a-table-summary-row v-if="columns.some((x) => x.componentProps?.subTotal)">
|
<a-table-summary-row v-if="columns.some((x) => x.componentProps?.subTotal)">
|
||||||
@ -54,11 +53,11 @@
|
|||||||
<template v-else-if="column.key !== 'index'">
|
<template v-else-if="column.key !== 'index'">
|
||||||
<component
|
<component
|
||||||
:is="componentMap.get(column.componentType)"
|
:is="componentMap.get(column.componentType)"
|
||||||
|
:key="column.dataIndex + record['_key_']"
|
||||||
v-model:value="record[column.dataIndex]"
|
v-model:value="record[column.dataIndex]"
|
||||||
:bordered="showComponentBorder"
|
:bordered="showComponentBorder"
|
||||||
:index="index"
|
:index="index"
|
||||||
:mainKey="mainKey"
|
:mainKey="mainKey"
|
||||||
:key="column.dataIndex + record['_key_']"
|
|
||||||
:row="record"
|
:row="record"
|
||||||
v-bind="getComponentsProps(column.componentProps, column.dataIndex, record, index)"
|
v-bind="getComponentsProps(column.componentProps, column.dataIndex, record, index)"
|
||||||
@blur="onFieldBlur(column, record, index)"
|
@blur="onFieldBlur(column, record, index)"
|
||||||
@ -68,7 +67,7 @@
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="column.key === 'action' && !disabled">
|
<template v-if="column.key === 'action' && !disabled">
|
||||||
<MinusCircleOutlined style="padding-bottom: 20px" @click="remove(index)" />
|
<MinusCircleOutlined style="padding-bottom: 20px" @click="remove(record)" />
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
@ -113,6 +112,7 @@
|
|||||||
import { getDicDetailList } from '/@/api/system/dic';
|
import { getDicDetailList } from '/@/api/system/dic';
|
||||||
import { useI18n } from '/@/hooks/web/useI18n';
|
import { useI18n } from '/@/hooks/web/useI18n';
|
||||||
import { MutipleHeadInfo } from '/@/components/Designer';
|
import { MutipleHeadInfo } from '/@/components/Designer';
|
||||||
|
import { buildUUID } from '/@/utils/uuid';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
// 用于包裹弹窗的form组件 因为一个FormItem 只能收集一个表单组件 所以弹窗的form 必须排除
|
// 用于包裹弹窗的form组件 因为一个FormItem 只能收集一个表单组件 所以弹窗的form 必须排除
|
||||||
@ -237,7 +237,7 @@
|
|||||||
function addDataKey(rows) {
|
function addDataKey(rows) {
|
||||||
rows.forEach((row) => {
|
rows.forEach((row) => {
|
||||||
if (!row['_key_']) {
|
if (!row['_key_']) {
|
||||||
row['_key_'] = Math.random();
|
row['_key_'] = buildUUID();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return rows;
|
return rows;
|
||||||
@ -375,7 +375,8 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const remove = (index) => {
|
const remove = (record) => {
|
||||||
|
const index = data.value.findIndex((r) => r._key_ === record._key_);
|
||||||
data.value.splice(index, 1);
|
data.value.splice(index, 1);
|
||||||
emit('change', unref(data));
|
emit('change', unref(data));
|
||||||
emit('update:value', unref(data));
|
emit('update:value', unref(data));
|
||||||
|
|||||||
Reference in New Issue
Block a user