index.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. Vue.use(Vuex);
  4. export default new Vuex.Store({
  5. state: {
  6. editCmd: "", //编辑器编辑命令
  7. legendObj: null, //获取的相关图例数据obj
  8. name: "", //图名称
  9. folderId: "", //文件id
  10. folderName: "", //文件夹名称
  11. buildingId: "", //建筑id
  12. floorId: "", //楼层id
  13. floorMap: "", //floorMap
  14. floorLocalName: "", //楼层本地名称
  15. id: "", //图id
  16. graphId: "", //图graphId
  17. version: "", //版本号
  18. projectId: "Pj1101050029", // projectId
  19. equipItemMap: {}, // 图上相关的设备实例
  20. equipItemNum: 0, // 图上相关的设备的数量
  21. zoneIteMap: {}, // 图上相关的空间实例
  22. zoneItemNum: 0, // 图上相关的空间实例的数量
  23. styleMap: {}, // 样式库信息
  24. ruleList: [], //规则列表
  25. objExtInfo: {}, // 对象实例信息
  26. showCheckbox: false, // 卡片复选框是否显示
  27. },
  28. mutations: {
  29. // 修改卡片复选框是否显示
  30. SETCARDSHOWCHECKBOX(state, data) {
  31. state.showCheckbox = data;
  32. },
  33. // 修改编辑器命令
  34. SETCHOICELEHEND(state, data) {
  35. state.editCmd = data;
  36. },
  37. // 修改编辑器图例
  38. SETLEGENDOBJ(state, data) {
  39. state.legendObj = data;
  40. },
  41. // 设置项目信息
  42. SETPROJECT(state, data) {
  43. const arr = [
  44. "name",
  45. "folderId",
  46. "folderName",
  47. "buildingId",
  48. "floorId",
  49. "floorMap",
  50. "floorLocalName",
  51. "id",
  52. "graphId",
  53. "state",
  54. "version",
  55. ];
  56. arr.map((key) => {
  57. // 对传入的参数进行修改
  58. if (data[key] !== undefined) {
  59. // @ts-ignore
  60. state[key] = data[key];
  61. }
  62. });
  63. },
  64. // 设置类型id
  65. SETCATEGROY(state, val) {
  66. state.folderId = val.folderId; //文件夹id
  67. state.name = val.name; //拓扑图名称
  68. state.version = val.version; //版本号
  69. },
  70. SETVERSION(state, val) {
  71. state.version = val; //版本号
  72. },
  73. // 初始化对象实例信息
  74. INITOBJEXTINFO(state, data) {
  75. state.objExtInfo = data;
  76. },
  77. // 初始化规则列表
  78. INITRULELIST(state, data) {
  79. state.ruleList = data;
  80. },
  81. // 初始化样式库信息
  82. INITSTYLE(state, data) {
  83. // 设备默认样式
  84. data.defaultEquipStyle = {
  85. color: "#1F2429",
  86. size: 12,
  87. url: "tognyong2020102700.svg",
  88. formula: JSON.stringify(["设备实例"]),
  89. };
  90. state.styleMap = data;
  91. },
  92. // 初始化 equipItemMap, equipItemNum
  93. INITEQUIPMAP(state, data) {
  94. if (data && Object.keys(data).length) {
  95. state.equipItemMap = data;
  96. state.equipItemNum = Object.keys(data).length;
  97. } else {
  98. state.equipItemMap = {};
  99. state.equipItemNum = 0;
  100. }
  101. },
  102. // 初始化 zoneIteMap, zoneIteMap
  103. INITZONEMAP(state, data) {
  104. if (data && Object.keys(data).length) {
  105. state.zoneIteMap = data;
  106. state.zoneItemNum = Object.keys(data).length;
  107. } else {
  108. state.zoneIteMap = {};
  109. state.zoneItemNum = 0;
  110. }
  111. },
  112. // 添加规则
  113. ADDRULE(state, data) {
  114. // @ts-ignore
  115. state.ruleList.push(data);
  116. },
  117. // 添加样式信息
  118. ADDSTYLE(state, data) {
  119. // @ts-ignore
  120. const { id, style } = { ...data };
  121. // @ts-ignore
  122. state.styleMap[id] = style;
  123. },
  124. // 添加对象实例信息
  125. // 增加设备实例item
  126. ADDEQUIP(state, item): void {
  127. // @ts-ignore
  128. if (!state.equipItemMap[item.id]) {
  129. // @ts-ignore
  130. state.equipItemMap[item.id] = item;
  131. state.equipItemNum = Object.keys(state.equipItemMap).length;
  132. }
  133. },
  134. // 添加空间实例item
  135. ADDZONE(state, item): void {
  136. // @ts-ignore
  137. if (!state.zoneIteMap[item.id]) {
  138. // @ts-ignore
  139. state.zoneIteMap[item.id] = item;
  140. state.zoneItemNum = Object.keys(state.zoneIteMap).length;
  141. }
  142. },
  143. // 删除实例item
  144. DELETEITEM(state): void {
  145. // 如果实例数组中parent 为null 则删除该数组
  146. let arr1 = Object.keys(state.equipItemMap);
  147. let arr2 = Object.keys(state.zoneIteMap);
  148. if (arr1.length) {
  149. // 如果设备实例不为空
  150. arr1.forEach((key) => {
  151. // @ts-ignore
  152. if (!state.equipItemMap[key].parent) {
  153. // @ts-ignore
  154. delete state.equipItemMap[key];
  155. }
  156. });
  157. state.equipItemNum = Object.keys(state.equipItemMap).length;
  158. } else if (arr2.length) {
  159. // 如果空间实例不为空
  160. arr2.forEach((key) => {
  161. // @ts-ignore
  162. if (!state.zoneIteMap[key].parent) {
  163. // @ts-ignore
  164. delete state.zoneIteMap[key];
  165. }
  166. });
  167. state.zoneItemNum = Object.keys(state.zoneIteMap).length;
  168. }
  169. },
  170. },
  171. actions: {},
  172. modules: {},
  173. });