bianjiang 2 年之前
父节点
当前提交
c58be660ef

+ 1 - 1
package.json

@@ -1,5 +1,5 @@
 {
-  "name": "queen.cloud",
+  "name": "screen.show",
   "version": "0.0.1",
   "private": true,
   "scripts": {

+ 150 - 0
src/controllers/natsController.ts

@@ -0,0 +1,150 @@
+import { queenApi } from "queenjs";
+import { connect, StringCodec, Empty, ErrorCode } from "nats.ws";
+
+export class BusController {
+  _params = new URLSearchParams(decodeURIComponent(location.search));
+
+  _conn: any;
+  _isConned = false;
+  _startInit = false;
+
+  getQuery(name: string): string {
+    return this._params.get(name) as string;
+  }
+
+  async init(host?: string) {
+    if (this._startInit) return;
+    this._startInit = true;
+
+    queenApi.showLoading("服务连接中...");
+    const wsHost = host ? host : this.getQuery("host");
+    let ret = false;
+    try {
+      this._conn = await connect({ servers: wsHost });
+      this._isConned = !!this._conn;
+
+      ret = true;
+    } catch (error) {
+      console.log(error);
+      queenApi.messageError("连接失败!");
+    }
+    queenApi.hideLoading();
+    this._startInit = false;
+
+    return ret;
+  }
+
+  async subscribe(subject: string, callback: any) {
+    if (!this._isConned) {
+      await this.init();
+    }
+
+    if (!this._isConned) {
+      console.error("建立连接失败");
+      return;
+    }
+
+    const sc = StringCodec();
+    const sub = this._conn.subscribe(subject);
+    console.log(sub);
+
+    (async () => {
+      for await (const m of sub) {
+        console.log(sub);
+
+        const ret = sc.decode(m.data);
+        console.log(subject, "=>recieved");
+        try {
+          if (ret) {
+            const msg = JSON.parse(ret);
+            callback(msg);
+          } else {
+            callback(ret);
+          }
+        } catch (error) {
+          console.log(subject, "=>recieved json parse eror", ret);
+          console.log(error);
+        }
+      }
+      console.log(subject, "subscription closed");
+    })();
+    return function () {
+      sub.unsubscribe();
+    };
+  }
+  async requestApi(subject: string, data?: any, timeout?: number) {
+     const ret = await this.request(subject, data, timeout)
+     if (ret.error || ret.result.ErrorNo != 200 ) {
+       queenApi.messageError(ret.error || ret.result.ErrorDesc );
+       return
+     }
+     try {
+        const retJson = ret.result.Result;
+        if (!retJson) return;
+        if (retJson[0] != '{' && retJson[0] != '[') return retJson;
+        return JSON.parse(retJson)
+     } catch (error) {
+        console.log( ret );
+        console.error(error);
+     }
+  }
+  
+  async request(subject: string, data?: any, timeout?: number) {
+    if (!this._isConned) {
+      await this.init();
+    }
+
+    const ret: { error: string; result: any } = { error: "", result: null };
+    if (!this._isConned) {
+      console.error("建立连接失败");
+      ret.error = "建立连接失败";
+
+      queenApi.showConfirm({
+        title: "数据请求失败",
+        content: "请求数据失败,请重新启动后再试",
+        type: "danger",
+      });
+      return ret;
+    }
+
+    const sc = StringCodec();
+    try {
+      let req = Empty;
+      if (data) {
+        if (typeof data != "string") {
+          req = sc.encode(JSON.stringify(data));
+        } else {
+          req = sc.encode(data);
+        }
+      }
+      const options = { timeout: 5000 };
+      if (timeout) {
+        options.timeout = timeout;
+      }
+      const m = await this._conn.request(subject, req, options);
+      let payload = sc.decode(m.data);
+      try {
+        payload = JSON.parse(payload);
+        console.log("m=>", payload);
+      } catch (error) {
+        console.log(error);
+      }
+      ret.result = payload;
+    } catch (error: any) {
+      console.error(error);
+      ret.error = error.message || "请求" + subject + "出错";
+      if (ret.error == "503") {
+        //NoResponders
+        ret.error = "网路异常,请重新服务";
+      }
+    }
+    return ret;
+  }
+
+  close() {
+    if (!this._isConned) {
+      return;
+    }
+    return this._conn.close();
+  }
+}

+ 2 - 1
src/modules/list/actions/index.ts

@@ -1,7 +1,8 @@
 import dialog from "./dialog";
 import load from "./load";
+import list from "./list";
 
 import canvas from "./canvas";
 import animate from "./animate";
 
-export default [load, dialog, canvas, animate];
+export default [load, dialog, canvas, animate,list];

+ 9 - 0
src/modules/list/actions/list.ts

@@ -0,0 +1,9 @@
+import ListModule from "..";
+
+export default ListModule.action({
+  getListData() {
+    this.controls.bus.requestApi("queentree.local.profile").then((list) => {
+      console.log(list);
+    });
+  },
+});

+ 3 - 2
src/modules/list/index.ts

@@ -3,7 +3,7 @@ import { ModuleRoot } from "queenjs";
 import actions from "./actions";
 import { https } from "./http";
 import { stores } from "./stores";
-
+import { BusController } from "@/controllers/natsController";
 export default class ListModule extends ModuleRoot {
   config = this.setConfig({
     httpConfig: {
@@ -14,11 +14,12 @@ export default class ListModule extends ModuleRoot {
   actions = this.createActions(actions);
   https = this.createHttps([https]);
   controls = {
+    bus: new BusController(),
     backendList: new PageListController(this.config.httpConfig),
   };
 
   onReady() {
-    this.controls.backendList.setCrudPrefix("/antique");
+    this.actions.getListData();
     this.actions.initAnimateAttr();
   }
 }

+ 5 - 20
src/pages/website/routes/backend/List.tsx

@@ -10,11 +10,6 @@ export default defineComponent({
   setup() {
     const { store, showModal } = useList();
     const columns = [
-      {
-        title: "文物名称",
-        dataIndex: "name",
-        key: "name",
-      },
       {
         title: "封面图",
         dataIndex: "thumbnail",
@@ -24,26 +19,16 @@ export default defineComponent({
         },
       },
       {
-        title: "展示形式",
-        dataIndex: "type",
-        key: "type",
-        customRender: ({ text }: any) => {
-          switch (text) {
-            case "img":
-              return "图片";
-            case "video":
-              return "视频";
-            case "3D":
-              return "模型";
-          }
-        },
+        title: "模型名称",
+        dataIndex: "name",
+        key: "name",
       },
     ];
 
     return () => (
       <div class={ViewStyle}>
         <div class="table_header">
-          <div class="title">文物列表</div>
+          <div class="title">模型列表</div>
           <div>
             <Space>
               <Button
@@ -53,7 +38,7 @@ export default defineComponent({
                   console.log(1);
                 }}
               >
-                导入资源
+                导入模型
               </Button>
             </Space>
           </div>

+ 4 - 4
src/pages/website/routes/backend/index.tsx

@@ -25,8 +25,8 @@ export default defineComponent({
         <Form {...layout} class={"setting_form"} onSubmit={submit}>
           <Form.Item label="滚动方向">
             <Radio.Group v-model={[formState.scrollType, "value"]}>
-              <Radio.Button value="horizontal">横向</Radio.Button>
-              <Radio.Button value="vertical">纵向</Radio.Button>
+              <Radio.Button value="horizontal">横向滚动</Radio.Button>
+              <Radio.Button value="vertical">纵向滚动</Radio.Button>
             </Radio.Group>
           </Form.Item>
           <Form.Item label="滚动条数">
@@ -43,13 +43,13 @@ export default defineComponent({
               step={1}
             />
           </Form.Item>
-          <Form.Item label="滚动速度">
+          {/* <Form.Item label="滚动速度">
             <InputNumber
               v-model={[formState.scrollSpeed, "value"]}
               min={1}
               step={1}
             />
-          </Form.Item>
+          </Form.Item> */}
           <Form.Item wrapperCol={{ offset: 6, span: 18 }}>
             <Button type="primary" htmlType="submit">
               保存设置