Commit ac2df5ab46fd66e8b5892dcfba2f7ca65f15e1a7
1 parent
0e4d1aee
[feature] 在盒模型中显示宽高
Showing
3 changed files
with
62 additions
and
7 deletions
front-end/h5/src/components/core/editor/right-panel/box-model/index.vue
| 1 | <template> | 1 | <template> |
| 2 | <div v-if="editingElement" class="box-model"> | 2 | <div v-if="editingElement" class="box-model"> |
| 3 | - <div v-if="lastSelect" class="prompt">设置 {{ lastSelect }} 大小</div> | 3 | + <div v-if="boxModelPart" class="prompt">设置 {{ boxModelPart }} 大小</div> |
| 4 | <div v-else>选择 margin/border/padding 设置大小</div> | 4 | <div v-else>选择 margin/border/padding 设置大小</div> |
| 5 | <PositionCheckbox label="上" label-key="top" /> | 5 | <PositionCheckbox label="上" label-key="top" /> |
| 6 | <div class="middle"> | 6 | <div class="middle"> |
| @@ -11,6 +11,9 @@ | @@ -11,6 +11,9 @@ | ||
| 11 | border | 11 | border |
| 12 | <div ref="padding" class="padding" data-type="padding"> | 12 | <div ref="padding" class="padding" data-type="padding"> |
| 13 | padding | 13 | padding |
| 14 | + <div class="content" data-type="padding"> | ||
| 15 | + {{ commonStyle.width | digit }} x {{ commonStyle.height | digit }} | ||
| 16 | + </div> | ||
| 14 | </div> | 17 | </div> |
| 15 | </div> | 18 | </div> |
| 16 | </div> | 19 | </div> |
| @@ -36,7 +39,18 @@ | @@ -36,7 +39,18 @@ | ||
| 36 | computed: { | 39 | computed: { |
| 37 | ...mapState('editor', { | 40 | ...mapState('editor', { |
| 38 | editingElement: state => state.editingElement | 41 | editingElement: state => state.editingElement |
| 39 | - }) | 42 | + }), |
| 43 | + boxModelPart () { | ||
| 44 | + return this.editingElement && this.editingElement.commonStyle.boxModelPart | ||
| 45 | + }, | ||
| 46 | + commonStyle () { | ||
| 47 | + return this.editingElement ? this.editingElement.commonStyle : {} | ||
| 48 | + } | ||
| 49 | + }, | ||
| 50 | + filters: { | ||
| 51 | + digit (val) { | ||
| 52 | + return val.toFixed(0) | ||
| 53 | + } | ||
| 40 | }, | 54 | }, |
| 41 | methods: { | 55 | methods: { |
| 42 | ...mapActions('editor', [ | 56 | ...mapActions('editor', [ |
| @@ -60,6 +74,23 @@ | @@ -60,6 +74,23 @@ | ||
| 60 | this.lastSelect = type | 74 | this.lastSelect = type |
| 61 | } | 75 | } |
| 62 | } | 76 | } |
| 77 | + }, | ||
| 78 | + watch: { | ||
| 79 | + /** | ||
| 80 | + * 监听当前是否有选中的组件,如果有判断之前是否保存了 boxModelPart | ||
| 81 | + * 如果保存了就将之前编辑状态重新复原。 | ||
| 82 | + */ | ||
| 83 | + editingElement: { | ||
| 84 | + immediate: true, | ||
| 85 | + handler (val) { | ||
| 86 | + if (!this.boxModelPart) return | ||
| 87 | + const selectClass = this.boxModelPart + '-select' | ||
| 88 | + this.$nextTick(() => { | ||
| 89 | + this.$refs[this.boxModelPart].classList.add(selectClass) | ||
| 90 | + this.lastSelect = this.boxModelPart | ||
| 91 | + }) | ||
| 92 | + } | ||
| 93 | + } | ||
| 63 | } | 94 | } |
| 64 | } | 95 | } |
| 65 | </script> | 96 | </script> |
| @@ -76,8 +107,6 @@ | @@ -76,8 +107,6 @@ | ||
| 76 | background-color: rgb(170, 170, 95); | 107 | background-color: rgb(170, 170, 95); |
| 77 | } | 108 | } |
| 78 | } | 109 | } |
| 79 | -.box-model{ | ||
| 80 | -} | ||
| 81 | .middle{ | 110 | .middle{ |
| 82 | margin:20px 0; | 111 | margin:20px 0; |
| 83 | display: flex; | 112 | display: flex; |
| @@ -104,4 +133,9 @@ | @@ -104,4 +133,9 @@ | ||
| 104 | height: 50px; | 133 | height: 50px; |
| 105 | .common() | 134 | .common() |
| 106 | } | 135 | } |
| 136 | +.content{ | ||
| 137 | + background-color: rgb(82, 82, 126); | ||
| 138 | + width:80%; | ||
| 139 | + .inline-block() | ||
| 140 | +} | ||
| 107 | </style> | 141 | </style> |
front-end/h5/src/components/core/editor/right-panel/box-model/position-checkbox.vue
| @@ -3,10 +3,13 @@ | @@ -3,10 +3,13 @@ | ||
| 3 | <!-- 只有选中 padding border margin 之后才会显示 --> | 3 | <!-- 只有选中 padding border margin 之后才会显示 --> |
| 4 | <template v-if="boxModelPart"> | 4 | <template v-if="boxModelPart"> |
| 5 | <div class="flex"> | 5 | <div class="flex"> |
| 6 | - <a-checkbox @change="onCheckboxChange"> | 6 | + <a-checkbox @change="onCheckboxChange" :checked="isChecked"> |
| 7 | </a-checkbox> | 7 | </a-checkbox> |
| 8 | <div class="label">{{label}}</div> | 8 | <div class="label">{{label}}</div> |
| 9 | </div> | 9 | </div> |
| 10 | + | ||
| 11 | + </template> | ||
| 12 | + <template v-if="boxModelPart && isChecked"> | ||
| 10 | <a-input-number style="width:70px" :value="value" :min="0" @change="onInputNumberChange" /> | 13 | <a-input-number style="width:70px" :value="value" :min="0" @change="onInputNumberChange" /> |
| 11 | <a-select :default-value="unitList[0]" style="width:70px"> | 14 | <a-select :default-value="unitList[0]" style="width:70px"> |
| 12 | <a-select-option v-for="(item,index) in unitList" :key="index" :value="item"> | 15 | <a-select-option v-for="(item,index) in unitList" :key="index" :value="item"> |
| @@ -31,6 +34,11 @@ | @@ -31,6 +34,11 @@ | ||
| 31 | default: '' | 34 | default: '' |
| 32 | } | 35 | } |
| 33 | }, | 36 | }, |
| 37 | + data () { | ||
| 38 | + return { | ||
| 39 | + isChecked: false | ||
| 40 | + } | ||
| 41 | + }, | ||
| 34 | computed: { | 42 | computed: { |
| 35 | ...mapState('editor', { | 43 | ...mapState('editor', { |
| 36 | editingElement: state => state.editingElement | 44 | editingElement: state => state.editingElement |
| @@ -51,6 +59,8 @@ | @@ -51,6 +59,8 @@ | ||
| 51 | 'setElementPosition' | 59 | 'setElementPosition' |
| 52 | ]), | 60 | ]), |
| 53 | onCheckboxChange (e) { | 61 | onCheckboxChange (e) { |
| 62 | + console.log(e) | ||
| 63 | + this.isChecked = e.target.checked | ||
| 54 | }, | 64 | }, |
| 55 | onInputNumberChange (value) { | 65 | onInputNumberChange (value) { |
| 56 | const boxModelPart = this.boxModelPart | 66 | const boxModelPart = this.boxModelPart |
| @@ -60,6 +70,16 @@ | @@ -60,6 +70,16 @@ | ||
| 60 | Object.assign(boxModelPartStyle[this.labelKey], { value }) | 70 | Object.assign(boxModelPartStyle[this.labelKey], { value }) |
| 61 | this.setElementPosition({ [boxModelPart]: boxModelPartStyle }) | 71 | this.setElementPosition({ [boxModelPart]: boxModelPartStyle }) |
| 62 | } | 72 | } |
| 73 | + }, | ||
| 74 | + watch: { | ||
| 75 | + value: { | ||
| 76 | + immediate: true, | ||
| 77 | + handler (val) { | ||
| 78 | + if (val) { | ||
| 79 | + this.isChecked = true | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + } | ||
| 63 | } | 83 | } |
| 64 | } | 84 | } |
| 65 | </script> | 85 | </script> |
front-end/h5/src/components/core/editor/right-panel/props.js
| @@ -180,11 +180,12 @@ export default { | @@ -180,11 +180,12 @@ export default { | ||
| 180 | class="props-config-form" | 180 | class="props-config-form" |
| 181 | layout={this.layout} | 181 | layout={this.layout} |
| 182 | > | 182 | > |
| 183 | - <BoxModel></BoxModel> | ||
| 184 | - {/* 只有在选中编辑组件的时候显示 */} | 183 | + {/* left,top,width,height编辑 只有在选中编辑组件的时候显示 */} |
| 185 | { | 184 | { |
| 186 | this.stateEditingElement ? this.renderEditorPositionConfig(h) : '' | 185 | this.stateEditingElement ? this.renderEditorPositionConfig(h) : '' |
| 187 | } | 186 | } |
| 187 | + {/* margin、padding编辑 */} | ||
| 188 | + <BoxModel /> | ||
| 188 | { | 189 | { |
| 189 | // plugin-custom-editor | 190 | // plugin-custom-editor |
| 190 | this.loadCustomEditorFlag && | 191 | this.loadCustomEditorFlag && |