当前位置: 首页 > news >正文

ArKTS: staic message simple

 

/**# encoding: utf-8# 版权所有 2024 ©涂聚文有限公司# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎# 描述: https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-dialog# Author    : geovindu,Geovin Du 涂聚文. https://yesicon.app/# IDE       : DevEco Studio 5.1.1 HarmonyOS ArKTS# OS        : windows 10  ohpm install @coremail/mail_base     https://gitee.com/openharmony-tpc/ohos_mail_base# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j# Datetime  : 2024/10/31 20:33# User      : geovindu# Product   : MyApplicatin# Project   : MyApplicatin# File      : WxList.ets* */
import { UserInfoBase } from '../../constant/UserInfoBase'
import { router } from '@kit.ArkUI';
import { TodoTitleNameUtils } from '../../pages/utils/TodoTitleNameUtils'
import { trustedAppService } from '@kit.DeviceSecurityKit';
import { CommonConstantWX } from '../../constant/CommonConstantWX'
import { UserMessageBase } from '../../constant/UserMessageBase';// 2. 定义传递的参数类型(包含user属性)
interface UserParams {user: UserInfoBase;
}@Entry
@Component
struct WxList {@State message: string = '聊天';@State users: UserInfoBase=new UserInfoBase() ;@State messagelist: Array<UserMessageBase> = CommonConstantWX.mUserMessage// 3. 获取参数并断言为UserParams类型//const params = router.getParams() as UserParams | undefined;aboutToAppear() {// 获取传递的参数const params =router.getParams() as UserParams | undefined;// router.getParams();if (params?.user) {this.users = params.user as UserInfoBase; // 类型转换,确保与传递的item结构一致}}build() {Column() {Row() {TodoTitleNameUtils({ isTitle: true, titleName: this.users.name === undefined ? "" : this.users.name })}.width('100%').height('15pv')List() {ForEach(this.messagelist, (item: UserMessageBase) => {ListItem() {Column() {// 外层Row设置主轴靠右对齐,确保内部元素整体靠右Row() {if(item.category===0) {Image(item.img).width(40).height(50).margin({right: 8}).borderRadius(5).objectFit(ImageFit.Contain)// 移除不必要的align,由外层Row统一控制对齐}Text(item.content).fontSize($r('app.float.pagemessagesize')).fontWeight(FontWeight.Bold).backgroundColor(item.category===0?'#ffffff': '#ff81cd0a') // 白色背景.borderRadius(10) // 圆角效果,数值可调整.padding({ left: 12, right: 12, top: 8, bottom: 8 }) // 文本与背景的内边距.margin({ right: 8 }) // 图片与文本之间的间距.onClick(() => {router.pushUrl({url: 'pages/weixin/WXHome',})})if(item.category===1) {Image(item.img).width(40).height(50).margin({left: 8}).borderRadius(5).objectFit(ImageFit.Contain)// 移除不必要的align,由外层Row统一控制对齐}}.width('100%').justifyContent(item.category===0?FlexAlign.Start:FlexAlign.End) // 关键:Row内元素靠右排列 FlexAlign.End.align(item.category===0?Alignment.Start:Alignment.End) // Alignment.End.margin({ right: 1})}.alignItems(item.category===0?HorizontalAlign.Start:HorizontalAlign.End) // 确保Column的子元素(Row)靠右对齐 HorizontalAlign.End.align(item.category===0?Alignment.Start:Alignment.End) //Alignment.End// 可根据需要添加整体外边距.margin({ right: 12, top: 8, bottom: 8 })}.align(item.category===0?Alignment.Start:Alignment.End) // Alignment.End})}.height('80%').width('100%').backgroundColor('#ccc').scrollSnapAlign(ScrollSnapAlign.START)Row({ space: 8 }) {// 语音按钮Image($r('app.media.SoundHighSolid')).width(30).height(30).objectFit(ImageFit.Contain).onClick(() => {router.pushUrl({url: 'pages/weixin/WXHome',})})// 输入框TextInput({ placeholder: '请输入消息...'}).id('WxListHelloWorld').fontSize($r('app.float.page_text_font_size')).fontWeight(FontWeight.Normal).backgroundColor('#ffffff').borderRadius(20)  // 圆角输入框.padding({ left: 16, right: 16 })  // 文本内边距.onClick(() => {this.message = this.users?.name || "";}).flexGrow(1)  // 自动填充剩余空间.width('75%')// 发送按钮Button('+').fontSize(18).width(40).height(40).borderRadius(20)  // 圆形按钮.backgroundColor('#07C160')  // 微信绿//.textStyle({ color: '#ffffff' }).onClick(() => {router.back()})}.margin({ top: 8, left: 12, right: 12, bottom: 8 })  // 整体外边距.height(50)  // 合适的高度.backgroundColor('#f5f5f5')  // 浅灰背景.alignItems(VerticalAlign.Center)  // 垂直居中对齐.width('100%')}}
}

  

 

070b407bc7d5d98d45b0fd7ddd8fab1

 

http://www.sczhlp.com/news/4257/

相关文章:

  • 决定了,我要
  • 汽车空调维修记录
  • Js 中的 this 指向
  • 基于PSO粒子群优化算法的256QAM星座图的最优概率整形matlab仿真,对比PSO优化前后整形星座图和误码率
  • OceanBase的全局元数据服务实现机制及如何保证元数据一致性和高可用
  • 二分习题补充 - L
  • CCF IVC 2025“汽车安全攻防赛” -- Crypto -- WriteUp
  • 程序员究竟要不要写文章
  • 数据库备份和恢复的策略有哪些?如何验证备份的有效性?Point-in-Time Recovery是如何实现的?
  • 变量、数组的内存图
  • 分库分表的常见方案和挑战是什么?
  • 2020年Q1/Q2机器学习研究奖项公布
  • POLIR-Laws-行政诉讼:1.北京市金融局:政府信息公开-2.行政诉讼:
  • mysql
  • c语言中的stdin
  • 使用JavaScript生成安全的随机密码 - 技术解析与实践
  • Atcoder Beginner Contest 417 A-C,E
  • 实用指南:【Keras学习笔记】开发环境搭建
  • redis
  • 怎么配置windows与远程服务器免密登录
  • 2025熵密杯 -- 初始谜题 -- Reproducibility
  • 测试主题
  • Extreme_Parkour复现及相关问题汇总
  • P1812 区间运算 题解
  • ctfshow web入门 常见姿势 Web801-Web810
  • 多模态指代消解模型在挑战赛中夺冠
  • CSP初赛知识点(Part2):基础算法与运算
  • 2025.8.2 随记
  • 软考系统分析师每日学习卡 | [日期:2025-08-01] | [今日主题:页式存储]
  • 软考系统分析师每日学习卡 | [日期:2025-08-02] | [今日主题:段式存储]