张善主

Merge remote-tracking branch 'origin/main'

Showing 21 changed files with 708 additions and 67 deletions
@@ -26,4 +26,12 @@ export class SpConstants{ @@ -26,4 +26,12 @@ export class SpConstants{
26 26
27 //未登录保存兴趣标签 27 //未登录保存兴趣标签
28 static PUBLICVISUTORMODE_INTERESTTAGS = 'PublicVisitorMode_InterestTags' 28 static PUBLICVISUTORMODE_INTERESTTAGS = 'PublicVisitorMode_InterestTags'
  29 +
  30 + //定位相关
  31 + static LOCATION_CITY_NAME = "location_city_name" //定位
  32 + static LOCATION_CITY_CODE = "location_city_code" //定位
  33 +
  34 + //启动页数据存储key
  35 + static APP_LAUNCH_PAGE_DATA_MODEL = 'app_launch_page_data_model'
  36 +
29 } 37 }
@@ -43,3 +43,9 @@ export { ErrorToastUtils } from './src/main/ets/utils/ErrorToastUtils' @@ -43,3 +43,9 @@ export { ErrorToastUtils } from './src/main/ets/utils/ErrorToastUtils'
43 export { EmitterUtils } from './src/main/ets/utils/EmitterUtils' 43 export { EmitterUtils } from './src/main/ets/utils/EmitterUtils'
44 44
45 export { EmitterEventId } from './src/main/ets/utils/EmitterEventId' 45 export { EmitterEventId } from './src/main/ets/utils/EmitterEventId'
  46 +
  47 +export { NetworkUtil } from './src/main/ets/utils/NetworkUtil'
  48 +
  49 +export { NetworkManager } from './src/main/ets/network/NetworkManager'
  50 +
  51 +export { NetworkType } from './src/main/ets/network/NetworkType'
  1 +import connection from '@ohos.net.connection';
  2 +import { BusinessError } from '@ohos.base';
  3 +import { Logger } from '../utils/Logger';
  4 +import { EmitterUtils } from '../utils/EmitterUtils';
  5 +import { EmitterEventId } from '../utils/EmitterEventId';
  6 +import { NetworkType } from './NetworkType';
  7 +
  8 +const TAG = 'NetworkManager'
  9 +
  10 +/**
  11 + * 网络管理类
  12 + */
  13 +export class NetworkManager {
  14 + private netCon: connection.NetConnection | null = null;
  15 + private static instance: NetworkManager;
  16 + private networkType: NetworkType = NetworkType.TYPE_UNKNOWN
  17 +
  18 + public static getInstance(): NetworkManager {
  19 + if (!NetworkManager.instance) {
  20 + NetworkManager.instance = new NetworkManager();
  21 + }
  22 + return NetworkManager.instance;
  23 + }
  24 +
  25 + public init() {
  26 + // 初始化
  27 + if (this.netCon) {
  28 + // 拦截重复初始化
  29 + return
  30 + }
  31 + this.networkMonitorRegister()
  32 + }
  33 +
  34 + public release() {
  35 + this.networkMonitorUnregister()
  36 + }
  37 +
  38 + private constructor() {
  39 + }
  40 +
  41 + private networkMonitorRegister() {
  42 + this.netCon = connection.createNetConnection();
  43 + this.netCon.register((error) => {
  44 + if (error) {
  45 + Logger.error(TAG, 'register error:' + error.message);
  46 + return;
  47 + }
  48 + Logger.info(TAG, 'register success');
  49 + })
  50 + this.netCon.on('netAvailable', (data: connection.NetHandle) => {
  51 + Logger.info(TAG, 'netAvailable, data is: ' + JSON.stringify(data))
  52 + })
  53 + this.netCon.on('netBlockStatusChange', (data: connection.NetBlockStatusInfo) => {
  54 + Logger.info(TAG, 'netBlockStatusChange, data is: ' + JSON.stringify(data))
  55 + // TODO 网络阻塞,是否创建新的网络、提示
  56 + })
  57 + this.netCon.on('netCapabilitiesChange', (data: connection.NetCapabilityInfo) => {
  58 + Logger.info(TAG, 'netCapabilitiesChange, data is: ' + JSON.stringify(data))
  59 + this.parseData(data)
  60 + // 可能多次通知
  61 + EmitterUtils.sendEvent(EmitterEventId.NETWORK_CONNECTED, JSON.stringify(this.networkType))
  62 + })
  63 + this.netCon.on('netConnectionPropertiesChange', (data: connection.NetConnectionPropertyInfo) => {
  64 + Logger.info(TAG, 'netConnectionPropertiesChange, data is: ' + JSON.stringify(data))
  65 + })
  66 +
  67 + this.netCon.on('netUnavailable', ((data: void) => {
  68 + Logger.info(TAG, 'netUnavailable, data is: ' + JSON.stringify(data))
  69 + }));
  70 + this.netCon.on('netLost', ((data: connection.NetHandle) => {
  71 + Logger.info(TAG, 'netLost, data is: ' + JSON.stringify(data))
  72 + // TODO 断网
  73 + EmitterUtils.sendEvent(EmitterEventId.NETWORK_DISCONNECTED)
  74 + this.networkType = NetworkType.TYPE_NONE
  75 + }))
  76 + }
  77 +
  78 + private networkMonitorUnregister() {
  79 + if (this.netCon) {
  80 + this.netCon.unregister((error: BusinessError) => {
  81 + if (error) {
  82 + Logger.error(TAG, 'unregister error:' + error.message);
  83 + return;
  84 + }
  85 + Logger.info(TAG, 'unregister success');
  86 + })
  87 + }
  88 + }
  89 +
  90 + /**
  91 + * @deprecated
  92 + */
  93 + private getNetworkMessage(netHandle: connection.NetHandle) {
  94 + connection.getNetCapabilities(netHandle, (error, netCap) => {
  95 + if (error) {
  96 + Logger.error(TAG, 'getNetCapabilities error:' + error.message);
  97 + return;
  98 + }
  99 + let netType = netCap.bearerTypes;
  100 + this.reset(netType)
  101 + })
  102 + }
  103 +
  104 + private reset(netType: Array<connection.NetBearType>) {
  105 + if (netType == null) {
  106 + return
  107 + }
  108 + for (let i = 0; i < netType.length; i++) {
  109 + if (netType[i] === 0) {
  110 + // 蜂窝网
  111 + this.networkType = NetworkType.TYPE_CELLULAR
  112 + } else if (netType[i] === 1) {
  113 + // Wi-Fi网络
  114 + this.networkType = NetworkType.TYPE_WIFI
  115 + } else {
  116 + // 以太网网络
  117 + this.networkType = NetworkType.TYPE_ETHERNET
  118 + }
  119 + }
  120 + }
  121 +
  122 + /**
  123 + * 获取网络类型,网络监听网络变化刷新类型,这里优先返回变量
  124 + */
  125 + public getNetType(): NetworkType {
  126 + if (this.networkType != NetworkType.TYPE_UNKNOWN) {
  127 + return this.networkType
  128 + }
  129 + return this.getNetTypeSync()
  130 + }
  131 +
  132 + /**
  133 + * 同步获取网络类型,耗时
  134 + */
  135 + public getNetTypeSync(): NetworkType {
  136 + let netHandle = connection.getDefaultNetSync();
  137 + let netCapabilities = connection.getNetCapabilitiesSync(netHandle)
  138 + this.reset(netCapabilities.bearerTypes)
  139 + return this.networkType;
  140 + }
  141 +
  142 + private parseData(data: connection.NetCapabilityInfo) {
  143 + // 解析网络信息
  144 + this.reset(data.netCap.bearerTypes)
  145 + }
  146 +}
  1 +/**
  2 + * 网络管理类
  3 + */
  4 +export enum NetworkType {
  5 + // 未知
  6 + TYPE_UNKNOWN = -1,
  7 + // 无网络
  8 + TYPE_NONE = 0,
  9 + // wifi
  10 + TYPE_WIFI = 1,
  11 + // 蜂窝网
  12 + TYPE_CELLULAR = 2,
  13 + // 以太网
  14 + TYPE_ETHERNET = 3,
  15 +}
