index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  5. <view class="list-scroll-view">
  6. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  7. <view class="list_1 textOver">{{item.name||'暂无'}}</view>
  8. <view class="list_2">
  9. <view class="time"><text>类型:</text>{{item.zhType||'暂无'}}
  10. </view>
  11. <view class="time"><text>来源:</text>{{item.source||'暂无'}}
  12. </view>
  13. <view class="time"><text>作者:</text>{{item.author||'暂无'}}
  14. </view>
  15. <view class="time"><text>发布时间:</text>{{item.fixed_time||'暂无'}}
  16. </view>
  17. </view>
  18. </view>
  19. <view class="is_bottom" v-if="is_bottom">
  20. <text>{{config.bottom_title||'到底了!'}}</text>
  21. </view>
  22. </view>
  23. </scroll-view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. config: {},
  32. user: {},
  33. list: [],
  34. total: 0,
  35. skip: 0,
  36. limit: 15,
  37. page: 0,
  38. // 数据是否触底
  39. is_bottom: false,
  40. scrollTop: 0,
  41. // 字典表
  42. typeList: []
  43. }
  44. },
  45. onLoad: async function(e) {
  46. const that = this;
  47. that.searchToken();
  48. that.searchConfig();
  49. await that.searchOther();
  50. },
  51. onShow: async function() {
  52. const that = this;
  53. that.clearPage();
  54. await that.search();
  55. },
  56. onPullDownRefresh: async function() {
  57. const that = this;
  58. that.clearPage();
  59. await that.search();
  60. uni.stopPullDownRefresh();
  61. },
  62. methods: {
  63. searchToken() {
  64. const that = this;
  65. try {
  66. const res = uni.getStorageSync('token');
  67. if (res) that.$set(that, `user`, res);
  68. } catch (e) {
  69. uni.showToast({
  70. title: err.errmsg,
  71. icon: 'error',
  72. duration: 2000
  73. });
  74. }
  75. },
  76. searchConfig() {
  77. const that = this;
  78. try {
  79. const res = uni.getStorageSync('config');
  80. if (res) that.$set(that, `config`, res);
  81. } catch (e) {
  82. uni.showToast({
  83. title: err.errmsg,
  84. icon: 'error',
  85. duration: 2000
  86. });
  87. }
  88. },
  89. async search() {
  90. const that = this;
  91. let info = {
  92. skip: that.skip,
  93. limit: that.limit,
  94. is_use: '0'
  95. }
  96. const res = await that.$api(`/news`, 'GET', {
  97. ...info,
  98. ...that.searchInfo
  99. })
  100. if (res.errcode == '0') {
  101. let list = [...that.list, ...res.data];
  102. for (let val of list) {
  103. const type = that.typeList.find(i => i.value == val.type)
  104. if (type) val.zhType = type.label
  105. }
  106. that.$set(that, `list`, list)
  107. that.$set(that, `total`, res.total)
  108. } else {
  109. uni.showToast({
  110. title: res.errmsg,
  111. });
  112. }
  113. },
  114. // 查看详情
  115. toInfo(item) {
  116. uni.navigateTo({
  117. url: `/pagesHome/news/detail?id=${item.id||item._id}`
  118. })
  119. },
  120. // 查询其他信息
  121. async searchOther() {
  122. const that = this;
  123. let res;
  124. // 查询类型
  125. res = await that.$api(`/dictData`, 'GET', {
  126. type: 'news_type',
  127. is_use: '0',
  128. })
  129. if (res.errcode == '0') that.$set(that, `typeList`, res.data);
  130. },
  131. // 分页
  132. toPage(e) {
  133. const that = this;
  134. let list = that.list;
  135. let limit = that.limit;
  136. if (that.total > list.length) {
  137. uni.showLoading({
  138. title: '加载中',
  139. mask: true
  140. })
  141. let page = that.page + 1;
  142. that.$set(that, `page`, page)
  143. let skip = page * limit;
  144. that.$set(that, `skip`, skip)
  145. that.search();
  146. uni.hideLoading();
  147. } else that.$set(that, `is_bottom`, true)
  148. },
  149. toScroll(e) {
  150. const that = this;
  151. let up = that.scrollTop;
  152. that.$set(that, `scrollTop`, e.detail.scrollTop);
  153. let num = Math.sign(up - e.detail.scrollTop);
  154. if (num == 1) that.$set(that, `is_bottom`, false);
  155. },
  156. // 清空列表
  157. clearPage() {
  158. const that = this;
  159. that.$set(that, `list`, [])
  160. that.$set(that, `skip`, 0)
  161. that.$set(that, `limit`, 15)
  162. that.$set(that, `page`, 0)
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .main {
  169. display: flex;
  170. flex-direction: column;
  171. width: 100vw;
  172. height: 100vh;
  173. .one {
  174. position: relative;
  175. flex-grow: 1;
  176. background-color: var(--f9Color);
  177. padding: 2vw 0 0 0;
  178. .list {
  179. background-color: var(--mainColor);
  180. border: 1px solid var(--f5Color);
  181. padding: 2vw;
  182. margin: 2vw 2vw 0 2vw;
  183. border-radius: 5px;
  184. .list_1 {
  185. padding: 2vw;
  186. font-weight: bold;
  187. font-size: var(--font16Size);
  188. }
  189. .list_2 {
  190. padding: 2vw;
  191. font-size: var(--font12Size);
  192. .time {
  193. padding: 0 0 2px 0;
  194. text {
  195. color: var(--f85Color);
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. .scroll-view {
  203. position: absolute;
  204. top: 0;
  205. left: 0;
  206. right: 0;
  207. bottom: 0;
  208. .list-scroll-view {
  209. display: flex;
  210. flex-direction: column;
  211. }
  212. }
  213. .is_bottom {
  214. width: 100%;
  215. text-align: center;
  216. text {
  217. padding: 2vw 0;
  218. display: inline-block;
  219. color: var(--f85Color);
  220. font-size: var(--font14Size);
  221. }
  222. }
  223. </style>