123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- import Vue from 'vue'
- import _ from 'lodash'
- import { defaultData } from './state'
- import moment from 'moment'
- import { randomString } from 'packages/js/utils'
- export default {
-
- changePageInfo (state, pageInfo) {
- state.pageInfo = pageInfo
- },
-
- changeLayout (state, layout) {
- state.pageInfo.chartList = layout
- },
-
- changeIframeDialog (state, dialogVisible) {
- state.iframeDialog = dialogVisible
- },
-
- changeActiveCode (state, code) {
- state.activeCode = code
- state.hoverCode = code
- const activeItem = _.cloneDeep(state.pageInfo.chartList?.find(
- item => item.code === code
- ))
- changeGroup(code, state)
- state.activeItemConfig = _.cloneDeep(activeItem)
- },
- changeActiveCodes (state, codes) {
- state.activeCodes = codes
- state.pageInfo.chartList = state.pageInfo.chartList?.map(chart => {
- return {
- ...chart,
- group: (codes.includes(chart.code) && !chart.group) ? 'tempGroup' : chart.group
- }
- })
- },
-
- changeHoverCode (state, code) {
- state.hoverCode = code
- },
- changePageLoading (state, booleanValue) {
- state.pageLoading = booleanValue
- },
-
- changeChartConfig (state, itemConfig) {
- const index = state.pageInfo.chartList.findIndex(
- item => item.code === itemConfig.code
- )
- Vue.set(state.pageInfo.chartList, index, {
- ...state.pageInfo.chartList[index],
- ...itemConfig
- })
-
- const oldConfig = state.pageInfo.chartList[index]
- if (
- oldConfig.x !== itemConfig.x ||
- oldConfig.y !== itemConfig.y ||
- oldConfig.w !== itemConfig.w ||
- oldConfig.h !== itemConfig.h
- ) {
-
- changePresetLine(state, itemConfig)
- }
- },
- setPresetLine (state, { x, y, w, h }) {
- state.presetLine = [
- { type: 'h', site: y || 0 },
- { type: 'v', site: x || 0 }
- ]
- },
- changeActiveItemConfig (state, config) {
- state.activeItemConfig = _.cloneDeep(config)
- },
-
- addItem (state, itemConfig) {
-
- state.pageInfo.chartList.unshift(itemConfig)
- changeZIndexFuc(state, state.pageInfo.chartList)
- saveTimeLineFunc(state, '新增组件' + itemConfig?.title)
- },
-
- delItem (state, codes) {
- if (Array.isArray(codes)) {
- state.pageInfo.chartList = state.pageInfo.chartList.filter(chart => !codes.includes(chart.code))
- } else {
- state.pageInfo.chartList = state.pageInfo.chartList.filter(chart => codes !== chart.code)
- }
-
- saveTimeLineFunc(state, '删除组件')
- },
- changePageConfig (state, pageConfig) {
- Vue.set(state.pageInfo, 'pageConfig', _.cloneDeep(pageConfig))
- state.updateKey = new Date().getTime()
- },
- changeActiveItem (state, activeItem) {
- state.activeItem = _.cloneDeep(activeItem)
- state.activeId = activeItem.code
-
- },
-
- resetPresetLine (state) {
- state.presetLine = []
- },
-
- changeZIndex (state, list) {
- changeZIndexFuc(state, list)
- },
-
- changeLocked (state, config) {
- const index = state.pageInfo.chartList.findIndex(
- item => item.code === config.code
- )
- Vue.set(state.pageInfo.chartList[index], 'locked', !config.locked)
- saveTimeLineFunc(state, !config.locked ? `解锁${config?.title}` : `锁定${config?.title}`)
- },
-
- changeGridShow (state, isShow) {
- state.hasGrid = isShow
- },
-
- changeChartKey (state, code) {
- const index = state.pageInfo.chartList.findIndex(
- item => item.code === code
- )
- if (index < 0) {
- return
- }
- const config = state.pageInfo.chartList[index]
- Vue.set(config, 'key', config.code + new Date().getTime())
- },
-
- changeCacheDataFields (state, { dataSetId, data }) {
-
- const index = state.pageInfo.pageConfig.cacheDataSets.findIndex(cacheData => cacheData.dataSetId === dataSetId)
- if (index < 0) {
- return
- }
- Vue.set(state.pageInfo.pageConfig.cacheDataSets[index], 'fields', data?.fields || [])
- },
-
- changeCacheDataParams (state, { dataSetId, data }) {
-
- const index = state.pageInfo.pageConfig.cacheDataSets.findIndex(cacheData => cacheData.dataSetId === dataSetId)
- if (index < 0) {
- return
- }
- Vue.set(state.pageInfo.pageConfig.cacheDataSets[index], 'params', data?.params || [])
- },
-
- changeCacheDataSetData (state, { dataSetId, data }) {
- const index = state.pageInfo.pageConfig.cacheDataSets.findIndex(cacheData => cacheData.dataSetId === dataSetId)
- if (index < 0) {
- return
- }
- state.pageInfo.pageConfig.cacheDataSets[index].data = data || []
- },
-
- changeCtrlOrCommandDown (state, isDown) {
- state.shiftKeyDown = isDown
- },
-
- resetStoreData (state) {
- for (const stateKey in state) {
- state[stateKey] = _.cloneDeep(defaultData[stateKey])
- }
- },
- changeZoom (state, zoom) {
- state.zoom = zoom
- },
- changeFitZoom (state, zoom) {
- state.fitZoom = zoom
- },
- changeActivePos (state, { diffX, diffY }) {
- const activeCodes = state.activeCodes
- activeCodes?.forEach(code => {
- const chart = state.pageInfo.chartList.find(item => item.code === code)
- if (chart) {
- chart.x += diffX
- chart.y += diffY
- }
- const index = state.pageInfo.chartList.findIndex(
- item => item.code === chart.code
- )
- if (index < 0) {
- return
- }
- Vue.set(state.pageInfo.chartList, index, {
- ...state.pageInfo.chartList[index],
- ...chart
- })
- changePresetLine(state, chart)
- })
- },
-
- saveTimeLine (state, title) {
- const date = new Date()
- const time = moment(date).format('HH:mm:ss')
-
- if (!title) {
- const date = new Date()
- title = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
- }
- saveTimeLineFunc(state, title, time)
- },
-
- undoTimeLine (state, isUndo = true) {
- let currentStore = {}
-
- if (isUndo) {
- if (state.timelineStore.length > 0 && state.currentTimeLine > 1) {
-
- state.currentTimeLine = state.currentTimeLine - 1
- currentStore = state.timelineStore[state.currentTimeLine - 1]
- if (currentStore?.chartList) {
- state.pageInfo.chartList = _.cloneDeep(currentStore?.chartList)
- }
- }
- }
-
- if (!isUndo) {
- if (state.currentTimeLine < state.timelineStore.length) {
-
- state.currentTimeLine = state.currentTimeLine + 1
- currentStore = state.timelineStore[state.currentTimeLine - 1]
- state.pageInfo.chartList = _.cloneDeep(currentStore?.chartList || [])
- }
- }
- },
- clearTimeline (state) {
-
- const lastStore = state.timelineStore[state.timelineStore.length - 1]
-
- state.timelineStore = [
- {
- ...lastStore,
- timelineTitle: '初始状态',
- updateTime: moment(new Date()).format('HH:mm:ss')
- }
- ]
- state.currentTimeLine = 1
- },
-
- rollbackTimeline (state, index) {
- state.pageInfo.chartList = _.cloneDeep(state.timelineStore[index]?.chartList || [])
- state.currentTimeLine = index + 1
- },
-
- copyCharts (state) {
- state.copyChartCodes = _.cloneDeep(state.activeCodes)
- },
-
- pasteCharts (state) {
- const copyChartCodes = state.copyChartCodes
- const chartList = state.pageInfo.chartList
-
- const additionCode = randomString(5)
- const copyCharts = copyChartCodes.map(code => {
- const chart = chartList.find(item => item.code === code)
- const copyChart = _.cloneDeep(chart)
- copyChart.code = `${copyChart.code}_${additionCode}`
- copyChart.key = `${copyChart.key}_${additionCode}`
- copyChart.group = (copyChart.group && copyChart.group !== 'tempGroup') ? `${copyChart.group}_${additionCode}` : ''
- copyChart.x += 50
- copyChart.y += 50
- return copyChart
- })
-
- state.pageInfo.chartList = [...copyCharts, ...state.pageInfo.chartList]
- }
- }
- function changeZIndexFuc (state, list) {
- const len = list?.length - 1 || 0
- list.forEach((item, i) => {
- const index = state.pageInfo.chartList.findIndex(
- _item => _item.code === item.code
- )
- Vue.set(state.pageInfo.chartList[len - index], 'z', i)
- })
- }
- function changePresetLine (state, { x, y, w, h }) {
- state.presetLine = [
- { type: 'h', site: y || 0 },
- { type: 'v', site: x || 0 }
- ]
- }
- function changeGroup (code, state) {
- if (code) {
-
- const group = state.pageInfo.chartList?.find(item => item.code === code)?.group
- if (group) {
- state.activeCodes = state.pageInfo.chartList?.filter(chart => chart.group === group && chart.group).map(item => item.code)
- }
- if (state.shiftKeyDown) {
- state.activeCodes = _.uniq([...state.activeCodes, code])
-
- state.pageInfo.chartList?.forEach(chart => {
- if (state.activeCodes.includes(chart.code)) {
- chart.group = 'tempGroup'
- }
- })
- } else {
- if (!group) {
- state.activeCodes = [code]
- }
- }
- } else {
- state.activeCodes = []
- state.pageInfo.chartList = state.pageInfo.chartList?.map(chart => ({
- ...chart,
- group: chart.group === 'tempGroup' ? '' : chart.group
- }))
- }
- }
- function saveTimeLineFunc (state, title, time) {
-
- const MAX_TIME_LINE = 10
- const stateCopy = _.cloneDeep(state.pageInfo)
- const date = new Date()
- time = time || moment(date).format('HH:mm:ss')
- stateCopy.timelineTitle = title
- stateCopy.updateTime = time
- if (!Array.isArray(state.timelineStore)) {
- state.timelineStore = []
- }
- if (!Number.isInteger(state.currentTimeLine)) {
- state.currentTimeLine = 0
- }
- if (state.timelineStore.length >= MAX_TIME_LINE) {
-
- state.timelineStore.shift()
- }
- state.timelineStore?.push(stateCopy)
- state.currentTimeLine = state.timelineStore?.length
- }
|