uni-app 149我的朋友圈分页列表实现

简介: uni-app 149我的朋友圈分页列表实现


下图是我测试的截图

/pages/find/moments/moments.vue

<template>
  <view>
    <free-transparent-bar :scrollTop="scrollTop" @clickRight="clickRight"></free-transparent-bar>
    <view class="position-relative" style="height: 620rpx;">
      <image src="https://douyinzcmcss.oss-cn-shenzhen.aliyuncs.com/shengchengqi/datapic/1.jpg" mode="aspectFill" style="height: 590rpx;" class="bg-secondary w-100"></image>
      <image :src="user.avatar || '/static/images/demo/demo6.jpg'" style="width: 120rpx;height:120rpx;right: 30rpx;" mode="" class="bg-secondary rounded position-absolute bottom-0"></image>
      <text class="text-white font-md position-absolute" style="bottom: 45rpx;right: 160rpx">{{user.nickname || user.username}}</text>
    </view>
    
    <!-- 朋友圈列表样式 -->
    <free-moment-list v-for="(item,index) in list" :key='index' :item="item" :index="index" @action="doAction"></free-moment-list>
    
    <!-- 评论框 -->
    <free-popup ref="action" bottom transformOrigin="center bottom">
      <view style="height: 105rpx;" class="bg-light border-top flex align-center">
        <textarea fixed class="bg-white rounded p-2 font-md" style="height: 75rpx;width: 520rpx;" value="" placeholder=""  v-model="content" :focus="true"/>
        <free-icon-button @click="changeFaceModeal"><text class="iconfont font-lg">&#xe605;</text></free-icon-button>
        <free-main-button name="发送" :disabled="content.length===0" @click="send"></free-main-button>
      </view>
      
      <!-- 表情包 -->
      <scroll-view v-if="faceModal" scroll-y="true" style="height: 350rpx;" class="bg-light flex flex-wrap">
        <view class="flex align-center justify-center" hover-class="bg-white" style="width:107rpx;height:107rpx;" v-for="(item,index) in faceList" :key="index" @click="addFace(item)">
          <text>{{item}}</text>
        </view>
      </scroll-view>
    </free-popup>
    
    <!-- 上拉加载 -->
    <view class="flex align-center justify-center py-5 bg-light" v-if="list.length >= 10">
      <text class="text-muted font">{{loadmore}}</text>
    </view>
  </view>
