file.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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: 4,
  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. }
  160. .name {
  161. font-size: 30px;
  162. color: #fff;
  163. }
  164. }
  165. .page-content {
  166. width: 1200px;
  167. margin: 0 auto;
  168. background-color: #fff;
  169. .divider {
  170. height: 16px;
  171. background: #f7f7f7;
  172. }
  173. .search {
  174. display: none;
  175. }
  176. }
  177. .list {
  178. border-top: 16px solid #f7f7f7;
  179. border-bottom: 16px solid #f7f7f7;
  180. .section {
  181. padding: 32px 0;
  182. margin: 0 24px;
  183. background: #fff;
  184. border-bottom: 1px solid #d8d8d8;
  185. transition: all 0.4s;
  186. cursor: pointer;
  187. &:last-child {
  188. border-bottom: 0;
  189. }
  190. &:hover {
  191. .name {
  192. color: #bc1724 !important;
  193. }
  194. }
  195. .info {
  196. width: 100%;
  197. position: relative;
  198. .name {
  199. width: 1050px;
  200. height: 56px;
  201. font-size: 18px;
  202. color: #404040;
  203. line-height: 1.6;
  204. margin-bottom: 18px;
  205. text-align: justify;
  206. @include ellipsis(2);
  207. transition: all 0.4s;
  208. }
  209. .date {
  210. font-size: 18px;
  211. color: #b2b2b2;
  212. line-height: 1.4;
  213. }
  214. .download {
  215. position: absolute;
  216. text-align: center;
  217. right: 0;
  218. top: 50%;
  219. transform: translateY(-50%);
  220. font-size: 16px;
  221. color: #bc1724;
  222. cursor: pointer;
  223. &::before {
  224. content: '';
  225. display: block;
  226. width: 54px;
  227. height: 59px;
  228. background: url(https://static.caimei365.com/www/authentic/pc/icon-pdf-download.png)
  229. no-repeat center;
  230. background-size: 54px;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. }
  237. // 移动 端
  238. @media screen and (max-width: 768px) {
  239. .page-top {
  240. height: 46vw;
  241. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  242. background-size: auto 46vw;
  243. .logo {
  244. display: block;
  245. width: 14.8vw;
  246. height: 14.8vw;
  247. border-radius: 50%;
  248. }
  249. .name {
  250. font-size: 4vw;
  251. color: #fff;
  252. }
  253. }
  254. .page-content {
  255. position: relative;
  256. .divider {
  257. border-bottom: 3.2vw solid #f7f7f7;
  258. height: 12.4vw;
  259. }
  260. }
  261. .search {
  262. position: absolute;
  263. left: 50%;
  264. top: 0;
  265. transform: translate(-50%, -50%);
  266. }
  267. .list {
  268. .section {
  269. position: relative;
  270. padding: 2.4vw 0;
  271. margin: 0 4vw;
  272. padding-bottom: 6.8vw;
  273. background: #fff;
  274. border-bottom: 0.1vw solid #d8d8d8;
  275. &:first-child {
  276. border-top: 0.1vw solid #d8d8d8;
  277. }
  278. .info {
  279. .name {
  280. font-size: 3.6vw;
  281. color: #404040;
  282. line-height: 1.5;
  283. margin-bottom: 2.4vw;
  284. text-align: justify;
  285. @include ellipsis(2);
  286. }
  287. .date {
  288. position: absolute;
  289. left: 0;
  290. bottom: 2.4vw;
  291. font-size: 3.2vw;
  292. color: #b2b2b2;
  293. line-height: 1.4;
  294. }
  295. .download {
  296. position: absolute;
  297. right: 0;
  298. bottom: 2.4vw;
  299. font-size: 3.2vw;
  300. color: #bc1724;
  301. cursor: pointer;
  302. margin-top: 1.2vw;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. </style>