album.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view class="app-page">
  3. <view v-if="loading != 'success'" class="loading-wrap">
  4. <tm-skeleton model="card"></tm-skeleton>
  5. <tm-skeleton model="card"></tm-skeleton>
  6. <tm-skeleton model="card"></tm-skeleton>
  7. <tm-skeleton model="card"></tm-skeleton>
  8. </view>
  9. <!-- 内容区域 -->
  10. <view v-else class="app-page-content">
  11. <view v-if="dataList.length == 0" class="content-empty flex flex-center"><tm-empty icon="icon-shiliangzhinengduixiang-" label="相册暂时还没有数据~"></tm-empty></view>
  12. <block v-else>
  13. <swiper
  14. class="swiper-album"
  15. :current="swiperIndex"
  16. :acceleration="true"
  17. :circular="true"
  18. :vertical="false"
  19. :indicator-dots="false"
  20. :autoplay="false"
  21. @change="fnOnChange"
  22. >
  23. <block v-for="(item, index) in dataList" :key="index">
  24. <swiper-item class="swiper-album-item">
  25. <view class="scroll-wrap">
  26. <view class="card">
  27. <cache-image
  28. class="card-image"
  29. width="100%"
  30. height="46vh"
  31. radius="12rpx"
  32. :url="item.image"
  33. :fileMd5="item.image"
  34. mode="aspectFill"
  35. @on-click="fnOnPreview(item)"
  36. ></cache-image>
  37. <view v-if="item.description" class="card-desc">{{ item.description }}</view>
  38. <view v-else class="card-desc is-empty flex flex-col">
  39. <view class="text-grey-darken-1">该照片没有记录任何信息</view>
  40. <view class="text-size-m mt-24 text-grey-darken-1">记录一下拍照的瞬间,会更精彩哟</view>
  41. </view>
  42. </view>
  43. </view>
  44. </swiper-item>
  45. </block>
  46. </swiper>
  47. <view class="tabbar">
  48. <view class="pre" @click="fnChange(false)">
  49. <text class="icon"><text class="iconfont icon-arrow-left"></text></text>
  50. <text class="text">上一张</text>
  51. </view>
  52. <view class="refresh" @click="fnRefresh()">刷新</view>
  53. <view class="next" @click="fnChange(true)">
  54. <text class="text">下一张</text>
  55. <text class="icon"><text class="iconfont icon-arrow-right"></text></text>
  56. </view>
  57. </view>
  58. </block>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import LoveConfig from '@/config/love.config.js';
  64. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  65. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  66. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  67. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  68. export default {
  69. components: {
  70. tmSkeleton,
  71. tmFlotbutton,
  72. tmTranslate,
  73. tmEmpty
  74. },
  75. data() {
  76. return {
  77. loading: 'loading',
  78. loveConfig: LoveConfig,
  79. queryParams: {
  80. size: 99,
  81. page: 0,
  82. sort: 'takeTime',
  83. team: LoveConfig.photoKeyName
  84. },
  85. result: {},
  86. dataList: [],
  87. cache: {
  88. dataList: [],
  89. total: 0
  90. },
  91. swiperIndex: 0,
  92. tabbar: {
  93. list: []
  94. }
  95. };
  96. },
  97. onLoad() {
  98. this.fnSetPageTitle('恋爱相册');
  99. },
  100. created() {
  101. this.fnGetData();
  102. },
  103. onPullDownRefresh() {
  104. this.fnRefresh();
  105. },
  106. methods: {
  107. fnRefresh() {
  108. this.queryParams.page = 0;
  109. this.fnGetData();
  110. },
  111. fnGetData() {
  112. uni.showLoading({
  113. mask: true,
  114. title: '加载中...'
  115. });
  116. this.loading = 'loading';
  117. this.$httpApi
  118. .getPhotoListByPage(this.queryParams)
  119. .then(res => {
  120. if (res.status == 200) {
  121. this.loading = 'success';
  122. if (res.data.content.length != 0) {
  123. const _list = res.data.content.map((item, index) => {
  124. item['image'] = this.$utils.checkImageUrl(item.thumbnail);
  125. item['takeTime'] = this.$tm.dayjs(item['takeTime']).format('DD/MM/YYYY');
  126. return item;
  127. });
  128. this.dataList = _list;
  129. // this.fnCacheDataList(_list);
  130. // this.dataList = this.dataList.concat(_list);
  131. this.swiperIndex = 0;
  132. uni.hideLoading();
  133. }
  134. } else {
  135. this.loading = 'error';
  136. uni.$tm.toast('加载失败,请下拉刷新重试!');
  137. }
  138. })
  139. .catch(err => {
  140. console.error(err);
  141. this.loading = 'error';
  142. uni.$tm.toast('加载失败,请下拉刷新重试!');
  143. })
  144. .finally(() => {
  145. setTimeout(() => {
  146. uni.stopPullDownRefresh();
  147. }, 200);
  148. });
  149. },
  150. // 缓存数据
  151. fnCacheDataList(dataList) {
  152. if (this.queryParams.page == 0) {
  153. this.cache.dataList = dataList;
  154. } else {
  155. this.cache.dataList = [...this.cache.dataList, ...dataList];
  156. }
  157. },
  158. fnOnPreview(item) {
  159. uni.previewImage({
  160. current: item.image,
  161. urls: this.dataList.map(x => x.image)
  162. });
  163. },
  164. fnOnChange(e) {
  165. console.log('e', e);
  166. this.swiperIndex = e.detail.current;
  167. },
  168. fnChange(isNext) {
  169. if (isNext) {
  170. if (this.swiperIndex == this.dataList.length - 1) {
  171. this.swiperIndex = 0;
  172. } else {
  173. this.swiperIndex += 1;
  174. }
  175. } else {
  176. if (this.swiperIndex == 0) {
  177. this.swiperIndex = this.dataList.length - 1;
  178. } else {
  179. this.swiperIndex -= 1;
  180. }
  181. }
  182. }
  183. }
  184. };
  185. </script>
  186. <style lang="scss" scoped>
  187. .app-page {
  188. width: 100vw;
  189. min-height: 100vh;
  190. display: flex;
  191. flex-direction: column;
  192. box-sizing: border-box;
  193. padding: 24rpx 0;
  194. padding-bottom: 144rpx;
  195. background: linear-gradient(
  196. -135deg,
  197. rgba(247, 149, 51, 0.1),
  198. rgba(243, 112, 85, 0.1) 15%,
  199. rgba(239, 78, 123, 0.1) 30%,
  200. rgba(161, 102, 171, 0.1) 44%,
  201. rgba(80, 115, 184, 0.1) 58%,
  202. rgba(16, 152, 173, 0.1) 72%,
  203. rgba(7, 179, 155, 0.1) 86%,
  204. rgba(109, 186, 130, 0.1)
  205. );
  206. color: #55423b;
  207. }
  208. .app-page-content {
  209. }
  210. .content-empty {
  211. width: 100%;
  212. height: 60vh;
  213. }
  214. .loading-wrap {
  215. box-sizing: border-box;
  216. padding: 0 24rpx;
  217. }
  218. .swiper-album {
  219. width: 100vw;
  220. height: calc(100vh - 24rpx - 144rpx);
  221. }
  222. .swiper-album-item {
  223. height: 100%;
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. box-sizing: border-box;
  228. padding: 36rpx;
  229. /* #ifdef H5 */
  230. padding-bottom: 110rpx;
  231. /* #endif */
  232. /* #ifndef H5 */
  233. padding-bottom: 60rpx;
  234. /* #endif */
  235. }
  236. .scroll-wrap {
  237. width: 100%;
  238. height: 100%;
  239. box-sizing: border-box;
  240. padding: 36rpx;
  241. background-color: #ffffff;
  242. border-radius: 12rpx;
  243. box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.03);
  244. }
  245. .card {
  246. display: flex;
  247. flex-direction: column;
  248. width: 100%;
  249. // height: 65vh;
  250. height: 100%;
  251. max-height: 100%;
  252. border-radius: 12rpx;
  253. background-color: #ffffff;
  254. box-sizing: border-box;
  255. // box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.03);
  256. overflow: hidden;
  257. overflow-y: auto;
  258. ::v-deep {
  259. .cache-image {
  260. height: initial !important;
  261. }
  262. }
  263. &-image {
  264. width: 100%;
  265. height: initial !important;
  266. border-radius: 12rpx;
  267. }
  268. &-desc {
  269. margin-top: 24rpx;
  270. line-height: 1.6;
  271. font-size: 28rpx;
  272. &.is-empty {
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. flex-grow: 1;
  277. font-size: 32rpx;
  278. }
  279. }
  280. }
  281. .tabbar {
  282. width: 80vw;
  283. position: fixed;
  284. left: 50%;
  285. bottom: 40rpx;
  286. transform: translateX(-50%);
  287. border-radius: 25rpx;
  288. box-sizing: border-box;
  289. padding: 24rpx;
  290. display: flex;
  291. align-items: center;
  292. justify-content: space-between;
  293. // background-color: rgba(0, 0, 0, 0.5);
  294. background-color: #ffffff;
  295. color: #333;
  296. box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.07);
  297. .pre {
  298. color: #56bbf9;
  299. .text {
  300. padding-left: 12rpx;
  301. }
  302. }
  303. .next {
  304. color: #f88ca2;
  305. .text {
  306. padding-right: 12rpx;
  307. }
  308. }
  309. }
  310. </style>