Commit 8b45dfe6faaa3782de2651b1fe45f6aedaac8647

Authored by 宋远桥
1 parent 877eb4b1

[feature] 添加组件的 top、left、width、height 编辑

front-end/h5/src/components/core/editor/right-panel/props.js
... ... @@ -4,8 +4,15 @@ import { getVM, getComponentsForPropsEditor } from '@/utils/element'
4 4 import 'core/styles/props-config-panel.scss'
5 5  
6 6 export default {
  7 + name: 'RightPanelProps',
7 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 17 props: {
11 18 layout: {
... ... @@ -31,7 +38,7 @@ export default {
31 38 },
32 39 methods: {
33 40 ...mapActions('editor', [
34   - 'setEditingElement'
  41 + 'setEditingElement', 'setElementPosition'
35 42 ]),
36 43 loadCustomEditorForPlugin () {
37 44 this.loadCustomEditorFlag = false
... ... @@ -114,10 +121,54 @@ export default {
114 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 169 renderPropsEditorPanel (h, editingElement) {
118 170 const vm = getVM(editingElement.name)
119 171 const props = vm.$options.props
120   -
121 172 return (
122 173 <a-form
123 174 ref="form"
... ... @@ -125,6 +176,10 @@ export default {
125 176 class="props-config-form"
126 177 layout={this.layout}
127 178 >
  179 + {/* 只有在选中编辑组件的时候显示 */}
  180 + {
  181 + this.stateEditingElement ? this.renderEditorPositionConfig(h) : ''
  182 + }
128 183 {
129 184 // plugin-custom-editor
130 185 this.loadCustomEditorFlag &&
... ...