HarmonyOS NEXT 实战之元服务:静态案例结果---教诲培训服务 ...

打印 上一主题 下一主题

主题 1052|帖子 1052|积分 3156

背景:

前几篇学习了元服务,后面几期就让我们开发简单的元服务吧,内里丰富的内容大家自己加,本期案例 仅供参考
先上本期结果图 ,内里图片自行更换


结果图1完整代码案比方下:

  1. import { authentication } from '@kit.AccountKit';
  2. import { BusinessError } from '@kit.BasicServicesKit';
  3. import { hilog } from '@kit.PerformanceAnalysisKit';
  4. import { promptAction } from '@kit.ArkUI';
  5. @Entry
  6. @ComponentV2
  7. struct Index {
  8.   build() {
  9.     Scroll() {
  10.       Column({ space: 8 }) {
  11.         Text($r('app.string.EntryAbility_label'))
  12.           .textAlign(TextAlign.Center)
  13.           .width('100%')
  14.           .fontSize(28)
  15.           .fontColor(Color.Black)
  16.           .fontWeight(FontWeight.Bold)
  17.         Column({ space: 5 }) {
  18.           Text('一、按教育阶段分类').text1()
  19.           Text('1、学前教育').text3()
  20.           Text('☛服务咨询:亲子早教、幼儿园教育').text2()
  21.           Text('2、中小学教育').text3()
  22.           Text('☛服务咨询:小学、初中、高中教育').text2()
  23.           Text('3、高等教育').text3()
  24.           Text('☛服务咨询:专科、本科、研究生教育').text2()
  25.           Text('二、按学科领域分类').text1()
  26.           Text('1、外语培训').text3()
  27.           Text('☛服务咨询:英语培训、小语种培训').text2()
  28.           Text('2、学科辅导').text3()
  29.           Text('☛服务咨询:理科辅导、文科辅导').text2()
  30.           Text('3、艺术培训').text3()
  31.           Text('☛服务咨询:音乐、舞蹈、美术培训').text2()
  32.           Text('三、按技能领域分类').text1()
  33.           Text('1、计算机与信息技术培训').text3()
  34.           Text('☛服务咨询:编程培训、软件应用培训、网络技术与信息安全培训').text2()
  35.         }.width('100%').alignItems(HorizontalAlign.Start)
  36.       }
  37.       .onClick(() => {
  38.         promptAction.showToast({ message: '当前城市暂不支持此服务,请耐心等待后续开通...' })
  39.       })
  40.       .height('100%')
  41.       .width('100%')
  42.       .alignItems(HorizontalAlign.Start)
  43.       .padding(12)
  44.     }.height('100%')
  45.     .width('100%')
  46.   }
  47.   aboutToAppear() {
  48.     hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
  49.     this.loginWithHuaweiID();
  50.   }
  51.   /**
  52.    * Sample code for using HUAWEI ID to log in to atomic service.
  53.    * According to the Atomic Service Review Guide, when a atomic service has an account system,
  54.    * the option to log in with a HUAWEI ID must be provided.
  55.    * The following presets the atomic service to use the HUAWEI ID silent login function.
  56.    * To enable the atomic service to log in successfully using the HUAWEI ID, please refer
  57.    * to the HarmonyOS HUAWEI ID Access Guide to configure the client ID and fingerprint certificate.
  58.    */
  59.   private loginWithHuaweiID() {
  60.     // Create a login request and set parameters
  61.     let loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
  62.     // Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI ID
  63.     loginRequest.forceLogin = false;
  64.     // Execute login request
  65.     let controller = new authentication.AuthenticationController();
  66.     controller.executeRequest(loginRequest).then((data) => {
  67.       let loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;
  68.       let authCode = loginWithHuaweiIDResponse.data?.authorizationCode;
  69.       // Send authCode to the backend in exchange for unionID, session
  70.     }).catch((error: BusinessError) => {
  71.       hilog.error(0x0000, 'testTag', 'error: %{public}s', JSON.stringify(error));
  72.       if (error.code == authentication.AuthenticationErrorCode.ACCOUNT_NOT_LOGGED_IN) {
  73.         // HUAWEI ID is not logged in, it is recommended to jump to the login guide page
  74.       }
  75.     });
  76.   }
  77. }
  78. @Extend(Text)
  79. function text1() {
  80.   .fontSize(24)
  81.   .fontColor(Color.White)
  82.   .fontWeight(FontWeight.Bold)
  83.   .backgroundColor('#788DF9')
  84.   .padding(5)
  85.   .borderRadius(6)
  86. }
  87. @Extend(Text)
  88. function text2() {
  89.   .fontSize(16)
  90.   .fontColor(Color.Black)
  91.   .margin({ left: 24 })
  92.   .borderWidth(2)
  93.   .borderRadius(5)
  94.   .borderColor('#CCC8F6')
  95.   .padding(3)
  96. }
  97. @Extend(Text)
  98. function text3() {
  99.   .fontSize(20)
  100.   .fontColor(Color.Black)
  101.   .fontWeight(FontWeight.Bold)
  102.   .margin({ left: 12 })
  103. }
复制代码
最近文章>>>>>>>>>>>

HarmonyOS NEXT实战:元服务与应用 APP 发布应用市场的详细步骤与流程
若本文对您稍有资助,诚望您不吝点赞,多谢。
有爱好的同学可以点击检察源码



  • gitee:https://gitee.com/jiaojiaoone/explore-harmony-next/tree/case%2Fwanandroid/
  • github:https://github.com/JasonYinH/ExploreHarmonyNext.git

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

傲渊山岳

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表