file.vue 7.2 KB

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