index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. if (!that.user._id) return
  83. let info = {
  84. skip: that.skip,
  85. limit: that.limit,
  86. is_use: '0'
  87. }
  88. const res = await that.$api(`/notice`, 'GET', {
  89. ...info,
  90. ...that.searchInfo
  91. })
  92. if (res.errcode == '0') {
  93. let list = [...that.list, ...res.data];
  94. that.$set(that, `list`, list)
  95. that.$set(that, `total`, res.total)
  96. } else {
  97. uni.showToast({
  98. title: res.errmsg,
  99. });
  100. }
  101. },
  102. // 查看详情
  103. toInfo(item) {
  104. uni.navigateTo({
  105. url: `/pagesHome/notice/detail?id=${item.id||item._id}`
  106. })
  107. },
  108. // 分页
  109. toPage(e) {
  110. const that = this;
  111. let list = that.list;
  112. let limit = that.limit;
  113. if (that.total > list.length) {
  114. uni.showLoading({
  115. title: '加载中',
  116. mask: true
  117. })
  118. let page = that.page + 1;
  119. that.$set(that, `page`, page)
  120. let skip = page * limit;
  121. that.$set(that, `skip`, skip)
  122. that.search();
  123. uni.hideLoading();
  124. } else that.$set(that, `is_bottom`, true)
  125. },
  126. toScroll(e) {
  127. const that = this;
  128. let up = that.scrollTop;
  129. that.$set(that, `scrollTop`, e.detail.scrollTop);
  130. let num = Math.sign(up - e.detail.scrollTop);
  131. if (num == 1) that.$set(that, `is_bottom`, false);
  132. },
  133. // 清空列表
  134. clearPage() {
  135. const that = this;
  136. that.$set(that, `list`, [])
  137. that.$set(that, `skip`, 0)
  138. that.$set(that, `limit`, 15)
  139. that.$set(that, `page`, 0)
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .main {
  146. display: flex;
  147. flex-direction: column;
  148. width: 100vw;
  149. height: 100vh;
  150. .one {
  151. position: relative;
  152. flex-grow: 1;
  153. background-color: var(--f9Color);
  154. padding: 2vw 0 0 0;
  155. .list {
  156. background-color: var(--mainColor);
  157. border: 1px solid var(--f5Color);
  158. padding: 2vw;
  159. margin: 2vw 2vw 0 2vw;
  160. border-radius: 5px;
  161. .list_1 {
  162. padding: 2vw;
  163. font-weight: bold;
  164. font-size: var(--font16Size);
  165. }
  166. .list_2 {
  167. padding: 2vw;
  168. font-size: var(--font12Size);
  169. text-align: right;
  170. .time {
  171. padding: 0 0 2px 0;
  172. text {
  173. color: var(--f85Color);
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }
  180. .scroll-view {
  181. position: absolute;
  182. top: 0;
  183. left: 0;
  184. right: 0;
  185. bottom: 0;
  186. .list-scroll-view {
  187. display: flex;
  188. flex-direction: column;
  189. }
  190. }
  191. .is_bottom {
  192. width: 100%;
  193. text-align: center;
  194. text {
  195. padding: 2vw 0;
  196. display: inline-block;
  197. color: var(--f85Color);
  198. font-size: var(--font14Size);
  199. }
  200. }
  201. </style>