mainPage.vue 7.8 KB

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