dragChart.js 4.5 KB

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