image.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <div class="page">
  3. <van-list
  4. v-model="isLoadingMore"
  5. :finished="finished"
  6. :immediate-check="false"
  7. :finished-text="total ? '没有更多了' : ''"
  8. @load="onLoadMore"
  9. >
  10. <div class="page-top flex flex-col justify-center items-center">
  11. <img class="logo" :src="supplierInfo.logo" />
  12. <span
  13. class="name mt-2"
  14. v-text="supplierInfo.shopName + '资料库'"
  15. ></span>
  16. </div>
  17. <div class="page-content">
  18. <!-- 搜索区域 -->
  19. <div class="search">
  20. <simple-search v-model="listQuery.imageTitle" @search="onSearch" />
  21. </div>
  22. <div class="divider"></div>
  23. <!-- tabbar -->
  24. <simple-tabs
  25. :tabs="tabs"
  26. :current="current"
  27. @change="onTabChange"
  28. @search="onSearch"
  29. ></simple-tabs>
  30. <div class="list">
  31. <div class="section" v-for="item in list" :key="item.imageId">
  32. <div class="info">
  33. <div class="name" v-text="item.imageTitle"></div>
  34. <div class="date">{{ item.createTime | dateFormat }}</div>
  35. <div class="download" @click="downloadLink(item.imageZipUrl)">
  36. 保存所有图片
  37. </div>
  38. </div>
  39. <div class="images grid grid-cols-4 md:grid-cols-8 gap-3 md:gap-4">
  40. <div
  41. class="item"
  42. v-for="(image, index) in item.imageList"
  43. :key="index"
  44. @click="onImagePreview(item.imageList, index)"
  45. >
  46. <img class="object-cover" :src="image" />
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <!-- 列表为空 -->
  52. <SimpleEmpty
  53. v-if="!total && !isRequest"
  54. description="敬请期待~"
  55. ></SimpleEmpty>
  56. </div>
  57. </van-list>
  58. </div>
  59. </template>
  60. <script>
  61. import { mapGetters } from 'vuex'
  62. import { tabs } from '@/configs/tabs'
  63. import downloadLink from '@/utils/download-link'
  64. import { ImagePreview } from 'vant'
  65. import { debounce } from '~/utils'
  66. export default {
  67. layout: 'app',
  68. data() {
  69. return {
  70. isLoadingMore: true,
  71. finished: false,
  72. isRequest: true,
  73. tabs: tabs(),
  74. current: 1,
  75. listQuery: {
  76. imageTitle: '',
  77. authUserId: '',
  78. pageNum: 1,
  79. pageSize: 4,
  80. },
  81. list: [],
  82. total: 0,
  83. }
  84. },
  85. computed: {
  86. ...mapGetters(['userInfo', 'supplierInfo']),
  87. },
  88. mounted() {
  89. this.fetchList()
  90. },
  91. methods: {
  92. // 下载方法
  93. downloadLink,
  94. // 获取列表
  95. fetchList: debounce(async function () {
  96. try {
  97. this.isLoadingMore = true
  98. this.listQuery.authUserId = this.userInfo.authUserId
  99. const res = await this.$http.api.getImageList(this.listQuery)
  100. this.list = [...this.list, ...res.data.list]
  101. this.finished = !res.data.hasNextPage
  102. this.total = res.data.total
  103. } catch (error) {
  104. console.log(error)
  105. } finally {
  106. this.isRequest = false
  107. this.isLoadingMore = false
  108. }
  109. }, 400),
  110. // 图片预览
  111. onImagePreview(imageList, index) {
  112. ImagePreview({
  113. images: imageList,
  114. startPosition: index,
  115. loop: true,
  116. showIndex: true,
  117. showIndicators: true,
  118. closeable: true,
  119. })
  120. },
  121. // tab切换
  122. onTabChange(item) {
  123. console.log(item)
  124. this.$router.push(`/ph${item.path}`)
  125. },
  126. // 搜索
  127. onSearch(keyword) {
  128. this.listQuery.imageTitle = keyword
  129. this.listQuery.pageNum = 1
  130. this.fetchList()
  131. },
  132. // 页码变化
  133. onPagiantionChange(index) {
  134. this.listQuery.pageNum = index
  135. this.fetchList()
  136. },
  137. // 加载更多
  138. onLoadMore() {
  139. this.listQuery.pageNum += 1
  140. this.fetchList()
  141. },
  142. },
  143. }
  144. </script>
  145. <style scoped lang="scss">
  146. /* scss中可以用mixin来扩展 */
  147. @mixin ellipsis($line: 1) {
  148. overflow: hidden;
  149. text-overflow: ellipsis;
  150. display: -webkit-box;
  151. -webkit-line-clamp: $line;
  152. -webkit-box-orient: vertical;
  153. }
  154. // pc 端
  155. @media screen and (min-width: 768px) {
  156. .page-top {
  157. height: 360px;
  158. background: url(https://static.caimei365.com/www/authentic/pc/bg-doc.png);
  159. background-size: auto 360px;
  160. .logo {
  161. display: block;
  162. width: 120px;
  163. height: 120px;
  164. border-radius: 50%;
  165. }
  166. .name {
  167. font-size: 30px;
  168. color: #fff;
  169. }
  170. }
  171. .page-content {
  172. width: 1200px;
  173. margin: 0 auto;
  174. background-color: #fff;
  175. .divider {
  176. height: 16px;
  177. background: #f7f7f7;
  178. }
  179. .search {
  180. display: none;
  181. }
  182. }
  183. .list {
  184. border-top: 16px solid #f7f7f7;
  185. border-bottom: 16px solid #f7f7f7;
  186. .section {
  187. padding: 32px 0;
  188. margin: 0 24px;
  189. background: #fff;
  190. border-bottom: 1px solid #d8d8d8;
  191. &:last-child {
  192. border-bottom: 0;
  193. }
  194. .info {
  195. position: relative;
  196. .name {
  197. font-size: 18px;
  198. color: #404040;
  199. line-height: 1.6;
  200. margin-bottom: 18px;
  201. text-align: justify;
  202. }
  203. .date {
  204. font-size: 18px;
  205. color: #b2b2b2;
  206. line-height: 1.4;
  207. }
  208. .download {
  209. bottom: 0;
  210. right: 0;
  211. position: absolute;
  212. color: #bc1724;
  213. font-size: 16px;
  214. cursor: pointer;
  215. }
  216. }
  217. .images {
  218. margin-top: 24px;
  219. .item {
  220. width: 126px;
  221. height: 126px;
  222. overflow: hidden;
  223. img {
  224. display: block;
  225. width: 100%;
  226. height: 100%;
  227. cursor: pointer;
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. // 移动 端
  235. @media screen and (max-width: 768px) {
  236. .page-top {
  237. height: 46vw;
  238. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  239. background-size: auto 46vw;
  240. .logo {
  241. display: block;
  242. width: 14.8vw;
  243. height: 14.8vw;
  244. border-radius: 50%;
  245. }
  246. .name {
  247. font-size: 4vw;
  248. color: #fff;
  249. }
  250. }
  251. .page-content {
  252. position: relative;
  253. .divider {
  254. border-bottom: 3.2vw solid #f7f7f7;
  255. height: 12.4vw;
  256. }
  257. }
  258. .search {
  259. position: absolute;
  260. left: 50%;
  261. top: 0;
  262. transform: translate(-50%, -50%);
  263. }
  264. .list {
  265. .section {
  266. position: relative;
  267. padding: 2.4vw 0;
  268. margin: 0 4vw;
  269. padding-bottom: 9.8vw;
  270. background: #fff;
  271. border-bottom: 0.1vw solid #d8d8d8;
  272. &:first-child {
  273. border-top: 0.1vw solid #d8d8d8;
  274. }
  275. .info {
  276. .name {
  277. font-size: 3.6vw;
  278. color: #404040;
  279. line-height: 1.5;
  280. margin-bottom: 2.4vw;
  281. @include ellipsis(2);
  282. text-align: justify;
  283. }
  284. .date {
  285. bottom: 2.4vw;
  286. left: 0;
  287. position: absolute;
  288. font-size: 3.2vw;
  289. color: #b2b2b2;
  290. line-height: 1.4;
  291. }
  292. .download {
  293. bottom: 2.4vw;
  294. right: 0;
  295. position: absolute;
  296. color: #bc1724;
  297. font-size: 3.6vw;
  298. cursor: pointer;
  299. }
  300. }
  301. .images {
  302. margin-top: 2.4vw;
  303. .item {
  304. width: 21vw;
  305. height: 21vw;
  306. overflow: hidden;
  307. img {
  308. display: block;
  309. width: 100%;
  310. height: 100%;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. </style>