Commit 4f8e1c1b5ffc78242b300e85be22b1fa07c7d902
1 parent
e250ad56
fix(table): fix known errors in editable tables close #267
Showing
5 changed files
with
43 additions
and
24 deletions
CHANGELOG.zh_CN.md
... | ... | @@ -4,9 +4,16 @@ |
4 | 4 | |
5 | 5 | - 新增 `settingButtonPosition`配置项,用于配置`设置`按钮位置 |
6 | 6 | |
7 | +### ⚡ Performance Improvements | |
8 | + | |
9 | +- 优化可编辑居中样式及下拉框宽度过短 | |
10 | +- 表格新增编辑时`edit-change`事件监听 | |
11 | + | |
7 | 12 | ### 🐛 Bug Fixes |
8 | 13 | |
9 | 14 | - 修复图片预览样式错误 |
15 | +- 修复图标样式问题 | |
16 | +- 修复可编辑表格下拉回显问题 | |
10 | 17 | |
11 | 18 | ## 2.0.0 (2021-02-18) |
12 | 19 | ... | ... |
src/components/Table/src/BasicTable.vue
src/components/Table/src/components/editable/EditableCell.vue
... | ... | @@ -29,21 +29,21 @@ |
29 | 29 | <script lang="ts"> |
30 | 30 | import type { CSSProperties, PropType } from 'vue'; |
31 | 31 | import type { BasicColumn } from '../../types/table'; |
32 | + import type { EditRecordRow } from './index'; | |
32 | 33 | |
33 | - import { defineComponent, ref, unref, nextTick, computed, watchEffect } from 'vue'; | |
34 | + import { defineComponent, ref, unref, nextTick, computed, watchEffect, toRaw } from 'vue'; | |
34 | 35 | import { FormOutlined, CloseOutlined, CheckOutlined } from '@ant-design/icons-vue'; |
36 | + import { CellComponent } from './CellComponent'; | |
35 | 37 | |
36 | 38 | import { useDesign } from '/@/hooks/web/useDesign'; |
37 | - import { isString, isBoolean, isFunction, isNumber, isArray } from '/@/utils/is'; | |
39 | + import { useTableContext } from '../../hooks/useTableContext'; | |
40 | + | |
38 | 41 | import clickOutside from '/@/directives/clickOutside'; |
39 | 42 | |
40 | - import { CellComponent } from './CellComponent'; | |
41 | - import { useTableContext } from '../../hooks/useTableContext'; | |
42 | 43 | import { propTypes } from '/@/utils/propTypes'; |
44 | + import { isString, isBoolean, isFunction, isNumber, isArray } from '/@/utils/is'; | |
43 | 45 | import { createPlaceholderMessage } from './helper'; |
44 | 46 | |
45 | - import type { EditRecordRow } from './index'; | |
46 | - | |
47 | 47 | export default defineComponent({ |
48 | 48 | name: 'EditableCell', |
49 | 49 | components: { FormOutlined, CloseOutlined, CheckOutlined, CellComponent }, |
... | ... | @@ -136,9 +136,11 @@ |
136 | 136 | if (!component.includes('Select')) { |
137 | 137 | return value; |
138 | 138 | } |
139 | + | |
139 | 140 | const options: LabelValueOptions = editComponentProps?.options ?? (unref(optionsRef) || []); |
140 | 141 | const option = options.find((item) => `${item.value}` === `${value}`); |
141 | - return option?.label; | |
142 | + | |
143 | + return option?.label ?? value; | |
142 | 144 | }); |
143 | 145 | |
144 | 146 | const getWrapperStyle = computed( |
... | ... | @@ -188,6 +190,11 @@ |
188 | 190 | } else if (isString(e) || isBoolean(e) || isNumber(e)) { |
189 | 191 | currentValueRef.value = e; |
190 | 192 | } |
193 | + table.emit?.('edit-change', { | |
194 | + column: props.column, | |
195 | + value: unref(currentValueRef), | |
196 | + record: toRaw(props.record), | |
197 | + }); | |
191 | 198 | handleSubmiRule(); |
192 | 199 | } |
193 | 200 | |
... | ... | @@ -220,13 +227,17 @@ |
220 | 227 | return true; |
221 | 228 | } |
222 | 229 | |
223 | - async function handleSubmit(needEmit = true) { | |
224 | - const isPass = await handleSubmiRule(); | |
225 | - if (!isPass) return false; | |
230 | + async function handleSubmit(needEmit = true, valid = true) { | |
231 | + if (valid) { | |
232 | + const isPass = await handleSubmiRule(); | |
233 | + if (!isPass) return false; | |
234 | + } | |
235 | + | |
226 | 236 | const { column, index } = props; |
227 | 237 | const { key, dataIndex } = column; |
228 | 238 | const value = unref(currentValueRef); |
229 | 239 | if (!key || !dataIndex) return; |
240 | + | |
230 | 241 | const dataKey = (dataIndex || key) as string; |
231 | 242 | |
232 | 243 | const record = await table.updateTableData(index, dataKey, value); |
... | ... | @@ -287,15 +298,15 @@ |
287 | 298 | const validFns = (props.record?.validCbs || []).map((fn) => fn()); |
288 | 299 | |
289 | 300 | const res = await Promise.all(validFns); |
301 | + | |
290 | 302 | const pass = res.every((item) => !!item); |
291 | 303 | |
292 | 304 | if (!pass) return; |
293 | 305 | const submitFns = props.record?.submitCbs || []; |
294 | - submitFns.forEach((fn) => fn(false)); | |
306 | + submitFns.forEach((fn) => fn(false, false)); | |
295 | 307 | table.emit?.('edit-row-end'); |
296 | 308 | return true; |
297 | 309 | } |
298 | - // isArray(props.record?.submitCbs) && props.record?.submitCbs.forEach((fn) => fn()); | |
299 | 310 | }; |
300 | 311 | } |
301 | 312 | |
... | ... | @@ -328,10 +339,6 @@ |
328 | 339 | @prefix-cls: ~'@{namespace}-editable-cell'; |
329 | 340 | |
330 | 341 | .edit-cell-rule-popover { |
331 | - // .ant-popover-arrow { | |
332 | - // // border-color: transparent @error-color @error-color transparent !important; | |
333 | - // } | |
334 | - | |
335 | 342 | .ant-popover-inner-content { |
336 | 343 | padding: 4px 8px; |
337 | 344 | color: @error-color; |
... | ... | @@ -346,6 +353,10 @@ |
346 | 353 | display: flex; |
347 | 354 | align-items: center; |
348 | 355 | justify-content: center; |
356 | + | |
357 | + > .ant-select { | |
358 | + min-width: calc(100% - 50px); | |
359 | + } | |
349 | 360 | } |
350 | 361 | |
351 | 362 | &__icon { |
... | ... | @@ -359,8 +370,6 @@ |
359 | 370 | } |
360 | 371 | |
361 | 372 | &__normal { |
362 | - padding-right: 48px; | |
363 | - | |
364 | 373 | &-icon { |
365 | 374 | position: absolute; |
366 | 375 | top: 4px; | ... | ... |
src/design/ant/index.less
src/views/demo/page/form/high/PersonTable.vue
1 | 1 | <template> |
2 | 2 | <div> |
3 | - <BasicTable @register="registerTable"> | |
3 | + <BasicTable @register="registerTable" @edit-change="handleEditChange"> | |
4 | 4 | <template #action="{ record, column }"> |
5 | 5 | <TableAction :actions="createActions(record, column)" /> |
6 | 6 | </template> |
... | ... | @@ -29,14 +29,11 @@ |
29 | 29 | title: '工号', |
30 | 30 | dataIndex: 'no', |
31 | 31 | editRow: true, |
32 | - // customRender: renderEditableRow({ dataIndex: 'no', placeholder: '请输入工号' }), | |
33 | 32 | }, |
34 | 33 | { |
35 | 34 | title: '所属部门', |
36 | 35 | dataIndex: 'dept', |
37 | 36 | editRow: true, |
38 | - | |
39 | - // customRender: renderEditableRow({ dataIndex: 'dept', placeholder: '请输入所属部门' }), | |
40 | 37 | }, |
41 | 38 | ]; |
42 | 39 | |
... | ... | @@ -90,6 +87,10 @@ |
90 | 87 | record.onEdit?.(false, true); |
91 | 88 | } |
92 | 89 | |
90 | + function handleEditChange(data: Recordable) { | |
91 | + console.log(data); | |
92 | + } | |
93 | + | |
93 | 94 | function handleAdd() { |
94 | 95 | const data = getDataSource(); |
95 | 96 | const addRow: EditRecordRow = { |
... | ... | @@ -136,6 +137,7 @@ |
136 | 137 | createActions, |
137 | 138 | handleAdd, |
138 | 139 | getDataSource, |
140 | + handleEditChange, | |
139 | 141 | }; |
140 | 142 | }, |
141 | 143 | }); | ... | ... |