背景:
前几篇学习了元服务,后面几期就让我们开发简单的元服务吧,内里丰富的内容大家自己加,本期案例 仅供参考
先上本期结果图 ,内里图片自行更换
结果图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 parameters
- let loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
- // Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI ID
- loginRequest.forceLogin = false;
- // Execute login request
- let 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
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |