file.vue 7.5 KB

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