|
@@ -25,7 +25,8 @@ import {
|
|
|
// import { SFloorParser } from "@persagy-web/big/lib";
|
|
|
import topoTooltip from "./topoTooltip.vue";
|
|
|
import { mapState, mapMutations } from "vuex";
|
|
|
-import base64ToFile from "@/utils/base64ToFile";
|
|
|
+import base64ToFile from "@/utils/base64ToFile"
|
|
|
+import { v1 as uuidv1 } from "uuid";
|
|
|
import bus from "@/bus/bus";
|
|
|
import {
|
|
|
saveGroup,
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
getImageGroup,
|
|
|
readPubGroup,
|
|
|
} from "@/api/editer";
|
|
|
+import { publishGraph } from "@/api/home"
|
|
|
export default {
|
|
|
components: { topoTooltip },
|
|
|
data() {
|
|
@@ -116,93 +118,68 @@ export default {
|
|
|
//初始化bus绑定事件
|
|
|
initBusEvent() {
|
|
|
// 改变样式
|
|
|
+ bus.$off('updateStyle');
|
|
|
bus.$on("updateStyle", (type, val) => {
|
|
|
this.scene.updateStyle(type, val);
|
|
|
});
|
|
|
// 撤销
|
|
|
+ bus.$off('topoUndo');
|
|
|
bus.$on("topoUndo", (val) => {
|
|
|
this.scene.undo();
|
|
|
});
|
|
|
// 重做
|
|
|
+ bus.$off('topoRedo');
|
|
|
bus.$on("topoRedo", (val) => {
|
|
|
this.scene.redo();
|
|
|
});
|
|
|
// 删除
|
|
|
+ bus.$off('deleteItem');
|
|
|
bus.$on("deleteItem", (val) => {
|
|
|
this.scene.deleteItem();
|
|
|
});
|
|
|
// 复制
|
|
|
+ bus.$off('copy');
|
|
|
bus.$on("copy", (val) => {
|
|
|
this.scene.copy();
|
|
|
});
|
|
|
// 粘贴
|
|
|
+ bus.$off('paste');
|
|
|
bus.$on("paste", (val) => {
|
|
|
this.scene.paste();
|
|
|
});
|
|
|
// 保存
|
|
|
+ bus.$off('saveTopo');
|
|
|
bus.$on("saveTopo", (val) => {
|
|
|
- const elements = this.scene.save();
|
|
|
- const obj = {
|
|
|
- elements,
|
|
|
- name: this.topoContent.name, // 名称
|
|
|
- categoryId: this.categoryId, // 图分类ID
|
|
|
- projectId: this.projectId, // 项目ID
|
|
|
- label: this.topoContent.label,
|
|
|
- buildingId: "1", // 建筑ID
|
|
|
- floorId: "1", // 楼层id
|
|
|
- note: "1", // 图说明
|
|
|
- log: {
|
|
|
- // 图操作日志
|
|
|
- mark: "1", // 图的存盘标记
|
|
|
- commandList: [
|
|
|
- {
|
|
|
- command: "1", // 命令
|
|
|
- desc: "1", // 描述
|
|
|
- detail: "1", // 详情
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- };
|
|
|
- Object.assign(obj, {
|
|
|
- graphId: this.graphId,
|
|
|
- id: this.id,
|
|
|
- });
|
|
|
- saveGroup(obj).then((res) => {
|
|
|
- // 如果是从已发布跳转过来
|
|
|
- if (this.isPub == 1) {
|
|
|
- // 设置发布状态为 未发布
|
|
|
- this.SETISPUB(0);
|
|
|
- const gid = res.entityList[0].graphId;
|
|
|
- const id = res.entityList[0].id;
|
|
|
- // 重设图id 与 id
|
|
|
- this.SETPROJECT({ graphId: gid, id: id });
|
|
|
- // 修改url参数
|
|
|
- this.$router.push({
|
|
|
- name: "Editer",
|
|
|
- query: {
|
|
|
- graphId: gid,
|
|
|
- id: id,
|
|
|
- categoryName: encodeURI(this.categoryName),
|
|
|
- isPub: 0,
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
- this.$message.success(`保存成功${res.entityList[0].version}`);
|
|
|
- });
|
|
|
+ this.saveTopoDraft()
|
|
|
});
|
|
|
// 设置实例置顶置底
|
|
|
+ bus.$off('setOrder');
|
|
|
bus.$on("setOrder", (val) => {
|
|
|
this.scene.setOrder(val);
|
|
|
});
|
|
|
// 设置实例status状态
|
|
|
+ bus.$off('setItemStatus');
|
|
|
bus.$on("setItemStatus", (val) => {
|
|
|
this.scene.setItemStatus();
|
|
|
});
|
|
|
// 下载图片
|
|
|
+ bus.$off('saveTopoImg');
|
|
|
bus.$on("saveTopoImg", () => {
|
|
|
- this.view.saveImage(`${this.topoContent.name}.png`, "png");
|
|
|
+ // 隐藏选择器
|
|
|
+ this.scene.selectContainer.clear();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.view.saveImage(`${this.topoContent.name}.png`, "png");
|
|
|
+ },80)
|
|
|
+ });
|
|
|
+ // 发布图片
|
|
|
+ bus.$off('issueTopo');
|
|
|
+ bus.$on("issueTopo", () => {
|
|
|
+ this.saveTopoDraft().then(() => {
|
|
|
+ this.issueDraft()
|
|
|
+ })
|
|
|
});
|
|
|
// 手动添加设备实例
|
|
|
+ bus.$off('addEquipment');
|
|
|
bus.$on("addEquipment", (val) => {
|
|
|
this.addEquipmentList(val);
|
|
|
});
|
|
@@ -244,6 +221,111 @@ export default {
|
|
|
});
|
|
|
this.view.fitSceneToView();
|
|
|
},
|
|
|
+ // 保存草稿
|
|
|
+ saveTopoDraft(){
|
|
|
+ const uuid = uuidv1();
|
|
|
+ return Promise.all([this.generateSnap(uuid), this.saveDraft(uuid)]).then(vals => {
|
|
|
+ this.$message.success(`保存成功${vals[1].version}`);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 生成快照
|
|
|
+ generateSnap(uuid) {
|
|
|
+ // 隐藏选择器
|
|
|
+ this.scene.selectContainer.clear();
|
|
|
+ setTimeout(() => {
|
|
|
+ // base64数据
|
|
|
+ const data = this.view.imageUrl('png');
|
|
|
+ // 根据base64生成file
|
|
|
+ const file = base64ToFile(data);
|
|
|
+ const reader = new FileReader();
|
|
|
+ const fileType = file.name.split(".");
|
|
|
+ const imgType = fileType[fileType.length - 1];
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ reader.onloadend = function () {
|
|
|
+ // 这个事件在读取结束后,无论成功或者失败都会触发
|
|
|
+ if (reader.error) {
|
|
|
+ console.log('reader error', reader.error);
|
|
|
+ reject(reader.error)
|
|
|
+ } else {
|
|
|
+ // 构造 XMLHttpRequest 对象,发送文件 Binary 数据
|
|
|
+ const xhr = new XMLHttpRequest();
|
|
|
+ xhr.open("POST", `/image-service/common/image_upload?systemId=dataPlatform&secret=9e0891a7a8c8e885&overwrite=true&key=${uuid}.${imgType}`);
|
|
|
+ xhr.send(reader.result);
|
|
|
+ xhr.onreadystatechange = function () {
|
|
|
+ if (xhr.readyState == 4) {
|
|
|
+ if (xhr.status == 200) {
|
|
|
+ resolve(xhr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ };
|
|
|
+ reader.readAsArrayBuffer(file);
|
|
|
+ })
|
|
|
+ },80)
|
|
|
+ },
|
|
|
+ // 保存草稿
|
|
|
+ saveDraft(uuid) {
|
|
|
+ const elements = this.scene.save();
|
|
|
+ const obj = {
|
|
|
+ elements,
|
|
|
+ name: this.topoContent.name, // 名称
|
|
|
+ categoryId: this.categoryId, // 图分类ID
|
|
|
+ projectId: this.projectId, // 项目ID
|
|
|
+ label: this.topoContent.label,
|
|
|
+ buildingId: "1", // 建筑ID
|
|
|
+ floorId: "1", // 楼层id
|
|
|
+ note: "1", // 图说明
|
|
|
+ pic: `${uuid}.png`,
|
|
|
+ graphId: this.graphId,
|
|
|
+ id: this.id,
|
|
|
+ log: {
|
|
|
+ // 图操作日志
|
|
|
+ mark: "1", // 图的存盘标记
|
|
|
+ commandList: [
|
|
|
+ {
|
|
|
+ command: "1", // 命令
|
|
|
+ desc: "1", // 描述
|
|
|
+ detail: "1", // 详情
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ saveGroup(obj).then((res) => {
|
|
|
+ // 如果是从已发布跳转过来
|
|
|
+ if (this.isPub == 1) {
|
|
|
+ // 设置发布状态为 未发布
|
|
|
+ this.SETISPUB(0);
|
|
|
+ const gid = res.entityList[0].graphId;
|
|
|
+ const id = res.entityList[0].id;
|
|
|
+ // 重设图id 与 id
|
|
|
+ this.SETPROJECT({ graphId: gid, id: id });
|
|
|
+ // 修改url参数
|
|
|
+ this.$router.push({
|
|
|
+ name: "Editer",
|
|
|
+ query: {
|
|
|
+ graphId: gid,
|
|
|
+ id: id,
|
|
|
+ categoryName: encodeURI(this.categoryName),
|
|
|
+ isPub: 0,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ resolve(res.entityList[0])
|
|
|
+ });
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 发布草稿
|
|
|
+ issueDraft(){
|
|
|
+ const pa = {
|
|
|
+ graphId: this.graphId,
|
|
|
+ id: this.id
|
|
|
+ }
|
|
|
+ publishGraph(pa).then(res => {
|
|
|
+ this.$message.success('发布成功');
|
|
|
+ })
|
|
|
+ },
|
|
|
// 手动添加设备
|
|
|
addEquipmentList(list) {
|
|
|
const parse = new PTopoParser();
|
|
@@ -279,8 +361,6 @@ export default {
|
|
|
this.view.fitSceneToView();
|
|
|
});
|
|
|
},
|
|
|
- // 生成快照
|
|
|
- generateSnap() {},
|
|
|
},
|
|
|
watch: {
|
|
|
editCmd(val) {
|