gallery.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="app-page" :class="{ 'is-balck grey-darken-6': isBlackTheme }">
  3. <!-- 顶部切换 -->
  4. <view class="e-fixed" v-if="category.list.length > 2">
  5. <tm-tabs color="light-blue" v-model="category.activeIndex" :list="category.list" align="left" @change="fnOnCategoryChange"></tm-tabs>
  6. </view>
  7. <!-- 占位区域 -->
  8. <view style="width: 100vw;height: 90rpx;"></view>
  9. <!-- 加载区域 -->
  10. <view v-if="loading != 'success'" class="loading-wrap">
  11. <tm-skeleton model="card"></tm-skeleton>
  12. <tm-skeleton model="cardActions"></tm-skeleton>
  13. <tm-skeleton model="list"></tm-skeleton>
  14. <tm-skeleton model="listAvatr"></tm-skeleton>
  15. <tm-skeleton model="listAvatr"></tm-skeleton>
  16. <tm-skeleton model="listAvatr"></tm-skeleton>
  17. </view>
  18. <!-- 内容区域 -->
  19. <view class="content" v-else :class="{ 'bg-white': dataList.length !== 0 }">
  20. <view v-if="dataList.length == 0" class="content-empty">
  21. <!-- 空布局 -->
  22. <tm-empty icon="icon-shiliangzhinengduixiang-" label="博主还没有分享图片~"></tm-empty>
  23. </view>
  24. <block v-else>
  25. <tm-flowLayout v-if="globalAppSettings.gallery.useWaterfull" @click="fnOnClick" ref="wafll">
  26. <template v-slot:left="{ hdata }">
  27. <tm-translate animation-name="fadeUp">
  28. <view class="round-3 shadow-2 overflow white">
  29. <tm-images :previmage="false" :src="hdata.item.image" @click="fnPreview(hdata.item)"></tm-images>
  30. <view class="pa-10 text-size-s">
  31. <view class="text-overflow-2">
  32. <tm-tags color="bg-gradient-amber-accent" :shadow="0" :dense="true" size="s" model="fill">{{ hdata.item.team }}</tm-tags>
  33. <text class="pl-6">{{ hdata.item.name }}</text>
  34. </view>
  35. <view v-if="hdata.item.description" class="ma-10">{{ hdata.item.description }}</view>
  36. <view v-if="hdata.item.location" class="mt-10 text-grey-lighten-1">
  37. <tm-icons name="icon-position-fill"></tm-icons>
  38. <text class="pl-5">{{ hdata.item.location }}</text>
  39. </view>
  40. <view class="flex-between mt-12 flex-center">
  41. <view>
  42. <text class="text-size-xs text-red ml-5">{{ hdata.item.likes }}</text>
  43. <text class="text-size-xs text-red ml-5">喜欢</text>
  44. </view>
  45. <view class="pl-10 text-size-xs text-grey-lighten-1">{{ hdata.item.takeTime }}</view>
  46. </view>
  47. </view>
  48. </view>
  49. </tm-translate>
  50. </template>
  51. <template v-slot:right="{ hdata }">
  52. <tm-translate animation-name="fadeUp">
  53. <view class="round-3 shadow-2 overflow white">
  54. <tm-images :previmage="false" :src="hdata.item.image" @click="fnPreview(hdata.item)"></tm-images>
  55. <view class="pa-10 text-size-s">
  56. <view class="text-overflow-2">
  57. <tm-tags :shadow="0" :dense="true" color="bg-gradient-amber-accent" size="s" model="fill">{{ hdata.item.team }}</tm-tags>
  58. <text class="pl-6">{{ hdata.item.name }}</text>
  59. </view>
  60. <view v-if="hdata.item.description" class="ma-10">{{ hdata.item.description }}</view>
  61. <view v-if="hdata.item.location" class="mt-10 text-grey-lighten-1">
  62. <tm-icons name="icon-position-fill"></tm-icons>
  63. <text class="pl-5">{{ hdata.item.location }}</text>
  64. </view>
  65. <view class="flex-between mt-12 flex-center">
  66. <view>
  67. <text class="text-size-xs text-red ml-5">{{ hdata.item.likes }}</text>
  68. <text class="text-size-xs text-red ml-5">喜欢</text>
  69. </view>
  70. <view class="pl-10 text-size-xs text-grey-lighten-1">{{ hdata.item.takeTime }}</view>
  71. </view>
  72. </view>
  73. </view>
  74. </tm-translate>
  75. </template>
  76. </tm-flowLayout>
  77. <block v-else>
  78. <block v-for="(item, index) in dataList" :key="index">
  79. <tm-translate animation-name="fadeUp" :wait="(index + 1) * 50">
  80. <view class="round-3 shadow-2 overflow white mb-24">
  81. <tm-images :previmage="false" :src="item.image" @click="fnPreview(item)"></tm-images>
  82. <view class="pa-24 text-size-m">
  83. <view class="text-overflow-2">
  84. <tm-tags :shadow="0" :dense="true" color="bg-gradient-amber-accent" size="s" model="fill">{{ item.team }}</tm-tags>
  85. <text class="pl-6">{{ item.name }}</text>
  86. </view>
  87. <view v-if="item.description" class="ma-10">{{ item.description }}</view>
  88. <view v-if="item.location" class="mt-10 text-grey-lighten-1">
  89. <tm-icons name="icon-position-fill"></tm-icons>
  90. <text class="pl-5">{{ item.location }}</text>
  91. </view>
  92. <view class="flex-between mt-12 flex-center">
  93. <view>
  94. <text class="text-size-m text-red ml-5">{{ item.likes }}</text>
  95. <text class="text-size-m text-red ml-5">喜欢</text>
  96. </view>
  97. <view class="pl-10 text-size-m text-grey-lighten-1">{{ item.takeTime }}</view>
  98. </view>
  99. </view>
  100. </view>
  101. </tm-translate>
  102. </block>
  103. </block>
  104. <tm-flotbutton @click="fnToTopPage" color="light-blue" size="m" icon="icon-angle-up"></tm-flotbutton>
  105. <view class="load-text">{{ loadMoreText }}</view>
  106. </block>
  107. </view>
  108. </view>
  109. </template>
  110. <script>
  111. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  112. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  113. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  114. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  115. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  116. import tmIcons from '@/tm-vuetify/components/tm-icons/tm-icons.vue';
  117. import tmImages from '@/tm-vuetify/components/tm-images/tm-images.vue';
  118. import tmFlowLayout from '@/tm-vuetify/components/tm-flowLayout/tm-flowLayout.vue';
  119. import tmTabs from '@/tm-vuetify/components/tm-tabs/tm-tabs.vue';
  120. export default {
  121. components: {
  122. tmSkeleton,
  123. tmTranslate,
  124. tmFlotbutton,
  125. tmTags,
  126. tmEmpty,
  127. tmIcons,
  128. tmImages,
  129. tmFlowLayout,
  130. tmTabs
  131. },
  132. data() {
  133. return {
  134. isBlackTheme: false,
  135. loading: 'loading',
  136. category: {
  137. activeIndex: 0,
  138. activeValue: '',
  139. list: []
  140. },
  141. queryParams: {
  142. size: 10,
  143. page: 0,
  144. team: null,
  145. keyword: ''
  146. },
  147. cache: {
  148. dataList: [],
  149. total: 0
  150. },
  151. isLoadMore: false,
  152. loadMoreText: '',
  153. result: {},
  154. dataList: []
  155. };
  156. },
  157. filters: {
  158. filterTakeTime(val) {
  159. return uni.$tm.dayjs(val).format('DD/MM/YYYY');
  160. }
  161. },
  162. watch: {
  163. globalAppSettings: {
  164. deep: true,
  165. handler() {
  166. // this.isLoadMore = false;
  167. // this.queryParams.page = 0;
  168. // this.dataList = [];
  169. // this.cache.list = [];
  170. // this.cache.total = 0;
  171. }
  172. }
  173. },
  174. onLoad() {
  175. this.fnSetPageTitle('个人图库');
  176. this.fnGetCategory();
  177. },
  178. created() {
  179. this.fnGetData();
  180. },
  181. onPullDownRefresh() {
  182. this.isLoadMore = false;
  183. this.queryParams.page = 0;
  184. this.fnGetData();
  185. },
  186. onReachBottom(e) {
  187. if (this.result.hasNext) {
  188. this.queryParams.page += 1;
  189. this.isLoadMore = true;
  190. this.fnGetData();
  191. } else {
  192. uni.showToast({
  193. icon: 'none',
  194. title: '没有更多数据了'
  195. });
  196. }
  197. },
  198. methods: {
  199. fnOnCategoryChange(index) {
  200. this.dataList = [];
  201. if (index == 0) {
  202. this.queryParams.team = null;
  203. } else {
  204. this.queryParams.team = this.category.list[index];
  205. }
  206. this.queryParams.page = 0;
  207. this.fnToTopPage();
  208. this.fnGetData();
  209. },
  210. fnGetCategory() {
  211. this.$httpApi.getPhotoTeams().then(res => {
  212. this.category.list = ['全部', ...res.data];
  213. });
  214. },
  215. fnGetData() {
  216. uni.showLoading({
  217. mask: true,
  218. title: '加载中...'
  219. });
  220. // 设置状态为加载中
  221. if (!this.isLoadMore) {
  222. this.loading = 'loading';
  223. }
  224. this.loadMoreText = '';
  225. this.$httpApi
  226. .getPhotoListByPage(this.queryParams)
  227. .then(res => {
  228. if (res.status == 200) {
  229. this.loading = 'success';
  230. this.result = res.data;
  231. if (res.data.content.length != 0) {
  232. const _list = res.data.content.map((item, index) => {
  233. item['image'] = this.$utils.checkImageUrl(item.thumbnail);
  234. item['model'] = 'text';
  235. item['takeTime'] = this.$tm.dayjs(item['takeTime']).format('DD/MM/YYYY');
  236. return item;
  237. });
  238. this.fnCacheDataList(_list);
  239. if (this.globalAppSettings.gallery.useWaterfull) {
  240. this.dataList = _list;
  241. this.$nextTick(() => {
  242. this.$refs.wafll.pushData(_list);
  243. });
  244. } else {
  245. this.dataList = this.dataList.concat(_list);
  246. }
  247. }
  248. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  249. } else {
  250. this.loading = 'error';
  251. this.waterfall.loading = 'finish';
  252. this.loadMoreText = '';
  253. }
  254. })
  255. .catch(err => {
  256. console.error(err);
  257. this.loading = 'error';
  258. this.waterfall.loading = 'finish';
  259. this.loadMoreText = '加载失败,请下拉刷新!';
  260. })
  261. .finally(() => {
  262. setTimeout(() => {
  263. uni.hideLoading();
  264. uni.stopPullDownRefresh();
  265. }, 500);
  266. });
  267. },
  268. // 缓存数据
  269. fnCacheDataList(dataList) {
  270. if (this.queryParams.page == 0) {
  271. this.cache.dataList = dataList;
  272. } else {
  273. this.cache.dataList = [...this.cache.dataList, ...dataList];
  274. }
  275. },
  276. // 瀑布流组件点击事件
  277. fnOnClick(data) {
  278. console.log('点击数据', data);
  279. },
  280. // 预览
  281. fnPreview(item) {
  282. const index = this.cache.dataList.findIndex(x => x.id == item.id);
  283. uni.previewImage({
  284. current: index,
  285. urls: this.cache.dataList.map(x => x.image),
  286. indicator: 'number',
  287. loop: true
  288. });
  289. }
  290. }
  291. };
  292. </script>
  293. <style lang="scss" scoped>
  294. .app-page {
  295. width: 100vw;
  296. min-height: 100vh;
  297. display: flex;
  298. flex-direction: column;
  299. padding-bottom: 24rpx;
  300. background-color: #fafafd;
  301. &.is-balck {
  302. background-color: #212121;
  303. }
  304. }
  305. .content {
  306. box-sizing: border-box;
  307. padding: 0 24rpx;
  308. padding-top: 24rpx;
  309. .content-empty {
  310. height: 60vh;
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. }
  315. }
  316. .loading-wrap {
  317. box-sizing: border-box;
  318. padding: 24rpx;
  319. }
  320. </style>