优化首页显示

This commit is contained in:
DevWiki 2024-04-30 12:32:25 +08:00
parent 0d43919561
commit bcb748a9b1
9 changed files with 152 additions and 26 deletions

View File

@ -0,0 +1,26 @@
export class HomeItem {
/**
* 列表项名称
*/
name: ResourceStr = '';
/**
* 列表项要打开的页面路径
*/
page?: string;
}
export class HomeItemGroup {
/**
* 分组的名称
*/
name: ResourceStr = '';
/**
* 分组图标
*/
icon?: Resource;
/**
* 分组的Item列表
*/
items: HomeItem[] = [];
}

View File

@ -1,4 +1,4 @@
import { TitleBar } from '@devwiki/common_ui'; import { CommonRes, TitleBar } from '@devwiki/common_ui';
import web_webview from '@ohos.web.webview'; import web_webview from '@ohos.web.webview';
import { TitleBarMenuType } from '@devwiki/common_ui'; import { TitleBarMenuType } from '@devwiki/common_ui';
import { router, window } from '@kit.ArkUI'; import { router, window } from '@kit.ArkUI';
@ -6,6 +6,7 @@ import promptAction from '@ohos.promptAction';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import { Log } from '@devwiki/base'; import { Log } from '@devwiki/base';
import { BaseLocalStorage, ScreenUtil } from '@devwiki/base'; import { BaseLocalStorage, ScreenUtil } from '@devwiki/base';
import { HomeItem, HomeItemGroup } from '../model/Home';
@CustomDialog @CustomDialog
struct WebViewDialog { struct WebViewDialog {
@ -28,6 +29,40 @@ struct WebViewDialog {
@Component @Component
struct Index { struct Index {
@State title: string = "Home"; @State title: string = "Home";
readonly itemGroups: HomeItemGroup[] = [
//Web部分
{
name: 'Web',
items: [
{ name: 'WebPage', page: 'pages/web/WebPage' },
{ name: 'WebDialogPage', page: 'pages/web/WebDialogPage' }
]
},
// 布局
{
name: 'Layout',
items: [
{ name: 'LinearLayout', page: 'pages/layout/LinearLayoutPage' },
{ name: 'RelativeContainer', page: 'pages/layout/RelativeContainerPage' },
]
},
//动画
{
name: "Animation",
items: [
{ name: 'CompTransition', page: 'pages/animation/CompTransitionPage'},
]
},
// 多媒体
{
name: 'Multimedia',
items: [
{ name: 'AVPlayer', page: 'pages/media/AVPlayerPage' },
]
}
];
dialogController: CustomDialogController = new CustomDialogController({ dialogController: CustomDialogController = new CustomDialogController({
builder: WebViewDialog(), builder: WebViewDialog(),
alignment: DialogAlignment.BottomEnd, alignment: DialogAlignment.BottomEnd,
@ -89,6 +124,33 @@ struct Index {
return true; return true;
} }
@Builder
groupBuilder(group: HomeItemGroup) {
Row(){
if (group.icon) {
Image(group.icon).width(24).height(24).margin({right: 8});
}
Text(group.name);
}.height(32).width('100%').padding({left: 8, right: 8})
.backgroundColor('#e0e0e0').alignItems(VerticalAlign.Center)
}
@Builder
itemBuilder(item: HomeItem) {
Column() {
Row() {
Text(item.name);
Image(CommonRes.getImageRes(CommonRes.IC_CHEVRON_RIGHT)).width(32).height(32);
}.width('100%').height(48).justifyContent(FlexAlign.SpaceBetween).alignItems(VerticalAlign.Center)
.padding({left: 16, right: 16})
Divider().margin({ top: 2 });
}.onClick(() => {
if (item.page) {
this.getUIContext().getRouter().pushUrl({url: item.page })
}
})
}
build() { build() {
Column() { Column() {
TitleBar({ TitleBar({
@ -99,29 +161,15 @@ struct Index {
rightMenuType: TitleBarMenuType.None rightMenuType: TitleBarMenuType.None
}).width('100%') }).width('100%')
Column({space: 8}) { List(){
Row() { ForEach(this.itemGroups, (group: HomeItemGroup) => {
Button("WebDialog").width(100).height('100%').type(ButtonType.Normal) ListItemGroup({header: this.groupBuilder(group)}) {
.onClick(async () => { ForEach(group.items, (item: HomeItem) => {
this.dialogController.open() this.itemBuilder(item);
}); })
}
Button("Layout").width(100).height('100%').type(ButtonType.Normal).onClick(() => { })
router.pushUrl({ url: "pages/layout/LinearLayoutPage" }); }.width('100%').height('100%').margin({top: 16})
});
Button("Animation").width(100).height('100%').type(ButtonType.Normal).onClick(() => {
router.pushUrl({ url: "pages/animation/CompTransitionPage" });
});
}.width('100%').height(48).justifyContent(FlexAlign.SpaceEvenly)
Row() {
Button("AVPlayer").width(100).height('100%').type(ButtonType.Normal).onClick(() => {
router.pushUrl({ url: "pages/media/AVPlayerPage" });
});
}.width('100%').height(48).justifyContent(FlexAlign.SpaceEvenly)
}.width('100%')
}.width('100%').height('100%') }.width('100%').height('100%')
} }
} }

View File

@ -0,0 +1,8 @@
@Entry
@Component
struct TextPage {
build() {
}
}

View File

@ -0,0 +1,27 @@
import { ComponentConst } from '@devwiki/common_ui/Index'
@Entry
@Component
export struct RelativeContainerPage {
build() {
RelativeContainer() {
Button('1111')
.alignRules({
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start },
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
}).id('left_menu')
Button(){
Text("2222").height(64)
}
.alignRules({
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
right: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.End },
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
}).id('right_menu')
}.height(64).width('100%').backgroundColor(Color.Red)
}
}

View File

@ -12,4 +12,12 @@ export struct WebPageDialog {
this.dialogController.close(); this.dialogController.close();
}}).height(this.isPortrait ? '95%' : '90%').width(this.isPortrait ? '100%' : '50%') }}).height(this.isPortrait ? '95%' : '90%').width(this.isPortrait ? '100%' : '50%')
} }
}
@Entry
@Component
export struct WebDialogPage {
build() {
}
} }

