gallery.vue 10 KB

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