image.vue 7.5 KB

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