import { SCALE } from "@/assets/js/constants/config.js"; import { Message } from "element-ui"; import { clearAllDataFromIndexedDB, clearMyIndexedDBIndexedDB, } from "@/utils/indexedDb"; const _ = require("lodash"); export default { namespaced: true, state: { triggerGetData: false, updateTriggerGetData: false, relatedFieldsData: [], //关联字段表 curEdit: {}, // 当前编辑的图表 currentChartList: [], // 当前文件的当前数据 originChartList: [], // 当前文件的原始数据 fileList: [], // 文件列表 dataBaseCheckList: [], //选中数据更新 }, mutations: { setUpdateTriggerGetData(state, value) { state.updateTriggerGetData = value; }, setTriggerGetData(state, value) { state.triggerGetData = value; }, setRelatedFieldsData(state, data) { state.relatedFieldsData = [...state.relatedFieldsData, { ...data }]; }, // 清空图表 clearchart(state) { const resetState = { curEdit: {}, currentChartList: [], originChartList: [], fileList: [], dataBaseCheckList: [], triggerGetData: false, updateTriggerGetData: false, formFilterAlignData: [], relatedFieldsData: [], //关联字段表 formFilterAlign: [], }; //跳转离开编辑表格页面触发清空indexeddb 数据库方法 clearAllDataFromIndexedDB(); clearMyIndexedDBIndexedDB(); // 遍历重置每个字段 Object.keys(resetState).forEach((key) => { state[key] = resetState[key]; }); }, //编辑数据筛选字段 setFormFilterAlignData(state, data) { //将数据存储起来用于回显数据---检查是否已经存在相同的 id state.currentChartList?.map((chartItem, ind) => { if (chartItem.id === data.id) { state.currentChartList[ind].formFilterAlignData = data.data; } }); }, // 设置当前编辑的图表 setCurEdit(state, data) { state.curEdit = data; }, // 当前画布添加图表 addChart(state, data) { // console.log("当前画布添加图表", data); if (state.currentChartList.length <= 0) { state.currentChartList.push({ ...data, index: 0 }); } else { state.currentChartList.push(data); } }, //更新数据配置当前选中数据 updateDataBase(state, data) { state.dataBaseCheckList = data; }, // 更新图表 updateChart(state, data) { if (state.currentChartList[data.index]) { state.currentChartList[data.index] = Object.assign( state.currentChartList[data.index], data ); } }, // 删除图表 deleteChart(state, index) { state.currentChartList.splice(index, 1); }, // 设置当前图表列表 setCurrentChartList(state, list = []) { state.currentChartList = list; }, // 文件删除 fileListDelete(state, item) { const index = state.fileList.indexOf(item); state.fileList.splice(index, 1); }, // 文件添加 fileListAdd(state, item) { state.fileList.push(item); }, fileListUpdate(state, item) { state.fileList = _.cloneDeep(item); }, // 记录当前文件的原始数据 recordOriginChartList(state, id) { const fileList = state.fileList; const item = fileList.find((i) => +i.id === +id); if (item) { state.originChartList = _.cloneDeep(item); } else { state.originChartList = {}; } }, // 还原当前文件的原始数据 restoreOriginChartList(state, id) { const fileList = state.fileList; const index = fileList.findIndex((i) => +i.id === +id); if (index > -1) { fileList.splice(index, 1, state.originChartList); } else { Message.warning("未找到文件!"); } }, // 缩放屏幕 // scaleScreen(state, isGrow) { // if (isGrow) { // state.currentChartList.forEach((item) => { // item.x = parseInt(item.x * SCALE); // item.y = parseInt(item.y * SCALE); // item.height = parseInt(item.height * SCALE); // item.width = parseInt(item.width * SCALE); // }); // } else { // state.currentChartList.forEach((item) => { // item.x = parseInt(item.x / SCALE); // item.y = parseInt(item.y / SCALE); // item.height = parseInt(item.height / SCALE); // item.width = parseInt(item.width / SCALE); // }); // } // }, }, actions: {}, };