Open Harmony开发之分布式账本(1),2024年最新HarmonyOS鸿蒙事件分发面试题

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新HarmonyOS鸿蒙全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img

img
img
htt

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注鸿蒙)
img

正文

Text(name)
.fontSize(16)
.fontColor(Color.Black)
Text(‘11:20’)
.fontSize(16)
.fontColor(Color.Gray)
}
.alignItems(HorizontalAlign.Start)
.margin({left:15})

Text(‘HUAWEI’)
.fontSize(12)
.fontColor(Color.Black)
.margin({left:20})

Text(des)
.fontSize(14)
.fontColor(Color.Gray)
.margin({left:15})

Column() {
Text(‘-100’)
.fontSize(16)
.fontColor(Color.Black)
Text(time)
.fontSize(16)
.fontColor(Color.Gray)
}
.alignItems(HorizontalAlign.Start)
.margin({left:20})
}
.width(400)
.height(50)
.margin({top:10})

}

build() {
List() {
ForEach(this.ProjectData, (item) => {
ListItem() {
this.ProjectItem(item.image, item.name, item.des,item.time,item.money)
}
.onClick(() => {
})

}, (item) => JSON.stringify(item)) {

}

}
}
}

底部TabContent 统计模块

@Component
struct Statistics{
build(){
Flex({ direction: FlexDirection.Row}){

Tabs() {
TabContent() {
PayList()
}
.tabBar(“支出分类”)

TabContent() {

}
.tabBar(“成员分类”)
}
}
}
}

统计模块里面的TabContent

@Component
struct PayList {

private PayData: PayBean[] = initializeOnStartup()
@Builder PayItem(previewUrl, title, describe) {
Flex({ direction: FlexDirection.Row,alignItems: ItemAlign.Center }){
Image(previewUrl)
.width(30)
.height(30)

Text(title)
.fontSize(16)
.fontColor(Color.Black)
.margin({left:8})

Text(‘100%’)
.fontSize(12)
.fontColor(Color.Black)
.margin({left:8})

Progress({ value: 20, total: 150, style: ProgressStyle.Linear }).color(Color.Red).value(150).width(200)

Text(‘-100’)
.fontSize(14)
.fontColor(Color.Gray)
.margin({left:8})
}
.width(400)
.height(50)
.margin({top:10})

}

build() {
List() {
ForEach(this.PayData, (item) => {
ListItem() {
this.PayItem(item.image, item.name, item.des)
}
.onClick(() => {
console.info(“点击我”)
router.push({
uri: “pages/VideoPlayer”,

})
})
}, (item) => JSON.stringify(item)) {

}
}
}
}

2) add.ets页面

build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center}) {

Flex({ direction: FlexDirection.Row,alignItems: ItemAlign.Center})
{
Image(“/picture/icon_back.png”)
.width(35)
.height(35)
.onClick(() =>{
router.push({
uri: “pages/index”,

})
})

Text(“加一笔”)
.fontSize(20)
.fontWeight(FontWeight.Bold)
.margin({left:20})
}.margin({top:10})
.padding({left:20})
.height(100)
.width(500)
Stack({
alignContent: Alignment.TopStart
}){
Tabs() {
TabContent() {
pay({payTime: s t r T i m e , p a y R e m a r k : strTime,payRemark: strTime,payRemark:strRemark,payType:$strType})
}
.tabBar(“支出”)

TabContent() {
Income()
}
.tabBar(“收入”)
}
.height(450)
}.width(500)
.height(500)
Flex({
direction: FlexDirection.Row,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center
}){
Text(“输入金额”)
.fontColor(Color.Black)
.fontSize(20)
.margin({
right:15
})
.width(100)
TextInput({ placeholder: ‘100’, text:this.strMoney })
.type(InputType.Normal)
.placeholderColor(Color.Gray)
.placeholderFont({ size: 20, weight: 2})
.enterKeyType(EnterKeyType.Search)
.caretColor(Color.Green)
.width(250)
.height(40)
.borderRadius(‘20px’)
}
.width(400)
.height(50)

Text(‘保存’)
.fontColor(Color.White)
.fontSize(20)
.margin({
top:20
})
.textAlign(TextAlign.Center)
.width(380)
.height(80)
.backgroundColor(“#FE4F16”)
.onClick(() =>{

TestData.push({image:“/picture/icon1.png”,title:‘canyin’,des:‘ceshi’,time:‘2021’,money:‘50’})
if (AppStorage.Get(“key1”) == null) {
AppStorage.SetAndLink(“key1”, TestData)
this.remoteDataManager.dataChange(“key2”, JSON.stringify(TestData))
}else{
this.TestStorageData = AppStorage.Get(“key1”)
//
// this.TestStorageData.push({image:“/picture/icon1.png”,title:‘canyin’,des:‘beizhu’,time:‘2021’,money:‘50’})
//具体代码
this.TestStorageData.push({image:“/picture/icon1.png”,title:this.strType,des:this.strRemark,time:this.strTime,money:this.strMoney})
AppStorage.SetAndLink(“key1”, this.TestStorageData)
let str = JSON.stringify(this.TestStorageData)
this.TestKvData = JSON.parse(str)
this.remoteDataManager.dataChange(“key2”, JSON.stringify(this.TestKvData))
}
router.push({
uri: “pages/index”,

})
})

}
.width(‘100%’)
.height(‘100%’)
}

