uni-app 14通讯录索引列功能

简介: uni-app 14通讯录索引列功能


这一块主要讲了,微信通讯录右边的音文字母的联动效果

mail.nvue

<template>
  <view>
    <!-- 导航栏 -->
    <free-nav-bar title="通讯录"></free-nav-bar>
    <!-- 通讯录列表 -->
      <scroll-view scroll-y="true" :style="'height:'+scrollHeight+'px;'"  :scroll-into-view="scrollInto">
        <free-list-item v-for="(item,index) in topList" :key="index"  :title="item.title" :cover="item.cover" @click=""></free-list-item>
        
        <view v-for="(item,index) in list" :key="index" v-if="item.data.length>0" :id="'item-'+item.letter">
          <view class="py-2 px-3 border-bottom bg-light">
            <text class="font-md text-dark">{{item.letter}}</text>
          </view>
          <free-list-item v-for="(item2,index2) in item.data" :key="index2"  :title="item2" cover="/static/images/mail/friend.png" @click=""></free-list-item>
        </view>
      </scroll-view>
      <!-- 侧边导航条 -->
      <view class="position-fixed right-0 bottom-0 flex  flex-column" :style="'top:'+top+'rpx;'" style="width: 50rpx;" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend" >
        <view class="flex-1 flex align-center justify-center" v-for="(item,index) in list" :key="index">
          <text class="font-sm text-muted">{{item.letter}}</text>
        </view>
      </view>
      
      <!-- <block v-if="current"> -->
      <view class="position-fixed rounded-circle bg-light border flex align-center justify-center" style="width: 150rpx;height: 150rpx; left: 300rpx;" :style="'top:'+modalTop+'px;'" v-if="current!=''">
        <text class="font-lg" >{{current}}</text>
      </view>
      <!-- </block> -->
  </view>
</template>
<script>
  import freeNavBar from "@/components/free-ui/free-nav-bar.vue";
  import freeListItem from '@/components/free-ui/free-list-item.vue';
  export default {
    components:{
      freeNavBar,
      freeListItem
    },
    computed:{
      modalTop(){
        return (this.scrollHeight-uni.upx2px(150))/2;
      },
      itemHeight(){
        let count = this.list.length;
        if(count<1){
          return 0;
        }
        return this.scrollHeight/count;
      }
    },
    onLoad() {
      let res = uni.getSystemInfoSync();
      this.top = res.statusBarHeight + uni.upx2px(90);
      this.scrollHeight = res.windowHeight-this.top;
    },
    data() {
      return {
        scrollInto:'',
        top:0,
        scrollHeight:0,
        current:'',
        topList:[
          {
            title:"新的朋友",
            cover:"/static/images/mail/friend.png",
            event:""
          },
          {
            title:"群聊",
            cover:"/static/images/mail/group.png",
            event:""
          },
          {
            title:"标签",
            cover:"/static/images/mail/tag.png",
            event:""
          }
        ],
        list:[{
          "letter":"A",
          "data":[
            "阿苏",
            "阿拉",
            "阿拉",
            "阿拉",
            "阿拉",
            "阿拉",
            "阿拉",
            "阿拉",
            "阿拉",
            "阿拉"
          ]
        },{
          "letter":"B",
          "data":[
            "baba",
            "霸占",
            "吧拉"
          ]
        },
        {
          "letter":"C",
          "data":[
            "吃好",
            "车霸占",
            "才吧拉"
          ]
        },
        {
          "letter":"D",
          "data":[
            "Dd",
            "dd",
            "滴滴滴"
          ]
        }]
      }
    },
    methods: {
      touchstart(e){
        this.changeScrollInto(e);
      },
      touchmove(e){
        this.changeScrollInto(e);
      },
      touchend(){
        this.current = '';
      },
      // 联动
      changeScrollInto(e){
        // let Y = e.touches[0].pageY;
        // let index = Math.floor(Y / this.itemHeight);
        // let item = this.list[index];
        // if(item){
        //  this.scrollInto = 'item-'+item.letter;
        //  this.current = item.letter;
        // }
        
        let Y = e.touches[0].pageY
      
        // #ifdef MP
          Y = Y - this.top
        // #endif
        
        let index = Math.floor(Y / this.itemHeight)
        let item = this.list[index]
        if(item){
          this.scrollInto = 'item-'+item.letter
          this.current = item.letter
        }
      }
    }
  }
</script>
<style>
</style>

所用到的插件

