Commit 8eaf57562610a833c8083ae9957f458319d1cc93
1 parent
d018363d
feat(table): editable component text align
使可编辑单元格显示的input中的文字对齐方式与列自身的align属性相匹配
Showing
2 changed files
with
41 additions
and
19 deletions
src/components/Table/src/components/editable/EditableCell.vue
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | :popoverVisible="getRuleVisible" | 13 | :popoverVisible="getRuleVisible" |
14 | :rule="getRule" | 14 | :rule="getRule" |
15 | :ruleMessage="ruleMessage" | 15 | :ruleMessage="ruleMessage" |
16 | + :class="getWrapperClass" | ||
16 | size="small" | 17 | size="small" |
17 | ref="elRef" | 18 | ref="elRef" |
18 | @change="handleChange" | 19 | @change="handleChange" |
@@ -140,6 +141,11 @@ | @@ -140,6 +141,11 @@ | ||
140 | }; | 141 | }; |
141 | }); | 142 | }); |
142 | 143 | ||
144 | + const getWrapperClass = computed(() => { | ||
145 | + const { align = 'center' } = props.column; | ||
146 | + return `edit-cell-align-${align}`; | ||
147 | + }); | ||
148 | + | ||
143 | const getRowEditable = computed(() => { | 149 | const getRowEditable = computed(() => { |
144 | const { editable } = props.record || {}; | 150 | const { editable } = props.record || {}; |
145 | return !!editable; | 151 | return !!editable; |
@@ -315,6 +321,7 @@ | @@ -315,6 +321,7 @@ | ||
315 | getComponentProps, | 321 | getComponentProps, |
316 | handleOptionsChange, | 322 | handleOptionsChange, |
317 | getWrapperStyle, | 323 | getWrapperStyle, |
324 | + getWrapperClass, | ||
318 | getRowEditable, | 325 | getRowEditable, |
319 | getValues, | 326 | getValues, |
320 | handleEnter, | 327 | handleEnter, |
@@ -326,6 +333,30 @@ | @@ -326,6 +333,30 @@ | ||
326 | <style lang="less"> | 333 | <style lang="less"> |
327 | @prefix-cls: ~'@{namespace}-editable-cell'; | 334 | @prefix-cls: ~'@{namespace}-editable-cell'; |
328 | 335 | ||
336 | + .edit-cell-align-left { | ||
337 | + text-align: left; | ||
338 | + | ||
339 | + input:not(.ant-calendar-picker-input, .ant-time-picker-input) { | ||
340 | + text-align: left; | ||
341 | + } | ||
342 | + } | ||
343 | + | ||
344 | + .edit-cell-align-center { | ||
345 | + text-align: center; | ||
346 | + | ||
347 | + input:not(.ant-calendar-picker-input, .ant-time-picker-input) { | ||
348 | + text-align: center; | ||
349 | + } | ||
350 | + } | ||
351 | + | ||
352 | + .edit-cell-align-right { | ||
353 | + text-align: right; | ||
354 | + | ||
355 | + input:not(.ant-calendar-picker-input, .ant-time-picker-input) { | ||
356 | + text-align: right; | ||
357 | + } | ||
358 | + } | ||
359 | + | ||
329 | .edit-cell-rule-popover { | 360 | .edit-cell-rule-popover { |
330 | .ant-popover-inner-content { | 361 | .ant-popover-inner-content { |
331 | padding: 4px 8px; | 362 | padding: 4px 8px; |
src/views/demo/table/EditRowTable.vue
@@ -28,33 +28,34 @@ | @@ -28,33 +28,34 @@ | ||
28 | editComponentProps: { | 28 | editComponentProps: { |
29 | prefix: '$', | 29 | prefix: '$', |
30 | }, | 30 | }, |
31 | - width: 200, | 31 | + width: 150, |
32 | }, | 32 | }, |
33 | { | 33 | { |
34 | title: '默认输入状态', | 34 | title: '默认输入状态', |
35 | dataIndex: 'name7', | 35 | dataIndex: 'name7', |
36 | editRow: true, | 36 | editRow: true, |
37 | - width: 200, | 37 | + width: 150, |
38 | }, | 38 | }, |
39 | { | 39 | { |
40 | title: '输入框校验', | 40 | title: '输入框校验', |
41 | dataIndex: 'name1', | 41 | dataIndex: 'name1', |
42 | editRow: true, | 42 | editRow: true, |
43 | + align: 'left', | ||
43 | // 默认必填校验 | 44 | // 默认必填校验 |
44 | editRule: true, | 45 | editRule: true, |
45 | - width: 200, | 46 | + width: 150, |
46 | }, | 47 | }, |
47 | { | 48 | { |
48 | title: '输入框函数校验', | 49 | title: '输入框函数校验', |
49 | dataIndex: 'name2', | 50 | dataIndex: 'name2', |
50 | editRow: true, | 51 | editRow: true, |
52 | + align: 'right', | ||
51 | editRule: async (text) => { | 53 | editRule: async (text) => { |
52 | if (text === '2') { | 54 | if (text === '2') { |
53 | return '不能输入该值'; | 55 | return '不能输入该值'; |
54 | } | 56 | } |
55 | return ''; | 57 | return ''; |
56 | }, | 58 | }, |
57 | - width: 200, | ||
58 | }, | 59 | }, |
59 | { | 60 | { |
60 | title: '数字输入框', | 61 | title: '数字输入框', |
@@ -62,7 +63,7 @@ | @@ -62,7 +63,7 @@ | ||
62 | editRow: true, | 63 | editRow: true, |
63 | editRule: true, | 64 | editRule: true, |
64 | editComponent: 'InputNumber', | 65 | editComponent: 'InputNumber', |
65 | - width: 200, | 66 | + width: 150, |
66 | }, | 67 | }, |
67 | { | 68 | { |
68 | title: '下拉框', | 69 | title: '下拉框', |
@@ -102,7 +103,7 @@ | @@ -102,7 +103,7 @@ | ||
102 | valueFormat: 'YYYY-MM-DD', | 103 | valueFormat: 'YYYY-MM-DD', |
103 | format: 'YYYY-MM-DD', | 104 | format: 'YYYY-MM-DD', |
104 | }, | 105 | }, |
105 | - width: 200, | 106 | + width: 150, |
106 | }, | 107 | }, |
107 | { | 108 | { |
108 | title: '时间选择', | 109 | title: '时间选择', |
@@ -113,17 +114,7 @@ | @@ -113,17 +114,7 @@ | ||
113 | valueFormat: 'HH:mm', | 114 | valueFormat: 'HH:mm', |
114 | format: 'HH:mm', | 115 | format: 'HH:mm', |
115 | }, | 116 | }, |
116 | - width: 200, | ||
117 | - }, | ||
118 | - { | ||
119 | - title: '远程下拉', | ||
120 | - dataIndex: 'name4', | ||
121 | - editRow: true, | ||
122 | - editComponent: 'ApiSelect', | ||
123 | - editComponentProps: { | ||
124 | - api: optionsListApi, | ||
125 | - }, | ||
126 | - width: 200, | 117 | + width: 100, |
127 | }, | 118 | }, |
128 | { | 119 | { |
129 | title: '勾选框', | 120 | title: '勾选框', |
@@ -134,7 +125,7 @@ | @@ -134,7 +125,7 @@ | ||
134 | editValueMap: (value) => { | 125 | editValueMap: (value) => { |
135 | return value ? '是' : '否'; | 126 | return value ? '是' : '否'; |
136 | }, | 127 | }, |
137 | - width: 200, | 128 | + width: 100, |
138 | }, | 129 | }, |
139 | { | 130 | { |
140 | title: '开关', | 131 | title: '开关', |
@@ -144,7 +135,7 @@ | @@ -144,7 +135,7 @@ | ||
144 | editValueMap: (value) => { | 135 | editValueMap: (value) => { |
145 | return value ? '开' : '关'; | 136 | return value ? '开' : '关'; |
146 | }, | 137 | }, |
147 | - width: 200, | 138 | + width: 100, |
148 | }, | 139 | }, |
149 | ]; | 140 | ]; |
150 | export default defineComponent({ | 141 | export default defineComponent({ |