@@ -3,6 +3,10 @@ @@ -3,6 +3,10 @@
3 */ 3 */
4 export enum EmitterEventId { 4 export enum EmitterEventId {
5 // 通知登出,事件id 5 // 通知登出,事件id
6 - FORCE_USER_LOGIN_OUT = 1 6 + FORCE_USER_LOGIN_OUT = 1,
  7 + // 网络连接成功,事件id
  8 + NETWORK_CONNECTED = 2,
  9 + // 网络断开,事件id
  10 + NETWORK_DISCONNECTED = 3,
7 } 11 }
8 12
  1 +import { NetworkManager } from '../network/NetworkManager'
  2 +import { NetworkType } from '../network/NetworkType'
  3 +
  4 +/**
  5 + * 网络相关工具类
  6 + * 要实时监听网络,需要添加注册函数{例:src/main/ets/entryability/EntryAbility.ets:32}
  7 + */
  8 +export class NetworkUtil {
  9 + /**
  10 + * 网络环境:0:无网 1:WiFi 2:2G 3:3G 4:4G 5:5G,暂时只识别出蜂窝网
  11 + * 扩展6-以太网
  12 + */
  13 + static TYPE_NONE = '0'
  14 + static TYPE_WIFI = '1'
  15 + static TYPE_CELLULAR = '5'
  16 + // TODO 以太网,手机不涉及
  17 + static TYPE_ETHERNET = '6'
  18 +
  19 + static getNetworkType(): string {
  20 + let type = NetworkManager.getInstance().getNetType()
  21 + return NetworkUtil.parseType(type)
  22 + }
  23 +
  24 + static parseType(type: NetworkType): string {
  25 + switch (type) {
  26 + case NetworkType.TYPE_UNKNOWN:
  27 + case NetworkType.TYPE_NONE:
  28 + return NetworkUtil.TYPE_NONE;
  29 + case NetworkType.TYPE_WIFI:
  30 + return NetworkUtil.TYPE_WIFI;
  31 + case NetworkType.TYPE_CELLULAR:
  32 + return NetworkUtil.TYPE_CELLULAR;
  33 + case NetworkType.TYPE_ETHERNET:
  34 + return NetworkUtil.TYPE_ETHERNET;
  35 + default:
  36 + return NetworkUtil.TYPE_NONE;
  37 + }
  38 + }
  39 +}
