第一次提交
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { router } from '@kit.ArkUI'
|
||||
|
||||
@Builder
|
||||
function defaultBuilder(): void {
|
||||
|
||||
}
|
||||
|
||||
@Component
|
||||
export struct HdNav {
|
||||
@StorageProp('topHeight')
|
||||
topHeight: number = 0
|
||||
@Prop
|
||||
title: string = ''
|
||||
@Prop
|
||||
textColor: ResourceStr = $r('app.color.top_title')
|
||||
@Prop
|
||||
bgColor: ResourceStr = $r('app.color.top_bg')
|
||||
@Prop
|
||||
hasBorder: boolean = false
|
||||
@Prop
|
||||
leftIcon: ResourceStr = $r('app.media.top_back')
|
||||
@Prop
|
||||
rightIcon: ResourceStr = $r('sys.media.ohos_ic_public_more')
|
||||
@Prop
|
||||
showRightIcon: boolean = true
|
||||
@Prop
|
||||
showLeftIcon: boolean = true
|
||||
@Prop
|
||||
showRightText: boolean = false
|
||||
@Prop
|
||||
rightText: string = ''
|
||||
@BuilderParam
|
||||
titleBuilder: () => void = defaultBuilder
|
||||
@BuilderParam
|
||||
menuBuilder: () => void = defaultBuilder
|
||||
|
||||
build() {
|
||||
Row({ space: 16 }) {
|
||||
if (this.showLeftIcon) {
|
||||
Image(this.leftIcon)
|
||||
.size({ width: 24, height: 24 })
|
||||
.margin({left:-5})
|
||||
.onClick(() => router.back())
|
||||
.fillColor($r('app.color.black'))
|
||||
}
|
||||
else {
|
||||
Blank()
|
||||
.width(24)
|
||||
}
|
||||
Row() {
|
||||
if (this.title) {
|
||||
Text(this.title)
|
||||
.fontWeight(600)
|
||||
.layoutWeight(1)
|
||||
.textAlign(TextAlign.Center)
|
||||
.fontSize(20)
|
||||
.fontColor(this.textColor)
|
||||
.maxLines(1)
|
||||
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
||||
} else if (this.titleBuilder) {
|
||||
this.titleBuilder()
|
||||
}
|
||||
}
|
||||
.height(56)
|
||||
.layoutWeight(1)
|
||||
|
||||
if (this.showRightIcon) {
|
||||
Image(this.rightIcon)
|
||||
.size({ width: 24, height: 24 })
|
||||
.objectFit(ImageFit.Contain)
|
||||
.bindMenu(this.menuBuilder)
|
||||
} else if (this.showRightText)
|
||||
{
|
||||
Text(this.rightText)
|
||||
.fontSize(16)
|
||||
.fontColor(this.textColor)
|
||||
.margin({right:10})
|
||||
}
|
||||
else {
|
||||
Blank()
|
||||
.width(24)
|
||||
}
|
||||
}
|
||||
.padding({ left: 16, right: 16, top: this.topHeight })
|
||||
.height(56 + this.topHeight)
|
||||
.width('100%')
|
||||
.backgroundColor(this.bgColor)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { webview } from '@kit.ArkWeb'
|
||||
import { logger } from '../utils/logger'
|
||||
|
||||
@Component
|
||||
export struct HdWeb {
|
||||
layoutMode: WebLayoutMode = WebLayoutMode.NONE
|
||||
src: ResourceStr = $rawfile('detail.html')
|
||||
onLoad: () => void = () => {
|
||||
}
|
||||
controller: webview.WebviewController = new webview.WebviewController()
|
||||
|
||||
build() {
|
||||
Web({ src: this.src, controller: this.controller })
|
||||
.javaScriptAccess(true)
|
||||
.onPageEnd(() => {
|
||||
this.onLoad()
|
||||
})
|
||||
.onErrorReceive(event => {
|
||||
logger.error(event!.error.getErrorInfo())
|
||||
})
|
||||
.layoutMode(this.layoutMode)
|
||||
.layoutWeight(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { ComponentContent, promptAction, UIContext } from '@kit.ArkUI';
|
||||
|
||||
export class PromptActionClass {
|
||||
static ctx: UIContext;
|
||||
static contentNode: ComponentContent<Object>;
|
||||
static options: promptAction.BaseDialogOptions;
|
||||
|
||||
static setContext(context: UIContext) {
|
||||
PromptActionClass.ctx = context;
|
||||
}
|
||||
|
||||
static setContentNode(node: ComponentContent<Object>) {
|
||||
PromptActionClass.contentNode = node;
|
||||
}
|
||||
|
||||
static setOptions(options: promptAction.BaseDialogOptions) {
|
||||
PromptActionClass.options = options;
|
||||
}
|
||||
|
||||
static openDialog() {
|
||||
if (PromptActionClass.contentNode !== null) {
|
||||
PromptActionClass.ctx.getPromptAction().openCustomDialog(PromptActionClass.contentNode, PromptActionClass.options)
|
||||
.then(() => {
|
||||
console.info('OpenCustomDialog complete.')
|
||||
})
|
||||
.catch((error: BusinessError) => {
|
||||
let message = (error as BusinessError).message;
|
||||
let code = (error as BusinessError).code;
|
||||
console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
static closeDialog() {
|
||||
if (PromptActionClass.contentNode !== null) {
|
||||
PromptActionClass.ctx.getPromptAction().closeCustomDialog(PromptActionClass.contentNode)
|
||||
.then(() => {
|
||||
console.info('CloseCustomDialog complete.')
|
||||
})
|
||||
.catch((error: BusinessError) => {
|
||||
let message = (error as BusinessError).message;
|
||||
let code = (error as BusinessError).code;
|
||||
console.error(`CloseCustomDialog args error code is ${code}, message is ${message}`);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
static updateDialog(options: promptAction.BaseDialogOptions) {
|
||||
if (PromptActionClass.contentNode !== null) {
|
||||
PromptActionClass.ctx.getPromptAction().updateCustomDialog(PromptActionClass.contentNode, options)
|
||||
.then(() => {
|
||||
console.info('UpdateCustomDialog complete.')
|
||||
})
|
||||
.catch((error: BusinessError) => {
|
||||
let message = (error as BusinessError).message;
|
||||
let code = (error as BusinessError).code;
|
||||
console.error(`UpdateCustomDialog args error code is ${code}, message is ${message}`);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user