add页面支出模块

@Component
struct pay{
@Link payTime:string
@Link payRemark:string
@Link payType:string
@State private index:number = 0
@State strType:string = “canyin”
@State AccountData: Array = [
{ previewUrl: “/picture/icon1.png”, title: “canyin” ,number:0},
{ previewUrl: “/picture/icon2_2.png”, title: “gouwu” ,number:1},
{ previewUrl: “/picture/icon3_3.png”, title: “jiaotong” ,number:2},
{ previewUrl: “/picture/icon4_4.png”, title: “fuwu” ,number:3},
{ previewUrl: “/picture/icon5_5.png”, title: “jiaoyu” ,number:4},
{ previewUrl: “/picture/icon6_6.png”, title: “yundong” ,number:5},
{ previewUrl: “/picture/icon7_7.png”, title: “luxing” ,number:6},
{ previewUrl: “/picture/icon8_8.png”, title: “yiliao” ,number:7},
// { previewUrl: “/picture/icon9_9.png”, title: “生活” ,number:9},
// { previewUrl: “/picture/icon10_10.png”, title: “宠物” ,number:10},
]

@Builder ProItem(previewUrl, title,number) {
Stack() {
Flex({
direction: FlexDirection.Column
}) {
if (this.index == number) {
if (number == 0) {
Image(“/picture/icon1.png”)
.width(60)
.height(60)
}else if (number == 1) {
Image(“/picture/icon2.png”)
.width(60)
.height(60)

}else if (number == 2) {
Image(“/picture/icon3.png”)
.width(60)
.height(60)

}else if (number == 3) {
Image(“/picture/icon4.png”)
.width(60)
.height(60)
}else if (number == 4) {
Image(“/picture/icon5.png”)
.width(60)
.height(60)

}else if (number == 5) {
Image(“/picture/icon6.png”)
.width(60)
.height(60)

}else if (number == 6) {
Image(“/picture/icon7.png”)
.width(60)
.height(60)
}else if (number == 7) {
Image(“/picture/icon8.png”)
.width(60)
.height(60)
}else if (number == 8) {
Image(“/picture/icon9.png”)
.width(60)
.height(60)
}else if (number == 9) {
Image(“/picture/icon10.png”)
.width(60)
.height(60)
}
}else{
if (number == 0) {
Image(“/picture/icon1_1.png”)
.width(60)
.height(60)
}else{
Image(previewUrl)
.width(60)
.height(60)
}

}
Column() {
Text(title)
.fontSize(16)
.fontColor(Color.Black)
}
.alignItems(HorizontalAlign.Center)
}

}
.height(100)
.width(100)
.margin({
bottom: 16
})

}
build(){
Flex({direction: FlexDirection.Column}){

Grid(){
ForEach(this.AccountData, (item) => {
GridItem() {
this.ProItem(item.previewUrl, item.title,item.number)
}
.onClick(() => {
console.info(“点击我”)
this.index = item.number
this.payType = this.AccountData[this.index].title
})
}, (item) => JSON.stringify(item)) {

}
}
.rowsTemplate(‘1fr 1fr’)
.columnsTemplate(‘1fr 1fr 1fr 1fr’)
.columnsGap(8)
.rowsGap(8)
.height(200)
// Time()
// Remark()
// 时间****
Flex({
direction: FlexDirection.Row,alignItems: ItemAlign.Center
}){
Text(“时间”)
.fontColor(Color.Black)
.fontSize(20)
.margin({
right:15
})
.width(70)

TextInput({ placeholder: ‘输入收支时间’, text: this.payTime })
.type(InputType.Normal)
.placeholderColor(Color.Gray)
.placeholderFont({ size: 20, weight: 2})
.enterKeyType(EnterKeyType.Search)
.caretColor(Color.Green)
.width(300)
.height(40)
.borderRadius(‘20px’)
.backgroundColor(Color.White)
.onChange((value: string) => {
this.payTime = value
})

}
.margin({
top:20,left:15
})
.width(200)
//备注*
Flex({
direction: FlexDirection.Row,alignItems: ItemAlign.Center
}){
Text(“备注”)
.fontColor(Color.Black)
.fontSize(20)
.margin({
right:15
})
.width(70)

TextInput({ placeholder: ‘输入说明’, text: this.payRemark })
.type(InputType.Normal)
.placeholderColor(Color.Gray)
.placeholderFont({ size: 20, weight: 2})
.enterKeyType(EnterKeyType.Search)
.caretColor(Color.Green)
// .layoutWeight(8)
.height(40)
.width(300)
.borderRadius(‘20px’)
.backgroundColor(Color.White)
.onChange((value: string) => {
this.payRemark = value
})
}
.margin({
top:20,left:15
})
.width(50)
.height(50)
}
.height(‘100%’)
.layoutWeight(1)

}
}

