import { CommonConstantWX } from "../../common/CommonConstantWX"
|
import { WxUserInfoBase } from "../../data/WxUserInfoBase"
|
|
/*
|
* Search({placeholder: '请输入您要搜索的内容',value: 'DeepSeek'})
|
.width('90%')
|
.backgroundColor(Color.White)
|
.searchButton('搜索')
|
.onChange((value: string) => {
|
console.info(`输入的内容为:${value}`)
|
})
|
//提交方法
|
.onSubmit((value:string) => {
|
console.info(`提交的内容为:${value}`)
|
})
|
* */
|
@Entry
|
@Component
|
export struct MessagePage {
|
@State userList:Array<WxUserInfoBase> = CommonConstantWX.mUser
|
@State searchUser:Array<WxUserInfoBase> = []
|
build() {
|
Column({space: 10}) {
|
Search({placeholder: '搜索'})
|
.backgroundColor(Color.White)
|
.width('90%')
|
.borderRadius(5)
|
.onChange((value: string) =>{
|
//每次输入都要清空searchUser数组
|
this.searchUser = []
|
let searchCount = 0
|
//进行遍历,在数组源头查找和value相关的数据
|
for (let index = 0; index < this.userList.length; index++) {
|
const element = this.userList[index];
|
//判断每一条数据是否有和Value相关的内容
|
if (element.name?.indexOf(value) != -1) {
|
//找到相关的数据,添加到search数组当中,并且数据加一
|
searchCount ++
|
this.searchUser.push(element)
|
}
|
}
|
//判断SearchCount是否为0
|
if (searchCount === 0) {
|
//表示查无此人
|
this.searchUser.push({
|
id: 999,
|
name: '无此用户',
|
img:$r('app.media.avatar_icon')
|
})
|
}
|
|
})
|
List({space: 20}){
|
ForEach(this.searchUser.length === 0 ? this.userList: this.searchUser,(item: WxUserInfoBase) => {
|
ListItem(){
|
userInfoItem({item: item})
|
}
|
})
|
}
|
.height('90%')
|
.padding({top:10})
|
.margin({bottom: 30})
|
.backgroundColor(Color.White)
|
.divider({strokeWidth: 2,color: '#ccc'})
|
}
|
.height('100%')
|
.width('100%')
|
.backgroundColor('#ccc')
|
}
|
}
|
|
@Component
|
struct userInfoItem {
|
@Prop item: WxUserInfoBase
|
build() {
|
Row({space: 15}){
|
Image(this.item.img)
|
.width(40)
|
.height(40)
|
.objectFit(ImageFit.Cover)
|
Text(this.item.name)
|
.fontSize(20)
|
}
|
.onClick(() => {
|
this.getUIContext().getRouter().pushUrl({
|
url: 'pages/message/MessageDetailsPage',
|
params:{
|
userInfo: this.item
|
}
|
})
|
})
|
.padding(10)
|
}
|
}
|