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 | 1 | <template> |
| 2 | 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 | 4 | <div v-else>选择 margin/border/padding 设置大小</div> |
| 5 | 5 | <PositionCheckbox label="上" label-key="top" /> |
| 6 | 6 | <div class="middle"> |
| ... | ... | @@ -11,6 +11,9 @@ |
| 11 | 11 | border |
| 12 | 12 | <div ref="padding" class="padding" data-type="padding"> |
| 13 | 13 | padding |
| 14 | + <div class="content" data-type="padding"> | |
| 15 | + {{ commonStyle.width | digit }} x {{ commonStyle.height | digit }} | |
| 16 | + </div> | |
| 14 | 17 | </div> |
| 15 | 18 | </div> |
| 16 | 19 | </div> |
| ... | ... | @@ -36,7 +39,18 @@ |
| 36 | 39 | computed: { |
| 37 | 40 | ...mapState('editor', { |
| 38 | 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 | 55 | methods: { |
| 42 | 56 | ...mapActions('editor', [ |
| ... | ... | @@ -60,6 +74,23 @@ |
| 60 | 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 | 96 | </script> |
| ... | ... | @@ -76,8 +107,6 @@ |
| 76 | 107 | background-color: rgb(170, 170, 95); |
| 77 | 108 | } |
| 78 | 109 | } |
| 79 | -.box-model{ | |
| 80 | -} | |
| 81 | 110 | .middle{ |
| 82 | 111 | margin:20px 0; |
| 83 | 112 | display: flex; |
| ... | ... | @@ -104,4 +133,9 @@ |
| 104 | 133 | height: 50px; |
| 105 | 134 | .common() |
| 106 | 135 | } |
| 136 | +.content{ | |
| 137 | + background-color: rgb(82, 82, 126); | |
| 138 | + width:80%; | |
| 139 | + .inline-block() | |
| 140 | +} | |
| 107 | 141 | </style> | ... | ... |
front-end/h5/src/components/core/editor/right-panel/box-model/position-checkbox.vue
| ... | ... | @@ -3,10 +3,13 @@ |
| 3 | 3 | <!-- 只有选中 padding border margin 之后才会显示 --> |
| 4 | 4 | <template v-if="boxModelPart"> |
| 5 | 5 | <div class="flex"> |
| 6 | - <a-checkbox @change="onCheckboxChange"> | |
| 6 | + <a-checkbox @change="onCheckboxChange" :checked="isChecked"> | |
| 7 | 7 | </a-checkbox> |
| 8 | 8 | <div class="label">{{label}}</div> |
| 9 | 9 | </div> |
| 10 | + | |
| 11 | + </template> | |
| 12 | + <template v-if="boxModelPart && isChecked"> | |
| 10 | 13 | <a-input-number style="width:70px" :value="value" :min="0" @change="onInputNumberChange" /> |
| 11 | 14 | <a-select :default-value="unitList[0]" style="width:70px"> |
| 12 | 15 | <a-select-option v-for="(item,index) in unitList" :key="index" :value="item"> |
| ... | ... | @@ -31,6 +34,11 @@ |
| 31 | 34 | default: '' |
| 32 | 35 | } |
| 33 | 36 | }, |
| 37 | + data () { | |
| 38 | + return { | |
| 39 | + isChecked: false | |
| 40 | + } | |
| 41 | + }, | |
| 34 | 42 | computed: { |
| 35 | 43 | ...mapState('editor', { |
| 36 | 44 | editingElement: state => state.editingElement |
| ... | ... | @@ -51,6 +59,8 @@ |
| 51 | 59 | 'setElementPosition' |
| 52 | 60 | ]), |
| 53 | 61 | onCheckboxChange (e) { |
| 62 | + console.log(e) | |
| 63 | + this.isChecked = e.target.checked | |
| 54 | 64 | }, |
| 55 | 65 | onInputNumberChange (value) { |
| 56 | 66 | const boxModelPart = this.boxModelPart |
| ... | ... | @@ -60,6 +70,16 @@ |
| 60 | 70 | Object.assign(boxModelPartStyle[this.labelKey], { value }) |
| 61 | 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 | 85 | </script> | ... | ... |
front-end/h5/src/components/core/editor/right-panel/props.js
| ... | ... | @@ -180,11 +180,12 @@ export default { |
| 180 | 180 | class="props-config-form" |
| 181 | 181 | layout={this.layout} |
| 182 | 182 | > |
| 183 | - <BoxModel></BoxModel> | |
| 184 | - {/* 只有在选中编辑组件的时候显示 */} | |
| 183 | + {/* left,top,width,height编辑 只有在选中编辑组件的时候显示 */} | |
| 185 | 184 | { |
| 186 | 185 | this.stateEditingElement ? this.renderEditorPositionConfig(h) : '' |
| 187 | 186 | } |
| 187 | + {/* margin、padding编辑 */} | |
| 188 | + <BoxModel /> | |
| 188 | 189 | { |
| 189 | 190 | // plugin-custom-editor |
| 190 | 191 | this.loadCustomEditorFlag && | ... | ... |