Commit c624fb9877cf0a8c4bb1be8d2d171ba81ce0bc76

Authored by liuhanchen
1 parent 36ef3084

feat: 优化表格编辑器事件

packages/form-item/index.vue
@@ -62,9 +62,9 @@ export default { @@ -62,9 +62,9 @@ export default {
62 colProps(props) { 62 colProps(props) {
63 return props.reduce((result, key) => { 63 return props.reduce((result, key) => {
64 if (this[key]) { 64 if (this[key]) {
65 - result[key] = this[key]; 65 + result[key] = Number(this[key]);
66 } else { 66 } else {
67 - result[key] = this.zForm ? this.zForm[key] : undefined; 67 + result[key] = this.zForm ? Number(this.zForm[key]) : undefined;
68 } 68 }
69 return result; 69 return result;
70 }, {}); 70 }, {});
packages/table/editor.vue
@@ -143,23 +143,30 @@ function editorRender(h, context, item) { @@ -143,23 +143,30 @@ function editorRender(h, context, item) {
143 } else { 143 } else {
144 setValue(val); 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 let itemProps = item.props || {}; 150 let itemProps = item.props || {};
157 if (typeof item.props === 'function') { 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 let itemAttrs = item.attrs || {}; 154 let itemAttrs = item.attrs || {};
161 if (typeof item.attrs === 'function') { 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 const editorProps = get(contentProps, 'editor') || {}; 172 const editorProps = get(contentProps, 'editor') || {};
@@ -167,11 +174,11 @@ function editorRender(h, context, item) { @@ -167,11 +174,11 @@ function editorRender(h, context, item) {
167 vnode = h(item.is, { 174 vnode = h(item.is, {
168 attrs: itemAttrs, 175 attrs: itemAttrs,
169 props: { ...editorProps, ...itemProps, value }, 176 props: { ...editorProps, ...itemProps, value },
170 - on: { input: inputEvent, blur: blurEvent }, 177 + on: itemOn,
171 }); 178 });
172 // 自定义具名插槽 179 // 自定义具名插槽
173 if (editorSlot) { 180 if (editorSlot) {
174 - return editorSlot({ item, value, index: scope.$index, ...scope, onInput: inputEvent }); 181 + return editorSlot(editorScope);
175 } 182 }
176 // 需要校验时外层嵌套校验组件 183 // 需要校验时外层嵌套校验组件
177 if (editorProps.validate) { 184 if (editorProps.validate) {