lsc 1 неделя назад
Родитель
Сommit
06d6cf4d22
2 измененных файлов с 680 добавлено и 0 удалено
  1. 671 0
      src/components/pages/pptEasy/addCourse2.vue
  2. 9 0
      src/router/index.js

+ 671 - 0
src/components/pages/pptEasy/addCourse2.vue

@@ -0,0 +1,671 @@
+<template>
+    <div class="pb_content" style="background: #F0F2F5;" v-loading="uploadWorkLoading">
+        <div class="pb_content_body" style="position: relative; margin: 0">
+            <div class="right">
+                <div style="width: 100%; height: 100%; overflow: auto" ref="stepBox">
+                    <div class="courseTop">
+                        <div class="stepsNav" v-if="!gotype">
+                            <el-breadcrumb separator-class="el-icon-arrow-right">
+                                <el-breadcrumb-item :to="{
+                                    path:
+                                        '/course?userid=' +
+                                        userid +
+                                        '&oid=' +
+                                        oid +
+                                        '&org=' +
+                                        org +
+                                        '&role=' +
+                                        role
+                                }">课程管理</el-breadcrumb-item>
+                                <el-breadcrumb-item>
+                                    <span style="color: rgb(15, 126, 255)">添加课程</span>
+                                </el-breadcrumb-item>
+                            </el-breadcrumb>
+                        </div>
+                        <div class="r_pub_button_retrun" @click="lastSteps()">返回</div>
+                    </div>
+                    <div
+                      class="rightBox"
+                      style="padding: 0;"
+                      :style="{
+                        height: 'calc(100% - 50px)'
+                      }"
+                      v-if="steps == 1"
+                    >
+                      <div class="pptIframeArea">
+                          <iframe
+                              allow="camera *; microphone *;display-capture;midi;encrypted-media;clipboard-write;clipboard-read"
+                              webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen="" frameborder="no"
+                              border="0" :src="pptIframeUrl" ref="pptIframeRef"></iframe>
+                      </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</template>
+
+<script>
+import "../../../common/aws-sdk-2.235.1.min.js";
+import { tools as toolsData } from "../../../common/tools.js";
+import $ from "jquery";
+import appDialog from "../components/appDialog.vue";
+import { myMixin } from "@/mixins/mixin.js";
+import { uploadFileMixin } from "../../tools/uploadFileMixin.js";
+import BilibiliSearchDialog from "./dialog/BilibiliSearchDialog.vue";
+import { v4 as uuidv4 } from "uuid";
+var OpenCC = require("opencc-js");
+let converter = OpenCC.Converter({
+  from: "hk",
+  to: "cn"
+});
+
+const getFile = (url) => {
+  return new Promise((resolve, reject) => {
+    var credentials = {
+        accessKeyId: "AKIATLPEDU37QV5CHLMH",
+        secretAccessKey: "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",
+      }; //秘钥形式的登录上传
+      window.AWS.config.update(credentials);
+      window.AWS.config.region = "cn-northwest-1"; //设置区域
+      let url2 = url;
+      let _url2 = "";
+      if (
+        url2.indexOf("https://view.officeapps.live.com/op/view.aspx?src=") != -1
+      ) {
+        _url2 = url2.split(
+          "https://view.officeapps.live.com/op/view.aspx?src="
+        )[1];
+      } else {
+        _url2 = url2;
+      }
+      var s3 = new window.AWS.S3({ params: { Bucket: "ccrb" } });
+      let name = decodeURIComponent(_url2.split("https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/")[1])
+      var params = {
+        Bucket: "ccrb",
+        Key: name
+      };
+      s3.getObject(params, function (err, data) {
+        if (err) {
+          console.log(err, err.stack)
+          resolve({ data: 1 });
+        }else {
+          resolve({ data: data.Body });
+          console.log(data);
+        }          // sxuccessful response
+
+      });
+  });
+};
+
+
+export default {
+  mixins: [myMixin, uploadFileMixin],
+  components: {
+  },
+  data() {
+    return {
+      gotype: (window.topU && window.topU.gotype) ?  window.topU.gotype : '',
+      userid: this.$route.query.userid,
+      oid: this.$route.query.oid,
+      org: this.$route.query.org,
+      role: this.$route.query.role,
+      cid: this.$route.query.cid != undefined ? this.$route.query.cid : "",
+      uploadWorkLoading:false,
+      courseName: "",
+      isTeacherSee: false,
+      courseText: "",
+      pptCourseJson:{
+        pptData:"",
+        toolsList:[],
+      },
+      unitJson2: [],
+      unitJson: [
+        {
+          dyName: "", //单元标题
+          chapterInfo: [
+            {
+              isread: false,
+              chapterid: this.guid(),
+              title: "",
+              courseName: "",
+              taskJson: [
+                {
+                  task: "",
+                  taskDetail: "",
+                  chapterData: [],
+                  toolChoose: [
+                    {
+                      tool: [],
+                      toolDetail: "",
+                      toolType: 0,
+                      askCount: 1,
+                      askTitle: "",
+                      askJson: [{ askstitle: "", askItem: 1, checkList: [] }]
+                    }
+                  ],
+                  toolText: "",
+                  isShowTools: false,
+                  askCount: 1,
+                  isFold: 1,
+                  askTitle: "",
+                  askJson: [{ askstitle: "", askItem: 1, checkList: [] }],
+                  checkJson: [{ checkCount: [], checkPerent: [] }],
+                  homeworkList: []
+                }
+              ],
+              itemCount: 1,
+              fileList1: [],
+              video: [],
+              testData: [],
+              pData: [],
+              templateArray: []
+            }
+          ]
+        }
+      ],
+      cover: [], //课程封面
+      checkboxList: [],
+      checkboxList2: [],
+      checkboxList3: [],
+      CourseType: [],
+      CourseType2: [],
+      CourseTypeJson: {},
+      courseTypeId: [],
+      cidType: 0,
+      number: "",
+      courseId: "",
+      courseUserid: "",
+      steps: 1,
+      // 荔园集团下的学校
+			mergedList: [
+				"3823a6a5-1b6e-11f0-a66a-005056924926",
+				"292e34dc-1b6e-11f0-a66a-005056924926",
+				"21d6b367-1b6e-11f0-a66a-005056924926",
+				"1a1a172d-1b6e-11f0-a66a-005056924926",
+				"1197f86b-1b6e-11f0-a66a-005056924926",
+				"f235659b-1b6d-11f0-a66a-005056924926",
+				"d87b62d3-1b6d-11f0-a66a-005056924926",
+				"c25ea59b-1b6d-11f0-a66a-005056924926",
+			],
+    };
+  },
+  computed: {
+    // 判断当前页面URL是否包含beta
+    isBetaEnv() {
+      return window.location.href.includes('beta');
+    },
+    // 动态生成PPT iframe的URL
+    pptIframeUrl() {
+
+      let ppturl = "https://beta.ppt.cocorobo.cn"
+      if (this.isBetaEnv) {
+        ppturl = "https://beta.ppt.cocorobo.cn"
+      } else if (this.lang.lang == 'com') {
+        ppturl = 'https://ppt.cocorobo.com'
+      } else if (this.lang.lang == 'hk') {
+        ppturl = 'https://ppt.cocorobo.hk'
+      } else {
+        ppturl = 'https://ppt.cocorobo.cn'
+      }
+      return `${ppturl}/?mode=editor&courseid=${this.cid}`;
+    },
+  },
+  watch: {
+  },
+  methods: {
+    guid() {
+      var _num,
+        i,
+        _guid = "";
+      for (i = 0; i < 32; i++) {
+        _guid += Math.floor(Math.random() * 16).toString(16); //随机0  - 16 的数字 转变为16进制的字符串
+        _num = Math.floor((i - 7) / 4); //计算 (i-7)除4
+        if (_num > -1 && _num < 4 && i == 7 + 4 * _num) {
+          //会使guid中间加 "-"   形式为xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+          _guid += "-";
+        }
+      }
+      return _guid;
+    },
+    setPPtToolList(){
+      let _toolList = JSON.parse(JSON.stringify(this.pptCourseJson.toolsList));
+      //把toolList挂载到window上
+      window.pptToolList = _toolList;
+    },
+    lastSteps() {
+      this.$confirm("是否保存已编辑内容?", "提示", {
+        confirmButtonText: "保存",
+        cancelButtonText: "不保存",
+        distinguishCancelAndClose: true,
+        type: "warning"
+      })
+        .then(() => {
+          console.log("保存已编辑内容");
+          if (this.cid == "" || this.cid == undefined) {
+            if (this.courseName == "") {
+              this.$message.error("请补充填写课程名称");
+              return;
+            } else {
+              this.addWork();
+            }
+          } else {
+            if (this.courseName == "") {
+              this.$message.error("请补充填写课程名称");
+              return;
+            } else {
+              this.updateWork();
+            }
+          }
+        })
+        .catch(v => {
+          console.log(v);
+          if (v == "cancel") {
+            this.goTo(
+              "/course?userid=" +
+                this.userid +
+                "&oid=" +
+                this.oid +
+                "&org=" +
+                this.org +
+                "&role=" +
+                this.role
+            );
+          }
+        });
+    },
+    //获取ppt的数据
+    async getPPtJson() {
+      const checkLoaded = async (resolve) => {
+        console.log("获取ppt数据")
+        let _pptIframe = this.$refs.pptIframeRef;
+        if (
+          _pptIframe &&
+          _pptIframe.contentWindow &&
+          _pptIframe.contentWindow.window &&
+          typeof _pptIframe.contentWindow.window.exportJSON === "function"
+        ) {
+          let _data = _pptIframe.contentWindow.window.exportJSON();
+          resolve(_data);
+        } else {
+          // 递归等待1000ms后重试
+          setTimeout(() => {
+            checkLoaded(resolve);
+          }, 1000);
+        }
+      };
+      return new Promise((resolve) => {
+        checkLoaded(resolve);
+      });
+    },
+    //上传文件
+    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)
+            }
+          });
+      }
+      })
+    },
+    // 上传文件
+    async uploadFile2(file, pptid) {
+      try {
+        let uuid = uuidv4();
+        let formData = new FormData();
+        const timestamp = Date.now();
+        const finalExtension = file.name.split(".").pop().toLowerCase();
+        const baseName = file.name.slice(0, -(finalExtension.length + 1));
+        formData.append(
+          "file",
+          new File([file], `${baseName}${timestamp}.${finalExtension}`)
+        );
+        formData.append("collection_ids", JSON.stringify([]));
+        formData.append("id", uuid);
+        formData.append("metadata", JSON.stringify({ title: file.name }));
+        formData.append("ingestion_mode", "fast");
+        formData.append("run_with_orchestration", "true");
+        // 确保formData是正确的格式
+        // this.$store.state.fileApi + "upload"
+
+        // 同步知识库
+        await this.ajax.post(
+          "https://r2rserver.cocorobo.cn/v3/documents",
+          formData,
+          {
+            headers: {
+              "Content-Type": "multipart/form-data",
+            },
+          }
+        );
+        let ptype = "1"; // 根据实际业务定义类型
+        let fileid = uuid; // 如果需要唯一fileid可以和pptid保持一致或按需更改
+        await this.ajax.post(this.$store.state.api + "addPPTFile", [{
+          pptid: pptid,
+          ptype: ptype,
+          fileid: fileid,
+          classid: "",
+          task: "",
+          tool: ""
+        }]);
+      } catch (err) {
+        console.error(err);
+        throw err;
+      }
+    },
+    async addWork() {
+      if(this.$refs.pptIframeRef.contentWindow.window.pptLoading !== 2)return this.$message.info("ppt正在加载中,请稍等")
+      if(this.uploadWorkLoading)return;
+      this.uploadWorkLoading = true;
+      let _pptData = await this.getPPtJson();
+
+      // 用_pptData生成json文件,并生成File对象
+      const pptJsonStr = JSON.stringify(_pptData, null, 2);
+      const pptJsonFile = new File([pptJsonStr], this.courseName+".json", { type: "application/json" });
+      // 你可以根据需要将pptJsonFile上传或保存
+
+      let _url = await this.uploadFile(pptJsonFile);
+
+      console.log(_url)
+      this.pptCourseJson.pptData = _url;
+
+
+
+      this.inputShow = true;
+
+      for (var i = 0; i < this.unitJson.length; i++) {
+        delete this.unitJson[i].isUpdate;
+      }
+      let params = [
+        {
+          uid: this.userid,
+          title: this.courseName,
+          brief: this.courseText,
+          cover:
+            this.cover.length > 0
+              ? JSON.stringify(this.cover)
+              : JSON.stringify([
+                  {
+                    name: "noBanner.jpg",
+                    url:
+                      "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/wu1676621845022.png",
+                    uid: 1656409780264,
+                    status: "success"
+                  }
+                ]),
+          evaId: "",
+          astudent:
+            this.checkboxList2.length > 0 ? this.checkboxList2.join(",") : "",
+          see: this.isTeacherSee == true ? 1 : 0,
+          chapters: JSON.stringify(this.pptCourseJson),
+          template: "",
+          courseType: JSON.stringify(this.courseTypeId),
+          ateacher:
+            this.checkboxList3.length > 0 ? this.checkboxList3.join(",") : "",
+          inviteCode: ""
+        }
+      ];
+      this.ajax
+        .post(this.$store.state.api + "insert_teacher_work_pptCourse", params)
+        .then(res => {
+          this.uploadWorkLoading = false;
+          console.log(this.steps);
+          // if (this.steps != 1 && this.steps != 2 && this.steps != 3) {
+          this.$message({
+            message: "新增成功",
+            type: "success"
+          });
+          // }
+          this.number = res.data.ordernumber;
+          this.courseId = res.data.courseId;
+          this.cid = res.data.courseId;
+          this.courseUserid = this.userid;
+          this.islogin = true;
+          this.steps = 4;
+          this.uploadFile2(pptJsonFile, this.courseId);
+          this.addOp3(
+            "1",
+            "",
+            { courseid: this.courseId, type: "course_pptEasyMode_clickUpload" },
+            "success"
+          );
+        })
+        .catch(err => {
+          this.uploadWorkLoading = false;
+          this.addOp3(
+            "1",
+            "",
+            { courseid: this.courseId, type: "course_pptEasyMode_clickUpload" },
+            err
+          );
+          this.$message.error("网络不佳");
+          console.error(err);
+        });
+    },
+     async updateWork() {
+      if(this.$refs.pptIframeRef.contentWindow.window.pptLoading !== 2)return this.$message.info("ppt正在加载中,请稍等")
+      if(this.uploadWorkLoading)return;
+      this.uploadWorkLoading = true;
+      let _pptData = await this.getPPtJson();
+
+      // 用_pptData生成json文件,并生成File对象
+      const pptJsonStr = JSON.stringify(_pptData, null, 2);
+      const pptJsonFile = new File([pptJsonStr], this.courseName + ".json", { type: "application/json" });
+      // 你可以根据需要将pptJsonFile上传或保存
+      console.log(_url)
+      let _url = await this.uploadFile(pptJsonFile);
+      this.uploadFile2(pptJsonFile, this.cid);
+
+      this.pptCourseJson.pptData = _url;
+
+      let params = [
+        {
+          cid: this.cid,
+          title: this.courseName,
+          brief: this.courseText,
+          cover:
+            this.cover.length > 0
+              ? JSON.stringify(this.cover)
+              : JSON.stringify([
+                  {
+                    name: "noBanner.jpg",
+                    url:
+                      "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/wu1676621845022.png",
+                    uid: 1656409780264,
+                    status: "success"
+                  }
+                ]),
+          evaId: "",
+          astudent:
+            this.checkboxList2.length > 0 ? this.checkboxList2.join(",") : "",
+          see: this.isTeacherSee == true ? 1 : 0,
+          chapters: JSON.stringify(this.pptCourseJson),
+          template: this.myWord != "undefined" ? this.myWord : [],
+          uid: this.userid,
+          courseType: JSON.stringify(this.courseTypeId),
+          ateacher:
+            this.checkboxList3.length > 0 ? this.checkboxList3.join(",") : "",
+          inviteCode: ""
+        }
+      ];
+      this.ajax
+        .post(this.$store.state.api + "updateWorkNew2", params)
+        .then(res => {
+          // if (this.steps != 1 && this.steps != 2 && this.steps != 3) {
+          this.uploadWorkLoading = false;
+          if (this.cidType == 1) {
+            this.$message({
+              message: "修改成功",
+              type: "success"
+            });
+          } else {
+            this.$message({
+              message: "新增成功",
+              type: "success"
+            });
+          }
+          // }
+          this.number = this.nbOrder;
+          this.courseId = this.cid;
+          this.steps = 4;
+          this.addOp3(
+            "1",
+            "",
+            { courseid: this.courseId, type: "course_pptEasyMode_clickUpload" },
+            "success"
+          );
+        })
+        .catch(err => {
+          this.uploadWorkLoading = false;
+          this.addOp3(
+            "1",
+            "",
+            { courseid: this.courseId, type: "course_pptEasyMode_clickUpload" },
+            err
+          );
+          this.$message.error("网络不佳");
+          console.error(err);
+        });
+    },
+  },
+  beforeDestroy() {
+
+  },
+  beforeRouteLeave(to, from, next) {
+ 
+  },
+  created() {
+
+  },
+  mounted() {
+    if(this.mergedList.includes(this.org) ){
+      this.isTeacherSee = true
+    }
+    // 清空
+    this.pptCourseJson.toolsList = [];
+    this.setPPtToolList()
+    // iframe页面加载完成
+    this.$refs.pptIframeRef.onload = () => {
+      console.log("iframe页面加载完成");
+
+    }
+
+  }
+};
+</script>
+
+<style scoped>
+.pb_content {
+  height: 100% !important;
+}
+
+.pb_content_body {
+  width: 100% !important;
+  height: 100%;
+}
+
+.pb_content_body {
+  width: 100% !important;
+  height: 100%;
+}
+
+.pptIframeArea {
+  width: 100%;
+  height: 1000px;
+  margin: 10px 0;
+  background-color: #fff;
+  overflow: hidden;
+  border-radius: 10px;
+}
+
+.pptIframeArea > iframe {
+  width: 98%;
+  height: 100%;
+  border: 0;
+}
+
+.courseTop {
+  display: flex;
+  flex-direction: row;
+  justify-content: space-between;
+  align-items: center;
+  width: calc(100%);
+  padding: 10px 0;
+  margin: 0 auto;
+}
+
+.stepsNav {
+  display: flex;
+  flex-direction: row;
+  justify-content: flex-start;
+  align-items: center;
+}
+
+.right {
+  height: 100%;
+  width: calc(100% - 40px);
+  display: flex;
+  overflow: hidden;
+  margin: 0 auto;
+}
+
+
+.rightBox {
+  width: calc(100%);
+  background: #f0f2f5;
+  /* border-radius: 10px; */
+  overflow: auto;
+  height: calc(100% - 120px);
+  margin: 0 auto;
+  position: relative;
+  box-sizing: border-box;
+  border-radius: 5px;
+}
+
+</style>