收入模块代码

@Component
struct Income{

build(){
Flex({direction: FlexDirection.Column}){
Time()
Remark()

}
}
}

时间模块

@Component
struct Time{
@State inputTime:string = ‘’
build(){
Flex({
direction: FlexDirection.Row,alignItems: ItemAlign.Center
}){
Text(“时间”)
.fontColor(Color.Black)
.fontSize(20)
.margin({
right:15
})
.width(70)

TextInput({ placeholder: ‘2021’, text: this.inputTime })
.type(InputType.Normal)
.placeholderColor(Color.Gray)
.placeholderFont({ size: 20, weight: 2})
.enterKeyType(EnterKeyType.Search)
.caretColor(Color.Green)
.width(300)
.height(40)
.borderRadius(‘20px’)
.backgroundColor(Color.White)
}
.margin({
top:20,left:15
})
.width(200)
}
}

备注模块

@Component
struct Remark{
@State inputRemark:string = ‘’
build(){
Flex({
direction: FlexDirection.Row,alignItems: ItemAlign.Center
}){
Text(“备注”)
.fontColor(Color.Black)
.fontSize(20)
.margin({
right:15
})
.width(70)

TextInput({ placeholder: ‘ceshe’, text: this.inputRemark })
.type(InputType.Normal)
.placeholderColor(Color.Gray)
.placeholderFont({ size: 20, weight: 2})
.enterKeyType(EnterKeyType.Search)
.caretColor(Color.Green)
// .layoutWeight(8)
.height(40)
.width(300)
.borderRadius(‘20px’)
.backgroundColor(Color.White)

}
.margin({
top:20,left:15
})
.width(50)
.height(50)

}
}

3.设备认证

设备认证是依赖 DeviceManager 组件来实现的,详细代码参考源码RemoteDeviceModel.ets

1.创建DeviceManager实例

registerDeviceListCallback(callback) {
if (typeof (this.#deviceManager) === ‘undefined’) {
deviceManager.createDeviceManager(‘com.example.tictactoegame’, (error, value) => {
if (error) return
this.#deviceManager = value;
this.registerDeviceListCallback_(callback);
});
} else {
this.registerDeviceListCallback_(callback);
}
}

2.查询可信设备列表

var list = this.#deviceManager.getTrustedDeviceListSync();
if (typeof (list) != ‘undefined’ && typeof (list.length) != ‘undefined’) {
this.deviceList = list;
}

3.注册设备上下线监听

this.#deviceManager.on(‘deviceStateChange’, (data) => {
switch (data.action) {
case 0:
this.deviceList[this.deviceList.length] = data.device;
this.callback();
if (this.authCallback != null) {
this.authCallback();
this.authCallback = null;
}
break;
case 2:
if (this.deviceList.length > 0) {
for (var i = 0; i < this.deviceList.length; i++) {
if (this.deviceList[i].deviceId === data.device.deviceId) {
this.deviceList[i] = data.device;
break;
}
}
}
this.callback();
break;
case 1:
if (this.deviceList.length > 0) {
var list = [];
for (var i = 0; i < this.deviceList.length; i++) {
if (this.deviceList[i].deviceId != data.device.deviceId) {
list[i] = data.device;
}
}
this.deviceList = list;
}
this.callback();
break;
default:
break;
}
});

4.设备发现

this.#deviceManager.on(‘deviceFound’, (data) => {
for (let i = 0; i < this.discoverList.length; i++) {
if (that.discoverList[i].deviceId === data.device.deviceId) {
return;
}
}
this.discoverList[this.discoverList.length] = data.device;
this.callback();
});

5.设备认证

authDevice(deviceInfo, callback){
let extraInfo = {
“targetPkgName”: ‘com.example.tictactoegame’,
“appName”: ‘com.example.tictactoegame’,
“appDescription”: ‘com.example.tictactoegame’,
“business”: ‘0’
};
let authParam = {
“authType”: 1,
“appIcon”: ‘’,
“appThumbnail”: ‘’,
“extraInfo”: extraInfo
};
this.#deviceManager.authenticateDevice(deviceInfo, authParam, (err, data) => {
if (err) {
this.authCallback = null;
} else {
this.authCallback = callback;
}
});
}

4.数据管理

分布式数据管理 依赖@ohos.data.distributedData模块实现,详细参考源码RemoteDataManager.ets

1.导入该模块

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注鸿蒙)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

tactoegame’,
“appDescription”: ‘com.example.tictactoegame’,
“business”: ‘0’
};
let authParam = {
“authType”: 1,
“appIcon”: ‘’,
“appThumbnail”: ‘’,
“extraInfo”: extraInfo
};
this.#deviceManager.authenticateDevice(deviceInfo, authParam, (err, data) => {
if (err) {
this.authCallback = null;
} else {
this.authCallback = callback;
}
});
}

4.数据管理

分布式数据管理 依赖@ohos.data.distributedData模块实现,详细参考源码RemoteDataManager.ets

1.导入该模块

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注鸿蒙)
[外链图片转存中…(img-pROnhIdu-1713596246385)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 21
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值