mainPage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <!-- 分析报告详情总页面 -->
  3. <div class="analysis_main">
  4. <div :class="['main_header', { 'full_screen': isLianXiao }]" ref="mainHeader">
  5. <div class="header_left">
  6. <span class="back_button" @click="GoBack">
  7. <i class="iconfont icon_return"></i>返回
  8. </span>
  9. <span class="header_title">{{ pageName }}</span>
  10. </div>
  11. <div class="header_right">
  12. <div class="select_list" v-if="isShowFilter">
  13. <el-select style="width: 120px" v-model="filterData[index].value" :placeholder="'请选择' + item.name"
  14. class="select_item" @change="ChangeFilters({ index: index, value: $event })"
  15. v-for="(item, index) in filteredFilterData" :key="index" v-show="item.list.length > 1">
  16. <el-option v-for="option in item.list" :key="option.value" :label="option.label"
  17. :value="option.value"></el-option>
  18. </el-select>
  19. </div>
  20. <template v-if="isShowBtn">
  21. <el-button size="medium" :disabled="!canBtnClick"
  22. @click="downloadWrongQuestions(0)">下载错题本</el-button>
  23. <el-button :disabled="!canBtnClick" type="primary" size="medium"
  24. @click="downloadWrongQuestions(1)">下载个性化提升手册</el-button>
  25. </template>
  26. <!-- <el-button v-if="isShowPadfBtn" style="margin-left: 10px;" size="medium" type="primary" :loading="stuPdfLoading" @click="StuDownloadPDF">下载PDF</el-button> -->
  27. </div>
  28. </div>
  29. <div class="main_content">
  30. <div class="content_right" ref="rightContent" @scroll="ScrollChange">
  31. <div :class="['content_right_scroll', { 'full_screen': isLianXiao }]" ref="contentRightScroll">
  32. <template v-if="isLianXiao">
  33. <div class="mm_body">
  34. <div class="left">
  35. <button class="mm_btn mb_10" :class="{ active: activeBtn === pathOne }"
  36. @click="toPage(pathOne)">成绩分析</button>
  37. <button v-if="isShowKnowledgeButtons" class="mm_btn mb_10"
  38. :class="{ active: activeBtn === pathTwo }" @click="toPage(pathTwo)">举一反三</button>
  39. <button v-if="!isTotalScore && schoolId == '520929546006958081'" class="mm_btn mb_10"
  40. :class="{ active: activeBtn === pathThree }"
  41. @click="toPage(pathThree)">个人画像</button>
  42. </div>
  43. <div class="right">
  44. <div class="page_filter" ref="filterContent">
  45. <FiltersItem :filtersData="filteredFilterData" @selectItem="ChangeFilters">
  46. </FiltersItem>
  47. </div>
  48. <router-view ref="child" @isPdfDataLoadEnd="isPdfDataLoadEnd"
  49. @closePdfLoading="closePdfLoading"></router-view>
  50. </div>
  51. </div>
  52. </template>
  53. <template v-else>
  54. <div class="page_filter" ref="filterContent">
  55. <FiltersItem :filtersData="filteredFilterData" @selectItem="ChangeFilters"></FiltersItem>
  56. </div>
  57. <router-view ref="child" @isPdfDataLoadEnd="isPdfDataLoadEnd"
  58. @closePdfLoading="closePdfLoading"></router-view>
  59. </template>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import FiltersItem from "@/components/FiltersItem_ruoyan.vue";
  67. export default {
  68. components: { FiltersItem },
  69. computed: {
  70. pageName() {
  71. // let examName = this.$store.state.report.examSelectItem.examName;
  72. // if (examName) {
  73. // return examName.split("_")[0];
  74. // }
  75. return this.$store.state.report.examSelectItem.examName
  76. },
  77. updateScrollTop() {
  78. return this.$store.state.report.updateScrollTop;//监听改变滚动条参数
  79. },
  80. isShowKnowledgeButtons() {
  81. // 从环境变量中获取基础URL,判断是否显示按钮
  82. return process.env.VUE_APP_BASE !== 'https://www.k12100.com';
  83. },
  84. // 判断是否为总分科目,用于控制个人画像按钮显示
  85. isTotalScore() {
  86. return this.$store.state.report.isTotalScore;
  87. },
  88. // 动态过滤筛选数据,在个人画像页面隐藏总分选项
  89. filteredFilterData() {
  90. // 检查当前是否在个人画像页面
  91. const isPersonalProfilePage = this.$route.path === '/studentAnalysisReport/reportDetails/personalProfile';
  92. if (!isPersonalProfilePage) {
  93. // 非个人画像页面,返回原始数据
  94. return this.filterData;
  95. }
  96. // 深拷贝原始数据,避免直接修改
  97. const updatedFilterData = JSON.parse(JSON.stringify(this.filterData));
  98. // 遍历筛选数据,找到科目名称筛选项
  99. updatedFilterData.forEach(filterItem => {
  100. if (filterItem.type === 'subjectName') {
  101. // 过滤掉总分选项(isTotal为1或subjectGroupType为1的选项)
  102. filterItem.list = filterItem.list.filter(item => item.isTotal !== 1 && item.subjectGroupType !== 1);
  103. }
  104. });
  105. return updatedFilterData;
  106. },
  107. canBtnClick() {
  108. return this.$store.state.question.canDownloanBtnClick;
  109. }
  110. },
  111. data() {
  112. return {
  113. isShowFilter: false, //是否显示筛选条件
  114. isShowBtn: false, //是否显示下载按钮
  115. isShowPadfBtn: false,//是否显示下载pdf按钮
  116. isPdfLoadEnd: false,//报告册数据是否加载完成
  117. filterData: [
  118. {
  119. name: "科目名称",
  120. value: '0',
  121. type: "subjectName",
  122. list: [], //选项
  123. }
  124. ],
  125. resizeTimer: null,
  126. activeBtn: this.$route.path,
  127. pathOne: '/studentAnalysisReport/reportDetails/scrolReport',
  128. pathTwo: '/studentAnalysisReport/reportDetails/personalWrongQuestions',
  129. pathThree: '/studentAnalysisReport/reportDetails/personalProfile',//个人画像
  130. isLianXiao: false,//是否联校
  131. stuPdfLoading: false,
  132. schoolId: this.$store.state.user.userInfo.id,
  133. };
  134. },
  135. created() {
  136. this.isShowPadfBtn = this.$route.path == '/studentAnalysisReport/reportDetails/scrolReport';
  137. const schoolType = sessionStorage.getItem('schoolType') || '1'; //1:单校 2:联校
  138. this.isLianXiao = schoolType === '2';
  139. if (this.$store.state.report.filterData.length > 0) {
  140. //有数据
  141. this.filterData = this.$store.state.report.filterData;
  142. }
  143. // 绑定 resize 事件
  144. window.addEventListener('resize', this.HandleWidthChange);
  145. this.$nextTick(() => {
  146. this.SetHeadWidth();
  147. })
  148. },
  149. methods: {
  150. toPage(type) {
  151. this.activeBtn = type;
  152. this.$router.push(type);
  153. },
  154. // 处理宽度变化的逻辑
  155. HandleWidthChange() {
  156. // 防抖:避免窗口 resize 时频繁触发(100ms 内只执行一次)
  157. clearTimeout(this.resizeTimer);
  158. this.resizeTimer = setTimeout(() => {
  159. this.SetHeadWidth();
  160. }, 100);
  161. },
  162. SetHeadWidth() {
  163. if (this.$refs.contentRightScroll) {
  164. let scrollDivWidth = 0;
  165. if (this.isLianXiao) {
  166. scrollDivWidth = this.$refs.contentRightScroll.offsetWidth - 20;//联校
  167. } else {
  168. scrollDivWidth = this.$refs.contentRightScroll.offsetWidth;
  169. }
  170. const headDiv = this.$refs.mainHeader;
  171. headDiv.style.width = `${scrollDivWidth}px`;
  172. }
  173. },
  174. // 筛选事件
  175. ChangeFilters(e) {
  176. this.filterData[e.index].value = e.value;
  177. // 选中科目数据
  178. let courseObj = this.filterData[0].list.find(item => item.value == this.filterData[0].value);
  179. let filterObject = {
  180. examLevel: courseObj.examLevel,//1-联考 2-单校
  181. contrastExamIds: courseObj.contrastExamIds,//多次考试任务对比ID,不包含当前任务ID
  182. examId: courseObj.examId,//考试id
  183. subjectCode: courseObj.subjectCode, //科目code
  184. subjectGroupType: courseObj.subjectGroupType, //是否为组合科目 1为组合科目 0为非组合科目
  185. subjectName: courseObj.subjectName,//科目名称
  186. isTotal: courseObj.isTotal //是否为总分科目 1为总分 0为非总分
  187. };
  188. //设置是否是总分
  189. const isTotal = courseObj.isTotal == 1 || courseObj.subjectGroupType == 1;//1为总分 0为非总分 1为组合科目 0为非组合科目
  190. this.$store.commit("report/set_state", {
  191. key: "isTotalScore",
  192. value: isTotal,
  193. });
  194. localStorage.setItem('reportExamCourseId', courseObj.subjectId);//单科的考试科目id
  195. localStorage.setItem('reportIsTotalScore', isTotal)
  196. this.$store.dispatch("report/UpdateFilterObject", filterObject);
  197. // 如果选择了总分且当前在个人画像页面,跳转到成绩分析页面
  198. if (isTotal && this.$route.path === '/studentAnalysisReport/reportDetails/personalProfile') {
  199. this.toPage(this.pathOne);
  200. }
  201. },
  202. // 滚动条事件
  203. ScrollChange() {
  204. const path = this.$route.path;
  205. let scrollTop = this.$refs.rightContent.scrollTop;
  206. if (path === '/studentAnalysisReport/reportDetails/scrolReport') {
  207. const filterContent = this.$refs.filterContent;
  208. let scrollHeight = 242;
  209. if (filterContent) {
  210. scrollHeight = filterContent.clientHeight;
  211. }
  212. this.isShowFilter = (scrollTop >= scrollHeight);
  213. this.$store.commit("report/set_state", {
  214. key: "isShowFilter",
  215. value: this.isShowFilter,
  216. });
  217. if (this.$refs.child && typeof this.$refs.child.GetScrollTop === 'function') {
  218. this.$refs.child.GetScrollTop(scrollTop);
  219. }
  220. }
  221. if (path === '/studentAnalysisReport/reportDetails/personalWrongQuestions') {
  222. this.isShowBtn = (scrollTop >= 250);
  223. if (this.$refs.child && typeof this.$refs.child.GetScrollTop === 'function') {
  224. this.$refs.child.GetScrollTop(scrollTop);
  225. }
  226. }
  227. },
  228. //重置滚动条
  229. ResetScroll() {
  230. this.$nextTick(() => {
  231. if (this.$refs.rightContent) {
  232. this.$refs.rightContent.scrollTop = 0;
  233. }
  234. })
  235. },
  236. downloadWrongQuestions(type) {
  237. this.$store.commit("question/SET_VARIANTION", type);
  238. },
  239. //返回按钮点击
  240. GoBack() {
  241. const schoolType = sessionStorage.getItem('schoolType');
  242. if (schoolType == 1) {//单校
  243. this.$router.push("/studentAnalysisReport/list");
  244. } else {//联校
  245. this.$router.push("/jointStudentAnalysisReport/list");
  246. }
  247. },
  248. StuDownloadPDF() {
  249. if (!this.isPdfLoadEnd) {
  250. return this.$message.warning('请稍等报告数据生成中!');
  251. }
  252. this.stuPdfLoading = true;
  253. this.$refs.child.DownloadPdf();
  254. },
  255. isPdfDataLoadEnd() {
  256. this.isPdfLoadEnd = true;
  257. },
  258. closePdfLoading() {
  259. this.stuPdfLoading = false;
  260. },
  261. // 处理筛选数据更新,在个人画像页面隐藏总分选项
  262. handleFilterDataUpdate() {
  263. // 检查当前是否在个人画像页面
  264. const isPersonalProfilePage = this.$route.path === '/studentAnalysisReport/reportDetails/personalProfile';
  265. if (isPersonalProfilePage) {
  266. // 深拷贝原始数据,避免直接修改props
  267. const updatedFilterData = JSON.parse(JSON.stringify(this.filterData));
  268. // 遍历筛选数据,找到科目名称筛选项
  269. updatedFilterData.forEach((filterItem, index) => {
  270. if (filterItem.type === 'subjectName') {
  271. // 过滤掉总分选项(isTotal为1的选项)
  272. const nonTotalItems = filterItem.list.filter(item => item.isTotal !== 1 && item.subjectGroupType !== 1);
  273. // 检查当前选中的是否是总分选项
  274. const currentSelected = filterItem.list.find(item => item.value === filterItem.value);
  275. const isCurrentTotal = currentSelected && (currentSelected.isTotal === 1 || currentSelected.subjectGroupType === 1);
  276. // 如果当前选中的是总分选项且有其他选项,切换到第一个非总分选项
  277. if (isCurrentTotal && nonTotalItems.length > 0) {
  278. this.ChangeFilters({ index, value: nonTotalItems[0].value });
  279. }
  280. }
  281. });
  282. }
  283. },
  284. },
  285. watch: {
  286. '$route'(to, from) {
  287. this.ResetScroll();//重置滚动条
  288. this.handleFilterDataUpdate();
  289. },//路由变化 重置页面滚动条位置
  290. updateScrollTop: {
  291. handler(newVal) {
  292. this.ResetScroll();//重置滚动条
  293. },
  294. },
  295. // 监听筛选数据变化,动态过滤总分选项
  296. filterData: {
  297. deep: true,
  298. handler() {
  299. this.handleFilterDataUpdate();
  300. }
  301. }
  302. },
  303. beforeUnmount() {
  304. // 解绑事件,避免内存泄漏
  305. window.removeEventListener('resize', this.HandleWidthChange);
  306. // 清除计时器
  307. clearTimeout(this.resizeTimer);
  308. }
  309. };
  310. </script>
  311. <style scoped lang="scss">
  312. .mm_body {
  313. display: flex;
  314. width: 100%;
  315. justify-content: space-between;
  316. .left {
  317. width: 170px;
  318. padding: 20px;
  319. border-radius: 10px;
  320. background-color: #ffffff;
  321. height: fit-content;
  322. box-sizing: border-box;
  323. position: sticky;
  324. top: 0px;
  325. .mb_10 {
  326. margin-bottom: 10px;
  327. }
  328. }
  329. .right {
  330. width: calc(100% - 180px);
  331. }
  332. }
  333. </style>