174 lines
5.9 KiB
Plaintext
174 lines
5.9 KiB
Plaintext
import { FlipperComp } from '../components/FlipperComp'
|
|
import { HomeIconComp } from '../components/HomeIconComp'
|
|
import { HomeSwiperComp } from '../components/HomeSwiperComp'
|
|
import { SpeciallyEStandingComp } from '../components/SpeciallyEStandingComp'
|
|
import { HomeReplayVideoComp } from '../components/HomeReplayVideoComp'
|
|
import { getDisplayWindowWidth } from 'media-player-common'
|
|
import { BusinessError } from '@kit.BasicServicesKit';
|
|
import HashMap from '@ohos.util.HashMap';
|
|
import { BasicConstant,hdHttp, HdResponse ,logger,HdHomeNav} from '@itcast/basic/Index'
|
|
import { HomeModel,dataModel, newsModel,iconsModel } from '../model/HomeModel';
|
|
import { DefaultHintProWindows,SignPopWindow,HdLoadingDialog } from '@itcast/basic'
|
|
import { promptAction, router } from '@kit.ArkUI';
|
|
|
|
@Entry
|
|
@Component
|
|
export struct HomePage {
|
|
@State homeData:dataModel = {} as dataModel;
|
|
@State navAlpha: number = 0;
|
|
@State navBackColor: string = 'FFFFFF'
|
|
// @Consume@Watch('gotoTop')
|
|
// toTop:boolean;
|
|
@State hintMessage:string = '';
|
|
@State signData:Record<string,string> = {};
|
|
|
|
scroller:Scroller = new Scroller()
|
|
|
|
dialog: CustomDialogController = new CustomDialogController({
|
|
builder: HdLoadingDialog({ message: '加载中...' }),
|
|
customStyle: true,
|
|
alignment: DialogAlignment.Center
|
|
})
|
|
|
|
hintWindowDialog: CustomDialogController = new CustomDialogController({
|
|
builder:DefaultHintProWindows({
|
|
message:this.hintMessage,
|
|
cancleTitle:'',
|
|
confirmTitle:'关闭',
|
|
confirmTitleColor: '#000000',
|
|
selectedButton: (index:number)=>{
|
|
this.hintWindowDialog.close();
|
|
}
|
|
}),
|
|
alignment: DialogAlignment.Center,
|
|
cornerRadius:24,
|
|
autoCancel:false,
|
|
backgroundColor: ('rgba(0,0,0,0.5)'),
|
|
})
|
|
|
|
signWindowDialog:CustomDialogController = new CustomDialogController({
|
|
builder:SignPopWindow({
|
|
signDay:'今天是我们相识的第'+String(this.signData.gdxzday)+'天',
|
|
signWeek:String(this.signData.totalDay),
|
|
signMouth:String(this.signData.continuous_day),
|
|
signNews:this.signData.news['title'],
|
|
signHtml:this.signData.news['path'],
|
|
}),
|
|
alignment: DialogAlignment.Center,
|
|
cornerRadius:8,
|
|
autoCancel:false,
|
|
backgroundColor: Color.Transparent,
|
|
backgroundBlurStyle: BlurStyle.NONE,
|
|
})
|
|
|
|
gotoTop() {
|
|
this.scroller.scrollToIndex(0);
|
|
this.initData()
|
|
}
|
|
|
|
aboutToAppear(): void {
|
|
this.initData()
|
|
}
|
|
|
|
initData() {
|
|
const hashMap: HashMap<string, string> = new HashMap();
|
|
this.dialog.open()
|
|
hashMap.clear();
|
|
hdHttp.httpReq<string>(BasicConstant.indexV2,hashMap).then(async (res: HdResponse<string>) => {
|
|
logger.info('Response indexV2'+res);
|
|
let json:HomeModel = JSON.parse(res+'') as HomeModel;
|
|
this.dialog.close();
|
|
this.homeData = json.data;
|
|
for (const item of this.homeData.news_list as newsModel[]) {
|
|
if (item.type == '1') {
|
|
this.navBackColor = item.color;
|
|
}
|
|
}
|
|
}).catch((err: BusinessError) => {
|
|
this.dialog.close();
|
|
})
|
|
}
|
|
|
|
getSignData() {
|
|
const hashMap: HashMap<string, string> = new HashMap()
|
|
this.dialog.open()
|
|
hashMap.clear()
|
|
hashMap.set('score_type','1')
|
|
hdHttp.httpReq<string>(BasicConstant.addBonusPoints,hashMap).then(async (res: HdResponse<string>) => {
|
|
logger.info('Response addBonusPoints'+res)
|
|
this.dialog.close()
|
|
let json:Record<string,string> = JSON.parse(res+'') as Record<string,string>
|
|
if (json.code == '1') {
|
|
this.homeData.sign_in = '1'
|
|
this.signData = json
|
|
this.signWindowDialog.open()
|
|
} else if (json.code == '201') {
|
|
this.homeData.sign_in = '1'
|
|
this.hintMessage = '今日已签到,每日只能签到一次。\n请明日继续哦~'
|
|
this.hintWindowDialog.open()
|
|
}
|
|
}).catch((err: BusinessError) => {
|
|
this.dialog.close()
|
|
})
|
|
}
|
|
|
|
build() {
|
|
Stack(){
|
|
Scroll(this.scroller) {
|
|
Column() {
|
|
if (this.homeData.news_list && this.homeData.news_list.length > 0) {
|
|
HomeSwiperComp({ newslist: this.homeData.news_list, expertData: this.homeData.expertDetail })
|
|
.height(getDisplayWindowWidth().vp / 16 * 9)
|
|
}
|
|
if (this.homeData.icons_list && this.homeData.icons_list.length > 0) {
|
|
HomeIconComp({iconList:this.homeData.icons_list})
|
|
}
|
|
if (this.homeData.meeting_list && this.homeData.meeting_list.length > 0) {
|
|
FlipperComp({ bankAdBeans: this.homeData.meeting_list })
|
|
.height(56)
|
|
.backgroundColor(Color.Yellow)
|
|
}
|
|
if (this.homeData.esite_list && this.homeData.esite_list.length > 0) {
|
|
SpeciallyEStandingComp({ esiteArray: this.homeData.esite_list })
|
|
}
|
|
if (this.homeData.video_list && this.homeData.video_list.length > 0) {
|
|
HomeReplayVideoComp({ videoList: this.homeData.video_list })
|
|
}
|
|
}
|
|
}
|
|
.edgeEffect(EdgeEffect.Spring)
|
|
.scrollBar(BarState.Off)
|
|
.onWillScroll(() => {
|
|
const yOffset = this.scroller.currentOffset().yOffset;
|
|
const threshold = 56;
|
|
if (yOffset <= 0) {
|
|
this.navAlpha = 0;
|
|
} else if (yOffset >= threshold) {
|
|
this.navAlpha = 1;
|
|
} else {
|
|
this.navAlpha = yOffset / threshold;
|
|
}
|
|
})
|
|
HdHomeNav({
|
|
leftIcon:this.homeData.sign_in == '0'?$r('app.media.home_no_qiandao_icon'):$r('app.media.home_qiandao_icon'),
|
|
placeholder:'搜索视频、会议',
|
|
alpha:this.navAlpha,
|
|
backColor:this.navBackColor,
|
|
leftItemAction:()=>{
|
|
this.getSignData();
|
|
},
|
|
searchItemAction:()=>{
|
|
router.pushUrl({
|
|
url:'pages/SearchPage/VideoSearchPage',
|
|
params:{'pageName':'视频'}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
.alignContent(Alignment.Top)
|
|
.backgroundColor('#f4f4f4')
|
|
.width('100%')
|
|
.height('100%')
|
|
}
|
|
}
|