Przeglądaj źródła

ai应用上传作业修改为链接

11wqe1 1 miesiąc temu
rodzic
commit
2f7ea93731
1 zmienionych plików z 77 dodań i 13 usunięć
  1. 77 13
      src/components/components/appStoreC.vue

+ 77 - 13
src/components/components/appStoreC.vue

@@ -71,26 +71,34 @@ import { myMixin } from "@/mixins/mixin.js"
                     document.msExitFullscreen();
                 }
             },
-            uploadWork(){
+            async uploadWork(){
                 // console.log('window.exposed_outputs',window.exposed_outputs);
                 let _iframe = this.$refs.appStore;
                 console.log('sStudent',this.userId);
-                
-                // window.exposed_outputs
-                let Cow = JSON.stringify(_iframe.contentWindow.exposed_outputs)
 
                 if (this.homeWorkLoading) return this.$message.info('点击过快,请稍后...')
                 this.homeWorkLoading = true
+                // window.exposed_outputs
+                // let Cow = _iframe.contentWindow.exposed_outputs
+
+                const pptJsonStr = JSON.stringify(_iframe.contentWindow.exposed_outputs);
+                const pptJsonFile = new File([pptJsonStr], "pptData.json", { type: "application/json" });
+                // 你可以根据需要将pptJsonFile上传或保存
+
+                let _url = await this.uploadFile(pptJsonFile);
+                console.log(_url)
+                // return
+                
                 let params = [
                     {
-                    uid: this.userId,
-                    cid: this.id,
-                    stage: this.courseType,
-                    task: this.taskCount,
-                    tool: this.toolindex,
-                    content: Cow,
-                    type: 20,
-                    atool:72
+                        uid: this.userId,
+                        cid: this.id,
+                        stage: this.courseType,
+                        task: this.taskCount,
+                        tool: this.toolindex,
+                        content: _url,
+                        type: 20,
+                        atool:72
                     }
                 ];
                 this.ajax
@@ -119,7 +127,63 @@ import { myMixin } from "@/mixins/mixin.js"
                         this.$message.error("提交失败");
                         console.error(err);
                     });
-            }
+            },
+            //上传文件
+            uploadFile(file) {
+                return new Promise((resolve)=>{
+                    var credentials = {
+                    accessKeyId: "AKIATLPEDU37QV5CHLMH",
+                    secretAccessKey: "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"
+                }; //秘钥形式的登录上传
+                window.AWS.config.update(credentials);
+                window.AWS.config.region = "cn-northwest-1"; //设置区域
+
+                var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
+                var _this = this;
+
+                if (file) {
+                    var params = {
+                    Key:
+                        file.name.split(".")[0] +
+                        new Date().getTime() +
+                        "." +
+                        file.name.split(".")[file.name.split(".").length - 1],
+                    ContentType: file.type,
+                    Body: file,
+                    "Access-Control-Allow-Credentials": "*",
+                    ACL: "public-read"
+                    }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
+                    var options = {
+                    partSize: 2048 * 1024 * 1024,
+                    queueSize: 2,
+                    leavePartsOnError: true
+                    };
+                    bucket
+                    .upload(params, options)
+                    .on("httpUploadProgress", function(evt) {
+                        //这里可以写进度条
+                        // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
+                    })
+                    .send(function(err, data) {
+                        if (err) {
+                        // var a = _this.$refs.upload1.uploadFiles;
+                        // a.splice(a.length - 1, a.length);
+                        _this.$message.error("上传失败ppt数据失败");
+                        } else {
+                        //上传成功处理
+                        // _this.unitJson[_this.unitIndex].chapterInfo[0].fileList1.push({
+                        //   name: file.name,
+                        //   url: data.Location,
+                        //   uid: file.uid
+                        // });
+                        // _this.imgChange();
+                        // console.log(data.Location);
+                        resolve(data.Location)
+                        }
+                    });
+                }
+                })
+            },
         },  
     }
 </script>