@@ -8,6 +8,11 @@ @@ -8,6 +8,11 @@
8 "tablet", 8 "tablet",
9 "2in1" 9 "2in1"
10 ], 10 ],
11 - "deliveryWithInstall": true 11 + "deliveryWithInstall": true,
  12 + "requestPermissions": [
  13 + {
  14 + "name": "ohos.permission.GET_NETWORK_INFO"
  15 + }
  16 + ]
12 } 17 }
13 } 18 }
@@ -324,8 +324,9 @@ export class HttpUrlUtils { @@ -324,8 +324,9 @@ export class HttpUrlUtils {
324 headers.set('EagleEye-TraceID', 'D539562E48554A60977AF4BECB6D6C7A') 324 headers.set('EagleEye-TraceID', 'D539562E48554A60977AF4BECB6D6C7A')
325 headers.set('imei', HttpUrlUtils.getImei()) 325 headers.set('imei', HttpUrlUtils.getImei())
326 headers.set('Accept-Language', 'zh') 326 headers.set('Accept-Language', 'zh')
327 - headers.set('city', HttpUrlUtils.getCity())  
328 - headers.set('city_dode', HttpUrlUtils.getCityCode()) 327 + // headers.set('city', HttpUrlUtils.getCity())
  328 + // headers.set('city_dode', HttpUrlUtils.getCityCode())
  329 + HttpUrlUtils.setLocationHeader(headers)
329 // TODO 判断是否登录 330 // TODO 判断是否登录
330 headers.set('userId', HttpUrlUtils.getUserId()) 331 headers.set('userId', HttpUrlUtils.getUserId())
331 headers.set('userType', HttpUrlUtils.getUserType()) 332 headers.set('userType', HttpUrlUtils.getUserType())
@@ -368,6 +369,17 @@ export class HttpUrlUtils { @@ -368,6 +369,17 @@ export class HttpUrlUtils {
368 } 369 }
369 } 370 }
370 371
  372 + static setLocationHeader(headers: HashMap<string, string>) {
  373 + let cityName = SPHelper.default.getSync(SpConstants.LOCATION_CITY_NAME, '') as string
  374 + if (StringUtils.isNotEmpty(cityName)) {
  375 + headers.set('city', encodeURI(cityName))
  376 + }
  377 + let cityCode = SPHelper.default.getSync(SpConstants.LOCATION_CITY_CODE, '') as string
  378 + if (StringUtils.isNotEmpty(cityCode)) {
  379 + headers.set('city_dode', encodeURI(cityCode))
  380 + }
  381 + }
  382 +
