article.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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.list = []
  115. this.listQuery.articleTitle = keyword
  116. this.listQuery.pageNum = 1
  117. this.fetchList()
  118. },
  119. // 页码变化
  120. onPagiantionChange(index) {
  121. this.listQuery.pageNum = index
  122. this.fetchList()
  123. },
  124. // 加载更多
  125. onLoadMore() {
  126. this.fetchList()
  127. },
  128. },
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. /* scss中可以用mixin来扩展 */
  133. @mixin ellipsis($line: 1) {
  134. overflow: hidden;
  135. text-overflow: ellipsis;
  136. display: -webkit-box;
  137. -webkit-line-clamp: $line;
  138. -webkit-box-orient: vertical;
  139. }
  140. // pc 端
  141. @media screen and (min-width: 768px) {
  142. .page-top {
  143. height: 360px;
  144. background: url(https://static.caimei365.com/www/authentic/pc/bg-doc.png);
  145. background-size: auto 360px;
  146. .logo {
  147. display: block;
  148. width: 120px;
  149. height: 120px;
  150. border-radius: 50%;
  151. background: #fff;
  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. @include themify($themes) {
  183. color: themed('color') !important;
  184. }
  185. }
  186. }
  187. &:last-child {
  188. border-bottom: 0;
  189. }
  190. .info {
  191. width: 1000px;
  192. height: 100%;
  193. .name {
  194. font-size: 18px;
  195. color: #404040;
  196. line-height: 1.6;
  197. margin-bottom: 18px;
  198. text-align: justify;
  199. @include ellipsis(2);
  200. }
  201. .date {
  202. font-size: 18px;
  203. color: #b2b2b2;
  204. line-height: 1.4;
  205. }
  206. }
  207. .cover {
  208. width: 106px;
  209. height: 106px;
  210. border-bottom: 1px solid #d8d8d8;
  211. }
  212. }
  213. }
  214. }
  215. // 移动 端
  216. @media screen and (max-width: 768px) {
  217. .page-top {
  218. height: 46vw;
  219. background: url(https://static.caimei365.com/www/authentic/h5/bg-club.png);
  220. background-size: auto 46vw;
  221. .logo {
  222. display: block;
  223. width: 14.8vw;
  224. height: 14.8vw;
  225. border-radius: 50%;
  226. background: #fff;
  227. }
  228. .name {
  229. font-size: 4vw;
  230. color: #fff;
  231. }
  232. }
  233. .page-content {
  234. position: relative;
  235. .divider {
  236. border-bottom: 3.2vw solid #f7f7f7;
  237. height: 12.4vw;
  238. }
  239. }
  240. .search {
  241. position: absolute;
  242. left: 50%;
  243. top: 0;
  244. transform: translate(-50%, -50%);
  245. }
  246. .list {
  247. .section {
  248. padding: 2.4vw 0;
  249. margin: 0 4vw;
  250. background: #fff;
  251. border-bottom: 0.1vw solid #d8d8d8;
  252. &:first-child {
  253. border-top: 0.1vw solid #d8d8d8;
  254. }
  255. .info {
  256. width: 67.3vw;
  257. height: 100%;
  258. .name {
  259. font-size: 3.6vw;
  260. color: #404040;
  261. line-height: 1.5;
  262. text-align: justify;
  263. margin-bottom: 2.4vw;
  264. @include ellipsis(2);
  265. }
  266. .date {
  267. font-size: 3.2vw;
  268. color: #b2b2b2;
  269. line-height: 1.4;
  270. }
  271. }
  272. .cover {
  273. width: 18vw;
  274. height: 18vw;
  275. border-bottom: 0.1vw solid #d8d8d8;
  276. }
  277. }
  278. }
  279. }
  280. </style>