panweitong 4 年之前
父節點
當前提交
d6da7f9128
共有 5 個文件被更改,包括 65 次插入47 次删除
  1. 4 4
      index.html
  2. 30 16
      index.js
  3. 1 1
      python/src/blockly/account.js
  4. 28 26
      src/blockly/account.js
  5. 2 0
      src/blockly/cocoblockly.js

+ 4 - 4
index.html

@@ -211,7 +211,7 @@
                             <li id="button_load">
                                 <span class="translatable_import_local_file">导入本地文件</span>
                             </li>
-                            <li id="button_import_cloud" href="#cloud_storage_modal">
+                            <li id="button_import_cloud" class='modal-trigger' href="#cloud_storage_modal">
                                 <span class="translatable_import_cloud_file">导入云端文件</span>
                             </li>
                             <li id="button_save">
@@ -1402,7 +1402,7 @@
             </ul>
             <a id='side-storage-trigger' class='dropdown-button' data-activates='side-storage'></a>
             <ul id='side-storage' class='dropdown-content'>
-                <li class='modal-trigger' href="#cloud_storage_modal" style="display:none;">
+                <li class='modal-trigger'  style="display:none;">
                     <span class="translatable_cloud_storage">Cloud</span>
                 </li>
                 <li class="divider"></li>
@@ -2868,8 +2868,8 @@
                 <i class="small material-icons" style="font-size: 1.5rem;">close</i>
             </span>
             <h4 class="translatable_cloudStorageTitle">Cloud Storage</h4>
-            <div id="cloud_askLogin"></div>
-            <div id="cloud_fileListArea" class="cloud-file" style="display:none">
+            <!-- <div id="cloud_askLogin"></div> -->
+            <div id="cloud_fileListArea" class="cloud-file">
             </div>
         </div>
         <div id="cloud_modal_preload" style="display:none">

+ 30 - 16
index.js

