bianjiang 1 tahun lalu
induk
melakukan
cb775c360d

+ 0 - 55
main.js

@@ -1,55 +0,0 @@
-const { app, BrowserWindow, Menu, ipcRenderer } = require("electron");
-
-const createWindow = () => {
-  const win = new BrowserWindow({
-    fullscreen: true,
-    autoHideMenuBar: true,
-  });
-  win.loadFile("./dist/index.html");
-
-  const template = [
-    {
-      label: "文件",
-      submenu: [{ label: "退出", role: "quit" }],
-    },
-    {
-      label: "页面",
-      submenu: [
-        {
-          label: "刷新",
-          role: "reload",
-        },
-        {
-          label: "主页",
-          click: () => {
-            win.loadFile("./dist/index.html", {
-              hash: "/",
-            });
-          },
-        },
-
-        {
-          label: "管理",
-          click: async () => {
-            win.loadFile("./dist/index.html", {
-              hash: "/backend",
-            });
-          },
-        },
-      ],
-    },
-    {
-      label: "开发",
-      submenu: [{ label: "控制台", role: "toggleDevTools" }],
-    },
-  ];
-  const menu = Menu.buildFromTemplate(template);
-  Menu.setApplicationMenu(menu);
-};
-
-app.on("window-all-closed", () => {
-  if (process.platform !== "darwin") app.quit();
-});
-app.whenReady().then(() => {
-  const main = createWindow();
-});

+ 1 - 0
package.json

@@ -39,6 +39,7 @@
     "echarts": "^5.4.0",
     "file-saver": "^2.0.5",
     "hotkeys-js": "^3.10.1",
+    "js-base64": "^3.7.5",
     "jszip": "^3.10.1",
     "load-asset": "^1.2.0",
     "lodash": "^4.17.21",

+ 2 - 0
src/comm/controllers/index.ts

@@ -1,11 +1,13 @@
 import { DeviceController } from "./deviceCtrl";
 import { NatsController } from "./natsCtrl";
