Преглед изворни кода

修改上课跳转与埋点

11wqe1 пре 2 дана
родитељ
комит
5c2a9b51a1
2 измењених фајлова са 166 додато и 41 уклоњено
  1. 57 41
      src/components/main/courseSelect.vue
  2. 109 0
      src/mixins/mixin.js

+ 57 - 41
src/components/main/courseSelect.vue

@@ -273,9 +273,11 @@
 
   <selectTeachingClassDialog 
   ref="DialogRef" />
+  <iframe :src="courseUrl" class="courseIframe" v-if="courseUrl"></iframe>
 
 </template>
 <script setup>
+import { addOp3 } from '@/mixins/mixin'
 import { ref, onMounted, watchEffect, inject } from 'vue';
 import { userCurrentRole, userInfoStore, userCurrent,pageGotype } from '../../stores/counter'
 // import JSZip from 'jszip';
@@ -477,6 +479,7 @@ const openCourseDetail = (id) => {
   .then(res => {
     console.log('openCourseDetail',res)
     if (res.data[0].length > 0) {
+      return getCourseUrl(res.data[0][0])
       // let isSave = res.value[0].filter(x => {
       //   return x.courseId == id
       // })
@@ -502,33 +505,52 @@ const openCourseDetail = (id) => {
   .catch(err => {
     console.log(err)
   })
-  // 会返回复制得课程
-  // top.U.A.Request("https://pbl.cocorobo.cn/api/pbl/getcopyCourseByUseridSz", [id, user.user.userid], function (res) {
-  //   console.log(res)
-  //   if (res.value[0].length > 0) {
-  //     // let isSave = res.value[0].filter(x => {
-  //     //   return x.courseId == id
-  //     // })
-  //     //这个是打开指定的课程接口
-  //     	let url = '';
-	// 			if (lang.lang == 'hk') {
-	// 				url = "https://pbl.cocorobo.hk"
-	// 			}else if (lang.lang == 'en') {
-	// 				url = "https://pbl.cocorobo.com"
-	// 			}else{
-	// 				url = "https://pbl.cocorobo.cn"
-	// 			}
-  //     // https://pbl.cocorobo.cn/pbl-student-table/dist/#/courseDetail?userid=0c3735c9-a2ef-11ef-9b30-005056b86db5&oid=414f2361-ad04-11ed-b13d-005056b86db5&org=0fec3a8a-ad04-11ed-b13d-005056b86db5&courseId=91886917-2f3b-11f1-bcd9-005056924926&tType=1&cid=&screenType=2
-      
-  //     let url2 = `${url}/pbl-student-table/dist/#/courseDetail?userid=${user.user.userid}&oid=${user.user.organizeid}&org=${user.user.org}&courseId=${res.value[0][0].courseId}&tType=1&cid=&screenType=2`
-  //     // top.U.MD.D.I.openInApplication("studyDetail", res.value[0][0].courseId, 2, user.user.type);
-  //     top.U.MD.D.I.openInApplication('setUrl',{url:url2,title:'课程详情',id:new Date().getTime()})
-  //   } else {
-  //     updateCourseId(id, "studyDetail")
-  //   }
-  // }, [], { "type": "POST", "withCredentials": true });
-
 }
+
+
+const courseUrl = ref('')
+ const getCourseUrl = (item) => {
+  // return console.log(item);
+  
+      let _str = ""
+      if(item.state == 1){
+        _str = "course_stageMode_open"
+      }if(item.state == 2){
+        _str = "course_taskMode_open"
+      }if(item.state == 3){
+        _str = "course_easyMode_open"
+      }if(item.state == 5){
+        _str = "course_aiMode_open"
+      }if(item.state == 6){
+        _str = "course_aiEasyMode_open"
+      }if(item.state == 7){
+        _str = "course_pptMode_open"
+      }
+      addOp3('1', "", { courseid: item.courseId, type: _str }, "success")
+
+      //  window.topU.postMessage({ cid: item.courseId, screenType: "3" }, "*");
+      // let url = 'https://beta.pbl.cocorobo.cn'
+      // if (window.location.href.includes('beta')) {
+      //   url = url
+      // }else if (lang.lang === 'cn') {
+      //   url = 'https://pbl.cocorobo.cn'
+      // }else if (lang.lang === 'hk') {
+      //   url = 'https://pbl.cocorobo.hk'
+      // }else if (lang.lang === 'en') {
+      //   url = 'https://pbl.cocorobo.com'
+      // }
+      let url = '';
+      if (lang.lang == 'hk') {
+        url = "https://pbl.cocorobo.hk"
+      }else if (lang.lang == 'en') {
+        url = "https://pbl.cocorobo.com"
+      }else{
+        url = "https://pbl.cocorobo.cn"
+      }
+      let url2 = `${url}/pbl-student-table/dist/#/courseDetail?userid=${user.user.userid}&oid=${user.user.organizeid}&org=${user.user.org}&courseId=${item.courseId}&tType=1&cid=&screenType=2`
+
+      courseUrl.value = url2
+    }
 const getTimeCourse = (id, item) => {
   if (setIntervalNum.value) {
     clearInterval(setIntervalNum.value)
@@ -575,21 +597,6 @@ const getTimeCourse = (id, item) => {
     })
   }, interValtTime);
 }
-// const updateCourse = (id, item) => {
-//   // 会返回courseId和state 两个参数  然后打开
-//   getTimeCourse(id, item)
-//   top.U.A.Request("https://pbl.cocorobo.cn/api/pbl/getcopyCourseByUseridSz", [id, user.user.userid], function (res) {
-//     console.log(res)
-//     if (res.value[0].length > 0) {
-//       // let isSave = res.value[0].filter(x => {
-//       //   return x.courseId == id
-//       // })
-//       top.U.MD.D.I.openInApplication('openCourseNewUpdate', res.value[0][0].courseId); //这个是打开指定的课程接口
-//     } else {
-//       updateCourseId(id, "openCourseNewUpdate")
-//     }
-//   }, [], { "type": "POST", "withCredentials": true });
-// }
 
 const updateCourseId = (id, type) => {
   axios.post('https://pbl.cocorobo.cn/api/pbl/copyCourseSz', {id: id +','+ user.user.userid}, {
@@ -1023,4 +1030,13 @@ watchEffect(() => {
 .grandTitle3{
   margin-top: 0;
 }
+.courseIframe{
+  width: 100vw;
+  height: 100vh;
+  position: fixed;
+  z-index: 99999;
+  top: 0;
+  left: 0;
+  border: none;
+}
 </style>

+ 109 - 0
src/mixins/mixin.js

@@ -0,0 +1,109 @@
+import { userInfoStore } from '../stores/counter'
+import axios from 'axios'
+import qs from 'qs'
+export const myMixin = {
+  data() {
+    return {
+        userJson: {},
+        new_url: 'https://appapi.cocorobo.cn'
+    };
+  },
+  methods: {
+    detectBrowser() {
+      const ua = navigator.userAgent;
+
+      // 按优先级顺序检测
+      if (ua.includes("Edg/") || ua.includes("Edge/")) {
+        return "Microsoft Edge";
+      } else if (ua.includes("Firefox")) {
+        return "Mozilla Firefox";
+      } else if (ua.includes("Trident") || ua.includes("MSIE")) {
+        return "Internet Explorer";
+      } else if (ua.includes("360EE")) {
+        return "360 Browser (极速模式)";
+      } else if (ua.includes("360SE")) {
+        return "360 Browser (安全模式)";
+      } else if (ua.includes("SLBrowser")) {
+        return "QQ Browser";
+      } else if (ua.includes("UCBrowser")) {
+        return "UC Browser";
+      } else if (ua.includes("Opera") || ua.includes("OPR/")) {
+        return "Opera";
+      } else if (ua.includes("Chrome") && !ua.includes("Edg/")) {
+        return "Google Chrome";
+      } else if (ua.includes("Safari/") && !ua.includes("Chrome")) {
+        return "Safari";
+      } else {
+        return "Other Browser";
+      }
+    },
+    async addOp3(userTime, loadTime, object, status,api = 'selectUser') {
+      const user = userInfoStore()
+      if (!user.user.userid) return
+
+      try {
+        if(!this.userJson || !this.userJson.accountNumber){
+            let res = await axios.get(`https://pbl.cocorobo.cn/api/pbl/${api}?userid=`+user.user.userid)
+            this.userJson = res.data[0][0]
+        }
+      } catch (e) {
+        console.log(e);
+        return this.addOp3(userTime, loadTime, object, status,'selectUser2');
+      }
+      let _time = new Date()
+        .toLocaleString("zh-CN", { hour12: false, timeZone: "Asia/Shanghai" })
+        .replace(/\//g, "-");
+      let browser = this.detectBrowser();
+      const params = {
+        userid: user.user.userid,
+        username: this.userJson.username,
+        accountNumber: this.userJson.accountNumber,
+        org: this.userJson.orgName,
+        school: this.userJson.schoolName,
+        role: this.userJson.type =='1'?'老师':'学生',
+        browser: browser,
+        userTime: userTime == "1" ? _time : userTime, // 使用时间 1次的就1 其次传秒
+        loadTime: loadTime, //load的时间没有就“”
+        object: JSON.stringify(object), //执行信息传json
+        status: status //成功返回success。失败返回error的信息
+      };
+      console.log('params',params);
+     let encoded = {};
+
+      for (const key in params) {
+        if (Object.hasOwnProperty.call(params, key)) {
+          encoded[key] = encodeURIComponent(params[key]);
+        }
+      }
+      console.log('encoded',encoded);
+      // params = qs.stringify([encoded]) //序列化post 参数
+      axios
+        .post("https://pbl.cocorobo.cn/api/mongo/updateUserData2", [encoded], {
+          headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
+          withCredentials: true
+        })
+        .then(res => {
+          console.log('res',res);
+          if (res.data.status == 1) {
+            console.log("保存成功");
+          } else {
+            console.log("保存失败");
+          }
+        })
+        .catch(e => {
+          console.log("保存失败");
+          console.log(e);
+        });
+    }
+
+  }
+};
+
+export function addOp3(...args) {
+  const ctx = {
+    ...myMixin.data(),
+    detectBrowser: myMixin.methods.detectBrowser,
+    addOp3: myMixin.methods.addOp3,
+  }
+  return myMixin.methods.addOp3.call(ctx, ...args)
+}