diff --git a/build-profile.json5 b/build-profile.json5 index 24a4284..ed2b75e 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,19 +1,6 @@ { "app": { "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": [ { diff --git a/entry/src/main/cangjie/src/components/chat/ChatList.cj b/entry/src/main/cangjie/src/components/chat/ChatList.cj index aaff98c..ddbfd05 100644 --- a/entry/src/main/cangjie/src/components/chat/ChatList.cj +++ b/entry/src/main/cangjie/src/components/chat/ChatList.cj @@ -7,24 +7,24 @@ internal import ohos.component.* internal import ohos.state_manage.* internal import ohos.base.* import ohos.state_macro_manage.* +import ohos_app_cangjie_entry.mock.* +import ohos_app_cangjie_entry.types.ChatData @Component public class ChatList { - let array: Array = Array(20, item: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf") + @Prop + var datasource: ObservedArray + func build() { Column { List(space: 20, initialIndex: 0) { ForEach( - this.array, + this.datasource, itemGeneratorFunc: { - item: String, index: Int64 => ListItem { + item: ChatData, _: Int => ListItem { ChatMessage( - message: item, - source: if (index % 2 == 0) { - EChatSource.ME - } else { - EChatSource.YOU - } + message: item.message, + source: item.source, ) } } diff --git a/entry/src/main/cangjie/src/components/chat/ChatMessage.cj b/entry/src/main/cangjie/src/components/chat/ChatMessage.cj index 56a9fe3..c9c9d21 100644 --- a/entry/src/main/cangjie/src/components/chat/ChatMessage.cj +++ b/entry/src/main/cangjie/src/components/chat/ChatMessage.cj @@ -14,8 +14,8 @@ public enum EChatSource { | ME | YOU - operator func == (right: EChatSource) { - + operator func ==(right: EChatSource) { + // fixme: enum无法比较 } } @@ -24,12 +24,24 @@ public class ChatMessage { @Prop var message: String @Prop - var source: EChatSource + var source: String + + func upperSource() { + return source.toAsciiUpper() + } + + @Builder + func matchSource() { + if (this.upperSource() == 'ME') { + ChatMessageMe(message: this.message) + } else if (this.upperSource() == 'YOU') { + ChatMessageYou(message: this.message) + } else {} + } func build() { - if (this.source == EChatSource.ME) { - ChatMessageMe(message: this.message)} - else {ChatMessageYou(message: this.message)} + Row() { + this.matchSource() } } } diff --git a/entry/src/main/cangjie/src/components/home/HomeMain.cj b/entry/src/main/cangjie/src/components/home/HomeMain.cj index 05626a9..b86e742 100644 --- a/entry/src/main/cangjie/src/components/home/HomeMain.cj +++ b/entry/src/main/cangjie/src/components/home/HomeMain.cj @@ -8,12 +8,17 @@ internal import ohos.component.* internal import ohos.state_manage.* import ohos.state_macro_manage.* import ohos_app_cangjie_entry.components.chat.ChatList +import ohos_app_cangjie_entry.mock.* +import ohos_app_cangjie_entry.types.ChatData @Component public class HomeMain { + @State + var mockData: ObservedArray = ObservedArray(genMockData()) + func build() { Column { - ChatList() + ChatList(datasource: this.mockData) }.width(100.percent).height(100.percent).padding(right: 8.vp, left: 8.vp) } } diff --git a/entry/src/main/cangjie/src/mock/Data.cj b/entry/src/main/cangjie/src/mock/Data.cj new file mode 100644 index 0000000..546d8d9 --- /dev/null +++ b/entry/src/main/cangjie/src/mock/Data.cj @@ -0,0 +1,27 @@ +/** + * Created on 2024/9/15 + */ +package ohos_app_cangjie_entry.mock + +import std.collection.* +import ohos_app_cangjie_entry.types.ChatData + +public func genMockData() { + Array( + 20, + { + index: Int => ChatData( + message: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf", + source: getSource(index) + ) + } + ) +} + +func getSource(index: Int): String { + if (index % 2 == 0) { + 'ME' + } else { + 'YOU' + } +} diff --git a/entry/src/main/cangjie/src/store/ChatStore.cj b/entry/src/main/cangjie/src/store/ChatStore.cj new file mode 100644 index 0000000..5665048 --- /dev/null +++ b/entry/src/main/cangjie/src/store/ChatStore.cj @@ -0,0 +1,24 @@ +/** + * Created on 2024/9/15 + */ +package ohos_app_cangjie_entry.store + +internal import ohos.state_manage.* +internal import ohos.base.* +import ohos.state_macro_manage.* +import ohos_app_cangjie_entry.types.ChatData +import ohos_app_cangjie_entry.mock.genMockData + +@Observed +public class ChatStore { + @Publish + private var chatDataList: ObservedArray = ObservedArray() + + func initChatStore() { + this.chatDataList = ObservedArray(genMockData()) + } + + func getChatDataList() { + return this.chatDataList + } +} diff --git a/entry/src/main/cangjie/src/types/ChatData.cj b/entry/src/main/cangjie/src/types/ChatData.cj new file mode 100644 index 0000000..296e8f0 --- /dev/null +++ b/entry/src/main/cangjie/src/types/ChatData.cj @@ -0,0 +1,8 @@ +/** + * Created on 2024/9/15 + */ +package ohos_app_cangjie_entry.types + +public struct ChatData { + public ChatData(public let message!: String, public let source!: String) {} +}