Browse Source

add vjson extract

zhoucg 1 year ago
parent
commit
0b1785db6f
8 changed files with 77 additions and 45 deletions
  1. 7 0
      src/api/ApiUrlConstant.ts
  2. 25 0
      src/api/index.ts
  3. 0 1
      src/globalConfig.ts
  4. 5 1
      src/initialize.ts
  5. 0 1
      src/main.ts
  6. 0 41
      src/router.ts
  7. 32 0
      src/utils/BusinessDesignExtractor.ts
  8. 8 1
      vite.config.ts

+ 7 - 0
src/api/ApiUrlConstant.ts

@@ -0,0 +1,7 @@
+export default class ApiUrlConstant {
+
+    private static readonly BASIC_PATH: string = '/wms_api/print'
+
+    public static readonly getResourceByIdUrl: string = ApiUrlConstant.BASIC_PATH + '/com/galaxis/wms/print/CommonManager@getResourceById'
+
+}

+ 25 - 0
src/api/index.ts

@@ -0,0 +1,25 @@
+import {request} from "@/utils/request";
+import ApiUrlConstant from "@/api/ApiUrlConstant";
+
+export default class Api {
+
+    private static getContextPath() {
+        return '';
+    }
+
+    private static request<T = any>(url: string, args: any = {}): Promise<T> {
+        return request.invoke(Api.getContextPath() + url, [args], {
+            headers: {
+                'Accept': 'application/json, */*',
+                'Content-Type': 'application/json',
+                'cache': 'default',
+                'x-ajax': 'true'
+            }
+        })
+    }
+
+    public static async getResourceById(resourceId) {
+        const params = {pageCode: resourceId};
+        return Api.request(ApiUrlConstant.getResourceByIdUrl, params);
+    }
+}

+ 0 - 1
src/globalConfig.ts

@@ -1,5 +1,4 @@
 import {router} from "@/router";
-import ElementUtils from "@/utils/ElementUtils";
 import {AxiosInstance, AxiosRequestConfig} from "axios";
 
 const httpStatus = {

+ 5 - 1
src/initialize.ts

@@ -1,5 +1,6 @@
-import * as Icons from '@ant-design/icons-vue'
+import * as Icons from '@ant-design/icons-vue';
 import ElementUtils from "@/utils/ElementUtils";
+import BusinessDesignExtractor from "@/utils/BusinessDesignExtractor";
 
 export default {
     install: (app, options) => {
@@ -7,5 +8,8 @@ export default {
             app.component(i, Icons[i])
         }
         ElementUtils.initElementBandCode();
+        BusinessDesignExtractor.getComponentVJson('314300107333828791').then((vjson) => {
+            console.log('vjson >>>', vjson)
+        });
     }
 }

+ 0 - 1
src/main.ts

@@ -5,7 +5,6 @@ import '@/style.css'
 import '@/assets/style/main.less'
 import '@/assets/style/variable.css'
 import 'element-plus/theme-chalk/index.css'
-
 import App from '@/App.vue'
 import elements from "@/components/elements"
 import initialize from "@/initialize"

+ 0 - 41
src/router.ts

@@ -1,52 +1,12 @@
-import lodash from "lodash"
 import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router'
-import typeUtils from './utils/typeUtils'
 
 // 基本页面
 const basePages = {
-    empty: () => import('@/components/Empty.vue'),
     design: () => import('@/pages/Design.vue'),
     studio: () => import('@/pages/Studio.vue'),
     404: () => import('@/components/NotFound.vue'),
 }
 
-// 利用vite扫描所有的页面组件 | /src/pages/Demo.vue -> import('/src/pages/Demo.vue') -> Module.default
-const imports = import.meta.glob(
-    ['@/pages/**/*.vue'],
-    {eager: false},
-);
-const pages = {};
-lodash.forEach(imports, (cmp, key: string) => {
-    let component = cmp;
-    if (typeUtils.variableTypeOf(cmp) === typeUtils.typeEnum.function) {
-        component = async () => {
-            return cmp().then((module: any) => {
-                // console.log("@@@", menu.pagePath)
-                if (module?.default) module.default.__filename = key;
-                return module;
-            });
-        };
-    }
-    pages[key] = component;
-});
-window['pages'] = pages
-
-const designJS = {};
-lodash.forEach(pages, (value, key: string) => {
-    if (key.startsWith("/src/pages")) {
-        key = key.substring(11, key.length - 4);
-    }
-    designJS[key] = async () => {
-        const module: any = await value();
-        let vjson = {};
-        if (lodash.isFunction(module?.default?.mixins[0]?.data)) {
-            vjson = module.default.mixins[0].data().vjson || {};
-        }
-        return vjson;
-    };
-});
-window['designJS'] = designJS
-
 /** 获取路由数据 */
 async function getRoutes(): Promise<RouteRecordRaw[]> {
     const routes: RouteRecordRaw[] = [];
@@ -87,7 +47,6 @@ async function initRouter() {
 }
 
 export {
-    pages,
     initRouter,
     router,
 };

+ 32 - 0
src/utils/BusinessDesignExtractor.ts

@@ -0,0 +1,32 @@
+import Api from "@/api";
+import lodash from 'lodash';
+
+export default class BusinessDesignExtractor {
+
+    private static readonly BUSINESS_DESIGN_BASIC_PATH: string = '/node_modules/wms-ui-pc/src/pages/';
+
+    private static readonly BUSINESS_DESIGN_SUFFIX: string = '.design.js';
+
+    /**
+     * 通过动态import design.js 可以获取vjson, 解析vjson数据aggrid column列表, 获取表格字段&数据源
+     * @param menuId
+     */
+    public static async getComponentVJson(menuId) {
+        const resource = await Api.getResourceById(menuId)
+        if (!resource || !resource?.data) {
+            return {};
+        }
+        const design = await import(BusinessDesignExtractor.getDesignJsPath(resource?.data?.menu_url));
+        if (!design) {
+            return {};
+        }
+        if (lodash.isFunction(design?.default?.data)) {
+            return design.default.data().vjson || {};
+        }
+        return {};
+    }
+
+    private static getDesignJsPath(designPath) {
+        return BusinessDesignExtractor.BUSINESS_DESIGN_BASIC_PATH + designPath + BusinessDesignExtractor.BUSINESS_DESIGN_SUFFIX;
+    }
+}

+ 8 - 1
vite.config.ts

@@ -37,7 +37,14 @@ export default defineConfig({
         host: true,
         port: 5170,
         proxy: {
-
+            '^/wms_api/print/.*': {
+                target: 'http://localhost:9085',
+                changeOrigin: false,
+            },
+            '^/wms_api/.*': {
+                target: 'http://localhost:9085',
+                changeOrigin: false,
+            },
         }
     }
 })