/* * @Author: your name * @Date: 2024-11-04 10:06:23 * @LastEditTime: 2024-11-18 15:27:25 * @LastEditors: bogon * @Description: In User Settings Edit * @FilePath: /performance-test/src/store/dragChart.js */ import { SCALE } from "@/assets/js/constants/config.js"; import { Message } from "element-ui"; const _ = require("lodash"); export default { namespaced: true, state: { triggerGetData: false, updateTriggerGetData: false, relatedFieldsData: [], //关联字段表 curEdit: {}, // 当前编辑的图表 currentChartList: [], // 当前文件的当前数据 originChartList: [], // 当前文件的原始数据 fileList: [], // 文件列表 dataBaseCheckList: {}, //选中数据更新 formFilterAlignData: [], //这个是所有图表数据筛选保存字段 }, mutations: { setUpdateTriggerGetData(state, value) { state.updateTriggerGetData = value; }, setTriggerGetData(state, value) { state.triggerGetData = value; }, setRelatedFieldsData(state, data) { console.log(data); state.relatedFieldsData = [...state.relatedFieldsData, { ...data }]; }, // 清空图表 clearchart(state) { const resetState = { curEdit: {}, currentChartList: [], originChartList: [], fileList: [], dataBaseCheckList: {}, triggerGetData: false, updateTriggerGetData: false, relatedFieldsData: [], //关联字段表 formFilterAlign: [], }; // 遍历重置每个字段 Object.keys(resetState).forEach((key) => { state[key] = resetState[key]; }); }, //编辑数据筛选字段 setFormFilterAlignData(state, data) { //将数据存储起来用于回显 数据 // 检查是否已经存在相同的 id const index = state.formFilterAlignData.findIndex( (item) => item.id === data.id ); if (index !== -1) { // 如果找到相同的 id,直接更新 state.formFilterAlignData[index] = { ...data, // data: [...state.formFilterAlignData[index].data, ...data.data], }; } else { // 如果不存在,新增一条数据 state.formFilterAlignData.push({ ...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) { // console.log("更改了图表数据", data); state.dataBaseCheckList = data; }, // 更新图表 updateChart(state, data) { // console.log("更改了图表组件", data.index, 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: {}, };