Commit b14a1ade7b54d415fc4cd9a25f9b0c1b46d5355f
Committed by
小小鲁班
1 parent
8ca8770f
[feature] 添加组件的 top、left、width、height 编辑
Showing
1 changed file
with
58 additions
and
3 deletions
front-end/h5/src/components/core/editor/right-panel/props.js
| @@ -4,8 +4,15 @@ import { getVM, getComponentsForPropsEditor } from '@/utils/element' | @@ -4,8 +4,15 @@ import { getVM, getComponentsForPropsEditor } from '@/utils/element' | ||
| 4 | import 'core/styles/props-config-panel.scss' | 4 | import 'core/styles/props-config-panel.scss' |
| 5 | 5 | ||
| 6 | export default { | 6 | export default { |
| 7 | + name: 'RightPanelProps', | ||
| 7 | data: () => ({ | 8 | data: () => ({ |
| 8 | - loadCustomEditorFlag: false | 9 | + loadCustomEditorFlag: false, |
| 10 | + editorPositionConfig: [ | ||
| 11 | + { type: 'a-input', label: 'top', key: 'top' }, | ||
| 12 | + { type: 'a-input', label: 'left', key: 'left' }, | ||
| 13 | + { type: 'a-input', label: 'width', key: 'width' }, | ||
| 14 | + { type: 'a-input', label: 'height', key: 'height' } | ||
| 15 | + ] | ||
| 9 | }), | 16 | }), |
| 10 | props: { | 17 | props: { |
| 11 | layout: { | 18 | layout: { |
| @@ -31,7 +38,7 @@ export default { | @@ -31,7 +38,7 @@ export default { | ||
| 31 | }, | 38 | }, |
| 32 | methods: { | 39 | methods: { |
| 33 | ...mapActions('editor', [ | 40 | ...mapActions('editor', [ |
| 34 | - 'setEditingElement' | 41 | + 'setEditingElement', 'setElementPosition' |
| 35 | ]), | 42 | ]), |
| 36 | loadCustomEditorForPlugin () { | 43 | loadCustomEditorForPlugin () { |
| 37 | this.loadCustomEditorFlag = false | 44 | this.loadCustomEditorFlag = false |
| @@ -114,10 +121,54 @@ export default { | @@ -114,10 +121,54 @@ export default { | ||
| 114 | </a-form-item> | 121 | </a-form-item> |
| 115 | ) | 122 | ) |
| 116 | }, | 123 | }, |
| 124 | + /** | ||
| 125 | + * 设置当前编辑元素的位置,通过 key 值(width,height,left,top)来控制更新相应的位置 | ||
| 126 | + * 在显示层已经通过 this.stateEditingElement 来控制是否选中编辑组件了 | ||
| 127 | + */ | ||
| 128 | + onPositionChange (value, key) { | ||
| 129 | + this.setElementPosition({ | ||
| 130 | + [key]: value | ||
| 131 | + }) | ||
| 132 | + }, | ||
| 133 | + /** | ||
| 134 | + * 渲染编辑组件的位置 | ||
| 135 | + */ | ||
| 136 | + renderEditorPositionConfig (h) { | ||
| 137 | + const _this = this | ||
| 138 | + const commonStyle = this.editingElement.commonStyle | ||
| 139 | + return this.editorPositionConfig.map(item => { | ||
| 140 | + const { type, label, key } = item | ||
| 141 | + const data = { | ||
| 142 | + props: { | ||
| 143 | + placeholder: `请输入${key},支持 %单位` | ||
| 144 | + }, | ||
| 145 | + domProps: { | ||
| 146 | + value: commonStyle[key] | ||
| 147 | + }, | ||
| 148 | + on: { | ||
| 149 | + change (e) { | ||
| 150 | + let value | ||
| 151 | + switch (type) { | ||
| 152 | + case 'a-input': | ||
| 153 | + value = e.target.value | ||
| 154 | + break | ||
| 155 | + } | ||
| 156 | + _this.onPositionChange(value, key) | ||
| 157 | + } | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + return ( | ||
| 161 | + <a-form-item label={label} label-col={ { span: 6 } } wrapperCol={{ span: 16 }}> | ||
| 162 | + { | ||
| 163 | + h(type, data) | ||
| 164 | + } | ||
| 165 | + </a-form-item> | ||
| 166 | + ) | ||
| 167 | + }) | ||
| 168 | + }, | ||
| 117 | renderPropsEditorPanel (h, editingElement) { | 169 | renderPropsEditorPanel (h, editingElement) { |
| 118 | const vm = getVM(editingElement.name) | 170 | const vm = getVM(editingElement.name) |
| 119 | const props = vm.$options.props | 171 | const props = vm.$options.props |
| 120 | - | ||
| 121 | return ( | 172 | return ( |
| 122 | <a-form | 173 | <a-form |
| 123 | ref="form" | 174 | ref="form" |
| @@ -125,6 +176,10 @@ export default { | @@ -125,6 +176,10 @@ export default { | ||
| 125 | class="props-config-form" | 176 | class="props-config-form" |
| 126 | layout={this.layout} | 177 | layout={this.layout} |
| 127 | > | 178 | > |
| 179 | + {/* 只有在选中编辑组件的时候显示 */} | ||
| 180 | + { | ||
| 181 | + this.stateEditingElement ? this.renderEditorPositionConfig(h) : '' | ||
| 182 | + } | ||
| 128 | { | 183 | { |
| 129 | // plugin-custom-editor | 184 | // plugin-custom-editor |
| 130 | this.loadCustomEditorFlag && | 185 | this.loadCustomEditorFlag && |