dataease-dm/frontend/src/store/index.js

143 lines
3.8 KiB
JavaScript
Raw Normal View History

2021-03-03 15:06:52 +08:00
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'
import permission from './modules/permission'
import dataset from './modules/dataset'
import chart from './modules/chart'
2021-03-04 14:58:52 +08:00
import request from './modules/request'
2021-03-08 14:31:09 +08:00
import panel from './modules/panel'
2021-03-29 21:24:33 +08:00
import application from './modules/application'
2021-03-30 15:38:32 +08:00
import animation from '@/components/canvas/store/animation'
import compose from '@/components/canvas/store/compose'
import contextmenu from '@/components/canvas/store/contextmenu'
import copy from '@/components/canvas/store/copy'
import event from '@/components/canvas/store/event'
import layer from '@/components/canvas/store/layer'
import snapshot from '@/components/canvas/store/snapshot'
import lock from '@/components/canvas/store/lock'
2021-03-25 19:16:32 +08:00
2021-03-03 15:06:52 +08:00
Vue.use(Vuex)
2021-03-25 19:16:32 +08:00
const data = {
state: {
...animation.state,
...compose.state,
...contextmenu.state,
...copy.state,
...event.state,
...layer.state,
...snapshot.state,
...lock.state,
editMode: 'edit', // 编辑器模式 edit preview
canvasStyleData: { // 页面全局数据
width: 1200,
height: 740,
scale: 100
},
componentData: [], // 画布组件数据
curComponent: null,
curComponentIndex: null,
// 点击画布时是否点中组件,主要用于取消选中组件用。
// 如果没点中组件,并且在画布空白处弹起鼠标,则取消当前组件的选中状态
isClickComponent: false
},
mutations: {
...animation.mutations,
...compose.mutations,
...contextmenu.mutations,
...copy.mutations,
...event.mutations,
...layer.mutations,
...snapshot.mutations,
...lock.mutations,
setClickComponentStatus(state, status) {
state.isClickComponent = status
},
setEditMode(state, mode) {
state.editMode = mode
},
setCanvasStyle(state, style) {
state.canvasStyleData = style
},
setCurComponent(state, { component, index }) {
state.curComponent = component
state.curComponentIndex = index
},
setShapeStyle({ curComponent }, { top, left, width, height, rotate }) {
if (top) curComponent.style.top = top
if (left) curComponent.style.left = left
if (width) curComponent.style.width = width
if (height) curComponent.style.height = height
if (rotate) curComponent.style.rotate = rotate
},
setShapeSingleStyle({ curComponent }, { key, value }) {
curComponent.style[key] = value
},
setComponentData(state, componentData = []) {
Vue.set(state, 'componentData', componentData)
},
addComponent(state, { component, index }) {
if (index !== undefined) {
state.componentData.splice(index, 0, component)
} else {
state.componentData.push(component)
}
},
2021-04-19 10:47:07 +08:00
setComponentWithId(state, component) {
for (let index = 0; index < state.componentData.length; index++) {
const element = state.componentData[index]
if (element.id && element.id === component.id) {
state.componentData[index] = component
return
}
}
state.componentData.push(component)
},
deleteComponentWithId(state, id) {
for (let index = 0; index < state.componentData.length; index++) {
const element = state.componentData[index]
if (element.id && element.id === id) {
state.componentData.splice(index, 1)
break
}
}
},
2021-03-25 19:16:32 +08:00
deleteComponent(state, index) {
if (index === undefined) {
index = state.curComponentIndex
}
state.componentData.splice(index, 1)
}
},
2021-03-03 15:06:52 +08:00
modules: {
app,
settings,
user,
permission,
dataset,
2021-03-04 14:58:52 +08:00
chart,
2021-03-08 14:31:09 +08:00
request,
2021-03-29 21:24:33 +08:00
panel,
application
2021-03-03 15:06:52 +08:00
},
getters
2021-03-25 19:16:32 +08:00
}
2021-03-03 15:06:52 +08:00
2021-03-25 19:16:32 +08:00
export default new Vuex.Store(data)