uni-app 124转发功能实现(四)

简介: uni-app 124转发功能实现(四)

本篇文章主要讲的是处理留言的发送

下图是我测试的截图

pages/chat/chat-list/chat-list.vue

<template>
  <view class="page">
    <!-- 导航栏 -->
    <free-nav-bar title="选择" showBack :showRight="true">
      <free-main-button :name="muliSelect ? '发送 ('+selectCount+')' : '多选'" slot="right" @click="handlenNav">
      </free-main-button>
    </free-nav-bar>
    <!-- 搜索框 -->
    <view class="p-3 bg-light position-fixed left-0 right-0" :style="'top:'+top+'px;'" style="z-index: 2;">
      <input type="text" value="" v-model="keyword" placeholder="搜索" class="bg-white rounded"
        placeholder-class="text-center" style="height: 80rpx;" />
    </view>
    <view style="height:140rpx;"></view>
    <free-list-item v-for="(item,index) in allList" :key="index" :title="item.name"
      :cover="item.avatar || '/static/images/userpic.png'" showRight :showRightIcon="false"
      @click="selectItem(item)">
      <view v-if="muliSelect" slot="right" class="border rounded-circle flex align-center"
        style="width: 40rpx;height: 40rpx;">
        <view v-if="item.checked" class="main-bg-color rounded-circle" style="width: 39rpx;height: 39rpx;">
        </view>
      </view>
    </free-list-item>
    <view style="height:100rpx;" class="flex align-center justify-center"
      v-if="keyword !== '' && searchList.length === 0">
      <text class="font text-light-muted">暂无搜索结果</text>
    </view>
    <free-confirm ref="confirm" title="发送给:">
      <scroll-view v-if="selectCount > 0" scroll-x="true" :show-scrollbar='false'>
        <view class="flex">
          <view class="mr-1" v-for="(item,index) in selectList" :key="index">
            <free-avatar :src="item.avatar" size="60"></free-avatar>
          </view>
        </view>
      </scroll-view>
      <view class="flex" v-else>
        <free-avatar :src="sendItem.avatar" size="60"></free-avatar>
        <text class="font text-muted ml-2">{{sendItem.name}}</text>
      </view>
      <view class="my-3 bg-light rounded p-2">
        <text class="font text-light-muted">{{message}}</text>
      </view>
      <input type="text" value="" class="border-bottom font-md" style="height: 60rpx;" placeholder="给朋友留言" v-model="content" />
    </free-confirm>
  </view>
</template>
<script>
  import freeNavBar from '@/components/free-ui/free-nav-bar.vue';
  import freeMainButton from '@/components/free-ui/free-main-button.vue';
  import freeListItem from '@/components/free-ui/free-list-item.vue';
  import freeConfirm from '@/components/free-ui/free-confirm.vue';
  import freeAvatar from '@/components/free-ui/free-avatar.vue';
  import {
    mapState
  } from 'vuex';
  export default {
    components: {
      freeNavBar,
      freeMainButton,
      freeListItem,
      freeConfirm,
      freeAvatar
    },
    data() {
      return {
        keyword: '',
        muliSelect: false,
        top: 0,
        list: [],
        detail: {},
        sendItem: {},
        content:''
      }
    },
    computed: {
      ...mapState({
        chatList: state => state.user.chatList,
        chat: state => state.user.chat,
      }),
      // 最终列表
      allList() {
        return this.keyword === '' ? this.list : this.searchList;
      },
      // 搜索结果列表
      searchList() {
        if (this.keyword === '') {
          return [];
        }
        return this.list.filter(item => {
          return item.name.indexOf(this.keyword) !== -1;
        })
      },
      // 选中列表
      selectList() {
        return this.list.filter(item => item.checked)
      },
      // 选中数量
      selectCount() {
        return this.selectList.length;
      },
      message() {
        let obj = {
          image: '[图片]',
          video: '[视频]',
          audio: '[语音]',
          card: '[名片]',
          emoticon: '[表情]'
        };
        return this.detail.type === 'text' ? this.detail.data : obj[this.detail.type];
      }
    },
    methods: {
      // 点击导航栏 (群发)
      handlenNav() {
        if (!this.muliSelect) {
          return this.muliSelect = true;
        }
        // 发送
        if (this.selectCount === 0) {
          return uni.showToast({
            title: '请先选择',
            icon: 'none'
          });
        }
        this.$refs.confirm.show((close) => {
          this.selectList.forEach(item => {
            this.send(item)
            
            if (this.content) {
              this.send(item, this.content, 'text')
            }
          });
          close();
          uni.reLaunch({
            url: "../../tabbar/index/index"
          })
        });
      },
      // 选中、取消选中
      selectItem(item) {
        // 选中、取消选中
        if (this.muliSelect) {
          // 选中
          if (!item.checked && (this.selectCount === 9)) {
            // 限制选中数量
            return uni.showToast({
              title: '最多选中9个',
              icon: 'none'
            })
          }
          
          // 取消选中
          return item.checked = !item.checked;
        }
        // 发送
        this.sendItem = item;
        this.$refs.confirm.show((close) => {
          this.send(item);
          
          if (this.content) {
            this.send(item, this.content, 'text')
          }
          
          close();
          uni.reLaunch({
            url: "../../tabbar/index/index"
          })
        });
      },
      send(item,data=false,type = false) {
        let message = this.chat.formatSendData({
          to_id: item.id,
          to_name: item.name,
          to_avatar: item.avatar,
          data:data || this.detail.data,
          type:type || this.detail.type,
          chat_type:item.chat_type,
          options: this.detail.opitons
        });
        this.chat.send(message);
        uni.$emit('updateHistory',false);
        
      }
    },
    onLoad(e) {
      let res = uni.getSystemInfoSync();
      this.top = res.statusBarHeight + uni.upx2px(90);
      this.list = this.chatList.map(item => {
        return {
          ...item,
          checked: false
        }
      })
      if (e.params) {
        this.detail = JSON.parse(decodeURIComponent(e.params))
      }
    }
  }
