| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880 |
- import { AppUtil, DeviceUtil, DisplayUtil, LogUtil, PreferencesUtil, ToastUtil } from '@pura/harmony-utils';
- import TitleBar from '../view/TitleBar';
- import { router } from '@kit.ArkUI';
- import mainViewModel, { MainViewModel } from '../viewmodel/MainViewModel';
- import ItemData from '../viewmodel/ItemData';
- import type { sysResource } from '../viewmodel/ItemData';
- import { CommonConstants } from '../common/constants/CommonConstants';
- import { VideoItem } from '../viewmodel/VideoItem';
- import ScreenUtil from '../common/util/ScreenUtil';
- import { Utility } from '../common/util/Utility';
- import { BusinessError, emitter } from '@kit.BasicServicesKit';
- import { common } from '@kit.AbilityKit';
- // import { AdSlot, AdSlotBuilder,
- // CSJAdCreator,
- // CSJAdSdk, CSJNativeExpressAd, NativeExpressAdListener } from '@csj/openadsdk';
- import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils';
- import { ArrayList } from '@kit.ArkTS';
- import { CSJUtil } from '../common/util/CSJUtil';
- import { LocalMusic } from '../view/LocalMusic';
- import { StreamContent } from '../view/StreamContent';
- import { AvSessionController } from '../controller/AvSessionController';
- import { BreakpointSystem, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
- import dataStorage from '@ohos.data.storage';
- import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
- import { SettingPage } from './SettingPage';
- import { deviceInfo } from '@kit.BasicServicesKit';
- import { resourceManager } from '@kit.LocalizationKit';
- import { systemShare } from '@kit.ShareKit';
- import { uniformTypeDescriptor } from '@kit.ArkData';
- import { hilog } from '@kit.PerformanceAnalysisKit';
- import { DialogHelper } from '@pura/harmony-dialog';
- import UserUtil from '../common/util/UserUtil';
- import json from '@ohos.util.json';
- import { UserCenter } from './UserCenter';
- import { ScanFilePage } from './ScanFilePage';
- import { AboutPage } from './AboutPage';
- const TAG = 'NewIndex'; // 日志标签
- /**
- * 首页主组件,包含顶部标题栏、主内容区(本地音乐/网络内容)、侧边抽屉菜单等。
- * 支持多端适配、广告集成、导航、生命周期管理等功能。
- */
- @Preview
- @Entry
- @Component
- struct NewIndex {
- /** 列表滚动器,用于抽屉菜单列表滚动 */
- private scroller: Scroller = new Scroller();
- /** 应用包名 */
- @State bundleName: string = ''
- @State appName: string = ''
- /** 是否显示侧边抽屉菜单 */
- @Provide isShowDrawer: boolean = false;
- /** 抽屉菜单 X 轴偏移量,用于手势滑动动画 */
- @Provide offsetX: number = 0;
- /** 本地视频列表,页面参数传入 */
- @Provide videoLocalList: Array<VideoItem> = []
- /** Y 轴偏移量(预留) */
- @State offsetY: number = 0;
- /** 主内容类型(0:本地音乐,1:网络内容) */
- @Provide mType: number = 0
- /** 模式类型(如歌手、专辑等) */
- @Provide modeType: number = 0
- /** 是否为零状态(预留) */
- @Provide('isZero') isZero: boolean = false;
- /** 是否显示赞助入口 */
- @State isShowSponsorship: boolean = false
- /** 页面上下文 */
- context = getContext(this);
- /** 音乐是否为零状态(预留) */
- @Provide('isMusicZero') isMusicZero: boolean = false;
- /** 本地音乐列表,持久化存储 */
- @StorageLink('musicLocalList') musicLocalList: Array<VideoItem> = []
- @Provide isFavMusic: boolean = false
- /** 标题栏配置模型 */
- @State titleBarModel: TitleBar.Model = new TitleBar.Model()
- .setTitleTextStyle(FontStyle.Normal)
- .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
- .setLeftIcon($r('app.media.menu'))
- .setLeftIconWidth(28)
- .setLeftIconHeight(28)
- .setTitleBarMinHeight(64)
- .setTitleName('首页')// .setRightIcon($r('app.media.add'))
- .setTitleFontSize(19)
- .setTitleFontColor(Color.White)
- .setTitleBarBackground($r('app.color.title_bar_bg'))
- .setLeftTitleBackground($r('app.color.title_bar_bg'))
- .setOnLeftClickListener(() => {
- // 打开菜单栏动画
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = true
- this.offsetX = 0
- })
- })
- .setRightTitleBackground($r('app.color.title_bar_bg'))
- // .setOnRightClickListener(()=>{
- // // this.goSelectVideo()
- // this.showSheelDialog()
- // })
- /** 应用版本号 */
- @State versionName: string = ''
- /** 音频根目录路径 */
- @Provide rootPath: string = ''
- /** 当前路径 */
- @Provide currentPath: string = ''
- /** 是否为历史记录页面 */
- @Provide isHistory: boolean = false
- /** 是否可以返回上一级 */
- @Provide isCanBack: boolean = false
- @StorageProp('currentColorMode') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
- @StorageProp('themeColor') themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
- /**
- * 一多界面适配断点系统
- */
- private breakpointSystem: BreakpointSystem = new BreakpointSystem();
- /** 当前断点类型(如大屏/小屏) */
- @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
- /** 记录上一次点击返回键的时间戳,用于双击退出 */
- private backTime: number = 0;
- /**
- * 返回键处理逻辑:
- * - 如果不是根目录或有历史记录,发送广播通知更新列表
- * - 如果是根目录,双击返回键退出应用,否则提示
- */
- onBackPress(): boolean | void {
- if (this.currentPath !== this.rootPath || this.isHistory || this.isFavMusic ||
- (this.modeType !== 0 && this.isCanBack)) {
- const eventData: emitter.EventData = {};
- emitter.emit({ eventId: 888 }, eventData); // 发送音频广播通知更新doSwipBack
- } else {
- let nowtime = Date.now();
- if (nowtime - this.backTime < 1000) {
- const mContext = getContext(this) as common.UIAbilityContext
- mContext.terminateSelf(); // 关闭应用
- AvSessionController.getInstance(true).unregisterSessionListener()
- } else {
- if (this.isShowDrawer) {
- // 如果抽屉菜单打开,先关闭抽屉
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- } else {
- this.backTime = nowtime;
- ToastUtil.showToast("再按一次将退出当前应用")
- }
- }
- }
- return true;
- }
- /**
- * 刷新@State用户信息变量,确保UI同步
- */
- refreshUserInfoState() {
- this.isLogin = PreferencesUtil.getBooleanSync('isLogin', false);
- this.userId = PreferencesUtil.getNumberSync('userId', 0);
- this.userName = PreferencesUtil.getStringSync('userName', '未登录用户');
- this.userAvatarUrl = PreferencesUtil.getStringSync('userAvatarUrl', '');
- this.subscriptionName = PreferencesUtil.getStringSync('subscriptionName', '');
- this.subscriptionEndDate = PreferencesUtil.getStringSync('subscriptionEndDate', '');
- this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
- }
- /**
- * 页面显示生命周期钩子
- * - 注册断点系统
- * - 获取页面参数
- * - 设置状态栏样式
- * - 初始化图片缓存
- * - 判断是否显示赞助入口
- */
- async aboutToAppear() {
- Utility.enableFullScreen()
- this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
- Utility.getAppName(getContext(this)).then((appName: string) => {
- this.appName = appName
- })
- this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
- this.breakpointSystem.register();
- let params = router.getParams() as Record<string, Object>;
- this.videoLocalList = params.videoList as VideoItem[];
- // Utility.setStatusBarLight()
- ScreenUtil.setScreenSize();
- this.bundleName = AppUtil.getBundleName()
- this.versionName = AppUtil.getVersionName();
- // await ImageKnife.getInstance().initFileCache(this.context, 256, 256 * 1024 * 1024)
- this.isShowSponsorship = Utility.isOpenTime()
- let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
- hilog.info(0x0000, 'Heanup', '当前 NewIndex themeColor:' + themeColor);
- AppStorage.setOrCreate('themeColor', themeColor);
- this.themeColor = themeColor
- // ====== 本地会员同步提醒逻辑 ======
- // this.refreshUserInfoState();
- // if (this.isLogin) {
- // void this.fetchUserInfo();
- // }
- console.log('Heanup isLogin:' + this.isLogin)
- console.log('Heanup Utility.isNobleForOld():' + Utility.isNobleForOld())
- await UserUtil.fetchUserInfo();
- this.refreshUserInfoState();
- let changeUserState: emitter.InnerEvent = { eventId: 1001 }
- emitter.on(changeUserState, () => {
- this.refreshUserInfoState();
- });
- }
- /**
- * 页面消失生命周期钩子
- * 注销断点系统
- */
- aboutToDisappear() {
- console.info('NewIndex aboutToDisappear');
- this.breakpointSystem.unregister();
- emitter.off(888);
- emitter.off(1001);
- }
- build() {
- SideBarContainer(SideBarContainerType.AUTO) {
- Column() {
- this.getLeftView()
- }
- // .backgroundColor(Color.Transparent)
- Column() {
- Stack() {
- // 本地音乐内容区
- LocalMusic()
- .visibility(this.mType === 0 ? Visibility.Visible : Visibility.None)
- // 网络内容区
- UserCenter()
- .visibility(this.mType === 1 ? Visibility.Visible : Visibility.None)
- ScanFilePage()
- .visibility(this.mType === 2 ? Visibility.Visible : Visibility.None)
- SettingPage()
- .visibility(this.mType === 3 ? Visibility.Visible : Visibility.None)
- AboutPage()
- .visibility(this.mType === 4 ? Visibility.Visible : Visibility.None)
-
- // 抽屉打开时的遮罩层,用于拦截点击事件 这个只能正常尺寸的手机竖屏的才能生效
- if (this.isShowDrawer&&this.isPhonePortrait()) {
- Column()
- .width('100%')
- .height('100%')
- .backgroundColor(Color.Transparent)
- .onClick(() => {
- // 点击遮罩层关闭抽屉
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- })
- }
- }
- }
- }
- .showControlButton(false)
- .minContentWidth(0)
- .sideBarWidth(this.isBigScreen() ? 300 : 270)
- .autoHide(true)
- .showSideBar($$this.isShowDrawer)
- .onChange((value: boolean) => {
- this.isShowDrawer = value
- })
- }
- //是不是正常的手机竖屏
- isPhonePortrait() {
- LogUtil.info('twocold this.currentHeightBreakpoint = '+this.currentHeightBreakpoint)
- LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
- if(DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
- &&this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG
- &&this.currentWidthBreakpoint==WidthBreakpoint.WIDTH_SM){//如果是手机横屏,返回false
- return true
- }
- return false
- }
- /**
- * 判断是否横屏
- * @returns
- */
- isBigScreen() {
- if (this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_LG) {
- return true
- }
- if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
- && this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
- && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG) {
- return false
- } else {
- return true
- }
- return false
- }
- @Builder
- getLeftView() {
- Column() {
- Column() {
- this.buildUserInfoCard()
- this.getDrawerView()
- }
- .width('100%')
- .height('100%')
- .onClick((event: ClickEvent) => {
- // 点击抽屉内部不关闭,通过返回值阻止事件传播
- return true
- })
- }
- // .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'36%':'70%')
- .height('100%')
- .borderRadius({
- topLeft: 0,
- topRight: 20,
- bottomLeft: 0,
- bottomRight: 20
- })
- // .backgroundColor($r('app.color.silvery'))
- .backgroundColor($r('app.color.index_background'))
- .alignItems(HorizontalAlign.Start)
- .translate({ x: this.offsetX, y: 0, z: 0 })
- .transition({ type: TransitionType.Insert, translate: { x: -DisplayUtil.getWidth(), y: 0 } })
- .transition({ type: TransitionType.Delete, translate: { x: -DisplayUtil.getWidth(), y: 0 } })
- .gesture(
- PanGesture()
- .onActionUpdate((event: GestureEvent) => {
- // 手势滑动更新抽屉偏移
- if (event.offsetX < 0) {
- this.offsetX = event.offsetX;
- }
- })
- .onActionEnd(() => {
- // 手势结束判断是否关闭抽屉
- if (this.offsetX < -DisplayUtil.getWidth() / 15) {
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- } else {
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = true
- this.offsetX = 0
- })
- }
- })
- )
- }
- @State isLogin: boolean = false;
- @State userAvatar: Resource = $r('app.media.icon_person2');
- @State userAvatarUrl: string = '';
- @State isVip: boolean = false;
- @State isDarkMode: boolean = false
- @State userName: string = '未登录用户';
- @State userId: number = 0;
- @State hasActiveSubscription: boolean = false;
- @State subscriptionName: string = '';
- @State subscriptionEndDate: string = '';
- // 用户信息卡片
- @Builder
- buildUserInfoCard() {
- Column() {
- Row() {
- Stack({ alignContent: Alignment.BottomEnd }){
- Image(this.userAvatarUrl && this.userAvatarUrl.length > 0 ? this.userAvatarUrl : this.userAvatar)
- .width(55)
- .height(55)
- .margin({ left: 12 })
- .borderRadius('50%')
- .clip(true)
- // .fillColor(this.themeColor)
- .backgroundColor(this.isDarkMode ? Color.Black : Color.White)
- Column() {
- Text('VIP')
- .fontSize(9)
- .padding(2)
- .textAlign(TextAlign.Center)
- .fontWeight(FontWeight.Bolder)
- .fontColor(Color.White)
- }
- .width(28)
- .height(16)
- .visibility(Utility.isNoble()?Visibility.Visible:Visibility.None)
- .borderRadius(15)
- .backgroundColor(this.themeColor)
- }
- Column() {
- Row() {
- Text(this.isLogin ? this.userName : '未登录用户')
- .fontSize(14)
- // .fontWeight(FontWeight.Bold)
- .fontColor(this.isDarkMode ? Color.White : Color.Black)
- .textAlign(TextAlign.Start)
- .maxLines(1)
- .width(110)
- .margin({ right: 12 })
- }
- .justifyContent(FlexAlign.Start)
- .margin({ top: 2 })
- if (this.isLogin) {
- if (this.hasActiveSubscription) {
- // Text(this.subscriptionName)
- // .fontSize(13)
- // .fontColor(themeColorWithAlpha(this.themeColor, 0.8, false))
- // .textAlign(TextAlign.Start)
- // .padding({top:5})
- this.TimeTextBuilder()
- } else {
- Text('普通用户')
- .fontSize(13)
- .fontColor(this.isDarkMode ? Color.White : Color.Grey)
- .textAlign(TextAlign.Start)
- .padding({top:5})
- this.TimeTextBuilder()
- }
- } else {
- this.TimeTextBuilder()
- }
- }
- .alignItems(HorizontalAlign.Start)
- .width(80)
- .margin({ left: 10 })
- }
- .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
- .onClick(() => {
- // if (!this.isLogin) {
- this.mType = 1
- if (!this.isBigScreen()) {
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- // }
- }
- })
- .width('100%')
- .padding(10)
- }
- .backgroundColor($r('app.color.user_center_card_background'))
- .borderRadius(24)
- .width('86%')
- .padding(8)
- .margin({ left: 10, right: 10, top: this.topRectHeight + 10,bottom:10 })
- .shadow({
- radius: 8,
- color: 0x11000000,
- offsetX: 0,
- offsetY: 2
- })
- }
- @Builder
- TimeTextBuilder() {
- Text(Utility.getTimePeriod())
- .fontSize(13)
- .margin({ top: 5 })
- .fontColor($r('app.color.text_color'))
- .align(Alignment.Start)
- }
- /**
- * 动态生成抽屉菜单内容
- * 根据 isShowSponsorship 展示不同菜单项
- */
- @Builder
- getDrawerView() {
- List({ space: 0, scroller: this.scroller }) {
- ForEach(mainViewModel.getDrawerData2(), (item: ItemData, index: number) => {
- ListItem() {
- Button({ type: ButtonType.Capsule, stateEffect: true }) {
- Row() {
- // 菜单图标
- if (typeof item.img === 'object' && item.img !== null && (item.img as sysResource).type === 'symbol') {
- SymbolGlyph((item.img as sysResource).value as Resource)// .size({ width: 22, height: 22 })
- .fontSize(22)
- .fontColor([this.themeColor])
- .alignSelf(ItemAlign.Center)
- .margin({ left: 25 })
- } else {
- Image(item.img as Resource)
- .height(22)
- .alignSelf(ItemAlign.Center)
- .fillColor(this.themeColor)
- .margin({ left: 25 })
- }
- // 菜单标题
- Text(item.title)
- .margin({ left: 10, right: 20 })
- .fontSize(15)
- .fontColor(this.mType == index ? this.themeColor : $r('app.color.index_tab_font_color'))
- .fontWeight(480)
- Blank()
- // 右侧箭头
- Image($r('app.media.arrow_right'))
- .width(22)
- .height(22)
- .margin({ left: 20, right: 0 })
- .align(Alignment.Center)
- }
- .width('100%')
- .height(55)
- }
- .backgroundColor(Color.Transparent)
- .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
- .onClick(async () => {
- // 根据 item.id 跳转或切换功能
- switch (item.id) {
- case MainViewModel.MENU_MUSIC:
- this.mType = 0
- if (!this.isBigScreen()) {
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- }
- break
- case MainViewModel.MENU_FILE_SCAN:
- this.mType = 2
- if (!this.isBigScreen()) {
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- }
- break
- // case MainViewModel.MENU_HOME:
- // this.mType = 0
- // this.modeType = 0
- // this.getUIContext()?.animateTo({ duration: 555 }, () => {
- // this.isShowDrawer = false
- // })
- // break
- case MainViewModel.MENU_MIEDIA_KU:
- this.modeType = 1
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- break
- case MainViewModel.MENU_MIEDIA_ARTIST:
- this.modeType = 2
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- break
- case MainViewModel.MENU_MIEDIA_ALBUM:
- this.modeType = 3
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- break
- case MainViewModel.MENU_SETTING:
- this.mType = 3
- if (!this.isBigScreen()) {
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- }
- // router.pushUrl({
- // url: 'pages/SettingPage'
- // }, router.RouterMode.Single);
- break
- case MainViewModel.MENU_VIP:
- router.pushUrl({
- url: 'pages/VipPage'
- }, router.RouterMode.Single);
- break
- case MainViewModel.MENU_USER:
- this.mType = 1
- if (!this.isBigScreen()) {
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- }
- // router.pushUrl({
- // url: 'pages/UserCenter'
- // }, router.RouterMode.Single);
- break
- case MainViewModel.MENU_NET_CONNECT:
- this.mType = 1
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- break
- case MainViewModel.MENU_SIMI:
- router.pushUrl({
- url: 'pages/VerifyPage'
- });
- break
- case MainViewModel.MENU_LIKE:
- router.pushUrl({
- url: 'pages/LikeVideoPage'
- });
- break
- case MainViewModel.MENU_DUTY:
- router.pushUrl({
- url: 'pages/WebIndex',
- params: { titleName: '用户协议', webUrl: CommonConstants.NEW_DUTY }
- });
- break
- case MainViewModel.MENU_HAOPING:
- Utility.gotoMarket(getContext(this) as common.UIAbilityContext, this.bundleName)
- break
- case MainViewModel.MENU_TEST_SPEED:
- router.pushUrl({
- url: 'pages/SpeedIndex'
- });
- break
- case MainViewModel.MENU_OPTIMIZE:
- router.pushUrl({
- url: 'pages/AddSpeedPage'
- });
- break
- case MainViewModel.MENU_ABOUT:
- this.mType = 4
- if (!this.isBigScreen()) {
- this.getUIContext()?.animateTo({ duration: 555 }, () => {
- this.isShowDrawer = false
- })
- }
- // router.pushUrl({
- // url: 'pages/AboutPage'
- // }, router.RouterMode.Single);
- break
- case MainViewModel.MENU_UPDATE:
- AlertDialog.show({
- title: '版本更新',
- message: '当前版本为最新版本:' + this.versionName,
- autoCancel: true,
- alignment: DialogAlignment.Center,
- offset: { dx: 0, dy: -20 }, //在Y轴方向上的编译量
- confirm: {
- value: '确定',
- fontColor: Color.White,
- backgroundColor: $r('app.color.title_bar_bg'),
- action: () => {
- }
- }
- })
- break
- case MainViewModel.MENU_YSZC:
- router.pushUrl({
- url: 'pages/WebIndex',
- params: { titleName: '隐私政策', webUrl: CommonConstants.NEW_YS_HW }
- });
- break
- case MainViewModel.MENU_SHARE:
- this.gotoShare()
- break
- }
- })
- }
- .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
- .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
- .width('90%')
- .height(55)
- })
- }
- .width('86%')
- .borderRadius(20)
- .margin({
- bottom: 20,
- left: 10,
- right: 10,
- top: 10
- })
- .alignListItem(ListItemAlign.Center)
- .layoutWeight(1)
- .backgroundColor($r('app.color.silvery'))
- .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
- }
- gotoShare() {
- let shareData: systemShare.SharedData = new systemShare.SharedData({
- utd: uniformTypeDescriptor.UniformDataType.TEXT,
- content: 'https://appgallery.huawei.com/app/detail?id=' + this.bundleName,
- title: this.appName, // 不传title字段时,显示content
- description: '精心雕琢的无损音乐播放器',
- // thumbnail: new Uint8Array() // 推荐传入适合的缩略图 不传则显示默认text图标
- });
- // 进行分享面板显示
- let controller: systemShare.ShareController = new systemShare.ShareController(shareData);
- let context = getContext(this) as common.UIAbilityContext;
- controller.show(context, {
- selectionMode: systemShare.SelectionMode.SINGLE,
- previewMode: systemShare.SharePreviewMode.DETAIL,
- }).then(() => {
- console.info('ShareController show success.');
- }).catch((error: BusinessError) => {
- console.error(`ShareController show error. code: ${error.code}, message: ${error.message}`);
- });
- }
- // /**
- // * ================== 穿山甲广告相关 ==================
- // */
- // /** Banner广告对象 */
- // private declare bannerAd: CSJNativeExpressAd;
- // /** 广告加载状态 */
- // @State private status: string = "未加载"
- // /** 是否展示广告 */
- // @State private isShowAd: boolean = false
- // /** 广告位配置信息 */
- // private declare mAdSlot: AdSlot;
- // /** 服务端bidding广告内容(可选) */
- // private mBiddingAdm = ''
- // /** 广告加载监听器 */
- // private expressLoadAdListener: NativeExpressAdListener = {
- // /**
- // * 广告加载失败回调
- // */
- // onError: (code: number, message: string) => {
- // console.error("加载广告失败,code=" + code + ",message=" + message);
- // this.status = "加载广告失败,code=" + code + ",message=" + message;
- // },
- // /**
- // * 广告加载成功回调
- // * @param ads 返回的广告列表
- // */
- // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
- // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
- // if (ads && ads.length > 0) {
- // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
- // // 设置广告交互监听
- // ad.setExpressInteractionListener({
- // /** 广告点击回调 */
- // onAdClicked: (type: number) => {
- // console.log("BannerExpressAdPage==onAdClicked......");
- // },
- // /** 广告展示回调 */
- // onAdShow: (type: number) => {
- // console.log("BannerExpressAdPage==onAdShow......");
- // },
- // /** 模板渲染失败回调 */
- // onRenderFail: (code: number, msg: string) => {
- // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
- // },
- // /** 模板渲染成功回调 */
- // onRenderSuccess: (width: number, height: number) => {
- // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
- // this.bannerAd = ad;
- // this.status = "广告加载完成待展示";
- // this.showBannerAd()
- // }
- // })
- // // 设置广告轮播时间
- // ad.setSlideIntervalTime(30 * 1000);//设置轮播时间长
- // this.setDislikeCallback(ad); //设置dislike
- // ad.render(this.getUIContext()) // 开始渲染广告
- // this.status = "广告加载中...";
- // });
- // }
- // }
- // }
- //
- // /**
- // * 设置广告 dislike 回调
- // * @param ad 广告对象
- // */
- // private setDislikeCallback(ad: CSJNativeExpressAd) {
- // ad.setDislikeCallback({
- // /** dislike 弹窗显示 */
- // onShow: () => {
- // console.log("BannerExpressAdPage==dislike......show");
- // },
- // /** 选择 dislike 选项 */
- // onSelected: (position: number, value: string, enforceRemove: boolean) => {
- // this.isShowAd = false;
- // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value + ",enforce=" + enforceRemove);
- // },
- // /** 点击取消 dislike */
- // onCancel: () => {
- // console.log("BannerExpressAdPage==dislike......onCancel");
- // }
- // })
- // }
- //
- // /**
- // * 加载Banner广告
- // * @param rit 广告位ID
- // */
- // loadBannerAd(rit: string) {
- // // 仅在满足条件时加载广告
- // if(!Utility.isNoble()){
- // return
- // }
- // if(!Utility.isPassInstallTime(2)){
- // return
- // }
- // this.isShowAd = false;
- // let adCreator:CSJAdCreator = CSJAdSdk.getAdCreator()
- // this.mAdSlot = new AdSlotBuilder()
- // .setCodeId(rit)
- // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
- // .setAdCount(1)
- // .setBidAdm(this.mBiddingAdm)
- // .build()
- // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
- // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
- // this.status = "广告加载中..."
- // }
- @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
- HeightBreakpoint.HEIGHT_LG;
- @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
- @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
- //是否是Pura X外屏,或者小屏幕
- isPuraWP() {
- return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
- && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
- }
- //是否是Pura X外屏,或者小屏幕或者手机横屏
- isCoverOpacity() {
- if (this.isPuraWP()) {
- return true
- }
- if (this.isPhoneLan()) {
- return true
- }
- if (deviceInfo.marketName.includes('Pura X')
- && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
- return true
- }
- return false
- }
- //是不是手机横屏
- isPhoneLan() {
- if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
- && this.currentBreakpoint !== BreakpointTypeEnum.SM) {
- if (DisplayUtil.getFoldStatus() === 0) {
- return true
- }
- }
- return false
- }
- isLoginChange() {
- this.refreshUserInfoState();
- }
- }
- // 1. 工具函数:将 #RRGGBB 字符串和透明度转为 'rgba(r,g,b,a)' 字符串,深色模式下可返回深色变体
- function themeColorWithAlpha(themeColor: string, alpha: number, isDarkMode: boolean = false): string {
- if (isDarkMode) {
- // 深色模式下返回更深的灰色或半透明黑色
- return `rgba(34,34,34,${alpha + 0.2 > 1 ? 1 : alpha + 0.2})`;
- }
- const color = themeColor.replace('#', '');
- const r = parseInt(color.substring(0, 2), 16);
- const g = parseInt(color.substring(2, 4), 16);
- const b = parseInt(color.substring(4, 6), 16);
- return `rgba(${r},${g},${b},${alpha})`;
- }
|