index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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.teacherId" @click="GoHonorTeacherDetail(item.teacherId,item.teacherName)">
  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 = (filterOptions,type) => {
  78. state.queryStr = filterOptions.searchWord;
  79. state.sortType = filterOptions.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. state.isLoading = false;
  110. state.isRefreshing = false;//下拉刷新未被触发
  111. state.loadStatus = state.noMoreData?'no-more':'more';
  112. }
  113. }).finally(()=>{
  114. // uni.hideLoading();
  115. //返回到页面顶部
  116. if(initPage){
  117. GoTop();
  118. }
  119. })
  120. }else{
  121. const start = (state.pageNum - 1) * state.pageSize;
  122. const end = start + state.pageSize;
  123. const list = state.pageLists.slice(start, end);
  124. state.pageList = [...state.pageList, ...list];
  125. state.noMoreData = state.pageNum == state.pages;
  126. state.pageNum++;
  127. setTimeout(() => {
  128. state.isLoading = false;
  129. state.isRefreshing = false; //下拉刷新未被触发
  130. state.loadStatus = state.noMoreData?'no-more':'more';
  131. }, 0)
  132. }
  133. }
  134. // 自定义下拉刷新被触发 下拉刷新
  135. const OnRefresh = () =>{
  136. state.isRefreshing = true;//下拉刷新已经被触发
  137. OnLoadData(true);
  138. }
  139. //滚动到底部/右边 触发上拉刷新
  140. const OnLoadMore = () => {
  141. if (state.isLoading || state.noMoreData) return;
  142. OnLoadData(false);
  143. }
  144. // 滚动时触发
  145. const OnScroll = (e) => {
  146. state.oldScrollTop = e.detail.scrollTop;
  147. }
  148. //返回到顶部
  149. const GoTop = () => {
  150. // 解决view层不同步的问题
  151. state.scrollTop = state.oldScrollTop;
  152. nextTick(() => {
  153. state.scrollTop = 0
  154. });
  155. }
  156. //教师荣誉详情
  157. const GoHonorTeacherDetail = (teacherId,teacherName) => {
  158. uni.navigateTo({
  159. url: `/pages/teacherHonor/honorTeacher/honorTeacherDetail?teacherId=${teacherId}&teacherName=${teacherName}`
  160. });
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .page_content{
  165. height: calc(100% - 360rpx);
  166. .scroll_view_y{
  167. height: 100%;
  168. .refresh_loading{
  169. padding: 10rpx 0;
  170. }
  171. }
  172. .page_list{
  173. display: flex;
  174. width: 100%;
  175. flex-wrap: wrap;
  176. gap:24rpx 22rpx;
  177. .list_item{
  178. width: calc((100% - 22rpx) / 2);
  179. // min-height: 280rpx;
  180. padding: 16rpx 12rpx 18rpx 16rpx;
  181. background-color: #F8FAFE;
  182. border-radius: 16rpx;
  183. border: 2rpx solid #EBEEF5;
  184. box-sizing: border-box;
  185. overflow: hidden;
  186. display: flex;
  187. flex-direction: column;
  188. .teacher_name{
  189. display: flex;
  190. width: 100%;
  191. align-items: center;
  192. .icon{
  193. width: 40rpx;
  194. height: 40rpx;
  195. margin-right: 16rpx;
  196. flex-shrink: 0;
  197. }
  198. .name{
  199. font-weight: 500;
  200. font-size: 36rpx;
  201. color: #333333;
  202. overflow: hidden;
  203. white-space: nowrap;
  204. text-overflow: ellipsis;
  205. }
  206. }
  207. .honor_count{
  208. display: flex;
  209. flex-wrap: wrap;
  210. align-items: center;
  211. width: 100%;
  212. margin-top: 8rpx;
  213. font-weight: 500;
  214. font-size: 28rpx;
  215. color: #666666;
  216. .count{
  217. color: #2E64FA;
  218. margin:0 8rpx;
  219. }
  220. }
  221. .honor_desc{
  222. display: -webkit-box;
  223. -webkit-line-clamp: 2;
  224. -webkit-box-orient: vertical;
  225. overflow: hidden;
  226. text-overflow: ellipsis;
  227. flex-wrap: wrap;
  228. word-break: break-all;
  229. width: 100%;
  230. margin-top: 16rpx;
  231. font-weight: 400;
  232. font-size: 28rpx;
  233. color: #999999;
  234. }
  235. .honor_date{
  236. width: 100%;
  237. display: flex;
  238. font-weight: 400;
  239. font-size: 24rpx;
  240. color: #999999;
  241. margin-top: 18rpx;
  242. }
  243. }
  244. }
  245. }
  246. </style>