</template>
<script>
  import freeTransparentBar from '@/components/free-ui/free-transparent-bar.vue';
  import freeMomentList from '@/components/free-ui/free-moment-list.vue';
  import freePopup from '@/components/free-ui/free-popup.vue';
  import freeIconButton from '@/components/free-ui/free-icon-button.vue';
  import freeMainButton from '@/components/free-ui/free-main-button.vue';
  import $H from '@/common/free-lib/request.js';
  import { mapState } from 'vuex';
  export default {
    components:{
      freeTransparentBar,
      freeMomentList,
      freePopup,
      freeIconButton,
      freeMainButton
    },
    data() {
      return {
        content:'',
        scrollTop:0,
        faceModal:false,
        faceList:["😀","😁","😂","😃","😄","😅","😆","😉","😊","😋","😎","😍","😘","😗","😙","😚","😇","😐","😑","😶","😏","😣","😥","😮","😯","😪","😫","😴","😌","😛","😜","😝","😒","😓","😔","😕","😲","😷","😖","😞","😟","😤","😢","😭","😦","😧","😨","😬","😰","😱","😳","😵","😡","😠"],
        commentIndex:-1,
        page:1,
        loadmore:'上拉加载更多',
        key:'moment_timeline',
        list:[],
      }
    },
    onPageScroll(e) {
      this.scrollTop = e.scrollTop;
    },
    onReachBottom() {
      if(this.loadmore !== '上拉加载更多'){
        return;
      }
      this.page += 1;
      this.loadmore = '加载中...';
      this.getData().catch(err=>{
        this.page -= 1;
        uni.showToast({
          title:'加载失败',
          icon:'none'
        });
        this.loadmore = '上拉加载更多';
      })
    },
    onLoad(e) {
      if(e.key){
        this.key  = e.key;
      }
      this.page = 1;
      this.getData();
    },
    onPullDownRefresh() {
      this.page = 1;
      this.getData().then(res=>{
        uni.showToast({
          title:'刷新成功',
          icon:'none'
        });
        uni.stopPullDownRefresh();
      }).catch(err=>{
        uni.showToast({
          title:'刷新失败',
          icon:'none'
        });
        uni.stopPullDownRefresh();
      });
    },
    computed:{
      ...mapState({
        user:state=>state.user.user
      })
    },
    methods: {
      // 点击操作菜单
      doAction(e){
        uni.showActionSheet({
          itemList: ['点赞','评论'],
          success: res => {
            if(res.tapIndex === 0){
              // 点赞
              this.doSupport(e)
            }else{
              this.content='';
              this.faceModal=false;
              this.commentIndex = e.index;
              this.$refs.action.show();
              // this.doComment(e)
            }
          }
        });
      },
      // 获取数据
      getData(){
        return new Promise((result,reject)=>{
          let page = this.page;
          $H.get('/'+this.key+'/'+page).then(res=>{
            this.list = page === 1 ? res : [...this.list,...res];
            this.loadmore = this.list.length === (page * 10) ? '上拉加载更多' : '没有更多了'
            result(res);
          }).catch(err=>{
            reject(err);
          })
        })
      },
      // 点赞
      doSupport(e){
        e.item.supports.push({
            id:1,
            username:'昵称',
            avatar:'/static/image/demo/demo6.jpg'
        });
      },
      // 添加表情
      addFace(item){
        this.content += item;
      },
      // 开启关闭表情包面板
      changeFaceModeal(){
        uni.hideKeyboard();
        setTimeout(()=>{
          this.faceModal = !this.faceModal;
        },100);
      },
      // 发送
      send(){
        this.list[this.commentIndex].comments.push({
          id:1,
          username:'昵称',
          content:this.content
        })
        this.$refs.action.hide();
      },
      // 选择发表朋友圈类型
      clickRight(){
        let list = [{
          name:'图文',
          key:'image'
        },
        {
          name:'视频',
          key:'video'
        },
        {
          name:'文字',
          key:'text'
        }];
        uni.showActionSheet({
          itemList:list.map(v=>v.name),
          success:res=>{
            uni.navigateTo({
              url: '../add-moment/add-moment?type='+list[res.tapIndex].key,
            });
          }
        })
      }
    },
  }
</script>
<style>
</style>

/pages/tabbar/my/my.vue

<template>
  <view class="page">
    <free-nav-bar bgColor="bg-white">
      <free-icon-button slot="right"><text class="iconfont font-md">&#xe6ed;</text></free-icon-button>
    </free-nav-bar>
    
    <free-list-item :cover="user.avatar ? user.avatar : '/static/images/userpic.png'" :title="nickname" showRight coverSize="120" @click="open('my/userinfo/userinfo')">
      <view class="flex flex-column">
        <text class="text-dark font-lg font-weight-bold">{{nickname}}</text>
        <text class="text-light-muted font-md">微信号:{{user.username}}</text>
      </view>
      <view slot="right">
        <text class="iconfont font-md text-light-muted">&#xe614;</text>
      </view>
    </free-list-item>
    
    <free-divider></free-divider>
    <free-list-item title="支付" showRight>
      <text slot="icon" class="iconfont font-lg py-1">&#xe66c;</text>
    </free-list-item>
    
    <free-divider></free-divider>
    <free-list-item title="收藏" @click="open('my/fava/fava')" showRight>
      <text slot="icon" class="iconfont font-lg py-1">&#xea2d;</text>
    </free-list-item>
    <free-list-item title="相册"  @click="open('find/moments/moments?key=moment')" showRight>
      <text slot="icon" class="iconfont font-lg py-1">&#xe608;</text>
    </free-list-item>
    <free-list-item title="表情" showRight>
      <text slot="icon" class="iconfont font-lg py-1">&#xe605;</text>
    </free-list-item>
    <free-list-item title="设置" showRight @click="open('my/setting/setting')">
      <text slot="icon" class="iconfont font-lg py-1">&#xe612;</text>
    </free-list-item>
  </view>
