image.vue 7.6 KB

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