成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

OpenHarmony數(shù)據(jù)轉(zhuǎn)碼應用開發(fā)實戰(zhàn)(中)

系統(tǒng) OpenHarmony
本文將以一個小項目—數(shù)據(jù)轉(zhuǎn)碼應用,來講解應用開發(fā)全流程。

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??

背景

對于剛?cè)腴TOpenHarmony開發(fā)的小伙伴來說,如果有一個合適的實戰(zhàn)項目來練手,對自身的技術(shù)能力提升是非常有幫助的,本文將以一個小項目——數(shù)據(jù)轉(zhuǎn)碼應用,來講解應用開發(fā)全流程。
在《OpenHarmony數(shù)據(jù)轉(zhuǎn)碼應用開發(fā)實戰(zhàn)(上)》中我們講述了項目的需求、設計以及項目創(chuàng)建、UI界面開發(fā),本篇將重點講解轉(zhuǎn)碼工具包的實現(xiàn)和UI組件數(shù)據(jù)綁定。

轉(zhuǎn)碼工具包

編碼時推薦單獨創(chuàng)建包路徑,不要與頁面UI寫在一起,這樣便于維護和代碼的復用。
我們創(chuàng)建/entry/src/main/ets/MainAbility/utils/numConvertUtil.ets,然后在index.ets頁面中引入。工具包將導出一個工具對象,每個方法實現(xiàn)一個轉(zhuǎn)碼需求,代碼如下:

export default {
/**
* 10進制轉(zhuǎn)16進制,并補零
* @param num
* @param len = 2
*/
dec2hex: function (numStr: string, len: number = 2) {
console.log(JS_TAG + 'dec2hex ' + numStr)
let result: string = Number(numStr).toString(16).toUpperCase()
result = this.addZero(result, len)
return result
},
/**
* 16進制轉(zhuǎn)10進制
* @param num
*/
hex2dex: function (numStr: string) {
console.log(JS_TAG + 'hex2dex ' + numStr)
return parseInt(numStr, 16).toString()
},
/**
* 16進制轉(zhuǎn)2進制
* @param num
* @param len
*/
hex2bin: function (numStr: string, len: number = 2) {
let hexNum: number = parseInt(numStr, 16)
let result: string = Number(hexNum).toString(2)
result = this.addZero(result, len)
return result
},
/**
* 2進制轉(zhuǎn)16進制
* @param num
* @param len
*/
bin2hex: function (numStr: string) {
let num: number = parseInt(numStr, 2)
let result: string = Number(num).toString(16)
result = this.addZero(result)
return result
},
/**
* 16進制轉(zhuǎn)ASCII碼
* @param hexCharCodeStr
*/
hex2ascii: function (hexStr: string) {
const tempStr: string = hexStr.trim()
const rawStr: string = tempStr.substr(0, 2).toLowerCase() === '0x' ? tempStr.substr(2) : tempStr
const len: number = rawStr.length
if (len % 2 !== 0) {
return ''
}
let curCharCode
const resultStr = []
for (let i = 0; i < len; i = i + 2) {
curCharCode = parseInt(rawStr.substr(i, 2), 16)
resultStr.push(String.fromCharCode(curCharCode))
}
return resultStr.join('')
},
/**
* ASCII碼轉(zhuǎn)16進制
* @param str
*/
ascii2hex: function (asciiStr: string) {
if (asciiStr === '') {
return ''
} else {
const hexCharCode = []
hexCharCode.push('0x')
for (let i = 0; i < asciiStr.length; i++) {
hexCharCode.push((asciiStr.charCodeAt(i)).toString(16))
}
return hexCharCode.join('')
}
},
addZero: function (numStr: string, len: number = 2) {
const needFill: number = len - numStr.length
let result: string = numStr
if (needFill > 0) {
for (let i = 0; i < needFill; i++) {
result = '0' + result
}
}
return result
}
}

綁定UI組件的事件輸出結(jié)果

引入數(shù)據(jù)轉(zhuǎn)碼工具包

import numConvertUtil from '../utils/numConvertUtil';

綁定按鈕Click事件

Button($r('app.string.btnDec2hex'), { type: ButtonType.Normal })
.width('50%')
.onClick(() => {
this.dec2hex()
})

Textarea數(shù)據(jù)改變事件是onChange,它無法像VUE組件一樣直接通過value綁定獲取,只能通過onChange事件獲取改變后的值。

TextArea()
.width('100%')
.height(180)
.backgroundColor(0x0ffff)
.borderRadius(0)
.onChange((value) => {
this.strInput = value
console.log(this.strInput)
})

