src/app/tab1/tab1.page.ts
| selector | app-tab1 |
| styleUrls | tab1.page.scss |
| templateUrl | tab1.page.html |
属性列表 |
方法 |
constructor(navCtrl: NavController)
|
||||||
|
参数列表 :
|
| openChat | ||||||
openChat(contact: literal type)
|
||||||
|
参数列表 :
返回 :
void
|
import { Component } from '@angular/core';
import { NavController } from '@ionic/angular';
import { Router } from '@angular/router';
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
contacts: { username: string, avatar: string, lastMessageTime: string, lastMessage: string }[] = [
{
username: 'Alice',
avatar: 'assets/1.png',
lastMessageTime: '10:30 AM',
lastMessage: 'Hey, how are you?',
},
{
username: 'Bob',
avatar: 'assets/时钟.png',
lastMessageTime: 'Yesterday',
lastMessage: 'Let\'s meet tomorrow.',
},
// Add more contacts as needed
];
constructor(private navCtrl: NavController) {}
openChat(contact: { username: string, avatar: string, lastMessageTime: string, lastMessage: string }) {
this.navCtrl.navigateForward(`chat-test1/${contact.username}`);
}
}
<ion-header>
<ion-toolbar>
<ion-title style="text-align: center;">联系人</ion-title>
</ion-toolbar>
<ion-toolbar>
<ion-searchbar class="custom-searchbar" placeholder="搜索联系人"></ion-searchbar>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list lines="full">
<ion-item *ngFor="let contact of contacts" (click)="openChat(contact)">
<ion-avatar slot="start">
<img [src]="contact.avatar">
</ion-avatar>
<ion-label>
<h2>{{ contact.username }}</h2>
<p>{{ contact.lastMessageTime }}</p>
<p>{{ contact.lastMessage }}</p>
</ion-label>
</ion-item>
</ion-list>
</ion-content>
tab1.page.scss
.custom-searchbar {
--background: #f2f2f2; /* 设置搜索栏的背景色为灰色 */
--border-width: 1px; /* 设置边框宽度 */
--border-color: #ccc; /* 设置边框颜色 */
--border-radius: 10px; /* 设置圆角半径 */
--box-shadow: none; /* 去掉阴影 */
}
.custom-searchbar .searchbar-input {
font-size: 14px; /* 设置字体大小 */
}
ion-avatar {
width: 56px;
height: 56px;
}
ion-item {
--ion-item-background: transparent;
--ion-item-text-transform: none;
}
ion-label h2 {
font-size: 18px;
font-weight: bold;
}
ion-label p {
font-size: 14px;
color: #888;
}
.header-md{
box-shadow: none;
border-bottom: 1px rgba(0,0,0,0.2) solid;
}
.custom-searchbar {
--border-radius: 20px; /* 设置圆角大小 */
--height: 10px; /* 设置搜索框高度 */
// --box-shadow: none; /* 去掉阴影 */
// border:#f0f0f0 8px solid;
/* 可选:调整输入框内部的样式 */
.searchbar-input {
border-radius: var(--border-radius);
height: var(--height);
box-shadow: var(--box-shadow);
}
/* 可选:调整输入框外部的样式 */
.searchbar-input-container {
border-radius: var(--border-radius);
height: var(--height);
box-shadow: var(--box-shadow);
}
}
ion-content {
background-color: #f0f0f0; /* 设置整体背景色为白灰色 */
}
/* 如果想突出显示聊天框,可以为ion-item添加自定义样式 */
ion-item.chat-item {
background-color: #ffffff; /* 设置聊天框的背景色为白色 */
border-radius: 10px; /* 可选:设置聊天框的圆角 */
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 可选:添加轻微阴影增强立体感 */
}
// .toolbar-con