index.vue 4.4 KB

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