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

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

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

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

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

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

背景

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

轉(zhuǎn)碼工具包

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

export default {
/**
* 10進(jìn)制轉(zhuǎn)16進(jìn)制,并補(bǔ)零
* @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進(jìn)制轉(zhuǎn)10進(jìn)制
* @param num
*/
hex2dex: function (numStr: string) {
console.log(JS_TAG + 'hex2dex ' + numStr)
return parseInt(numStr, 16).toString()
},
/**
* 16進(jìn)制轉(zhuǎn)2進(jìn)制
* @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進(jìn)制轉(zhuǎn)16進(jìn)制
* @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進(jìn)制轉(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進(jìn)制
* @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ī)劃好公用方法,這樣即降低了維護(hù)成本,又能做到代碼復(fù)用。eTS的組件事件與VUE框架大體相同,但也有略微的差異,比如Textarea的值綁定是通過onChange事件來獲取的,在不確定時定可以多看官方組件文檔。

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

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

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

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

2022-11-02 15:49:45

應(yīng)用開發(fā)鴻蒙

2022-11-11 09:37:58

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

2022-03-02 16:08:31

Harmony應(yīng)用開發(fā)鴻蒙

2022-10-08 16:19:40

智能喂食器鴻蒙

2022-11-04 14:58:59

應(yīng)用開發(fā)鴻蒙

2023-08-17 15:04:22

2022-10-08 16:26:23

APP應(yīng)用開發(fā)

2022-02-17 18:08:04

OpenHarmon應(yīng)用開發(fā)鴻蒙

2023-04-07 09:20:55

2022-02-15 14:06:36

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

2023-03-09 15:10:49

應(yīng)用開發(fā)鴻蒙

2023-07-31 17:35:31

ArkTS鴻蒙

2022-02-24 16:39:41

OpenHarmonNiobe開發(fā)鴻蒙

2024-07-26 16:39:33

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

2023-08-10 17:14:52

鴻蒙自定義彈窗

2023-05-16 14:45:42

應(yīng)用開發(fā)鴻蒙

2022-04-18 10:37:01

鴻蒙操作系統(tǒng)開發(fā)工具

2014-12-17 10:29:59

混合應(yīng)用Hybrid App開發(fā)實戰(zhàn)

2023-04-21 15:54:08

應(yīng)用開發(fā)鴻蒙

2022-10-12 15:00:02

設(shè)備開發(fā)應(yīng)用開發(fā)
點贊
收藏

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

主站蜘蛛池模板: 国产成人99久久亚洲综合精品 | 视频三区 | 成人精品毛片国产亚洲av十九禁 | 欧美一区二区在线观看 | 日本福利在线观看 | 在线免费中文字幕 | 999热精品视频| 精品视频一区在线 | 国产免费xxx | 国产日韩久久 | 国产一区二区三区在线看 | 精品久久久久久久 | 国产精品日本一区二区在线播放 | 精品丝袜在线 | 亚洲精品91| 日韩三级在线观看 | 涩涩鲁亚洲精品一区二区 | 日韩二三区 | 亚洲国产精品人人爽夜夜爽 | 56pao在线 | 射久久| 国产精品黄色 | 国产日韩一区二区三免费高清 | 国产午夜精品一区二区三区嫩草 | 在线四虎 | 美美女高清毛片视频免费观看 | 午夜欧美一区二区三区在线播放 | 97精品国产97久久久久久免费 | 日日干夜夜干 | 久久久久一区二区三区四区 | 免费观看黄网站 | 国产精品久久久久久久久久久久久 | 精品久久电影 | 在线国产一区二区 | 欧美最猛黑人xxxx黑人 | 日韩国产一区二区三区 | 欧美日韩在线观看视频 | 免费高清成人 | 日韩精品一区二区三区视频播放 | 高清久久| www.色婷婷 |