// free-nav-bar.vue
<template>
  <view>
    <view :class="getClass">
      <!-- 状态栏 -->
      <view :style="'height:'+statusBarHeight+'px;'"></view>
      <!-- 导航 -->
      <view class="w-100 flex align-center justify-between" style="height: 90rpx;">
        <!-- 左边 -->
        <view class="flex align-center">
          <!-- 返回按钮 -->
          <free-icon-button v-if="showBack" @click="back"><text class="iconfont font-md">&#xe60d;</text></free-icon-button>
          <!-- 标题 -->
          <text v-if="title" class="font-md ml-3" >{{getTitle}}</text>
        </view>
        <!-- 右边 -->
        <view class="flex align-center" v-if="showRight">
          <slot name="right">
            <free-icon-button @click="search"><text class="iconfont font-md">&#xe6e3;</text></free-icon-button>
            <free-icon-button @click="openExtend"><text class="iconfont font-md">&#xe682;</text></free-icon-button>
          </slot>
        </view>
        <!--\ue6e3 \ue682 -->
      </view>
    </view>
    <!-- 站位 -->
    <view v-if="fixed" :style="fixedStyle"></view>
    
    <!-- 扩展菜单  -->
    <free-popup v-if="showRight" ref="extend" maskColor bottom :bodyWidth="320" :bodyHeight="525" bodyBgColor="bg-dark" transformOrigin="right top">
      <view class="flex flex-column" style="width:320rpx;height: 525rpx;">
          <view v-for="(item,index) in menus" :key="index" class="flex-1 flex align-center" hover-class="bg-hover-dark" @click="clickEvent(item.event)">
            <text class="pl-3 pr-2 iconfont font-md text-white">{{item.icon}}</text>
            <text class="font-md text-white">{{item.name}}</text>
          </view>
      </view>
    </free-popup>
  </view>
</template>
<script>
  import freeIconButton from './free-icon-button.vue';
  import freePopup from './free-popup.vue';
  export default {
    components: {
      freeIconButton,
      freePopup
    },
    props: {
      showBack:{
        type:Boolean,
        default:false
      },
      title: {
        type: String,
        default: ''
      },
      fixed:{
        type:Boolean,
        default:false
      },
      noreadnum:{
        type:Number,
        default:0
      },
      bgColor:{
        type:String,
        default:"bg-light"
      },
      showRight:{
        type:Boolean,
        default:true
      }
    },
    data() {
      return {
        statusBarHeight: 0,
        navBarHeight: 0,
        menus:[
          {
            name:'发起群聊',
            event:"",
            icon:"\ue633"
          },
          {
            name:'添加好友',
            event:"",
            icon:"\ue65d"
          },
          {
            name:'扫一扫',
            event:"",
            icon:"\ue614"
          },
          {
            name:'收付款',
            event:"",
            icon:"\ue66c"
          },
          {
            name:'帮助与反馈',
            event:"",
            icon:"\ue61c"
          }
        ],
      }
    },
    mounted() {
      // 获取任务栏高度
      // #ifdef APP-PLUS-NVUE
      this.statusBarHeight = plus.navigator.getStatusbarHeight()
      // #endif
      this.navBarHeight = this.statusBarHeight + uni.upx2px(90)
    },
    computed: {
      fixedStyle() {
        return `height:${this.navBarHeight}px`;
      },
      getTitle(){
        let noreadnum = this.noreadnum>0 ? '('+this.noreadnum+')' : '';
        return this.title + noreadnum;
      },
      getClass(){
        let fixed = this.fixed?"fixed-top":"";
        return `${fixed} ${this.bgColor}`;
      }
    },
    methods:{
      openExtend(){
        this.$refs.extend.show(uni.upx2px(415),uni.upx2px(150));
      },
      // 返回
      back(){
        uni.navigateBack({
          delta:1
        })
      }
    }
  }
</script>
<style>
</style>
// free-list-item.vue
<template> 
  <view class="bg-white flex align-stretch" hover-class="bg-light" @click="$emit('click')">
    <view class="flex align-center justify-center py-2 pl-3" v-if="showLeftIcon">
      <slot name="icon"></slot> 
      <image :src="cover" v-if="cover" style="width: 75rpx;height: 75rpx;" mode="widthFix" :style="coverStyle"></image>
    </view>
    <view class="flex-1 flex align-center justify-between py-3 pl-3" :class="border ? 'border-bottom' : ''">
      <slot>
        <text class="font-md text-dark">{{title}}</text>
      </slot>
      <view class="flex align-center pr-3" v-if="showRight">
        <slot name="right"></slot>
        <!-- 右 -->
        <text class="iconfont text-light-muted font-md" v-if="showRightIcon" >&#xe60c;</text>
      </view>
    </view>
  </view>
