提交 df841373 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

fix: 修复画布中组件加载多次

上级 39a282dd
...@@ -89,6 +89,7 @@ export default { ...@@ -89,6 +89,7 @@ export default {
deleteCurCondition() { deleteCurCondition() {
if (this.curComponent.type === 'custom') { if (this.curComponent.type === 'custom') {
this.$store.dispatch('conditions/delete', { componentId: this.curComponent.id })
bus.$emit('delete-condition', { componentId: this.curComponent.id }) bus.$emit('delete-condition', { componentId: this.curComponent.id })
} }
}, },
......
...@@ -92,6 +92,10 @@ export default { ...@@ -92,6 +92,10 @@ export default {
}) })
}) })
}, },
created() {
// 先清除查询条件
this.$store.dispatch('conditions/clear')
},
methods: { methods: {
changeStyleWithScale, changeStyleWithScale,
getStyle, getStyle,
...@@ -105,7 +109,7 @@ export default { ...@@ -105,7 +109,7 @@ export default {
resetID(data) { resetID(data) {
if (data) { if (data) {
data.forEach(item => { data.forEach(item => {
item.id = uuid.v1() item.type !== 'custom' && (item.id = uuid.v1())
}) })
} }
return data return data
......
...@@ -118,7 +118,7 @@ export default { ...@@ -118,7 +118,7 @@ export default {
resetID(data) { resetID(data) {
if (data) { if (data) {
data.forEach(item => { data.forEach(item => {
item.id = uuid.v1() item.type !== 'custom' && (item.id = uuid.v1())
}) })
} }
return data return data
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
class="component" class="component"
:style="item.style" :style="item.style"
:element="item" :element="item"
@set-condition-value="setConditionValue"
/> />
<component <component
...@@ -109,7 +108,7 @@ export default { ...@@ -109,7 +108,7 @@ export default {
height: this.changeStyleWithScale(this.canvasStyleData.height) + 'px' height: this.changeStyleWithScale(this.canvasStyleData.height) + 'px'
} }
if (this.canvasStyleData.openCommonStyle) { if (this.canvasStyleData.openCommonStyle) {
if (this.canvasStyleData.panel.backgroundType === 'image'&&this.canvasStyleData.panel.imageUrl) { if (this.canvasStyleData.panel.backgroundType === 'image' && this.canvasStyleData.panel.imageUrl) {
style = { style = {
width: this.changeStyleWithScale(this.canvasStyleData.width) + 'px', width: this.changeStyleWithScale(this.canvasStyleData.width) + 'px',
height: this.changeStyleWithScale(this.canvasStyleData.height) + 'px', height: this.changeStyleWithScale(this.canvasStyleData.height) + 'px',
...@@ -148,6 +147,9 @@ export default { ...@@ -148,6 +147,9 @@ export default {
this.deleteCondition(condition) this.deleteCondition(condition)
}) })
}, },
created() {
this.$store.dispatch('conditions/clear')
},
methods: { methods: {
changeStyleWithScale, changeStyleWithScale,
......
...@@ -69,9 +69,9 @@ export default { ...@@ -69,9 +69,9 @@ export default {
}, },
resetID(data) { resetID(data) {
if( data ) { if (data) {
data.forEach(item => { data.forEach(item => {
item.id = uuid.v1() item.type !== 'custom' && (item.id = uuid.v1())
}) })
} }
......
...@@ -44,6 +44,7 @@ export default { ...@@ -44,6 +44,7 @@ export default {
created() { created() {
this.options = this.element.options this.options = this.element.options
this.setCondition()
}, },
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
...@@ -52,8 +53,12 @@ export default { ...@@ -52,8 +53,12 @@ export default {
}, },
methods: { methods: {
changeValue(value) { changeValue(value) {
this.inDraw && this.$store.dispatch('conditions/add', { component: this.element, value: [this.options.value], operator: this.operator }) this.setCondition()
this.inDraw && this.$emit('set-condition-value', { component: this.element, value: [value], operator: this.operator }) this.inDraw && this.$emit('set-condition-value', { component: this.element, value: [value], operator: this.operator })
},
setCondition() {
this.inDraw && this.$store.dispatch('conditions/add', { component: this.element, value: [this.options.value], operator: this.operator })
} }
} }
} }
......
...@@ -5,11 +5,13 @@ const state = { ...@@ -5,11 +5,13 @@ const state = {
const mutations = { const mutations = {
ADD_CONDITION: (state, condition) => { ADD_CONDITION: (state, condition) => {
!condition && (condition = []) condition && valueValid(condition) && state.conditions.push(condition)
state.conditions.push(condition)
}, },
REDUCE_CONDITION: (state, index) => { REDUCE_CONDITION: (state, index) => {
state.conditions && state.conditions.length > index && state.conditions.splice(index, 1) state.conditions && state.conditions.length > index && state.conditions.splice(index, 1)
},
CLEAR: (state) => {
state.conditions = []
} }
} }
...@@ -30,6 +32,17 @@ const actions = { ...@@ -30,6 +32,17 @@ const actions = {
}, },
reduce({ commit }, index) { reduce({ commit }, index) {
commit('ADD_CONDITION', index) commit('ADD_CONDITION', index)
},
delete({ commit }, component) {
for (let index = 0; index < state.conditions.length; index++) {
const element = state.conditions[index]
if (element.componentId === component.componentId) {
commit('REDUCE_CONDITION', index)
}
}
},
clear({ commit }) {
commit('CLEAR')
} }
} }
...@@ -61,6 +74,10 @@ const isValid = condition => { ...@@ -61,6 +74,10 @@ const isValid = condition => {
return validResult return validResult
} }
const valueValid = condition => {
return condition && condition.value && condition.value.length > 0 && condition.value[0]
}
const formatCondition = obj => { const formatCondition = obj => {
const { component, value, operator } = obj const { component, value, operator } = obj
const fieldId = component.options.attrs.fieldId const fieldId = component.options.attrs.fieldId
......
...@@ -38,7 +38,7 @@ export default { ...@@ -38,7 +38,7 @@ export default {
resetID(data) { resetID(data) {
if (data) { if (data) {
data.forEach(item => { data.forEach(item => {
item.id = uuid.v1() item.type !== 'custom' && (item.id = uuid.v1())
}) })
} }
return data return data
......
...@@ -51,9 +51,9 @@ export default { ...@@ -51,9 +51,9 @@ export default {
}) })
}, },
resetID(data) { resetID(data) {
if( data ) { if (data) {
data.forEach(item => { data.forEach(item => {
item.id = uuid.v1() item.type !== 'custom' && (item.id = uuid.v1())
}) })
} }
......
...@@ -270,7 +270,7 @@ export default { ...@@ -270,7 +270,7 @@ export default {
resetID(data) { resetID(data) {
if (data) { if (data) {
data.forEach(item => { data.forEach(item => {
item.id = uuid.v1() item.type !== 'custom' && (item.id = uuid.v1())
}) })
} }
return data return data
...@@ -372,7 +372,7 @@ export default { ...@@ -372,7 +372,7 @@ export default {
}, },
closeLeftPanel() { closeLeftPanel() {
this.show = false this.show = false
this.beforeDestroy() // this.beforeDestroy()
} }
} }
} }
......
...@@ -53,7 +53,7 @@ export default { ...@@ -53,7 +53,7 @@ export default {
resetID(data) { resetID(data) {
if (data) { if (data) {
data.forEach(item => { data.forEach(item => {
item.id = uuid.v1() item.type !== 'custom' && (item.id = uuid.v1())
}) })
} }
......
...@@ -486,6 +486,7 @@ export default { ...@@ -486,6 +486,7 @@ export default {
// 加载视图数据 // 加载视图数据
get('panel/group/findOne/' + data.id).then(response => { get('panel/group/findOne/' + data.id).then(response => {
this.$store.commit('setComponentData', this.resetID(JSON.parse(response.data.panelData))) this.$store.commit('setComponentData', this.resetID(JSON.parse(response.data.panelData)))
// this.$store.commit('setComponentData', sourceInfo.type === 'custom' ? sourceInfo : this.resetID(sourceInfo))
const temp = JSON.parse(response.data.panelStyle) const temp = JSON.parse(response.data.panelStyle)
this.$store.commit('setCanvasStyle', temp) this.$store.commit('setCanvasStyle', temp)
this.$store.dispatch('panel/setPanelInfo', data) this.$store.dispatch('panel/setPanelInfo', data)
...@@ -535,7 +536,7 @@ export default { ...@@ -535,7 +536,7 @@ export default {
resetID(data) { resetID(data) {
if (data) { if (data) {
data.forEach(item => { data.forEach(item => {
item.id = uuid.v1() item.type !== 'custom' && (item.id = uuid.v1())
}) })
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论