photo_album.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <view>
  3. <view
  4. v-for="item in albumList"
  5. :key="item.id"
  6. @click="lookMore(item)"
  7. >
  8. <view v-if="!item.is_old" class="album_list">
  9. <view class="title">{{ item.imgclass_name }}</view>
  10. <view class="flex">
  11. <view class="intr">创建于{{ item.created_at.substring(0, 10) }} 共{{ item.count }}{{ item.img_type == 0 ? '张照片' : '个视频' }}</view>
  12. <view class="more">
  13. <text>更多</text>
  14. <text class="iconfont iconyoujiantou"></text>
  15. </view>
  16. </view>
  17. <view v-if="item.is_old || (!item.is_old && item.img_type === 1)" class="imgs">
  18. <template v-if="item.images && item.images.length > 0">
  19. <view v-for="(temp, ti) in item.images" :key="temp.id" class="imgs_box">
  20. <view
  21. v-if="ti < 8"
  22. class="bg"
  23. :style="{backgroundImage: `url(${temp.thumbnail})`}"
  24. />
  25. </view>
  26. <!-- <image v-if="ti < 8" :src="temp.thumbnail"></image> -->
  27. </template>
  28. <template v-else>
  29. <image
  30. v-if="userInfo.type == 1 || userInfo.sign_up"
  31. src="../../static/imgs/noPhoto.png"
  32. mode="widthFix"
  33. class="no_img"
  34. ></image>
  35. <image
  36. v-if="userInfo.type == 0 && !userInfo.sign_up"
  37. src="../../static/imgs/noRoot.png"
  38. mode="widthFix"
  39. class="no_img"
  40. ></image>
  41. </template>
  42. </view>
  43. <template v-else>
  44. <swiper
  45. v-if="item.folder.length > 0"
  46. :display-multiple-items="2"
  47. next-margin="40rpx"
  48. class="swiper_container"
  49. >
  50. <swiper-item
  51. v-for="(temp, index) in item.folder"
  52. :key="temp.id"
  53. class="swiper_img"
  54. @click.stop="toClassifyImgs(temp)"
  55. >
  56. <view class="swiper_img_box">
  57. <!-- <image :src="temp.cover.thumbnail" mode="widthFix" class="img"></image> -->
  58. <view
  59. class="img"
  60. :style="{backgroundImage: `url(${temp.cover.thumbnail})`}"
  61. />
  62. <view class="swiper_mask">{{ temp.image_name }}</view>
  63. </view>
  64. </swiper-item>
  65. <swiper-item v-if="item.folder.length === 1" />
  66. </swiper>
  67. <template v-else>
  68. <image src="../../static/imgs/noPhoto.png" class="no_img" v-if="userInfo.type == 1 || userInfo.sign_up"></image>
  69. <image src="../../static/imgs/noRoot.png" class="no_img" v-if="userInfo.type == 0 && !userInfo.sign_up"></image>
  70. </template>
  71. </template>
  72. </view>
  73. <view v-else class="old_album_list">
  74. <view class="old_title">{{ item.imgclass_name }}</view>
  75. <view class="old_intr">创建于{{ item.created_at.substring(0, 10) }} 共{{ item.count }}{{ item.img_type == 0 ? '张照片' : '个视频' }}</view>
  76. <view class="old_imgs">
  77. <view v-for="(temp, index) in item.images" :key="temp.id"><image :src="temp.thumbnail"></image></view>
  78. <image src="../../static/imgs/noPhoto.png" v-if="(userInfo.type == 1 || userInfo.sign_up) && item.images.length == 0"></image>
  79. <image src="../../static/imgs/noRoot.png" v-if="item.images.length == 0 && userInfo.type == 0 && !userInfo.sign_up"></image>
  80. </view>
  81. <view class="old_more">
  82. <text>查看更多</text>
  83. <text class="iconfont iconyoujiantou"></text>
  84. </view>
  85. </view>
  86. </view>
  87. <view class="no" v-if="albumList.length == 0">--暂无相册--</view>
  88. </view>
  89. </template>
  90. <script>
  91. import { getAlbum } from '../../api/album.js';
  92. export default {
  93. data() {
  94. return {
  95. albumList: [], //相册列表
  96. params: {
  97. page_size: 5, //一页显示几条
  98. page_index: 1 //当前是第几页
  99. },
  100. userInfo: {}, //用户信息
  101. pages: '' //总页数
  102. };
  103. },
  104. onLoad() {
  105. this.getAlbum();
  106. },
  107. onShow() {
  108. if (uni.getStorageSync('userInfo')) {
  109. this.userInfo = uni.getStorageSync('userInfo');
  110. }
  111. },
  112. onPullDownRefresh() {
  113. uni.showNavigationBarLoading();
  114. this.getAlbum();
  115. },
  116. onReachBottom: function() {
  117. this.more();
  118. },
  119. methods: {
  120. toClassifyImgs(item) {
  121. if(!item.total || item.total === 0) {
  122. uni.showModal({
  123. content: '暂无图片',
  124. showCancel: false
  125. })
  126. return false
  127. }
  128. uni.navigateTo({
  129. url: '../photos/photos?title=' + item.image_name + '&activity_id=' + item.activity_id + '&id=' + item.id + '&type=1'
  130. });
  131. },
  132. /*获取相册列表
  133. * @params page_size 显示页数
  134. * @params page_index 当前页数
  135. */
  136. getAlbum(page) {
  137. this.params.page_index = 1;
  138. let { page_size, page_index } = this.params;
  139. getAlbum({ page_size, page_index })
  140. .then(res => {
  141. if (res.code == 200) {
  142. uni.stopPullDownRefresh();
  143. uni.hideNavigationBarLoading();
  144. this.albumList = res.data.list;
  145. this.pages = Math.ceil(res.data.total / this.params.page_size);
  146. } else {
  147. uni.showModal({
  148. content: res.message || '请求失败',
  149. showCancel: false
  150. });
  151. }
  152. })
  153. .finally(() => {
  154. uni.stopPullDownRefresh();
  155. });
  156. },
  157. //上拉加载获取更多相册
  158. more() {
  159. this.params.page_index++;
  160. if (this.params.page_index > this.pages) {
  161. uni.showToast({
  162. title: '没有更多啦~',
  163. icon: 'none'
  164. });
  165. return false;
  166. }
  167. let { page_size, page_index } = this.params;
  168. getAlbum({ page_size, page_index }).then(res => {
  169. if (res.code == 200) {
  170. if (res.data.list.length > 0) {
  171. this.albumList = this.albumList.concat(res.data.list);
  172. }
  173. } else {
  174. uni.showModal({
  175. content: res.message || '请求失败',
  176. showCancel: false
  177. });
  178. }
  179. });
  180. },
  181. /*点击查看详情
  182. * @params imgclass_name 相册名称
  183. * @params activity_id 活动id
  184. * @params id 相册id
  185. */
  186. lookMore(item) {
  187. if(!item.is_old) {
  188. if(!item.folder || item.folder.length === 0) {
  189. uni.showModal({
  190. content: '暂无图片分类',
  191. showCancel: false
  192. });
  193. return false
  194. }
  195. uni.navigateTo({
  196. url: '../photo_classify/photo_classify?id='+item.id
  197. })
  198. } else {
  199. if(!item.images || item.images.length == 0) {
  200. uni.showModal({
  201. content: item.img_type ? '暂无视频' : '暂无照片',
  202. showCancel: false
  203. });
  204. return false;
  205. }
  206. if(item.img_type) {
  207. uni.navigateTo({
  208. url: '../video_detail/video_detail?title=' + item.imgclass_name + '&activity_id=' + item.activity_id + '&id=' + item.id + '&status=' + 0
  209. });
  210. } else {
  211. uni.navigateTo({
  212. url: '../photos/photos?title=' + item.imgclass_name + '&activity_id=' + item.activity_id + '&id=' + item.id
  213. });
  214. }
  215. }
  216. }
  217. }
  218. };
  219. </script>
  220. <style lang="scss">
  221. .no {
  222. width: 100%;
  223. text-align: center;
  224. font-size: 24rpx;
  225. color: #666666;
  226. margin-top: 40rpx;
  227. }
  228. .album_list {
  229. width: 92%;
  230. margin: 0 auto 30rpx;
  231. background: #FFFFFF;
  232. padding: 30rpx;
  233. border-radius: 24rpx;
  234. &:nth-of-type(1) {
  235. margin-top: 30rpx;
  236. }
  237. .title {
  238. font-size: 32rpx;
  239. color: #333;
  240. line-height: 44rpx;
  241. margin-bottom: 10rpx;
  242. }
  243. .flex {
  244. display: flex;
  245. align-items: center;
  246. justify-content: space-between;
  247. }
  248. .swiper_container {
  249. width: calc(100% + 30rpx);
  250. min-height: 240rpx;
  251. margin-top: 30rpx;
  252. }
  253. .swiper_img {
  254. display: flex;
  255. align-items: flex-start;
  256. overflow: hidden;
  257. .swiper_img_box {
  258. width: calc(100% - 18rpx);
  259. height: 100%;
  260. position: relative;
  261. border-radius: 16rpx;
  262. overflow: hidden;
  263. }
  264. .img {
  265. display: block;
  266. width: 100%;
  267. height: 100%;
  268. background-repeat: no-repeat;
  269. background-position: center;
  270. background-size: cover;
  271. }
  272. &:nth-last-of-type(1) {
  273. .img {
  274. // width: 100%;
  275. }
  276. .swiper_mask {
  277. // right: 0;
  278. }
  279. }
  280. .swiper_mask {
  281. position: absolute;
  282. height: 60rpx;
  283. left: 0;
  284. right: 0;
  285. bottom: 0;
  286. background: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,6));
  287. color: #FFFFFF;
  288. font-size: 28rpx;
  289. line-height: 60rpx;
  290. overflow: hidden;
  291. padding: 0 20rpx;
  292. box-sizing: border-box;
  293. }
  294. }
  295. .imgs {
  296. display: flex;
  297. align-items: center;
  298. width: 100%;
  299. flex-wrap: wrap;
  300. overflow: hidden;
  301. margin-top: 20rpx;
  302. .imgs_box {
  303. width: 100%;
  304. width: calc((100% - 60rpx) / 4);
  305. overflow: hidden;
  306. margin-right: 20rpx;
  307. margin-bottom: 20rpx;
  308. height: 155rpx;
  309. &:nth-of-type(4n) {
  310. margin-right: 0;
  311. }
  312. image, .bg {
  313. display: block;
  314. width: 100%;
  315. height: 100%;
  316. background-repeat: no-repeat;
  317. background-position: center;
  318. background-size: cover;
  319. }
  320. }
  321. }
  322. .intr {
  323. // margin: 30rpx 0;
  324. color: #999999;
  325. font-size: 28rpx;
  326. line-height: 40rpx;
  327. }
  328. .intr,
  329. .more {
  330. color: #666;
  331. font-size: 26rpx;
  332. }
  333. .more {
  334. font-size: 28rpx;
  335. vertical-align: 3rpx;
  336. margin-left: 5rpx;
  337. }
  338. .no_img {
  339. display: block;
  340. height: 155rpx;
  341. width: 155rpx;
  342. }
  343. }
  344. .old_album_list {
  345. width: 92%;
  346. margin: 0 auto 30rpx;
  347. .old_title {
  348. font-size: 36rpx;
  349. color: #333;
  350. padding-top: 36rpx;
  351. }
  352. .old_imgs {
  353. display: flex;
  354. align-items: center;
  355. width: 100%;
  356. max-height: 433rpx;
  357. flex-wrap: wrap;
  358. overflow: hidden;
  359. image {
  360. width: 25%;
  361. margin-right: 4rpx;
  362. height: 160rpx;
  363. width: 160rpx;
  364. // object-fit: contain;
  365. }
  366. }
  367. .old_intr {
  368. margin: 30rpx 0;
  369. }
  370. .old_intr,
  371. .old_more {
  372. color: #666;
  373. font-size: 26rpx;
  374. }
  375. .old_more {
  376. margin-top: 20rpx;
  377. text-align: right;
  378. image {
  379. width: 20rpx;
  380. height: 20rpx;
  381. margin-left: 15rpx;
  382. }
  383. .iconfont {
  384. font-size: 25rpx;
  385. vertical-align: 3rpx;
  386. margin-left: 5rpx;
  387. }
  388. }
  389. }
  390. </style>