uni-app 102修改我在本群的昵称(二)

简介: uni-app 102修改我在本群的昵称(二)


先看效果图

/pages/chat/chat-set/chat-set.vue

<template>
  <view style="background-color: #EDEDED;">
    <!-- 导航栏 -->
    <free-nav-bar title="聊天信息" showBack :showRight="false"></free-nav-bar>
    <view class="flex flex-wrap py-3 bg-white">
      <!-- 私聊 -->
      <view v-if="detail.chat_type === 'user'" class="flex flex-column align-center justify-center mb-2" style="width: 150rpx;">
        <free-avatar :src="detail.avatar || '/static/images/userpic.png'" size="110"></free-avatar>
        <text class="font text-muted mt-1" >{{detail.name}}</text>
      </view>
      <!-- 群聊 -->
      <view v-else class="flex flex-column align-center justify-center mb-2" style="width: 150rpx;" v-for="(item,index) in list" :key='index'>
        <free-avatar :src="item.avatar || '/static/images/userpic.png'" size="110"></free-avatar>
        <text class="font text-muted mt-1" >{{item.name}}</text>
      </view>
      
      <view class="flex flex-column align-center justify-center mb-2" style="width: 150rpx;"  @click="openMail">
        <view class="flex align-center justify-center border"  hover-class="bg-light" style="width: 120rpx;height: 120rpx;">
          <text class="text-light-muted" style="font-size: 100rpx;" >+</text>
        </view>
      </view>
    </view>
    
    <free-divider></free-divider>
    <view v-if="detail.chat_type==='group'">
      <free-list-item title="群聊名称" showRight :showLeftIcon="false" @click="updateName()">
        <text slot="right" class="font text-muted">{{detail.name}}</text>
      </free-list-item>
      <free-list-item title="群二维码" showRight :showLeftIcon="false">
        <text slot="right" class="iconfont font-md text-light-muted">&#xe647;</text>
      </free-list-item>
      <free-list-item title="群公告" showRight :showLeftIcon="false" @click="openGroupRemark"></free-list-item>
    </view>
    
    <free-divider></free-divider>
    <free-list-item title="查找聊天记录" showRight :showLeftIcon="false"></free-list-item>
    <free-divider></free-divider>
    <free-list-item title="消息免打扰" showRight :showLeftIcon="false" :showRightIcon="false">
      <switch slot="right" :checked="detail.nowarn" @change="" color="#08C060"/>
    </free-list-item>
    <free-list-item title="置顶聊天" showRight :showLeftIcon="false" :showRightIcon="false">
      <switch slot="right" :checked="detail.istop" @change="" color="#08C060"/>
    </free-list-item>
    <free-list-item title="强提醒" showRight :showLeftIcon="false" :showRightIcon="false">
      <switch slot="right" :checked="detail.strongwarn" @change="" color="#08C060"/>
    </free-list-item>
    <free-divider></free-divider>
    <free-list-item title="清空聊天记录" showRight :showLeftIcon="false"></free-list-item>
    <free-divider></free-divider>
    
    <view v-if="detail.chat_type==='group'">
      <free-divider></free-divider>
      <free-list-item title="我在本群的昵称" showRight :showLeftIcon="false" @click="updatenickName">
        <text slot="right" class="font text-muted">{{nickname}}</text>
      </free-list-item>
      <free-list-item title="显示群成员昵称" showRight :showLeftIcon="false" :showRightIcon="false">
        <switch slot="right" :checked="detail.shownickname" @change="" color="#08C060"/>
      </free-list-item>
      </view>
    
    
    
    <free-divider></free-divider>
    <free-list-item title="投诉" showRight :showLeftIcon="false"></free-list-item>
    
    <free-divider></free-divider>
    <view class="py-3 flex align-center justify-center bg-white" hover-class="bg-light">
      <text class="font-md text-danger">删除并退出</text>
    </view>
    
    <free-confirm :title="'修改'+confirmTitle" ref="confirm">
        <input type="text" class="border-bottom font-md" :placeholder="confirmTitle" v-model="confirmText"/>
    </free-confirm>
    
    <view style="height: 200rpx;"></view>
  </view>
