背景:
前幾篇學習了元服務,后面幾期就讓我們開發簡單的元服務吧,里面豐富的內容大家自己加,本期案例 僅供參考
先上本期效果圖 ,里面圖片自行替換
效果圖1完整代碼案例如下:
import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { promptAction } from '@kit.ArkUI';@Entry
@ComponentV2
struct Index {build() {Scroll() {Column({ space: 8 }) {Text($r('app.string.EntryAbility_label')).textAlign(TextAlign.Center).width('100%').fontSize(28).fontColor(Color.Black).fontWeight(FontWeight.Bold)Column({ space: 5 }) {Text('一、按教育階段分類').text1()Text('1、學前教育').text3()Text('?服務咨詢:親子早教、幼兒園教育').text2()Text('2、中小學教育').text3()Text('?服務咨詢:小學、初中、高中教育').text2()Text('3、高等教育').text3()Text('?服務咨詢:專科、本科、研究生教育').text2()Text('二、按學科領域分類').text1()Text('1、外語培訓').text3()Text('?服務咨詢:英語培訓、小語種培訓').text2()Text('2、學科輔導').text3()Text('?服務咨詢:理科輔導、文科輔導').text2()Text('3、藝術培訓').text3()Text('?服務咨詢:音樂、舞蹈、美術培訓').text2()Text('三、按技能領域分類').text1()Text('1、計算機與信息技術培訓').text3()Text('?服務咨詢:編程培訓、軟件應用培訓、網絡技術與信息安全培訓').text2()}.width('100%').alignItems(HorizontalAlign.Start)}.onClick(() => {promptAction.showToast({ message: '當前城市暫不支持此服務,請耐心等待后續開通...' })}).height('100%').width('100%').alignItems(HorizontalAlign.Start).padding(12)}.height('100%').width('100%')}aboutToAppear() {hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');this.loginWithHuaweiID();}/*** Sample code for using HUAWEI ID to log in to atomic service.* According to the Atomic Service Review Guide, when a atomic service has an account system,* the option to log in with a HUAWEI ID must be provided.* The following presets the atomic service to use the HUAWEI ID silent login function.* To enable the atomic service to log in successfully using the HUAWEI ID, please refer* to the HarmonyOS HUAWEI ID Access Guide to configure the client ID and fingerprint certificate.*/private loginWithHuaweiID() {// Create a login request and set parameterslet loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();// Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI IDloginRequest.forceLogin = false;// Execute login requestlet controller = new authentication.AuthenticationController();controller.executeRequest(loginRequest).then((data) => {let loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;let authCode = loginWithHuaweiIDResponse.data?.authorizationCode;// Send authCode to the backend in exchange for unionID, session}).catch((error: BusinessError) => {hilog.error(0x0000, 'testTag', 'error: %{public}s', JSON.stringify(error));if (error.code == authentication.AuthenticationErrorCode.ACCOUNT_NOT_LOGGED_IN) {// HUAWEI ID is not logged in, it is recommended to jump to the login guide page}});}
}@Extend(Text)
function text1() {.fontSize(24).fontColor(Color.White).fontWeight(FontWeight.Bold).backgroundColor('#788DF9').padding(5).borderRadius(6)
}@Extend(Text)
function text2() {.fontSize(16).fontColor(Color.Black).margin({ left: 24 }).borderWidth(2).borderRadius(5).borderColor('#CCC8F6').padding(3)
}@Extend(Text)
function text3() {.fontSize(20).fontColor(Color.Black).fontWeight(FontWeight.Bold).margin({ left: 12 })
}
最近文章>>>>>>>>>>>
HarmonyOS NEXT實戰:元服務與應用 APP 發布應用市場的詳細步驟與流程
若本文對您稍有幫助,誠望您不吝點贊,多謝。
有興趣的同學可以點擊查看源碼
- gitee:https://gitee.com/jiaojiaoone/explore-harmony-next/tree/case%2Fwanandroid/
- github:https://github.com/JasonYinH/ExploreHarmonyNext.git