feat: 基础的Chat List

This commit is contained in:
Cheliangzhao 2024-09-11 20:48:34 +08:00
parent 406685b399
commit 1668cbfea9
5 changed files with 183 additions and 1 deletions

View File

@ -1,6 +1,20 @@
{ {
"app": { "app": {
"signingConfigs": [], "signingConfigs": [
{
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "C:\\Users\\wps\\.ohos\\config\\default_himi_ZikZBgBxljB_K_Bxk-D2cAAnn7PtvbqmLsGmCt8Tywc=.cer",
"storePassword": "0000001A324907DCD55F55682629687D2AECF782CD5EE7AFB5FD4E1CE3F410EBB601D67AC641B4072B46",
"keyAlias": "debugKey",
"keyPassword": "0000001A8EDEBEC4585D89D8F1A91107E51ECAE951E2849CB803CBA06C9E49A8A59CCB6CECAF7EA5DADA",
"profile": "C:\\Users\\wps\\.ohos\\config\\default_himi_ZikZBgBxljB_K_Bxk-D2cAAnn7PtvbqmLsGmCt8Tywc=.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "C:\\Users\\wps\\.ohos\\config\\default_himi_ZikZBgBxljB_K_Bxk-D2cAAnn7PtvbqmLsGmCt8Tywc=.p12"
}
}
],
"products": [ "products": [
{ {
"name": "default", "name": "default",

View File

@ -0,0 +1,93 @@
/**
* Created on 2024/9/10
*/
package ohos_app_cangjie_entry.components.Chat
import std.collection.*
import ohos.component.*
import ohos.state_macro_manage.*
import ohos.state_manage.*
import ohos.base.*
public enum EChatSource {
| ME
| YOU
}
@Component
public class ChatMessage {
@Prop
var message: String
@Prop
var source: EChatSource
@State
var radiusMap: HashMap<String, Length> = HashMap<String, Length>()
protected func aboutToAppear() {
this.radiusMap = this.messageRadius()
}
func fontColor() {
match (this.source) {
case EChatSource.ME => Color.WHITE
case EChatSource.YOU => Color.BLACK
}
}
func bgColor() {
match (this.source) {
case EChatSource.YOU => Color.WHITE
case EChatSource.ME => Color.BLUE
}
}
func orient() {
match (this.source) {
case EChatSource.YOU => FlexAlign.Start
case EChatSource.ME => FlexAlign.End
}
}
func messageRadius(): HashMap<String, Length> {
match (this.source) {
case EChatSource.YOU => HashMap<String, Length>(
[
("topLeft", 12.vp),
("topRight", 12.vp),
("bottomLeft", 0.vp),
("bottomRight", 12.vp)
]
)
case EChatSource.ME => HashMap<String, Length>(
[
("topLeft", 12.vp),
("topRight", 12.vp),
("bottomLeft", 12.vp),
("bottomRight", 0.vp)
]
)
}
}
func build() {
Row() {
Row() {
Text(message)
.fontColor(this.fontColor())
.backgroundColor(this.bgColor())
.padding(top: 8, right: 16,bottom: 8, left: 16)
.borderRadius(
topLeft: this.radiusMap['topLeft'],
topRight: this.radiusMap['topRight'],
bottomLeft: this.radiusMap['bottomLeft'],
bottomRight: this.radiusMap['bottomRight'],
)
}
.width(60.percent)
.justifyContent(this.orient())
}
.width(100.percent)
.justifyContent(this.orient())
}
}

View File

@ -0,0 +1,36 @@
/**
* Created on 2024/9/10
*/
package ohos_app_cangjie_entry.components
internal import ohos.component.*
internal import ohos.state_manage.*
internal import ohos.base.*
import ohos.state_macro_manage.*
import ohos_app_cangjie_entry.components.Chat.*
@Component
public class ChatList {
let array: Array<String> = Array<String>(20, item: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf")
func build() {
Column {
List(space: 20, initialIndex: 0) {
ForEach(
this.array,
itemGeneratorFunc: {
item: String, index: Int64 => ListItem {
ChatMessage(
message: item,
source: if (index % 2 == 0) {
EChatSource.ME
} else {
EChatSource.YOU
}
)
}
}
)
}
}.height(100.percent).width(100.percent).padding(top: 5.vp)
}
}

View File

@ -9,9 +9,13 @@ import ohos_app_cangjie_entry.pages.*
@Entry @Entry
@Component @Component
class MyView { class MyView {
let TAG = "MyView"
@State @State
var message: String = "Hello Cangjie" var message: String = "Hello Cangjie"
protected func aboutToAppear() {
}
func build() { func build() {
Row { Row {
HomePage() HomePage()

View File

@ -0,0 +1,35 @@
/**
* Created on 2024/9/7
*/
package ohos_app_cangjie_entry.utils
import std.log.*
import log.*
import std.console.*
public class Logger {
private let TAG: String
private static let logger = SimpleLogger()
private static let isOutputFile: Bool = false
private static let outputFilePath: String = './logger.log'
public init(TAG: String) {
logger.setOutput(Console.stdOut)
this.TAG = TAG + ": "
}
public func debug(message: String) {
logger.debug(this.TAG + message)
logger.flush()
}
public func info(msg: String) {
logger.info(this.TAG + msg)
logger.flush()
}
public func warn(msg: String) {
logger.warn(this.TAG + msg)
}
public func error(msg: String) {
logger.error(this.TAG + msg)
}
}