xingzhaojie

desc:设置页面UI

  1 +import ArrayList from '@ohos.util.ArrayList'
  2 +import { MineSettingComponent } from 'wdComponent';
  3 +
  4 +@Entry
  5 +@Component
  6 +struct SettingPage {
  7 + @State message: string = 'Hello World 02'
  8 +
  9 + build() {
  10 + Column() {
  11 + MineSettingComponent()
  12 + }.setFullWidth()
  13 + }
  14 +
  15 + // 私有方法
  16 + @Styles setFullWidth(){
  17 + .width('100%')
  18 + }
  19 +}
  20 +/*
  21 +
  22 +* */
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 "pages/Index", 3 "pages/Index",
4 "pages/MainPage", 4 "pages/MainPage",
5 "pages/ColumnPage", 5 "pages/ColumnPage",
6 - "pages/TestPage" 6 + "pages/TestPage",
  7 + "pages/SettingPage"
7 ] 8 ]
8 } 9 }
@@ -27,3 +27,5 @@ export { TriPicCardComponent } from "./components/view/TriPicCardComponent" @@ -27,3 +27,5 @@ export { TriPicCardComponent } from "./components/view/TriPicCardComponent"
27 export { BigPicCardComponent } from "./components/view/BigPicCardComponent" 27 export { BigPicCardComponent } from "./components/view/BigPicCardComponent"
28 28
29 export { HeadPictureCardComponent } from "./components/view/HeadPictureCardComponent" 29 export { HeadPictureCardComponent } from "./components/view/HeadPictureCardComponent"
  30 +
  31 +export { MineSettingComponent } from "./components/page/MineSettingComponent"
