123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <template>
-
- <mescroll-body ref="mescrollRef" bottom="50%" @init="mescrollInit" :down="downOption" @down="downCallback" :up="upOption">
-
- <view v-if="isEnd" class="msg-end">没有更多消息了</view>
-
-
- <view class="msg" v-for="msg in msgList" :key="msg.id" :id="msg.VIEW_ID" :class="[msg.id%2==0 ? 'right' : 'left']">
- <view class="msg-warp">
- <view class="msg-title">{{msg.title}}</view>
- <view class="msg-content">{{msg.content}}</view>
- </view>
- </view>
- </mescroll-body>
- </template>
- <script>
- import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
- import {apiMsgList} from "@/api/mock.js"
-
- export default {
- mixins: [MescrollMixin],
- data() {
- return {
- downOption:{
- autoShowLoading: true,
- textColor: "#FF8095"
- },
- upOption: {
- use: false,
- toTop: {
- src: ''
- }
- },
- pageNum: 1,
- pageSize: 10,
- isEnd: false,
- msgList: []
- }
- },
- methods: {
-
- downCallback() {
-
- apiMsgList(this.pageNum, this.pageSize).then(data => {
-
- this.pageNum ++;
-
- this.mescroll.endSuccess();
-
- if(data.length < this.pageSize){
- this.isEnd = true;
- this.mescroll.lockDownScroll(true);
- }
-
- data.forEach(val=>{
- val.VIEW_ID = "msg" + val.id
- })
-
-
- let topMsg = this.msgList[0]
-
-
- this.msgList = data.concat(this.msgList);
-
- this.$nextTick(()=>{
- if(this.pageNum <= 2){
-
- this.mescroll.scrollTo(99999, 0)
- }else if(topMsg){
-
- let view = uni.createSelectorQuery().select('#'+topMsg.VIEW_ID);
- view.boundingClientRect(v => {
- console.log("节点离页面顶部的距离=" + v.top);
- this.mescroll.scrollTo(v.top - 100, 0)
- }).exec();
- }
- })
-
- }).catch(()=>{
- this.pageNum --;
- this.mescroll.endErr();
- })
- }
- }
- }
- </script>
- <style lang="scss">
- /* 无更多消息 */
- .msg-end{
- padding: 40rpx 0;
- font-size: 24rpx;
- text-align: center;
- color: #FF8095;
- }
- /*消息列表*/
- .msg{
- margin: 30rpx;
- &.right{
- text-align: right;
- }
- &.left{
- text-align: left;
- }
- .msg-warp{
- width: 50%;
- display: inline-block;
- padding: 30rpx;
- border-radius: 30rpx;
- background-color: #FF8095;
- color: #fff;
- .msg-title{
- margin-left: -12rpx;
- font-size: 32rpx;
- text-align: left;
- }
- .msg-content{
- font-size: 26rpx;
- margin-top: 10rpx;
- text-align: left;
- }
- }
- }
- </style>
|