Bläddra i källkod

feat(draw): api

gemercheung 1 år sedan
förälder
incheckning
cd7fc984c0
2 ändrade filer med 27 tillägg och 2 borttagningar
  1. 6 0
      src/core/player/Player.js
  2. 21 2
      src/view/case/photos/index.vue

+ 6 - 0
src/core/player/Player.js

@@ -247,6 +247,7 @@ export default class Player {
     if (this.mode === 2) {
       // this.drawing = false;
     }
+    this.syncDrawData();
   };
 
   Listener = {
@@ -404,6 +405,11 @@ export default class Player {
     // console.log("sceneType", this.scene.sceneType);
     return data;
   }
+
+  syncDrawData() {
+    const data = this.getDrawData();
+    this.scene.emit("data", data);
+  }
   load(type, data) {
     if (type === 1) {
       console.log("data1", data);

+ 21 - 2
src/view/case/photos/index.vue

@@ -25,8 +25,13 @@
         <el-button @click="handleMark">标注方向</el-button>
         <el-button @click="handleLine">标注连线</el-button>
         <el-button @click="handleSave" type="success">保存</el-button>
+        <!-- 
+        <el-button @click="handleClear" v-if="hasDrawData" type="warning"
+          >清空</el-button
+        > -->
+
         <el-button @click="handleFree" v-if="isShowExitEdit" type="warning"
-          >退出</el-button
+          >退出编辑</el-button
         >
       </div>
       <swiper
@@ -85,7 +90,7 @@ const sortType = ref(false);
 const drawMode = ref(0);
 const isShowExitEdit = computed(() => drawMode.value > 0);
 import { ElMessage } from "element-plus";
-
+const hasDrawData = ref(false);
 let scene = null;
 
 const addCaseFileHandler = async () => {
@@ -140,6 +145,14 @@ const renderCanvas = () => {
   scene.on("markerExist", () => {
     ElMessage.error("该案件已有方向标注!");
   });
+  scene.on("data", (data) => {
+    console.log("sync", data);
+    Object.keys(data).forEach((key) => {
+      if (Array.isArray(data[key]) && data[key].length > 0) {
+        hasDrawData.value = true;
+      }
+    });
+  });
 };
 const onSwiper = (swiper) => {
   console.log("onSwiper");
@@ -189,6 +202,12 @@ const handleFree = () => {
     window.scene.player.setMode(0);
   }
 };
+const handleClear = () => {
+  if (window.scene) {
+    window.scene.player.reset();
+  }
+};
+
 onMounted(() => {
   renderCanvas();
 });