mainPage.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <!-- 分析报告详情总页面 -->
  3. <div class="analysis_main">
  4. <div class="main_header" 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="item.value" :placeholder="'请选择' + item.name" class="select_item"
  14. @change="ChangeFilters({ index: index, value: item.value })" v-for="(item, index) in filterData" :key="index"
  15. v-show="item.list.length > 1">
  16. <el-option v-for="item in item.list" :key="item.value" :label="item.label" :value="item.value"></el-option>
  17. </el-select>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="main_content">
  22. <div class="content_right" ref="rightContent" @scroll="ScrollChange">
  23. <div class="content_right_scroll" ref="contentRightScroll">
  24. <div class="page_filter" ref="filterContent">
  25. <FiltersItem :filtersData="filterData" @selectItem="ChangeFilters"></FiltersItem>
  26. </div>
  27. <router-view ref="child"></router-view>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import FiltersItem from "@/components/FiltersItem_ruoyan.vue";
  35. export default {
  36. components: { FiltersItem },
  37. computed: {
  38. pageName() {
  39. let examName = this.$store.state.report.examSelectItem.examName;
  40. if (examName) {
  41. return examName.split("_")[0];
  42. }
  43. },
  44. updateScrollTop() {
  45. return this.$store.state.report.updateScrollTop;//监听改变滚动条参数
  46. },
  47. },
  48. data() {
  49. return {
  50. isShowFilter: false, //是否显示筛选条件
  51. filterData: [
  52. {
  53. name: "科目名称",
  54. value: '0',
  55. type: "subjectName",
  56. list: [], //选项
  57. }
  58. ],
  59. resizeTimer:null
  60. };
  61. },
  62. created() {
  63. if (this.$store.state.report.filterData.length > 0) {
  64. //有数据
  65. this.filterData = this.$store.state.report.filterData;
  66. }
  67. // 绑定 resize 事件
  68. window.addEventListener('resize', this.HandleWidthChange);
  69. this.$nextTick(()=>{
  70. this.SetHeadWidth();
  71. })
  72. },
  73. methods: {
  74. // 处理宽度变化的逻辑
  75. HandleWidthChange() {
  76. // 防抖:避免窗口 resize 时频繁触发(100ms 内只执行一次)
  77. clearTimeout(this.resizeTimer);
  78. this.resizeTimer = setTimeout(() => {
  79. this.SetHeadWidth();
  80. }, 100);
  81. },
  82. SetHeadWidth(){
  83. const scrollDivWidth = this.$refs.contentRightScroll.offsetWidth;
  84. const headDiv = this.$refs.mainHeader;
  85. headDiv.style.width = `${scrollDivWidth}px`;
  86. },
  87. // 筛选事件
  88. ChangeFilters(e) {
  89. this.filterData[e.index].value = e.value;
  90. // 选中科目数据
  91. let courseObj = this.filterData[0].list.find(item => item.value == this.filterData[0].value);
  92. let filterObject = {
  93. examLevel: courseObj.examLevel,//1-联考 2-单校
  94. contrastExamIds: courseObj.contrastExamIds,//多次考试任务对比ID,不包含当前任务ID
  95. examId: courseObj.examId,//考试id
  96. subjectCode: courseObj.subjectCode, //科目code
  97. subjectGroupType: courseObj.subjectGroupType, //是否为组合科目 1为组合科目 0为非组合科目
  98. subjectGroupNames: courseObj.subjectName,//科目名称
  99. isTotal: courseObj.isTotal //是否为总分科目 1为总分 0为非总分
  100. };
  101. //设置是否是总分
  102. this.$store.commit("report/set_state", {
  103. key: "isTotalScore",
  104. value: courseObj.isTotal == 1 || courseObj.subjectGroupType == 1,//1为总分 0为非总分 1为组合科目 0为非组合科目
  105. });
  106. localStorage.setItem('reportExamCourseId', courseObj.subjectId);//单科的考试科目id
  107. localStorage.setItem('reportIsTotalScore', courseObj.isTotal == 1 || courseObj.subjectGroupType == 1)
  108. console.log("打印筛选数据", filterObject);
  109. this.$store.dispatch("report/UpdateFilterObject", filterObject);
  110. },
  111. // 滚动条事件
  112. ScrollChange() {
  113. let scrollTop = this.$refs.rightContent.scrollTop;
  114. const filterContent = this.$refs.filterContent;
  115. let scrollHeight = 242;
  116. if (filterContent) {
  117. scrollHeight = filterContent.clientHeight;
  118. }
  119. if (scrollTop >= scrollHeight) {
  120. this.isShowFilter = true;
  121. }
  122. else {
  123. this.isShowFilter = false;
  124. }
  125. this.$store.commit("report/set_state", {
  126. key: "isShowFilter",
  127. value: this.isShowFilter,
  128. });
  129. if (this.$refs.child && typeof this.$refs.child.GetScrollTop === 'function') {
  130. this.$refs.child.GetScrollTop(scrollTop);
  131. }
  132. },
  133. //重置滚动条
  134. ResetScroll() {
  135. this.$nextTick(() => {
  136. if (this.$refs.rightContent) {
  137. this.$refs.rightContent.scrollTop = 0;
  138. }
  139. })
  140. },
  141. //返回按钮点击
  142. GoBack() {
  143. this.$router.push("/studentAnalysisReport/list");
  144. },
  145. },
  146. watch: {
  147. '$route'(to, from) {
  148. console.log('路由变化', to, from);
  149. this.ResetScroll();//重置滚动条
  150. },//路由变化 重置页面滚动条位置
  151. updateScrollTop: {
  152. handler(newVal) {
  153. console.log("updateScrollTop changed:", newVal);
  154. this.ResetScroll();//重置滚动条
  155. },
  156. },
  157. },
  158. beforeUnmount() {
  159. // 解绑事件,避免内存泄漏
  160. window.removeEventListener('resize', this.HandleWidthChange);
  161. // 清除计时器
  162. clearTimeout(this.resizeTimer);
  163. }
  164. };
  165. </script>
  166. <style scoped lang="scss"></style>