Commit c624fb9877cf0a8c4bb1be8d2d171ba81ce0bc76
1 parent
36ef3084
Exists in
master
and in
1 other branch
feat: 优化表格编辑器事件
Showing
2 changed files
with
21 additions
and
14 deletions
Show diff stats
packages/form-item/index.vue
| ... | ... | @@ -62,9 +62,9 @@ export default { |
| 62 | 62 | colProps(props) { |
| 63 | 63 | return props.reduce((result, key) => { |
| 64 | 64 | if (this[key]) { |
| 65 | - result[key] = this[key]; | |
| 65 | + result[key] = Number(this[key]); | |
| 66 | 66 | } else { |
| 67 | - result[key] = this.zForm ? this.zForm[key] : undefined; | |
| 67 | + result[key] = this.zForm ? Number(this.zForm[key]) : undefined; | |
| 68 | 68 | } |
| 69 | 69 | return result; |
| 70 | 70 | }, {}); | ... | ... |
packages/table/editor.vue
| ... | ... | @@ -143,23 +143,30 @@ function editorRender(h, context, item) { |
| 143 | 143 | } else { |
| 144 | 144 | setValue(val); |
| 145 | 145 | } |
| 146 | - if (item.on && item.on.input) { | |
| 147 | - item.on.input(val); | |
| 148 | - } | |
| 149 | - }; | |
| 150 | - const blurEvent = val => { | |
| 151 | - if (item.on && item.on.blur) { | |
| 152 | - item.on.blur(val); | |
| 153 | - } | |
| 154 | 146 | }; |
| 147 | + // 向外提供的值 | |
| 148 | + const editorScope = { item, value, index: scope.$index, ...scope, onInput: inputEvent }; | |
| 155 | 149 | // 编辑表单项配置 |
| 156 | 150 | let itemProps = item.props || {}; |
| 157 | 151 | if (typeof item.props === 'function') { |
| 158 | - itemProps = item.props({ item, value, index: scope.$index, ...scope, onInput: inputEvent }); | |
| 152 | + itemProps = item.props(editorScope); | |
| 159 | 153 | } |
| 160 | 154 | let itemAttrs = item.attrs || {}; |
| 161 | 155 | if (typeof item.attrs === 'function') { |
| 162 | - itemAttrs = item.attrs({ item, value, index: scope.$index, ...scope, onInput: inputEvent }); | |
| 156 | + itemAttrs = item.attrs(editorScope); | |
| 157 | + } | |
| 158 | + let itemOn = item.on || {}; | |
| 159 | + if (typeof item.on === 'function') { | |
| 160 | + itemOn = item.on(editorScope); | |
| 161 | + } | |
| 162 | + if (itemOn.input) { | |
| 163 | + const itemOnInput = itemOn.input; | |
| 164 | + itemOn.input = function(e) { | |
| 165 | + inputEvent(e); | |
| 166 | + itemOnInput(e); | |
| 167 | + }; | |
| 168 | + } else { | |
| 169 | + itemOn.input = inputEvent; | |
| 163 | 170 | } |
| 164 | 171 | // 编辑器统一配置 |
| 165 | 172 | const editorProps = get(contentProps, 'editor') || {}; |
| ... | ... | @@ -167,11 +174,11 @@ function editorRender(h, context, item) { |
| 167 | 174 | vnode = h(item.is, { |
| 168 | 175 | attrs: itemAttrs, |
| 169 | 176 | props: { ...editorProps, ...itemProps, value }, |
| 170 | - on: { input: inputEvent, blur: blurEvent }, | |
| 177 | + on: itemOn, | |
| 171 | 178 | }); |
| 172 | 179 | // 自定义具名插槽 |
| 173 | 180 | if (editorSlot) { |
| 174 | - return editorSlot({ item, value, index: scope.$index, ...scope, onInput: inputEvent }); | |
| 181 | + return editorSlot(editorScope); | |
| 175 | 182 | } |
| 176 | 183 | // 需要校验时外层嵌套校验组件 |
| 177 | 184 | if (editorProps.validate) { | ... | ... |