harmony/features/Home/src/main/ets/components/ListCompVideoSelect.ets
2025-05-30 17:11:58 +08:00

135 lines
3.5 KiB
Plaintext

import { VideoMoreModel,VideoMore } from '../model/VideoMoreModel'
import { HdList, HdListController,BasicConstant,hdHttp, HdResponse ,logger} from '@itcast/basic/Index'
import { promptAction, router } from '@kit.ArkUI'
import { BusinessError } from '@kit.BasicServicesKit';
import { HdLoadingDialog,EmptyViewComp } from '@itcast/basic'
import HashMap from '@ohos.util.HashMap';
import { videoTools } from '../polyv/VideoUtil'
@Component
export struct ListCompVideoSelect {
@State isEmptyViewVisible: boolean = false; // 控制显隐的状态变量
@Prop
type_uuid:string=''
@State
list: VideoMore[] = []
controller = new HdListController()
@State
page: number = 1
@State
keyword: string = ''
hashMap: HashMap<string, string> = new HashMap();
dialog: CustomDialogController = new CustomDialogController({
builder: HdLoadingDialog({ message: '加载中...' }),
customStyle: true,
alignment: DialogAlignment.Center
})
onRefresh() {
this.page = 1
this.initData(0)
}
initData(type:number)
{
this.dialog.open()
this.hashMap.clear();
this.hashMap.set('page', this.page+"")
this.hashMap.set('typeUuid', this.type_uuid)
hdHttp.httpReq<string>(BasicConstant.videoByTypeNew,this.hashMap).then(async (res: HdResponse<string>) => {
logger.info('Response videoByTypeNew'+res);
let json:VideoMoreModel = JSON.parse(res+'') as VideoMoreModel;
this.dialog.close()
if(type==0)
{
this.controller.refreshed()
}
else
{
this.controller.loaded()
}
if(this.page==1)
{
this.list=[]
if(json.data!=null&&json.data.list!)
{
this.list = json.data.list
}
}
else if(this.page>1)
{
this.list.push(...json.data.list)
}
if (this.page >= json.data.totalPage) {
this.controller.finished()
} else {
this.page++
}
if (this.list.length>0) {
this.isEmptyViewVisible = false;
} else {
this.isEmptyViewVisible = true;
}
}).catch((err: BusinessError) => {
this.dialog.close()
if (this.list.length>0) {
this.isEmptyViewVisible = false;
} else {
this.isEmptyViewVisible = true;
}
})
}
build() {
if (this.isEmptyViewVisible){
EmptyViewComp({promptText:'暂无数据',isVisibility:this.isEmptyViewVisible})
.width('100%')
.height('100%')
} else {
HdList({
lw: 1,
controller: this.controller,
onRefresh: () => {
this.onRefresh()
},
onLoad: () => {
this.initData(1)
}
}) {
ForEach(this.list, (items: VideoMore) => {
ListItem() {
Column()
{
Row()
{
Text(items.name) .textOverflow({ overflow: TextOverflow.Ellipsis })
.maxLines(1)
.textAlign(TextAlign.Start)
.layoutWeight(1)
.fontSize(16)
.padding(10)
Image($r('sys.media.ohos_ic_public_arrow_right'))
.width(15)
.height(15)
.margin({ right: 10})
}
.width('100%')
Text('').height(1).width('100%')
.backgroundColor($r('app.color.1a000000'))
}
.onClick(()=>{
videoTools.getVideoDetail(items.uuid)
})
}
})
}
}
}
}