Prechádzať zdrojové kódy

添加webpackuri数据的接收

liwei 1 rok pred
rodič
commit
8fe2f1deb8

+ 9 - 0
src/comm/controllers/appMsgQueen5Ctrl.ts

@@ -72,6 +72,15 @@ export class AppMsgQueen5Controller extends Controller {
             queenApi.hideLoading();
             return true;
         })
+        recvCtrl.addWebpackuriListener("添加3D组件", async (url:string, name:string, thumbnail:string)=>{
+            console.log("url", url, name, thumbnail);
+
+            await this.editor.actions.clickCompToDesign("Web3D", (comp) => {
+                comp.value.url = url;
+                comp.value.poster = thumbnail;
+            });
+            return true;
+        })
         recvCtrl.emitChange();
     }
 }

+ 26 - 4
src/comm/controllers/appMsgRecvCtrl.ts

@@ -6,7 +6,9 @@ import { Controller } from "../core/controller";
 import { useCtx } from "../ctx";
 
 export type AssetSendedCallback = (assetUri:string)=>Promise<boolean>;
-export type AssetType = "empty" | "image"
+export type AssetWebpackUriSendedCallback = (uri:string, name:string, thumbnail:string)=>Promise<boolean>;
+
+export type AssetType = "empty" | "image" | "webpackuri"
 const RevcChangeEvent = "app.recv.change"
 class AssetListener {
     id = "";
@@ -35,14 +37,22 @@ export class AppMsgRecvController extends Controller {
 
         this.appGuid = deviceCtrl.profile.appGuid;
 
-        natsCtrl.subscribe(`send.${this.appGuid}`, async (msg:{id:string,fromKey:string, uri:string,name?:string, thumbnail?:string})=>{
+        natsCtrl.subscribe(`send.${this.appGuid}`, async (msg:{id:string,fromKey:string, uri:string, name?:string, thumbnail?:string})=>{
             const listen = this.listeners.find(item=>item.id == msg.id)
             if (!listen) return {
                 isOk: false,
                 error: "nolistener"
             }
-            const ok = await listen.callback(msg.uri);
-            return JSON.stringify({ isOk: ok})
+            if (listen.type == "image") {
+                const callback = listen.callback as AssetSendedCallback
+                const ok = await callback(msg.uri);
+                return JSON.stringify({ isOk: ok})
+            } 
+            if (listen.type == "webpackuri" ) {
+                const callback = listen.callback as AssetWebpackUriSendedCallback
+                const ok = await callback(msg.uri, msg.name as string, msg.thumbnail as string);
+                return JSON.stringify({ isOk: ok})
+            }
         })
 
         natsCtrl.subscribe(`recv.actions.${this.appGuid}`, async ()=>{
@@ -73,6 +83,18 @@ export class AppMsgRecvController extends Controller {
         this.listeners.push(listen);
     }
 
+     //添加webpackUri听者
+     addWebpackuriListener(actionName:string, handle: AssetWebpackUriSendedCallback) {
+        let listen = this.listeners.find(item=>item.actionName == actionName);
+        if (listen)  {
+            listen.callback = handle as any;
+            return listen.id;
+        }
+        listen = new AssetListener(actionName, handle as any)
+        listen.type = "webpackuri";
+        this.listeners.push(listen);
+    }
+    
     removeListener(id:string) {
         let listen = this.listeners.find(item=>item.id == id);
         if (!listen)  {