背景:
前几篇学习了元服务,后面几期就让我们开发简单的元服务吧,里面丰富的内容大家自己加,本期案例 仅供参考
先上本期效果图 ,里面图片自行替换
效果图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