NewIndex.ets 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. import { AppUtil, DeviceUtil,DisplayUtil, PreferencesUtil, ToastUtil } from '@pura/harmony-utils';
  2. import TitleBar from '../view/TitleBar';
  3. import { router } from '@kit.ArkUI';
  4. import mainViewModel, { MainViewModel } from '../viewmodel/MainViewModel';
  5. import ItemData from '../viewmodel/ItemData';
  6. import type { sysResource } from '../viewmodel/ItemData';
  7. import { CommonConstants } from '../common/constants/CommonConstants';
  8. import { VideoItem } from '../viewmodel/VideoItem';
  9. import ScreenUtil from '../common/util/ScreenUtil';
  10. import { Utility } from '../common/util/Utility';
  11. import { BusinessError, emitter } from '@kit.BasicServicesKit';
  12. import { common } from '@kit.AbilityKit';
  13. // import { AdSlot, AdSlotBuilder,
  14. // CSJAdCreator,
  15. // CSJAdSdk, CSJNativeExpressAd, NativeExpressAdListener } from '@csj/openadsdk';
  16. import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils';
  17. import { ArrayList } from '@kit.ArkTS';
  18. import { CSJUtil } from '../common/util/CSJUtil';
  19. import { LocalMusic } from '../view/LocalMusic';
  20. import { StreamContent } from '../view/StreamContent';
  21. import { AvSessionController } from '../controller/AvSessionController';
  22. import { BreakpointSystem, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
  23. import dataStorage from '@ohos.data.storage';
  24. import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
  25. import { SettingPage } from './SettingPage';
  26. import { deviceInfo } from '@kit.BasicServicesKit';
  27. import { resourceManager } from '@kit.LocalizationKit';
  28. import { systemShare } from '@kit.ShareKit';
  29. import { uniformTypeDescriptor } from '@kit.ArkData';
  30. import { hilog } from '@kit.PerformanceAnalysisKit';
  31. const TAG = 'NewIndex'; // 日志标签
  32. /**
  33. * 首页主组件,包含顶部标题栏、主内容区(本地音乐/网络内容)、侧边抽屉菜单等。
  34. * 支持多端适配、广告集成、导航、生命周期管理等功能。
  35. */
  36. @Preview
  37. @Entry
  38. @Component
  39. struct NewIndex{
  40. /** 列表滚动器,用于抽屉菜单列表滚动 */
  41. private scroller: Scroller = new Scroller();
  42. /** 应用包名 */
  43. @State bundleName:string = ''
  44. @State appName:string = ''
  45. /** 是否显示侧边抽屉菜单 */
  46. @Provide isShowDrawer:boolean = false;
  47. /** 抽屉菜单 X 轴偏移量,用于手势滑动动画 */
  48. @Provide offsetX: number = 0;
  49. /** 本地视频列表,页面参数传入 */
  50. @Provide videoLocalList: Array<VideoItem> = []
  51. /** Y 轴偏移量(预留) */
  52. @State offsetY: number = 0;
  53. /** 主内容类型(0:本地音乐,1:网络内容) */
  54. @State mType:number = 0
  55. /** 模式类型(如歌手、专辑等) */
  56. @Provide modeType:number = 0
  57. /** 是否为零状态(预留) */
  58. @Provide('isZero') isZero:boolean = false;
  59. /** 是否显示赞助入口 */
  60. @State isShowSponsorship:boolean = false
  61. /** 页面上下文 */
  62. context = getContext(this);
  63. /** 音乐是否为零状态(预留) */
  64. @Provide('isMusicZero') isMusicZero:boolean = false;
  65. /** 本地音乐列表,持久化存储 */
  66. @StorageLink('musicLocalList') musicLocalList: Array<VideoItem> = []
  67. @Provide isFavMusic:boolean = false
  68. /** 标题栏配置模型 */
  69. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  70. .setTitleTextStyle(FontStyle.Normal)
  71. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  72. .setLeftIcon($r('app.media.menu'))
  73. .setLeftIconWidth(28)
  74. .setLeftIconHeight(28)
  75. .setTitleBarMinHeight(64)
  76. .setTitleName('首页')
  77. // .setRightIcon($r('app.media.add'))
  78. .setTitleFontSize(19)
  79. .setTitleFontColor(Color.White)
  80. .setTitleBarBackground($r('app.color.title_bar_bg'))
  81. .setLeftTitleBackground($r('app.color.title_bar_bg'))
  82. .setOnLeftClickListener(() => {
  83. // 打开菜单栏动画
  84. animateTo({ duration: 555 }, () => {
  85. this.isShowDrawer = true
  86. this.offsetX = 0
  87. })
  88. })
  89. .setRightTitleBackground($r('app.color.title_bar_bg'))
  90. // .setOnRightClickListener(()=>{
  91. // // this.goSelectVideo()
  92. // this.showSheelDialog()
  93. // })
  94. /** 应用版本号 */
  95. @State versionName:string =''
  96. /** 音频根目录路径 */
  97. @Provide rootPath:string = ''
  98. /** 当前路径 */
  99. @Provide currentPath:string = ''
  100. /** 是否为历史记录页面 */
  101. @Provide isHistory:boolean = false
  102. /** 是否可以返回上一级 */
  103. @Provide isCanBack:boolean= false
  104. @StorageProp('currentColorMode') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  105. @StorageProp('themeColor') themeColor: string = '#FF4081';
  106. /**
  107. * 一多界面适配断点系统
  108. */
  109. private breakpointSystem: BreakpointSystem = new BreakpointSystem();
  110. /** 当前断点类型(如大屏/小屏) */
  111. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  112. /** 记录上一次点击返回键的时间戳,用于双击退出 */
  113. private backTime:number=0;
  114. /**
  115. * 返回键处理逻辑:
  116. * - 如果不是根目录或有历史记录,发送广播通知更新列表
  117. * - 如果是根目录,双击返回键退出应用,否则提示
  118. */
  119. onBackPress(): boolean | void {
  120. if(this.currentPath !== this.rootPath||this.isHistory||this.isFavMusic||(this.modeType!==0&&this.isCanBack)){
  121. const eventData: emitter.EventData = {};
  122. emitter.emit({ eventId: 888 }, eventData); // 发送音频广播通知更新doSwipBack
  123. }else{
  124. let nowtime = Date.now();
  125. if(nowtime - this.backTime < 1000){
  126. const mContext = getContext(this) as common.UIAbilityContext
  127. mContext.terminateSelf(); // 关闭应用
  128. AvSessionController.getInstance(true).unregisterSessionListener()
  129. }else {
  130. if(this.isShowDrawer){
  131. // 如果抽屉菜单打开,先关闭抽屉
  132. animateTo({ duration: 555 }, () => {
  133. this.isShowDrawer = false
  134. })
  135. }else{
  136. this.backTime=nowtime;
  137. ToastUtil.showToast("再按一次将退出当前应用")
  138. }
  139. }
  140. }
  141. return true;
  142. }
  143. /**
  144. * 页面显示生命周期钩子
  145. * - 注册断点系统
  146. * - 获取页面参数
  147. * - 设置状态栏样式
  148. * - 初始化图片缓存
  149. * - 判断是否显示赞助入口
  150. */
  151. async aboutToAppear() {
  152. Utility.enableFullScreen()
  153. Utility.getAppName(getContext(this)).then((appName:string)=>{
  154. this.appName = appName
  155. })
  156. this.breakpointSystem.register();
  157. let params = router.getParams() as Record<string, Object>;
  158. this.videoLocalList = params.videoList as VideoItem[];
  159. Utility.setStatusBarLight()
  160. ScreenUtil.setScreenSize();
  161. this.bundleName = AppUtil.getBundleName()
  162. this.versionName = AppUtil.getVersionName();
  163. // await ImageKnife.getInstance().initFileCache(this.context, 256, 256 * 1024 * 1024)
  164. this.isShowSponsorship = Utility.isOpenTime()
  165. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
  166. hilog.info(0x0000, 'Heanup', '当前 NewIndex themeColor:'+themeColor);
  167. AppStorage.setOrCreate('themeColor', themeColor);
  168. this.themeColor=themeColor
  169. }
  170. /**
  171. * 页面消失生命周期钩子
  172. * 注销断点系统
  173. */
  174. aboutToDisappear() {
  175. console.info('NewIndex aboutToDisappear');
  176. this.breakpointSystem.unregister();
  177. emitter.off(888);
  178. }
  179. /**
  180. * 构建主页面结构,包括顶部横线、主内容区和抽屉菜单
  181. */
  182. build() {
  183. Stack({ alignContent: Alignment.TopStart }) {
  184. // 顶部横线
  185. Column(){
  186. Line()
  187. .width('100%')
  188. .height(1)
  189. }
  190. .backgroundColor($r('app.color.title_bar_bg'))
  191. .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
  192. // 主内容区
  193. Column() {
  194. Stack(){
  195. // 本地音乐内容区
  196. LocalMusic()
  197. .visibility(this.mType===0?Visibility.Visible:Visibility.None)
  198. // 网络内容区
  199. StreamContent()
  200. .visibility(this.mType===1?Visibility.Visible:Visibility.None)
  201. }
  202. }
  203. .width('100%')
  204. .height('100%')
  205. .justifyContent(FlexAlign.Start)
  206. .backgroundColor($r('app.color.bottom_control_background'))
  207. // 侧边抽屉菜单
  208. if(this.isShowDrawer){
  209. Column() {
  210. Column() {
  211. // 抽屉顶部背景图
  212. Image($r('app.media.bg_music'))
  213. .width('100%')
  214. .visibility(this.isCoverOpacity()?Visibility.None:Visibility.Visible)
  215. .height(180)
  216. Blank()
  217. .backgroundColor(this.themeColor)
  218. .visibility(this.isCoverOpacity()?Visibility.Visible:Visibility.None)
  219. .width('100%')
  220. .height(55)
  221. // 动态生成抽屉菜单内容
  222. this.getDrawerView()
  223. }
  224. .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'40%':'75%')
  225. .height('100%')
  226. .backgroundColor($r('app.color.silvery'))
  227. .onClick((event:ClickEvent)=>{
  228. // 阻止事件冒泡
  229. })
  230. }
  231. .width('100%')
  232. .height('100%')
  233. .backgroundColor($r('app.color.ban_touming'))
  234. .alignItems(HorizontalAlign.Start)
  235. .onClick((event:ClickEvent)=>{
  236. // 点击抽屉外部关闭抽屉
  237. animateTo({ duration: 555 }, () => {
  238. this.isShowDrawer = false
  239. })
  240. })
  241. .translate({ x: this.offsetX, y: 0, z: 0 })
  242. .transition({ type: TransitionType.Insert, translate: { x: -DisplayUtil.getWidth(), y: 0 } })
  243. .transition({ type: TransitionType.Delete, translate: { x: -DisplayUtil.getWidth(), y: 0 } })
  244. .gesture(
  245. PanGesture()
  246. .onActionUpdate((event:GestureEvent)=>{
  247. // 手势滑动更新抽屉偏移
  248. if(event.offsetX<0){
  249. this.offsetX = event.offsetX;
  250. }
  251. })
  252. .onActionEnd(() => {
  253. // 手势结束判断是否关闭抽屉
  254. if(this.offsetX<-DisplayUtil.getWidth()/9){
  255. animateTo({ duration: 555 }, () => {
  256. this.isShowDrawer = false
  257. })
  258. }else{
  259. animateTo({ duration: 555 }, () => {
  260. this.isShowDrawer = true
  261. this.offsetX = 0
  262. })
  263. }
  264. })
  265. )
  266. }
  267. }
  268. }
  269. /**
  270. * 动态生成抽屉菜单内容
  271. * 根据 isShowSponsorship 展示不同菜单项
  272. */
  273. @Builder
  274. getDrawerView(){
  275. List({space: 0, scroller: this.scroller}){
  276. ForEach(this.isShowSponsorship?mainViewModel.getDrawerData2():mainViewModel.getDrawerData(),(item: ItemData,index:number)=>{
  277. ListItem(){
  278. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  279. Row() {
  280. // 菜单图标
  281. if (typeof item.img === 'object' && item.img !== null && (item.img as sysResource).type === 'symbol') {
  282. SymbolGlyph((item.img as sysResource).value as Resource)
  283. // .size({ width: 22, height: 22 })
  284. .fontSize(22)
  285. .fontColor([this.themeColor])
  286. .alignSelf(ItemAlign.Center)
  287. .margin({ left: 2 })
  288. }else {
  289. Image(item.img as Resource)
  290. .height(22)
  291. .alignSelf(ItemAlign.Center)
  292. .fillColor($r('app.color.img_color'))
  293. .margin({ left: 2 })
  294. }
  295. // 菜单标题
  296. Text(item.title)
  297. .margin({ left: 10, right: 20 })
  298. .fontSize(15)
  299. .fontColor($r('app.color.index_tab_font_color'))
  300. .fontWeight(480)
  301. Blank()
  302. // 右侧箭头
  303. Image($r('app.media.arrow_right'))
  304. .width(22)
  305. .height(22)
  306. .margin({ left: 20, right: 0 })
  307. .align(Alignment.Center)
  308. }
  309. .width('100%')
  310. .height(55)
  311. }
  312. .backgroundColor(Color.Transparent)
  313. .onClick(async () => {
  314. // 根据 item.id 跳转或切换功能
  315. switch (item.id) {
  316. case MainViewModel.MENU_MUSIC:
  317. this.mType = 0
  318. animateTo({ duration: 555 }, () => {
  319. this.isShowDrawer = false
  320. })
  321. break
  322. case MainViewModel.MENU_FILE_SCAN:
  323. router.pushUrl({
  324. url: 'pages/ScanFilePage'
  325. });
  326. break
  327. case MainViewModel.MENU_HOME:
  328. this.mType = 0
  329. this.modeType = 0
  330. animateTo({ duration: 555 }, () => {
  331. this.isShowDrawer = false
  332. })
  333. break
  334. case MainViewModel.MENU_MIEDIA_KU:
  335. this.modeType = 1
  336. animateTo({ duration: 555 }, () => {
  337. this.isShowDrawer = false
  338. })
  339. break
  340. case MainViewModel.MENU_MIEDIA_ARTIST:
  341. this.modeType = 2
  342. animateTo({ duration: 555 }, () => {
  343. this.isShowDrawer = false
  344. })
  345. break
  346. case MainViewModel.MENU_MIEDIA_ALBUM:
  347. this.modeType = 3
  348. animateTo({ duration: 555 }, () => {
  349. this.isShowDrawer = false
  350. })
  351. break
  352. case MainViewModel.MENU_SETTING:
  353. router.pushUrl({
  354. url: 'pages/SettingPage'
  355. }, router.RouterMode.Single);
  356. break
  357. case MainViewModel.MENU_VIP:
  358. router.pushUrl({
  359. url: 'pages/VipPage'
  360. }, router.RouterMode.Single);
  361. break
  362. case MainViewModel.MENU_USER:
  363. router.pushUrl({
  364. url: 'pages/UserCenter'
  365. }, router.RouterMode.Single);
  366. break
  367. case MainViewModel.MENU_NET_CONNECT:
  368. this.mType = 1
  369. animateTo({ duration: 555 }, () => {
  370. this.isShowDrawer = false
  371. })
  372. break
  373. case MainViewModel.MENU_SIMI:
  374. router.pushUrl({
  375. url: 'pages/VerifyPage'
  376. });
  377. break
  378. case MainViewModel.MENU_LIKE:
  379. router.pushUrl({
  380. url: 'pages/LikeVideoPage'
  381. });
  382. break
  383. case MainViewModel.MENU_DUTY:
  384. router.pushUrl({
  385. url: 'pages/WebIndex',
  386. params: { titleName: '用户协议', webUrl: CommonConstants.NEW_DUTY }
  387. });
  388. break
  389. case MainViewModel.MENU_HAOPING:
  390. Utility.gotoMarket(getContext(this) as common.UIAbilityContext,this.bundleName)
  391. break
  392. case MainViewModel.MENU_TEST_SPEED:
  393. router.pushUrl({
  394. url: 'pages/SpeedIndex'
  395. });
  396. break
  397. case MainViewModel.MENU_OPTIMIZE:
  398. router.pushUrl({
  399. url: 'pages/AddSpeedPage'
  400. });
  401. break
  402. case MainViewModel.MENU_ABOUT:
  403. router.pushUrl({
  404. url: 'pages/AboutPage'
  405. }, router.RouterMode.Single);
  406. break
  407. case MainViewModel.MENU_UPDATE:
  408. AlertDialog.show({title:'版本更新',message:'当前版本为最新版本:'+this.versionName,
  409. autoCancel:true, alignment:DialogAlignment.Center,
  410. offset:{dx:0,dy:-20},//在Y轴方向上的编译量
  411. confirm:{
  412. value:'确定',fontColor:Color.White,backgroundColor:$r('app.color.title_bar_bg'),
  413. action:()=>{
  414. }
  415. }
  416. })
  417. break
  418. case MainViewModel.MENU_YSZC:
  419. router.pushUrl({
  420. url: 'pages/WebIndex',
  421. params: { titleName: '隐私政策', webUrl: CommonConstants.NEW_YS_HW }
  422. });
  423. break
  424. case MainViewModel.MENU_SHARE:
  425. this.gotoShare()
  426. break
  427. }
  428. })
  429. }
  430. .transition(TransitionEffect.move(TransitionEdge.BOTTOM).animation({ duration: 600, curve: Curve.Ease, delay: 60*index }))
  431. .width('90%')
  432. .height(55)
  433. })
  434. }
  435. .width('100%')
  436. .alignListItem(ListItemAlign.Center)
  437. .backgroundColor($r('app.color.silvery'))
  438. .layoutWeight(1)
  439. // .divider({ strokeWidth: 1, color: this.isDarkMode? '333333':'#ffe9f0f0' })
  440. .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
  441. }
  442. gotoShare(){
  443. let shareData: systemShare.SharedData = new systemShare.SharedData({
  444. utd: uniformTypeDescriptor.UniformDataType.TEXT,
  445. content: 'https://appgallery.huawei.com/app/detail?id='+this.bundleName,
  446. title: this.appName, // 不传title字段时,显示content
  447. description: '精心雕琢的无损音乐播放器',
  448. // thumbnail: new Uint8Array() // 推荐传入适合的缩略图 不传则显示默认text图标
  449. });
  450. // 进行分享面板显示
  451. let controller: systemShare.ShareController = new systemShare.ShareController(shareData);
  452. let context = getContext(this) as common.UIAbilityContext;
  453. controller.show(context, {
  454. selectionMode: systemShare.SelectionMode.SINGLE,
  455. previewMode: systemShare.SharePreviewMode.DETAIL,
  456. }).then(() => {
  457. console.info('ShareController show success.');
  458. }).catch((error: BusinessError) => {
  459. console.error(`ShareController show error. code: ${error.code}, message: ${error.message}`);
  460. });
  461. }
  462. // /**
  463. // * ================== 穿山甲广告相关 ==================
  464. // */
  465. // /** Banner广告对象 */
  466. // private declare bannerAd: CSJNativeExpressAd;
  467. // /** 广告加载状态 */
  468. // @State private status: string = "未加载"
  469. // /** 是否展示广告 */
  470. // @State private isShowAd: boolean = false
  471. // /** 广告位配置信息 */
  472. // private declare mAdSlot: AdSlot;
  473. // /** 服务端bidding广告内容(可选) */
  474. // private mBiddingAdm = ''
  475. // /** 广告加载监听器 */
  476. // private expressLoadAdListener: NativeExpressAdListener = {
  477. // /**
  478. // * 广告加载失败回调
  479. // */
  480. // onError: (code: number, message: string) => {
  481. // console.error("加载广告失败,code=" + code + ",message=" + message);
  482. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  483. // },
  484. // /**
  485. // * 广告加载成功回调
  486. // * @param ads 返回的广告列表
  487. // */
  488. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  489. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  490. // if (ads && ads.length > 0) {
  491. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  492. // // 设置广告交互监听
  493. // ad.setExpressInteractionListener({
  494. // /** 广告点击回调 */
  495. // onAdClicked: (type: number) => {
  496. // console.log("BannerExpressAdPage==onAdClicked......");
  497. // },
  498. // /** 广告展示回调 */
  499. // onAdShow: (type: number) => {
  500. // console.log("BannerExpressAdPage==onAdShow......");
  501. // },
  502. // /** 模板渲染失败回调 */
  503. // onRenderFail: (code: number, msg: string) => {
  504. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  505. // },
  506. // /** 模板渲染成功回调 */
  507. // onRenderSuccess: (width: number, height: number) => {
  508. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  509. // this.bannerAd = ad;
  510. // this.status = "广告加载完成待展示";
  511. // this.showBannerAd()
  512. // }
  513. // })
  514. // // 设置广告轮播时间
  515. // ad.setSlideIntervalTime(30 * 1000);//设置轮播时间长
  516. // this.setDislikeCallback(ad); //设置dislike
  517. // ad.render(this.getUIContext()) // 开始渲染广告
  518. // this.status = "广告加载中...";
  519. // });
  520. // }
  521. // }
  522. // }
  523. //
  524. // /**
  525. // * 设置广告 dislike 回调
  526. // * @param ad 广告对象
  527. // */
  528. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  529. // ad.setDislikeCallback({
  530. // /** dislike 弹窗显示 */
  531. // onShow: () => {
  532. // console.log("BannerExpressAdPage==dislike......show");
  533. // },
  534. // /** 选择 dislike 选项 */
  535. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  536. // this.isShowAd = false;
  537. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value + ",enforce=" + enforceRemove);
  538. // },
  539. // /** 点击取消 dislike */
  540. // onCancel: () => {
  541. // console.log("BannerExpressAdPage==dislike......onCancel");
  542. // }
  543. // })
  544. // }
  545. //
  546. // /**
  547. // * 加载Banner广告
  548. // * @param rit 广告位ID
  549. // */
  550. // loadBannerAd(rit: string) {
  551. // // 仅在满足条件时加载广告
  552. // if(!Utility.isNoble()){
  553. // return
  554. // }
  555. // if(!Utility.isPassInstallTime(2)){
  556. // return
  557. // }
  558. // this.isShowAd = false;
  559. // let adCreator:CSJAdCreator = CSJAdSdk.getAdCreator()
  560. // this.mAdSlot = new AdSlotBuilder()
  561. // .setCodeId(rit)
  562. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  563. // .setAdCount(1)
  564. // .setBidAdm(this.mBiddingAdm)
  565. // .build()
  566. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  567. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  568. // this.status = "广告加载中..."
  569. // }
  570. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  571. HeightBreakpoint.HEIGHT_LG;
  572. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  573. //是否是Pura X外屏,或者小屏幕
  574. isPuraWP() {
  575. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  576. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  577. }
  578. //是否是Pura X外屏,或者小屏幕或者手机横屏
  579. isCoverOpacity() {
  580. if (this.isPuraWP()) {
  581. return true
  582. }
  583. if (this.isPhoneLan()) {
  584. return true
  585. }
  586. if (deviceInfo.marketName.includes('Pura X')
  587. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  588. return true
  589. }
  590. return false
  591. }
  592. //是不是手机横屏
  593. isPhoneLan() {
  594. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  595. && this.currentBreakpoint !== BreakpointTypeEnum.SM) {
  596. if (DisplayUtil.getFoldStatus() === 0 ) {
  597. return true
  598. }
  599. }
  600. return false
  601. }
  602. /**
  603. * 展示Banner广告
  604. */
  605. // showBannerAd() {
  606. // if (!this.bannerAd) {
  607. // return
  608. // }
  609. // this.isShowAd = true
  610. // this.status = "已展示"
  611. // }
  612. /**
  613. * ================== 穿山甲广告相关结束 ==================
  614. */
  615. // geIDD() {
  616. // // 获取应用签名等信息示例代码
  617. // let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
  618. // bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
  619. // try {
  620. // bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
  621. // hilog.info(0x0000, 'testTag11', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
  622. // }).catch((err: BusinessError) => {
  623. // hilog.error(0x0000, 'testTag11', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
  624. // });
  625. // } catch (err) {
  626. // let message = (err as BusinessError).message;
  627. // hilog.error(0x0000, 'testTag33', 'getBundleInfoForSelf failed: %{public}s', message);
  628. // }
  629. // }
  630. }