Click事件直接調(diào)用工具包

dec2hex() {
this.strEncode = ''
console.log(JS_TAG + this.strInput)
this.strEncode = numConvertUtil.dec2hex(this.strInput)
console.log(JS_TAG + this.strInput + ' ' + this.strEncode)
}
hex2dex() {
this.strEncode = ''
this.strEncode = numConvertUtil.hex2dex(this.strInput)
console.log(JS_TAG + this.strInput + ' ' + this.strEncode)
}
hex2bin() {
this.strEncode = ''
this.strEncode = numConvertUtil.hex2bin(this.strInput)
console.log(JS_TAG + this.strInput + ' ' + this.strEncode)
}
bin2hex() {
this.strEncode = ''
this.strEncode = numConvertUtil.bin2hex(this.strInput)
console.log(JS_TAG + this.strInput + ' ' + this.strEncode)
}
hex2ascii() {
this.strEncode = ''
this.strEncode = numConvertUtil.hex2ascii(this.strInput)
console.log(JS_TAG + this.strInput + ' ' + this.strEncode)
}
ascii2hex() {
this.strEncode = ''
this.strEncode = numConvertUtil.ascii2hex(this.strInput)
console.log(JS_TAG + this.strInput + ' ' + this.strEncode)
}

總結(jié)

在編碼過程中我們要提前規(guī)劃好公用方法,這樣即降低了維護成本,又能做到代碼復用。eTS的組件事件與VUE框架大體相同,但也有略微的差異,比如Textarea的值綁定是通過onChange事件來獲取的,在不確定時定可以多看官方組件文檔。

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??

責任編輯:jianghua 來源: 51CTO開源基礎(chǔ)軟件社區(qū)
相關(guān)推薦

2022-11-11 09:37:58

數(shù)據(jù)轉(zhuǎn)碼應用開發(fā)

2022-11-02 15:49:45

應用開發(fā)鴻蒙

2022-03-02 16:08:31

Harmony應用開發(fā)鴻蒙

2022-11-04 14:58:59

應用開發(fā)鴻蒙

2022-10-08 16:19:40

智能喂食器鴻蒙

2022-02-15 14:06:36

OpenHarmon操作系統(tǒng)鴻蒙

2023-03-09 15:10:49

應用開發(fā)鴻蒙

2023-08-17 15:04:22

2022-10-08 16:26:23

APP應用開發(fā)

2022-02-17 18:08:04

OpenHarmon應用開發(fā)鴻蒙

2024-07-26 16:39:33

鴻蒙系統(tǒng)開源構(gòu)建系統(tǒng)

2022-02-24 16:39:41

OpenHarmonNiobe開發(fā)鴻蒙

2023-08-10 17:14:52

鴻蒙自定義彈窗

2023-04-07 09:20:55

2023-07-31 17:35:31

ArkTS鴻蒙

2023-05-16 14:45:42

應用開發(fā)鴻蒙

2022-02-15 14:45:14

OpenHarmo系統(tǒng)鴻蒙

2023-08-07 15:23:28

鴻蒙首次啟動申請授權(quán)

2024-08-08 15:46:34

2023-08-04 15:00:43

ArkTS語言鴻蒙
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 国产电影一区二区在线观看 | 在线色网址 | 91免费小视频 | 毛片一区二区三区 | 在线看亚洲 | 精品一区二区三区入口 | 久久久久久女 | 亚洲一区二区三区免费在线 | 精品久久久久久 | 亚洲免费在线 | 久久99精品久久久97夜夜嗨 | 欧美在线| 久久亚洲天堂 | 欧美无乱码久久久免费午夜一区 | 人人叉| 亚洲国产精品99久久久久久久久 | 欧美一级久久 | 丁香久久 | 亚洲视频一区在线观看 | 在线婷婷 | 欧美成人精品 | 国产精品成人一区二区三区夜夜夜 | 午夜一区二区三区 | 亚洲视频免费在线观看 | 日韩欧美一区二区三区四区 | 欧美成人黄色小说 | 国精久久 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 中文字幕在线免费 | 中文字幕三区 | 日韩免费毛片视频 | 日韩三级一区 | 国产精品久久久久一区二区三区 | 日韩成人在线视频 | 国产精品视频不卡 | 中文字幕成人 | 日本天天操 | 中文字幕亚洲区一区二 | 日本久久黄色 | 超碰人人人 | 亚洲精品乱码久久久久久按摩 |