Showing
18 changed files
with
261 additions
and
45 deletions
| @@ -66,4 +66,10 @@ export class SpConstants{ | @@ -66,4 +66,10 @@ export class SpConstants{ | ||
| 66 | static GETUI_PUSH_DEVICE_TOKEN = "deviceToken" | 66 | static GETUI_PUSH_DEVICE_TOKEN = "deviceToken" |
| 67 | //link | 67 | //link |
| 68 | static HAS_LINK="has_link" | 68 | static HAS_LINK="has_link" |
| 69 | + | ||
| 70 | + // 是否开启H5白名单 | ||
| 71 | + static H5_WHITE_LIST_ENABLE ="h5_whilte_list_enable" | ||
| 72 | + static H5_WHITE_LIST_LAST_DATA_MD5 ="h5_whilte_list_last_data_md5" | ||
| 73 | + | ||
| 74 | + | ||
| 69 | } | 75 | } |
| 1 | 1 | ||
| 2 | import fs from '@ohos.file.fs'; | 2 | import fs from '@ohos.file.fs'; |
| 3 | import { BusinessError } from '@kit.BasicServicesKit'; | 3 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 4 | +import { util } from '@kit.ArkTS'; | ||
| 4 | 5 | ||
| 5 | export class FileUtils { | 6 | export class FileUtils { |
| 6 | 7 | ||
| @@ -31,4 +32,26 @@ export class FileUtils { | @@ -31,4 +32,26 @@ export class FileUtils { | ||
| 31 | }) | 32 | }) |
| 32 | }) | 33 | }) |
| 33 | } | 34 | } |
| 35 | + | ||
| 36 | + static readFile(path: string): ArrayBuffer { | ||
| 37 | + try { | ||
| 38 | + let stat = fs.statSync(path) | ||
| 39 | + let fd = fs.openSync(path, fs.OpenMode.READ_ONLY).fd; | ||
| 40 | + let length = stat.size | ||
| 41 | + let buf = new ArrayBuffer(length); | ||
| 42 | + fs.readSync(fd, buf) | ||
| 43 | + fs.closeSync(fd) | ||
| 44 | + return buf | ||
| 45 | + } catch (e) { | ||
| 46 | + console.log("FileUtils - readFilePicSync " + e) | ||
| 47 | + return new ArrayBuffer(0) | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + static readFileAsString(path: string): string { | ||
| 52 | + const data = FileUtils.readFile(path) | ||
| 53 | + let decoder = util.TextDecoder.create('utf-8'); | ||
| 54 | + let str = decoder.decodeToString(new Uint8Array(data)); | ||
| 55 | + return str | ||
| 56 | + } | ||
| 34 | } | 57 | } |
| 1 | import { SpConstants } from 'wdConstant/Index'; | 1 | import { SpConstants } from 'wdConstant/Index'; |
| 2 | -import { DeviceUtil, SPHelper, StringUtils } from 'wdKit/Index'; | 2 | +import { DeviceUtil, Logger, SPHelper, StringUtils } from 'wdKit/Index'; |
| 3 | import { HttpRequest } from '../http/HttpRequest'; | 3 | import { HttpRequest } from '../http/HttpRequest'; |
| 4 | +import { http } from '@kit.NetworkKit'; | ||
| 5 | +import fs from '@ohos.file.fs'; | ||
| 6 | +import { BusinessError } from '@kit.BasicServicesKit'; | ||
| 7 | +import { JSON } from '@kit.ArkTS'; | ||
| 4 | 8 | ||
| 5 | const TAG: string = '[HttpUtils]' | 9 | const TAG: string = '[HttpUtils]' |
| 6 | 10 | ||
| @@ -81,4 +85,37 @@ export class HttpUtils { | @@ -81,4 +85,37 @@ export class HttpUtils { | ||
| 81 | } | 85 | } |
| 82 | return true | 86 | return true |
| 83 | } | 87 | } |
| 88 | + | ||
| 89 | + static downloadUrlToPathWithout(url: string, toFilePath: string): Promise<boolean> { | ||
| 90 | + Logger.debug(TAG, "will donwload url:" + url + " ======> " + toFilePath); | ||
| 91 | + | ||
| 92 | + return new Promise((reslove, fail) => { | ||
| 93 | + | ||
| 94 | + let httpRequest = http.createHttp() | ||
| 95 | + httpRequest.request(url, (err, data) => { | ||
| 96 | + | ||
| 97 | + if (!err && data.responseCode == http.ResponseCode.OK) { | ||
| 98 | + let imgFile = fs.openSync(toFilePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); | ||
| 99 | + let wroteLength = 0 | ||
| 100 | + fs.write(imgFile.fd, data.result as ArrayBuffer).then((writeLen: number) => { | ||
| 101 | + Logger.debug(TAG, "write data to file succeed and size is:" + writeLen); | ||
| 102 | + wroteLength = writeLen | ||
| 103 | + }).catch((err: BusinessError) => { | ||
| 104 | + Logger.error(TAG, "write data to file failed with error message: " + err.message + ", error code: " + err.code); | ||
| 105 | + }).finally(() => { | ||
| 106 | + fs.closeSync(imgFile); | ||
| 107 | + httpRequest.destroy() | ||
| 108 | + | ||
| 109 | + reslove(wroteLength > 0) | ||
| 110 | + }); | ||
| 111 | + return | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + Logger.error(TAG, "download failed " + JSON.stringify(err)); | ||
| 115 | + httpRequest.destroy() | ||
| 116 | + fail("failed") | ||
| 117 | + }); | ||
| 118 | + | ||
| 119 | + }) | ||
| 120 | + } | ||
| 84 | } | 121 | } |
| @@ -258,7 +258,10 @@ export struct H5NewsWebPageComponent { | @@ -258,7 +258,10 @@ export struct H5NewsWebPageComponent { | ||
| 258 | // 初次进入详情页偶现获取失败,重新获取newsStatusOfUser对象 | 258 | // 初次进入详情页偶现获取失败,重新获取newsStatusOfUser对象 |
| 259 | this.getInteractDataStatus() | 259 | this.getInteractDataStatus() |
| 260 | } | 260 | } |
| 261 | + }).catch((error:Error) =>{ | ||
| 262 | + ToastUtils.showToast(error.message, 1000); | ||
| 261 | }) | 263 | }) |
| 264 | + | ||
| 262 | } | 265 | } |
| 263 | 266 | ||
| 264 | /** | 267 | /** |
| @@ -465,7 +465,10 @@ export struct ImageAndTextPageComponent { | @@ -465,7 +465,10 @@ export struct ImageAndTextPageComponent { | ||
| 465 | // 初次进入详情页偶现获取失败,重新获取newsStatusOfUser对象 | 465 | // 初次进入详情页偶现获取失败,重新获取newsStatusOfUser对象 |
| 466 | this.getInteractDataStatus() | 466 | this.getInteractDataStatus() |
| 467 | } | 467 | } |
| 468 | + }).catch((error:Error) =>{ | ||
| 469 | + ToastUtils.showToast(error.message, 1000); | ||
| 468 | }) | 470 | }) |
| 471 | + | ||
| 469 | } | 472 | } |
| 470 | 473 | ||
| 471 | /** | 474 | /** |
| @@ -537,6 +537,8 @@ export struct OperRowListView { | @@ -537,6 +537,8 @@ export struct OperRowListView { | ||
| 537 | this.queryContentInteractCount() | 537 | this.queryContentInteractCount() |
| 538 | } | 538 | } |
| 539 | console.log(TAG, '收藏点击 this.newsStatusOfUser', JSON.stringify(this.newsStatusOfUser)) | 539 | console.log(TAG, '收藏点击 this.newsStatusOfUser', JSON.stringify(this.newsStatusOfUser)) |
| 540 | + }).catch((error:Error) =>{ | ||
| 541 | + ToastUtils.showToast(error.message, 1000); | ||
| 540 | }) | 542 | }) |
| 541 | } | 543 | } |
| 542 | 544 |
| @@ -51,6 +51,8 @@ export struct DetailPlayVLivePage { | @@ -51,6 +51,8 @@ export struct DetailPlayVLivePage { | ||
| 51 | @State toastText: ResourceStr = "这是一个非Wi-Fi环境。请注意流量消耗" | 51 | @State toastText: ResourceStr = "这是一个非Wi-Fi环境。请注意流量消耗" |
| 52 | chatRoomController: LiveDetailChatRoomController = new LiveDetailChatRoomController() | 52 | chatRoomController: LiveDetailChatRoomController = new LiveDetailChatRoomController() |
| 53 | @Provide banComment: boolean = true | 53 | @Provide banComment: boolean = true |
| 54 | + /// null 直播流画面类型未知,0 横屏流,1 竖屏流,后台选择画面时,以选择的为准 | ||
| 55 | + @Provide isVerticalStream: boolean | null = this.liveDetailPageLogic.dealLiveStreamType() | ||
| 54 | 56 | ||
| 55 | dialogToast: CustomDialogController = new CustomDialogController({ | 57 | dialogToast: CustomDialogController = new CustomDialogController({ |
| 56 | builder: CustomToast({ | 58 | builder: CustomToast({ |
| @@ -109,4 +109,20 @@ export class LiveDetailPageLogic { | @@ -109,4 +109,20 @@ export class LiveDetailPageLogic { | ||
| 109 | return false | 109 | return false |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | + dealLiveStreamType(): boolean | null { | ||
| 113 | + if (this.contentDetailData.liveInfo.vlive && this.contentDetailData.liveInfo.vlive.count > 0) { | ||
| 114 | + const liveStreamType: number | null = this.contentDetailData.liveInfo.vlive[0].liveStreamType | ||
| 115 | + if (liveStreamType == null) { ///直播流画面类型位置 | ||
| 116 | + return null | ||
| 117 | + } | ||
| 118 | + if (liveStreamType == 1) { ///后台选择的竖屏流 | ||
| 119 | + return true | ||
| 120 | + } | ||
| 121 | + if (liveStreamType == 0) { ///后台选择的横屏流 | ||
| 122 | + return false | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + return true | ||
| 126 | + } | ||
| 127 | + | ||
| 112 | } | 128 | } |
| @@ -27,6 +27,7 @@ export struct PlayerComponent { | @@ -27,6 +27,7 @@ export struct PlayerComponent { | ||
| 27 | @Link isPlayerError: boolean | 27 | @Link isPlayerError: boolean |
| 28 | @Link isCanplay: boolean | 28 | @Link isCanplay: boolean |
| 29 | @State isLarge:boolean = false | 29 | @State isLarge:boolean = false |
| 30 | + @Consume isVerticalStream: boolean | ||
| 30 | pageShowChange() { | 31 | pageShowChange() { |
| 31 | this.playerController?.play() | 32 | this.playerController?.play() |
| 32 | } | 33 | } |
| @@ -54,13 +55,15 @@ export struct PlayerComponent { | @@ -54,13 +55,15 @@ export struct PlayerComponent { | ||
| 54 | 55 | ||
| 55 | } | 56 | } |
| 56 | this.playerController.onVideoSizePlayerComponentBack = (width: number, height: number) => { | 57 | this.playerController.onVideoSizePlayerComponentBack = (width: number, height: number) => { |
| 57 | - if(width>height){ | 58 | + if (this.isVerticalStream != null) { |
| 59 | + return | ||
| 60 | + } | ||
| 61 | + if (width > height) { | ||
| 58 | this.isLarge = false | 62 | this.isLarge = false |
| 59 | - if(width > 2){ | ||
| 60 | - this.liveStreamType = 0 | ||
| 61 | - } | ||
| 62 | - }else{ | 63 | + this.liveStreamType = 0 |
| 64 | + }else { | ||
| 63 | this.isLarge = true | 65 | this.isLarge = true |
| 66 | + this.liveStreamType = 1 | ||
| 64 | } | 67 | } |
| 65 | } | 68 | } |
| 66 | } | 69 | } |
| @@ -17,6 +17,7 @@ export struct PlayerUIComponent { | @@ -17,6 +17,7 @@ export struct PlayerUIComponent { | ||
| 17 | @Consume isFullScreen: boolean | 17 | @Consume isFullScreen: boolean |
| 18 | @Consume displayDirection: DisplayDirection | 18 | @Consume displayDirection: DisplayDirection |
| 19 | @State isPlayStatus: boolean = true; | 19 | @State isPlayStatus: boolean = true; |
| 20 | + @Consume isVerticalStream: boolean | null | ||
| 20 | onChangeMenuVisible() { | 21 | onChangeMenuVisible() { |
| 21 | if (this.displayDirection == DisplayDirection.VERTICAL | 22 | if (this.displayDirection == DisplayDirection.VERTICAL |
| 22 | || !this.isShowControl | 23 | || !this.isShowControl |
| @@ -38,6 +39,10 @@ export struct PlayerUIComponent { | @@ -38,6 +39,10 @@ export struct PlayerUIComponent { | ||
| 38 | return | 39 | return |
| 39 | } | 40 | } |
| 40 | this.playerController.onVideoSizePlayerUIComponentMethod = (width: number, height: number) => { | 41 | this.playerController.onVideoSizePlayerUIComponentMethod = (width: number, height: number) => { |
| 42 | + if (this.isVerticalStream != null) { | ||
| 43 | + this.isSmall = this.isVerticalStream == false | ||
| 44 | + return | ||
| 45 | + } | ||
| 41 | if (width > height){ | 46 | if (width > height){ |
| 42 | this.isSmall = true | 47 | this.isSmall = true |
| 43 | } else { | 48 | } else { |
| @@ -16,7 +16,6 @@ export struct PlayerVideoControlComponent { | @@ -16,7 +16,6 @@ export struct PlayerVideoControlComponent { | ||
| 16 | @Link isPlayStatus?: boolean | 16 | @Link isPlayStatus?: boolean |
| 17 | @Consume displayDirection: DisplayDirection | 17 | @Consume displayDirection: DisplayDirection |
| 18 | @Consume contentDetailData: ContentDetailDTO | 18 | @Consume contentDetailData: ContentDetailDTO |
| 19 | - @Consume isSmall:boolean | ||
| 20 | @Consume isFullScreen: boolean | 19 | @Consume isFullScreen: boolean |
| 21 | @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 | 20 | @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 |
| 22 | aboutToAppear(): void { | 21 | aboutToAppear(): void { |
| @@ -61,37 +60,6 @@ export struct PlayerVideoControlComponent { | @@ -61,37 +60,6 @@ export struct PlayerVideoControlComponent { | ||
| 61 | right: 16 | 60 | right: 16 |
| 62 | }) | 61 | }) |
| 63 | } | 62 | } |
| 64 | - //全屏按钮 | ||
| 65 | - // if(!this.isSmall) { | ||
| 66 | - // Image($r('app.media.icon_live_player_full_screen')) | ||
| 67 | - // .height(32) | ||
| 68 | - // .width(32) | ||
| 69 | - // .padding(5) | ||
| 70 | - // .borderRadius($r('app.float.vp_16')) | ||
| 71 | - // .border({width:0.5}) | ||
| 72 | - // .borderColor(0x4DFFFFFF) | ||
| 73 | - // .backgroundColor(0x4D222222) | ||
| 74 | - // .margin({right:10}) | ||
| 75 | - // .onClick(() => { | ||
| 76 | - // WindowModel.shared.setSpecificSystemBarEnabled(false) | ||
| 77 | - // this.displayDirection = DisplayDirection.VIDEO_HORIZONTAL | ||
| 78 | - // WindowModel.shared.setPreferredOrientation( | ||
| 79 | - // window.Orientation.LANDSCAPE) | ||
| 80 | - // if(this.playerController){ | ||
| 81 | - // // if(this.playerController.onVideoSizePlayerUIComponentMethod){ | ||
| 82 | - // // this.playerController.onVideoSizePlayerUIComponentMethod(1,2) | ||
| 83 | - // // } | ||
| 84 | - // if(this.playerController.onVideoSizePlayerComponentBack){ | ||
| 85 | - // this.playerController.onVideoSizePlayerComponentBack(1,2) | ||
| 86 | - // } | ||
| 87 | - // | ||
| 88 | - // if(this.playerController.onVideoSizePlayerTitleComponentBack){ | ||
| 89 | - // this.playerController.onVideoSizePlayerTitleComponentBack(1,2) | ||
| 90 | - // } | ||
| 91 | - // } | ||
| 92 | - // this.isFullScreen = true | ||
| 93 | - // }) | ||
| 94 | - // } | ||
| 95 | } | 63 | } |
| 96 | .alignItems(VerticalAlign.Center) | 64 | .alignItems(VerticalAlign.Center) |
| 97 | // .linearGradient({ angle: 0, colors: [['#99000000', 0], ['#00000000', 1]] }) | 65 | // .linearGradient({ angle: 0, colors: [['#99000000', 0], ['#00000000', 1]] }) |
| @@ -90,7 +90,10 @@ export struct OperationListView { | @@ -90,7 +90,10 @@ export struct OperationListView { | ||
| 90 | // console.log('点赞、取消点赞==', this.newsStatusOfUser?.likeStatus, this.interactData?.likeNum) | 90 | // console.log('点赞、取消点赞==', this.newsStatusOfUser?.likeStatus, this.interactData?.likeNum) |
| 91 | // this.queryContentInteractCount() | 91 | // this.queryContentInteractCount() |
| 92 | } | 92 | } |
| 93 | + }).catch((error:Error) =>{ | ||
| 94 | + ToastUtils.showToast(error.message, 1000); | ||
| 93 | }) | 95 | }) |
| 96 | + | ||
| 94 | } | 97 | } |
| 95 | 98 | ||
| 96 | /** | 99 | /** |
| @@ -124,8 +127,11 @@ export struct OperationListView { | @@ -124,8 +127,11 @@ export struct OperationListView { | ||
| 124 | } | 127 | } |
| 125 | // console.log('收藏、取消收藏==', this.newsStatusOfUser?.collectStatus, this.interactData?.collectNum) | 128 | // console.log('收藏、取消收藏==', this.newsStatusOfUser?.collectStatus, this.interactData?.collectNum) |
| 126 | } | 129 | } |
| 130 | + }).catch((error:Error) =>{ | ||
| 131 | + ToastUtils.showToast(error.message, 1000); | ||
| 127 | }) | 132 | }) |
| 128 | 133 | ||
| 134 | + | ||
| 129 | } | 135 | } |
| 130 | 136 | ||
| 131 | /** | 137 | /** |
| @@ -114,7 +114,10 @@ export struct PlayerRightView { | @@ -114,7 +114,10 @@ export struct PlayerRightView { | ||
| 114 | // this.queryContentInteractCount() | 114 | // this.queryContentInteractCount() |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | + }).catch((error:Error) =>{ | ||
| 118 | + ToastUtils.showToast(error.message, 1000); | ||
| 117 | }) | 119 | }) |
| 120 | + | ||
| 118 | } | 121 | } |
| 119 | 122 | ||
| 120 | /** | 123 | /** |
| @@ -152,8 +155,11 @@ export struct PlayerRightView { | @@ -152,8 +155,11 @@ export struct PlayerRightView { | ||
| 152 | } | 155 | } |
| 153 | // console.log(TAG, '收藏、取消收藏==', this.newsStatusOfUser?.collectStatus, this.interactData?.collectNum) | 156 | // console.log(TAG, '收藏、取消收藏==', this.newsStatusOfUser?.collectStatus, this.interactData?.collectNum) |
| 154 | } | 157 | } |
| 158 | + }).catch((error:Error) =>{ | ||
| 159 | + ToastUtils.showToast(error.message, 1000); | ||
| 155 | }) | 160 | }) |
| 156 | 161 | ||
| 162 | + | ||
| 157 | } | 163 | } |
| 158 | 164 | ||
| 159 | /** | 165 | /** |
| @@ -114,6 +114,9 @@ struct LaunchPage { | @@ -114,6 +114,9 @@ struct LaunchPage { | ||
| 114 | if (!dataModelStr) { | 114 | if (!dataModelStr) { |
| 115 | //直接跳转首页 | 115 | //直接跳转首页 |
| 116 | WDRouterRule.jumpWithReplacePage(WDRouterPage.mainPage) | 116 | WDRouterRule.jumpWithReplacePage(WDRouterPage.mainPage) |
| 117 | + | ||
| 118 | + //同意隐私协议后每次启动app请求启动页相关数据,并更新数据 | ||
| 119 | + this.requestLaunchPageData(); | ||
| 117 | return | 120 | return |
| 118 | } | 121 | } |
| 119 | 122 |
| @@ -2,22 +2,26 @@ | @@ -2,22 +2,26 @@ | ||
| 2 | import LaunchDataModel from '../viewModel/LaunchDataModel' | 2 | import LaunchDataModel from '../viewModel/LaunchDataModel' |
| 3 | 3 | ||
| 4 | import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest'; | 4 | import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest'; |
| 5 | -import { HttpUrlUtils, ResponseDTO } from 'wdNetwork/Index'; | ||
| 6 | -import { DisplayUtils, Logger, SPHelper } from 'wdKit/Index'; | 5 | +import { HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork/Index'; |
| 6 | +import { AppUtils, DisplayUtils, Logger, SPHelper } from 'wdKit/Index'; | ||
| 7 | import { SpConstants } from 'wdConstant/Index'; | 7 | import { SpConstants } from 'wdConstant/Index'; |
| 8 | +import { FileUtils } from '@ohos/imageknife'; | ||
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | export class LaunchPageModel { | 11 | export class LaunchPageModel { |
| 11 | 12 | ||
| 12 | getLaunchPageData(): Promise<LaunchDataModel> { | 13 | getLaunchPageData(): Promise<LaunchDataModel> { |
| 13 | return new Promise<LaunchDataModel>((success, fail) => { | 14 | return new Promise<LaunchDataModel>((success, fail) => { |
| 14 | - HttpRequest.get<ResponseDTO<LaunchDataModel>>(HttpUrlUtils.getLaunchPageDataUrl()+ `?height=${DisplayUtils.getDeviceHeight()}&width=${DisplayUtils.getDeviceWidth()}`).then((data: ResponseDTO<LaunchDataModel>) => { | 15 | + HttpRequest.get<ResponseDTO<LaunchDataModel>>(HttpUrlUtils.getLaunchPageDataUrl()+ `?height=${DisplayUtils.getDeviceHeight()}&width=${DisplayUtils.getDeviceWidth()}`) |
| 16 | + .then(async (data: ResponseDTO<LaunchDataModel>) => { | ||
| 15 | if (!data || !data.data) { | 17 | if (!data || !data.data) { |
| 16 | fail("数据为空") | 18 | fail("数据为空") |
| 19 | + LaunchPageModel.dealWithLaunchDataModel() | ||
| 17 | return | 20 | return |
| 18 | } | 21 | } |
| 19 | if (data.code != 0) { | 22 | if (data.code != 0) { |
| 20 | fail(data.message) | 23 | fail(data.message) |
| 24 | + LaunchPageModel.dealWithLaunchDataModel() | ||
| 21 | return | 25 | return |
| 22 | } | 26 | } |
| 23 | // Logger.debug("LaunchPageModel获取启动相关数据获取成功:success ", JSON.stringify(data)) | 27 | // Logger.debug("LaunchPageModel获取启动相关数据获取成功:success ", JSON.stringify(data)) |
| @@ -27,6 +31,8 @@ export class LaunchPageModel { | @@ -27,6 +31,8 @@ export class LaunchPageModel { | ||
| 27 | // console.log(obj) | 31 | // console.log(obj) |
| 28 | SPHelper.default.saveSync(SpConstants.APP_LAUNCH_PAGE_DATA_MODEL,obj) | 32 | SPHelper.default.saveSync(SpConstants.APP_LAUNCH_PAGE_DATA_MODEL,obj) |
| 29 | 33 | ||
| 34 | + LaunchPageModel.dealWithLaunchDataModel(data.data) | ||
| 35 | + | ||
| 30 | }, (error: Error) => { | 36 | }, (error: Error) => { |
| 31 | // Logger.debug("LaunchPageModel获取启动相关数据获取失败:error ", error.toString()) | 37 | // Logger.debug("LaunchPageModel获取启动相关数据获取失败:error ", error.toString()) |
| 32 | fail(error.message) | 38 | fail(error.message) |
| @@ -34,6 +40,47 @@ export class LaunchPageModel { | @@ -34,6 +40,47 @@ export class LaunchPageModel { | ||
| 34 | }) | 40 | }) |
| 35 | } | 41 | } |
| 36 | 42 | ||
| 43 | + static async dealWithLaunchDataModel(model?: LaunchDataModel) { | ||
| 44 | + if (!model) { | ||
| 45 | + let dataModelStr = SPHelper.default.getSync(SpConstants.APP_LAUNCH_PAGE_DATA_MODEL, '') as string | ||
| 46 | + model = JSON.parse(dataModelStr ?? "") | ||
| 47 | + if (!model) { return } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + LaunchPageModel.dealWithWhiteListWith(model) | ||
| 51 | + | ||
| 52 | + // TODO: others | ||
| 53 | + | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + static async dealWithWhiteListWith(model: LaunchDataModel) { | ||
| 61 | + SPHelper.default.saveSync(SpConstants.H5_WHITE_LIST_ENABLE, model.operationUrl.enabled) | ||
| 62 | + | ||
| 63 | + const lastMD5 = SPHelper.default.getSync(SpConstants.H5_WHITE_LIST_LAST_DATA_MD5, "") as string | ||
| 64 | + if (lastMD5 && lastMD5 == model.operationUrl.md5) { | ||
| 65 | + // MD5未变更,保持已下载的白名单 | ||
| 66 | + if (AppUtils.gotApplicationContextFunc) { | ||
| 67 | + let filePath = AppUtils.gotApplicationContextFunc().getApplicationContext().filesDir + "/h5_whitelist.txt" | ||
| 68 | + if (FileUtils.getInstance().exist(filePath)) { | ||
| 69 | + return | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + if (!AppUtils.gotApplicationContextFunc) { | ||
| 75 | + return | ||
| 76 | + } | ||
| 77 | + let filePath = AppUtils.gotApplicationContextFunc().getApplicationContext().filesDir + "/h5_whitelist.txt" | ||
| 78 | + const result = await HttpUtils.downloadUrlToPathWithout(model.operationUrl.linkUrl, filePath) | ||
| 79 | + if (result) { | ||
| 80 | + SPHelper.default.saveSync(SpConstants.H5_WHITE_LIST_LAST_DATA_MD5, model.operationUrl.md5 ?? "") | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 37 | getMournsInfoData(): Promise<LaunchDataModel> { | 84 | getMournsInfoData(): Promise<LaunchDataModel> { |
| 38 | return new Promise<LaunchDataModel>((success, fail) => { | 85 | return new Promise<LaunchDataModel>((success, fail) => { |
| 39 | HttpRequest.get<ResponseDTO<LaunchDataModel>>(HttpUrlUtils.getLaunchPageDataUrl()).then((data: ResponseDTO<LaunchDataModel>) => { | 86 | HttpRequest.get<ResponseDTO<LaunchDataModel>>(HttpUrlUtils.getLaunchPageDataUrl()).then((data: ResponseDTO<LaunchDataModel>) => { |
| @@ -62,10 +62,8 @@ struct H5TipsPage { | @@ -62,10 +62,8 @@ struct H5TipsPage { | ||
| 62 | 62 | ||
| 63 | // 获取系统剪贴板对象 | 63 | // 获取系统剪贴板对象 |
| 64 | let systemPasteboard = pasteboard.getSystemPasteboard(); | 64 | let systemPasteboard = pasteboard.getSystemPasteboard(); |
| 65 | - // 创建一条纯文本类型的剪贴板内容对象createPlainTextData | ||
| 66 | - let pasteData = pasteboard.createPlainTextData(this.webUrl); | ||
| 67 | - pasteData.addTextRecord(this.webUrl); | ||
| 68 | - // 将数据写入系统剪贴板 | 65 | + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, this.webUrl) |
| 66 | + // // 将数据写入系统剪贴板 | ||
| 69 | systemPasteboard.setData(pasteData).then(()=>{ | 67 | systemPasteboard.setData(pasteData).then(()=>{ |
| 70 | // 存入成功,处理正常场景 | 68 | // 存入成功,处理正常场景 |
| 71 | ToastUtils.shortToast('复制成功') | 69 | ToastUtils.shortToast('复制成功') |
| 1 | +import { FileUtils as imageFileUtils } from '@ohos/imageknife' | ||
| 2 | +import { Action } from 'wdBean' | ||
| 3 | +import { AppUtils, FileUtils, SPHelper } from 'wdKit' | ||
| 4 | +import { JumpInterceptorAction, RouterJumpInterceptor, WDRouterPage } from 'wdRouter' | ||
| 5 | +import { JSON, uri } from '@kit.ArkTS' | ||
| 6 | +import { SpConstants } from 'wdConstant' | ||
| 7 | +import { router } from '@kit.ArkUI' | ||
| 8 | + | ||
| 9 | +interface WhiteListModel { | ||
| 10 | + whiteurls: string[] | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +class DefaultWebJumpHandler implements JumpInterceptorAction { | ||
| 14 | + | ||
| 15 | + /// 说明是调用了跳转 WDRouterPage.loginPage 页面的行为 | ||
| 16 | + on(params?: object | undefined, singleMode?: boolean | undefined): boolean { | ||
| 17 | + let action = params as Action | ||
| 18 | + | ||
| 19 | + if (action.params?.url) { | ||
| 20 | + | ||
| 21 | + const whiteListEnable = SPHelper.default.getSync(SpConstants.H5_WHITE_LIST_ENABLE, false) as boolean | ||
| 22 | + if (!whiteListEnable) { | ||
| 23 | + return false | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + const jumpHost = new uri.URI(action.params?.url).host | ||
| 27 | + const list = this.configWhiteLists() | ||
| 28 | + list.push(...this.localWhiteLists()) | ||
| 29 | + | ||
| 30 | + const inWhilteList = list.filter((host) => { | ||
| 31 | + return host == jumpHost | ||
| 32 | + }).length > 0 | ||
| 33 | + | ||
| 34 | + if (false == inWhilteList) { | ||
| 35 | + router.pushUrl({url: WDRouterPage.h5TipsPage.url(), params: action.params}) | ||
| 36 | + return true | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + return false | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + configWhiteLists() : string[] { | ||
| 43 | + let list : string[] = [] | ||
| 44 | + | ||
| 45 | + if (!AppUtils.gotApplicationContextFunc) { | ||
| 46 | + return list | ||
| 47 | + } | ||
| 48 | + let filePath = AppUtils.gotApplicationContextFunc().getApplicationContext().filesDir + "/h5_whitelist.txt" | ||
| 49 | + const jsonStr = FileUtils.readFileAsString(filePath) | ||
| 50 | + const listObj = JSON.parse(jsonStr) as WhiteListModel | ||
| 51 | + if (listObj && listObj.whiteurls && listObj.whiteurls.length) { | ||
| 52 | + | ||
| 53 | + const urls = listObj.whiteurls.map((obj) => { | ||
| 54 | + if (obj.startsWith("http")) { | ||
| 55 | + return new uri.URI(obj).host | ||
| 56 | + } | ||
| 57 | + return new uri.URI("https://" + obj).host | ||
| 58 | + }) | ||
| 59 | + | ||
| 60 | + list.push(...urls) | ||
| 61 | + } | ||
| 62 | + return list | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + localWhiteLists() : string[] { | ||
| 66 | + const list = [ | ||
| 67 | + "https://cdnpeoplefrontdev.aikan.pdnews.cn", | ||
| 68 | + "https://cdnpeoplefrontsit.aikan.pdnews.cn", | ||
| 69 | + "https://cdnpeoplefrontuat.aikan.pdnews.cn", | ||
| 70 | + "https://cdnpeoplefront.aikan.pdnews.cn", | ||
| 71 | + "https://pd-people-uat.pdnews.cn", | ||
| 72 | + "https://pd-people-sit.pdnews.cn", | ||
| 73 | + "https://pd-people-dev.pdnews.cn", | ||
| 74 | + "https://www.peopleapp.com", | ||
| 75 | + "https://h5.peopleapp.com" | ||
| 76 | + ] | ||
| 77 | + return list.map((url) => { | ||
| 78 | + return new uri.URI(url).host | ||
| 79 | + }) | ||
| 80 | + } | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +export function registerDefaultWebJumpInterceptor() { | ||
| 84 | + RouterJumpInterceptor.register(WDRouterPage.defaultWebPage, new DefaultWebJumpHandler()) | ||
| 85 | + RouterJumpInterceptor.register(WDRouterPage.h5NewsWebPage, new DefaultWebJumpHandler()) | ||
| 86 | +} |
| @@ -27,6 +27,7 @@ import { initGlobalPlayerSettings } from 'wdPlayer/src/main/ets/utils/GlobalSett | @@ -27,6 +27,7 @@ import { initGlobalPlayerSettings } from 'wdPlayer/src/main/ets/utils/GlobalSett | ||
| 27 | import { BackgroundAudioController } from 'wdPlayer/Index' | 27 | import { BackgroundAudioController } from 'wdPlayer/Index' |
| 28 | import { SpConstants } from 'wdConstant' | 28 | import { SpConstants } from 'wdConstant' |
| 29 | import { WDShareBase } from 'wdShareBase/Index'; | 29 | import { WDShareBase } from 'wdShareBase/Index'; |
| 30 | +import { registerDefaultWebJumpInterceptor } from '../pages/web/WebPageJumpInterceptor' | ||
| 30 | 31 | ||
| 31 | const TAG = "[StartupManager]" | 32 | const TAG = "[StartupManager]" |
| 32 | 33 | ||
| @@ -59,6 +60,7 @@ export class StartupManager { | @@ -59,6 +60,7 @@ export class StartupManager { | ||
| 59 | KVStoreHelper.init(context) | 60 | KVStoreHelper.init(context) |
| 60 | // 路由注册 | 61 | // 路由注册 |
| 61 | registerRouter(); | 62 | registerRouter(); |
| 63 | + registerDefaultWebJumpInterceptor() | ||
| 62 | 64 | ||
| 63 | // 设置全局context | 65 | // 设置全局context |
| 64 | AppUtils.gotApplicationContextFunc = () => { | 66 | AppUtils.gotApplicationContextFunc = () => { |
-
Please register or login to post a comment