article.vue 6.3 KB

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