</script>
<style>
</style>

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

目录
相关文章
|
5月前
uni-app 155朋友圈评论功能(二)
uni-app 155朋友圈评论功能(二)
97 0
|
2天前
|
移动开发 Android开发 数据安全/隐私保护
移动应用与系统的技术演进:从开发到操作系统的全景解析随着智能手机和平板电脑的普及,移动应用(App)已成为人们日常生活中不可或缺的一部分。无论是社交、娱乐、购物还是办公,移动应用都扮演着重要的角色。而支撑这些应用运行的,正是功能强大且复杂的移动操作系统。本文将深入探讨移动应用的开发过程及其背后的操作系统机制,揭示这一领域的技术演进。
本文旨在提供关于移动应用与系统技术的全面概述,涵盖移动应用的开发生命周期、主要移动操作系统的特点以及它们之间的竞争关系。我们将探讨如何高效地开发移动应用,并分析iOS和Android两大主流操作系统的技术优势与局限。同时,本文还将讨论跨平台解决方案的兴起及其对移动开发领域的影响。通过这篇技术性文章,读者将获得对移动应用开发及操作系统深层理解的钥匙。
|
2月前
|
Java PHP
【应用服务 App Service】 App Service Rewrite 实例 - 反向代理转发功能
【应用服务 App Service】 App Service Rewrite 实例 - 反向代理转发功能
【应用服务 App Service】 App Service Rewrite 实例 - 反向代理转发功能
|
2月前
|
Python
【Azure 应用服务】App Service的运行状况检查功能失效,一直提示"实例运行不正常"
【Azure 应用服务】App Service的运行状况检查功能失效,一直提示"实例运行不正常"
|
4月前
|
开发框架 移动开发 JavaScript
SpringCloud微服务实战——搭建企业级开发框架(四十七):【移动开发】整合uni-app搭建移动端快速开发框架-添加Axios并实现登录功能
在uni-app中,使用axios实现网络请求和登录功能涉及以下几个关键步骤: 1. **安装axios和axios-auth-refresh**: 在项目的`package.json`中添加axios和axios-auth-refresh依赖,可以通过HBuilderX的终端窗口运行`yarn add axios axios-auth-refresh`命令来安装。 2. **配置自定义常量**: 创建`project.config.js`文件,配置全局常量,如API基础URL、TenantId、APP_CLIENT_ID和APP_CLIENT_SECRET等。
206 60
|
2月前
|
测试技术
一款功能完善的智能匹配1V1视频聊天App应该通过的测试CASE
文章列举了一系列针对1V1视频聊天App的测试用例,包括UI样式、权限请求、登录流程、匹配逻辑、消息处理、充值功能等多个方面的测试点,并标注了每个测试用例的执行状态,如通过(PASS)、失败(FAIL)或需要进一步处理(延期修改、待定、方案再定等)。
39 0
|
2月前
|
Linux C++ Docker
【Azure 应用服务】App Service for Linux 中实现 WebSocket 功能 (Python SocketIO)
【Azure 应用服务】App Service for Linux 中实现 WebSocket 功能 (Python SocketIO)
|
2月前
|
监控 安全 前端开发
【Azure 应用服务】App Service 运行状况健康检查功能简介 (Health check)
【Azure 应用服务】App Service 运行状况健康检查功能简介 (Health check)
|
3月前
|
存储 前端开发 测试技术
同城交友APP系统开发运营版/案例详细/功能步骤/逻辑方案
开发一款同城交友APP系统需要经过以下大致流程:
|
3月前
|
JavaScript Java 测试技术
基于SpringBoot+Vue+uniapp的多功能智能手机阅读APP的详细设计和实现(源码+lw+部署文档+讲解等)
基于SpringBoot+Vue+uniapp的多功能智能手机阅读APP的详细设计和实现(源码+lw+部署文档+讲解等)