1
0

gallery.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <view class="app-page">
  3. <!-- 顶部切换 -->
  4. <view class="e-fixed" v-if="category.list.length > 0">
  5. <tm-tabs color="light-blue" :shadow="0" v-model="category.activeIndex" range-key="displayName" :list="category.list"
  6. align="left" @change="fnOnCategoryChange($event, false)"></tm-tabs>
  7. </view>
  8. <!-- 占位区域 -->
  9. <view v-if="category.list.length > 0" style="width: 100vw;height: 90rpx;"></view>
  10. <!-- 加载区域 -->
  11. <view v-if="loading == 'loading'" class="loading-wrap">
  12. <tm-skeleton model="card"></tm-skeleton>
  13. <tm-skeleton model="card"></tm-skeleton>
  14. <tm-skeleton model="card"></tm-skeleton>
  15. <tm-skeleton model="card"></tm-skeleton>
  16. </view>
  17. <view v-else-if="loading == 'error'" class="flex flex-col flex-center" style="width:100%;height:60vh;">
  18. <tm-empty icon="icon-wind-cry" label="阿偶,似乎获取数据失败了~">
  19. <tm-button theme="light-blue" size="m" :shadow="0" @click="fnGetData(true)">刷新试试</tm-button>
  20. </tm-empty>
  21. </view>
  22. <!-- 内容区域 -->
  23. <view v-else class="content">
  24. <k-touch-listen class="touch-listen-content" @touchLeft="touchLeft" @touchRight="touchRight">
  25. <view v-if="dataList.length === 0" class="content-empty">
  26. <!-- 空布局 -->
  27. <tm-empty icon="icon-shiliangzhinengduixiang-" label="博主还没有分享图片~"></tm-empty>
  28. </view>
  29. <block v-else>
  30. <block v-if="galleryConfig.useWaterfall">
  31. <!--瀑布流-->
  32. <tm-flowLayout-custom ref="wafll" style="width: 100%;" @click="fnOnFlowClick"></tm-flowLayout-custom>
  33. </block>
  34. <!-- 列表 -->
  35. <block v-else>
  36. <tm-translate v-for="(item, index) in dataList" :key="index"
  37. style="box-sizing: border-box;padding: 6rpx;width: 50%;height: 250rpx;"
  38. animation-name="fadeUp" :wait="calcAniWait(index)">
  39. <view style="border-radius: 12rpx;overflow: hidden;width: 100%;height: 250rpx;">
  40. <image style="width: 100%;height: 100%;" mode="aspectFill" :src="item.spec.url"
  41. @click="fnPreview(item)"/>
  42. </view>
  43. </tm-translate>
  44. </block>
  45. <view class="load-text">{{ loadMoreText }}</view>
  46. </block>
  47. </k-touch-listen>
  48. </view>
  49. <view v-if="!calcAuditModeEnabled" class="flot-buttons">
  50. <tm-button v-if="loading == 'error'" @click="fnGetCategory" size="m" :fab="true" theme="light-blue"
  51. icon="icon-sync-alt"></tm-button>
  52. <tm-button @click="fnToTopPage" size="m" :fab="true" theme="light-blue"
  53. icon="icon-angle-up"></tm-button>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  59. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  60. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  61. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  62. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  63. import tmIcons from '@/tm-vuetify/components/tm-icons/tm-icons.vue';
  64. import tmImages from '@/tm-vuetify/components/tm-images/tm-images.vue';
  65. import tmFlowLayoutCustom from '@/tm-vuetify/components/tm-flowLayout-custom/tm-flowLayout-custom.vue';
  66. import tmTabs from '@/tm-vuetify/components/tm-tabs/tm-tabs.vue';
  67. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  68. export default {
  69. options: {
  70. multipleSlots: true
  71. },
  72. components: {
  73. tmSkeleton,
  74. tmTranslate,
  75. tmFlotbutton,
  76. tmTags,
  77. tmEmpty,
  78. tmIcons,
  79. tmImages,
  80. tmFlowLayoutCustom,
  81. tmTabs,
  82. tmButton
  83. },
  84. data() {
  85. return {
  86. isBlackTheme: false,
  87. loading: 'loading',
  88. category: {
  89. activeIndex: 0,
  90. activeValue: '',
  91. list: []
  92. },
  93. queryParams: {
  94. size: 10,
  95. page: 1,
  96. group: ""
  97. },
  98. isLoadMore: false,
  99. loadMoreText: '',
  100. hasNext: false,
  101. dataList: [],
  102. lock:false
  103. };
  104. },
  105. computed: {
  106. galleryConfig() {
  107. return this.$tm.vx.getters().getConfigs.pageConfig.galleryConfig;
  108. },
  109. haloConfigs() {
  110. return this.$tm.vx.getters().getConfigs;
  111. },
  112. mockJson() {
  113. return this.$tm.vx.getters().getMockJson;
  114. },
  115. calcAuditModeEnabled(){
  116. return this.haloConfigs.auditConfig.auditModeEnabled
  117. },
  118. },
  119. watch: {
  120. galleryConfig: {
  121. handler(newValue, oldValue) {
  122. if (!newValue) return;
  123. this.fnSetPageTitle(newValue.pageTitle);
  124. this.fnGetCategory();
  125. },
  126. deep: true,
  127. immediate: true
  128. }
  129. },
  130. onPullDownRefresh() {
  131. this.dataList = []
  132. this.isLoadMore = false;
  133. this.queryParams.page = 1;
  134. this.fnGetData(true);
  135. },
  136. onReachBottom(e) {
  137. if (this.calcAuditModeEnabled) {
  138. uni.showToast({
  139. icon: 'none',
  140. title: '没有更多数据了'
  141. });
  142. return;
  143. }
  144. if (this.hasNext) {
  145. this.queryParams.page += 1;
  146. this.isLoadMore = true;
  147. this.fnGetData(false);
  148. } else {
  149. uni.showToast({
  150. icon: 'none',
  151. title: '没有更多数据了'
  152. });
  153. }
  154. },
  155. methods: {
  156. fnGetDataByCategory(index){
  157. this.fnResetSetAniWaitIndex();
  158. this.queryParams.group = this.category.list[index].name;
  159. this.queryParams.page = 1;
  160. this.fnToTopPage();
  161. this.dataList = [];
  162. this.fnGetData(true);
  163. },
  164. fnOnCategoryChange(index) {
  165. if(this.lock) {
  166. // uni.showToast({
  167. // title: "上一个请求进行中...",
  168. // icon: "none"
  169. // })
  170. return;
  171. }
  172. this.fnGetDataByCategory(index)
  173. },
  174. fnGetCategory() {
  175. if (this.calcAuditModeEnabled) {
  176. this.fnGetData(true);
  177. return
  178. }
  179. this.$httpApi.v2.getPhotoGroupList({
  180. page: 1,
  181. size: 0
  182. }).then(res => {
  183. this.category.list = res.items.map(item => {
  184. return {
  185. name: item.metadata.name,
  186. displayName: item.spec.displayName,
  187. priority: item.spec.priority
  188. }
  189. }).sort((a,b) => a.priority - b.priority);
  190. if (this.category.list.length !== 0) {
  191. this.queryParams.group = this.category.list[0].name;
  192. this.fnGetData(true);
  193. }
  194. }).catch(e=>{
  195. this.loading = 'error'
  196. this.category.list = []
  197. this.category.activeIndex = 0
  198. this.category.activeValue = ""
  199. });
  200. },
  201. fnGetData(isClearWaterfall = false) {
  202. if (this.calcAuditModeEnabled) {
  203. this.dataList = this.mockJson.gallery.list.map(item => {
  204. return {
  205. metadata: {
  206. name: Date.now() * Math.random(),
  207. },
  208. spec: {
  209. url: this.$utils.checkImageUrl(item)
  210. }
  211. }
  212. })
  213. this.loading = 'success';
  214. if (this.galleryConfig.useWaterfall) {
  215. this.$nextTick(() => {
  216. if (isClearWaterfall) {
  217. this.$refs.wafll.clear()
  218. }
  219. setTimeout(() => {
  220. this.$refs.wafll.pushData(this.dataList)
  221. }, 50)
  222. })
  223. }
  224. this.loadMoreText = '呜呜,没有更多数据啦~';
  225. uni.hideLoading();
  226. uni.stopPullDownRefresh();
  227. this.lock = false;
  228. return;
  229. }
  230. // 设置状态为加载中
  231. if (!this.isLoadMore) {
  232. this.loading = 'loading';
  233. }
  234. this.loadMoreText = '';
  235. this.$httpApi.v2
  236. .getPhotoListByGroupName(this.queryParams)
  237. .then(res => {
  238. this.hasNext = res.hasNext;
  239. this.loading = 'success';
  240. if (res.items.length !== 0) {
  241. const _list = res.items.map((item, index) => {
  242. item.spec.url = this.$utils.checkImageUrl(item.spec.url || item.spec.cover);
  243. return item;
  244. });
  245. if (this.isLoadMore) {
  246. this.dataList = this.dataList.concat(_list);
  247. } else {
  248. this.dataList = _list;
  249. }
  250. if (this.galleryConfig.useWaterfall) {
  251. this.$nextTick(() => {
  252. if (isClearWaterfall) {
  253. this.$refs.wafll.clear()
  254. }
  255. this.$refs.wafll.pushData(_list)
  256. })
  257. }
  258. }
  259. this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  260. })
  261. .catch(err => {
  262. console.error(err);
  263. this.loading = 'error';
  264. this.loadMoreText = '加载失败,请下拉刷新!';
  265. })
  266. .finally(() => {
  267. setTimeout(() => {
  268. uni.hideLoading();
  269. uni.stopPullDownRefresh();
  270. this.lock = false;
  271. }, 500);
  272. });
  273. },
  274. fnOnFlowClick({item}) {
  275. this.fnPreview(item)
  276. },
  277. // 预览
  278. fnPreview(data) {
  279. uni.previewImage({
  280. current: this.dataList.findIndex(x => x.metadata.name === data.metadata.name),
  281. urls: this.dataList.map(x => x.spec.url),
  282. indicator: 'number',
  283. loop: true
  284. });
  285. },
  286. touchLeft(){
  287. if(this.loading != "success") return;
  288. this.category.activeIndex += 1
  289. if(this.category.activeIndex >= this.category.list.length){
  290. this.category.activeIndex = 0
  291. }
  292. this.lock = true
  293. this.fnGetDataByCategory(this.category.activeIndex)
  294. },
  295. touchRight(){
  296. if(this.loading != "success") return;
  297. this.category.activeIndex -= 1
  298. if(this.category.activeIndex < 0){
  299. this.category.activeIndex = 0
  300. }
  301. this.lock = true
  302. this.fnGetDataByCategory(this.category.activeIndex)
  303. }
  304. }
  305. };
  306. </script>
  307. <style lang="scss" scoped>
  308. .app-page {
  309. width: 100vw;
  310. min-height: 100vh;
  311. display: flex;
  312. flex-direction: column;
  313. padding-bottom: 24rpx;
  314. background-color: #fafafa;
  315. }
  316. .content {
  317. width:100%;
  318. display: flex;
  319. flex-wrap: wrap;
  320. box-sizing: border-box;
  321. .content-empty {
  322. width: 100%;
  323. height: 70vh;
  324. display: flex;
  325. align-items: center;
  326. justify-content: center;
  327. }
  328. }
  329. .touch-listen-content {
  330. width:100%;
  331. display: flex;
  332. flex-wrap: wrap;
  333. box-sizing: border-box;
  334. padding: 24rpx 24rpx 0;
  335. gap: 12rpx 0;
  336. }
  337. .loading-wrap {
  338. box-sizing: border-box;
  339. padding: 24rpx;
  340. }
  341. .load-text {
  342. width: 100%;
  343. text-align: center;
  344. }
  345. .flot-buttons {
  346. position: fixed;
  347. bottom: 100rpx;
  348. right: 32rpx;
  349. flex-direction: column;
  350. display: flex;
  351. gap: 6rpx;
  352. z-index: 999;
  353. }
  354. </style>