Commit a81a9fb670db6c5584debd2db04a6cd12df728a3
Committed by
小小鲁班
1 parent
b4ad6c18
[feature] 盒模型展示区域绘制
Showing
3 changed files
with
159 additions
and
0 deletions
front-end/h5/src/components/core/editor/right-panel/box-model/index.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="box-model"> | ||
| 3 | + <div v-if="lastSelect" class="prompt">设置 {{ lastSelect }} 大小</div> | ||
| 4 | + <div v-else>选择 margin/border/padding 设置大小</div> | ||
| 5 | + <PositionCheckbox label="上" /> | ||
| 6 | + <div class="middle"> | ||
| 7 | + <PositionCheckbox label="左" /> | ||
| 8 | + <div ref="margin" class="margin" data-type="margin" @click="onBoxModelClick"> | ||
| 9 | + margin | ||
| 10 | + <div ref="border" class="border" data-type="border"> | ||
| 11 | + border | ||
| 12 | + <div ref="padding" class="padding" data-type="padding"> | ||
| 13 | + padding | ||
| 14 | + </div> | ||
| 15 | + </div> | ||
| 16 | + </div> | ||
| 17 | + <PositionCheckbox label="右" /> | ||
| 18 | + </div> | ||
| 19 | + <PositionCheckbox label="下" /> | ||
| 20 | + </div> | ||
| 21 | +</template> | ||
| 22 | + | ||
| 23 | +<script> | ||
| 24 | + import PositionCheckbox from './position-checkbox' | ||
| 25 | + export default { | ||
| 26 | + name: 'BoxModel', | ||
| 27 | + components: { | ||
| 28 | + PositionCheckbox | ||
| 29 | + }, | ||
| 30 | + data () { | ||
| 31 | + return { | ||
| 32 | + lastSelect: '' | ||
| 33 | + } | ||
| 34 | + }, | ||
| 35 | + | ||
| 36 | + methods: { | ||
| 37 | + onBoxModelClick (e) { | ||
| 38 | + const target = e.target | ||
| 39 | + const classList = target.classList | ||
| 40 | + const type = target.dataset.type | ||
| 41 | + const selectClass = type + '-select' | ||
| 42 | + | ||
| 43 | + if (this.lastSelect && type !== this.lastSelect) { | ||
| 44 | + this.$refs[this.lastSelect].classList.remove(this.lastSelect + '-select') | ||
| 45 | + } | ||
| 46 | + // 选中的元素添加上选中的 className | ||
| 47 | + if (!classList.contains(selectClass)) { | ||
| 48 | + target.classList.add(selectClass) | ||
| 49 | + this.lastSelect = type | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | +</script> | ||
| 55 | + | ||
| 56 | +<style lang='less' scoped> | ||
| 57 | +.inline-block{ | ||
| 58 | + display:inline-block; | ||
| 59 | + text-align: center; | ||
| 60 | +} | ||
| 61 | +.common{ | ||
| 62 | + .inline-block(); | ||
| 63 | + background-color:rgb(15, 14, 14); | ||
| 64 | + &-select{ | ||
| 65 | + background-color: rgb(170, 170, 95); | ||
| 66 | + } | ||
| 67 | +} | ||
| 68 | +.box-model{ | ||
| 69 | +} | ||
| 70 | +.middle{ | ||
| 71 | + margin:20px 0; | ||
| 72 | + display: flex; | ||
| 73 | + align-items: center; | ||
| 74 | +} | ||
| 75 | +.margin{ | ||
| 76 | + width:150px; | ||
| 77 | + height: 110px; | ||
| 78 | + border:1px dashed #fff; | ||
| 79 | + color: #fff; | ||
| 80 | + font-size:12px; | ||
| 81 | + flex-shrink: 0; | ||
| 82 | + .common() | ||
| 83 | +} | ||
| 84 | +.border{ | ||
| 85 | + width:120px; | ||
| 86 | + height: 80px; | ||
| 87 | + border:1px solid #fff; | ||
| 88 | + .common() | ||
| 89 | +} | ||
| 90 | +.padding{ | ||
| 91 | + border:1px dashed #fff; | ||
| 92 | + width:90px; | ||
| 93 | + height: 50px; | ||
| 94 | + .common() | ||
| 95 | +} | ||
| 96 | +</style> |
front-end/h5/src/components/core/editor/right-panel/box-model/position-checkbox.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="position-checkbox"> | ||
| 3 | + <div class="flex"> | ||
| 4 | + <a-checkbox @change="onCheckboxChange"> | ||
| 5 | + </a-checkbox> | ||
| 6 | + <div class="label">{{label}}</div> | ||
| 7 | + </div> | ||
| 8 | + <a-input-number style="width:70px" v-model="value" :min="0" @change="onInputNumberChange" /> | ||
| 9 | + <a-select default-value="px" style="width:70px"> | ||
| 10 | + <a-select-option value="px"> | ||
| 11 | + px | ||
| 12 | + </a-select-option> | ||
| 13 | + <a-select-option value="%"> | ||
| 14 | + % | ||
| 15 | + </a-select-option> | ||
| 16 | + <a-select-option value="em"> | ||
| 17 | + em | ||
| 18 | + </a-select-option> | ||
| 19 | + </a-select> | ||
| 20 | + </div> | ||
| 21 | +</template> | ||
| 22 | + | ||
| 23 | +<script> | ||
| 24 | + export default { | ||
| 25 | + name: 'PositionCheckbox', | ||
| 26 | + props: { | ||
| 27 | + label: { | ||
| 28 | + type: String, | ||
| 29 | + default: '' | ||
| 30 | + } | ||
| 31 | + }, | ||
| 32 | + data () { | ||
| 33 | + return { | ||
| 34 | + value: 1 | ||
| 35 | + } | ||
| 36 | + }, | ||
| 37 | + | ||
| 38 | + methods: { | ||
| 39 | + onCheckboxChange () {}, | ||
| 40 | + onInputNumberChange () {} | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | +</script> | ||
| 44 | + | ||
| 45 | +<style lang='less' scoped> | ||
| 46 | +.flex{ | ||
| 47 | + display: flex; | ||
| 48 | + align-items: center; | ||
| 49 | +} | ||
| 50 | +.position-checkbox{ | ||
| 51 | + display: flex; | ||
| 52 | + justify-content: center; | ||
| 53 | + flex-wrap: wrap; | ||
| 54 | +} | ||
| 55 | +.label{ | ||
| 56 | + margin:0 10px; | ||
| 57 | +} | ||
| 58 | +</style> |
front-end/h5/src/components/core/editor/right-panel/props.js
| 1 | import Vue from 'vue' | 1 | import Vue from 'vue' |
| 2 | import { mapState, mapActions } from 'vuex' | 2 | import { mapState, mapActions } from 'vuex' |
| 3 | +import BoxModel from './box-model' | ||
| 3 | import { getVM, getComponentsForPropsEditor } from '@/utils/element' | 4 | import { getVM, getComponentsForPropsEditor } from '@/utils/element' |
| 4 | import 'core/styles/props-config-panel.scss' | 5 | import 'core/styles/props-config-panel.scss' |
| 5 | 6 | ||
| 6 | export default { | 7 | export default { |
| 7 | name: 'RightPanelProps', | 8 | name: 'RightPanelProps', |
| 9 | + components: { | ||
| 10 | + BoxModel | ||
| 11 | + }, | ||
| 8 | data: () => ({ | 12 | data: () => ({ |
| 9 | loadCustomEditorFlag: false, | 13 | loadCustomEditorFlag: false, |
| 10 | editorPositionConfig: [ | 14 | editorPositionConfig: [ |
| @@ -176,6 +180,7 @@ export default { | @@ -176,6 +180,7 @@ export default { | ||
| 176 | class="props-config-form" | 180 | class="props-config-form" |
| 177 | layout={this.layout} | 181 | layout={this.layout} |
| 178 | > | 182 | > |
| 183 | + <BoxModel></BoxModel> | ||
| 179 | {/* 只有在选中编辑组件的时候显示 */} | 184 | {/* 只有在选中编辑组件的时候显示 */} |
| 180 | { | 185 | { |
| 181 | this.stateEditingElement ? this.renderEditorPositionConfig(h) : '' | 186 | this.stateEditingElement ? this.renderEditorPositionConfig(h) : '' |