371 static getHost() { 383 static getHost() {
372 return HttpUrlUtils._hostUrl; 384 return HttpUrlUtils._hostUrl;
373 } 385 }
  1 +
  2 +/**
  3 + * @Description: 信息集合
  4 + * @Author:
  5 + * @Email: liyubing@wondertek.com.cn
  6 + * @CreateDate:
  7 + * @UpdateRemark: 更新说明
  8 + * @Version: 1.0
  9 + */
  10 +export interface AdvertsBean{
  11 +
  12 + /**
  13 + * 广告id
  14 + */
  15 + id:string
  16 +
  17 + /**
  18 + * 广告relId
  19 + */
  20 + relId:string
  21 +
  22 + /**
  23 + * 广告素材名称
  24 + */
  25 + matTitle:string
  26 +
  27 + /**
  28 + * 投放开始时间yyyy-MM-dd HH:mm:ss
  29 + */
  30 + startTime:string
  31 +
  32 + /**
  33 + * 投放结束时间yyyy-MM-dd HH:mm:ss
  34 + */
  35 + endTime:string
  36 +
  37 + /**
  38 + * 展现时段,多组数据:9:00:00-10:00:00|17:00:00-18:00:00
  39 + */
  40 + displayTime:string
  41 +
  42 + /**
  43 + * 展现优先级,数值越小,等级越高
  44 + */
  45 + displayLevel:string
  46 +
  47 + /**
  48 + * 链接跳转类型,0:无连接;1:内链(站内内容);2:外链
  49 + */
  50 + linkType:number;
  51 +
  52 + /**
  53 + * 外链广告外链地址,link_type=2生效
  54 + */
  55 + linkUrl:string
  56 +
  57 + /**
  58 + * 内链内容id 仅link_type=1生效
  59 + */
  60 + contentId:string
  61 +
  62 + /**
  63 + * 对象类型 0:不跳转 1:视频,2:直播,5:专题,6:链接,8:图文,9:组图,10:H5新闻,11:频道
  64 + */
  65 + objectType:string
  66 + /**
  67 + * 内容标题
  68 + */
  69 + contentTitle:string
  70 +
  71 + /**
  72 + * 专题页面id
  73 + */
  74 + topicPageId:string
  75 +
  76 + /**
  77 + * 挂角封面图
  78 + */
  79 + displayUrl:string
  80 +
  81 + /**
  82 + * 页面id
  83 + */
  84 + pageId:string
  85 +
  86 + /**
  87 + * 跳转id
  88 + */
  89 + objectId:string
  90 +
  91 + /**
  92 + * 对象分类 ;频道(1:一级频道,2:二级频道),专题(1:普通专题,2:主题专题,3:作者专题)
  93 + */
  94 + objectLevel:string
  95 +
  96 + /**
  97 + * 底部导航栏 id(用于频道跳转)
  98 + */
  99 + bottomNavId:string
  100 +
  101 +}
  1 +/**
  2 + * @Description: 挂角广告数据
  3 + * @Author:
  4 + * @Email: liyubing@wondertek.com.cn
  5 + * @CreateDate:
  6 + * @UpdateRemark: 更新说明
  7 + * @Version: 1.0
  8 + */
  9 +import { AdvertsBean } from './AdvertsBean';
  10 +import { CompAdvMatInfoBean, CompAdvSlotInfoBean } from './CompAdvInfoBean';
  11 +
  12 +export interface AdvRuleBean {
  13 +
  14 + /**
  15 + * 广告投放位编码
  16 + */
  17 + pos: string;
  18 +
  19 + /**
  20 + * 广告展示顺序,0:随机展示;1列表循环
  21 + */
  22 + displayMode:number
  23 +
  24 + /**
  25 + * 每间隔刷新n次展示广告
  26 + */
  27 + refreshFrequency:number
  28 +
  29 + /**
  30 + * 广告信息集合
  31 + */
  32 + advert:AdvertsBean;
  33 +
  34 +}
  35 +
  36 +/**
  37 + * 广告组件数据
  38 + */
  39 +export interface CompAdvBean{
  40 +
  41 + /**
  42 + * 广告订单id
  43 + */
  44 + id:string;
  45 +
  46 + /**
  47 + * 投放开始时间
  48 + */
  49 + startTime:number;
  50 +
  51 + /**
  52 + * 投放结束时间
  53 + */
  54 + endTime:number;
  55 +
  56 + /**
  57 + * 信息流广告素材
  58 + */
  59 + matInfo:CompAdvMatInfoBean
  60 +
  61 + /**
  62 + * 信息流广告位
  63 + */
  64 + slotInfo:CompAdvSlotInfoBean
  65 +
  66 +
  67 +}
  1 +/**
  2 + * @Description: 组件广告信息
  3 + * @Author:
  4 + * @Email: liyubing@wondertek.com.cn
  5 + * @CreateDate:
  6 + * @UpdateRemark: 更新说明
  7 + * @Version: 1.0
  8 + */
  9 +
  10 +/*
  11 + 信息流广告素材解析累
  12 + */
  13 +export interface CompAdvMatInfoBean {
  14 +
  15 + /**
  16 + * 广告标题
  17 + */
  18 + advTitle: string
  19 + /**
  20 + * 3:信息流广告
  21 + */
  22 + advType: string
  23 + /**
  24 + * 信息流广告类型(4:轮播图 5:三图广告 6:小图广告 7:长通栏广告 8:大图广告 9:视频广告 10:展会广告 11:冠名广告 12:顶部长通栏广告)
  25 + */
  26 + advSubType: string
  27 + /**
  28 + * 素材图片信息;adv_subtype=4,5,6,7,8,9,12 时使用
  29 + */
  30 + matImageUrl: string[]
  31 + /**
  32 + * 视频广告地址(adv_subtype=9)
  33 + */
  34 + matVideoUrl: string
  35 + /**
  36 + * 扩展信息:advSubType=10,11时使用,字段示例见接口备注。
  37 + */
  38 + extraData: string
  39 + /**
  40 + * 链接类型: 0:无链接;1:内链(文章);2:外链
  41 + */
  42 + linkType: string
  43 + /**
  44 + * 链接跳转类型 :0-没链接,不用打开,1-端内打开,2-端外打开
  45 + */
  46 + openType: string
  47 + /**
  48 + * 广告跳转链接
  49 + */
  50 + linkUrl: string
  51 + /**
  52 + * 素材类型(0:图片 1:视频)
  53 + */
  54 + matType: string
  55 + /**
  56 + * 开屏样式(1:全屏样式 0:底部固定Logo)
  57 + */
  58 + startStyle: string
  59 +}
  60 +
  61 +/**
  62 + * 信息流广告位
  63 + */
  64 +export interface CompAdvSlotInfoBean {
  65 +
  66 +
  67 + /**
  68 + * 组件id
  69 + */
  70 + compId: string;
  71 +
  72 + /**
  73 + * 广告位位置 从1开始
  74 + */
  75 + position: number;
  76 +
  77 + /**
  78 + * 频道id
  79 + */
  80 + channelId: string;
  81 +
  82 +}
