Compare commits

..

No commits in common. "470c66a61256e94049425fc0c6749b82d6eb53d0" and "b9cd46db5e1a16904f16bc130a45c928b43e41dd" have entirely different histories.

14 changed files with 20 additions and 262 deletions

View File

@ -1,8 +0,0 @@
{
"color": [
{
"name": "bg_01",
"value": "#F2F3F5"
}
]
}

View File

@ -1,19 +1,6 @@
{ {
"app": { "app": {
"signingConfigs": [ "signingConfigs": [
{
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "C:\\Users\\wps\\.ohos\\config\\default_himi_ZikZBgBxljB_K_Bxk-D2cAAnn7PtvbqmLsGmCt8Tywc=.cer",
"storePassword": "0000001B9A5987C8C2ED4361B7927D584652F717FF7936EC3310D0B9BCEEA9B1E3485C8480FF92C40CA86E",
"keyAlias": "debugKey",
"keyPassword": "0000001BC10C705923EBF5BFF9E770159DFBE2DD5E92BD7DCC5F78CCF2629A20BA2BD3177C275B83ADB93F",
"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": [
{ {

View File

@ -6,28 +6,18 @@ package ohos_app_cangjie_entry.components.chat
internal import ohos.component.* internal import ohos.component.*
internal import ohos.state_manage.* internal import ohos.state_manage.*
internal import ohos.base.* internal import ohos.base.*
import std.collection.*
import ohos.state_macro_manage.* import ohos.state_macro_manage.*
import ohos_app_cangjie_entry.mock.* import ohos_app_cangjie_entry.mock.*
import ohos_app_cangjie_entry.types.ChatData import ohos_app_cangjie_entry.types.ChatData
import ohos_app_cangjie_entry.utils.Logger
import ohos_app_cangjie_entry.view_model.ChatListControl
@Component @Component
public class ChatList { public class ChatList {
let TAG: String = "ChatList"
@Prop @Prop
var datasource: ArrayList<ChatData> var datasource: ObservedArray<ChatData>
let scrollerForList = Scroller()
protected func aboutToAppear() {
Logger(TAG).info("About to Appear")
ChatListControl().setScrollerForList(this.scrollerForList)
}
func build() { func build() {
Column { Column {
List(space: 20, initialIndex: Int32(this.datasource.size - 1), scroller: this.scrollerForList) { List(space: 20, initialIndex: 0) {
ForEach( ForEach(
this.datasource, this.datasource,
itemGeneratorFunc: { itemGeneratorFunc: {
@ -37,7 +27,7 @@ public class ChatList {
source: item.source, source: item.source,
) )
} }
}, }
) )
} }
}.height(100.percent).width(100.percent).padding(top: 5.vp) }.height(100.percent).width(100.percent).padding(top: 5.vp)

View File

@ -19,9 +19,6 @@ public enum EChatSource {
} }
} }
/**
* 只限定UI
**/
@Component @Component
public class ChatMessage { public class ChatMessage {
@Prop @Prop

View File

@ -7,60 +7,12 @@ internal import ohos.base.*
internal import ohos.component.* internal import ohos.component.*
internal import ohos.state_manage.* internal import ohos.state_manage.*
import ohos.state_macro_manage.* import ohos.state_macro_manage.*
import ohos_app_cangjie_entry.utils.Logger
import ohos_app_cangjie_entry.store.ChatStore
import ohos_app_cangjie_entry.types.ChatData
import ohos_app_cangjie_entry.view_model.ChatListControl
@Component @Component
public class HomeBottom { public class HomeBottom {
let TAG: String = "HomeBottom"
@State
var isPedding: Bool = false
@State
var inputText: String = ""
let inputPlaceHolder: String = "有什么问题尽管问我"
let inputController = TextInputController()
protected func aboutToAppear() {
Logger(TAG).info("About to appear.")
}
func submitInput() {
if (this.inputText == "") {
return
}
if (this.isPedding) {
// 处理正在等待的情况
return
}
this.isPedding = true
ChatStore().add(
ChatData(
id: ChatStore().genID(),
message: this.inputText,
source: 'ME',
)
)
this.inputText = ""
this.isPedding = false
ChatListControl().toBottom()
}
func build() { func build() {
Row { Row {
TextInput( Text("HomeBottom")
text: this.inputText,
placeholder: this.inputPlaceHolder,
controller: this.inputController,
).onChange {
value => this.inputText = value
}.onSubmit {
_ => this.submitInput()
}
}.width(100.percent) }.width(100.percent)
} }
} }

View File

@ -6,28 +6,15 @@ package ohos_app_cangjie_entry.components.home
internal import ohos.base.* internal import ohos.base.*
internal import ohos.component.* internal import ohos.component.*
internal import ohos.state_manage.* internal import ohos.state_manage.*
import ohos_app_cangjie_entry.utils.Logger
import ohos.state_macro_manage.* import ohos.state_macro_manage.*
import ohos_app_cangjie_entry.components.chat.ChatList import ohos_app_cangjie_entry.components.chat.ChatList
import ohos_app_cangjie_entry.mock.* import ohos_app_cangjie_entry.mock.*
import ohos_app_cangjie_entry.types.ChatData import ohos_app_cangjie_entry.types.ChatData
import std.collection.*
import ohos_app_cangjie_entry.store.ChatStore
import ohos_app_cangjie_entry.view_model.ChatListControl
@Component @Component
public class HomeMain { public class HomeMain {
let TAG: String = "HomeMain"
@State @State
var mockData: ArrayList<ChatData> = ChatStore().use() var mockData: ObservedArray<ChatData> = ObservedArray<ChatData>(genMockData())
let chatListController = ChatListControl()
protected func aboutToAppear(): Unit {
Logger(TAG).info("About to appear.")
ChatStore().register(this.TAG) {
this.mockData = ChatStore().use()
}
}
func build() { func build() {
Column { Column {

View File

@ -19,6 +19,6 @@ class MyView {
func build() { func build() {
Row { Row {
HomePage() HomePage()
}.height(100.percent).width(100.percent).backgroundColor(@r(app.color.bg_01)) }.height(100.percent).width(100.percent)
} }
} }

View File

@ -11,7 +11,6 @@ public func genMockData() {
20, 20,
{ {
index: Int => ChatData( index: Int => ChatData(
id: index.toString(),
message: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf", message: "teststesstasdasdasdadasdasdsaesrfsfdfsfdsf",
source: getSource(index) source: getSource(index)
) )

View File

@ -9,20 +9,16 @@ import ohos.state_macro_manage.*
internal import ohos.component.* internal import ohos.component.*
internal import ohos.state_manage.* internal import ohos.state_manage.*
internal import ohos.base.* internal import ohos.base.*
import ohos_app_cangjie_entry.store.ChatStore
@Component @Component
public class HomePage { public class HomePage {
private let TAG = "HomePage" private let TAG = "HomePage"
protected func aboutToAppear() { protected func aboutToAppear() {
ChatStore().initStore()
} }
func build() { func build() {
Column(10) { Column(10) {
HomeTitle() HomeTitle()
Column {
HomeMain() HomeMain()
}.layoutWeight(1)
HomeBottom() HomeBottom()
}.width(100.percent).height(100.percent) }.width(100.percent).height(100.percent)
} }

View File

@ -8,62 +8,17 @@ internal import ohos.base.*
import ohos.state_macro_manage.* import ohos.state_macro_manage.*
import ohos_app_cangjie_entry.types.ChatData import ohos_app_cangjie_entry.types.ChatData
import ohos_app_cangjie_entry.mock.genMockData import ohos_app_cangjie_entry.mock.genMockData
import std.collection.*
import ohos_app_cangjie_entry.utils.Logger
@Observed
public class ChatStore { public class ChatStore {
private let TAG: String = "ChatStore" @Publish
private static let chatDataList: ArrayList<ChatData> = ArrayList<ChatData>() private var chatDataList: ObservedArray<ChatData> = ObservedArray<ChatData>()
private static let observers: HashMap<String, () -> Unit> = HashMap<String, () -> Unit>()
public func initStore() { func initChatStore() {
ChatStore.chatDataList.appendAll(genMockData()) this.chatDataList = ObservedArray<ChatData>(genMockData())
} }
public func genID() { func getChatDataList() {
return chatDataList.size.toString() return this.chatDataList
}
public func len() {
return chatDataList.size
}
public func use() {
return ChatStore.chatDataList.clone()
}
public func resetStore() {
ChatStore.chatDataList.clear()
}
public func register(id: String, action: () -> Unit) {
if (observers.contains(id)) {
Logger(TAG).warn("this id: ${id} is existed.")
}
ChatStore.observers[id] = action
return this
}
public func unregister(id: String) {
ChatStore.observers.remove(id)
return this
}
public func add(chatData: ChatData) {
chatDataList.append(chatData)
this.onUpdate()
return this
}
public func remove(chatData: ChatData) {
chatDataList.removeIf {item => item == chatData}
this.onUpdate()
return this
}
private func onUpdate() {
ChatStore.observers.values().iterator().forEach {
action => action()
}
} }
} }

View File

@ -1,17 +0,0 @@
/**
* Created on 2024/9/19
*/
package ohos_app_cangjie_entry.support.support_database
import ohos.preferences.*
internal import ohos.ability.*
internal import ohos.window.*
import ohos.base.*
public class PreferencesStore {
private let context: AbilityContext
public init(context: AbilityContext) {
this.context = context
}
}

View File

@ -3,48 +3,6 @@
*/ */
package ohos_app_cangjie_entry.types package ohos_app_cangjie_entry.types
import serialization.serialization.* public struct ChatData {
import std.math.* public ChatData(public let message!: String, public let source!: String) {}
import encoding.json.*
public class ChatData <: Serializable<ChatData> {
public ChatData(public let id!: String, public let message!: String, public let source!: String) {}
public operator func ==(right: ChatData) {
return (
this.id == right.id
&& this.message == right.message
&& this.source == right.source
)
}
public func serialize(): DataModel {
return (
DataModelStruct()
.add(field<String>('id', id))
.add(field<String>('message', message))
.add(field<String>('source', source))
)
}
public static func deserialize(dm: DataModel): ChatData {
let dms = match (dm) {
case data: DataModelStruct => data
case _ => throw Exception("this data is not DataModelStruct")
}
ChatData(
id: String.deserialize(dms.get('id')),
message: String.deserialize(dms.get('message')),
source: String.deserialize(dms.get('source')),
)
}
public func toString(): String {
this.serialize().toJson().toString()
}
public static func fromString(s: String): ChatData {
let jsonObj = JsonValue.fromStr(s)
ChatData.deserialize(DataModel.fromJson(jsonObj))
}
} }

View File

@ -3,26 +3,16 @@
*/ */
package ohos_app_cangjie_entry.utils package ohos_app_cangjie_entry.utils
internal import ohos.base.*
public class Logger { public class Logger {
private let TAG: String private let TAG: String
public init(TAG: String) { public init(TAG: String) {
this.TAG = TAG + ": " this.TAG = TAG + ": "
} }
public func debug(msg: String) { public func debug(msg: String) {}
AppLog.debug(this.TAG + msg)
}
public func error(msg: String) { public func error(msg: String) {}
AppLog.error(this.TAG + msg)
}
public func info(msg: String) { public func info(msg: String) {}
AppLog.info(this.TAG + msg)
}
public func warn(msg: String) { public func warn(msg: String) {}
AppLog.warn(this.TAG + msg)
}
} }

View File

@ -1,28 +0,0 @@
/**
* Created on 2024/9/18
*/
package ohos_app_cangjie_entry.view_model
internal import ohos.component.Scroller
import ohos_app_cangjie_entry.store.ChatStore
import ohos_app_cangjie_entry.utils.Logger
public class ChatListControl {
private let TAG: String = "ChatListControl"
private static var scrollerForList: ?Scroller = None
private let chatStore = ChatStore()
public func setScrollerForList(scroller: Scroller) {
scrollerForList = scroller
}
public func toBottom(smooth!: Bool = false): Unit {
Logger(TAG).info("toBottom")
scrollerForList?.scrollToIndex(Int32(this.chatStore.len() - 1), smooth: smooth)
}
public func toTop(smooth!: Bool = false): Unit {
Logger(TAG).info("toTop")
scrollerForList?.scrollToIndex(0, smooth: smooth)
}
}