</template>
<script>
  export default{
    props:{
      // 是否开启下边线
      border:{
        type:Boolean,
        default:true
      },
      // 封面
      cover:{
        type:String,
        default:""
      },
      // 标题
      title:{
        type:String,
        default:""
      },
      // 显示右边
      showRight:{
        type:Boolean,
        default:false
      },
      // 封面大小
      coverSize:{
        type:[String,Number],
        default:75
      },
      // 显示左边图标
      showLeftIcon:{
        type:Boolean,
        default:true
      },
      showRightIcon:{
        type:Boolean,
        default:true
      }
    },
    computed:{
      coverStyle(){
        return `width:${this.coverSize}rpx;height:${this.coverSize}rpx;`;
      }
    }
  }
</script>
<style>
</style>

界面是酱紫的

感谢大家观看,我们下期见。

目录
相关文章
|
小程序 视频直播 数据安全/隐私保护
如何在1v1视频直播交友APP中实现防录屏防截屏功能?
婚恋交友市场快速增长,1v1社交应用海外投放增86.49%,中东、东南亚及北美需求旺盛。用户偏好私密高效交流,国内“云相亲”兴起。开发需合规备案、实名认证,并防范诈骗。本文详解原生APP防录屏技术:Android通过MediaProjection检测,iOS监听UIScreen状态,结合动态水印、远程销毁等增强防护,平衡体验与安全。
|
移动开发 小程序 Android开发
基于 uni-app 开发的废品回收类多端应用功能与界面说明
本文将对一款基于 uni-app 开发的废品回收类多端应用,从多端支持范围、核心功能模块及部分界面展示进行客观说明,相关资源信息也将一并呈现。
463 0
|
JavaScript API 开发工具
如何在原生App中调用Uniapp的原生功能?
如何在原生App中调用Uniapp的原生功能?
1305 139
|
存储 自然语言处理 算法
参照Yalla、Hawa等主流APP核心功能,开发一款受欢迎的海外语聊需要从哪些方面入手
海外语聊APP开发需结合Yalla、Hawa等主流产品,聚焦多语言支持、实时音视频、社交互动与安全合规。兼顾技术架构、本地化运营与法律风险,避免劣质成品代码,平衡创新与成本,打造差异化出海产品。(239字)
|
JSON 自然语言处理 前端开发
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
928 72
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
|
存储 Java PHP
轻量化短视频电商直播带货APP源码全解析:核心功能与设计流程​
在电商直播热潮下,开发专属直播带货APP成为抢占市场关键。本文详解原生开发轻量化APP的核心功能与全流程设计,涵盖用户登录、商品浏览、直播互动、购物车、订单及售后功能,并介绍安卓端Java、苹果端Object-C、后台PHP的技术实现,助力打造高效优质的直播电商平台。
|
数据库
《仿盒马》app开发技术分享-- 回收订单页功能完善(45)
上一节我们实现了订单的待取件、已取消状态展示,并且成功实现了修改订单状态后的列表刷新,实现了云端数据的修改,这一节我们来实现订单页剩下的两个板块的业务逻辑,分别是运输中、已完成状态下的列表展示以及订单状态的修改
299 1
|
Web App开发 编解码 算法
布谷一对一直播源码开发:阿里云视频语音通话社交交友App的必备功能
在当今移动社交领域,一对一视频和语音通话功能已成为用户期待的基础配置。从熟人社交到陌生人交友,从专业咨询到情感陪伴,实时音视频互动能力直接决定了社交App的用户留存和市场竞争力。山东布谷科技将深入探讨一对一直播源码开发高质量一对一视频和语音通话功能的关键要素和技术实现方案。
布谷一对一直播源码开发:阿里云视频语音通话社交交友App的必备功能
|
存储 移动开发 监控
App Trace功能实战:一键拉起、快速安装与免提写邀请码的应用实践
App Trace系统通过一键拉起、快速安装和免提写邀请码三大功能,显著提升用户转化率、安装成功率和邀请注册率。结合深度技术实现与优化,助力公司用户增长,成为移动端核心基础设施。
《仿盒马》app开发技术分享-- 扫一扫功能(35)
随着app的逐渐完善,我们现在需要在细节处做更多的打磨,在首页我们添加了很多静态的按钮和组件,现在我们开始对这些组件进行功能的添加,这次首先实现的是首页头部的扫一扫功能,扫一扫我们实现扫码后跳转商品详情页
337 0

热门文章

最新文章