Showing
1 changed file
with
0 additions
and
235 deletions
1 | -<template> | |
2 | - <div class="table-content"> | |
3 | - <!-- 采用的原生表格 --> | |
4 | - <table align="center"> | |
5 | - <thead> | |
6 | - <tr> | |
7 | - <th v-for="item in editCellTableTHeadConfig" :key="item">{{ item }}</th> | |
8 | - </tr> | |
9 | - </thead> | |
10 | - <tbody> | |
11 | - <tr v-for="(item, index) in tableArray.content" :key="index"> | |
12 | - <td> | |
13 | - {{ index + 1 }} | |
14 | - </td> | |
15 | - <td style="width: 12vw"> | |
16 | - <Select | |
17 | - v-model:value="item.key" | |
18 | - placeholder="请选择" | |
19 | - :options="selectOptions" | |
20 | - @change="handleChange" | |
21 | - @dropdownVisibleChange="hanldeDropdownVisibleChange" | |
22 | - allowClear | |
23 | - /> | |
24 | - </td> | |
25 | - <td style="width: 12vw"> | |
26 | - <div v-if="item.key === 'date_range'"> | |
27 | - <a-input style="width: 6vw" placeholder="请输入" v-model:value="item.date1" /> | |
28 | - <span>~</span> | |
29 | - <a-input style="width: 6vw" placeholder="请输入" v-model:value="item.date2" /> | |
30 | - </div> | |
31 | - <div v-else> | |
32 | - <a-input | |
33 | - :disabled="item.editDisabled" | |
34 | - placeholder="请输入" | |
35 | - v-model:value="item.value" | |
36 | - /> | |
37 | - </div> | |
38 | - </td> | |
39 | - <td style="width: 4vw"> | |
40 | - <a-switch v-model:checked="item.required" /> | |
41 | - </td> | |
42 | - <td style="width: 4vw"> | |
43 | - <div> | |
44 | - <Button type="dashed" @click="add(item, index)"> | |
45 | - <template #icon><PlusOutlined /></template | |
46 | - ></Button> | |
47 | - <Button type="dashed" style="margin-left: 5px" @click="remove(item, index)"> | |
48 | - <template #icon> <MinusOutlined /></template> | |
49 | - </Button> | |
50 | - </div> | |
51 | - </td> | |
52 | - </tr> | |
53 | - </tbody> | |
54 | - </table> | |
55 | - </div> | |
56 | -</template> | |
57 | -<script lang="ts" setup name="editCellTable"> | |
58 | - import { reactive, ref, onMounted, nextTick } from 'vue'; | |
59 | - import { Select, Button } from 'ant-design-vue'; | |
60 | - import { findDictItemByCode } from '/@/api/system/dict'; | |
61 | - import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; | |
62 | - import { editCellTableTHeadConfig } from '../../../config/config'; | |
63 | - import { selectType, tableItems } from '../../../config/types'; | |
64 | - | |
65 | - defineProps({ | |
66 | - method: { | |
67 | - type: String, | |
68 | - }, | |
69 | - }); | |
70 | - | |
71 | - const selectOptions = ref<selectType[]>([]); | |
72 | - | |
73 | - onMounted(() => { | |
74 | - getSelectOptions(); | |
75 | - }); | |
76 | - | |
77 | - const getSelectOptions = async () => { | |
78 | - const res = await findDictItemByCode({ dictCode: 'dataview_builtin_params' }); | |
79 | - selectOptions.value = res.map((m) => ({ label: m.itemText, value: m.itemValue })); | |
80 | - selectOptions.value.push({ | |
81 | - label: '自定义', | |
82 | - value: 'scope', | |
83 | - }); | |
84 | - }; | |
85 | - | |
86 | - const tableArray = reactive<{ | |
87 | - content: tableItems[]; | |
88 | - }>({ | |
89 | - content: [ | |
90 | - { | |
91 | - key: undefined, | |
92 | - value: '', | |
93 | - editDisabled: false, | |
94 | - required: false, | |
95 | - date1: '', | |
96 | - date2: '', | |
97 | - }, | |
98 | - ], | |
99 | - }); | |
100 | - | |
101 | - // 新增 | |
102 | - const add = (_, index: number) => { | |
103 | - tableArray.content.splice(index + 1, 0, { | |
104 | - key: undefined, | |
105 | - value: '', | |
106 | - editDisabled: false, | |
107 | - required: false, | |
108 | - date1: '', | |
109 | - date2: '', | |
110 | - }); | |
111 | - }; | |
112 | - | |
113 | - // 减少 | |
114 | - const remove = (item, index: number) => { | |
115 | - if (tableArray.content.length > 1) { | |
116 | - selectOptions.value.forEach((ele) => { | |
117 | - if (ele.value == item.key) { | |
118 | - ele.disabled = false; | |
119 | - } | |
120 | - }); | |
121 | - tableArray.content.splice(index, 1); | |
122 | - } else { | |
123 | - resetValue(); | |
124 | - } | |
125 | - }; | |
126 | - | |
127 | - const hanldeDropdownVisibleChange = () => handleChange(); | |
128 | - | |
129 | - //Select互斥 | |
130 | - const handleChange = () => { | |
131 | - selectOptions.value.forEach((ele) => { | |
132 | - ele.disabled = false; | |
133 | - tableArray.content.forEach((element) => { | |
134 | - if (element.key === 'scope' || element.key === 'fixed_date') { | |
135 | - element.editDisabled = false; | |
136 | - } else { | |
137 | - element.value = ''; | |
138 | - element.editDisabled = true; | |
139 | - } | |
140 | - if (element.key === ele.value && element.key !== 'scope' && element.key !== 'fixed_date') { | |
141 | - ele.disabled = true; | |
142 | - } | |
143 | - }); | |
144 | - }); | |
145 | - }; | |
146 | - | |
147 | - //获取数据 | |
148 | - const getValue = () => { | |
149 | - const assemblyData = tableArray.content.map((it) => { | |
150 | - return { | |
151 | - key: it.key, | |
152 | - value: it.key === 'date_range' ? `${it.date1},${it.date2}` : it.value, | |
153 | - editDisabled: it.editDisabled, | |
154 | - required: it.required, | |
155 | - }; | |
156 | - }); | |
157 | - return assemblyData; | |
158 | - }; | |
159 | - | |
160 | - //设置数据 | |
161 | - const setValue = async (data) => { | |
162 | - await nextTick(); | |
163 | - const assemblyData = data.map((it) => { | |
164 | - return { | |
165 | - key: it.key, | |
166 | - value: it.value, | |
167 | - editDisabled: it.editDisabled, | |
168 | - required: it.required, | |
169 | - date1: it.key === 'date_range' ? it.value?.split(',')?.at(-2) : '', | |
170 | - date2: it.key === 'date_range' ? it.value?.split(',')?.at(-1) : '', | |
171 | - }; | |
172 | - }); | |
173 | - tableArray.content = assemblyData; | |
174 | - tableArray.content.forEach(() => { | |
175 | - handleChange(); | |
176 | - }); | |
177 | - }; | |
178 | - | |
179 | - //重置数据 | |
180 | - const resetValue = () => { | |
181 | - tableArray.content = []; | |
182 | - tableArray.content.push({ | |
183 | - key: undefined, | |
184 | - value: '', | |
185 | - editDisabled: false, | |
186 | - required: false, | |
187 | - date1: '', | |
188 | - date2: '', | |
189 | - }); | |
190 | - nextTick(() => { | |
191 | - tableArray.content.forEach(() => { | |
192 | - handleChange(); | |
193 | - }); | |
194 | - }); | |
195 | - }; | |
196 | - defineExpose({ | |
197 | - getValue, | |
198 | - setValue, | |
199 | - resetValue, | |
200 | - }); | |
201 | -</script> | |
202 | - | |
203 | -<style scoped lang="less"> | |
204 | - @table-color: #e5e7eb; | |
205 | - | |
206 | - .table-border-color { | |
207 | - border: 1px solid #e5e7eb; | |
208 | - text-align: center; | |
209 | - } | |
210 | - | |
211 | - .table-content { | |
212 | - overflow-x: auto; | |
213 | - | |
214 | - table { | |
215 | - border-collapse: collapse; | |
216 | - width: 35vw; | |
217 | - &:extend(.table-border-color); | |
218 | - } | |
219 | - | |
220 | - table thead { | |
221 | - white-space: nowrap; | |
222 | - } | |
223 | - | |
224 | - table td { | |
225 | - padding: 5px; | |
226 | - white-space: nowrap; | |
227 | - &:extend(.table-border-color); | |
228 | - } | |
229 | - | |
230 | - table th { | |
231 | - padding: 5px; | |
232 | - &:extend(.table-border-color); | |
233 | - } | |
234 | - } | |
235 | -</style> |