index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import Vue from "vue";
  2. import Router from "vue-router";
  3. import store from '../store'
  4. Vue.use(Router);
  5. const originalPush = Router.prototype.push;
  6. Router.prototype.push = function push(location) {
  7. return originalPush.call(this, location).catch((err) => err);
  8. };
  9. // 其他路由
  10. let constantRoutes = [
  11. {
  12. path: "/",
  13. component: () => import("@/views/login/login.vue"),
  14. meta: {
  15. title: "login",
  16. },
  17. },
  18. {
  19. path: "/login",
  20. component: () => import("@/views/login/login_ruoyan.vue"),
  21. meta: {
  22. title: "login",
  23. },
  24. },
  25. // 个人中心
  26. {
  27. path: "/userInfo",
  28. redirect: "/userInfo/personInfo",
  29. component: () => import("@/views/userInfo/index"),
  30. meta: {
  31. title: "个人中心",
  32. },
  33. children: [
  34. {
  35. path: "personInfo",
  36. component: () => import("@/views/userInfo/personInfo"),
  37. meta: {
  38. title: "个人信息",
  39. },
  40. },
  41. ],
  42. },
  43. ];
  44. // 学生端分析报告
  45. let studentAnalysisReport = {
  46. path: "/studentAnalysisReport",
  47. redirect: "/studentAnalysisReport/list",
  48. component: () => import("@/views/analysisReport/index"),
  49. children: [
  50. {
  51. path: "/jointStudentAnalysisReport/list", // 报告列表
  52. meta: {
  53. title: "分析报告",
  54. },
  55. component: () => import("@/views/analysisReport/studentPage/list/mainPage"),
  56. },
  57. {
  58. path: "/studentAnalysisReport/list", // 报告列表
  59. meta: {
  60. title: "校考分析报告",
  61. },
  62. component: () => import("@/views/analysisReport/studentPage/list/mainPage"),
  63. },
  64. {
  65. name: "reportDetails",
  66. path: "/studentAnalysisReport/reportDetails",
  67. component: () => import("@/views/analysisReport/studentPage/mainPage"),
  68. children: [
  69. {
  70. path: "scrolReport",
  71. component: () => import("@/views/analysisReport/studentPage/scrolReport/transcript"),
  72. meta: {
  73. title: "学生分析",
  74. },
  75. },
  76. {
  77. path: "studentReport",
  78. meta: {
  79. title: "学生报告册",
  80. },
  81. component: () => import("@/views/analysisReport/studentPage/downloadPdf/studentReport"),
  82. },
  83. {
  84. path: "personalWrongQuestions",
  85. component: () => import("@/views/analysisReport/wrongQuestion/index"),
  86. meta: {
  87. title: "个性化错题",
  88. },
  89. },
  90. {
  91. path: "personalProfile",
  92. component: () => import("@/views/analysisReport/personalProfile/index"),
  93. meta: {
  94. title: "个人画像",
  95. },
  96. },
  97. ],
  98. },
  99. ],
  100. };
  101. const createRouter = () =>
  102. new Router({
  103. mode: "hash",
  104. routes: [
  105. ...constantRoutes,
  106. studentAnalysisReport
  107. ],
  108. scrollBehavior(to, from, savedPosition) {
  109. if (savedPosition) {
  110. return savedPosition;
  111. } else {
  112. return {
  113. x: 0,
  114. y: 0,
  115. };//路由切换时,滚动条回到顶部
  116. }
  117. },
  118. });
  119. // 添加统计分析脚本的函数
  120. function addAnalyticsScript() {
  121. // 移除已存在的统计脚本
  122. let existingScript = document.getElementById('_bxtj');
  123. // console.log('移除已存在的统计脚本...',existingScript);
  124. while (existingScript) {
  125. existingScript.remove();
  126. existingScript = document.getElementById('_bxtj');
  127. }
  128. // 移除已存在的统计脚本
  129. let existingScriptFrame = document.getElementById('_bxtjiframe');
  130. // console.log('移除已存在的统计脚本...',existingScriptFrame);
  131. while (existingScriptFrame) {
  132. existingScriptFrame.remove();
  133. existingScriptFrame = document.getElementById('_bxtjiframe');
  134. }
  135. console.log('添加统计分析脚本...');
  136. // 等待DOM加载完成
  137. setTimeout(() => {
  138. var _s = document.createElement('script');
  139. _s.setAttribute('type', 'text/javascript');
  140. _s.setAttribute('id', '_bxtj');
  141. _s.setAttribute('async', true);
  142. // 获取当前用户信息
  143. const userInfo = store.state.user.userInfo || {};
  144. const currentUser = userInfo.loginName || ''; // 当前用户名
  145. const subSiteName = userInfo.schoolName || '';
  146. const mySiteId = localStorage.getItem("user_schoolWebSiteId") || ''; // 你的站点ID
  147. console.log("当前学校站点id", userInfo, mySiteId);
  148. if (mySiteId != '') {
  149. // 构建URL(按照原始代码格式)
  150. let src = `https://bjedures.bjedu.cn/bjjw_logdb/bxlog.js?user=${currentUser}&id=${mySiteId}`;
  151. if (subSiteName) {
  152. src += `&subSiteName=${encodeURIComponent(subSiteName)}`;
  153. }
  154. _s.setAttribute('src', src);
  155. var body = document.getElementsByTagName('body');
  156. body[0].appendChild(_s);
  157. console.log('统计分析脚本已添加到body中。');
  158. }
  159. }, 1000);//1秒后添加
  160. }
  161. let router = createRouter();
  162. router.beforeEach((to, from, next) => {
  163. if (to.meta.title) {
  164. document.title = "大数据精准教学诊断平台-" + to.meta.title;
  165. }
  166. next();
  167. });
  168. // 路由后置守卫:添加统计脚本
  169. router.afterEach(() => {
  170. // 添加统计分析脚本
  171. addAnalyticsScript()
  172. });
  173. export default router;