@@ -345,6 +345,9 @@ export struct MinePageComponent { @@ -345,6 +345,9 @@ export struct MinePageComponent {
345 }.padding({left:'27lpx'}) 345 }.padding({left:'27lpx'})
346 .onClick(()=>{ 346 .onClick(()=>{
347 console.log(index+"") 347 console.log(index+"")
  348 + if (index == 4) {
  349 + RouteManager.jumpNewPage("pages/SettingPage") // 调用跳转方法,跳转新页面
  350 + }
348 }) 351 })
349 .height('117lpx') 352 .height('117lpx')
350 }, item => item) 353 }, item => item)
  1 +// @ts-nocheck
  2 +import { BottomNavi, CommonConstants } from 'wdConstant';
  3 +import { Logger } from 'wdKit';
  4 +import { TopNavigationComponent } from './TopNavigationComponent';
  5 +import { BottomNavDTO } from '../../repository/bean/BottomNavDTO';
  6 +import { UIUtils } from '../../repository/UIUtils';
  7 +import { MinePageComponent } from './MinePageComponent';
  8 +import PageViewModel from '../../viewmodel/PageViewModel';
  9 +
  10 +import storageStatistics from "@ohos.file.storageStatistics";
  11 +import { BusinessError } from '@ohos.base';
  12 +
  13 +
  14 +@Component
  15 +export struct MineSettingComponent {
  16 + @State listData: Array<string | Array<string>> = new Array();
  17 + @State privacySwitch:boolean = false
  18 + @State cacheSice:number = 0
  19 +
  20 + aboutToAppear() {
  21 + // 获取设置页面数据
  22 + this.getSettingPageData()
  23 +
  24 + // 获取缓存数据
  25 + storageStatistics.getCurrentBundleStats((err: BusinessError, bundleStats: storageStatistics.BundleStats) => {
  26 + if (err) {
  27 + console.error(`Invoke getCurrentBundleStats failed, code is ${err.code}, message is ${err.message}`);
  28 + } else {
  29 + this.cacheSice = bundleStats.appSize / 1024.00 / 1024.00.toFixed(2);
  30 + }
  31 + });
  32 + }
  33 +
  34 + getSettingPageData() {
  35 + let listArr = [['账户与安全', '接收推送', '隐私设罝', '仅WiFi网络加载图片', 'WiFi网络情况下自动播放视频', '开户播放器悬浮窗'], ['清除缓存', '去评分']];
  36 + this.listData = listArr;
  37 + }
  38 +
  39 + build() {
  40 + Navigation() {
  41 + //滑动区域
  42 + this.settingList()
  43 + }.titleMode(NavigationTitleMode.Mini)
  44 + .title('设置')
  45 + }
  46 +
  47 + // 页面布局
  48 + @Builder settingList() {
  49 + Column() {
  50 + List() {
  51 + // 循环渲染ListItemGroup,contactsGroups为多个分组联系人contacts和标题title的数据集合
  52 + ForEach(this.listData, (item: Array<string>, index: number) => {
  53 + ListItemGroup({ header: index === 0 ? this.itemHead("") : this.itemHead("1") }) {
  54 + // 循环渲染ListItem
  55 + ForEach(item, (subItem: string, subIndex: number) => {
  56 + ListItem() {
  57 + if (subIndex == 6) {
  58 + this.getArrowCell(subItem, subIndex, index)
  59 + } else if (subIndex == 1 || subIndex == 3 || subIndex == 4 || subIndex == 5) {
  60 + this.getSwitchCell(subItem, subIndex)
  61 + } else {
  62 + this.getArrowCell(subItem, subIndex, index)
  63 + }
  64 +
  65 + }.padding({ left: '27lpx' })
  66 + .onClick(() => {
  67 + console.log(subIndex + "")
  68 + if (subIndex == 4) {
  69 + // RouteManager.jumpNewPage("pages/SettingPage") // 调用跳转方法,跳转新页面
  70 + }
  71 + })
  72 + .height('117lpx')
  73 + }, subItem => subItem)
  74 + }
  75 + .divider({
  76 + strokeWidth: 1,
  77 + startMargin: 15,
  78 + endMargin: 10,
  79 + color: '#f0f0f0'
  80 + })
  81 + })
  82 + }.onScrollFrameBegin((offset, state) => {
  83 + return { offsetRemain: 0 }
  84 + })
  85 + }
  86 + .backgroundColor(Color.White)
  87 + .borderRadius(8)
  88 + }
  89 +
  90 + @Builder itemHead(text: string) {
  91 + // 列表分组的头部组件,对应联系人分组A、B等位置的组件
  92 + if (text.length > 0) {
  93 + Row().width('100%').height('20lpx').backgroundColor(0xf0f0f0)
  94 + }
  95 + }
  96 +
  97 + // 右侧开关cell
  98 + @Builder getSwitchCell(item, index) {
  99 + Column() {
  100 + Row() {
  101 + // 左侧logo和标题
  102 + Row() {
  103 + // 判断有没有图片
  104 + if (0) {
  105 + Image('https://pic.rmb.bdstatic.com/e182cf67c341d1128d2a6cc05886bf62.jpeg@s_0,h_2000')
  106 + .height('38lpx')
  107 + .margin({ right: '5lpx' })
  108 +
  109 + Text(`${item}`)
  110 + .margin({ top: '8lpx' })
  111 + .height('38lpx')
  112 + .fontColor('#333333')
  113 + .fontSize('29lpx')
  114 + } else {
  115 + Text(`${item}`)
  116 + .margin({ top: '8lpx' })
  117 + .height('38lpx')
  118 + .fontColor('#333333')
  119 + .fontSize('29lpx')
  120 + }
  121 + }.width('60%')
  122 +
  123 + // 右侧文案和右箭头
  124 + Row() {
  125 + Toggle({ type: ToggleType.Switch, isOn: false })
  126 + .height('50lpx')
  127 + .margin({ left: '81lpx', right: '29lpx' })
  128 + .selectedColor(Color.Pink)
  129 + .onChange((isOn: boolean) => {
  130 + this.privacySwitch = isOn;
  131 + })
  132 + }.width('40%')
  133 + .margin({ right: '29lpx' })
  134 + .justifyContent(FlexAlign.End)
  135 +
  136 + }
  137 + .alignItems(VerticalAlign.Center)
  138 + .justifyContent(FlexAlign.SpaceBetween)
  139 + }.height('54lpx')
  140 + }
  141 +
  142 + // 右文字+箭头cell
  143 + @Builder getArrowCell(item, index, mainIndex) {
  144 + Column() {
  145 +
  146 + Row() {
  147 + // 左侧logo和标题
  148 + Row() {
  149 + // 判断有没有图片
  150 + if (this.privacySwitch) {
  151 + Image('https://pic.rmb.bdstatic.com/e182cf67c341d1128d2a6cc05886bf62.jpeg@s_0,h_2000')
  152 + .height('38lpx')
  153 + .margin({ right: '5lpx' })
  154 + }
  155 + Text(`${item}`)
  156 + .margin({ top: '8lpx' })
  157 + .height('38lpx')
  158 + .fontColor('#333333')
  159 + .fontSize('29lpx')
  160 + }.width('60%')
  161 +
  162 + // 右侧文案和右箭头
  163 + Row() {
  164 + Text((index == 0 && mainIndex != 0) ? this.cacheSice.toString() + 'MB' : '')
  165 + .fontColor('#999999')
  166 + .maxLines(1)
  167 + Image($r('app.media.mine_user_arrow'))
  168 + .width('27lpx')
  169 + .height('27lpx')
  170 + .objectFit(ImageFit.Auto)
  171 + Column().width('29lpx')
  172 + }.width('40%')
  173 + .margin({ right: '29lpx' })
  174 + .justifyContent(FlexAlign.End)
  175 +
  176 + }
  177 + .alignItems(VerticalAlign.Center)
  178 + .justifyContent(FlexAlign.SpaceBetween)
  179 +
  180 + }
  181 + .height('54lpx')
  182 + }
  183 +}