View File

@ -2,7 +2,9 @@
"src": [ "src": [
"pages/Index", "pages/Index",
"pages/web/WebPage", "pages/web/WebPage",
"pages/web/WebDialogPage",
"pages/layout/LinearLayoutPage", "pages/layout/LinearLayoutPage",
"pages/layout/RelativeContainerPage",
"pages/animation/CompTransitionPage", "pages/animation/CompTransitionPage",
"pages/media/AVPlayerPage" "pages/media/AVPlayerPage"
] ]

View File

@ -1,5 +1,4 @@
export { TitleBar, TitleBarMenuType } from './src/main/ets/component/TitleBar' export { TitleBar, TitleBarMenuType } from './src/main/ets/component/TitleBar'
export { ComponentConst } from './src/main/ets/component/ComponentConst' export { ComponentConst } from './src/main/ets/component/ComponentConst'
export { WebViewEventKey } from '../base/src/main/ets/event/EventKey'
export { WebView, WebViewController, WebViewParam } from './src/main/ets/component/web/WebView' export { WebView, WebViewController, WebViewParam } from './src/main/ets/component/web/WebView'
export { CommonRes, CommonMediaName } from './src/main/ets/utils/CommonRes' export { CommonRes, CommonMediaName } from './src/main/ets/utils/CommonRes'

View File

@ -1,5 +1,8 @@
export class CommonRes { export class CommonRes {
static readonly IC_CHEVRON_LEFT = "ic_chevron_left";
static readonly IC_CHEVRON_RIGHT = "ic_chevron_right";
private constructor() { private constructor() {
} }
@ -7,10 +10,14 @@ export class CommonRes {
return $r("app.media.ic_refresh"); return $r("app.media.ic_refresh");
} }
public static getIconBack(): Resource { public static getIconChevronLeft(): Resource {
return $r("app.media.ic_chevron_left"); return $r("app.media.ic_chevron_left");
} }
public static getIconChevronRight(): Resource {
return $r("app.media.ic_chevron_right");
}
public static getIconClose(): Resource { public static getIconClose(): Resource {
return $r("app.media.ic_close"); return $r("app.media.ic_close");
} }

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>chevron-right</title><path d="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z" /></svg>

After

Width:  |  Height:  |  Size: 166 B