| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- export const myMixin = {
- data() {
- return {
- userJson: {},
- };
- },
- 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') {
- if (!this.$route.query.userid) return
- try {
- if(!this.userJson || !this.userJson.accountNumber){
- let res = await this.ajax.get(this.$store.state.api + api, {
- userid: this.$route.query.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();
- let params = {
- userid: this.$route.query.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);
-
- this.ajax
- .post(this.$store.state.apiM + 'updateUserData2', [params])
- .then(res => {
- if (res.data.status == 1) {
- console.log("保存成功");
- } else {
- console.log("保存失败");
- }
- })
- .catch(e => {
- console.log("保存失败");
- console.log(e);
- });
- },
- // 新增:上课/备课数据实时同步接口
- async syncClassData(classData,api = 'selectUser') {
- if (!this.$route.query.userid) return
- try {
- if(!this.userJson || !this.userJson.accountNumber){
- let res = await this.ajax.get(this.$store.state.api + api, {
- userid: this.$route.query.userid
- });
- this.userJson = res.data[0][0]
- }
- } catch (e) {
- console.log(e);
- return this.syncClassData(classData,'selectUser2');
- }
- let courseGrade = classData.courseGrade ? await this.ajax.get(this.$store.state.api + "getClassById", { id: classData.courseGrade }) : '';
- let coursePackageName = await this.ajax.get(this.$store.state.api + "getCopyCourseName", { id: classData.courseId });
- let params = {
- "serverName": "深教AI6",
- "dataType": 1,
- "teacherName": this.userJson.username,
- "teacherAccount": this.userJson.accountNumber,
- "teacherPhone": this.userJson.phonenumber,
- "eduId": this.userJson.sessionid,
- "schoolName": this.userJson.schoolName,
- "area": this.schooldest,
- "coursePackageName": coursePackageName.data[0][0].title,
- "courseId": classData.courseId,
- "courseName": classData.title,
- "courseGrade": courseGrade ? courseGrade.data[0][0].name : '无年级',
- "courseTime": classData.courseTime,
- "startTime": classData.startTime,
- "endTime": classData.endTime
- }
- try {
- const response = await this.ajax.post(
- this.$store.state.apiSz + 'sync/class',
- params
- );
- return { success: true, data: response.data };
- } catch (error) {
- console.error("同步失败:", error);
- return { success: false, msg: error };
- }
- },
- // 新增:上课/备课数据实时同步接口
- async syncClassData2(classData,api = 'selectUser') {
- if (!this.$route.query.userid) return
- try {
- if(!this.userJson || !this.userJson.accountNumber){
- let res = await this.ajax.get(this.$store.state.api + api, {
- userid: this.$route.query.userid
- });
- this.userJson = res.data[0][0]
- }
- } catch (e) {
- console.log(e);
- return this.syncClassData(classData,'selectUser2');
- }
- let courseGrade = classData.courseGrade ? await this.ajax.get(this.$store.state.api + "getClassById", { id: classData.courseGrade }) : '';
- let coursePackageName = await this.ajax.get(this.$store.state.api + "getCopyCourseName", { id: classData.courseId });
- let params = {
- "serverName": "深教AI6",
- "dataType": 0,
- "teacherName": this.userJson.username,
- "teacherAccount": this.userJson.accountNumber,
- "teacherPhone": this.userJson.phonenumber,
- "eduId": this.userJson.sessionid,
- "schoolName": this.userJson.schoolName,
- "area": this.schooldest,
- "coursePackageName": coursePackageName.data[0][0].title,
- "courseId": classData.courseId,
- "courseName": classData.title,
- "courseGrade": courseGrade ? courseGrade.data[0][0].name : '无年级',
- "courseTime": classData.courseTime,
- "startTime": classData.startTime,
- "endTime": classData.endTime
- }
- try {
- const response = await this.ajax.post(
- this.$store.state.apiSz + 'sync/class',
- params
- );
- return { success: true, data: response.data };
- } catch (error) {
- console.error("同步失败:", error);
- return { success: false, msg: error };
- }
- }
- }
- };
|