feat: add data store
This commit is contained in:
parent
71ee06965c
commit
891915b386
|
@ -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": [
|
||||
{
|
||||
|
|
|
@ -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<String> = Array<String>(20, item: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf")
|
||||
@Prop
|
||||
var datasource: ObservedArray<ChatData>
|
||||
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ChatData> = ObservedArray<ChatData>(genMockData())
|
||||
|
||||
func build() {
|
||||
Column {
|
||||
ChatList()
|
||||
ChatList(datasource: this.mockData)
|
||||
}.width(100.percent).height(100.percent).padding(right: 8.vp, left: 8.vp)
|
||||
}
|
||||
}
|
||||
|
|
27
entry/src/main/cangjie/src/mock/Data.cj
Normal file
27
entry/src/main/cangjie/src/mock/Data.cj
Normal file
|
@ -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<ChatData>(
|
||||
20,
|
||||
{
|
||||
index: Int => ChatData(
|
||||
message: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf",
|
||||
source: getSource(index)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
func getSource(index: Int): String {
|
||||
if (index % 2 == 0) {
|
||||
'ME'
|
||||
} else {
|
||||
'YOU'
|
||||
}
|
||||
}
|
24
entry/src/main/cangjie/src/store/ChatStore.cj
Normal file
24
entry/src/main/cangjie/src/store/ChatStore.cj
Normal file
|
@ -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<ChatData> = ObservedArray<ChatData>()
|
||||
|
||||
func initChatStore() {
|
||||
this.chatDataList = ObservedArray<ChatData>(genMockData())
|
||||
}
|
||||
|
||||
func getChatDataList() {
|
||||
return this.chatDataList
|
||||
}
|
||||
}
|
8
entry/src/main/cangjie/src/types/ChatData.cj
Normal file
8
entry/src/main/cangjie/src/types/ChatData.cj
Normal file
|
@ -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) {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user