headerTable.vue
2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<template>
<div class="table-content">
<!-- 采用的原生表格 -->
<table align="center">
<thead>
<tr>
<th v-for="item in editTestCellTableTHeaderConfig" :key="item">{{ item }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in tableArray.content" :key="index">
<td>
{{ index + 1 }}
</td>
<td style="width: 12vw">
<a-input style="width: 12vw" placeholder="请输入" v-model:value="item.key" />
</td>
<td style="width: 12vw">
<a-input style="width: 12vw" placeholder="请输入" v-model:value="item.value" />
</td>
<td style="width: 4vw">
<a-switch v-model:checked="item.required" />
</td>
<td style="width: 4vw">
<div>
<Button type="dashed" @click="add(item, index)">
<template #icon><PlusOutlined /></template
></Button>
<Button type="dashed" style="margin-left: 5px" @click="remove(index)">
<template #icon> <MinusOutlined /></template>
</Button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script lang="ts" setup name="editCellTable">
import { reactive, nextTick } from 'vue';
import { Button } from 'ant-design-vue';
import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
import { editTestCellTableTHeaderConfig } from '../../../config/config';
import { tableItems } from '../../../config/types';
import { useUtils } from '../../../hooks/useUtils';
const { CommonFuncValue } = useUtils();
const tableArray = reactive<{
content: tableItems[];
}>({
content: [
{
key: '',
value: '',
required: false,
},
],
});
const add = (_, index: number) => {
tableArray.content.splice(index + 1, 0, {
key: '',
value: '',
required: false,
});
};
const remove = (index: number) => {
if (tableArray.content.length > 1) {
tableArray.content.splice(index, 1);
} else {
resetValue();
}
};
//获取数据
const getValue = () => {
const newFuncValue = new CommonFuncValue(tableArray.content as tableItems[]);
return newFuncValue.get();
};
//设置数据
const setValue = async (data) => {
await nextTick();
tableArray.content = data;
};
//重置数据
const resetValue = () => {
tableArray.content = [];
tableArray.content.push({
key: 'ContentType',
value: 'none',
required: false,
});
};
defineExpose({
getValue,
setValue,
resetValue,
});
</script>
<style scoped lang="less">
@import '../common/commonTable.less';
</style>