| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import Vue from "vue";
- import Router from "vue-router";
- import store from '../store'
- Vue.use(Router);
- const originalPush = Router.prototype.push;
- Router.prototype.push = function push(location) {
- return originalPush.call(this, location).catch((err) => err);
- };
- // 其他路由
- let constantRoutes = [
- {
- path: "/",
- component: () => import("@/views/login/login.vue"),
- meta: {
- title: "login",
- },
- },
- {
- path: "/login",
- component: () => import("@/views/login/login_ruoyan.vue"),
- meta: {
- title: "login",
- },
- },
- // 个人中心
- {
- path: "/userInfo",
- redirect: "/userInfo/personInfo",
- component: () => import("@/views/userInfo/index"),
- meta: {
- title: "个人中心",
- },
- children: [
- {
- path: "personInfo",
- component: () => import("@/views/userInfo/personInfo"),
- meta: {
- title: "个人信息",
- },
- },
- ],
- },
- ];
- // 学生端分析报告
- let studentAnalysisReport = {
- path: "/studentAnalysisReport",
- redirect: "/studentAnalysisReport/list",
- component: () => import("@/views/analysisReport/index"),
- children: [
- {
- path: "/jointStudentAnalysisReport/list", // 报告列表
- meta: {
- title: "分析报告",
- },
- component: () => import("@/views/analysisReport/studentPage/list/mainPage"),
- },
- // {
- // path: "/studentAnalysisReport/list", // 报告列表
- // meta: {
- // title: "校考分析报告",
- // },
- // component: () => import("@/views/analysisReport/studentPage/list/mainPage"),
- // },
- {
- name: "reportDetails",
- path: "/studentAnalysisReport/reportDetails",
- component: () => import("@/views/analysisReport/studentPage/mainPage"),
- children: [
- {
- path: "scrolReport",
- component: () => import("@/views/analysisReport/studentPage/scrolReport/transcript"),
- meta: {
- title: "学生分析",
- },
- },
- {
- path: "studentReport",
- meta: {
- title: "学生报告册",
- },
- component: () => import("@/views/analysisReport/studentPage/downloadPdf/studentReport"),
- },
- {
- path: "personalWrongQuestions",
- component: () => import("@/views/analysisReport/wrongQuestion/index"),
- meta: {
- title: "举一反三",
- },
- },
- {
- path: "personalProfile",
- component: () => import("@/views/analysisReport/personalProfile/index"),
- meta: {
- title: "个人画像",
- },
- },
- {
- path: "studentCase",
- component: () => import("@/views/analysisReport/studentPage/studentCase/mainPage"),
- meta: {
- title: "一生一案",
- },
- },
- {
- path: "studentReport",
- component: () => import("@/views/analysisReport/studentPage/downloadPdf/studentReport"),
- meta: {
- title: "一生一案",
- },
- }
- ],
- },
- ],
- };
- const createRouter = () =>
- new Router({
- mode: "hash",
- routes: [
- ...constantRoutes,
- studentAnalysisReport
- ],
- scrollBehavior(to, from, savedPosition) {
- if (savedPosition) {
- return savedPosition;
- } else {
- return {
- x: 0,
- y: 0,
- };//路由切换时,滚动条回到顶部
- }
- },
- });
- // 添加统计分析脚本的函数
- function addAnalyticsScript() {
- // 移除已存在的统计脚本
- let existingScript = document.getElementById('_bxtj');
- while (existingScript) {
- existingScript.remove();
- existingScript = document.getElementById('_bxtj');
- }
- // 移除已存在的统计脚本
- let existingScriptFrame = document.getElementById('_bxtjiframe');
- while (existingScriptFrame) {
- existingScriptFrame.remove();
- existingScriptFrame = document.getElementById('_bxtjiframe');
- }
- // 等待DOM加载完成
- setTimeout(() => {
- var _s = document.createElement('script');
- _s.setAttribute('type', 'text/javascript');
- _s.setAttribute('id', '_bxtj');
- _s.setAttribute('async', true);
- // 获取当前用户信息
- const userInfo = store.state.user.userInfo || {};
- const currentUser = userInfo.loginName || ''; // 当前用户名
- const subSiteName = userInfo.schoolName || '';
- const mySiteId = localStorage.getItem("user_schoolWebSiteId") || ''; // 你的站点ID
- if (mySiteId != '') {
- // 构建URL(按照原始代码格式)
- let src = `https://bjedures.bjedu.cn/bjjw_logdb/bxlog.js?user=${currentUser}&id=${mySiteId}`;
- if (subSiteName) {
- src += `&subSiteName=${encodeURIComponent(subSiteName)}`;
- }
- _s.setAttribute('src', src);
- var body = document.getElementsByTagName('body');
- body[0].appendChild(_s);
- }
- }, 1000);//1秒后添加
- }
- let router = createRouter();
- router.beforeEach((to, from, next) => {
- if (to.meta.title) {
- document.title = "大数据精准教学诊断平台-" + to.meta.title;
- }
- next();
- });
- // 路由后置守卫:添加统计脚本
- router.afterEach(() => {
- // 添加统计分析脚本
- addAnalyticsScript()
- });
- export default router;
|