image.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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.list = []
  136. this.listQuery.imageTitle = keyword
  137. this.listQuery.pageNum = 1
  138. this.fetchList()
  139. },
  140. // 页码变化
  141. onPagiantionChange(index) {
  142. this.listQuery.pageNum = index
  143. this.fetchList()
  144. },
  145. // 加载更多
  146. onLoadMore() {
  147. this.fetchList()
  148. },
  149. },
  150. }
  151. </script>
  152. <style scoped lang="scss">
  153. /* scss中可以用mixin来扩展 */
  154. @mixin ellipsis($line: 1) {
  155. overflow: hidden;
  156. text-overflow: ellipsis;
  157. display: -webkit-box;
  158. -webkit-line-clamp: $line;
  159. -webkit-box-orient: vertical;
  160. }
  161. // pc 端
  162. @media screen and (min-width: 768px) {
  163. .page-top {
  164. height: 360px;
  165. background: url(https://static.caimei365.com/www/authentic/pc/bg-doc.png);
  166. background-size: auto 360px;
  167. .logo {
  168. display: block;
  169. width: 120px;
  170. height: 120px;
  171. border-radius: 50%;
  172. background: #fff;
  173. }
  174. .name {
  175. font-size: 30px;
  176. color: #fff;
  177. }
  178. }
  179. .page-content {
  180. width: 1200px;
  181. margin: 0 auto;
  182. background-color: #fff;
  183. .divider {
  184. height: 16px;
  185. background: #f7f7f7;
  186. }
  187. .search {
  188. display: none;
  189. }
  190. }
  191. .list {
  192. border-top: 16px solid #f7f7f7;
  193. border-bottom: 16px solid #f7f7f7;
  194. .section {
  195. padding: 32px 0;
  196. margin: 0 24px;
  197. background: #fff;
  198. border-bottom: 1px solid #d8d8d8;
  199. &:last-child {
  200. border-bottom: 0;
  201. }
  202. .info {
  203. position: relative;
  204. .name {
  205. font-size: 18px;
  206. color: #404040;
  207. line-height: 1.6;
  208. margin-bottom: 18px;
  209. text-align: justify;
  210. }
  211. .date {
  212. font-size: 18px;
  213. color: #b2b2b2;
  214. line-height: 1.4;
  215. }
  216. .download {
  217. bottom: 0;
  218. right: 0;
  219. position: absolute;
  220. @include themify($themes) {
  221. color: themed('color');
  222. }
  223. font-size: 16px;
  224. cursor: pointer;
  225. }
  226. }
  227. .images {
  228. margin-top: 24px;
  229. .item {
  230. width: 126px;
  231. height: 126px;
  232. overflow: hidden;
  233. img {
  234. display: block;
  235. width: 100%;
  236. height: 100%;
  237. cursor: pointer;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. }
  244. // 移动 端
  245. @media screen and (max-width: 768px) {
  246. .page-top {
  247. height: 46vw;
  248. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  249. background-size: auto 46vw;
  250. .logo {
  251. display: block;
  252. width: 14.8vw;
  253. height: 14.8vw;
  254. border-radius: 50%;
  255. background: #fff;
  256. }
  257. .name {
  258. font-size: 4vw;
  259. color: #fff;
  260. }
  261. }
  262. .page-content {
  263. position: relative;
  264. .divider {
  265. border-bottom: 3.2vw solid #f7f7f7;
  266. height: 12.4vw;
  267. }
  268. }
  269. .search {
  270. position: absolute;
  271. left: 50%;
  272. top: 0;
  273. transform: translate(-50%, -50%);
  274. }
  275. .list {
  276. .section {
  277. position: relative;
  278. padding: 2.4vw 0;
  279. margin: 0 4vw;
  280. padding-bottom: 9.8vw;
  281. background: #fff;
  282. border-bottom: 0.1vw solid #d8d8d8;
  283. &:first-child {
  284. border-top: 0.1vw solid #d8d8d8;
  285. }
  286. .info {
  287. .name {
  288. font-size: 3.6vw;
  289. color: #404040;
  290. line-height: 1.5;
  291. margin-bottom: 2.4vw;
  292. @include ellipsis(2);
  293. text-align: justify;
  294. }
  295. .date {
  296. bottom: 2.4vw;
  297. left: 0;
  298. position: absolute;
  299. font-size: 3.2vw;
  300. color: #b2b2b2;
  301. line-height: 1.4;
  302. }
  303. .download {
  304. bottom: 2.4vw;
  305. right: 0;
  306. position: absolute;
  307. @include themify($themes) {
  308. color: themed('color');
  309. }
  310. font-size: 3.6vw;
  311. cursor: pointer;
  312. }
  313. }
  314. .images {
  315. margin-top: 2.4vw;
  316. .item {
  317. width: 21vw;
  318. height: 21vw;
  319. overflow: hidden;
  320. img {
  321. display: block;
  322. width: 100%;
  323. height: 100%;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. </style>