综合办公系统
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.

mescroll-uni-part.vue 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <!-- mescroll-uni本质是scroll-view,支持局部区域滚动,可使用flex布局灵活的嵌在某个view中, 而mescroll-body只能靠fixed定位其他元素变相实现'局部滚动' -->
  3. <view class="page-warp">
  4. <view class="top-warp">
  5. <view>顶部区域</view>
  6. <view style="font-size: 24rpx;">mescroll-uni 支持局部区域滚动,支持使用flex嵌在某个view</view>
  7. </view>
  8. <view class="center-warp">
  9. <!-- 左边 -->
  10. <scroll-view class="left-warp" :scroll-y="true">
  11. <view class="tab" :class="{active:i==tabIndex}" v-for="(tab,i) in tabs" :key="i" @click="tabChange(i)">{{tab}}</view>
  12. </scroll-view>
  13. <view class="right-warp">
  14. <!--右边 :fixed="false", 高度跟随父元素 (不在组件上定义class,避免部分小程序平台编译丢失, 如支付宝,钉钉小程序) -->
  15. <mescroll-uni :fixed="false" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
  16. <good-list :list="goods"></good-list>
  17. </mescroll-uni>
  18. </view>
  19. </view>
  20. <view class="bottom-warp"> 底部区域 </view>
  21. </view>
  22. </template>
  23. <script>
  24. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  25. import {apiSearch} from "@/api/mock.js"
  26. export default {
  27. mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
  28. data() {
  29. return {
  30. goods: [], // 数据列表
  31. tabs: ['全部', '奶粉', '面膜', '图书', '果汁', '奶瓶', '美素', '花王', '韩蜜', '口红', '毛巾', '玩具', '衣服'],
  32. tabIndex: 0 // tab下标
  33. }
  34. },
  35. methods: {
  36. upCallback(page) {
  37. //联网加载数据
  38. let keyword = this.tabs[this.tabIndex]
  39. apiSearch(page.num, page.size, keyword).then(curPageData=>{
  40. //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
  41. this.mescroll.endSuccess(curPageData.length);
  42. //设置列表数据
  43. if(page.num == 1) this.goods = []; //如果是第一页需手动制空列表
  44. this.goods=this.goods.concat(curPageData); //追加新数据
  45. }).catch(()=>{
  46. //联网失败, 结束加载
  47. this.mescroll.endErr();
  48. })
  49. },
  50. // 切换菜单
  51. tabChange(i){
  52. if(this.tabIndex != i){
  53. this.tabIndex = i
  54. this.goods = []; // 先置空列表,显示加载进度条
  55. this.mescroll.resetUpScroll(); // 重置列表数据
  56. }
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="scss">
  62. /*根元素需要有固定的高度*/
  63. page{
  64. height: 100%;
  65. // 支付宝小程序,钉钉小程序需添加绝对定位,否则height:100%失效: https://opendocs.alipay.com/mini/framework/acss#%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98
  66. /* #ifdef MP-ALIPAY || MP-DINGTALK*/
  67. position: absolute;
  68. top: 0;
  69. left: 0;
  70. width: 100%;
  71. /* #endif */
  72. /*需给父元素设置height:100%*/
  73. .page-warp{
  74. height: 100%;
  75. display: flex;
  76. flex-direction: column;
  77. /* 顶部区域 */
  78. .top-warp{
  79. font-size: 28rpx;
  80. padding: 20rpx;
  81. text-align: center;
  82. background-color: #CFE0DA;
  83. }
  84. /* 中间 */
  85. .center-warp{
  86. flex: 1;
  87. min-width: 0;
  88. min-height: 0;/* 需给flex:1的元素加上最小高,否则内容超过会溢出容器 (如:小程序Android真机) */
  89. border: 4px solid red;
  90. display: flex;
  91. // 左边
  92. .left-warp{
  93. width: 180rpx;
  94. height: 100%;
  95. background-color: #eee;
  96. .tab{
  97. font-size: 28rpx;
  98. padding: 28rpx;
  99. &.active{
  100. background-color: #fff;
  101. }
  102. }
  103. }
  104. // 右边
  105. .right-warp{
  106. flex: 1;
  107. min-width: 0;
  108. }
  109. }
  110. /* 底部区域 */
  111. .bottom-warp{
  112. padding: 20rpx;
  113. text-align: center;
  114. background-color: #FF6990;
  115. }
  116. }
  117. }
  118. </style>