Showing
5 changed files
with
151 additions
and
37 deletions
| @@ -30,4 +30,8 @@ export class SpConstants{ | @@ -30,4 +30,8 @@ export class SpConstants{ | ||
| 30 | //定位相关 | 30 | //定位相关 |
| 31 | static LOCATION_CITY_NAME = "location_city_name" //定位 | 31 | static LOCATION_CITY_NAME = "location_city_name" //定位 |
| 32 | static LOCATION_CITY_CODE = "location_city_code" //定位 | 32 | static LOCATION_CITY_CODE = "location_city_code" //定位 |
| 33 | + | ||
| 34 | + //启动页数据存储key | ||
| 35 | + static APP_LAUNCH_PAGE_DATA_MODEL = 'app_launch_page_data_model' | ||
| 36 | + | ||
| 33 | } | 37 | } |
| 1 | import router from '@ohos.router' | 1 | import router from '@ohos.router' |
| 2 | import { WDRouterRule } from 'wdRouter'; | 2 | import { WDRouterRule } from 'wdRouter'; |
| 3 | import { WDRouterPage } from 'wdRouter'; | 3 | import { WDRouterPage } from 'wdRouter'; |
| 4 | +import { Logger, SPHelper } from 'wdKit/Index'; | ||
| 5 | +import { SpConstants } from 'wdConstant/Index'; | ||
| 6 | +import LaunchDataModel from '../viewModel/LaunchDataModel' | ||
| 7 | +import { LaunchModel } from '../viewModel/LaunchModel'; | ||
| 8 | +import { ifaa } from '@kit.OnlineAuthenticationKit'; | ||
| 9 | + | ||
| 10 | +import common from '@ohos.app.ability.common'; | ||
| 11 | +import Want from '@ohos.app.ability.Want'; | ||
| 12 | +import { BusinessError } from '@ohos.base'; | ||
| 13 | + | ||
| 14 | + | ||
| 4 | @Entry | 15 | @Entry |
| 5 | @Component | 16 | @Component |
| 6 | struct LaunchAdvertisingPage { | 17 | struct LaunchAdvertisingPage { |
| 7 | @State time: number = 4 | 18 | @State time: number = 4 |
| 8 | timer :number = -1 | 19 | timer :number = -1 |
| 20 | + @State model : LaunchDataModel = {} as LaunchDataModel | ||
| 21 | + | ||
| 9 | 22 | ||
| 10 | enter() { | 23 | enter() { |
| 11 | // router.replaceUrl({ | 24 | // router.replaceUrl({ |
| @@ -15,7 +28,22 @@ struct LaunchAdvertisingPage { | @@ -15,7 +28,22 @@ struct LaunchAdvertisingPage { | ||
| 15 | clearInterval(this.timer) | 28 | clearInterval(this.timer) |
| 16 | } | 29 | } |
| 17 | 30 | ||
| 31 | + aboutToAppear(): void { | ||
| 32 | + | ||
| 33 | + let dataModelStr : string = SPHelper.default.getSync(SpConstants.APP_LAUNCH_PAGE_DATA_MODEL,'') as string | ||
| 34 | + let dataModel : LaunchDataModel = JSON.parse(dataModelStr) | ||
| 35 | + this.model = dataModel | ||
| 36 | + console.log(dataModelStr) | ||
| 37 | + if(this.model.launchAdInfo.length){ | ||
| 38 | + //设置倒计时时间 | ||
| 39 | + this.time = this.model.launchAdInfo[0].displayDuration | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + | ||
| 18 | onPageShow(){ | 45 | onPageShow(){ |
| 46 | + | ||
| 19 | this.timer = setInterval(() => { | 47 | this.timer = setInterval(() => { |
| 20 | this.time-- | 48 | this.time-- |
| 21 | if (this.time < 1) { | 49 | if (this.time < 1) { |
| @@ -32,10 +60,20 @@ struct LaunchAdvertisingPage { | @@ -32,10 +60,20 @@ struct LaunchAdvertisingPage { | ||
| 32 | 60 | ||
| 33 | Stack({alignContent:Alignment.Bottom}){ | 61 | Stack({alignContent:Alignment.Bottom}){ |
| 34 | Column(){ | 62 | Column(){ |
| 35 | - Image($r('app.media.app_icon')) | ||
| 36 | - .margin({ | ||
| 37 | - top:'128lpx',left:'48lpx',right:'48lpx',bottom:'128lpx' | ||
| 38 | - }) | 63 | + if(!(this.model.launchAdInfo[0].matInfo.matType == '1')){ |
| 64 | + //显示图片 | ||
| 65 | + Image(this.model.launchAdInfo[0].matInfo.matImageUrl[0]) | ||
| 66 | + .width('100%') | ||
| 67 | + .height('100%') | ||
| 68 | + // .margin({ | ||
| 69 | + // top:'128lpx',left:'48lpx',right:'48lpx',bottom:'128lpx' | ||
| 70 | + // }) | ||
| 71 | + }else { | ||
| 72 | + //显示视频播放 | ||
| 73 | + | ||
| 74 | + | ||
| 75 | + } | ||
| 76 | + | ||
| 39 | } | 77 | } |
| 40 | .justifyContent(FlexAlign.Center) | 78 | .justifyContent(FlexAlign.Center) |
| 41 | .width('100%') | 79 | .width('100%') |
| @@ -62,48 +100,105 @@ struct LaunchAdvertisingPage { | @@ -62,48 +100,105 @@ struct LaunchAdvertisingPage { | ||
| 62 | } | 100 | } |
| 63 | .width('100%') | 101 | .width('100%') |
| 64 | .height('100%') | 102 | .height('100%') |
| 65 | - | ||
| 66 | - Button(){ | ||
| 67 | - Row(){ | ||
| 68 | - Text('点击跳转至详情或第三方应用') | ||
| 69 | - .fontSize('31lpx') | ||
| 70 | - .fontColor(Color.White) | ||
| 71 | - .margin({ | ||
| 72 | - left:'55lpx' | ||
| 73 | - }) | ||
| 74 | - Image($r('app.media.Slice')) | ||
| 75 | - .width('46lpx') | ||
| 76 | - .height('46lpx') | ||
| 77 | - .margin({right:'55lpx'}) | ||
| 78 | - }.alignItems(VerticalAlign.Center) | 103 | + if(!(this.model.launchAdInfo[0].matInfo.startStyle == 1)){ |
| 104 | + //底部logo样式 按钮加载在背景展示图上 | ||
| 105 | + Button(){ | ||
| 106 | + Row(){ | ||
| 107 | + Text('点击跳转至详情或第三方应用') | ||
| 108 | + .fontSize('31lpx') | ||
| 109 | + .fontColor(Color.White) | ||
| 110 | + .margin({ | ||
| 111 | + left:'55lpx' | ||
| 112 | + }) | ||
| 113 | + Image($r('app.media.Slice')) | ||
| 114 | + .width('46lpx') | ||
| 115 | + .height('46lpx') | ||
| 116 | + .margin({right:'55lpx'}) | ||
| 117 | + }.alignItems(VerticalAlign.Center) | ||
| 118 | + } | ||
| 119 | + .width('566lpx') | ||
| 120 | + .height('111lpx') | ||
| 121 | + .margin({ | ||
| 122 | + bottom: '51lpx' | ||
| 123 | + }) | ||
| 124 | + .backgroundColor('#80000000') | ||
| 125 | + .onClick(()=>{ | ||
| 126 | + this.action() | ||
| 127 | + }) | ||
| 79 | } | 128 | } |
| 80 | - .width('566lpx') | ||
| 81 | - .height('111lpx') | ||
| 82 | - .margin({ | ||
| 83 | - bottom: '51lpx' | ||
| 84 | - }) | ||
| 85 | - .backgroundColor('#80000000') | ||
| 86 | - | ||
| 87 | } | 129 | } |
| 88 | 130 | ||
| 89 | } | 131 | } |
| 90 | .width('100%') | 132 | .width('100%') |
| 91 | .height('84%') | 133 | .height('84%') |
| 92 | - .backgroundColor('#FF6C75') | ||
| 93 | .margin({top:'0'}) | 134 | .margin({top:'0'}) |
| 94 | 135 | ||
| 95 | - Image($r('app.media.LaunchPage_logo')) | ||
| 96 | - .width('278lpx') | ||
| 97 | - .height('154lpx') | ||
| 98 | - .margin({bottom: '48lpx'}) | 136 | + if(this.model.launchAdInfo[0].matInfo.startStyle == 1){ |
| 137 | + //全屏样式,底部无logo 按钮放在原底部logo位置 | ||
| 138 | + Button(){ | ||
| 139 | + Row(){ | ||
| 140 | + Text('点击跳转至详情或第三方应用') | ||
| 141 | + .fontSize('31lpx') | ||
| 142 | + .fontColor(Color.White) | ||
| 143 | + .margin({ | ||
| 144 | + left:'55lpx' | ||
| 145 | + }) | ||
| 146 | + Image($r('app.media.Slice')) | ||
| 147 | + .width('46lpx') | ||
| 148 | + .height('46lpx') | ||
| 149 | + .margin({right:'55lpx'}) | ||
| 150 | + }.alignItems(VerticalAlign.Center) | ||
| 151 | + } | ||
| 152 | + .width('566lpx') | ||
| 153 | + .height('111lpx') | ||
| 154 | + .margin({ | ||
| 155 | + top: '28lpx' | ||
| 156 | + }) | ||
| 157 | + .backgroundColor('#80000000') | ||
| 158 | + .onClick(()=>{ | ||
| 159 | + this.action() | ||
| 160 | + }) | ||
| 161 | + }else { | ||
| 162 | + //底部logo样式 | ||
| 163 | + Image($r('app.media.LaunchPage_logo')) | ||
| 164 | + .width('278lpx') | ||
| 165 | + .height('154lpx') | ||
| 166 | + .margin({top: '28lpx'}) | ||
| 167 | + } | ||
| 168 | + | ||
| 99 | } | 169 | } |
| 100 | .width('100%') | 170 | .width('100%') |
| 101 | .height('100%') | 171 | .height('100%') |
| 102 | .backgroundColor(Color.White) | 172 | .backgroundColor(Color.White) |
| 103 | - | ||
| 104 | } | 173 | } |
| 105 | 174 | ||
| 106 | 175 | ||
| 176 | + action(){ | ||
| 177 | + //跳转 url linkUrl https://news.bjd.com.cn/2024/03/19/10724331.shtml | ||
| 178 | + // openType 端外 端内 打开 | ||
| 179 | + if (this.model.launchAdInfo[0].matInfo.openType == '2') { | ||
| 180 | + //端外打开 | ||
| 181 | + let context = getContext(this) as common.UIAbilityContext; | ||
| 182 | + let wantInfo: Want = { | ||
| 183 | + // uncomment line below if wish to implicitly query only in the specific bundle. | ||
| 184 | + // bundleName: 'com.example.myapplication', | ||
| 185 | + action: 'ohos.want.action.viewData', | ||
| 186 | + // entities can be omitted. | ||
| 187 | + entities: ['entity.system.browsable'], | ||
| 188 | + uri: 'https://news.bjd.com.cn/2024/03/19/10724331.shtml' | ||
| 189 | + } | ||
| 190 | + context.startAbility(wantInfo).then(() => { | ||
| 191 | + // ... | ||
| 192 | + }).catch((err: BusinessError) => { | ||
| 193 | + // ... | ||
| 194 | + }) | ||
| 195 | + }else { | ||
| 196 | + //端内打开 | ||
| 197 | + | ||
| 198 | + | ||
| 199 | + } | ||
| 200 | + } | ||
| 201 | + | ||
| 107 | 202 | ||
| 108 | 203 | ||
| 109 | } | 204 | } |
| @@ -10,6 +10,9 @@ import { WDRouterRule } from 'wdRouter'; | @@ -10,6 +10,9 @@ import { WDRouterRule } from 'wdRouter'; | ||
| 10 | import { WDRouterPage } from 'wdRouter'; | 10 | import { WDRouterPage } from 'wdRouter'; |
| 11 | import { LaunchModel } from '../viewModel/LaunchModel' | 11 | import { LaunchModel } from '../viewModel/LaunchModel' |
| 12 | import { LaunchPageModel } from '../viewModel/LaunchPageModel' | 12 | import { LaunchPageModel } from '../viewModel/LaunchPageModel' |
| 13 | +import LaunchDataModel from '../viewModel/LaunchDataModel' | ||
| 14 | +import { Logger, SPHelper } from 'wdKit/Index'; | ||
| 15 | +import { SpConstants } from 'wdConstant/Index'; | ||
| 13 | 16 | ||
| 14 | @Entry | 17 | @Entry |
| 15 | @Component | 18 | @Component |
| @@ -92,8 +95,19 @@ struct LaunchPage { | @@ -92,8 +95,19 @@ struct LaunchPage { | ||
| 92 | // } | 95 | // } |
| 93 | } else { | 96 | } else { |
| 94 | //需要根据请求数据判断是否需要进入广告页,广告数据为nil则直接跳转到首页 | 97 | //需要根据请求数据判断是否需要进入广告页,广告数据为nil则直接跳转到首页 |
| 95 | - //跳转广告页 | ||
| 96 | - this.jumpToAdvertisingPage(); | 98 | + //获取本地存储的启动页数据 |
| 99 | + | ||
| 100 | + let dataModelStr : string = SPHelper.default.getSync(SpConstants.APP_LAUNCH_PAGE_DATA_MODEL,'') as string | ||
| 101 | + let dataModel : LaunchDataModel = JSON.parse(dataModelStr) | ||
| 102 | + console.log(dataModelStr) | ||
| 103 | + | ||
| 104 | + if (dataModel.launchAdInfo.length) { | ||
| 105 | + //跳转广告页 | ||
| 106 | + this.jumpToAdvertisingPage(); | ||
| 107 | + }else { | ||
| 108 | + //直接跳转首页 | ||
| 109 | + WDRouterRule.jumpWithReplacePage(WDRouterPage.mainPage) | ||
| 110 | + } | ||
| 97 | //同意隐私协议后每次启动app请求启动页相关数据,并更新数据 | 111 | //同意隐私协议后每次启动app请求启动页相关数据,并更新数据 |
| 98 | this.requestLaunchPageData(); | 112 | this.requestLaunchPageData(); |
| 99 | } | 113 | } |
| @@ -161,7 +175,6 @@ struct LaunchPage { | @@ -161,7 +175,6 @@ struct LaunchPage { | ||
| 161 | //请求启动页相关接口数据并保存 | 175 | //请求启动页相关接口数据并保存 |
| 162 | let launchPageModel = new LaunchPageModel() | 176 | let launchPageModel = new LaunchPageModel() |
| 163 | launchPageModel.getLaunchPageData() | 177 | launchPageModel.getLaunchPageData() |
| 164 | - | ||
| 165 | } | 178 | } |
| 166 | 179 | ||
| 167 | aboutToAppear(): void { | 180 | aboutToAppear(): void { |
| @@ -40,6 +40,7 @@ export interface NetLayerLauncherADInfoModel{ | @@ -40,6 +40,7 @@ export interface NetLayerLauncherADInfoModel{ | ||
| 40 | startTime : number | 40 | startTime : number |
| 41 | endTime : number | 41 | endTime : number |
| 42 | displayDuration : number | 42 | displayDuration : number |
| 43 | + displayPriority : number | ||
| 43 | displayRound : number | 44 | displayRound : number |
| 44 | matInfo : NetLayerLauncherADMaterialModel | 45 | matInfo : NetLayerLauncherADMaterialModel |
| 45 | 46 |
| @@ -11,7 +11,7 @@ import { SpConstants } from 'wdConstant/Index'; | @@ -11,7 +11,7 @@ import { SpConstants } from 'wdConstant/Index'; | ||
| 11 | 11 | ||
| 12 | export class LaunchPageModel { | 12 | export class LaunchPageModel { |
| 13 | 13 | ||
| 14 | - getLaunchPageData() { | 14 | + getLaunchPageData(): Promise<LaunchDataModel> { |
| 15 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 15 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 16 | return new Promise<LaunchDataModel>((success, fail) => { | 16 | return new Promise<LaunchDataModel>((success, fail) => { |
| 17 | HttpRequest.get<ResponseDTO<LaunchDataModel>>(HttpUrlUtils.getLaunchPageDataUrl(), headers).then((data: ResponseDTO<LaunchDataModel>) => { | 17 | HttpRequest.get<ResponseDTO<LaunchDataModel>>(HttpUrlUtils.getLaunchPageDataUrl(), headers).then((data: ResponseDTO<LaunchDataModel>) => { |
| @@ -26,8 +26,9 @@ export class LaunchPageModel { | @@ -26,8 +26,9 @@ export class LaunchPageModel { | ||
| 26 | Logger.debug("LaunchPageModel获取启动相关数据获取成功:success ", JSON.stringify(data)) | 26 | Logger.debug("LaunchPageModel获取启动相关数据获取成功:success ", JSON.stringify(data)) |
| 27 | success(data.data); | 27 | success(data.data); |
| 28 | //存储数据 | 28 | //存储数据 |
| 29 | - | ||
| 30 | - | 29 | + let obj : string = JSON.stringify(data.data) |
| 30 | + console.log(obj) | ||
| 31 | + SPHelper.default.saveSync(SpConstants.APP_LAUNCH_PAGE_DATA_MODEL,obj) | ||
| 31 | 32 | ||
| 32 | }, (error: Error) => { | 33 | }, (error: Error) => { |
| 33 | Logger.debug("LaunchPageModel获取启动相关数据获取失败:error ", error.toString()) | 34 | Logger.debug("LaunchPageModel获取启动相关数据获取失败:error ", error.toString()) |
-
Please register or login to post a comment