mixin.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. export const myMixin = {
  2. data() {
  3. return {
  4. userJson: {},
  5. };
  6. },
  7. methods: {
  8. detectBrowser() {
  9. const ua = navigator.userAgent;
  10. // 按优先级顺序检测
  11. if (ua.includes("Edg/") || ua.includes("Edge/")) {
  12. return "Microsoft Edge";
  13. } else if (ua.includes("Firefox")) {
  14. return "Mozilla Firefox";
  15. } else if (ua.includes("Trident") || ua.includes("MSIE")) {
  16. return "Internet Explorer";
  17. } else if (ua.includes("360EE")) {
  18. return "360 Browser (极速模式)";
  19. } else if (ua.includes("360SE")) {
  20. return "360 Browser (安全模式)";
  21. } else if (ua.includes("SLBrowser")) {
  22. return "QQ Browser";
  23. } else if (ua.includes("UCBrowser")) {
  24. return "UC Browser";
  25. } else if (ua.includes("Opera") || ua.includes("OPR/")) {
  26. return "Opera";
  27. } else if (ua.includes("Chrome") && !ua.includes("Edg/")) {
  28. return "Google Chrome";
  29. } else if (ua.includes("Safari/") && !ua.includes("Chrome")) {
  30. return "Safari";
  31. } else {
  32. return "Other Browser";
  33. }
  34. },
  35. async addOp3(userTime, loadTime, object, status,api = 'selectUser') {
  36. if (!this.$route.query.userid) return
  37. try {
  38. if(!this.userJson || !this.userJson.accountNumber){
  39. let res = await this.ajax.get(this.$store.state.api + api, {
  40. userid: this.$route.query.userid
  41. });
  42. this.userJson = res.data[0][0]
  43. }
  44. } catch (e) {
  45. console.log(e);
  46. return this.addOp3(userTime, loadTime, object, status,'selectUser2');
  47. }
  48. let _time = new Date()
  49. .toLocaleString("zh-CN", { hour12: false, timeZone: "Asia/Shanghai" })
  50. .replace(/\//g, "-");
  51. let browser = this.detectBrowser();
  52. let params = {
  53. userid: this.$route.query.userid,
  54. username: this.userJson.username,
  55. accountNumber: this.userJson.accountNumber,
  56. org: this.userJson.orgName,
  57. school: this.userJson.schoolName,
  58. role: this.userJson.type =='1'?'老师':'学生',
  59. browser: browser,
  60. userTime: userTime == "1" ? _time : userTime, // 使用时间 1次的就1 其次传秒
  61. loadTime: loadTime, //load的时间没有就""
  62. object: JSON.stringify(object), //执行信息传json
  63. status: status //成功返回success。失败返回error的信息
  64. };
  65. // console.log('params',params);
  66. this.ajax
  67. .post(this.$store.state.apiM + 'updateUserData2', [params])
  68. .then(res => {
  69. if (res.data.status == 1) {
  70. console.log("保存成功");
  71. } else {
  72. console.log("保存失败");
  73. }
  74. })
  75. .catch(e => {
  76. console.log("保存失败");
  77. console.log(e);
  78. });
  79. },
  80. // 新增:上课/备课数据实时同步接口
  81. async syncClassData(classData,api = 'selectUser') {
  82. if (!this.$route.query.userid) return
  83. try {
  84. if(!this.userJson || !this.userJson.accountNumber){
  85. let res = await this.ajax.get(this.$store.state.api + api, {
  86. userid: this.$route.query.userid
  87. });
  88. this.userJson = res.data[0][0]
  89. }
  90. } catch (e) {
  91. console.log(e);
  92. return this.syncClassData(classData,'selectUser2');
  93. }
  94. let courseGrade = classData.courseGrade ? await this.ajax.get(this.$store.state.api + "getClassById", { id: classData.courseGrade }) : '';
  95. let coursePackageName = await this.ajax.get(this.$store.state.api + "getCopyCourseName", { id: classData.courseId });
  96. let params = {
  97. "serverName": "深教AI6",
  98. "dataType": 1,
  99. "teacherName": this.userJson.username,
  100. "teacherAccount": this.userJson.accountNumber,
  101. "teacherPhone": this.userJson.phonenumber,
  102. "eduId": this.userJson.sessionid,
  103. "schoolName": this.userJson.schoolName,
  104. "area": this.schooldest,
  105. "coursePackageName": coursePackageName.data[0][0].title,
  106. "courseId": classData.courseId,
  107. "courseName": classData.title,
  108. "courseGrade": courseGrade ? courseGrade.data[0][0].name : '无年级',
  109. "courseTime": classData.courseTime,
  110. "startTime": classData.startTime,
  111. "endTime": classData.endTime
  112. }
  113. try {
  114. const response = await this.ajax.post(
  115. this.$store.state.apiSz + 'sync/class',
  116. params
  117. );
  118. return { success: true, data: response.data };
  119. } catch (error) {
  120. console.error("同步失败:", error);
  121. return { success: false, msg: error };
  122. }
  123. },
  124. // 新增:上课/备课数据实时同步接口
  125. async syncClassData2(classData,api = 'selectUser') {
  126. if (!this.$route.query.userid) return
  127. try {
  128. if(!this.userJson || !this.userJson.accountNumber){
  129. let res = await this.ajax.get(this.$store.state.api + api, {
  130. userid: this.$route.query.userid
  131. });
  132. this.userJson = res.data[0][0]
  133. }
  134. } catch (e) {
  135. console.log(e);
  136. return this.syncClassData(classData,'selectUser2');
  137. }
  138. let courseGrade = classData.courseGrade ? await this.ajax.get(this.$store.state.api + "getClassById", { id: classData.courseGrade }) : '';
  139. let coursePackageName = await this.ajax.get(this.$store.state.api + "getCopyCourseName", { id: classData.courseId });
  140. let params = {
  141. "serverName": "深教AI6",
  142. "dataType": 0,
  143. "teacherName": this.userJson.username,
  144. "teacherAccount": this.userJson.accountNumber,
  145. "teacherPhone": this.userJson.phonenumber,
  146. "eduId": this.userJson.sessionid,
  147. "schoolName": this.userJson.schoolName,
  148. "area": this.schooldest,
  149. "coursePackageName": coursePackageName.data[0][0].title,
  150. "courseId": classData.courseId,
  151. "courseName": classData.title,
  152. "courseGrade": courseGrade ? courseGrade.data[0][0].name : '无年级',
  153. "courseTime": classData.courseTime,
  154. "startTime": classData.startTime,
  155. "endTime": classData.endTime
  156. }
  157. try {
  158. const response = await this.ajax.post(
  159. this.$store.state.apiSz + 'sync/class',
  160. params
  161. );
  162. return { success: true, data: response.data };
  163. } catch (error) {
  164. console.error("同步失败:", error);
  165. return { success: false, msg: error };
  166. }
  167. }
  168. }
  169. };