ソースを参照

自訂名單:改寫 listID存偏好設定 整份 lists 存blob  之流程

Louise lin 2 年 前
コミット
54dda04f47

+ 32 - 10
HiTeachCC/ClientApp/src/components/EditMemberList.vue

@@ -71,7 +71,7 @@
           </div>
         </div>
       </div>
-      <div class="errmsg" v-if="showAddListReachMax">{{ $t("memberlist['自訂名單已達上限提示字']")}}</div>
+      <div class="errmsg" v-if="showAddListReachMax">{{ $t("memberlist['自訂名單已達上限提示字']") }}</div>
       <div class="errmsg" v-if="showAddStudentReachMax">{{ $t("memberlist['新增單筆名單人數達上限提示字']") }}</div>
     </div>
     <!--新增學生名單-->
@@ -152,7 +152,7 @@ export default {
       showEditListName: false,
       showEditListNameMsg: false,
       showAddListReachMax: false,
-      showAddStudentReachMax:false
+      showAddStudentReachMax: false,
     };
   },
   computed: {
@@ -200,9 +200,31 @@ export default {
         this.showAddListReachMax = true;
       }
     },
-    closeEditMemberList() {
+    async closeEditMemberList() {
       this.showEditMemberList = false;
       this.showAddMemberList = false;
+      let blob = new Blob([JSON.stringify(this.$parent.customMemberlist)], { type: "application/json" });
+      blob.lastModifiedDate = new Date();
+      blob.name = "CCroster.json";
+      await this.$parent.uploadResourceByPath(blob, "local/CCroster");
+    },
+    fetchCCroster() {
+      return new Promise(async (r, j) => {
+        const blobinfo = this.$parent.classInfo.blob;
+        const CCrosterURL = blobinfo.url + "/local/CCroster/CCroster.json" + "?" + blobinfo.sas_read;
+        try {
+          await fetch(CCrosterURL)
+            .then((res) => {
+              return res.json();
+            })
+            .then((data) => {
+              r(data);
+            });
+        } catch (err) {
+          j(err, "fetchCCroster err");
+          console.log(err, "fetchCCroster err");
+        }
+      });
     },
     hasDuplicates(arr) {
       return arr.some((x) => arr.indexOf(x) !== arr.lastIndexOf(x));
@@ -273,7 +295,7 @@ export default {
           if (index % 2 == 1 && !isNaN(parseInt(item))) {
             this.tempAddMemberList.push({
               seatID: item,
-              memberID: new Date().getTime() + index,
+              memberID: "member" + new Date().getTime() + index,
               memberName: data[index - 1],
             });
           }
@@ -284,7 +306,7 @@ export default {
           if (item) {
             this.tempAddMemberList.push({
               seatID: index + 1,
-              memberID: new Date().getTime() + index,
+              memberID: "member" + new Date().getTime() + index,
               memberName: data[index],
             });
           }
@@ -301,7 +323,7 @@ export default {
         this.$parent.customMemberlist.push({
           listName: this.currentEditMemberListName,
           list: this.tempAddMemberList,
-          listID: new Date().getTime(),
+          listID: "list" + new Date().getTime(),
         });
         this.editMemberListMode == "Init" ? this.closeEditMemberList() : (this.showAddMemberList = false);
         this.$parent.currentMemberList = this.$parent.customMemberlist[this.$parent.customMemberlist.length - 1];
@@ -346,7 +368,7 @@ export default {
         if (!this.isSeatIDduplicate()) {
           this.$parent.customMemberlist[parentIndex].list.push({
             seatID: this.tempEditSeatID,
-            memberID: new Date().getTime(),
+            memberID: "member" + new Date().getTime(),
             memberName: this.tempEditName,
           });
           this.currentEditStudent = this.$parent.customMemberlist[parentIndex].list[this.$parent.customMemberlist[parentIndex].list.length - 1];
@@ -369,7 +391,7 @@ export default {
       const targetId = this.$parent.customMemberlist[parentIndex].list.findIndex((stu) => stu.memberID === this.currentEditStudent.memberID);
       this.$parent.customMemberlist[parentIndex].list.splice(targetId, 1);
       this.currentEditStudent = {};
-      this.showAddStudentReachMax=false
+      this.showAddStudentReachMax = false;
     },
     editStudent() {
       this.showStudentErrMsgNum = 0;
@@ -379,14 +401,14 @@ export default {
       this.tempEditName = this.currentEditStudent.memberName;
     },
     addStudent() {
-      if ( this.$parent.currentMemberList.list.length < 100) {
+      if (this.$parent.currentMemberList.list.length < 100) {
         this.showStudentErrMsgNum = 0;
         this.showEditStudent = true;
         this.editStudentMode = "add";
         this.tempEditName = "";
         this.tempEditSeatID = "";
       } else {
-        this.showAddStudentReachMax=true
+        this.showAddStudentReachMax = true;
       }
     },
     hintBugRow(row, index) {

+ 2 - 2
HiTeachCC/ClientApp/src/store/module/preferences.js

@@ -27,7 +27,7 @@ export default {
                     size: '3',
                 },
             ],
-            memberList:[]
+            memberListIDs:[]
         }
     },
     getters: {
@@ -36,7 +36,7 @@ export default {
        getPenState: state => (type) => {
         return state.pref.pens.find(item => item.type === type)
        },
-       getPREFMemberList:state=>state.pref.memberList // 取得自訂名單
+       getPREFMemberList:state=>state.pref.memberListIDs // 取得自訂名單
     },
     mutations: {
         [KEEPSTORAGE](state, data) {

+ 30 - 2
HiTeachCC/ClientApp/src/views/Board.vue

@@ -1637,6 +1637,33 @@ export default {
     //   })
     // },
 
+     // 上傳到Temp工作目錄之外的地方,給定路徑,如上傳名單
+    async uploadResourceByPath(file, path) {
+      return new Promise(async (r, j) => {
+        let blobinfo = this.classInfo.blob;
+        console.log(this.classInfo);
+        // 調整BlobURL設定 Osbert
+        this.blobinit = new Upblob(blobinfo.url, "", blobinfo.sas_write);
+        let fileBolb = {
+          url: blobinfo.url,
+          name: file.name,
+          size: file.size,
+          loadedBytes: 0,
+          progress: 0,
+          status: 0,
+        };
+        this.uploadedList.push(fileBolb);
+        await this.blobinit.upload(file, path, { blobHTTPHeaders: { blobContentType: file.type } }).then(
+          (res) => {
+            r(res);
+          },
+          (err) => {
+            j(err);
+          }
+        );
+      });
+    },
+
     // 上傳不需要修改檔名的圖片或其他資源檔案
     async uploadResourceFile(file, subFileName) {
       return new Promise(async (r, j) => {
@@ -6441,7 +6468,7 @@ export default {
         MCQType: this.$store.state.currentAnsOption, // 選擇題選項
         IRSBlockSize: this.$store.state.tempIRSBlockSize, // IRS Block 大小
         pens: this.$store.state.tempPenstate,
-        memberList:this.customMemberlist
+        memberListIDs:this.customMemberlist.map(item=>item.listID)
       };
       this.$Spin.show(); // 畫面loading表現你可以自己調整
       await this.$store.dispatch("preferences/updProfilePREF", data).then(() => {
@@ -6941,8 +6968,9 @@ export default {
     let that = this;
     if (sessionStorage.getItem("currentAnsOption")) this.setAnsOption(sessionStorage.getItem("currentAnsOption"));
     else this.setAnsOption(this.getPREFMCQType);
+    
      //帶入自訂名單偏好設定
-    this.customMemberlist=this.getPREFMemberList?this.getPREFMemberList:[]
+    this.customMemberlist=this.getPREFMemberList?await this.$refs.editMemberList.fetchCCroster():[]
 
     this.getStorageSize("session");