Forráskód Böngészése

添加图片添加和替换功能

liwei 1 éve
szülő
commit
c4de10ee95

+ 35 - 2
src/comm/controllers/appMsgQueen5Ctrl.ts

@@ -9,6 +9,8 @@
 import { EditorModule } from "@/modules/editor/module";
 import { Controller } from "../core/controller";
 import { useCtx } from "../ctx";
+import { queenApi } from "queenjs";
+import { CompImageObj } from "@/modules/editor/components/CompUI/basicUI/Image2";
 export class AppMsgQueen5Controller extends Controller {
 
     editorModule?:EditorModule;
@@ -28,6 +30,14 @@ export class AppMsgQueen5Controller extends Controller {
         recvCtrl.emitChange();
     }
 
+    async uploadImage(url:string) {
+
+        const response = await fetch(url)
+        const blob = await response.blob();
+        const file = await this.editor.controls.uploader.uploadFile(blob, "queenshow");
+        return file.url;
+    }
+
     //重置状态    
     ResetEditor() {
         const { recvCtrl } = useCtx();
@@ -35,8 +45,31 @@ export class AppMsgQueen5Controller extends Controller {
         recvCtrl.addImageListener("添加图片", async (uri:string)=>{
             console.log("添加图片=>", uri);
 
-            alert("收到图片"+uri);
-            
+            queenApi.showLoading("添加图片中")
+            const url = await this.uploadImage(uri)
+            await this.editor.actions.addImageToDesign(url);
+            queenApi.hideLoading();
+
+            return true;
+        })
+        recvCtrl.addImageListener("替换当前图片", async (uri:string)=>{
+            console.log("替换当前图片=>", uri);
+
+            if (this.editor.controls.selectCtrl.gizmo.selectedIds.length != 1) {
+                queenApi.messageError("当前没有选中的图片");
+                return true;
+            }
+
+            queenApi.showLoading("图片替换中")
+            const url = await this.uploadImage(uri) as string;
+
+            const comp = this.editor.controls.pageCtrl.currComp  as CompImageObj;
+            comp.value.url = url;
+            comp.value.x = 0;
+            comp.value.y = 0;
+            comp.value.s = 1;
+            comp.value.matrix = "";
+            queenApi.hideLoading();
             return true;
         })
         recvCtrl.emitChange();

+ 2 - 1
src/modules/editor/components/CompUI/basicUI/Image2/component.tsx

@@ -37,7 +37,8 @@ export const Component = defineComponent({
       try {
         const url = await controls.pickCtrl.pickOneImage();
         if (!url) return;
-
+        console.log("xx->",url);
+        
         comp.value.url = url;
         comp.value.x = 0;
         comp.value.y = 0;