index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <!-- 头部 -->
  3. <nav-bar height="224" backPath="workspace" title="教师专业发展" :tabList="state.tabList" :onlyTitle="false" :showFilterPicker="false" :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" @click="GoVideoDetails(item.id)">
  22. <view class="teacher_name">
  23. <image class="icon" src="@/static/image/icon/person.png"></image>
  24. <text class="name">{{item.teacherName}}</text>
  25. </view>
  26. <view class="honor_count">共<text class="count">{{item.honorCount}}</text>个奖项</view>
  27. <view class="honor_desc">{{item.honorName}}</view>
  28. <view class="honor_date">更新时间:{{item?.createdAt?.slice(0, 10)}}</view>
  29. </view>
  30. </view>
  31. <view class="no_data" v-if="!state.isLoading && state.pageList.length == 0">
  32. <image class="no_data_img" src="@/static/image/bg/no_data.png"></image>
  33. <text class="no_data_text">暂无数据</text>
  34. </view>
  35. <uni-load-more v-if="state.pageList.length > 0" :status="state.loadStatus" />
  36. </scroll-view>
  37. </view>
  38. </template>
  39. <script setup>
  40. import navBar from '@/components/nav-bar.vue';
  41. import {queryHonorTeacherListData} from '@/reqApi/teacherHonor.js';
  42. import {
  43. reactive,
  44. ref,
  45. onMounted,
  46. nextTick
  47. } from 'vue';
  48. const state = reactive({
  49. tabList:[ {
  50. label:'更新时间',
  51. value:'0',
  52. },{
  53. label:'获奖数量',
  54. value:'1',
  55. },{
  56. label:'姓名',
  57. value:'2',
  58. }],
  59. pageLists:[],//全部数据
  60. pageList:[],//列表数据
  61. sortType:'0',
  62. queryStr: '',
  63. pageSize: 30,
  64. pageNum: 1,
  65. pages:0,
  66. scrollTop:0,
  67. oldScrollTop:0,
  68. isRefreshing:false,//设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发
  69. isLoading:true,//加载中
  70. noMoreData:false,//没有更多数据了
  71. loadStatus:'more',//loading状态
  72. })
  73. onMounted(() => {
  74. OnLoadData(true);
  75. });
  76. //切换条件选择器
  77. const CommonFilterData = (searchWord,filterPicker,tabsSelected,type) => {
  78. state.queryStr = searchWord;
  79. state.sortType = tabsSelected;
  80. OnLoadData(true)
  81. }
  82. /*
  83. *获取数据
  84. * initPage:初始分页 从第一开始
  85. */
  86. const OnLoadData = (initPage) => {
  87. state.isLoading = true;
  88. state.loadStatus = 'loading';
  89. if (initPage) {
  90. // uni.showLoading({
  91. // title: '加载中'
  92. // });
  93. state.pageNum = 1;//如果是下拉刷新、重新查询 默认加载第一页
  94. queryHonorTeacherListData({
  95. queryStr:state.queryStr,
  96. sortType:state.sortType
  97. }).then(res=>{
  98. if(res.code == 200){
  99. const recordsData = res?.data || [];
  100. state.pageLists = recordsData;//全部数据
  101. const total = recordsData?.length || 0;//总数
  102. state.pages = Math.ceil(total / state.pageSize);//总页数
  103. //默认加载
  104. state.pageList = state.pageLists.slice(0, state.pageSize);
  105. //没有更多了
  106. state.noMoreData = state.pageNum == state.pages;
  107. //分页+1
  108. state.pageNum++;
  109. console.log()
  110. state.isLoading = false;
  111. state.isRefreshing = false;//下拉刷新未被触发
  112. state.loadStatus = state.noMoreData?'no-more':'more';
  113. }
  114. }).finally(()=>{
  115. // uni.hideLoading();
  116. //返回到页面顶部
  117. if(initPage){
  118. GoTop();
  119. }
  120. })
  121. }else{
  122. const start = (state.pageNum - 1) * state.pageSize;
  123. const end = start + state.pageSize;
  124. const list = state.pageLists.slice(start, end);
  125. state.pageList = [...state.pageList, ...list];
  126. state.noMoreData = state.pageNum == state.pages;
  127. state.pageNum++;
  128. setTimeout(() => {
  129. state.isLoading = false;
  130. state.isRefreshing = false; //下拉刷新未被触发
  131. state.loadStatus = state.noMoreData?'no-more':'more';
  132. }, 0)
  133. }
  134. }
  135. // 自定义下拉刷新被触发 下拉刷新
  136. const OnRefresh = () =>{
  137. state.isRefreshing = true;//下拉刷新已经被触发
  138. OnLoadData(true);
  139. }
  140. //滚动到底部/右边 触发上拉刷新
  141. const OnLoadMore = () => {
  142. if (state.isLoading || state.noMoreData) return;
  143. OnLoadData(false);
  144. }
  145. // 滚动时触发
  146. const OnScroll = (e) => {
  147. state.oldScrollTop = e.detail.scrollTop;
  148. }
  149. //返回到顶部
  150. const GoTop = () => {
  151. // 解决view层不同步的问题
  152. state.scrollTop = state.oldScrollTop;
  153. nextTick(() => {
  154. state.scrollTop = 0
  155. });
  156. }
  157. //视频详情
  158. const GoVideoDetails = (id) => {
  159. // uni.navigateTo({
  160. // url: `/pages/studentStudy/videoDetails?id=${id}`
  161. // });
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. .page_content{
  166. height: calc(100% - 360rpx);
  167. .scroll_view_y{
  168. height: 100%;
  169. .refresh_loading{
  170. padding: 10rpx 0;
  171. }
  172. }
  173. .page_list{
  174. display: flex;
  175. width: 100%;
  176. flex-wrap: wrap;
  177. gap:22rpx;
  178. .list_item{
  179. &:nth-child(1){
  180. margin-top: 0rpx;
  181. }
  182. &:nth-child(2){
  183. margin-top: 0rpx;
  184. }
  185. width: calc((100% - 22rpx) / 2);
  186. // min-height: 280rpx;
  187. padding: 16rpx 12rpx 18rpx 16rpx;
  188. background-color: #F8FAFE;
  189. border-radius: 16rpx;
  190. border: 2rpx solid #EBEEF5;
  191. box-sizing: border-box;
  192. margin-top: 24rpx;
  193. overflow: hidden;
  194. display: flex;
  195. flex-direction: column;
  196. .teacher_name{
  197. display: flex;
  198. width: 100%;
  199. align-items: center;
  200. .icon{
  201. width: 40rpx;
  202. height: 40rpx;
  203. margin-right: 16rpx;
  204. flex-shrink: 0;
  205. }
  206. .name{
  207. font-weight: 500;
  208. font-size: 36rpx;
  209. color: #333333;
  210. overflow: hidden;
  211. white-space: nowrap;
  212. text-overflow: ellipsis;
  213. }
  214. }
  215. .honor_count{
  216. display: flex;
  217. flex-wrap: wrap;
  218. align-items: center;
  219. width: 100%;
  220. margin-top: 8rpx;
  221. font-weight: 500;
  222. font-size: 28rpx;
  223. color: #666666;
  224. .count{
  225. color: #2E64FA;
  226. margin:0 8rpx;
  227. }
  228. }
  229. .honor_desc{
  230. display: -webkit-box;
  231. -webkit-line-clamp: 2;
  232. -webkit-box-orient: vertical;
  233. overflow: hidden;
  234. text-overflow: ellipsis;
  235. flex-wrap: wrap;
  236. word-break: break-all;
  237. width: 100%;
  238. margin-top: 16rpx;
  239. font-weight: 400;
  240. font-size: 28rpx;
  241. color: #999999;
  242. }
  243. .honor_date{
  244. width: 100%;
  245. display: flex;
  246. font-weight: 400;
  247. font-size: 24rpx;
  248. color: #999999;
  249. margin-top: 18rpx;
  250. }
  251. }
  252. }
  253. }
  254. </style>