</template>
<script>
  import freeNavBar from '@/components/free-ui/free-nav-bar.vue';
  import freeAvatar from '@/components/free-ui/free-avatar.vue';
  import freeDivider from '@/components/free-ui/free-divider.vue';
  import freeListItem from '@/components/free-ui/free-list-item.vue';
  import freeConfirm from '@/components/free-ui/free-confirm.vue';
  import { mapState } from 'vuex';
  import $H from '@/common/free-lib/request.js';
  export default {
    components:{
      freeNavBar,
      freeAvatar,
      freeDivider,
      freeListItem,
      freeConfirm
    },
    computed:{
      ...mapState({
        chat:state=>state.user.chat,
        user:state=>state.user.user
      }),
      confirmTitle(){
        return this.confirmType === 'name' ? '群名称' : '昵称';
      }
    },
    data() {
      return {
        list:[],
        confirmText:'',
        nickname:'',
        detail:{
              id:0,  // 接收人/群 id
              chat_type:'user', // 接收类型 user 单聊 group群聊
              name:'', // 接收人/群 昵称
              avatar:"", // 接收人/群 头像
              type:'',// 最后一条消息类型
              istop:false, // 是否置顶
              shownickname:false, // 是否显示昵称
              nowarn:false, // 是否免打扰
              strongwarn:false, //  是否强提醒
              user_id:0,//管理员id,
              remark:'', // 群公告
              invite_confirm:0, // 邀请确认
        }
      }
    },
    methods: {
      updatenickName(){
        this.confirmType = 'nickname';
        this.confirmText = this.nickname
          this.$refs.confirm.show((close)=>{
            if(this.confirmText == ''){
              return uni.showToast({
                title:'昵称不能为空',
                icon:'none'
              })
            }
            $H.post('/group/nickname',{
              id:this.detail.id,
              nickname:this.confirmText
            }).then(res=>{
              uni.showToast({
                title:'修改成功',
                icon:'none'
              });
              this.nickname = this.confirmText;
              close();
            })
          });
      },
      openGroupRemark(){
        uni.navigateTo({
          url: '../group-remark/group-remark?params='+encodeURIComponent(JSON.stringify({
            id:this.detail.id,
            remark:this.detail.remark
          }))
        });
      },
      openMail(){
        uni.navigateTo({
          url:'/pages/mail/mail/mail?type=createGroup'
        })
      },
      updateName(){
        this.confirmText = this.detail.name
        this.$refs.confirm.show((close)=>{
          if(this.confirmText == ''){
            return uni.showToast({
              title:'群名称不能为空',
              icon:'none'
            })
          }
          $H.post('/group/rename',{
            id:this.detail.id,
            name:this.confirmText
          }).then(res=>{
            uni.showToast({
              title:'修改成功',
              icon:'none'
            });
            this.detail.name = this.confirmText;
            close();
          })
        });
      }
    },
    onLoad(e) {
      if(!e.params){
        return this.backToast();
      }
      let detail = JSON.parse(e.params);
      // 获取当前会话的详细资料
      detail = this.chat.getChatListItem(detail.id,detail.chat_type);
      if(!detail){
        return this.backToast()
      }
      this.detail = detail;
      if(this.detail.chat_type === 'group'){
        $H.get('/group_info/'+this.detail.id).then(res=>{
          this.detail.remark = res.remark;
          this.list = res.group_users.map(item=>{
            if(item.user_id === this.user.id){
              this.nickname = item.nickname;
            }
            return {
              id:item.user_id,
              name:item.nickname || item.user.nickname || item.user.username,
              avatar:item.user.avatar
            }
          })
          
        }).catch(err=>{
          uni.navigateBack({
            delta:1,
          })
        })
      }
    }
  }
</script>
<style>
</style>

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

目录
相关文章
|
2月前
|
自然语言处理 IDE Java
IDEA 2026.3 EAP新特性:终于要向“包名对不上文件夹”的代码低头了
IntelliJ IDEA 2026.3 EAP新增特性:支持包名与目录结构不一致时的通配符导入(如`import org.classa.*`)。不再强求目录匹配包名,而是依据类声明的全限定名进行符号解析,使遗留、脚本化或非标准项目中的导入正常高亮与补全,真正让工具适配真实代码。(239字)
207 0
|
11月前
|
人工智能 监控 架构师
驾驭“数字员工”:AI Agent时代的组织变革与未来十年黄金职业路线
本文前瞻性解析AI Agent时代组织变革,提出“人机混合智能组织”三大新角色(智能体主管、协作架构师、AI伦理官),首创TECH领导力模型(技术素养、伦理框架、协调沟通、以人为本),并为技术、管理、运营从业者提供实操转型路径。(239字)
1377 3
|
11月前
|
Windows
geek卸载软件怎么安装?详细安装步骤
geek.exe是一款轻量级Windows清理优化工具,专用于卸载软件、清除残留文件及注册表垃圾。下载后需核对文件名与大小,安装时建议更改路径至非系统盘,注意取消捆绑软件勾选,完成后可快速启动使用,操作简单高效。(238字)
2133 3
|
SQL 人工智能 安全
五星认可!瑞数信息入选IDC中国WAAP厂商技术能力评估报告
IDC发布2025《中国WAAP厂商技术能力评估》报告,瑞数信息WAAP平台在WAF、API保护、Bot管理及大模型协同防护等多维度获五星评价。依托“动态安全+AI”核心技术,实现全业务渠道与全功能超融合防护,助力企业构建智能化、一体化LLM安全防御体系,广泛服务于政企、金融、医疗等关键领域。
481 1
|
6月前
|
SQL 人工智能 安全
Zed 官宣:正式支持SKILL
Zed编辑器新推AI Skills功能,以“可复用指令包”重塑人机协作:技能即师徒契约,渐进式披露保隐私,Git化管理促共享,只读设计守安全。它不替代思考,而是将隐性经验显性化、可复用化,让AI真正成为懂行的协作者。(239字)
474 0
|
6月前
|
存储 人工智能 运维
现代勒索软件攻击演进与中小企业分层闭环防御体系研究
本文基于ESET 2026年威胁报告,系统剖析现代勒索软件向“数据窃取+系统加密+业务中断”三重勒索演进的规律,揭示RaaS商业化与PromptLock等AI驱动新型攻击特征;结合MITRE ATT&CK框架拆解四大入侵路径,提出适配中小微企业的分层防御体系,涵盖MFA加固、优先级补丁、3-2-1-1-0备份等六大落地措施。(239字)
401 0
|
人工智能 开发者
2025魔搭开发者大会!来了!
2025魔搭开发者大会!来了!
1370 1
|
消息中间件 Java Kafka
flowable6.8.0正式发布了
flowable6.8.0正式发布了
1525 0
|
12月前
|
传感器 人工智能 算法
校园服务机器人关键技术解析与选型
智慧校园中,服务机器人已升级为集导览、安防、教学辅助与数据管理于一体的智能终端。依托大模型、多传感器融合导航与情感计算技术,实现精准交互与自主决策。猎户星空、优必选、科大讯飞等品牌各具优势,满足多样化教育场景需求,推动AI赋能校园智能化转型。(238字)
|
监控 Java 测试技术
Nacos 配置中心变更利器:自定义标签灰度
本文是对 MSE Nacos 应用自定义标签灰度的功能介绍,欢迎大家升级版本进行试用。
1538 230