mainPage.vue 15 KB

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