前面已經學習了ArkTs的基本語法和DevEcoStudio的基本操作,接下來按照官方提示開發(fā)一個基本案例。
接下來我來演示如何運行demo。我在demo中加入了自己的注釋。
切記:文件夾不能有中文!這點華為有點不厚道?,F(xiàn)在idea都支持全中文了。
打開后,會自動顯示MD的內容
├──entry/src/main/ets/│├──common││├──constants│││└──//常量類││└──utils││├──//彈窗工具類││├──//日志工具類││└──//算法工具類│├──entryability││└──│├──entrybackupability││└──│├──pages││└──//界面實現(xiàn)│└──view│├──//水仙花數(shù)彈窗實現(xiàn)│├──//閏年判斷數(shù)彈窗實現(xiàn)│├──//回文字符串判斷數(shù)彈窗實現(xiàn)│├──//九九乘法表彈窗實現(xiàn)│└──//字符串反轉彈窗實現(xiàn)└───entry/src/main/resources//應用資源目錄
華為將第一個項目整得太復雜了,如果是新手的話,看到這個項目基本上就是:我是誰,我在哪?
這里面用到了非常多的封裝,例如common的封裝,字符串封裝,單位常量的封裝,包括MVVC的分層結構,作為小白來說,這純純的zhuangB啊。
本地化
其實主要的核心方法都是一個ets文件里面,做了封裝。
/**Copyright(c)2024HuaweiDeviceCo.,Ltd.*LicensedundertheApacheLicense,(the"License");*youmaynotusethisfileexceptincompliancewiththeLicense.*YoumayobtainacopyoftheLicenseat****Unlessrequiredbyapplicablelaworagreedtoinwriting,software*distributedundertheLicenseisdistributedonan"ASIS"BASIS,*WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.*SeetheLicenseforthespecificlanguagegoverningpermissionsand*limitationsundertheLicense.*///水仙花數(shù)字exportfunctiondaffodilsNumber():number[]{letresult:number[]=[];for(leti=100;i1000;i++){letunitsDigit:number=i%10;lettenthsDigit:number=(i/10)-(i/100)*10;lethundredthsDigit:number=(i/100);if(i===unitsDigit*unitsDigit*unitsDigit+tenthsDigit*tenthsDigit*tenthsDigit+hundredthsDigit*hundredthsDigit*hundredthsDigit){(i);}}returnresult;}//乘法口訣表exportfunctionmultiplicationTable():string[][]{letresult:string[][]=[];for(leti=1;i=9;i++){letindex:string[]=[];for(letj=1;j=i;j++){lettemp:string=j+'*'+i+'='+i*j;(temp);}(index);}returnresult;}//是否回文exportfunctionisPalindromicString(content:string):boolean{letresult:boolean=true;leti:number=0;letj:number=;while(i=j){if((i)!==(j)){result=false;break;}i++;j--;}returnresult;}//字符串反轉exportfunctionstringReversal(content:string):string{letresult:string='';for(letindex=;index=0;index--){result+=(index);}returnresult;}//是否閏年exportfunctionisLeapYear(year:number):boolean{letresult:boolean=false;if((year%4===0year%100!==0)||(year%400===0)){result=true;}else{result=false;}returnresult;}
華為不地道,真的不地道,所有的代碼完全沒有一點中文,這上面的出現(xiàn)的中文注釋都是我加進去的。
下面來看看閏年是如何寫的代碼
還是一樣,中文注釋都是我加進去的。里面沒有出現(xiàn)任何一個中文字符。
總結:
華為鴻蒙next開發(fā)可能太希望能做標準化了,作為新手入門的第一個項目,基本上所有的代碼都封裝了,非常標準,分層,本地化都做到了,但是這能入門嗎?
如果作為一個老鳥,以后的項目參考這個項目來寫,還是非常有幫助的,如需下載項目,請直接去官網(wǎng)。
需要我的這份也可以,留下email即可發(fā)送。