school_photo.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="container">
  3. <!-- 顶部区域 -->
  4. <view class="top">
  5. <view class="top_search">
  6. <uni-icons type="search" size="30" color="#999999"></uni-icons>
  7. <input class="input" type="text" placeholder="请输入关键字" v-model="inputValue" @blur="handleBlur" />
  8. </view>
  9. <view class="top_btn" @click="handlebtn">
  10. <uni-icons type="plus" size="20" color="#fff"></uni-icons>
  11. <view class="btn_text">上传照片</view>
  12. </view>
  13. </view>
  14. <!-- 分段器区域 -->
  15. <view class="control">
  16. <common-controlTag :tagList="tagList" rangekey="name" @change="handleChange"></common-controlTag>
  17. </view>
  18. <!-- 列表区域 -->
  19. <view class="list">
  20. <!-- 每一个相册区域 -->
  21. <view class="list_box" v-for="item in dataList" :key="item.id">
  22. <view class="box_top">
  23. <image class="img" src="@/static/images/9.png" mode="aspectFill"></image>
  24. <view class="top_msg">
  25. <view class="msg_name">
  26. {{ item.name }}
  27. <text class="text">{{ item.orgName }}</text>
  28. </view>
  29. <view class="msg_class">{{ item.schoolInfo }}</view>
  30. </view>
  31. </view>
  32. <view class="box_center">
  33. <image v-for="(ele, index) in item.images" :key="index" class="img" :src="ele" mode="aspectFill" @click="clickImg(item.images, index)"></image>
  34. </view>
  35. <view class="box_bottom">{{ item.createTime }} {{ item.categoryName }}</view>
  36. </view>
  37. <!-- 没有数据时展示 -->
  38. <noData v-if="!dataList.length"></noData>
  39. </view>
  40. </view>
  41. </template>
  42. <script setup>
  43. import { onLoad, onReachBottom } from '@dcloudio/uni-app'
  44. import { ref } from 'vue'
  45. import { getCategoryImages, getMobileImagePage } from '@/api/index.js'
  46. // 搜索框绑定数据
  47. const inputValue = ref('')
  48. // 当前页
  49. const currentPage = ref(1)
  50. // 每页多少条
  51. const pageCount = ref(6)
  52. // 总条数
  53. const total = ref(0)
  54. // 分段器当前索引
  55. const currentIndex = ref(0)
  56. // 分段器数组
  57. const tagList = ref(['全部'])
  58. // 列表数据
  59. const dataList = ref([])
  60. onLoad(() => {
  61. // 获取相册分类集合
  62. getTagList()
  63. // 根据分类ID获取校友相册分页数据
  64. getData()
  65. })
  66. // 页面触底触发的回调
  67. onReachBottom(() => {
  68. if (total.value > dataList.value.length) {
  69. currentPage.value++
  70. getData()
  71. } else {
  72. uni.showToast({
  73. title: '没有更多数据了~~',
  74. icon: 'none'
  75. })
  76. }
  77. })
  78. // 获取相册分类集合
  79. const getTagList = async () => {
  80. const res = await getCategoryImages()
  81. // console.log(res)
  82. tagList.value = [...tagList.value, ...res.data]
  83. // console.log(tagList.value)
  84. }
  85. // 根据分类ID获取校友相册分页数据
  86. const getData = async () => {
  87. let data = {
  88. currentPage: currentPage.value,
  89. pageCount: pageCount.value,
  90. keyword: inputValue.value,
  91. categoryId: tagList.value[currentIndex.value].id || 0
  92. }
  93. const res = await getMobileImagePage(data)
  94. // console.log(res)
  95. dataList.value = [...dataList.value, ...res.data.list]
  96. total.value = res.data.totalCount
  97. }
  98. // 点击上传照片按钮回调
  99. const handlebtn = () => {
  100. uni.navigateTo({
  101. url: `/pages/school_photo_upload/school_photo_upload?type=2`
  102. })
  103. }
  104. // 分段器切换时的回调
  105. const handleChange = (e) => {
  106. if (currentIndex.value != e) {
  107. currentIndex.value = e
  108. currentPage.value = 1
  109. dataList.value = []
  110. getData()
  111. }
  112. }
  113. // 输入框失去焦点回调 搜索回调
  114. const handleBlur = () => {
  115. currentPage.value = 1
  116. dataList.value = []
  117. getData()
  118. }
  119. // 点击图片回调
  120. const clickImg = (urls, current) => {
  121. uni.previewImage({
  122. urls,
  123. current
  124. })
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .container {
  129. padding: 20rpx 18rpx;
  130. min-height: 100vh;
  131. font-size: 28rpx;
  132. .top {
  133. display: flex;
  134. justify-content: space-between;
  135. .top_search {
  136. display: flex;
  137. align-items: center;
  138. padding: 0 25rpx;
  139. width: 491rpx;
  140. height: 80rpx;
  141. border-radius: 145rpx;
  142. border: 2rpx solid #e5e5e5;
  143. background-color: #f5f5f5;
  144. .input {
  145. margin-left: 20rpx;
  146. font-size: 28rpx;
  147. }
  148. }
  149. .top_btn {
  150. display: flex;
  151. align-items: center;
  152. justify-content: center;
  153. padding: 22rpx;
  154. width: 196rpx;
  155. height: 70rpx;
  156. color: #fff;
  157. font-size: 20rpx;
  158. border-radius: 68rpx;
  159. background-color: #007aff;
  160. .btn_text {
  161. margin-left: 10rpx;
  162. }
  163. }
  164. }
  165. .control {
  166. margin-top: 15rpx;
  167. }
  168. .list {
  169. margin-top: 20rpx;
  170. font-size: 24rpx;
  171. .list_box {
  172. padding: 25rpx 30rpx;
  173. margin-bottom: 20rpx;
  174. width: 714rpx;
  175. border-radius: 28rpx;
  176. box-shadow: 0 4rpx 35rpx rgba(211, 211, 211, 0.32);
  177. .box_top {
  178. display: flex;
  179. height: 80rpx;
  180. .img {
  181. width: 80rpx;
  182. height: 80rpx;
  183. border-radius: 50%;
  184. }
  185. .top_msg {
  186. display: flex;
  187. flex-direction: column;
  188. justify-content: space-between;
  189. flex: 1;
  190. margin-left: 20rpx;
  191. .msg_name {
  192. font-size: 32rpx;
  193. .text {
  194. margin-left: 20rpx;
  195. font-size: 24rpx;
  196. color: #366fff;
  197. }
  198. }
  199. .msg_class {
  200. color: #808080;
  201. }
  202. }
  203. }
  204. .box_center {
  205. display: grid;
  206. grid-template-columns: repeat(3, 1fr);
  207. gap: 15rpx;
  208. margin-top: 35rpx;
  209. .img {
  210. width: 200rpx;
  211. height: 220rpx;
  212. }
  213. }
  214. .box_bottom {
  215. margin-top: 20rpx;
  216. color: #808080;
  217. line-height: 32rpx;
  218. overflow: hidden;
  219. white-space: nowrap;
  220. text-overflow: ellipsis;
  221. }
  222. }
  223. }
  224. }
  225. </style>