+ 9 - 0
src/router/index.js

@@ -164,6 +164,7 @@ import safeTest from '@/components/pages/liyuan/page/safeTest'
 import workPage from '@/components/pages/workPage/index'
 import workPage from '@/components/pages/workPage/index'
 import workPageNew from '@/components/pages/workPage/index_new'
 import workPageNew from '@/components/pages/workPage/index_new'
 import pptEasy from '@/components/pages/pptEasy/addCourse'
 import pptEasy from '@/components/pages/pptEasy/addCourse'
+import pptEasy2 from '@/components/pages/pptEasy/addCourse2'
 import noticeCenter from '@/components/pages/noticeCenter/index'
 import noticeCenter from '@/components/pages/noticeCenter/index'
 import PersonnelManagement from "@/components/pages/PersonnelManagement";
 import PersonnelManagement from "@/components/pages/PersonnelManagement";
 import topTalent from "@/components/pages/liyuan/topTalent";
 import topTalent from "@/components/pages/liyuan/topTalent";
@@ -1468,6 +1469,14 @@ export default new Router({
       requireAuth:''//不需要鉴权
       requireAuth:''//不需要鉴权
     }
     }
   },
   },
+  {
+    path:"/pptEasy2",
+    name:"pptEasy2",
+    component:pptEasy2,
+    meta:{
+      requireAuth:''//不需要鉴权
+    }
+  },
   {
   {
     path:"/noticeCenter",
     path:"/noticeCenter",
     name:"noticeCenter",
     name:"noticeCenter",