综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xinlang.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view>
  3. <!-- 模拟的标题 -->
  4. <image class="header" src="https://www.mescroll.com/img/xinlang/header.jpg" mode="aspectFit"/>
  5. <view :style="{'top':top}" class="download-tip">1条新微博</view>
  6. <mescroll-body-diy ref="mescrollRef" @init="mescrollInit" top="100" bottom="100" :down="downOption" @down="downCallback" @up="upCallback">
  7. <!-- 新增的微博 -->
  8. <view class="news-li" v-for="news in addList" :key="news.id">
  9. <view>{{news.title}}</view>
  10. <view class="new-content">{{news.content}}</view>
  11. </view>
  12. <!-- 模拟的内容 -->
  13. <image src="https://www.mescroll.com/img/xinlang/xinlang1.jpg" mode="widthFix"/>
  14. <!-- 分页的数据 -->
  15. <view class="news-li" v-for="news in dataList" :key="news.id">
  16. <view>{{news.title}}</view>
  17. <view class="new-content">{{news.content}}</view>
  18. </view>
  19. </mescroll-body-diy>
  20. <!-- 模拟的底部 -->
  21. <image class="footer" src="https://www.mescroll.com/img/xinlang/footer.jpg" mode="aspectFit"/>
  22. </view>
  23. </template>
  24. <script>
  25. import MescrollBodyDiy from "@/components/mescroll-diy/xinlang/mescroll-body.vue";
  26. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  27. import {apiWeiboList} from "@/api/mock.js"
  28. export default {
  29. mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
  30. components: {
  31. MescrollBodyDiy, // 避免与main.js注册的全局组件名称相同,否则注册组件失效(iOS真机 APP HBuilderX2.7.9)
  32. },
  33. data() {
  34. return {
  35. downOption:{
  36. auto:false,//是否在初始化完毕之后自动执行下拉回调callback; 默认true
  37. },
  38. addList:[],//新增微博
  39. dataList: [], // 数据列表
  40. top: 0 //提示,到顶部的距离
  41. }
  42. },
  43. methods: {
  44. /*下拉刷新的回调 */
  45. downCallback(){
  46. //加载轮播数据..
  47. //...
  48. //加载列表数据
  49. apiWeiboList().then(curPageData=>{
  50. //联网成功的回调,隐藏下拉刷新的状态
  51. this.mescroll.endSuccess();
  52. //添加新数据到顶部
  53. this.addList.unshift(curPageData[0]);
  54. //显示提示
  55. // #ifdef H5
  56. this.top=uni.upx2px(100+88)+"px"; // H5的高度需加上 88的标题栏
  57. // #endif
  58. // #ifndef H5
  59. this.top=uni.upx2px(100)+"px"; // 非H5不必加
  60. // #endif
  61. setTimeout(()=> {
  62. this.top=0;
  63. },2000);
  64. }).catch(()=>{
  65. //联网失败, 结束加载
  66. this.mescroll.endErr();
  67. })
  68. },
  69. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  70. upCallback(page) {
  71. //联网加载数据
  72. apiWeiboList(page.num, page.size).then(curPageData=>{
  73. //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
  74. this.mescroll.endSuccess(curPageData.length);
  75. //追加新数据
  76. this.dataList=this.dataList.concat(curPageData);
  77. }).catch(()=>{
  78. //联网失败, 结束加载
  79. this.mescroll.endErr();
  80. })
  81. }
  82. }
  83. }
  84. </script>
  85. <style>
  86. image{width: 100%;vertical-align: bottom;height:auto}
  87. .header{z-index: 9900;position: fixed;top: --window-top;left: 0;height: 100upx;background: #fff;}
  88. .footer{z-index: 9900;position: fixed;bottom: 0;left: 0;height: 100upx;background: white;}
  89. .download-tip{
  90. z-index: 900;
  91. position: fixed;
  92. top: calc(var(--window-top) + 20upx);
  93. left: 0;
  94. width: 100%;
  95. height: 60upx;
  96. line-height: 60upx;
  97. font-size: 24upx;
  98. text-align: center;
  99. background-color: rgba(255,130,1,.7);
  100. color: white;
  101. -webkit-transition: top 300ms;
  102. transition: top 300ms;
  103. }
  104. /*展示上拉加载的数据列表*/
  105. .news-li{
  106. padding: 32upx;
  107. border-bottom: 1upx solid #eee;
  108. }
  109. .news-li .new-content{
  110. font-size: 28upx;
  111. margin-top: 10upx;
  112. margin-left: 20upx;
  113. color: #666;
  114. }
  115. </style>