NewIndex.ets 25 KB

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