index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <!-- 头部 -->
  3. <nav-bar height="312" backPath="workspace" title="教师研修" :filterPickerData="state.filterPickerData" :tabList="state.tabList" :onlyTitle="false" :showFilterPicker="true" :showTabs="true" rightWidth="0rpx" @CommonFilterData="CommonFilterData"></nav-bar>
  4. <view class="page_content">
  5. <scroll-view
  6. class="scroll_view_y"
  7. :scroll-top="state.scrollTop"
  8. scroll-y="true"
  9. :refresher-enabled="false"
  10. :enable-back-to-top="true"
  11. :show-scrollbar="false"
  12. :scroll-with-animation="true"
  13. refresher-default-style="none"
  14. refresher-background="#F8F9FD"
  15. :refresher-triggered="state.isRefreshing"
  16. @scrolltolower="OnLoadMore"
  17. @refresherrefresh="OnRefresh"
  18. @scroll="OnScroll">
  19. <view class="refresh_loading" v-if="state.isRefreshing"><uni-load-more status="loading" /></view>
  20. <view class="page_list">
  21. <view class="list_item" v-for="item in state.pageList" :key="item.id">
  22. <view class="item_img_box">
  23. <image class="item_img" mode="aspectFill" :src="item.videoCoverUrl"></image>
  24. <view class="remaining_days">剩余{{item.remainingTime}}</view>
  25. <view class="progress"><view class="done" :style="{width:item.progress}"></view></view>
  26. </view>
  27. <view class="item_title">2025{{item.courseName}}</view>
  28. <view class="item_time">
  29. <image class="img" src="@/static/image/icon/time2x.png"></image>
  30. <text class="time">{{item.courseStartDatetime}}</text>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="no_data" v-if="!state.isLoading && state.pageList.length == 0">
  35. <image class="no_data_img" src="@/static/image/bg/no_data.png"></image>
  36. <text class="no_data_text">暂无数据</text>
  37. </view>
  38. <uni-load-more v-if="state.pageList.length > 0" :status="state.loadStatus" />
  39. </scroll-view>
  40. </view>
  41. </template>
  42. <script setup>
  43. import navBar from '@/components/nav-bar.vue';
  44. import {queryCourseTypeDataList,recordPageListData} from '@/reqApi/teacherStudy.js';
  45. import {
  46. reactive,
  47. ref,
  48. onMounted,
  49. nextTick
  50. } from 'vue';
  51. const state = reactive({
  52. courseTypeData:[],//顶部查询数据
  53. filterPickerData: [{
  54. valueIndex:0,//默认值索引
  55. defaultValue:'',//默认值
  56. list:[]
  57. },{
  58. valueIndex:0,//默认值索引
  59. defaultValue:'',//默认值
  60. list:[]
  61. }],
  62. tabList: [{
  63. label: '最新发布',
  64. value: '0'
  65. }, {
  66. label: '播放最多',
  67. value: '1'
  68. }, {
  69. label: '关注最多',
  70. value: '2'
  71. }],
  72. pageList:[],//列表数据
  73. queryStr: '',
  74. courseType: '0',//排序方式,课程中心参数,0-最新发布,1-播放最多,2-关注最多
  75. teachCourseTypeClassId: '',//研修专题
  76. teachCourseTypeId: '',//内容领域
  77. pageSize: 30,
  78. pageNum: 1,
  79. scrollTop:0,
  80. oldScrollTop:0,
  81. isRefreshing:false,//设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发
  82. isLoading:true,//加载中
  83. noMoreData:false,//没有更多数据了
  84. loadStatus:'more',//loading状态
  85. })
  86. onMounted(() => {
  87. getCourseTypeDataList();
  88. OnLoadData(true);
  89. });
  90. //获取顶部查询项
  91. const getCourseTypeDataList = () => {
  92. queryCourseTypeDataList().then(res => {
  93. if(res.code == 200){
  94. const defaultData = [{
  95. label:'内容领域',
  96. id:'',
  97. value:''
  98. }];
  99. const resData = res?.data || [];
  100. state.courseTypeData = defaultData.concat(resData);
  101. //一级条件
  102. state.filterPickerData[0].list = state.courseTypeData.map(item=>({
  103. ...item,
  104. value:item.id
  105. }))
  106. }else{
  107. state.courseTypeData = [];
  108. state.filterPickerData = [{
  109. valueIndex:0,//默认值索引
  110. defaultValue:'',//默认值
  111. list:[],
  112. },{
  113. valueIndex:0,
  114. defaultValue:'',//默认值
  115. list:[],
  116. }]
  117. }
  118. })
  119. }
  120. //切换条件选择器
  121. const CommonFilterData = (searchWord,filterPicker,tabsSelected,type) => {
  122. const {valueIndex, index,filterPickerValue} = filterPicker;
  123. if(type == 'filterPicker'){
  124. if(index==0){//索引
  125. state.filterPickerData[index].valueIndex = valueIndex;//一级条件选中项的索引
  126. state.filterPickerData[1].valueIndex = 0;//二级条件选中项的索引
  127. const childrenData = state.courseTypeData?.[valueIndex]?.children || [];
  128. const childrenList = childrenData.map(item=>({
  129. ...item,
  130. value:item?.id ?? ''
  131. }))
  132. if(childrenList.length){
  133. childrenList.unshift({
  134. label:'内容领域',
  135. id:'',
  136. value:''
  137. })
  138. }
  139. state.filterPickerData[1].list = childrenList;//二级条件数据
  140. }else{
  141. state.filterPickerData[index].valueIndex = valueIndex;//二级条件选中项的索引
  142. }
  143. }
  144. state.queryStr = searchWord;
  145. state.teachCourseTypeId = filterPickerValue[0];
  146. state.teachCourseTypeClassId = filterPickerValue[1];
  147. state.courseType = tabsSelected;
  148. OnLoadData(true)
  149. }
  150. /*
  151. *获取数据
  152. * initPage:初始分页 从第一开始
  153. */
  154. const OnLoadData = (initPage) => {
  155. // uni.showLoading({
  156. // title: '加载中'
  157. // });
  158. if (initPage) state.pageNum = 1;//如果是下拉刷新、重新查询 默认加载第一页
  159. state.isLoading = true;
  160. state.loadStatus = 'loading';
  161. recordPageListData({
  162. queryStr:state.queryStr,
  163. teachCourseTypeId:state.teachCourseTypeId,
  164. teachCourseTypeClassId:state.teachCourseTypeClassId,
  165. courseType:'0',
  166. learnStatus:'',
  167. pageSize:state.pageSize,
  168. pageNum:state.pageNum
  169. }).then(res=>{
  170. if(res.code == 200){
  171. const total = Number(res?.data?.dateList?.total) || 0;//总数
  172. const pages = Math.ceil(total / state.pageSize);//总页数
  173. const recordsData = res?.data?.dateList?.records || [];
  174. state.pageList = initPage ? recordsData : [...state.pageList,...recordsData];
  175. state.noMoreData = state.pageNum == pages;
  176. state.pageNum++;
  177. }
  178. }).finally(()=>{
  179. // uni.hideLoading();
  180. state.isLoading = false;
  181. state.isRefreshing = false;//下拉刷新未被触发
  182. if(state.noMoreData){
  183. state.loadStatus = 'no-more';
  184. }else{
  185. state.loadStatus = 'more';
  186. }
  187. //返回到页面顶部
  188. if(initPage){
  189. GoTop();
  190. }
  191. })
  192. }
  193. // 自定义下拉刷新被触发 下拉刷新
  194. const OnRefresh = () =>{
  195. state.isRefreshing = true;//下拉刷新已经被触发
  196. OnLoadData(true);
  197. }
  198. //滚动到底部/右边 触发上拉刷新
  199. const OnLoadMore = () => {
  200. if (state.isLoading || state.noMoreData) return;
  201. OnLoadData(false);
  202. }
  203. // 滚动时触发
  204. const OnScroll = (e) => {
  205. state.oldScrollTop = e.detail.scrollTop;
  206. }
  207. //返回到顶部
  208. const GoTop = () => {
  209. // 解决view层不同步的问题
  210. state.scrollTop = state.oldScrollTop;
  211. nextTick(() => {
  212. state.scrollTop = 0
  213. });
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .page_content{
  218. height: calc(100% - 448rpx);
  219. .scroll_view_y{
  220. height: 100%;
  221. .refresh_loading{
  222. padding: 10rpx 0;
  223. }
  224. }
  225. .page_list{
  226. display: flex;
  227. width: 100%;
  228. flex-wrap: wrap;
  229. gap:32rpx;
  230. .list_item{
  231. &:nth-child(1){
  232. margin-top: 16rpx;
  233. }
  234. &:nth-child(2){
  235. margin-top: 16rpx;
  236. }
  237. width: calc((100% - 32rpx) / 2);
  238. overflow: hidden;
  239. display: flex;
  240. flex-direction: column;
  241. .item_img_box{
  242. width: 100%;
  243. height: 220rpx;
  244. border-radius: 8rpx;
  245. overflow: hidden;
  246. position: relative;
  247. .item_img{
  248. width: 100%;
  249. height: 100%;
  250. border-radius: 8rpx;
  251. }
  252. .remaining_days{
  253. position: absolute;
  254. top:0;
  255. right: 0;
  256. width: 134rpx;
  257. height: 48rpx;
  258. background-color: #2E64FA;
  259. border-radius: 0px 8px 0px 8px;
  260. font-weight: 400;
  261. font-size: 28rpx;
  262. color: #FFFFFF;
  263. text-align: center;
  264. line-height: 48rpx;
  265. }
  266. .progress{
  267. width: 100%;
  268. height: 12rpx;
  269. position: absolute;
  270. left: 0;
  271. bottom: 0;
  272. .done{
  273. height: 12rpx;
  274. background-color: #2E64FA;
  275. display: flex;
  276. width: 70%;
  277. }
  278. }
  279. }
  280. .item_title{
  281. display: flex;
  282. width: 100%;
  283. margin:8rpx 0;
  284. font-weight: 400;
  285. font-size: 24rpx;
  286. color: #333333;
  287. display: -webkit-box;
  288. -webkit-line-clamp: 2;
  289. -webkit-box-orient: vertical;
  290. overflow: hidden;
  291. text-overflow: ellipsis;
  292. }
  293. .item_time{
  294. display: flex;
  295. align-items: center;
  296. width: 100%;
  297. .img{
  298. width: 28rpx;
  299. height: 28rpx;
  300. margin-right: 8rpx;
  301. }
  302. .time{
  303. font-weight: 400;
  304. font-size: 24rpx;
  305. color: #999999;
  306. }
  307. }
  308. }
  309. }
  310. }
  311. </style>