file.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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.fileTitle"
  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
  36. class="section md:flex md:justify-between md:items-center"
  37. v-for="item in list"
  38. :key="item.fileId"
  39. @click="previewFile(item)"
  40. >
  41. <div class="info">
  42. <div class="name" v-text="item.fileName"></div>
  43. <div class="date">{{ item.createTime | dateFormat }}</div>
  44. <div class="download" @click.stop="downloadLink(item, $event)">
  45. 下载
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <!-- 列表为空 -->
  51. <SimpleEmpty
  52. v-if="!total && !isRequest"
  53. description="敬请期待~"
  54. ></SimpleEmpty>
  55. </div>
  56. </van-list>
  57. </div>
  58. </template>
  59. <script>
  60. import { mapGetters } from 'vuex'
  61. import { tabs } from '@/configs/tabs'
  62. import downloadLink from '@/utils/download-link'
  63. import { debounce } from '~/utils'
  64. export default {
  65. layout: 'app',
  66. data() {
  67. return {
  68. isLoadingMore: true,
  69. finished: false,
  70. isRequest: true,
  71. tabs: tabs(),
  72. current: 3,
  73. listQuery: {
  74. fileType: 1,
  75. fileTitle: '',
  76. authUserId: '',
  77. pageNum: 1,
  78. pageSize: 10,
  79. },
  80. list: [],
  81. total: 0,
  82. }
  83. },
  84. computed: {
  85. ...mapGetters(['routePrefix', 'supplierInfo', 'authUserId']),
  86. },
  87. mounted() {
  88. this.fetchList()
  89. },
  90. methods: {
  91. // 下载方法
  92. downloadLink(item, $event) {
  93. const url = `${process.env.BASE_URL}/download/file?ossName=${item.fileDownloadUrl}&fileName=${item.fileName}`
  94. downloadLink(url, $event)
  95. },
  96. // 预览文件
  97. previewFile(item) {
  98. window.open(item.filePreviewUrl)
  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.getFileList(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. // tab切换
  118. onTabChange(item) {
  119. this.$router.push(`${this.routePrefix}${item.path}`)
  120. },
  121. // 搜索
  122. onSearch(keyword) {
  123. this.listQuery.fileTitle = keyword
  124. this.listQuery.pageNum = 1
  125. this.fetchList()
  126. },
  127. // 页码变化
  128. onPagiantionChange(index) {
  129. this.listQuery.pageNum = index
  130. this.fetchList()
  131. },
  132. // 加载更多
  133. onLoadMore() {
  134. this.fetchList()
  135. },
  136. },
  137. }
  138. </script>
  139. <style scoped lang="scss">
  140. /* scss中可以用mixin来扩展 */
  141. @mixin ellipsis($line: 1) {
  142. overflow: hidden;
  143. text-overflow: ellipsis;
  144. display: -webkit-box;
  145. -webkit-line-clamp: $line;
  146. -webkit-box-orient: vertical;
  147. }
  148. // pc 端
  149. @media screen and (min-width: 768px) {
  150. .page-top {
  151. height: 360px;
  152. background: url(https://static.caimei365.com/www/authentic/pc/bg-doc.png);
  153. background-size: auto 360px;
  154. .logo {
  155. display: block;
  156. width: 120px;
  157. height: 120px;
  158. border-radius: 50%;
  159. background: #fff;
  160. }
  161. .name {
  162. font-size: 30px;
  163. color: #fff;
  164. }
  165. }
  166. .page-content {
  167. width: 1200px;
  168. margin: 0 auto;
  169. background-color: #fff;
  170. .divider {
  171. height: 16px;
  172. background: #f7f7f7;
  173. }
  174. .search {
  175. display: none;
  176. }
  177. }
  178. .list {
  179. border-top: 16px solid #f7f7f7;
  180. border-bottom: 16px solid #f7f7f7;
  181. .section {
  182. padding: 32px 0;
  183. margin: 0 24px;
  184. background: #fff;
  185. border-bottom: 1px solid #d8d8d8;
  186. transition: all 0.4s;
  187. cursor: pointer;
  188. &:last-child {
  189. border-bottom: 0;
  190. }
  191. &:hover {
  192. .name {
  193. color: #bc1724 !important;
  194. }
  195. }
  196. .info {
  197. width: 100%;
  198. position: relative;
  199. .name {
  200. width: 1050px;
  201. height: 56px;
  202. font-size: 18px;
  203. color: #404040;
  204. line-height: 1.6;
  205. margin-bottom: 18px;
  206. text-align: justify;
  207. @include ellipsis(2);
  208. transition: all 0.4s;
  209. }
  210. .date {
  211. font-size: 18px;
  212. color: #b2b2b2;
  213. line-height: 1.4;
  214. }
  215. .download {
  216. position: absolute;
  217. text-align: center;
  218. right: 0;
  219. top: 50%;
  220. transform: translateY(-50%);
  221. font-size: 16px;
  222. color: #bc1724;
  223. cursor: pointer;
  224. &::before {
  225. content: '';
  226. display: block;
  227. width: 54px;
  228. height: 59px;
  229. background: url(https://static.caimei365.com/www/authentic/pc/icon-pdf-download.png)
  230. no-repeat center;
  231. background-size: 54px;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. // 移动 端
  239. @media screen and (max-width: 768px) {
  240. .page-top {
  241. height: 46vw;
  242. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  243. background-size: auto 46vw;
  244. .logo {
  245. display: block;
  246. width: 14.8vw;
  247. height: 14.8vw;
  248. border-radius: 50%;
  249. background: #fff;
  250. }
  251. .name {
  252. font-size: 4vw;
  253. color: #fff;
  254. }
  255. }
  256. .page-content {
  257. position: relative;
  258. .divider {
  259. border-bottom: 3.2vw solid #f7f7f7;
  260. height: 12.4vw;
  261. }
  262. }
  263. .search {
  264. position: absolute;
  265. left: 50%;
  266. top: 0;
  267. transform: translate(-50%, -50%);
  268. }
  269. .list {
  270. .section {
  271. position: relative;
  272. padding: 2.4vw 0;
  273. margin: 0 4vw;
  274. padding-bottom: 6.8vw;
  275. background: #fff;
  276. border-bottom: 0.1vw solid #d8d8d8;
  277. &:first-child {
  278. border-top: 0.1vw solid #d8d8d8;
  279. }
  280. .info {
  281. .name {
  282. font-size: 3.6vw;
  283. color: #404040;
  284. line-height: 1.5;
  285. margin-bottom: 2.4vw;
  286. text-align: justify;
  287. @include ellipsis(2);
  288. }
  289. .date {
  290. position: absolute;
  291. left: 0;
  292. bottom: 2.4vw;
  293. font-size: 3.2vw;
  294. color: #b2b2b2;
  295. line-height: 1.4;
  296. }
  297. .download {
  298. position: absolute;
  299. right: 0;
  300. bottom: 2.4vw;
  301. font-size: 3.2vw;
  302. color: #bc1724;
  303. cursor: pointer;
  304. margin-top: 1.2vw;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. </style>