dragChart.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * @Author: your name
  3. * @Date: 2024-11-04 10:06:23
  4. * @LastEditTime: 2024-11-18 15:27:25
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/store/dragChart.js
  8. */
  9. import { SCALE } from "@/assets/js/constants/config.js";
  10. import { Message } from "element-ui";
  11. const _ = require("lodash");
  12. export default {
  13. namespaced: true,
  14. state: {
  15. triggerGetData: false,
  16. updateTriggerGetData: false,
  17. relatedFieldsData: [], //关联字段表
  18. curEdit: {}, // 当前编辑的图表
  19. currentChartList: [], // 当前文件的当前数据
  20. originChartList: [], // 当前文件的原始数据
  21. fileList: [], // 文件列表
  22. dataBaseCheckList: {}, //选中数据更新
  23. formFilterAlignData: [], //这个是所有图表数据筛选保存字段
  24. },
  25. mutations: {
  26. setUpdateTriggerGetData(state, value) {
  27. state.updateTriggerGetData = value;
  28. },
  29. setTriggerGetData(state, value) {
  30. state.triggerGetData = value;
  31. },
  32. setRelatedFieldsData(state, data) {
  33. console.log(data);
  34. state.relatedFieldsData = [...state.relatedFieldsData, { ...data }];
  35. },
  36. // 清空图表
  37. clearchart(state) {
  38. const resetState = {
  39. curEdit: {},
  40. currentChartList: [],
  41. originChartList: [],
  42. fileList: [],
  43. dataBaseCheckList: {},
  44. triggerGetData: false,
  45. updateTriggerGetData: false,
  46. relatedFieldsData: [], //关联字段表
  47. formFilterAlign: [],
  48. };
  49. // 遍历重置每个字段
  50. Object.keys(resetState).forEach((key) => {
  51. state[key] = resetState[key];
  52. });
  53. },
  54. //编辑数据筛选字段
  55. setFormFilterAlignData(state, data) {
  56. //将数据存储起来用于回显 数据
  57. // 检查是否已经存在相同的 id
  58. const index = state.formFilterAlignData.findIndex(
  59. (item) => item.id === data.id
  60. );
  61. if (index !== -1) {
  62. // 如果找到相同的 id,直接更新
  63. state.formFilterAlignData[index] = {
  64. ...data,
  65. // data: [...state.formFilterAlignData[index].data, ...data.data],
  66. };
  67. } else {
  68. // 如果不存在,新增一条数据
  69. state.formFilterAlignData.push({ ...data });
  70. }
  71. },
  72. // 设置当前编辑的图表
  73. setCurEdit(state, data) {
  74. state.curEdit = data;
  75. },
  76. // 当前画布添加图表
  77. addChart(state, data) {
  78. // console.log("当前画布添加图表", data);
  79. if (state.currentChartList.length <= 0) {
  80. state.currentChartList.push({ ...data, index: 0 });
  81. } else {
  82. state.currentChartList.push(data);
  83. }
  84. },
  85. //更新数据配置当前选中数据
  86. updateDataBase(state, data) {
  87. // console.log("更改了图表数据", data);
  88. state.dataBaseCheckList = data;
  89. },
  90. // 更新图表
  91. updateChart(state, data) {
  92. // console.log("更改了图表组件", data.index, data);
  93. if (state.currentChartList[data.index]) {
  94. state.currentChartList[data.index] = Object.assign(
  95. state.currentChartList[data.index],
  96. data
  97. );
  98. }
  99. },
  100. // 删除图表
  101. deleteChart(state, index) {
  102. state.currentChartList.splice(index, 1);
  103. },
  104. // 设置当前图表列表
  105. setCurrentChartList(state, list = []) {
  106. state.currentChartList = list;
  107. },
  108. // 文件删除
  109. fileListDelete(state, item) {
  110. const index = state.fileList.indexOf(item);
  111. state.fileList.splice(index, 1);
  112. },
  113. // 文件添加
  114. fileListAdd(state, item) {
  115. state.fileList.push(item);
  116. },
  117. fileListUpdate(state, item) {
  118. state.fileList = _.cloneDeep(item);
  119. },
  120. // 记录当前文件的原始数据
  121. recordOriginChartList(state, id) {
  122. const fileList = state.fileList;
  123. const item = fileList.find((i) => +i.id === +id);
  124. if (item) {
  125. state.originChartList = _.cloneDeep(item);
  126. } else {
  127. state.originChartList = {};
  128. }
  129. },
  130. // 还原当前文件的原始数据
  131. restoreOriginChartList(state, id) {
  132. const fileList = state.fileList;
  133. const index = fileList.findIndex((i) => +i.id === +id);
  134. if (index > -1) {
  135. fileList.splice(index, 1, state.originChartList);
  136. } else {
  137. Message.warning("未找到文件!");
  138. }
  139. },
  140. // 缩放屏幕
  141. scaleScreen(state, isGrow) {
  142. if (isGrow) {
  143. state.currentChartList.forEach((item) => {
  144. item.x = parseInt(item.x * SCALE);
  145. item.y = parseInt(item.y * SCALE);
  146. item.height = parseInt(item.height * SCALE);
  147. item.width = parseInt(item.width * SCALE);
  148. });
  149. } else {
  150. state.currentChartList.forEach((item) => {
  151. item.x = parseInt(item.x / SCALE);
  152. item.y = parseInt(item.y / SCALE);
  153. item.height = parseInt(item.height / SCALE);
  154. item.width = parseInt(item.width / SCALE);
  155. });
  156. }
  157. },
  158. },
  159. actions: {},
  160. };