index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. path: "studentCase",
  99. component: () => import("@/views/analysisReport/studentPage/studentCase/mainPage"),
  100. meta: {
  101. title: "一生一案",
  102. },
  103. },
  104. {
  105. path: "studentReport",
  106. component: () => import("@/views/analysisReport/studentPage/downloadPdf/studentReport"),
  107. meta: {
  108. title: "一生一案",
  109. },
  110. }
  111. ],
  112. },
  113. ],
  114. };
  115. const createRouter = () =>
  116. new Router({
  117. mode: "hash",
  118. routes: [
  119. ...constantRoutes,
  120. studentAnalysisReport
  121. ],
  122. scrollBehavior(to, from, savedPosition) {
  123. if (savedPosition) {
  124. return savedPosition;
  125. } else {
  126. return {
  127. x: 0,
  128. y: 0,
  129. };//路由切换时,滚动条回到顶部
  130. }
  131. },
  132. });
  133. // 添加统计分析脚本的函数
  134. function addAnalyticsScript() {
  135. // 移除已存在的统计脚本
  136. let existingScript = document.getElementById('_bxtj');
  137. while (existingScript) {
  138. existingScript.remove();
  139. existingScript = document.getElementById('_bxtj');
  140. }
  141. // 移除已存在的统计脚本
  142. let existingScriptFrame = document.getElementById('_bxtjiframe');
  143. while (existingScriptFrame) {
  144. existingScriptFrame.remove();
  145. existingScriptFrame = document.getElementById('_bxtjiframe');
  146. }
  147. // 等待DOM加载完成
  148. setTimeout(() => {
  149. var _s = document.createElement('script');
  150. _s.setAttribute('type', 'text/javascript');
  151. _s.setAttribute('id', '_bxtj');
  152. _s.setAttribute('async', true);
  153. // 获取当前用户信息
  154. const userInfo = store.state.user.userInfo || {};
  155. const currentUser = userInfo.loginName || ''; // 当前用户名
  156. const subSiteName = userInfo.schoolName || '';
  157. const mySiteId = localStorage.getItem("user_schoolWebSiteId") || ''; // 你的站点ID
  158. if (mySiteId != '') {
  159. // 构建URL(按照原始代码格式)
  160. let src = `https://bjedures.bjedu.cn/bjjw_logdb/bxlog.js?user=${currentUser}&id=${mySiteId}`;
  161. if (subSiteName) {
  162. src += `&subSiteName=${encodeURIComponent(subSiteName)}`;
  163. }
  164. _s.setAttribute('src', src);
  165. var body = document.getElementsByTagName('body');
  166. body[0].appendChild(_s);
  167. }
  168. }, 1000);//1秒后添加
  169. }
  170. let router = createRouter();
  171. router.beforeEach((to, from, next) => {
  172. if (to.meta.title) {
  173. document.title = "大数据精准教学诊断平台-" + to.meta.title;
  174. }
  175. next();
  176. });
  177. // 路由后置守卫:添加统计脚本
  178. router.afterEach(() => {
  179. // 添加统计分析脚本
  180. addAnalyticsScript()
  181. });
  182. export default router;