article.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 v-model="listQuery.articleTitle" @search="onSearch" />
  21. </div>
  22. <div class="divider"></div>
  23. <!-- tabbar -->
  24. <simple-tabs
  25. :tabs="tabs"
  26. :current="current"
  27. @change="onTabChange"
  28. @search="onSearch"
  29. ></simple-tabs>
  30. <div class="list">
  31. <div
  32. class="section flex justify-between items-center"
  33. v-for="item in list"
  34. :key="item.articleId"
  35. @click="toDetail(item)"
  36. >
  37. <div class="info">
  38. <div class="name" v-text="item.articleTitle"></div>
  39. <div class="date">{{ item.createTime | dateFormat }}</div>
  40. </div>
  41. <img class="cover" :src="item.articleImage" />
  42. </div>
  43. </div>
  44. <!-- 列表为空 -->
  45. <SimpleEmpty
  46. v-if="!total && !isRequest"
  47. description="敬请期待~"
  48. ></SimpleEmpty>
  49. </div>
  50. </van-list>
  51. </div>
  52. </template>
  53. <script>
  54. import { mapGetters } from 'vuex'
  55. import { tabs } from '@/configs/tabs'
  56. import { debounce } from '~/utils'
  57. export default {
  58. layout: 'app',
  59. data() {
  60. return {
  61. isLoadingMore: true,
  62. finished: false,
  63. isRequest: true,
  64. tabs: tabs(),
  65. current: 0,
  66. listQuery: {
  67. articleTitle: '',
  68. authUserId: '102',
  69. pageNum: 1,
  70. pageSize: 4,
  71. },
  72. list: [],
  73. total: 0,
  74. }
  75. },
  76. computed: {
  77. ...mapGetters(['userInfo', 'supplierInfo', 'authUserId']),
  78. },
  79. mounted() {
  80. this.fetchList()
  81. },
  82. methods: {
  83. fetchList: debounce(async function () {
  84. try {
  85. this.isLoadingMore = true
  86. this.listQuery.authUserId = this.userInfo.authUserId
  87. const res = await this.$http.api.getArticleList(this.listQuery)
  88. this.list = [...this.list, ...res.data.list]
  89. this.finished = !res.data.hasNextPage
  90. this.total = res.data.total
  91. } catch (error) {
  92. console.log(error)
  93. } finally {
  94. this.isRequest = false
  95. this.isLoadingMore = false
  96. }
  97. }, 400),
  98. // 详情
  99. toDetail(item) {
  100. localStorage.setItem('articleInfo', JSON.stringify(item))
  101. const url = `/${this.authUserId}/app/database/article-detail`
  102. this.$router.push(url)
  103. },
  104. // tab切换
  105. onTabChange(item) {
  106. console.log(item)
  107. this.$router.push(`/ph${item.path}`)
  108. },
  109. // 搜索
  110. onSearch(keyword) {
  111. this.listQuery.articleTitle = keyword
  112. this.listQuery.pageNum = 1
  113. this.fetchList()
  114. },
  115. // 页码变化
  116. onPagiantionChange(index) {
  117. this.listQuery.pageNum = index
  118. this.fetchList()
  119. },
  120. // 加载更多
  121. onLoadMore() {
  122. this.listQuery.pageNum += 1
  123. this.fetchList()
  124. },
  125. },
  126. }
  127. </script>
  128. <style scoped lang="scss">
  129. /* scss中可以用mixin来扩展 */
  130. @mixin ellipsis($line: 1) {
  131. overflow: hidden;
  132. text-overflow: ellipsis;
  133. display: -webkit-box;
  134. -webkit-line-clamp: $line;
  135. -webkit-box-orient: vertical;
  136. }
  137. // pc 端
  138. @media screen and (min-width: 768px) {
  139. .page-top {
  140. height: 360px;
  141. background: url(https://static.caimei365.com/www/authentic/pc/bg-doc.png);
  142. background-size: auto 360px;
  143. .logo {
  144. display: block;
  145. width: 120px;
  146. height: 120px;
  147. border-radius: 50%;
  148. }
  149. .name {
  150. font-size: 30px;
  151. color: #fff;
  152. }
  153. }
  154. .page-content {
  155. width: 1200px;
  156. margin: 0 auto;
  157. background-color: #fff;
  158. .divider {
  159. height: 16px;
  160. background: #f7f7f7;
  161. }
  162. .search {
  163. display: none;
  164. }
  165. }
  166. .list {
  167. border-top: 16px solid #f7f7f7;
  168. border-bottom: 16px solid #f7f7f7;
  169. .section {
  170. padding: 32px 0;
  171. margin: 0 24px;
  172. background: #fff;
  173. border-bottom: 1px solid #d8d8d8;
  174. transition: all 0.4s;
  175. cursor: pointer;
  176. &:hover {
  177. .name {
  178. color: #bc1724 !important;
  179. }
  180. }
  181. &:last-child {
  182. border-bottom: 0;
  183. }
  184. .info {
  185. width: 1000px;
  186. height: 100%;
  187. .name {
  188. font-size: 18px;
  189. color: #404040;
  190. line-height: 1.6;
  191. margin-bottom: 18px;
  192. text-align: justify;
  193. @include ellipsis(2);
  194. }
  195. .date {
  196. font-size: 18px;
  197. color: #b2b2b2;
  198. line-height: 1.4;
  199. }
  200. }
  201. .cover {
  202. width: 106px;
  203. height: 106px;
  204. border-bottom: 1px solid #d8d8d8;
  205. }
  206. }
  207. }
  208. }
  209. // 移动 端
  210. @media screen and (max-width: 768px) {
  211. .page-top {
  212. height: 46vw;
  213. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  214. background-size: auto 46vw;
  215. .logo {
  216. display: block;
  217. width: 14.8vw;
  218. height: 14.8vw;
  219. border-radius: 50%;
  220. }
  221. .name {
  222. font-size: 4vw;
  223. color: #fff;
  224. }
  225. }
  226. .page-content {
  227. position: relative;
  228. .divider {
  229. border-bottom: 3.2vw solid #f7f7f7;
  230. height: 12.4vw;
  231. }
  232. }
  233. .search {
  234. position: absolute;
  235. left: 50%;
  236. top: 0;
  237. transform: translate(-50%, -50%);
  238. }
  239. .list {
  240. .section {
  241. padding: 2.4vw 0;
  242. margin: 0 4vw;
  243. background: #fff;
  244. border-bottom: 0.1vw solid #d8d8d8;
  245. &:first-child {
  246. border-top: 0.1vw solid #d8d8d8;
  247. }
  248. .info {
  249. width: 67.3vw;
  250. height: 100%;
  251. .name {
  252. font-size: 3.6vw;
  253. color: #404040;
  254. line-height: 1.5;
  255. text-align: justify;
  256. margin-bottom: 2.4vw;
  257. @include ellipsis(2);
  258. }
  259. .date {
  260. font-size: 3.2vw;
  261. color: #b2b2b2;
  262. line-height: 1.4;
  263. }
  264. }
  265. .cover {
  266. width: 18vw;
  267. height: 18vw;
  268. border-bottom: 0.1vw solid #d8d8d8;
  269. }
  270. }
  271. }
  272. }
  273. </style>