From 3f33dc38db8e2c1c79317ad87fae78f34eacec25 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 20 May 2021 12:02:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9F=A5=E8=AF=A2=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=98=E5=82=A8=E5=88=B0store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Editor/ComponentWrapper.vue | 9 +++ .../components/widget/DeWidget/DeSelect.vue | 3 +- frontend/src/store/getters.js | 3 +- frontend/src/store/index.js | 4 +- frontend/src/store/modules/conditions.js | 77 +++++++++++++++++++ 5 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 frontend/src/store/modules/conditions.js diff --git a/frontend/src/components/canvas/components/Editor/ComponentWrapper.vue b/frontend/src/components/canvas/components/Editor/ComponentWrapper.vue index 84c3526cd5..2c6c56c610 100644 --- a/frontend/src/components/canvas/components/Editor/ComponentWrapper.vue +++ b/frontend/src/components/canvas/components/Editor/ComponentWrapper.vue @@ -2,6 +2,15 @@
+ - + state.application.drawWidgetMap, validate: state => state.lic.validate, licMsg: state => state.lic.licMsg, - uiInfo: state => state.user.uiInfo + uiInfo: state => state.user.uiInfo, + conditions: state => state.conditions.conditions } export default getters diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 0ee2634c16..c85871d612 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -11,6 +11,7 @@ import request from './modules/request' import panel from './modules/panel' import application from './modules/application' import lic from './modules/lic' +import conditions from './modules/conditions' import animation from '@/components/canvas/store/animation' import compose from '@/components/canvas/store/compose' import contextmenu from '@/components/canvas/store/contextmenu' @@ -135,7 +136,8 @@ const data = { request, panel, application, - lic + lic, + conditions }, getters } diff --git a/frontend/src/store/modules/conditions.js b/frontend/src/store/modules/conditions.js new file mode 100644 index 0000000000..965b239c8f --- /dev/null +++ b/frontend/src/store/modules/conditions.js @@ -0,0 +1,77 @@ +import { Condition } from '@/components/widget/bean/Condition' +const state = { + conditions: [] +} + +const mutations = { + ADD_CONDITION: (state, condition) => { + !condition && (condition = []) + state.conditions.push(condition) + }, + REDUCE_CONDITION: (state, index) => { + state.conditions && state.conditions.length > index && state.conditions.splice(index, 1) + } +} + +const actions = { + add({ commit }, data) { + const condition = formatCondition(data) + if (!state.conditions || state.conditions.length === 0) { + state.conditions = [] + } + const validResult = isValid(condition) + if (!validResult.statu && validResult.hasOwnProperty('existIndex') && validResult.existIndex !== -1) { + commit('REDUCE_CONDITION', validResult.existIndex) + commit('ADD_CONDITION', condition) + } + if (validResult.statu) { + commit('ADD_CONDITION', condition) + } + }, + reduce({ commit }, index) { + commit('ADD_CONDITION', index) + } + +} +// 判断条件condition是否有效 +const isValid = condition => { + const nullResult = { + statu: false, + msg: 'condition is null' + } + const repeatResult = { + statu: false, + existIndex: -1, + msg: 'condition is exist' + } + const validResult = { + statu: true, + msg: null + } + if (!condition) { + return nullResult + } + for (let index = 0; index < state.conditions.length; index++) { + const item = state.conditions[index] + if (item.componentId === condition.componentId) { + repeatResult.existIndex = index + return repeatResult + } + } + return validResult +} + +const formatCondition = obj => { + const { component, value, operator } = obj + const fieldId = component.options.attrs.fieldId + const viewIds = component.options.attrs.viewIds + const condition = new Condition(component.id, fieldId, operator, value, viewIds) + return condition +} + +export default { + namespaced: true, + state, + mutations, + actions +}