file.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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="download(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 downloadFile from '~/utils/donwload-tools'
  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. download(item, $event) {
  93. const url = `${process.env.BASE_URL}/download/file?ossName=${item.fileDownloadUrl}&fileName=${item.fileName}`
  94. downloadFile(url, item.fileName, this, $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. @include themify($themes) {
  154. background: themed('pc-banner-doc');
  155. }
  156. background-size: auto 360px;
  157. .logo {
  158. display: block;
  159. width: 120px;
  160. height: 120px;
  161. border-radius: 50%;
  162. background: #fff;
  163. }
  164. .name {
  165. font-size: 30px;
  166. color: #fff;
  167. }
  168. }
  169. .page-content {
  170. width: 1200px;
  171. margin: 0 auto;
  172. background-color: #fff;
  173. .divider {
  174. height: 16px;
  175. background: #f7f7f7;
  176. }
  177. .search {
  178. display: none;
  179. }
  180. }
  181. .list {
  182. border-top: 16px solid #f7f7f7;
  183. border-bottom: 16px solid #f7f7f7;
  184. .section {
  185. padding: 32px 0;
  186. margin: 0 24px;
  187. background: #fff;
  188. border-bottom: 1px solid #d8d8d8;
  189. transition: all 0.4s;
  190. cursor: pointer;
  191. &:last-child {
  192. border-bottom: 0;
  193. }
  194. &:hover {
  195. .name {
  196. @include themify($themes) {
  197. color: themed('color') !important;
  198. }
  199. }
  200. }
  201. .info {
  202. width: 100%;
  203. position: relative;
  204. .name {
  205. width: 1050px;
  206. height: 56px;
  207. font-size: 18px;
  208. color: #404040;
  209. line-height: 1.6;
  210. margin-bottom: 18px;
  211. text-align: justify;
  212. @include ellipsis(2);
  213. transition: all 0.4s;
  214. }
  215. .date {
  216. font-size: 18px;
  217. color: #b2b2b2;
  218. line-height: 1.4;
  219. }
  220. .download {
  221. position: absolute;
  222. text-align: center;
  223. right: 0;
  224. top: 50%;
  225. transform: translateY(-50%);
  226. font-size: 16px;
  227. color: #1890ff;
  228. cursor: pointer;
  229. &::before {
  230. content: '';
  231. display: block;
  232. width: 54px;
  233. height: 59px;
  234. background: url(~assets/theme-images/common/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. @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: 6.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. text-align: justify;
  294. @include ellipsis(2);
  295. }
  296. .date {
  297. position: absolute;
  298. left: 0;
  299. bottom: 2.4vw;
  300. font-size: 3.2vw;
  301. color: #b2b2b2;
  302. line-height: 1.4;
  303. }
  304. .download {
  305. position: absolute;
  306. right: 0;
  307. bottom: 2.4vw;
  308. font-size: 3.2vw;
  309. @include themify($themes) {
  310. color: themed('color');
  311. }
  312. cursor: pointer;
  313. margin-top: 1.2vw;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. </style>