@@ -1448,9 +1448,9 @@ function appearExample(type) {
 function savelxfile(code, title, cb) {
   var _token = window.localStorage.Token;
   if (_token) {
-    $.ajax(`/api/web/v1/blockpy/project/add`, {
+    $.ajax(`https://demo-lecode.smartedu.lenovo.com/api/web/v1/blockpy/project/add`, {
       type: "POST",
-      headers: { 'Authorization': "Bearer " + _token, 'content-type': "application/json;charset=UTF-8" },
+      headers: { 'Authorization': "Bearer " + _token},
       data: { code: code, title: title },
       success: (data) => {
         cb(data)
@@ -1462,10 +1462,10 @@ function savelxfile(code, title, cb) {
 function getlxfiles(page, cb) {
   var _token = window.localStorage.Token;
   if (_token) {
-    $.ajax(`/api/web/v1/blockpy/project/list`, {
+    $.ajax(`https://demo-lecode.smartedu.lenovo.com/api/web/v1/blockpy/project/list`, {
       type: "GET",
       headers: { 'Authorization': "Bearer " + _token },
-      data: "pageNumber=" + page + "pageSize=20",
+      data: "pageNumber=" + "&" + page + "pageSize=500",
       success: (data) => {
         cb(data)
       }
@@ -1473,17 +1473,31 @@ function getlxfiles(page, cb) {
   }
 }
 
-
-function getlxfilebyid(id) {
-  var _token = window.localStorage.Token;
-  if (_token) {
-    $.ajax(`/api/web/v1/blockpy/project/` + id, {
-      type: "GET",
-      headers: { 'Authorization': "Bearer " + _token },
-      success: (data) => {
-        cb(data)
-      }
+function getFileList(data) {
+  var fileList = [];
+  data.data.records.filter(val => {
+    var filename = val.title;
+    var date = val.updateTime;
+    var Timestamp = new Date(date).getTime();
+    fileList.push({
+      filename: filename,
+      date: date,
+      timestamp: Timestamp,
+      filenameId: val.id
     });
+  });
+  console.log(fileList, 'getCloudFileList')
+  updateCloudFileList(fileList);
+  updateCloudFilePanel();
+  // openCloudFile(CCB.cloudFileList[i].filename); 打开文件
+  let arr = window.location.search.split('&')[1]
+  if (arr) {
+    fileList.map(x => {
+      if (x.filenameid == arr.split('=')[1]) {
+        openCloudFile(x.filename)
+      }
+      return x;
+    })
   }
 }
 
@@ -1505,7 +1519,7 @@ function upadtelxfilenamebyid(id, title) {
   if (_token) {
     $.ajax(`/api/web/v1/blockpy/project/title/update`, {
       type: "POST",
-      headers: { 'Authorization': "Bearer " + _token, 'content-type': "application/json;charset=UTF-8" },
+      headers: { 'Authorization': "Bearer " + _token},
       data: { id: id, title: title },
       success: (data) => {
         cb(data)
@@ -1520,7 +1534,7 @@ function uploadlxfilecontentbyid(id, code) {
   if (_token) {
     $.ajax(`/api/web/v1/blockpy/project/code/update`, {
       type: "POST",
-      headers: { 'Authorization': "Bearer " + _token, 'content-type': "application/json;charset=UTF-8" },
+      headers: { 'Authorization': "Bearer " + _token },
       data: { id: id, code: code },
       success: (data) => {
         cb(data)

+ 1 - 1
python/src/blockly/account.js

@@ -1067,7 +1067,7 @@ window.addEventListener("message", e => {
       CCB.userState = true;
       getUserProfile(data.data);
       loginModalStatus();
-      getCloudFileList();
+      // getCloudFileList();
       CCB.UserInfo = data;
       /**
       *post login session message into TM_iframe

+ 28 - 26
src/blockly/account.js

@@ -151,29 +151,30 @@ function createCloudFile(filename) {
  * @param {String} filename : the name of file
  */
 function openCloudFile(filename) {
-  $.ajax(`${CCB.base_url}blockx/${filename}`, {
-    type: "GET",
-    xhrFields: {
-      withCredentials: true
-    },
-    before: () => { $("#cloud_modal_preload").css("display", "block") },
-    success: data => {
-      var file = data.xml;
-      var date = data.date;
-      Materialize.toast(CCB.str_group.success_downloadFile, 4000);
-      loadCloudXmlFile(file, filename);
-      $("#cloud_storage_modal").modal("close");
-      $("#cloud_modal_preload").css("display", "none");
-      let i = indexGet(filename, CCB.cloudFileList);
-      CCB.selectCloudFile = filename;
-      relistCloudFile(filename);
-      updateCloudFilePanel();
-    },
-    error: () => {
-      $("#cloud_modal_preload").css("display", "none");
-      Materialize.toast(CCB.str_group.error_downloadFile, 4000);
-    }
-  });
+  var _token = window.localStorage.Token;
+  if (_token) {
+    $.ajax(`https://demo-lecode.smartedu.lenovo.com/api/web/v1/blockpy/project/` + filename, {
+      type: "GET",
+      headers: { 'Authorization': "Bearer " + _token },
+      before: () => { $("#cloud_modal_preload").css("display", "block") },
+      success: (data) => {
+        var file = data.data.instructions;
+        var date = data.data.updateTime;
+        Materialize.toast(CCB.str_group.success_downloadFile, 4000);
+        loadCloudXmlFile(file, data.data.id);
+        $("#cloud_storage_modal").modal("close");
+        $("#cloud_modal_preload").css("display", "none");
+        let i = indexGet(data.data.id, CCB.cloudFileList);
+        CCB.selectCloudFile = filename;
+        relistCloudFile(filename);
+        updateCloudFilePanel();
+      },
+      error: () => {
+        $("#cloud_modal_preload").css("display", "none");
+        Materialize.toast(CCB.str_group.error_downloadFile, 4000);
+      }
+    });
+  }
 }
 
 /**
@@ -364,7 +365,7 @@ function updateCloudFileList(filelist) {
       filename: filename,
       time: date,
       timestamp: Timestamp,
-      filenameId: val.filenameid
+      filenameId: val.filenameId
     });
   });
   cloudlist.sort((a, b) => {
@@ -1067,7 +1068,7 @@ window.addEventListener("message", e => {
       CCB.userState = true;
       getUserProfile(data.data);
       loginModalStatus();
-      getCloudFileList();
+      // getCloudFileList();
       CCB.UserInfo = data;
       /**
       *post login session message into TM_iframe
@@ -1170,6 +1171,7 @@ function dateFormat(date) {
   if (date == null) {
     return "-/-";
   }
-  data = date.split("T")[0].replace(/-/g, "/")
+
+  data = date.split(" ")[0].replace(/-/g, "/")
   return data;
 }

+ 2 - 0
src/blockly/cocoblockly.js

@@ -1699,6 +1699,8 @@ async function cocoblockly() {
     clipboard_copy("#err-copy", "#apikey-copy", "#code-copy");
     add_tooltips(tooltips);
     ws_connect();
+
+    getlxfiles(0,getFileList);
 };