Commit 8929ee3abf73f2f2a017a6bef33872d13decf7b3
Committed by
小小鲁班
1 parent
4d079cc6
[feat] 添加border-color&修改edit 和 preview 样式统一
Showing
4 changed files
with
43 additions
and
7 deletions
front-end/h5/src/components/core/editor/canvas/preview.js
| ... | ... | @@ -11,12 +11,19 @@ export default { |
| 11 | 11 | methods: { |
| 12 | 12 | renderPreview (h, elements) { |
| 13 | 13 | const pageWrapperStyle = { height: this.height || '100%', position: 'relative' } |
| 14 | + // 与 edit 组件保持样式一致 | |
| 15 | + const data = { | |
| 16 | + style: { | |
| 17 | + width: '100%', | |
| 18 | + height: '100%' | |
| 19 | + } | |
| 20 | + } | |
| 14 | 21 | return ( |
| 15 | 22 | <div style={pageWrapperStyle}> |
| 16 | 23 | { |
| 17 | 24 | elements.map((element, index) => { |
| 18 | 25 | return <node-wrapper element={element}> |
| 19 | - {h(element.name, element.getPreviewData({ position: 'static' }))} | |
| 26 | + {h(element.name, data)} | |
| 20 | 27 | </node-wrapper> |
| 21 | 28 | }) |
| 22 | 29 | } | ... | ... |
front-end/h5/src/components/core/editor/right-panel/box-model/index.vue
| 1 | 1 | <template> |
| 2 | 2 | <div v-if="editingElement" class="box-model"> |
| 3 | - <div v-if="boxModelPart" class="prompt">设置 {{ boxModelPart }} 大小</div> | |
| 4 | - <div v-else>选择 margin/border/padding 设置大小</div> | |
| 3 | + <div v-if="boxModelPart" class="prompt">设置 {{ boxModelPart }}</div> | |
| 4 | + <div v-else>选择 margin/border/padding 进行设置</div> | |
| 5 | + <el-color-picker v-if="isEditingBorder" size="small" :value="borderColor" @change="onColorChange"/> | |
| 5 | 6 | <PositionCheckbox label="上" label-key="top" /> |
| 6 | 7 | <div class="middle"> |
| 7 | 8 | <PositionCheckbox label="左" label-key="left" /> |
| ... | ... | @@ -45,6 +46,12 @@ |
| 45 | 46 | }, |
| 46 | 47 | commonStyle () { |
| 47 | 48 | return this.editingElement ? this.editingElement.commonStyle : {} |
| 49 | + }, | |
| 50 | + borderColor () { | |
| 51 | + return this.commonStyle ? this.commonStyle.border.color.value : '' | |
| 52 | + }, | |
| 53 | + isEditingBorder () { | |
| 54 | + return this.boxModelPart === 'border' | |
| 48 | 55 | } |
| 49 | 56 | }, |
| 50 | 57 | filters: { |
| ... | ... | @@ -73,6 +80,18 @@ |
| 73 | 80 | target.classList.add(selectClass) |
| 74 | 81 | this.lastSelect = type |
| 75 | 82 | } |
| 83 | + }, | |
| 84 | + onColorChange (color) { | |
| 85 | + console.log('color', color) | |
| 86 | + this.changeCommonStyle(color, 'color') | |
| 87 | + }, | |
| 88 | + changeCommonStyle (changeValue, labelKey, key = 'value') { | |
| 89 | + const boxModelPart = this.boxModelPart | |
| 90 | + // 例如 boxModelPart 为 margin 时候 | |
| 91 | + const boxModelPartStyle = this.editingElement.commonStyle[boxModelPart] | |
| 92 | + // 更新值例如: padding-top | |
| 93 | + Object.assign(boxModelPartStyle[labelKey], { [key]: changeValue }) | |
| 94 | + this.setElementPosition({ [boxModelPart]: boxModelPartStyle }) | |
| 76 | 95 | } |
| 77 | 96 | }, |
| 78 | 97 | watch: { | ... | ... |
front-end/h5/src/components/core/editor/right-panel/box-model/position-checkbox.vue
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | </template> |
| 12 | 12 | <template v-if="boxModelPart && isChecked"> |
| 13 | 13 | <a-input-number style="width:70px" :value="value" :min="0" @change="onInputNumberChange" /> |
| 14 | - <a-select :default-value="unitList[0]" style="width:70px"> | |
| 14 | + <a-select :value="unit" style="width:70px" @change="onUnitChange"> | |
| 15 | 15 | <a-select-option v-for="(item,index) in unitList" :key="index" :value="item"> |
| 16 | 16 | {{ item }} |
| 17 | 17 | </a-select-option> |
| ... | ... | @@ -50,6 +50,10 @@ |
| 50 | 50 | const { editingElement, labelKey, boxModelPart } = this |
| 51 | 51 | return this.boxModelPart ? editingElement.commonStyle[boxModelPart][labelKey].value : '' |
| 52 | 52 | }, |
| 53 | + unit () { | |
| 54 | + const { editingElement, labelKey, boxModelPart } = this | |
| 55 | + return this.boxModelPart ? editingElement.commonStyle[boxModelPart][labelKey].unit : '' | |
| 56 | + }, | |
| 53 | 57 | unitList () { |
| 54 | 58 | return this.boxModelPart === 'border' ? ['px', 'em'] : ['px', '%', 'em'] |
| 55 | 59 | } |
| ... | ... | @@ -58,16 +62,22 @@ |
| 58 | 62 | ...mapActions('editor', [ |
| 59 | 63 | 'setElementPosition' |
| 60 | 64 | ]), |
| 65 | + onUnitChange (unit) { | |
| 66 | + this.changeCommonStyle(unit, 'unit') | |
| 67 | + }, | |
| 61 | 68 | onCheckboxChange (e) { |
| 62 | 69 | console.log(e) |
| 63 | 70 | this.isChecked = e.target.checked |
| 64 | 71 | }, |
| 65 | 72 | onInputNumberChange (value) { |
| 66 | - const boxModelPart = this.boxModelPart | |
| 73 | + this.changeCommonStyle(value) | |
| 74 | + }, | |
| 75 | + changeCommonStyle (changeValue, key = 'value') { | |
| 76 | + const boxModelPart = this.boxModelPart | |
| 67 | 77 | // 例如 boxModelPart 为 margin 时候 |
| 68 | 78 | const boxModelPartStyle = this.editingElement.commonStyle[boxModelPart] |
| 69 | 79 | // 更新值例如: padding-top |
| 70 | - Object.assign(boxModelPartStyle[this.labelKey], { value }) | |
| 80 | + Object.assign(boxModelPartStyle[this.labelKey], { [key]: changeValue }) | |
| 71 | 81 | this.setElementPosition({ [boxModelPart]: boxModelPartStyle }) |
| 72 | 82 | } |
| 73 | 83 | }, | ... | ... |
front-end/h5/src/components/core/models/element.js
| ... | ... | @@ -151,7 +151,7 @@ class Element { |
| 151 | 151 | * 使用 border-left border-right 等方式,在 chrome 浏览器中会导致渲染问题 |
| 152 | 152 | * 这里就将他拼接成完整的 border-width解决bug,不知道是什么原因 |
| 153 | 153 | */ |
| 154 | - 'border-width': `${top.value}px ${right.value}px ${bottom.value}px ${left.value}px `, | |
| 154 | + 'border-width': `${top.value}${top.unit} ${right.value}${right.unit} ${bottom.value}${bottom.unit} ${left.value}${left.unit} `, | |
| 155 | 155 | 'border-style': style.value, |
| 156 | 156 | 'border-color': color.value |
| 157 | 157 | } | ... | ... |