index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <page-layout class="news-index">
  3. <nav-bar title="新闻" @init="onInitNavbar"></nav-bar>
  4. <u-scroll-view :tabbar-conflict="false" @scroll-near-lower="onScrollToLower">
  5. <view class="main-container">
  6. <u-tabs :active.sync="tabActive" :tabs="tabs" tab-style="default" @change="tabChange"/>
  7. <van-empty v-if="newsList.length === 0" description="暂无数据" />
  8. <view v-else class="news-list">
  9. <template v-for="(item, index) in newsList">
  10. <news-item :item="item" :key="index" :type="tabActive" />
  11. </template>
  12. </view>
  13. <disclaimer-text></disclaimer-text>
  14. </view>
  15. </u-scroll-view>
  16. <float-button></float-button>
  17. <van-dialog id="van-dialog" />
  18. </page-layout>
  19. </template>
  20. <script>
  21. import NavBar from '@/components/layout/nav-bar'
  22. import UTabs from '@/components/common/u-tabs'
  23. import UScrollView from '@/components/common/u-scroll-view'
  24. import NewsItem from '@/pages/news/components/news-item.vue'
  25. import { exhibitorsNewsList, newsList } from '@/api/exhibitor'
  26. import DisclaimerText from '@/components/disclaimer-text/index.vue'
  27. import floatButton from "@/components/layout/float-button"
  28. import PageLayout from "@/components/layout/page-layout";
  29. export default {
  30. options: {
  31. styleIsolation: 'shared'
  32. },
  33. components: {
  34. PageLayout,
  35. NavBar,
  36. UTabs,
  37. UScrollView,
  38. NewsItem,
  39. DisclaimerText,
  40. floatButton
  41. },
  42. data() {
  43. return {
  44. tabActive: 'exhibition',
  45. tabs: [{
  46. label: '展会新闻',
  47. value: 'exhibition'
  48. }, {
  49. label: '展商新闻',
  50. value: 'exhibitor'
  51. }],
  52. newsList: [],
  53. newsParams: {
  54. page: 1,
  55. page_size: 10,
  56. keyword: '',
  57. },
  58. newsListLoading: false,
  59. newsListLastPage: 1
  60. }
  61. },
  62. onLoad(options) {
  63. if (options.type) {
  64. this.tabActive = options.type
  65. }
  66. },
  67. mounted() {
  68. this.getList()
  69. },
  70. methods: {
  71. onShareAppMessage: function () {
  72. return {
  73. title: '慕尼黑上海电子生产设备展',
  74. path: '/pages/news/index',
  75. imageUrl: 'https://oss.productronicachina.com.cn/resources/common/up/0000001002/20250221/67b829f60c212.png'
  76. }
  77. },
  78. onShareTimeline() {
  79. return {
  80. title: '慕尼黑上海电子生产设备展',
  81. path: '/pages/news/index',
  82. imageUrl: 'https://oss.productronicachina.com.cn/resources/common/up/0000001002/20250221/67b829f60c212.png'
  83. };
  84. },
  85. getList() {
  86. if (this.tabActive === 'exhibitor') {
  87. this.getExhibitorsNewsList()
  88. }
  89. if (this.tabActive === 'exhibition') {
  90. this.getNewsList()
  91. }
  92. },
  93. getNewsList() {
  94. this.newsListLoading = true
  95. newsList(this.newsParams).then(res => {
  96. if (res.data.data) {
  97. if (this.newsParams.page > 1) {
  98. this.newsList = [...this.newsList, ...res.data.data]
  99. } else {
  100. this.newsList = res.data.data
  101. this.newsListLastPage = res.data.last_page
  102. }
  103. } else {
  104. this.showToast('系统繁忙,稍候再试')
  105. }
  106. this.newsListLoading = false
  107. })
  108. },
  109. getExhibitorsNewsList() {
  110. this.newsListLoading = true
  111. exhibitorsNewsList(this.newsParams).then(res => {
  112. if (res.data.data) {
  113. if (this.newsParams.page > 1) {
  114. this.newsList = [...this.newsList, ...res.data.data]
  115. } else {
  116. this.newsList = res.data.data
  117. this.newsListLastPage = res.data.last_page
  118. }
  119. } else {
  120. this.showToast('系统繁忙,稍候再试')
  121. }
  122. this.newsListLoading = false
  123. })
  124. },
  125. onScrollToLower(e) {
  126. if (this.newsListLastPage === this.newsParams.page) {
  127. return
  128. }
  129. if (this.newsListLoading === true) {
  130. return
  131. }
  132. this.newsListLoading = true
  133. this.newsParams.page = this.newsParams.page+1
  134. this.getList()
  135. },
  136. tabChange(e) {
  137. this.tabActive = e.detail.value
  138. this.newsParams.page = 1
  139. this.newsList = []
  140. this.getList()
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .news-list{
  147. display: grid;
  148. grid-template-columns: 1fr;
  149. grid-row-gap: 18rpx;
  150. margin-top: 28rpx;
  151. }
  152. </style>