Преглед на файлове

修复低代码引擎的BUG.

杨志杰 преди 3 години
родител
ревизия
78710a3675
променени са 3 файла, в които са добавени 91 реда и са изтрити 13 реда
  1. 27 0
      src/api/dic/LowcodeWindowResource.js
  2. 57 8
      src/lowcode/LowcodeConfig.js
  3. 7 5
      src/lowcode/LowcodePage.js

+ 27 - 0
src/api/dic/LowcodeWindowResource.js

@@ -37,4 +37,31 @@ export default {
       });
     });
   },
+
+  uniqueByNo: function(lowcodeWindowNo){
+    var requestUrl = 'api/LowcodeWindowEditResource/uniqueByNo?lowcodeWindowNo='+lowcodeWindowNo;
+
+
+    return new Promise((resolve, reject) => {
+      $.ajax({
+        url: Common.getApiUrl2(requestUrl),
+        type: 'get',
+        contentType: 'application/json',
+				
+				
+				
+				
+        beforeSend: function(request) {
+          Common.addTokenToRequest(request);
+        },
+        success: function(data) {
+          resolve(data);
+        },
+        error: function(XMLHttpRequest, textStatus, errorThrown) {
+          reject(XMLHttpRequest);
+        },
+      });
+    });
+  },
+
 };

+ 57 - 8
src/lowcode/LowcodeConfig.js

@@ -19,11 +19,34 @@ const getProjectSchema = async lowcodeWindowNo => {
   }
 };
 
+
+/**
+ * 从服务器端获取 Lowcode Window
+ * @param {*} lowcodeWindowNo 
+ * @returns 
+ */
+const getLowcodeWidnow = async lowcodeWindowNo => {
+  let baseObjectResponse = await LowcodeWindowResource.uniqueByNo(lowcodeWindowNo);
+  
+  if(baseObjectResponse.errorCode === 0){
+    return baseObjectResponse.data;
+  }else{
+    Notify.error('提示', baseObjectResponse.errorMessage, false);
+    return null;
+  }
+};
+
 const init = async lowcodeWindowNo => {
-  const packages = [{'package':'lowcode-engine-vue-material-dashboard','version':'1.0.0','library':'lowcode-engine-vue-material-dashboard','urls':['http://127.0.0.1:9002\\index.js']}];
+  // const packages = [{'package':'lowcode-engine-vue-material-dashboard','version':'1.0.0','library':'lowcode-engine-vue-material-dashboard',
+  // 'urls':['http://127.0.0.1:9002\\index.js']}];
   // const packages = JSON.parse(window.localStorage.getItem('packages') || '[]');
   // const projectSchema = JSON.parse(window.localStorage.getItem('projectSchema') || '{}');
+
+
+
+  const lowcodeWindow = await getLowcodeWidnow(lowcodeWindowNo);
   const projectSchema = await getProjectSchema(lowcodeWindowNo);
+  let materialInfos = lowcodeWindow.materialInfos;
   const { componentsMap: componentsMapArray = [], componentsTree = [] } = projectSchema;
 
   const componentsMap = {};
@@ -33,14 +56,40 @@ const init = async lowcodeWindowNo => {
 
   const libraryMap = {};
   const libraryAsset = [];
-  packages.forEach(({ package: _package, library, urls, renderUrls }) => {
-    libraryMap[_package] = library;
-    if (renderUrls) {
-      libraryAsset.push(renderUrls);
-    } else if (urls) {
-      libraryAsset.push(urls);
+  // packages.forEach(({ package: _package, library, urls, renderUrls }) => {
+  //   libraryMap[_package] = library;
+  //   if (renderUrls) {
+  //     libraryAsset.push(renderUrls);
+  //   } else if (urls) {
+  //     libraryAsset.push(urls);
+  //   }
+  // });
+
+  if(materialInfos == null || materialInfos.length == 0){
+    Notify.error('错误', '低代码定义中缺少物料的定义,请在低代码编辑器选择使用到的物料。', false);
+    return;
+  }
+
+  for(let i = 0, size = materialInfos.length; i < size; i ++) {
+    let materialInfo = materialInfos[i];
+    const assets = await fetch(materialInfo.url).then(res =>
+      res.json(),
+    );
+    let packages = assets.packages;
+    console.log(packages);
+    if(packages != null && packages.length > 0){
+      packages.forEach(item => {
+        libraryMap[item.package] = item.library;
+        if (item.renderUrls) {
+          libraryAsset.push(item.renderUrls);
+        } else if (item.urls) {
+          libraryAsset.push(item.urls);
+        }
+      });
     }
-  });
+  }
+
+
   await new AssetLoader().load(libraryAsset);
   const components = await buildComponents(libraryMap, componentsMap);
 

+ 7 - 5
src/lowcode/LowcodePage.js

@@ -1,4 +1,4 @@
-import { defineComponent, onMounted, reactive, h, toRaw } from 'vue';
+import { defineComponent, onMounted, reactive, h, toRaw, Suspense } from 'vue';
 import VueRenderer, { config } from '@leanwo/lowcode-vue-renderer';
 import { init } from './LowcodeConfig';
 import { useRoute } from 'vue-router';
@@ -20,10 +20,12 @@ const LowcodePage = defineComponent(() => {
     }
 
     return h('div', { class: 'lowcode-plugin-sample-preview' }, [
-      h(VueRenderer, {
-        class: 'lowcode-plugin-sample-preview-content',
-        schema: toRaw(schema),
-        components: toRaw(components),
+      h(Suspense, null, {
+        default : () => h(VueRenderer, {
+          class: 'lowcode-plugin-sample-preview-content',
+          schema: toRaw(schema),
+          components: toRaw(components),
+        }),
       }),
     ]);
   };