question.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="pages">
  3. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  4. <view class="questions wrap40">
  5. <view class="questions-item" v-for="(item,index) in questionlist" :key="index">
  6. <view class="questions-item-til">
  7. <image :src="$getimg + 'icon-questions.png'" class="questions-item-img" mode="scaleToFill"></image>
  8. <view class="questions-item-text">{{index+1}}.{{item.problemName}}</view>
  9. </view>
  10. <view class="questions-item-con">{{item.problemAnswer}}</view>
  11. </view>
  12. </view>
  13. </mescroll-body>
  14. </view>
  15. </template>
  16. <script>
  17. // 引入mescroll-mixins.js
  18. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  19. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  20. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  21. export default {
  22. mixins: [MescrollMixin], // 使用mixin
  23. components: {
  24. MescrollBody,
  25. },
  26. data() {
  27. return {
  28. $getimg:this.$getimg,
  29. params:{},
  30. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  31. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  32. downOption: {
  33. // ...
  34. },
  35. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  36. upOption: {
  37. page: {
  38. size: 10 // 每页数据的数量,默认10
  39. },
  40. noMoreSize: 3, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  41. empty: {
  42. tip: '暂无相关数据'
  43. }
  44. },
  45. questionlist:[],
  46. }
  47. },
  48. onShow() {
  49. this.token = this.$store.state.token;
  50. },
  51. onLoad() {
  52. let self = this;
  53. uni.getStorage({
  54. key:'token',
  55. success: function (res) {
  56. self.token = res.data;
  57. // console.log(res.data);
  58. }
  59. });
  60. uni.getStorage({
  61. key:'tokenhead',
  62. success: function (res) {
  63. self.tokenhead = res.data;
  64. // console.log(res.data);
  65. }
  66. });
  67. },
  68. methods: {
  69. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  70. mescrollInit(mescroll) {
  71. this.mescroll = mescroll;
  72. },
  73. /*下拉刷新的回调, 有三种处理方式:*/
  74. downCallback(){
  75. // 第2种: 下拉刷新和上拉加载调同样的接口, 那么不用第1种方式, 直接mescroll.resetUpScroll()即可
  76. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  77. },
  78. /*上拉加载的回调*/
  79. upCallback(page) {
  80. let pageNum = page.num; // 页码, 默认从1开始
  81. let pageSize = page.size; // 页长, 默认每页10条
  82. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  83. let thetoken = 'Bearer ' + this.token;
  84. // console.log('thetoken',thetoken);
  85. this.$api.http.post(this.config.apiBaseurl + '/carbon-h5/carbon/problem/list',this.params,{
  86. header: {
  87. Accept:'application/json',
  88. Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  89. },
  90. }).then(data => {
  91. // console.log(data);
  92. // 接口返回的当前页数据列表 (数组)
  93. let curPageData = data.data.retBody;
  94. // console.log('curPageData',curPageData);
  95. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  96. let curPageLen = curPageData.length;
  97. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  98. // let totalPage = data.xxx;
  99. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  100. let totalSize = data.data.retHead.total;
  101. // this.mescrollList = curPageData;
  102. // 接口返回的是否有下一页 (true/false)
  103. // let hasNext = data.xxx;
  104. //设置列表数据
  105. if(page.num == 1) this.questionlist = []; //如果是第一页需手动置空列表
  106. this.questionlist = this.questionlist.concat(curPageData); //追加新数据
  107. // console.log('page.num',page.num);
  108. console.log('this.questionlist',JSON.parse(JSON.stringify(this.questionlist)));
  109. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  110. this.mescroll.endBySize(curPageLen, totalSize);
  111. // setTimeout(()=>{
  112. // this.mescroll.endSuccess(curPageLen)
  113. // },20)
  114. }).catch(err => {
  115. this.mescroll.endErr()
  116. console.log(err)
  117. });
  118. },
  119. }
  120. }
  121. </script>
  122. <style>
  123. @import url("./question.css");
  124. </style>