+import { ProjectController } from "./lancherPrjCtrl";
 import { CmdSvcController } from "./cmdsvcCtrl";
 import { AppMsgRecvController } from "./appMsgRecvCtrl";
 import { AppMsgController } from "./appMsgCtrl";
 
 export {
   DeviceController,
+  ProjectController,
   NatsController,
   CmdSvcController,
   AppMsgRecvController,

+ 128 - 0
src/comm/controllers/lancherPrjCtrl.ts

@@ -0,0 +1,128 @@
+import { useCtx } from "../ctx";
+import { Controller } from "../core/controller";
+import { Base64 } from "js-base64";
+
+type GetAssetPathFunc = (ext: string) => string;
+
+export class ProjectController extends Controller {
+  RootDir = "";
+  DataDir = "";
+  HostURL = "";
+  _swiftLocal = true;
+  _spu3dFile: any;
+  UserId = "spu3d";
+  NatsProfile = { apiPort: "", wsPort: "", ip: "" };
+
+  async onReady() {
+    // const params = new URLSearchParams(location.search);
+    // const projectPath = params.get("path") as string;
+    // this.RootDir = projectPath;
+    const deviceCtrl = useCtx().deviceCtrl;
+
+    deviceCtrl.GetAppDataDir().then((dir) => {
+      this.DataDir = dir;
+      this.RootDir = dir;
+    });
+
+    // if (!projectPath) {
+    //   deviceCtrl.SetMainTitle("spu3d");
+    //   return;
+    // }
+    // deviceCtrl.SetMainTitle("项目:" + projectPath);
+    // this.HostURL = await deviceCtrl.StartHttpServer(this.RootDir);
+    // console.log("host url=>", this.HostURL);
+    this.NatsProfile = await deviceCtrl.GetNatsProfile();
+
+    console.log("nats profile=>", this.NatsProfile);
+  }
+
+  getOutputDir() {
+    return this.RootDir + "/" + "outputs";
+  }
+  getAppDataDir() {
+    return this.DataDir;
+  }
+  getAppInstallDir() {
+    return this.createPath("installDir");
+  }
+
+  getDefaultLogo() {
+    return this.DataDir + "/static/thumbnail.png";
+  }
+  createPath(fpath: string) {
+    return this.RootDir + "/" + fpath;
+  }
+
+  createBase64Path(fpath: string) {
+    const str = Base64.encode(this.createPath(fpath));
+    console.log("str", str);
+    return str;
+  }
+
+  getSwiftUri(assetPath: string) {
+    if (this._swiftLocal) return this.getLocalAbsoluteUri(assetPath);
+    return this.getHttpAbsoluteUri(assetPath);
+  }
+
+  getHttpAbsoluteUri(url: string) {
+    if (!url) return "";
+    if (url.substring(0, 2) == "//") return "http://" + url;
+    if (url.substring(0, 4) == "http") return url;
+    if (url.charAt(0) == "/") return this.HostURL + url.substring(1);
+    return this.HostURL + url;
+  }
+
+  getLocalAbsoluteUri(url: string) {
+    if (!url) return "";
+    if (url.substring(0, 2) == "//") return "http://" + url;
+    if (url.substring(0, 4) == "http") return url;
+    if (url.charAt(0) == "/") return this.RootDir + url;
+    return this.RootDir + "/" + url;
+  }
+
+  getRelativeUri(url: string) {
+    let s = this.HostURL.length;
+    let pre = url.substring(0, s);
+    if (pre == this.HostURL) return url.substring(s + 1);
+
+    s = this.RootDir.length;
+    pre = url.substring(0, s);
+    if (pre == this.RootDir) return url.substring(s + 1);
+
+    return "";
+  }
+
+  async pickProject() {
+    const deviceCtrl = useCtx().deviceCtrl;
+    const projectDir = await deviceCtrl.SelectDir();
+    if (await this.isProjectExit(projectDir)) {
+      return projectDir;
+    } else {
+      return Promise.reject();
+    }
+  }
+
+  async isProjectExit(dir: string) {
+    const deviceCtrl = useCtx().deviceCtrl;
+    return await deviceCtrl.IsFileExit(`${dir}/project.spu3d`);
+  }
+
+  isProjectFile(fpath: string) {
+    const r = fpath.substring(0, this.RootDir.length);
+    return r == this.RootDir;
+  }
+
+  async copy2Project(fpath: string, getAssetPath: GetAssetPathFunc) {
+    if (this.isProjectFile(fpath)) {
+      return fpath.substring(this.RootDir.length + 1);
+    }
+
+    const ext = fpath.substring(fpath.lastIndexOf("."));
+
+    const assetfpath = getAssetPath(ext);
+
+    await useCtx().deviceCtrl.CopyFile(fpath, this.createPath(assetfpath));
+
+    return assetfpath;
+  }
+}

+ 1 - 0
src/comm/ctx/config.ts

@@ -1,6 +1,7 @@
 import * as Controls from "../controllers";
 const ctx = {
   deviceCtrl: new Controls.DeviceController(),
+  prjCtrl: new Controls.ProjectController(),
   natsCtrl: new Controls.NatsController(),
   recvCtrl: new Controls.AppMsgRecvController(),
   msgCtrl:new Controls.AppMsgController(),

+ 14 - 10
src/modules/list/actions/list.ts

@@ -1,15 +1,19 @@
+import { useCtx } from "@/comm/ctx";
 import ListModule from "..";
 
 export default ListModule.action({
-  async getProfileData() {
-    // const data = await this.controls.bus.requestApi("queentree.local.profile");
-    // console.log(data);
-    // localStorage.setItem("token", JSON.stringify(data.Token));
-    // this.store.baseURL = data.BaseUrl;
-    // this.actions.initExpStorage(data.BaseUrl);
-  },
-  async getAssetList(dbId: string, defineId: string) {
-    const res = await this.https.loadAsset(dbId, defineId, this.store.baseURL);
-    this.store.list = res.result.list;
+  async getAssetList() {
+    const { deviceCtrl, prjCtrl } = useCtx();
+    const installdir = prjCtrl.getAppInstallDir();
+    const jsonDir=`${installdir}/screen/assets.json`
+    try {
+      const listConfig = await deviceCtrl.ReadFileText(jsonDir);
+      if (!listConfig.error && listConfig.text) {
+        const list = JSON.parse(listConfig.text);
+        this.store.list = list;
+      }
+    } catch (e) {
+      console.error(e);
+    }
   },
 });

+ 1 - 1
src/modules/list/actions/load.ts

@@ -61,7 +61,7 @@ export default ListModule.action({
     if (!dbId || !defineId) {
       return;
     }
-    await this.actions.getAssetList(dbId, defineId);
+    await this.actions.getAssetList();
 
     const ps = this.store.list.map((item: ItemObject, index) =>
       loadImg(item.thumbnail, item._id, item.name)

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

@@ -3,7 +3,6 @@ import { ModuleRoot } from "queenjs";
 import actions from "./actions";
 import { https } from "./http";
 import { stores } from "./stores";
-import { NatsController } from "@/comm/controllers/natsCtrl";
 
 export default class ListModule extends ModuleRoot {
   config = this.setConfig({
@@ -20,7 +19,7 @@ export default class ListModule extends ModuleRoot {
   };
 
   onReady() {
-    this.actions.getProfileData();
+    this.actions.getAssetList();
     this.actions.initAnimateAttr();
   }
 }

+ 34 - 36
src/pages/website/routes/backend/List.tsx

@@ -1,10 +1,8 @@
 import { useList } from "@/modules/list";
 import { css } from "@linaria/core";
 import { setQueentreeExplorer } from "@queenjs-modules/queentree-explorer";
-import PickNodeSteps from "@queenjs-modules/queentree-explorer/components/PickNodeSteps";
 import { Image } from "@queenjs/ui";
 import { Button, Space, Table } from "ant-design-vue";
-import Modal from "queenjs/adapter/vue/components/modal";
 import { defineComponent } from "vue";
 
 export default defineComponent({
@@ -28,40 +26,40 @@ export default defineComponent({
     ];
 
     const showFiles = async () => {
-      showModal(
-        <PickNodeSteps
-          onSubmit={(branchArr: any) => {
-            const branch = branchArr[0][0];
-            const dbId = branch.parent?.state.id;
-            const defineId = branch.state.id;
-            localStorage.setItem("dbId", dbId);
-            localStorage.setItem("defineId", defineId);
-            console.log("xxxxxxxxxxxxxxxxx", dbId, defineId);
-            actions.getAssetList(dbId, defineId);
-            Modal.clear();
-          }}
-          lastStepText="选择"
-          steps={[
-            {
-              title: "选择模型库",
-              content: () => {
-                return (
-                  <PickNodeSteps.PickNodeStep
-                    options={{
-                      nodeType: "branch",
-                      childNodeType: "pack",
-                    }}
-                  />
-                );
-              },
-            },
-          ]}
-          expConfig={{ showNodeToolbar: false, nodeListColumns: 6 }}
-        />,
-        {
-          width: "600px",
-        }
-      );
+      // showModal(
+      //   <PickNodeSteps
+      //     onSubmit={(branchArr: any) => {
+      //       const branch = branchArr[0][0];
+      //       const dbId = branch.parent?.state.id;
+      //       const defineId = branch.state.id;
+      //       localStorage.setItem("dbId", dbId);
+      //       localStorage.setItem("defineId", defineId);
+      //       console.log("xxxxxxxxxxxxxxxxx", dbId, defineId);
+      //       actions.getAssetList(dbId, defineId);
+      //       Modal.clear();
+      //     }}
+      //     lastStepText="选择"
+      //     steps={[
+      //       {
+      //         title: "选择模型库",
+      //         content: () => {
+      //           return (
+      //             <PickNodeSteps.PickNodeStep
+      //               options={{
+      //                 nodeType: "branch",
+      //                 childNodeType: "pack",
+      //               }}
+      //             />
+      //           );
+      //         },
+      //       },
+      //     ]}
+      //     expConfig={{ showNodeToolbar: false, nodeListColumns: 6 }}
+      //   />,
+      //   {
+      //     width: "600px",
+      //   }
+      // );
     };
     return () => (
       <div class={ViewStyle}>

+ 1 - 1
src/pages/website/routes/home/index.tsx

@@ -14,7 +14,7 @@ export default defineComponent({
     const rootRef = ref<HTMLElement>();
 
     onMounted(() => {
-      actions.on("getProfileData:success", async () => {
+      actions.on("getAssetList:success", async () => {
         const res = await actions.initListCanvasData(
           rootRef.value?.clientWidth as number,
           rootRef.value?.clientHeight as number

+ 0 - 113
vue.config2.js

@@ -1,113 +0,0 @@
-const modifyVars = require("./src/styles/theme-antd");
-const path = require('path');
-const fs = require('fs');
-const MiniCssExtractPlugin = require('mini-css-extract-plugin');
-
-const getDirectories = (source) =>
-  fs
-    .readdirSync(source, { withFileTypes: true })
-    .filter((dirent) => dirent.isDirectory())
-    .map((dirent) => dirent.name);
-
-const getAlias = (alias, path) => {
-  const aliases = {};
-  const dirs = getDirectories(path);
-  dirs.forEach((dir) => (aliases[`${alias}/${dir}`] = `${path}/${dir}`));
-  return aliases;
-};
-const aliases = getAlias('@', path.resolve(__dirname, './src'));
-
-module.exports = {
-  publicPath: "./",
-  // process.env.NODE_ENV === 'production'
-  //   ? `//infishwaibao.oss-cn-chengdu.aliyuncs.com/bess/`
-  //   : './',
-  lintOnSave: false,
-  pages: {
-    index: {
-      entry: 'src/pages/website/main.ts',
-      template: 'public/index.html',
-      filename: 'index.html',
-      chunks: ['chunk-vendors', 'chunk-common', 'index']
-    },
-    frame3d: {
-      entry: 'src/pages/frame3d/main.ts',
-      template: 'public/index.html',
-      filename: 'frame3d.html',
-      chunks: ['chunk-vendors', 'chunk-common', 'frame3d']
-    },
-  },
-  css: {
-    loaderOptions: {
-      less: {
-        lessOptions: {
-          modifyVars,
-          javascriptEnabled: true,
-        },
-      },
-    },
-  },
-  chainWebpack: (config) => {
-    // if (process.env.NODE_ENV === 'production') {
-    //   config.plugin('extract-css').tap((args) => {
-    //     args[0].ignoreOrder = true;
-    //     return args;
-    //   });
-    //   config.optimization.minimizer('terser').tap(args => {
-    //     Object.assign(args[0].terserOptions.compress, {
-    //       pure_funcs: ['console.log']
-    //     })
-    //     return args
-    //   })
-    // }
-    const tsRule = config.module.rule("ts");
-    tsRule
-      .use("moduse-loader")
-      .loader("moduse/webpack-loader")
-      .options({
-        include: [
-          path.resolve(__dirname, "./src/modules"),
-          path.resolve(__dirname, "./node_modules/@queenjs-modules"),
-        ],
-      });
-  },
-  configureWebpack: {
-    module: {
-      rules: [
-        {
-          test: /\.(tsx)$/,
-          use: [
-            {
-              loader: '@linaria/webpack-loader',
-              options: {
-                sourceMap: process.env.NODE_ENV !== 'production',
-                babelOptions: {
-                  plugins: [
-                    [
-                      'babel-plugin-module-resolver',
-                      {
-                        root: ['.'], //the value mentioned in the path section of the `tsconfig.json based on your CWD`
-                        extensions: ['.tsx', '.ts'],
-                        alias: aliases, //The important part!!
-                      },
-                    ],
-                  ],
-                },
-              },
-            },
-          ],
-        }, {
-          test: /\.svga$/,
-          use: [{ loader: 'file-loader' }],
-        },
-        {
-          test: /\.(frag|vert|glsl)$/,
-          use: [{ loader: 'raw-loader' }],
-        }, {
-          test: /\.(glb)$/,
-          use: [{ loader: 'url-loader' }],
-        },
-      ],
-    },
-  },
-};

+ 5 - 0
yarn.lock

@@ -4874,6 +4874,11 @@ js-base64@^2.5.2:
   resolved "http://124.70.149.18:4873/js-base64/-/js-base64-2.6.4.tgz"
   integrity sha512-pZe//GGmwJndub7ZghVHz7vjb2LgC1m8B07Au3eYqeqv9emhESByMXxaEgkUkEqJe87oBbSniGYoQNIBklc7IQ==
 
+js-base64@^3.7.5:
+  version "3.7.5"
+  resolved "http://124.70.149.18:4873/js-base64/-/js-base64-3.7.5.tgz#21e24cf6b886f76d6f5f165bfcd69cc55b9e3fca"
+  integrity sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==
+
 js-message@1.0.7:
   version "1.0.7"
   resolved "http://124.70.149.18:4873/js-message/-/js-message-1.0.7.tgz"