Commit 66a2a7409d924b9f11f8ae6807e5db24e2ab5355

Authored by ly525
1 parent ce9774a6

chore: patch for guanwanxiao:syq/box-model

front-end/h5/src/components/core/editor/right-panel/background.js
... ... @@ -27,7 +27,11 @@ export default {
27 27 const bgEle = this.editingPage.elements.find(e => e.name === 'lbp-background')
28 28 return (
29 29 <div>
30   - <RenderWorkMode />
  30 + <a-collapse expand-icon-position="right">
  31 + <a-collapse-panel key="1" header="H5模式">
  32 + <RenderWorkMode />
  33 + </a-collapse-panel>
  34 + </a-collapse>
31 35 <PropsEditPanel
32 36 layout="vertical"
33 37 realEditingElement={bgEle}
... ...
front-end/h5/src/components/core/editor/right-panel/box-model/index.vue
... ... @@ -20,18 +20,19 @@
20 20 <PositionCheckbox label="右" label-key="right" />
21 21 </div>
22 22 <PositionCheckbox label="下" label-key="bottom" />
23   - <template v-if="isEditingBorder">
24   - <div> 设置border-color </div>
  23 + <div v-if="isEditingBorder" style="margin: 20px;">
  24 + <span> 设置border-color </span>
25 25 <el-color-picker size="small" :value="borderColor" @change="onColorChange"/>
26   - </template>
  26 + </div>
27 27 </div>
28 28 </template>
29 29  
30 30 <script>
  31 + // 盒子模型编辑器
31 32 import { mapState, mapActions } from 'vuex'
32 33 import PositionCheckbox from './position-checkbox'
33 34 export default {
34   - name: 'BoxModel',
  35 + name: 'BoxModelEditor',
35 36 components: {
36 37 PositionCheckbox
37 38 },
... ... @@ -79,6 +80,10 @@
79 80 // 取出 commonStyle.border,并更改 border.color.value 的值
80 81 const boxModelPartStyle = this.editingElement.commonStyle[boxModelPart]
81 82 Object.assign(boxModelPartStyle.color, { value: color })
  83 + // TODO 收归style至commonStyle,而非pluginProps
  84 + if (boxModelPart === 'border') {
  85 + this.editingElement.pluginProps.borderColor = color
  86 + }
82 87 this.setElementPosition({ [boxModelPart]: boxModelPartStyle })
83 88 }
84 89 }
... ... @@ -86,21 +91,27 @@
86 91 </script>
87 92  
88 93 <style lang='less' scoped>
  94 +.box-model {
  95 + margin: 8px 0;
  96 + border-top: 1px dashed #eee;
  97 + border-bottom: 1px dashed #eee;
  98 +}
89 99 .inline-block{
90 100 display:inline-block;
91 101 text-align: center;
92 102 }
93 103 .common{
94 104 .inline-block();
95   - background-color:rgb(15, 14, 14);
  105 + background-color:#52527e;
96 106 &-select{
97   - background-color: rgb(170, 170, 95);
  107 + background-color: #fedd9b;
98 108 }
99 109 }
100 110 .middle{
101   - margin:20px 0;
  111 + margin:12px 0;
102 112 display: flex;
103 113 align-items: center;
  114 + justify-content: center;
104 115 }
105 116 .margin{
106 117 width:150px;
... ... @@ -124,6 +135,7 @@
124 135 .common()
125 136 }
126 137 .content{
  138 + border: 1px solid #fff;
127 139 background-color: rgb(82, 82, 126);
128 140 width:80%;
129 141 .inline-block()
... ...
front-end/h5/src/components/core/editor/right-panel/box-model/position-checkbox.vue
... ... @@ -3,15 +3,15 @@
3 3 <!-- 只有选中 padding border margin 之后才会显示 -->
4 4 <template v-if="boxModelPart">
5 5 <div class="flex">
6   - <a-checkbox @change="onCheckboxChange" :checked="isChecked">
  6 + <a-checkbox @change="onCheckboxChange" :checked="isChecked" size="small">
7 7 </a-checkbox>
8 8 <div class="label">{{label}}</div>
9 9 </div>
10 10  
11 11 </template>
12 12 <template v-if="boxModelPart && isChecked">
13   - <a-input-number style="width:70px" :value="value" :min="0" @change="onInputNumberChange" />
14   - <a-select :value="unit" style="width:70px" @change="onUnitChange">
  13 + <a-input-number style="width:70px" :value="value" :min="0" @change="onInputNumberChange" size="small" />
  14 + <a-select :value="unit" style="width:70px" @change="onUnitChange" size="small" >
15 15 <a-select-option v-for="(item,index) in unitList" :key="index" :value="item">
16 16 {{ item }}
17 17 </a-select-option>
... ...
front-end/h5/src/components/core/editor/right-panel/props.js
1 1 import Vue from 'vue'
2 2 import { mapState, mapActions } from 'vuex'
3   -import BoxModel from './box-model'
  3 +import BoxModelEditor from './box-model'
4 4 import { getVM, getComponentsForPropsEditor } from '@/utils/element'
5 5 import 'core/styles/props-config-panel.scss'
6 6  
7 7 export default {
8 8 name: 'RightPanelProps',
9 9 components: {
10   - BoxModel
  10 + BoxModelEditor
11 11 },
12 12 data: () => ({
13 13 loadCustomEditorFlag: false,
14 14 editorPositionConfig: [
15   - { type: 'a-input', label: 'top', key: 'top' },
16   - { type: 'a-input', label: 'left', key: 'left' },
17   - { type: 'a-input', label: 'width', key: 'width' },
18   - { type: 'a-input', label: 'height', key: 'height' }
  15 + { type: 'a-input-number', label: '上', key: 'top' },
  16 + { type: 'a-input-number', label: '左', key: 'left' },
  17 + { type: 'a-input-number', label: '宽', key: 'width' },
  18 + { type: 'a-input-number', label: '高', key: 'height' }
19 19 ]
20 20 }),
21 21 props: {
... ... @@ -129,7 +129,7 @@ export default {
129 129 * 设置当前编辑元素的位置,通过 key 值(width,height,left,top)来控制更新相应的位置
130 130 * 在显示层已经通过 this.stateEditingElement 来控制是否选中编辑组件了
131 131 */
132   - onPositionChange (value, key) {
  132 + onPositionChange (key, value) {
133 133 this.setElementPosition({
134 134 [key]: Number(value)
135 135 })
... ... @@ -140,74 +140,81 @@ export default {
140 140 renderEditorPositionConfig (h) {
141 141 const _this = this
142 142 const commonStyle = this.editingElement.commonStyle
143   - return this.editorPositionConfig.map(item => {
144   - const { type, label, key } = item
145   - const data = {
146   - props: {
147   - placeholder: `请输入${key}`
148   - },
149   - domProps: {
150   - value: commonStyle[key]
151   - },
152   - on: {
153   - change (e) {
154   - let value
155   - switch (type) {
156   - case 'a-input':
157   - value = e.target.value
158   - break
  143 + return <a-form layout="inline">
  144 + {
  145 + this.editorPositionConfig.map(item => {
  146 + const { type, label, key } = item
  147 + console.log(key, commonStyle)
  148 + const data = {
  149 + props: {
  150 + value: commonStyle[key],
  151 + placeholder: `请输入${key}`,
  152 + formatter: value => `${label} ${value}`,
  153 + size: 'small'
  154 + },
  155 + on: {
  156 + change (e) {
  157 + const value = e.target ? e.target.value : e
  158 + _this.onPositionChange(key, value)
  159 + }
159 160 }
160   - _this.onPositionChange(value, key)
161 161 }
162   - }
  162 + return (
  163 + <a-form-item>
  164 + {
  165 + h(type, data)
  166 + }
  167 + </a-form-item>
  168 + )
  169 + })
163 170 }
164   - return (
165   - <a-form-item label={label} label-col={ { span: 6 } } wrapperCol={{ span: 16 }}>
166   - {
167   - h(type, data)
168   - }
169   - </a-form-item>
170   - )
171   - })
  171 + </a-form>
172 172 },
173 173 renderPropsEditorPanel (h, editingElement) {
174 174 const vm = getVM(editingElement.name)
175 175 const props = vm.$options.props
176 176 return (
177   - <a-form
178   - ref="form"
179   - size="mini"
180   - class="props-config-form"
181   - layout={this.layout}
182   - >
183   - {/* left,top,width,height编辑 只有在选中编辑组件的时候显示 */}
  177 + <div>
  178 + <a-collapse bordered={true} expand-icon-position="right">
  179 + <a-collapse-panel key="1" header="通用样式">
  180 + {/* left,top,width,height编辑 只有在选中编辑组件的时候显示 */}
  181 + {
  182 + this.stateEditingElement ? this.renderEditorPositionConfig(h) : ''
  183 + }
  184 + {/* margin、padding编辑 */}
  185 + <BoxModelEditor />
  186 + </a-collapse-panel>
  187 + </a-collapse>
  188 + <a-form
  189 + ref="form"
  190 + size="mini"
  191 + class="props-config-form"
  192 + layout={this.layout}
  193 + >
  194 +
184 195 {
185   - this.stateEditingElement ? this.renderEditorPositionConfig(h) : ''
186   - }
187   - {/* margin、padding编辑 */}
188   - <BoxModel />
189   - {
190   - // plugin-custom-editor
191   - this.loadCustomEditorFlag &&
192   - h(this.customEditorName, {
193   - props: {
194   - elementProps: editingElement.pluginProps
195   - }
196   - })
197   - }
198   - {
199   - Object
200   - .entries(props)
201   - .filter(([propKey, propConfig]) => {
202   - // 1. 如果开发者给 某个prop 显式指定了 visible 属性,则取开发者指定的值;
203   - // 2. 否则取默认值:true,即默认在属性面板显示该属性
204   - // 3. 组件的某些属性是不需要显示在 配置编辑器的,比如:editorMode(编辑模式/预览模式),因为这个是鲁班编辑器默认注入到每个组件的,无须显示出来
205   - const isVisible = propConfig.hasOwnProperty('visible') ? propConfig.visible : true
206   - return isVisible && propConfig.editor && !propConfig.editor.custom
  196 + // plugin-custom-editor
  197 + this.loadCustomEditorFlag &&
  198 + h(this.customEditorName, {
  199 + props: {
  200 + elementProps: editingElement.pluginProps
  201 + }
207 202 })
208   - .map(([propKey, propConfig]) => this.renderPropFormItem(h, { propKey, propConfig }))
209   - }
210   - </a-form>
  203 + }
  204 + {
  205 + Object
  206 + .entries(props)
  207 + .filter(([propKey, propConfig]) => {
  208 + // 1. 如果开发者给 某个prop 显式指定了 visible 属性,则取开发者指定的值;
  209 + // 2. 否则取默认值:true,即默认在属性面板显示该属性
  210 + // 3. 组件的某些属性是不需要显示在 配置编辑器的,比如:editorMode(编辑模式/预览模式),因为这个是鲁班编辑器默认注入到每个组件的,无须显示出来
  211 + const isVisible = propConfig.hasOwnProperty('visible') ? propConfig.visible : true
  212 + return isVisible && propConfig.editor && !propConfig.editor.custom
  213 + })
  214 + .map(([propKey, propConfig]) => this.renderPropFormItem(h, { propKey, propConfig }))
  215 + }
  216 + </a-form>
  217 + </div>
211 218 )
212 219 },
213 220 renderWorkGlobalPropsPanel (h) {
... ...
front-end/h5/src/components/core/models/element.js
... ... @@ -101,7 +101,7 @@ class Element {
101 101  
102 102 getCommonStyle (ele) {
103 103 if (typeof ele.commonStyle === 'object') {
104   - return cloneObj(ele.commonStyle)
  104 + return cloneObj({ ...defaultStyle, ...ele.commonStyle })
105 105 }
106 106 return {
107 107 ...defaultStyle,
... ... @@ -167,7 +167,11 @@ class Element {
167 167 const commonStyle = this.commonStyle
168 168 const { margin, padding } = commonStyle
169 169 // 由于在 defaultStyle 定义的时候是对象,这里需要将数据重新组装成 margin-top 这种形式
170   - const boxModel = { ...this.packPosData(margin, 'margin'), ...this.packPosData(padding, 'padding'), ...this.packBorderData() }
  170 + const boxModel = {
  171 + ...this.packPosData(margin, 'margin'),
  172 + ...this.packPosData(padding, 'padding'),
  173 + ...this.packBorderData()
  174 + }
171 175 let style = {
172 176 top: parsePx(pluginProps.top || commonStyle.top, isRem),
173 177 left: parsePx(pluginProps.left || commonStyle.left, isRem),
... ...