Commit 4f8e1c1b5ffc78242b300e85be22b1fa07c7d902

Authored by vben
1 parent e250ad56

fix(table): fix known errors in editable tables close #267

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