article.vue 6.4 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: 4,
  75. },
  76. list: [],
  77. total: 0,
  78. }
  79. },
  80. computed: {
  81. ...mapGetters(['userInfo', 'supplierInfo', 'authUserId']),
  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.userInfo.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. localStorage.setItem('articleInfo', JSON.stringify(item))
  106. const url = `/${this.authUserId}/app/database/article-detail`
  107. this.$router.push(url)
  108. },
  109. // tab切换
  110. onTabChange(item) {
  111. console.log(item)
  112. this.$router.push(`/${this.authUserId}/app${item.path}`)
  113. },
  114. // 搜索
  115. onSearch(keyword) {
  116. this.listQuery.articleTitle = keyword
  117. this.listQuery.pageNum = 1
  118. this.fetchList()
  119. },
  120. // 页码变化
  121. onPagiantionChange(index) {
  122. this.listQuery.pageNum = index
  123. this.fetchList()
  124. },
  125. // 加载更多
  126. onLoadMore() {
  127. this.fetchList()
  128. },
  129. },
  130. }
  131. </script>
  132. <style scoped lang="scss">
  133. /* scss中可以用mixin来扩展 */
  134. @mixin ellipsis($line: 1) {
  135. overflow: hidden;
  136. text-overflow: ellipsis;
  137. display: -webkit-box;
  138. -webkit-line-clamp: $line;
  139. -webkit-box-orient: vertical;
  140. }
  141. // pc 端
  142. @media screen and (min-width: 768px) {
  143. .page-top {
  144. height: 360px;
  145. background: url(https://static.caimei365.com/www/authentic/pc/bg-doc.png);
  146. background-size: auto 360px;
  147. .logo {
  148. display: block;
  149. width: 120px;
  150. height: 120px;
  151. border-radius: 50%;
  152. }
  153. .name {
  154. font-size: 30px;
  155. color: #fff;
  156. }
  157. }
  158. .page-content {
  159. width: 1200px;
  160. margin: 0 auto;
  161. background-color: #fff;
  162. .divider {
  163. height: 16px;
  164. background: #f7f7f7;
  165. }
  166. .search {
  167. display: none;
  168. }
  169. }
  170. .list {
  171. border-top: 16px solid #f7f7f7;
  172. border-bottom: 16px solid #f7f7f7;
  173. .section {
  174. padding: 32px 0;
  175. margin: 0 24px;
  176. background: #fff;
  177. border-bottom: 1px solid #d8d8d8;
  178. transition: all 0.4s;
  179. cursor: pointer;
  180. &:hover {
  181. .name {
  182. color: #bc1724 !important;
  183. }
  184. }
  185. &:last-child {
  186. border-bottom: 0;
  187. }
  188. .info {
  189. width: 1000px;
  190. height: 100%;
  191. .name {
  192. font-size: 18px;
  193. color: #404040;
  194. line-height: 1.6;
  195. margin-bottom: 18px;
  196. text-align: justify;
  197. @include ellipsis(2);
  198. }
  199. .date {
  200. font-size: 18px;
  201. color: #b2b2b2;
  202. line-height: 1.4;
  203. }
  204. }
  205. .cover {
  206. width: 106px;
  207. height: 106px;
  208. border-bottom: 1px solid #d8d8d8;
  209. }
  210. }
  211. }
  212. }
  213. // 移动 端
  214. @media screen and (max-width: 768px) {
  215. .page-top {
  216. height: 46vw;
  217. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  218. background-size: auto 46vw;
  219. .logo {
  220. display: block;
  221. width: 14.8vw;
  222. height: 14.8vw;
  223. border-radius: 50%;
  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>