1 /** 1 /**
2 * page接口返回的Page数据DTO 2 * page接口返回的Page数据DTO
3 */ 3 */
  4 +import { AdvRuleBean, CompAdvBean } from '../adv/AdvsRuleBean';
  5 +
4 export interface PageInfoDTO { 6 export interface PageInfoDTO {
5 pageId: string; // 页面id 7 pageId: string; // 页面id
6 id: number; // 楼层id 8 id: number; // 楼层id
7 name: string; // 名称 9 name: string; // 名称
8 - hasAdInfo: number;  
9 hasPopUp: number; 10 hasPopUp: number;
10 baselineShow: number; 11 baselineShow: number;
11 groups: GroupInfoDTO[]; 12 groups: GroupInfoDTO[];
12 channelInfo: ChannelInfoDTO; 13 channelInfo: ChannelInfoDTO;
  14 +
  15 + /**
  16 + * 1-有过广告配置,0-没有广告配置
  17 + */
  18 + hasAdInfo: number;
  19 +
  20 + /**
  21 + * 挂角广告数据
  22 + */
  23 + cornersAdv:AdvRuleBean
  24 + /**
  25 + * 广告中心-挂角广告信息
  26 + */
  27 + cornersAdv2:CompAdvBean[]
  28 +
13 } 29 }
14 30
15 export interface ChannelInfoDTO { 31 export interface ChannelInfoDTO {
@@ -20,7 +20,8 @@ import { ZhCarouselLayout01 } from './compview/ZhCarouselLayout01'; @@ -20,7 +20,8 @@ import { ZhCarouselLayout01 } from './compview/ZhCarouselLayout01';
20 import { CardParser } from './CardParser'; 20 import { CardParser } from './CardParser';
21 import { LiveHorizontalReservationComponent } from './view/LiveHorizontalReservationComponent'; 21 import { LiveHorizontalReservationComponent } from './view/LiveHorizontalReservationComponent';
22 import { ZhGridLayout02 } from './compview/ZhGridLayout02'; 22 import { ZhGridLayout02 } from './compview/ZhGridLayout02';
23 -import { Card5Component } from './cardview/Card5Component' 23 +import { Card5Component } from './cardview/Card5Component';
  24 +import { Card2Component } from './cardview/Card2Component';
24 import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; 25 import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
25 26
26 /** 27 /**
@@ -71,6 +72,9 @@ export struct CompParser { @@ -71,6 +72,9 @@ export struct CompParser {
71 } else if (compDTO.compStyle === CompStyle.Zh_Single_Column_02) { 72 } else if (compDTO.compStyle === CompStyle.Zh_Single_Column_02) {
72 //头图卡 和comStyle 2相同, 73 //头图卡 和comStyle 2相同,
73 Card5Component({ contentDTO: compDTO.operDataList[0] }) 74 Card5Component({ contentDTO: compDTO.operDataList[0] })
  75 + } else if (compDTO.compStyle === CompStyle.Zh_Single_Column_03) {
  76 + // 大图卡
  77 + Card2Component({ contentDTO: compDTO.operDataList[0] })
74 } else if (compDTO.compStyle === CompStyle.Zh_Single_Column_04) { 78 } else if (compDTO.compStyle === CompStyle.Zh_Single_Column_04) {
75 ZhSingleColumn04({ compDTO: compDTO }) 79 ZhSingleColumn04({ compDTO: compDTO })
76 } else if (compDTO.compStyle === CompStyle.Zh_Single_Column_05) { 80 } else if (compDTO.compStyle === CompStyle.Zh_Single_Column_05) {
1 import { abilityAccessCtrl, bundleManager, Permissions } from '@kit.AbilityKit'; 1 import { abilityAccessCtrl, bundleManager, Permissions } from '@kit.AbilityKit';
2 import { BusinessError } from '@kit.BasicServicesKit'; 2 import { BusinessError } from '@kit.BasicServicesKit';
3 import { geoLocationManager } from '@kit.LocationKit'; 3 import { geoLocationManager } from '@kit.LocationKit';
  4 +import { SpConstants } from 'wdConstant/Index';
4 import { Logger, PermissionUtils, ResourcesUtils, SPHelper } from 'wdKit/Index'; 5 import { Logger, PermissionUtils, ResourcesUtils, SPHelper } from 'wdKit/Index';
  6 +import { ResponseDTO } from 'wdNetwork/Index';
5 7
6 /** 8 /**
7 * 系统定位服务实现 9 * 系统定位服务实现
8 * */ 10 * */
9 export class HWLocationUtils { 11 export class HWLocationUtils {
10 - //d定位相关  
11 - static LOCATION_CITY_NAME = "location_city_name" //定位  
12 - static LOCATION_CITY_CODE = "location_city_code" //定位  
13 12
14 13
15 static LOCATION: Permissions = 'ohos.permission.LOCATION' 14 static LOCATION: Permissions = 'ohos.permission.LOCATION'
@@ -107,10 +106,14 @@ export class HWLocationUtils { @@ -107,10 +106,14 @@ export class HWLocationUtils {
107 Logger.debug('location :' + JSON.stringify(data)) 106 Logger.debug('location :' + JSON.stringify(data))
108 if (data[0] && data[0].administrativeArea && data[0].subAdministrativeArea) { 107 if (data[0] && data[0].administrativeArea && data[0].subAdministrativeArea) {
109 let cityName = data[0].subAdministrativeArea; 108 let cityName = data[0].subAdministrativeArea;
  109 + let name = await SPHelper.default.get(SpConstants.LOCATION_CITY_NAME, '') as string
  110 + if (cityName == name) {
  111 + return
  112 + }
110 let code = await HWLocationUtils.getCityCode(data[0].administrativeArea, data[0].subAdministrativeArea) 113 let code = await HWLocationUtils.getCityCode(data[0].administrativeArea, data[0].subAdministrativeArea)
111 if (code) { 114 if (code) {
112 - SPHelper.default.save(HWLocationUtils.LOCATION_CITY_NAME, cityName)  
113 - SPHelper.default.save(HWLocationUtils.LOCATION_CITY_CODE, code) 115 + SPHelper.default.save(SpConstants.LOCATION_CITY_NAME, cityName)
  116 + SPHelper.default.save(SpConstants.LOCATION_CITY_CODE, code)
114 } 117 }
115 } 118 }
116 } 119 }
@@ -151,23 +154,6 @@ export class HWLocationUtils { @@ -151,23 +154,6 @@ export class HWLocationUtils {
151 } 154 }
152 } 155 }
153 156
154 -interface ResponseDTO<T> {  
155 - success: boolean;  
156 -  
157 - // 服务请求响应值/微服务响应状态码”  
158 - code: number;  
159 -  
160 - // 服务请求响应说明  
161 - message: string;  
162 -  
163 - // 响应结果  
164 - data?: T;  
165 - totalCount?: number;  
166 -  
167 - // 请求响应时间戳(unix格式)  
168 - timestamp?: number;  
169 -}  
170 -  
171 interface LocalData { 157 interface LocalData {
172 "code": string, 158 "code": string,
173 "id": string, 159 "id": string,
@@ -9,6 +9,18 @@ @@ -9,6 +9,18 @@
9 "2in1" 9 "2in1"
10 ], 10 ],
11 "deliveryWithInstall": true, 11 "deliveryWithInstall": true,
12 - "pages": "$profile:main_pages" 12 + "pages": "$profile:main_pages",
  13 + "requestPermissions": [
  14 + {
  15 + "name": "ohos.permission.APPROXIMATELY_LOCATION",
  16 + "reason": "$string:location_reason",
  17 + "usedScene": {
  18 + "abilities": [
  19 + "FormAbility"
  20 + ],
  21 + "when": "inuse"
  22 + }
  23 + }
  24 + ]
13 } 25 }
14 } 26 }
@@ -3,6 +3,10 @@ @@ -3,6 +3,10 @@
3 { 3 {
4 "name": "shared_desc", 4 "name": "shared_desc",
5 "value": "description" 5 "value": "description"
  6 + },
  7 + {
  8 + "name": "location_reason",
  9 + "value": " "
6 } 10 }
7 ] 11 ]
8 } 12 }
@@ -4,7 +4,16 @@ import UIAbility from '@ohos.app.ability.UIAbility'; @@ -4,7 +4,16 @@ import UIAbility from '@ohos.app.ability.UIAbility';
4 import Want from '@ohos.app.ability.Want'; 4 import Want from '@ohos.app.ability.Want';
5 import window from '@ohos.window'; 5 import window from '@ohos.window';
6 import { registerRouter } from 'wdRouter'; 6 import { registerRouter } from 'wdRouter';
7 -import { SPHelper, StringUtils, WindowModel } from 'wdKit'; 7 +import {
  8 + EmitterEventId,
  9 + EmitterUtils,
  10 + Logger,
  11 + NetworkManager,
  12 + NetworkType,
  13 + SPHelper,
  14 + StringUtils,
  15 + WindowModel
  16 +} from 'wdKit';