</template>
<script>
  import freeNavBar from "@/components/free-ui/free-nav-bar.vue";
  import freeIconButton from "@/components/free-ui/free-icon-button.vue";
  import freeListItem from "@/components/free-ui/free-list-item.vue";
  import freeDivider from "@/components/free-ui/free-divider.vue";
  import auth from '@/common/mixin/auth.js';
  import { mapState } from 'vuex';
  export default {
    mixins:[auth],
    components:{
      freeNavBar,
      freeIconButton,
      freeListItem,
      freeDivider
    },
    data() {
      return {
        
      }
    },
    computed:{
      ...mapState({
        user:state=>state.user.user,
      }),
      nickname(){
        return this.user.nickname ? this.user.nickname : this.user.username;
      }
    },
    methods: {
      open(path){
        uni.navigateTo({
          url:'/pages/'+path,
        })
      }
    }
  }
</script>
<style>
</style>

感谢大家观看,我们下次见

目录
相关文章
|
11月前
uni-app 172标签列表和标签用户列表
uni-app 172标签列表和标签用户列表
98 1
|
11月前
uni-app 155朋友圈评论功能(二)
uni-app 155朋友圈评论功能(二)
164 0
|
2月前
|
Dart 前端开发 Android开发
【09】flutter首页进行了完善-采用android studio 进行真机调试开发-增加了直播间列表和短视频人物列表-增加了用户中心-卓伊凡换人优雅草Alex-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
【09】flutter首页进行了完善-采用android studio 进行真机调试开发-增加了直播间列表和短视频人物列表-增加了用户中心-卓伊凡换人优雅草Alex-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
74 4
【09】flutter首页进行了完善-采用android studio 进行真机调试开发-增加了直播间列表和短视频人物列表-增加了用户中心-卓伊凡换人优雅草Alex-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
|
4月前
|
存储 监控 API
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
289 11
|
5月前
【Azure App Service】PowerShell脚本批量添加IP地址到Web App允许访问IP列表中
Web App取消公网访问后,只允许特定IP能访问Web App。需要写一下段PowerShell脚本,批量添加IP到Web App的允许访问IP列表里!
|
6月前
|
JavaScript 小程序 开发者
uni-app开发实战:利用Vue混入(mixin)实现微信小程序全局分享功能,一键发送给朋友、分享到朋友圈、复制链接
uni-app开发实战:利用Vue混入(mixin)实现微信小程序全局分享功能,一键发送给朋友、分享到朋友圈、复制链接
1036 0
|
10月前
|
搜索推荐
App Inventor 2 列表排序,函数式编程轻松实现高级排序算法
本文探讨了列表的函数式编程高级用法,允许根据自定义逻辑进行排序。不仅支持基本数据类型(文本和数字)的升序和降序排序,还能处理复杂结构类型中特定元素的排序。通过示例展示了如何定义比较函数来实现升序和降序,简化了排序操作。
127 0
|
11月前
|
移动开发 前端开发
uni-app 180查看好友朋友圈完善(一)
uni-app 180查看好友朋友圈完善(一)
65 3
|
11月前
uni-app 182查看好友朋友圈完善(三)
uni-app 182查看好友朋友圈完善(三)
45 3
|
11月前
|
移动开发 前端开发
uni-app 184查看好友朋友圈完善(五)
uni-app 184查看好友朋友圈完善(五)
47 2

热门文章

最新文章

下一篇
oss创建bucket