|
@@ -1,5 +1,12 @@
|
|
|
<template>
|
|
|
- <BasicTable @register="registerTable" @edit-change="onEditChange" :pagination="false" :data-source="modelValue">
|
|
|
+ <BasicTable
|
|
|
+ @register="registerTable"
|
|
|
+ @edit-change="onEditChange"
|
|
|
+ :pagination="false"
|
|
|
+ :row-key="handleKey"
|
|
|
+ :autoCreateKey="false"
|
|
|
+ :data-source="modelValue"
|
|
|
+ >
|
|
|
<template #headerCell="{ column }">
|
|
|
<template v-if="column.dataIndex == 'operation' && showAction">
|
|
|
<div class="text-18px cursor-pointer" @click="handleAdd">
|
|
@@ -20,7 +27,7 @@
|
|
|
</BasicTable>
|
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
|
- import { ref, computed, withDefaults, nextTick } from 'vue';
|
|
|
+ import { computed, withDefaults, nextTick } from 'vue';
|
|
|
import { PlusCircleOutlined, MinusCircleOutlined } from '@ant-design/icons-vue';
|
|
|
import { BasicTable, BasicColumn } from '/@/components/Table';
|
|
|
import { useListPage } from '/@/hooks/system/useListPage';
|
|
@@ -47,12 +54,12 @@
|
|
|
const emit = defineEmits(['update:value', 'update:deleteId']);
|
|
|
const modelValue = computed({
|
|
|
get() {
|
|
|
- console.log(props.value, 'get得到值');
|
|
|
+ // console.log(props.value, 'get-------------props.value');
|
|
|
+
|
|
|
return props.value;
|
|
|
},
|
|
|
set(val) {
|
|
|
- console.log(val, 'set得到值');
|
|
|
-
|
|
|
+ // console.log(val, 'set-------------props.value');
|
|
|
emit('update:value', val);
|
|
|
},
|
|
|
});
|
|
@@ -81,7 +88,8 @@
|
|
|
});
|
|
|
|
|
|
//BasicTable绑定注册
|
|
|
- const [registerTable, { getDataSource }] = tableContext;
|
|
|
+ const [registerTable] = tableContext;
|
|
|
+
|
|
|
function onEditChange({ column, value, record }) {
|
|
|
if (column.dataIndex == 'time') {
|
|
|
record.editValueRefs.time.value = value;
|
|
@@ -97,23 +105,18 @@
|
|
|
const newRow: DataRow = {};
|
|
|
inputFields.forEach((field) => {
|
|
|
newRow[String(field)] = null;
|
|
|
- newRow['key'] = `table-${dayjs().valueOf()}`;
|
|
|
+ newRow['key'] = dayjs().valueOf();
|
|
|
});
|
|
|
return newRow;
|
|
|
};
|
|
|
function handleAdd() {
|
|
|
if (props.count == modelValue.value.length) return useMessage().createMessage.error('最多添加' + props.count + '行数据');
|
|
|
- modelValue.value.push(JSON.parse(JSON.stringify(addEmptyRow(props.tableColumn))));
|
|
|
+ modelValue.value.push(addEmptyRow(props.tableColumn));
|
|
|
modelValue.value = [].concat(modelValue.value);
|
|
|
}
|
|
|
function handleRemove(index, column) {
|
|
|
- const newData = cloneDeep(
|
|
|
- getDataSource()
|
|
|
- .filter((it) => it.key !== column.key)
|
|
|
- .map((it) => {
|
|
|
- return { ...it.editValueRefs, key: it.key };
|
|
|
- })
|
|
|
- );
|
|
|
+ modelValue.value.splice(index, 1);
|
|
|
+ const newData = cloneDeep(modelValue.value.map((it) => it.editValueRefs));
|
|
|
modelValue.value = [];
|
|
|
nextTick(() => {
|
|
|
modelValue.value = newData;
|
|
@@ -123,4 +126,7 @@
|
|
|
deletIdVaule.value = ([] as string[]).concat(deletIdVaule.value);
|
|
|
}
|
|
|
}
|
|
|
+ function handleKey(row) {
|
|
|
+ return row.key;
|
|
|
+ }
|
|
|
</script>
|