Commit a59dbd3e0d3283e7f3bdabf99815b43f175091ec

Authored by 宋远桥
Committed by 小小鲁班
1 parent baab9cc2

[feat] 优化box-model选中逻辑

front-end/h5/src/components/core/editor/right-panel/box-model/index.vue
@@ -5,11 +5,11 @@ @@ -5,11 +5,11 @@
5 <PositionCheckbox label="上" label-key="top" /> 5 <PositionCheckbox label="上" label-key="top" />
6 <div class="middle"> 6 <div class="middle">
7 <PositionCheckbox label="左" label-key="left" /> 7 <PositionCheckbox label="左" label-key="left" />
8 - <div ref="margin" class="margin" data-type="margin" @click="onBoxModelClick"> 8 + <div ref="margin" class="margin" data-type="margin" :class="{'margin-select':boxModelPart === 'margin'}" @click="onBoxModelClick">
9 margin 9 margin
10 - <div ref="border" class="border" data-type="border"> 10 + <div ref="border" class="border" data-type="border" :class="{'border-select':boxModelPart === 'border'}">
11 border 11 border
12 - <div ref="padding" class="padding" data-type="padding"> 12 + <div ref="padding" class="padding" data-type="padding" :class="{'padding-select':boxModelPart === 'padding'}">
13 padding 13 padding
14 <div class="content" data-type="padding"> 14 <div class="content" data-type="padding">
15 {{ commonStyle.width | digit }} x {{ commonStyle.height | digit }} 15 {{ commonStyle.width | digit }} x {{ commonStyle.height | digit }}
@@ -37,7 +37,8 @@ @@ -37,7 +37,8 @@
37 }, 37 },
38 data () { 38 data () {
39 return { 39 return {
40 - lastSelect: '' 40 + lastSelect: '',
  41 + select: ''
41 } 42 }
42 }, 43 },
43 computed: { 44 computed: {
@@ -68,49 +69,17 @@ @@ -68,49 +69,17 @@
68 ]), 69 ]),
69 onBoxModelClick (e) { 70 onBoxModelClick (e) {
70 const target = e.target 71 const target = e.target
71 - const classList = target.classList  
72 const type = target.dataset.type 72 const type = target.dataset.type
73 - const selectClass = type + '-select'  
74 - // 更新选中的 boxModelPart,用于判断当前设置的是 margin / border / padding  
75 this.setElementPosition({ 73 this.setElementPosition({
76 boxModelPart: type 74 boxModelPart: type
77 }) 75 })
78 - if (this.lastSelect && type !== this.lastSelect) {  
79 - this.$refs[this.lastSelect].classList.remove(this.lastSelect + '-select')  
80 - }  
81 - // 选中的元素添加上选中的 className  
82 - if (!classList.contains(selectClass)) {  
83 - this.$refs[type].classList.add(selectClass)  
84 - this.lastSelect = type  
85 - }  
86 }, 76 },
87 onColorChange (color) { 77 onColorChange (color) {
88 - this.changeCommonStyle(color, 'color')  
89 - },  
90 - changeCommonStyle (changeValue, labelKey, key = 'value') {  
91 - const boxModelPart = this.boxModelPart  
92 - // 例如 boxModelPart 为 margin 时候 78 + const boxModelPart = this.boxModelPart
  79 + // 取出 commonStyle.border,并更改 border.color.value 的值
93 const boxModelPartStyle = this.editingElement.commonStyle[boxModelPart] 80 const boxModelPartStyle = this.editingElement.commonStyle[boxModelPart]
94 - // 更新值例如: padding-top  
95 - Object.assign(boxModelPartStyle[labelKey], { [key]: changeValue })  
96 - this.setElementPosition({ [boxModelPart]: boxModelPartStyle })  
97 - }  
98 - },  
99 - watch: {  
100 - /**  
101 - * 监听当前是否有选中的组件,如果有判断之前是否保存了 boxModelPart  
102 - * 如果保存了就将之前编辑状态重新复原。  
103 - */  
104 - editingElement: {  
105 - immediate: true,  
106 - handler (val) {  
107 - if (!this.boxModelPart) return  
108 - const selectClass = this.boxModelPart + '-select'  
109 - this.$nextTick(() => {  
110 - this.$refs[this.boxModelPart].classList.add(selectClass)  
111 - this.lastSelect = this.boxModelPart  
112 - })  
113 - } 81 + Object.assign(boxModelPartStyle.color, { value: color })
  82 + this.setElementPosition({ [boxModelPart]: boxModelPartStyle })
114 } 83 }
115 } 84 }
116 } 85 }