鸿蒙实战案列-欢迎页面

打印 上一主题 下一主题

主题 1034|帖子 1034|积分 3102

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

x
前言

        在黑马康健应用开辟的过程中,欢迎页面每每是首个吸引用户眼光的存在。所以欢迎页面要注重简便性和功能性,确保用户能敏捷理解主要功能和特点。所以介绍一下怎样用HarmonyOS构建欢迎页面。

一、页面计划

    欢迎页面整体的布局非常简单,是一个从上到下的列式布局,所以使用Column就行了。同时整个页面的配景致是一个绿色,所以需要加上一个绿色配景致铺满整个屏幕,宽高比都是100%。整个页面从上到下第一部门是一个logo,是一个图片然后再往下黑马康健这是个logo,同样也是一个图片,再往下有三行文本介绍,所以整个页面结构很简单




二、相干代码

1.欢迎页面的UI

代码如下:
  1. import common from '@ohos.app.ability.common'
  2. import preferences from '@ohos.data.preferences'
  3. import router from '@ohos.router'
  4. import preferenceUtil from '../common/utils/PreferenceUtil'
  5. import UserPrivacyDialog from '../view/welcome/UserPrivacyDialog'
  6. @Extend(Text) function opacityWhiteText(opacity:number ,fontSize:number=10){
  7.   .fontSize(fontSize)
  8.   .opacity(opacity)
  9.   .fontColor(Color.White)
  10. }
  11. const PREF_KEY = 'userPrivacyKey'
  12. @Entry
  13. @Component
  14. struct welcomePage {
  15.   context = getContext(this) as common.UIAbilityContext
  16.   controller:CustomDialogController= new CustomDialogController({
  17.     builder:UserPrivacyDialog({
  18.       confirm: () => this.onConfirm(),
  19.       cancel: () => this.exitApp()
  20.     })
  21.   })
  22.   async aboutToAppear(){
  23.     //1.加载首选项
  24.     let isAgree = await preferenceUtil.getPreferenceValue(PREF_KEY,false)
  25.     //2.判断是否同意
  26.     if (isAgree) {
  27.       //2.1.同意,跳转首页
  28.       this.jumpToIndex()
  29.     }else {
  30.       //2.2.不同意,弹窗
  31.       this.controller.open()
  32.     }
  33.   }
  34.   jumpToIndex(){
  35.     setTimeout(()=>{
  36.       router.replaceUrl({
  37.         url:'Pages/Index'
  38.       })
  39.     },1000)
  40.   }
  41.   onConfirm(){
  42.     //1.保存首选项
  43.     preferenceUtil.putPreferenceValue(PREF_KEY,true)
  44.     //2.跳转到首页
  45.     this.jumpToIndex()
  46.   }
  47.   exitApp(){
  48.     //退出
  49.     this.context.terminateSelf()
  50.   }
  51.   build() {
  52.     Column({space:10}) {
  53.       Row(){
  54.         Image($r('app.media.home_slogan'))
  55.           .width(260)
  56.       }
  57.       .layoutWeight(1)//布局权重
  58.       Image($r('app.media.home_logo'))
  59.         .width(150)
  60.       Row(){
  61.         Text('黑马健康支持').opacityWhiteText(0.8,12)
  62.         Text('IPv6')
  63.           .opacityWhiteText(0.8)
  64.           .border({style:BorderStyle.Solid,width:1,color:Color.White,radius:15})
  65.           .padding({left:5,right:5})
  66.         Text('网络').opacityWhiteText(0.8,12)
  67.       }
  68.       Text('‘减更多’指黑马健康App希望通过软件工具的形式,帮助更多用户实现身材管理')
  69.         .opacityWhiteText(0.6)
  70.       Text('浙ICP备0000000号-36D')
  71.         .opacityWhiteText(0.4)
  72.         .margin({bottom:35})//外边距
  73.     }
  74.     .width('100%')
  75.     .height('100%')
  76.     .backgroundColor($r('app.color.welcome_page_background'))
  77.   }
  78. }
复制代码
效果图如下:


2.欢迎页面的业务

代码如下:
  1. import { CommonConstants } from '../../common/constants/CommonConstants'
  2. //@Preview//可预览
  3. @CustomDialog
  4. export default struct userPrivacyDialog {
  5.   controller:CustomDialogController
  6.   confirm: () => void
  7.   cancel: () => void
  8.   build() {
  9.     Column({space:10}){
  10.       //1.标题
  11.       Text($r('app.string.user_privacy_title'))
  12.         .fontSize(20)
  13.         .fontWeight(CommonConstants.FONT_WEIGHT_700)
  14.       //2.内容
  15.       Text($r('app.string.user_privacy_content'))
  16.       //3.按钮
  17.       Button($r('app.string.agree_label'))
  18.         .width(150)
  19.         .backgroundColor($r('app.color.primary_color'))
  20.         .onClick(()=>{
  21.           this.confirm()
  22.           this.controller.close()
  23.         })
  24.       Button($r('app.string.refuse_label'))
  25.         .width(150)
  26.         .backgroundColor($r('app.color.lightest_primary_color'))
  27.         .fontColor($r('app.color.light_gray'))
  28.         .onClick(()=>{
  29.           this.cancel()
  30.           this.controller.close()
  31.         })
  32.     }
  33.     .width('100%')
  34.     .padding(0)
  35.   }
  36. }
复制代码
效果图如下:



总结

以上就是欢迎页面的内容,页面起首会弹窗来检测用户是否同意隐私协议,如果同意协议将会关闭弹窗并进入应用,同时生存效果,下次用户进入应用将不会再次弹窗。如果不同意隐私协议将会退出该应用

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

使用道具 举报

0 个回复

倒序浏览

快速回复

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

本版积分规则

卖不甜枣

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