123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- import Vue from "vue";
- import Vuex from "vuex";
- Vue.use(Vuex);
- export default new Vuex.Store({
- state: {
- editCmd: "", //编辑器编辑命令
- legendObj: null, //获取的相关图例数据obj
- name: "", //图名称
- folderId: "", //文件id
- folderName: "", //文件夹名称
- buildingId: "", //建筑id
- floorId: "", //楼层id
- floorMap: "", //floorMap
- floorLocalName: "", //楼层本地名称
- id: "", //图id
- graphId: "", //图graphId
- version: "", //版本号
- projectId: "Pj1101050029", // projectId
- equipItemMap: {}, // 图上相关的设备实例
- equipItemNum: 0, // 图上相关的设备的数量
- zoneIteMap: {}, // 图上相关的空间实例
- zoneItemNum: 0, // 图上相关的空间实例的数量
- styleMap: {}, // 样式库信息
- ruleList: [], //规则列表
- objExtInfo: {}, // 对象实例信息
- showCheckbox: false, // 卡片复选框是否显示
- },
- mutations: {
- // 修改卡片复选框是否显示
- SETCARDSHOWCHECKBOX(state, data) {
- state.showCheckbox = data;
- },
- // 修改编辑器命令
- SETCHOICELEHEND(state, data) {
- state.editCmd = data;
- },
- // 修改编辑器图例
- SETLEGENDOBJ(state, data) {
- state.legendObj = data;
- },
- // 设置项目信息
- SETPROJECT(state, data) {
- const arr = [
- "name",
- "folderId",
- "folderName",
- "buildingId",
- "floorId",
- "floorMap",
- "floorLocalName",
- "id",
- "graphId",
- "state",
- "version",
- ];
- arr.map((key) => {
- // 对传入的参数进行修改
- if (data[key] !== undefined) {
- // @ts-ignore
- state[key] = data[key];
- }
- });
- },
- // 设置类型id
- SETCATEGROY(state, val) {
- state.folderId = val.folderId; //文件夹id
- state.name = val.name; //拓扑图名称
- state.version = val.version; //版本号
- },
- SETVERSION(state, val) {
- state.version = val; //版本号
- },
- // 初始化对象实例信息
- INITOBJEXTINFO(state, data) {
- state.objExtInfo = data;
- },
- // 初始化规则列表
- INITRULELIST(state, data) {
- state.ruleList = data;
- },
- // 初始化样式库信息
- INITSTYLE(state, data) {
- // 设备默认样式
- data.defaultEquipStyle = {
- color: "#1F2429",
- size: 12,
- url: "tognyong2020102700.svg",
- formula: JSON.stringify(["设备实例"]),
- };
- state.styleMap = data;
- },
- // 初始化 equipItemMap, equipItemNum
- INITEQUIPMAP(state, data) {
- if (data && Object.keys(data).length) {
- state.equipItemMap = data;
- state.equipItemNum = Object.keys(data).length;
- } else {
- state.equipItemMap = {};
- state.equipItemNum = 0;
- }
- },
- // 初始化 zoneIteMap, zoneIteMap
- INITZONEMAP(state, data) {
- if (data && Object.keys(data).length) {
- state.zoneIteMap = data;
- state.zoneItemNum = Object.keys(data).length;
- } else {
- state.zoneIteMap = {};
- state.zoneItemNum = 0;
- }
- },
- // 添加规则
- ADDRULE(state, data) {
- // @ts-ignore
- state.ruleList.push(data);
- },
- // 添加样式信息
- ADDSTYLE(state, data) {
- // @ts-ignore
- const { id, style } = { ...data };
- // @ts-ignore
- state.styleMap[id] = style;
- },
- // 添加对象实例信息
- // 增加设备实例item
- ADDEQUIP(state, item): void {
- // @ts-ignore
- if (!state.equipItemMap[item.id]) {
- // @ts-ignore
- state.equipItemMap[item.id] = item;
- state.equipItemNum = Object.keys(state.equipItemMap).length;
- }
- },
- // 添加空间实例item
- ADDZONE(state, item): void {
- // @ts-ignore
- if (!state.zoneIteMap[item.id]) {
- // @ts-ignore
- state.zoneIteMap[item.id] = item;
- state.zoneItemNum = Object.keys(state.zoneIteMap).length;
- }
- },
- // 删除实例item
- DELETEITEM(state): void {
- // 如果实例数组中parent 为null 则删除该数组
- let arr1 = Object.keys(state.equipItemMap);
- let arr2 = Object.keys(state.zoneIteMap);
- if (arr1.length) {
- // 如果设备实例不为空
- arr1.forEach((key) => {
- // @ts-ignore
- if (!state.equipItemMap[key].parent) {
- // @ts-ignore
- delete state.equipItemMap[key];
- }
- });
- state.equipItemNum = Object.keys(state.equipItemMap).length;
- } else if (arr2.length) {
- // 如果空间实例不为空
- arr2.forEach((key) => {
- // @ts-ignore
- if (!state.zoneIteMap[key].parent) {
- // @ts-ignore
- delete state.zoneIteMap[key];
- }
- });
- state.zoneItemNum = Object.keys(state.zoneIteMap).length;
- }
- },
- },
- actions: {},
- modules: {},
- });
|