8 import { HttpUrlUtils, WDHttp } from 'wdNetwork'; 17 import { HttpUrlUtils, WDHttp } from 'wdNetwork';
9 18
10 export default class EntryAbility extends UIAbility { 19 export default class EntryAbility extends UIAbility {
@@ -12,15 +21,30 @@ export default class EntryAbility extends UIAbility { @@ -12,15 +21,30 @@ export default class EntryAbility extends UIAbility {
12 SPHelper.init(this.context); 21 SPHelper.init(this.context);
13 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); 22 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
14 registerRouter(); 23 registerRouter();
  24 + NetworkManager.getInstance().init()
15 WDHttp.initHttpHeader() 25 WDHttp.initHttpHeader()
16 const spHostUrl = SPHelper.default.getSync('hostUrl', '') as string 26 const spHostUrl = SPHelper.default.getSync('hostUrl', '') as string
17 if (StringUtils.isNotEmpty(spHostUrl)) { 27 if (StringUtils.isNotEmpty(spHostUrl)) {
18 HttpUrlUtils.hostUrl = spHostUrl 28 HttpUrlUtils.hostUrl = spHostUrl
19 } 29 }
  30 +
  31 + // 注册监听网络连接
  32 + EmitterUtils.receiveEvent(EmitterEventId.NETWORK_CONNECTED, ((str?: string) => {
  33 + let type: NetworkType | null = null
  34 + if (str) {
  35 + type = JSON.parse(str) as NetworkType
  36 + }
  37 + Logger.info('network connected: ' + type?.toString())
  38 + }))
  39 + // 注册监听网络断开
  40 + EmitterUtils.receiveEvent(EmitterEventId.NETWORK_DISCONNECTED, (() => {
  41 + Logger.info('network disconnected')
  42 + }))
20 } 43 }
21 44
22 onDestroy(): void { 45 onDestroy(): void {
23 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); 46 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
  47 + NetworkManager.getInstance().release()
24 } 48 }
25 49
26 onWindowStageCreate(windowStage: window.WindowStage): void { 50 onWindowStageCreate(windowStage: window.WindowStage): void {
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())