NewIndex.ets 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070
  1. import { AppUtil, ArrayUtil, DeviceUtil, DisplayUtil, LogUtil, PreferencesUtil,
  2. StrUtil,
  3. ToastUtil } from '@pura/harmony-utils';
  4. import TitleBar from '../view/TitleBar';
  5. import { curves,
  6. ImmersiveMode,
  7. LengthMetrics,
  8. LevelMode,
  9. MenuModifier,
  10. router, SegmentButton, SegmentButtonOptions, SymbolGlyphModifier } from '@kit.ArkUI';
  11. import mainViewModel, { MainViewModel } from '../viewmodel/MainViewModel';
  12. import ItemData from '../viewmodel/ItemData';
  13. import type { sysResource } from '../viewmodel/ItemData';
  14. import { CommonConstants } from '../common/constants/CommonConstants';
  15. import { EventConstants } from '../common/constants/EventConstants';
  16. import { VideoItem } from '../viewmodel/VideoItem';
  17. import ScreenUtil from '../common/util/ScreenUtil';
  18. import { Utility } from '../common/util/Utility';
  19. import { BusinessError, emitter } from '@kit.BasicServicesKit';
  20. import { common } from '@kit.AbilityKit';
  21. import { BreakpointSystem, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
  22. import dataStorage from '@ohos.data.storage';
  23. import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
  24. import { SettingPage } from './SettingPage';
  25. import { deviceInfo } from '@kit.BasicServicesKit';
  26. import { resourceManager } from '@kit.LocalizationKit';
  27. import { systemShare } from '@kit.ShareKit';
  28. import { uniformTypeDescriptor } from '@kit.ArkData';
  29. import { hilog } from '@kit.PerformanceAnalysisKit';
  30. import { DialogHelper, DialogAction } from '@pura/harmony-dialog';
  31. import UserUtil from '../common/util/UserUtil';
  32. import json from '@ohos.util.json';
  33. import { UserCenter } from './UserCenter';
  34. import { ScanFilePage } from './ScanFilePage';
  35. import { AboutPage, gotoShare } from './AboutPage';
  36. import { smartMobilityCommon } from '@kit.CarKit';
  37. import { UpdateLogManager } from '../common/util/UpdateLogManager';
  38. import OnlineUpdateLogDialog from '../dialog/OnlineUpdateLog';
  39. import OnlineUpdateLog from '../dialog/OnlineUpdateLog';
  40. import { LocalMusic } from '../view/LocalMusic';
  41. import { ChartsCount } from './ChartsCount';
  42. import { image } from '@kit.ImageKit';
  43. import { Playlist, PlaylistSong } from '../viewmodel/Playlist';
  44. import PlaylistTable from '../common/util/PlaylistTable';
  45. import { convertPlaylistSongsToVideoItems } from './PlaylistDetailPage';
  46. import MediaTable from '../common/util/MediaTable';
  47. import { showCreatePlaylistDialog } from '../dialog/PlaylistDialog';
  48. import { ImagePickerUtil } from '../common/util/ImagePickerUtil';
  49. import { WebDavMainPage } from './WebDavMainPage';
  50. import { WebDavAccount } from '../viewmodel/WebDavAccount';
  51. import { RemoteDriveManager } from '../common/util/RemoteDriveManager';
  52. import { getCloudDiskIcon, RemoteDriveAccountDialog } from '../dialog/RemoteDriveAccountDialog';
  53. import ReqPermissionUtil from '../common/util/ReqPermissionUtil';
  54. import { getRemoteDriveAccountLabel, getRemoteDriveDisplayLabel, getRemoteDriveProtocolLabel } from '../common/util/RemoteDriveLabel';
  55. import { RemoteDriveType } from '../common/enums/RemoteDriveType';
  56. import { NavidromePage } from '../view/NavidromePage';
  57. import { ServerLogUtil } from '../common/util/ServerLogUtil';
  58. import { PlayStatus } from '../common/PlayStatus';
  59. // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
  60. const TAG = 'NewIndex'; // 日志标签
  61. /**
  62. * 首页主组件,包含顶部标题栏、主内容区(本地音乐/网络内容)、侧边抽屉菜单等。
  63. * 支持多端适配、广告集成、导航、生命周期管理等功能。
  64. */
  65. @Preview
  66. @Entry
  67. @Component
  68. struct NewIndex {
  69. @Provide isShowPlay: boolean = false;
  70. @Provide CONTROL_PlayStatus: number = PlayStatus.INIT;
  71. @Provide progressValue: number = 0;
  72. @State isShowPrecious: boolean = false //播控条显示上一首按钮
  73. @State bottomBarHeight: number = 70;
  74. @StorageProp('bottomSafeHeight') bottomSafeHeight: number = 0;
  75. @Provide cover: string | undefined = '';
  76. // @Provide currentSong: VideoItem | undefined = undefined;
  77. @StorageLink('currentSong') currentSong: VideoItem | undefined = undefined;
  78. @Provide isMultiSelect: boolean = false;
  79. /** 页面上下文 */
  80. context = this.getUIContext().getHostContext() as common.UIAbilityContext
  81. @Provide currentSongListName:string = '' //当前歌单名称
  82. @Provide currentSongListID:string='' //当前歌单ID
  83. @State isDarkMode: boolean = false
  84. /** 列表滚动器,用于抽屉菜单列表滚动 */
  85. private scroller: Scroller = new Scroller();
  86. /** 应用包名 */
  87. @State bundleName: string = ''
  88. @State appName: string = ''
  89. /** 是否显示侧边抽屉菜单 */
  90. @Provide isShowDrawer: boolean = false;
  91. /** 抽屉菜单 X 轴偏移量,用于手势滑动动画 */
  92. @Provide offsetX: number = 0;
  93. /** 本地视频列表,页面参数传入 */
  94. @Provide videoLocalList: Array<VideoItem> = []
  95. /** Y 轴偏移量(预留) */
  96. @State offsetY: number = 0;
  97. /** 主内容类型(0:本地音乐,1:网络内容) */
  98. @Provide mType: number = 0
  99. /** 模式类型(如文件夹 媒体库 艺术家、专辑等) */
  100. @Provide modeType: number = 0
  101. /** 是否为零状态(预留) */
  102. @Provide('isZero') isZero: boolean = false;
  103. /** 是否显示赞助入口 */
  104. @State isShowSponsorship: boolean = false
  105. /** 音乐是否为零状态(预留) */
  106. @Provide('isMusicZero') isMusicZero: boolean = false;
  107. @State isShowTitleBar: boolean = false //是否显示分类导航条
  108. /** 本地音乐列表,持久化存储 */
  109. @StorageLink('musicLocalList') musicLocalList: Array<VideoItem> = []
  110. @Provide isFavMusic: boolean = false
  111. @StorageProp('windowWidth') windowWidth: number = 0;
  112. @StorageProp('windowHeight') windowHeight: number = 0;
  113. @StorageProp('isHiCarStatus') isHiCarStatus: boolean = false;
  114. @StorageProp('curDisplayIsHiCar') curDisplayIsHiCar: boolean = false;
  115. @State idDefaultMediaKu: boolean = false
  116. /**
  117. * 是否显示更新日志开关
  118. */
  119. @State isShowUpdateDialog: boolean = false
  120. /** 标题栏配置模型 */
  121. @State titleBarModel: TitleBar.Model = new TitleBar.Model()
  122. .setTitleTextStyle(FontStyle.Normal)
  123. .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
  124. .setLeftIcon($r('app.media.menu'))
  125. .setLeftIconWidth(28)
  126. .setLeftIconHeight(28)
  127. .setTitleBarMinHeight(64)
  128. .setTitleName('首页')// .setRightIcon($r('app.media.add'))
  129. .setTitleFontSize(19)
  130. .setTitleFontColor(Color.White)
  131. .setTitleBarBackground($r('app.color.title_bar_bg'))
  132. .setLeftTitleBackground($r('app.color.title_bar_bg'))
  133. .setOnLeftClickListener(() => {
  134. // 打开菜单栏动画
  135. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  136. this.isShowDrawer = true
  137. this.offsetX = 0
  138. })
  139. })
  140. .setRightTitleBackground($r('app.color.title_bar_bg'))
  141. // .setOnRightClickListener(()=>{
  142. // // this.goSelectVideo()
  143. // this.showSheelDialog()
  144. // })
  145. /** 应用版本号 */
  146. @State versionName: string = ''
  147. /** 音频根目录路径 */
  148. @Provide rootPath: string = ''
  149. /** 当前路径 */
  150. @Provide currentPath: string = ''
  151. /** 是否为历史记录页面 */
  152. @Provide isHistory: boolean = false
  153. /** 是否可以返回上一级 */
  154. @Provide isCanBack: boolean = false
  155. @StorageProp('currentColorMode') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
  156. @StorageProp('themeColor') themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
  157. /**
  158. * 一多界面适配断点系统
  159. */
  160. private breakpointSystem: BreakpointSystem = new BreakpointSystem();
  161. /** 当前断点类型(如大屏/小屏) */
  162. @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
  163. /** 记录上一次点击返回键的时间戳,用于双击退出 */
  164. private backTime: number = 0;
  165. @State tabOptions: SegmentButtonOptions = SegmentButtonOptions.tab({
  166. buttons: [{ text: '分类' }, { text: '歌单' }, { text: '网盘' }],
  167. direction: Direction.Ltr,
  168. backgroundColor: $r('app.color.index_background'),
  169. selectedBackgroundColor:$r('app.color.start_window_background'),
  170. selectedFontColor: $r('app.color.text_color'),
  171. localizedTextPadding: {
  172. end: LengthMetrics.vp(10),
  173. start: LengthMetrics.vp(10)
  174. }
  175. })
  176. @State @Watch('tabSelectedIndexesChanged') tabSelectedIndexes: number[] = [0]
  177. //当胶囊按钮的选择发生变化时调用此函数
  178. tabSelectedIndexesChanged() {
  179. if(this.tabSelectedIndexes[0]==1){
  180. this.mType = 0
  181. } else if(this.tabSelectedIndexes[0]==2){
  182. // 网盘选项卡
  183. this.mType = 6
  184. }
  185. }
  186. // 歌单相关状态变量
  187. @State playlistList: Playlist[] = []
  188. @State isShowCreatePlaylistDialog: boolean = false
  189. @State selectedPlaylist: Playlist | null = null
  190. private playlistTable: PlaylistTable | null = null
  191. // 网盘账户相关状态变量
  192. @State webDavAccounts: WebDavAccount[] = []
  193. private webdavManager: RemoteDriveManager = RemoteDriveManager.getInstance()
  194. private _webDavLoading: boolean = false // 防止重复加载网盘账户的标志
  195. @State selectedAccount: WebDavAccount = new WebDavAccount()
  196. /**
  197. * 返回键处理逻辑:
  198. * - 如果不是根目录或有历史记录,发送广播通知更新列表
  199. * - 如果是根目录,双击返回键退出应用,否则提示
  200. */
  201. onBackPress(): boolean | void {
  202. if (this.currentPath !== this.rootPath || this.isHistory || this.isFavMusic ||
  203. (this.modeType !== 0 && this.isCanBack)) {
  204. console.info('onecold 返回键处理逻辑:发送音频广播通知更新列表');
  205. const eventData: emitter.EventData = {};
  206. emitter.emit({ eventId: EventConstants.EVENT_SWIPE_BACK_UPDATE }, eventData); // 发送音频广播通知更新doSwipBack
  207. }else if(this.mType > 0){
  208. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  209. // 动画闭包内控制Image组件的出现和消失
  210. // this.isShowDrawer = !this.isShowDrawer
  211. // this.offsetX = 0
  212. this.mType =0
  213. })
  214. } else {
  215. console.info('onecold 返回键处理 关闭');
  216. if (this.isShowDrawer) {
  217. // 如果抽屉菜单打开,先关闭抽屉
  218. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  219. this.isShowDrawer = false
  220. })
  221. } else {
  222. return false
  223. }
  224. }
  225. return true;
  226. }
  227. /**
  228. * 刷新@State用户信息变量,确保UI同步
  229. */
  230. refreshUserInfoState() {
  231. this.isLogin = PreferencesUtil.getBooleanSync('isLogin', false);
  232. this.userId = PreferencesUtil.getNumberSync('userId', 0);
  233. this.userName = PreferencesUtil.getStringSync('userName', '未登录用户');
  234. this.userAvatarUrl = PreferencesUtil.getStringSync('userAvatarUrl', '');
  235. this.subscriptionName = PreferencesUtil.getStringSync('subscriptionName', '');
  236. this.subscriptionEndDate = PreferencesUtil.getStringSync('subscriptionEndDate', '');
  237. this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
  238. }
  239. onPageShow() {
  240. LogUtil.info('heanup NewIndex', 'onPageShow 被调用,刷新歌单列表和网盘账户列表')
  241. // 加载歌单列表
  242. this.loadPlaylistList()
  243. // 加载网盘账户列表
  244. this.loadWebDavAccounts()
  245. }
  246. /**
  247. * 页面显示生命周期钩子
  248. * - 注册断点系统
  249. * - 获取页面参数
  250. * - 设置状态栏样式
  251. * - 初始化图片缓存
  252. * - 判断是否显示赞助入口
  253. */
  254. async aboutToAppear() {
  255. this.isShowPrecious = PreferencesUtil.getBooleanSync('isShowPrecious', false)
  256. ReqPermissionUtil.reqPermissionsFromUser(ReqPermissionUtil.permissions, this.context);
  257. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, false)
  258. this.idDefaultMediaKu = PreferencesUtil.getBooleanSync('idDefaultMediaKu', false)
  259. if(this.idDefaultMediaKu){
  260. this.modeType = 1
  261. }
  262. Utility.enableFullScreen()
  263. this.topRectHeight = px2vp(AppUtil.getStatusBarHeight());
  264. Utility.getAppName(getContext(this)).then((appName: string) => {
  265. this.appName = appName
  266. })
  267. this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
  268. this.breakpointSystem.register();
  269. let params = router.getParams() as Record<string, Object>;
  270. if (params && params.videoList) {
  271. this.videoLocalList = params.videoList as VideoItem[];
  272. LogUtil.info('heanup NewIndex', '从路由参数获取到播放列表,长度:' + this.videoLocalList.length)
  273. } else {
  274. this.videoLocalList = []
  275. LogUtil.info('heanup NewIndex', '路由参数中没有播放列表,使用空数组')
  276. }
  277. // 检查是否从WebDavPage返回
  278. if (params && params.fromWebDavPage) {
  279. LogUtil.info('heanup NewIndex', '从WebDavPage返回,切换到网盘标签页')
  280. this.mType = 6
  281. this.tabSelectedIndexes = [2] // 切换到网盘标签
  282. }
  283. // Utility.setStatusBarLight()
  284. ScreenUtil.setScreenSize();
  285. this.bundleName = AppUtil.getBundleName()
  286. this.versionName = AppUtil.getVersionName();
  287. // await ImageKnife.getInstance().initFileCache(this.context, 256, 256 * 1024 * 1024)
  288. this.isShowSponsorship = Utility.isOpenTime()
  289. let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', CommonConstants.DEFAULT_THEME_COLOR);
  290. hilog.info(0x0000, 'Heanup', '当前 NewIndex themeColor:' + themeColor);
  291. AppStorage.setOrCreate('themeColor', themeColor);
  292. this.themeColor = themeColor
  293. // ====== 本地会员同步提醒逻辑 ======
  294. // this.refreshUserInfoState();
  295. // if (this.isLogin) {
  296. // void this.fetchUserInfo();
  297. // }
  298. await UserUtil.fetchUserInfo();
  299. this.refreshUserInfoState();
  300. let changeUserState: emitter.InnerEvent = { eventId: EventConstants.EVENT_USER_STATE_CHANGE }
  301. emitter.on(changeUserState, () => {
  302. this.refreshUserInfoState();
  303. });
  304. let eventSetting: emitter.InnerEvent = { eventId: EventConstants.EVENT_SETTING_UPDATE }
  305. // 监听广播事件(通用设置配置更新)
  306. emitter.on(eventSetting, (eventData: emitter.EventData) => {
  307. this.isShowTitleBar = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_TITLTBAR, true)
  308. });
  309. this.logHiCar('info', `getHiCarStatus isHiCarStatus=${this.isHiCarStatus}`)
  310. if(this.curDisplayIsHiCar||this.isBigScreen()){
  311. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  312. this.isShowDrawer = true
  313. this.offsetX = 0
  314. })
  315. this.isShowTitleBar = false
  316. }
  317. // 检查并显示更新日志
  318. this.checkAndShowUpdateLog();
  319. // 初始化歌单数据库
  320. await this.initPlaylistTable();
  321. // 初始化WebDAV管理器
  322. await this.initWebDavManager();
  323. // 监听歌单刷新事件
  324. emitter.on({ eventId: EventConstants.EVENT_PLAYLIST_REFRESH }, (eventData: emitter.EventData) => {
  325. LogUtil.info('heanup NewIndex', '收到歌单刷新事件,开始刷新歌单列表')
  326. this.loadPlaylistList()
  327. });
  328. if(Utility.isOpenTime()&&!PreferencesUtil.getBooleanSync('isShowHaoPingDialog179', false)){
  329. setTimeout(()=>{
  330. Utility.showHaoPingDialog(this.getUIContext(),this.context,this.appName,this.bundleName)
  331. PreferencesUtil.putSync('isShowHaoPingDialog179', true)
  332. },25000)
  333. }
  334. }
  335. /**
  336. * 检查并显示更新日志
  337. */
  338. private async checkAndShowUpdateLog() {
  339. try {
  340. const shouldShow = await UpdateLogManager.checkAndShowUpdateLog();
  341. if (shouldShow) {
  342. this.isShowUpdateDialog = !this.isShowUpdateDialog
  343. UpdateLogManager.markCurrentVersionShown()
  344. }
  345. // this.isShowUpdateDialog = true;//调试期间显示更新日志,测试完成后请删除
  346. } catch (error) {
  347. console.error('NewIndex checkAndShowUpdateLog error:', error);
  348. }
  349. }
  350. /**
  351. * 页面消失生命周期钩子
  352. * 注销断点系统
  353. */
  354. aboutToDisappear() {
  355. console.info('NewIndex aboutToDisappear');
  356. this.breakpointSystem.unregister();
  357. emitter.off(EventConstants.EVENT_SWIPE_BACK_UPDATE);
  358. emitter.off(EventConstants.EVENT_USER_STATE_CHANGE);
  359. // 监听歌单刷新事件
  360. emitter.off(EventConstants.EVENT_PLAYLIST_REFRESH);
  361. // 清理WebDAV管理器订阅
  362. if (this.webdavManager) {
  363. this.webdavManager.observers = [];
  364. }
  365. }
  366. @Builder
  367. ContentBuild() {
  368. Stack() {
  369. // 本地音乐内容区
  370. LocalMusic()
  371. .visibility(this.mType === 0 ? Visibility.Visible : Visibility.None)
  372. // 网络内容区
  373. UserCenter()
  374. .visibility(this.mType === 1 ? Visibility.Visible : Visibility.None)
  375. ScanFilePage()
  376. .visibility(this.mType === 2 ? Visibility.Visible : Visibility.None)
  377. ChartsCount({
  378. isShowDrawer:this.isShowDrawer,
  379. offsetX:this.offsetX
  380. })
  381. .visibility(this.mType === 3 ? Visibility.Visible : Visibility.None)
  382. SettingPage()
  383. .visibility(this.mType === 4 ? Visibility.Visible : Visibility.None)
  384. AboutPage()
  385. .visibility(this.mType === 5 ? Visibility.Visible : Visibility.None)
  386. WebDavMainPage({
  387. offsetX:this.offsetX,
  388. isShowDrawer:this.isShowDrawer,
  389. mType:this.mType,
  390. selectedAccount:this.selectedAccount
  391. })
  392. .visibility(this.mType === 6 ? Visibility.Visible : Visibility.None)
  393. if(this.mType === 7){
  394. NavidromePage({
  395. offsetX:this.offsetX,
  396. isShowDrawer:this.isShowDrawer,
  397. mType:this.mType,
  398. selectedAccount:this.selectedAccount
  399. })
  400. .visibility(this.mType === 7 ? Visibility.Visible : Visibility.None)
  401. }
  402. // 抽屉打开时的遮罩层,用于拦截点击事件 这个只能正常尺寸的手机竖屏的才能生效
  403. if (this.isShowDrawer&&this.isPhonePortrait()) {
  404. Column()
  405. .width('100%')
  406. .height('100%')
  407. .backgroundBlurStyle(BlurStyle.BACKGROUND_THIN)
  408. .transition(TransitionEffect.OPACITY.animation({
  409. curve: curves.springMotion(0, 1)
  410. }))
  411. .onClick(() => {
  412. // 点击遮罩层关闭抽屉
  413. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  414. this.isShowDrawer = false
  415. })
  416. })
  417. }
  418. }
  419. .bindSheet($$this.isShowUpdateDialog, this.updateSheet(), {
  420. height: '90%',
  421. dragBar: true,
  422. preferType: this.currentBreakpoint !== BreakpointTypeEnum.SM ? SheetType.CENTER : SheetType.BOTTOM,
  423. showClose: true,
  424. blurStyle: BlurStyle.Regular,
  425. title: { title: '更新日志' }
  426. })
  427. }
  428. build() {
  429. SideBarContainer(SideBarContainerType.AUTO) {
  430. Column() {
  431. this.getLeftView()
  432. }
  433. .backgroundColor(Color.Transparent)
  434. Stack() {
  435. this.ContentBuild()
  436. Stack() {
  437. this.PlayController()
  438. }
  439. .width('90%')
  440. .borderRadius(15)
  441. .margin({ bottom:DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_2IN1
  442. ? 30 :this.bottomSafeHeight })
  443. .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
  444. .backgroundImage(StrUtil.isEmpty(this.cover) ?$r('app.media.alt'):this.cover)
  445. .visibility(this.isMultiSelect||(this.mType>0&&this.mType<6) ? Visibility.None : Visibility.Visible)
  446. .backgroundImageSize( { width: '100%' })
  447. .animation({
  448. duration: 500,
  449. curve: Curve.Friction // 可选动画曲线
  450. })
  451. .opacity(0.99)
  452. .clickEffect({ level: ClickEffectLevel.HEAVY })
  453. }
  454. .alignContent(Alignment.Bottom)
  455. .width('100%')
  456. .height('100%')
  457. .gesture(SwipeGesture({ direction: SwipeDirection.Horizontal }).onAction((event: GestureEvent) => {
  458. if (event) {//手势返回
  459. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  460. this.isShowDrawer = !this.isShowDrawer
  461. if(this.isShowDrawer)
  462. this.offsetX = 0
  463. })
  464. }
  465. }))
  466. }
  467. .showControlButton(false)
  468. .minContentWidth(0)
  469. .sideBarWidth(260)
  470. .autoHide(true)
  471. .showSideBar($$this.isShowDrawer)
  472. .onChange((value: boolean) => {
  473. this.isShowDrawer = value
  474. })
  475. }
  476. @Builder
  477. centerName() {
  478. Column() {
  479. Text(this.currentSong?.name)
  480. .fontSize(16)
  481. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  482. .maxLines(1)
  483. .fontColor(Color.White)
  484. .fontWeight(FontWeight.Bolder);
  485. Row() {
  486. Text(this.currentSong?.artist)
  487. .margin({ top: 2 })
  488. .fontSize(13)
  489. .textAlign(TextAlign.Start)
  490. .maxLines(1)
  491. .fontWeight(FontWeight.Bold)
  492. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  493. .fontColor(Color.White)
  494. }
  495. .visibility(this.currentSong?.artist? Visibility.Visible:Visibility.None)
  496. }
  497. .alignItems(HorizontalAlign.Center)
  498. }
  499. setShowPlayTrue(){
  500. if (this.isShowPlay === true) {
  501. this.isShowPlay = false
  502. }
  503. this.getUIContext()?.animateTo({
  504. duration: 500,
  505. curve: Curve.Friction
  506. }, () => {
  507. this.isShowPlay = true;
  508. });
  509. this.getUIContext().getHostContext()!.eventHub.emit('showPlayerView');
  510. }
  511. @Builder
  512. PlayController() {
  513. Row() {
  514. this.playConLeft(!this.curDisplayIsHiCar)
  515. if(!this.curDisplayIsHiCar){
  516. this.playConRigth()
  517. }
  518. if(this.curDisplayIsHiCar){
  519. Column(){
  520. this.centerName()
  521. }
  522. .layoutWeight(1)
  523. .onClick(()=>{
  524. this.setShowPlayTrue()
  525. })
  526. }
  527. }
  528. .width('100%')
  529. .height(this.bottomBarHeight)
  530. .hitTestBehavior(HitTestMode.Transparent)
  531. .zIndex(2)
  532. .padding({
  533. left: 16,
  534. right: 16
  535. })
  536. }
  537. @Builder
  538. playConLeft(isLeft: boolean = true) {
  539. Row() {
  540. Image( StrUtil.isNotEmpty(this.currentSong?.pixelMapPath)?
  541. this.currentSong?.pixelMapPath:$r('app.media.alt'))
  542. .height(48)
  543. .objectFit(ImageFit.Contain)
  544. .alt( $r('app.media.alt'))
  545. .fillColor(this.themeColor)
  546. .borderRadius(8)
  547. .shadow({
  548. radius: 15,
  549. type: ShadowType.BLUR,
  550. color: 'on_primary'
  551. })
  552. .geometryTransition('cover', { follow: true }) // 绑定标识符
  553. if(!this.curDisplayIsHiCar){
  554. Column() {
  555. Text(this.currentSong?.name)
  556. .fontSize(16)
  557. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  558. .maxLines(1)
  559. .fontColor(Color.White)
  560. .fontWeight(FontWeight.Bolder);
  561. Row() {
  562. Text(this.currentSong?.artist)
  563. .margin({ top: 2 })
  564. .fontSize(13)
  565. .textAlign(TextAlign.Start)
  566. .maxLines(1)
  567. .fontWeight(FontWeight.Bold)
  568. .textOverflow({ overflow: TextOverflow.MARQUEE }) //超长滚动
  569. .fontColor(Color.White)
  570. }
  571. .visibility(this.currentSong?.artist? Visibility.Visible:Visibility.None)
  572. }
  573. .padding({left:8})
  574. .alignItems(isLeft?HorizontalAlign.Start:HorizontalAlign.End)
  575. .margin({ right: isLeft?22:10 })
  576. }else{
  577. this.playConRigth()
  578. }
  579. }
  580. .padding({ right: 18 })
  581. .layoutWeight(1)
  582. .alignItems(VerticalAlign.Center)
  583. .justifyContent(FlexAlign.Start)
  584. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.8 })
  585. .onClick(() => {
  586. this.setShowPlayTrue()
  587. })
  588. }
  589. @Builder
  590. playConRigth() {
  591. Row() {
  592. SymbolGlyph($r('sys.symbol.backward_end_fill'))
  593. .fontSize(28)
  594. .fontColor([this.themeColor])
  595. .alignSelf(ItemAlign.Center)
  596. .visibility(this.isShowPrecious? Visibility.Visible:Visibility.None)
  597. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  598. .margin({ left: 8, right: 14 })
  599. .displayPriority(2)
  600. .onClick(() => {
  601. this.getUIContext().getHostContext()!.eventHub.emit('playPrevious');
  602. })
  603. //播放进度条
  604. Stack() {
  605. Progress({
  606. value: Math.floor(this.progressValue),
  607. type: ProgressType.Ring,
  608. })
  609. .color(this.themeColor)// 进度条前景色为灰色
  610. .height(38)
  611. .aspectRatio(CommonConstants.ASPECT_RATIO)
  612. Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
  613. .height(36)
  614. .width(36)
  615. .displayPriority(3)
  616. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
  617. .fillColor(this.themeColor)
  618. .onClick(() => {
  619. this.getUIContext().getHostContext()!.eventHub.emit('playOrPause');
  620. })
  621. }
  622. SymbolGlyph($r('sys.symbol.forward_end_fill'))
  623. .fontSize(28)
  624. .fontColor([this.themeColor])
  625. .alignSelf(ItemAlign.Center)
  626. .margin({
  627. right: 14,
  628. left: 14
  629. })
  630. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  631. .displayPriority(2)
  632. .onClick(() => {
  633. this.getUIContext().getHostContext()!.eventHub.emit('playNext');
  634. })
  635. Image($r('app.media.hm_playlist'))
  636. .height(26)
  637. .width(26)
  638. .displayPriority(1)
  639. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  640. .fillColor(this.themeColor)
  641. .onClick(() => {
  642. this.getUIContext().getHostContext()!.eventHub.emit('openPlayList');
  643. })
  644. }
  645. .margin({left:this.curDisplayIsHiCar?20:5})
  646. .justifyContent(this.curDisplayIsHiCar?FlexAlign.Start:FlexAlign.End)
  647. }
  648. //是不是hicar的屏幕分辨率
  649. isHiCar() {
  650. return this.curDisplayIsHiCar;
  651. }
  652. //是不是正常的手机竖屏
  653. isPhonePortrait() {
  654. LogUtil.info('twocold this.currentHeightBreakpoint = '+this.currentHeightBreakpoint)
  655. LogUtil.info('twocold this.currentWidthBreakpoint = '+this.currentWidthBreakpoint)
  656. if(DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  657. &&this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG
  658. &&this.currentWidthBreakpoint==WidthBreakpoint.WIDTH_SM){//如果是手机横屏,返回false
  659. return true
  660. }
  661. return false
  662. }
  663. /**
  664. * 判断是否横屏
  665. * @returns
  666. */
  667. isBigScreen() {
  668. if (this.currentWidthBreakpoint == WidthBreakpoint.WIDTH_LG) {
  669. return true
  670. }
  671. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  672. && this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  673. && this.currentHeightBreakpoint == HeightBreakpoint.HEIGHT_LG) {
  674. return false
  675. } else {
  676. return true
  677. }
  678. return false
  679. }
  680. @Builder
  681. getLeftView() {
  682. Column() {
  683. Column() {
  684. this.getDrawerView()
  685. }
  686. .width('100%')
  687. .height('100%')
  688. .onClick((event: ClickEvent) => {
  689. // 点击抽屉内部不关闭,通过返回值阻止事件传播
  690. return true
  691. })
  692. }
  693. // .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?'36%':'70%')
  694. .height('100%')
  695. .borderRadius({
  696. topLeft: 0,
  697. topRight: 20,
  698. bottomLeft: 0,
  699. bottomRight: 20
  700. })
  701. // .backgroundColor($r('app.color.silvery'))
  702. // .backgroundColor($r('app.color.index_background'))
  703. .backgroundColor($r('app.color.user_center_card_background'))
  704. .alignItems(HorizontalAlign.Start)
  705. .translate({ x: this.offsetX, y: 0, z: 0 })
  706. .transition({ type: TransitionType.Insert, translate: { x: -DisplayUtil.getWidth(), y: 0 } })
  707. .transition({ type: TransitionType.Delete, translate: { x: -DisplayUtil.getWidth(), y: 0 } })
  708. .gesture(
  709. PanGesture()
  710. .onActionUpdate((event: GestureEvent) => {
  711. // 手势滑动更新抽屉偏移
  712. if (event.offsetX < 0) {
  713. this.offsetX = event.offsetX;
  714. }
  715. })
  716. .onActionEnd(() => {
  717. // 手势结束判断是否关闭抽屉
  718. if (this.offsetX < -DisplayUtil.getWidth() / 15) {
  719. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  720. this.isShowDrawer = false
  721. })
  722. } else {
  723. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  724. this.isShowDrawer = true
  725. this.offsetX = 0
  726. })
  727. }
  728. })
  729. )
  730. }
  731. @State isLogin: boolean = false;
  732. @State userAvatar: Resource = $r('app.media.icon_person2');
  733. @State userAvatarUrl: string = '';
  734. @State isVip: boolean = false;
  735. @State userName: string = '未登录用户';
  736. @State userId: number = 0;
  737. @State hasActiveSubscription: boolean = false;
  738. @State subscriptionName: string = '';
  739. @State subscriptionEndDate: string = '';
  740. // 用户信息卡片
  741. @Builder
  742. buildUserInfoCard() {
  743. Column() {
  744. this.userInfoView()
  745. Column({ space: 20 }) {
  746. SegmentButton({ options: this.tabOptions, selectedIndexes: $tabSelectedIndexes })
  747. }
  748. .padding({ bottom:10 })
  749. .width('90%')
  750. }
  751. }
  752. @Builder
  753. userInfoView() {
  754. Column() {
  755. Row() {
  756. Stack({ alignContent: Alignment.BottomEnd }){
  757. Image(this.userAvatarUrl && this.userAvatarUrl.length > 0 ? this.userAvatarUrl : this.userAvatar)
  758. .width(55)
  759. .height(55)
  760. .margin({ left: 12 })
  761. .borderRadius('50%')
  762. .clip(true)
  763. // .fillColor(this.themeColor)
  764. // .backgroundColor(this.isDarkMode ? Color.Black : Color.White)
  765. Column() {
  766. Text('VIP')
  767. .fontSize(9)
  768. .padding(2)
  769. .textAlign(TextAlign.Center)
  770. .fontWeight(FontWeight.Bolder)
  771. .fontColor(Color.White)
  772. }
  773. .width(28)
  774. .height(16)
  775. .visibility(Utility.isNoble()?Visibility.Visible:Visibility.None)
  776. .borderRadius(15)
  777. .backgroundColor(this.themeColor)
  778. }
  779. Column() {
  780. Row() {
  781. Text(this.isLogin ? this.userName : '未登录用户')
  782. .fontSize(14)
  783. // .fontWeight(FontWeight.Bold)
  784. // .fontColor(this.isDarkMode ? Color.White : Color.Black)
  785. .textAlign(TextAlign.Start)
  786. .maxLines(1)
  787. .width(110)
  788. .margin({ right: 12 })
  789. }
  790. .justifyContent(FlexAlign.Start)
  791. .margin({ top: 2 })
  792. if (this.isLogin) {
  793. if (this.hasActiveSubscription) {
  794. // Text(this.subscriptionName)
  795. // .fontSize(13)
  796. // .fontColor(themeColorWithAlpha(this.themeColor, 0.8, false))
  797. // .textAlign(TextAlign.Start)
  798. // .padding({top:5})
  799. this.TimeTextBuilder()
  800. } else {
  801. Text('普通用户')
  802. .fontSize(13)
  803. .fontColor(this.isDarkMode ? Color.White : Color.Grey)
  804. .textAlign(TextAlign.Start)
  805. .padding({top:5})
  806. this.TimeTextBuilder()
  807. }
  808. } else {
  809. this.TimeTextBuilder()
  810. }
  811. }
  812. .alignItems(HorizontalAlign.Start)
  813. .width(80)
  814. .margin({ left: 10 })
  815. }
  816. .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.7})
  817. .onClick(() => {
  818. // if (!this.isLogin) {
  819. this.mType = 1
  820. if (!this.isBigScreen()) {
  821. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  822. this.isShowDrawer = false
  823. })
  824. // }
  825. }
  826. })
  827. .width('100%')
  828. .padding(10)
  829. }
  830. .backgroundColor($r('app.color.user_center_card_background'))
  831. .borderRadius(24)
  832. .width('86%')
  833. .padding(8)
  834. .margin({ left: 10, right: 10, top: this.topRectHeight + 10,bottom:10 })
  835. .shadow({
  836. radius: 8,
  837. color: 0x11000000,
  838. offsetX: 0,
  839. offsetY: 2
  840. })
  841. }
  842. @Builder
  843. TimeTextBuilder() {
  844. Text(Utility.getTimePeriod())
  845. .fontSize(13)
  846. .margin({ top: 5 })
  847. .fontColor($r('app.color.text_color'))
  848. .align(Alignment.Start)
  849. }
  850. @State ratioL: number = 1;
  851. @State isRefreshing: boolean = false;
  852. @State maxRefreshingHeight: number = 100.0;
  853. private contentNode?: ComponentContent<Object> = undefined;
  854. /**
  855. * 动态生成抽屉菜单内容
  856. * 根据 isShowSponsorship 展示不同菜单项
  857. */
  858. @Builder
  859. getDrawerView() {
  860. Refresh({ refreshing: $$this.isRefreshing, refreshingContent: this.contentNode }) {
  861. List({ space: 0, scroller: this.scroller }) {
  862. ListItemGroup({ header: this.buildUserInfoCard() }) {
  863. if(this.tabSelectedIndexes[0]==0){//分类
  864. this.buildTabCate()
  865. }else if(this.tabSelectedIndexes[0]==1){//歌单
  866. this.buildPlaylistTab()
  867. }else if(this.tabSelectedIndexes[0]==2){//网盘
  868. this.buildCloudStorageTab()
  869. }
  870. }
  871. }
  872. .scrollBar(BarState.Off)
  873. .width('86%')
  874. .borderRadius(20)
  875. .margin({
  876. bottom: 20,
  877. left: 10,
  878. right: 10,
  879. top: 10
  880. })
  881. .alignListItem(ListItemAlign.Center)
  882. .layoutWeight(1)
  883. .backgroundColor($r('app.color.left_draw_bg'))
  884. .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
  885. }
  886. .pullDownRatio(this.ratioL)
  887. .pullToRefresh(true)
  888. .refreshOffset(0)
  889. .onOffsetChange((offset: number) => {
  890. // 越接近最大距离,下拉跟手系数越小。
  891. this.ratioL = 1 - Math.pow((offset / this.maxRefreshingHeight), 3);
  892. })
  893. .onStateChange((refreshStatus: RefreshStatus) => {
  894. console.info('onecold Refresh onStatueChange state is ' + refreshStatus);
  895. })
  896. .onRefreshing(async () => {
  897. if(this.tabSelectedIndexes[0]==0){//分类
  898. this.isRefreshing = false
  899. }else if(this.tabSelectedIndexes[0]==1){//歌单
  900. this.loadPlaylistList()
  901. }else if(this.tabSelectedIndexes[0]==2){//网盘
  902. this.loadWebDavAccounts()
  903. }
  904. })
  905. }
  906. @Builder
  907. buildTabCate() {
  908. ForEach(mainViewModel.getDrawerData(), (item: ItemData, index: number) => {
  909. ListItem() {
  910. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  911. Row() {
  912. // 菜单图标
  913. if (typeof item.img === 'object' && item.img !== null && (item.img as sysResource).type === 'symbol') {
  914. SymbolGlyph((item.img as sysResource).value as Resource)// .size({ width: 22, height: 22 })
  915. .fontSize(22)
  916. .fontColor([this.themeColor])
  917. .effectStrategy(SymbolEffectStrategy.HIERARCHICAL)
  918. .alignSelf(ItemAlign.Center)
  919. .margin({ left: 15 })
  920. } else {
  921. Image(item.img as Resource)
  922. .height(22)
  923. .alignSelf(ItemAlign.Center)
  924. .fillColor(this.themeColor)
  925. .margin({ left: 15 })
  926. }
  927. // 菜单标题
  928. Text(item.title)
  929. .margin({ left: 10, right: 20 })
  930. .fontSize(15)
  931. .fontColor(this.isTextSelected(index) ? this.themeColor : $r('app.color.index_tab_font_color'))
  932. .fontWeight(480)
  933. Blank()
  934. // 右侧箭头
  935. Image($r('app.media.arrow_right'))
  936. .width(22)
  937. .height(22)
  938. .margin({ left: 20, right: 0 })
  939. .align(Alignment.Center)
  940. }
  941. .width('100%')
  942. .height(55)
  943. }
  944. .backgroundColor(Color.Transparent)
  945. .clickEffect({ level: ClickEffectLevel.MIDDLE,scale:0.6 })
  946. .onClick(async () => {
  947. // 根据 item.id 跳转或切换功能
  948. switch (item.id) {
  949. case MainViewModel.MENU_MUSIC:
  950. this.mType = 0
  951. this.modeType = 0
  952. this.currentSongListID = ''
  953. this.doShowDrawer()
  954. break
  955. case MainViewModel.MENU_FILE_SCAN:
  956. this.mType = 2
  957. this.doShowDrawer()
  958. break
  959. case MainViewModel.MENU_CHARTS:
  960. this.mType = 3
  961. this.modeType = 0
  962. this.doShowDrawer()
  963. break
  964. case MainViewModel.MENU_MIEDIA_KU:
  965. this.modeType = 1
  966. this.mType = 0
  967. this.currentSongListID = ''
  968. this.doShowDrawer()
  969. break
  970. case MainViewModel.MENU_MIEDIA_ARTIST:
  971. this.modeType = 2
  972. this.mType = 0
  973. this.currentSongListID = ''
  974. this.doShowDrawer()
  975. break
  976. case MainViewModel.MENU_MIEDIA_ALBUM:
  977. this.modeType = 3
  978. this.mType = 0
  979. this.currentSongListID = ''
  980. this.doShowDrawer()
  981. break
  982. case MainViewModel.MENU_SETTING:
  983. this.mType = 4
  984. this.doShowDrawer()
  985. break
  986. case MainViewModel.MENU_VIP:
  987. router.pushUrl({
  988. url: 'pages/VipPage'
  989. }, router.RouterMode.Single);
  990. break
  991. case MainViewModel.MENU_USER:
  992. this.mType = 1
  993. this.doShowDrawer()
  994. break
  995. case MainViewModel.MENU_NET_CONNECT:
  996. this.mType = 1
  997. this.doShowDrawer()
  998. break
  999. case MainViewModel.MENU_SIMI:
  1000. router.pushUrl({
  1001. url: 'pages/VerifyPage'
  1002. });
  1003. break
  1004. case MainViewModel.MENU_DUTY:
  1005. router.pushUrl({
  1006. url: 'pages/WebIndex',
  1007. params: { titleName: '用户协议', webUrl: CommonConstants.NEW_DUTY }
  1008. });
  1009. break
  1010. case MainViewModel.MENU_HAOPING:
  1011. Utility.gotoMarket(getContext(this) as common.UIAbilityContext, this.bundleName)
  1012. break
  1013. case MainViewModel.MENU_ABOUT:
  1014. this.mType = 5
  1015. this.doShowDrawer()
  1016. break
  1017. case MainViewModel.MENU_UPDATE:
  1018. AlertDialog.show({
  1019. title: '版本更新',
  1020. message: '当前版本为最新版本:' + this.versionName,
  1021. autoCancel: true,
  1022. alignment: DialogAlignment.Center,
  1023. offset: { dx: 0, dy: -20 }, //在Y轴方向上的编译量
  1024. confirm: {
  1025. value: '确定',
  1026. fontColor: Color.White,
  1027. backgroundColor: $r('app.color.title_bar_bg'),
  1028. action: () => {
  1029. }
  1030. }
  1031. })
  1032. break
  1033. case MainViewModel.MENU_YSZC:
  1034. router.pushUrl({
  1035. url: 'pages/WebIndex',
  1036. params: { titleName: '隐私政策', webUrl: CommonConstants.NEW_YS_HW }
  1037. });
  1038. break
  1039. case MainViewModel.MENU_SHARE:
  1040. gotoShare(this.context,this.appName,this.bundleName)
  1041. break
  1042. }
  1043. })
  1044. }
  1045. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  1046. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  1047. .width('90%')
  1048. .height(55)
  1049. })
  1050. }
  1051. isTextSelected(index:number):boolean{
  1052. if(this.mType == 0){
  1053. return this.modeType == index
  1054. }
  1055. return this.mType+3 == index
  1056. }
  1057. doShowDrawer(){
  1058. if (!this.isBigScreen()) {
  1059. this.getUIContext()?.animateTo({ duration: 555 }, () => {
  1060. this.isShowDrawer = false
  1061. })
  1062. }
  1063. }
  1064. @Builder
  1065. updateSheet() {
  1066. Scroll() {
  1067. Column() {
  1068. OnlineUpdateLog()
  1069. }
  1070. }
  1071. .width('100%')
  1072. .height('100%')
  1073. }
  1074. // /**
  1075. // * ================== 穿山甲广告相关 ==================
  1076. // */
  1077. // /** Banner广告对象 */
  1078. // private declare bannerAd: CSJNativeExpressAd;
  1079. // /** 广告加载状态 */
  1080. // @State private status: string = "未加载"
  1081. // /** 是否展示广告 */
  1082. // @State private isShowAd: boolean = false
  1083. // /** 广告位配置信息 */
  1084. // private declare mAdSlot: AdSlot;
  1085. // /** 服务端bidding广告内容(可选) */
  1086. // private mBiddingAdm = ''
  1087. // /** 广告加载监听器 */
  1088. // private expressLoadAdListener: NativeExpressAdListener = {
  1089. // /**
  1090. // * 广告加载失败回调
  1091. // */
  1092. // onError: (code: number, message: string) => {
  1093. // console.error("加载广告失败,code=" + code + ",message=" + message);
  1094. // this.status = "加载广告失败,code=" + code + ",message=" + message;
  1095. // },
  1096. // /**
  1097. // * 广告加载成功回调
  1098. // * @param ads 返回的广告列表
  1099. // */
  1100. // onNativeExpressAdLoad: (ads: ArrayList<CSJNativeExpressAd>) => {
  1101. // console.log("BannerExpressAdPage==onNativeExpressAdLoad......success");
  1102. // if (ads && ads.length > 0) {
  1103. // ads.forEach((ad: CSJNativeExpressAd, idx: number) => {
  1104. // // 设置广告交互监听
  1105. // ad.setExpressInteractionListener({
  1106. // /** 广告点击回调 */
  1107. // onAdClicked: (type: number) => {
  1108. // console.log("BannerExpressAdPage==onAdClicked......");
  1109. // },
  1110. // /** 广告展示回调 */
  1111. // onAdShow: (type: number) => {
  1112. // console.log("BannerExpressAdPage==onAdShow......");
  1113. // },
  1114. // /** 模板渲染失败回调 */
  1115. // onRenderFail: (code: number, msg: string) => {
  1116. // console.log("BannerExpressAdPage==onRenderFail...code=" + code + ",msg=" + msg);
  1117. // },
  1118. // /** 模板渲染成功回调 */
  1119. // onRenderSuccess: (width: number, height: number) => {
  1120. // console.log("BannerExpressAdPage==onRenderSuccess......width=" + width + ",height=" + height);
  1121. // this.bannerAd = ad;
  1122. // this.status = "广告加载完成待展示";
  1123. // this.showBannerAd()
  1124. // }
  1125. // })
  1126. // // 设置广告轮播时间
  1127. // ad.setSlideIntervalTime(30 * 1000);//设置轮播时间长
  1128. // this.setDislikeCallback(ad); //设置dislike
  1129. // ad.render(this.getUIContext()) // 开始渲染广告
  1130. // this.status = "广告加载中...";
  1131. // });
  1132. // }
  1133. // }
  1134. // }
  1135. //
  1136. // /**
  1137. // * 设置广告 dislike 回调
  1138. // * @param ad 广告对象
  1139. // */
  1140. // private setDislikeCallback(ad: CSJNativeExpressAd) {
  1141. // ad.setDislikeCallback({
  1142. // /** dislike 弹窗显示 */
  1143. // onShow: () => {
  1144. // console.log("BannerExpressAdPage==dislike......show");
  1145. // },
  1146. // /** 选择 dislike 选项 */
  1147. // onSelected: (position: number, value: string, enforceRemove: boolean) => {
  1148. // this.isShowAd = false;
  1149. // console.log("BannerExpressAdPage==dislike......onSelected:position=" + position + ",value:" + value + ",enforce=" + enforceRemove);
  1150. // },
  1151. // /** 点击取消 dislike */
  1152. // onCancel: () => {
  1153. // console.log("BannerExpressAdPage==dislike......onCancel");
  1154. // }
  1155. // })
  1156. // }
  1157. //
  1158. // /**
  1159. // * 加载Banner广告
  1160. // * @param rit 广告位ID
  1161. // */
  1162. // loadBannerAd(rit: string) {
  1163. // // 仅在满足条件时加载广告
  1164. // if(!Utility.isNoble()){
  1165. // return
  1166. // }
  1167. // if(!Utility.isPassInstallTime(2)){
  1168. // return
  1169. // }
  1170. // this.isShowAd = false;
  1171. // let adCreator:CSJAdCreator = CSJAdSdk.getAdCreator()
  1172. // this.mAdSlot = new AdSlotBuilder()
  1173. // .setCodeId(rit)
  1174. // .setAcceptSize(CSJUtil.BANNER_WIGTH, CSJUtil.BANNER_HEIGHT)
  1175. // .setAdCount(1)
  1176. // .setBidAdm(this.mBiddingAdm)
  1177. // .build()
  1178. // PrintBiddingTokenUtils.printBiddingToken(this.mAdSlot, adCreator);
  1179. // adCreator.loadBannerAd(this.mAdSlot, this.expressLoadAdListener)
  1180. // this.status = "广告加载中..."
  1181. // }
  1182. @StorageProp('currentHeightBreakpoint') currentHeightBreakpoint: HeightBreakpoint | undefined =
  1183. HeightBreakpoint.HEIGHT_LG;
  1184. @StorageProp('currentWidthBreakpoint') currentWidthBreakpoint: WidthBreakpoint | undefined = WidthBreakpoint.WIDTH_SM;
  1185. @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
  1186. //是否是Pura X外屏,或者小屏幕
  1187. isPuraWP() {
  1188. return this.currentWidthBreakpoint === WidthBreakpoint.WIDTH_SM
  1189. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_MD
  1190. }
  1191. //是否是Pura X外屏,或者小屏幕或者手机横屏
  1192. isCoverOpacity() {
  1193. if (this.isPuraWP()) {
  1194. return true
  1195. }
  1196. if (this.isPhoneLan()) {
  1197. return true
  1198. }
  1199. if (deviceInfo.marketName.includes('Pura X')
  1200. && this.currentHeightBreakpoint === HeightBreakpoint.HEIGHT_SM) {
  1201. return true
  1202. }
  1203. return false
  1204. }
  1205. //是不是手机横屏
  1206. isPhoneLan() {
  1207. if (DeviceUtil.getDeviceType() === resourceManager.DeviceType.DEVICE_TYPE_PHONE
  1208. && this.currentBreakpoint !== BreakpointTypeEnum.SM) {
  1209. if (DisplayUtil.getFoldStatus() === 0) {
  1210. return true
  1211. }
  1212. }
  1213. return false
  1214. }
  1215. isLoginChange() {
  1216. this.refreshUserInfoState();
  1217. }
  1218. /**
  1219. * 构建歌单tab内容
  1220. */
  1221. @Builder
  1222. buildPlaylistTab() {
  1223. // 创建歌单按钮
  1224. ListItem() {
  1225. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  1226. Row() {
  1227. SymbolGlyph($r('sys.symbol.plus_circle'))
  1228. .fontSize(22)
  1229. .fontColor([this.themeColor])
  1230. .effectStrategy(SymbolEffectStrategy.HIERARCHICAL)
  1231. .alignSelf(ItemAlign.Center)
  1232. .margin({ left: 25 })
  1233. Text('创建歌单')
  1234. .margin({ left: 10, right: 20 })
  1235. .fontSize(14)
  1236. .fontColor($r('app.color.index_tab_font_color'))
  1237. .fontWeight(480)
  1238. Blank()
  1239. Image($r('app.media.arrow_right'))
  1240. .width(22)
  1241. .height(22)
  1242. .margin({ left: 20, right: 0 })
  1243. .align(Alignment.Center)
  1244. }
  1245. .width('100%')
  1246. .height(55)
  1247. }
  1248. .backgroundColor(Color.Transparent)
  1249. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  1250. .onClick(() => {
  1251. this.showCreatePlaylistDialog()
  1252. })
  1253. }
  1254. // 歌单列表
  1255. ForEach(this.playlistList, (playlist: Playlist,index:number) => {
  1256. ListItem() {
  1257. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  1258. Row() {
  1259. Image(playlist.coverPath || $r('app.media.hm_playlist'))
  1260. .width(22)
  1261. .height(22)
  1262. .margin({ left: 25 })
  1263. .borderRadius(4)
  1264. .fillColor(this.themeColor)
  1265. .clip(true)
  1266. Column() {
  1267. Text(playlist.name)
  1268. .margin({ left: 10, right: 20 })
  1269. .fontSize(15)
  1270. .fontColor($r('app.color.index_tab_font_color'))
  1271. .fontWeight(480)
  1272. .maxLines(1)
  1273. .textOverflow({ overflow: TextOverflow.Ellipsis })
  1274. Text(`${playlist.songCount}首`)
  1275. .margin({ left: 10, right: 20 })
  1276. .fontSize(12)
  1277. .fontColor($r('app.color.index_tab_font_color'))
  1278. .opacity(0.7)
  1279. }
  1280. .alignItems(HorizontalAlign.Start)
  1281. Blank()
  1282. Image($r('app.media.arrow_right'))
  1283. .width(22)
  1284. .height(22)
  1285. .margin({ left: 20, right: 0 })
  1286. .align(Alignment.Center)
  1287. }
  1288. .width('100%')
  1289. .height(55)
  1290. }
  1291. .backgroundColor(Color.Transparent)
  1292. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  1293. .onClick(async () => {
  1294. if(playlist.songCount==0){
  1295. this.openPlaylist(playlist)
  1296. }else{
  1297. this.doShowDrawer();
  1298. this.mType = 0
  1299. this.modeType = 4
  1300. this.currentSongListName = playlist.name;
  1301. this.currentSongListID = playlist.id;
  1302. }
  1303. })
  1304. .bindContextMenu(this.MenuBuilder(playlist), ResponseType.LongPress,
  1305. {
  1306. preview: MenuPreviewMode.IMAGE,
  1307. previewAnimationOptions: { scale: [0.8, 1.0] },
  1308. })
  1309. .bindContextMenu(this.MenuBuilder(playlist), ResponseType.RightClick,
  1310. {
  1311. preview: MenuPreviewMode.IMAGE,
  1312. previewAnimationOptions: { scale: [0.8, 1.0] },
  1313. })
  1314. }
  1315. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  1316. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  1317. })
  1318. }
  1319. /**
  1320. * 构建网盘tab内容 - 从数据库获取所有网盘账户
  1321. * 支持多种类型的网盘账户(目前支持WebDAV,将来可扩展其他类型)
  1322. */
  1323. @Builder
  1324. buildCloudStorageTab() {
  1325. // 当前只支持网盘账户,将来可以在这里添加其他类型的网盘账户
  1326. // 例如:OneDrive, Google Drive, Dropbox等
  1327. // 添加新账户按钮
  1328. ListItem() {
  1329. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  1330. Row() {
  1331. SymbolGlyph($r('sys.symbol.plus_circle'))
  1332. .fontSize(22)
  1333. .fontColor([this.themeColor])
  1334. .effectStrategy(SymbolEffectStrategy.HIERARCHICAL)
  1335. .alignSelf(ItemAlign.Center)
  1336. .margin({ left: 25 })
  1337. Text(`添加${getRemoteDriveAccountLabel()}`)
  1338. .margin({ left: 10, right: 20 })
  1339. .fontSize(14)
  1340. .fontColor($r('app.color.index_tab_font_color'))
  1341. .fontWeight(480)
  1342. Blank()
  1343. Image($r('app.media.arrow_right'))
  1344. .width(22)
  1345. .height(22)
  1346. .margin({ left: 20, right: 0 })
  1347. .align(Alignment.Center)
  1348. }
  1349. .width('100%')
  1350. .height(55)
  1351. }
  1352. .backgroundColor(Color.Transparent)
  1353. .bindMenu(this.AddMenuBuilder)
  1354. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
  1355. }
  1356. // 显示所有网盘账户
  1357. ForEach(this.webDavAccounts, (account: WebDavAccount,index:number) => {
  1358. ListItem() {
  1359. Button({ type: ButtonType.Capsule, stateEffect: true }) {
  1360. Row() {
  1361. // 账户封面或默认图标
  1362. Stack() {
  1363. Image(account.coverPath?account.coverPath:getCloudDiskIcon(account.webType))
  1364. .width(25)
  1365. .height(25)
  1366. .borderRadius(4)
  1367. .objectFit(ImageFit.Cover)
  1368. }
  1369. .margin({ left: 20 })
  1370. Column() {
  1371. // 账户名称
  1372. Text(account.name)
  1373. .margin({ left: 8, right: 20 })
  1374. .fontSize(15)
  1375. .fontColor(this.selectedAccount==account?this.themeColor:$r('app.color.text_color'))
  1376. .fontWeight(480)
  1377. .maxLines(1)
  1378. .textOverflow({ overflow: TextOverflow.Ellipsis })
  1379. Row() {
  1380. // 账户类型标签
  1381. Text(getRemoteDriveDisplayLabel(account.webType))
  1382. .fontSize(10)
  1383. .fontColor(this.selectedAccount==account?this.themeColor:$r('app.color.index_tab_font_color'))
  1384. .opacity(0.8)
  1385. .padding({ left: 8, top: 2, bottom: 2 })
  1386. .borderRadius(3)
  1387. // 服务器地址
  1388. Text(`@${account.isUseLocalHost ? account.localHost : account.host}:${account.port}`)
  1389. .fontSize(12)
  1390. .fontColor(this.selectedAccount==account?this.themeColor:$r('app.color.index_tab_font_color'))
  1391. .opacity(0.7)
  1392. .maxLines(1)
  1393. .padding({ right: 8, top: 2, bottom: 2 })
  1394. .textOverflow({ overflow: TextOverflow.Ellipsis })
  1395. }
  1396. }
  1397. .alignItems(HorizontalAlign.Start)
  1398. Blank()
  1399. Image($r('app.media.arrow_right'))
  1400. .width(22)
  1401. .height(22)
  1402. .margin({ left: 20, right: 0 })
  1403. .align(Alignment.Center)
  1404. }
  1405. .width('100%')
  1406. .height(60)
  1407. }
  1408. .backgroundColor(Color.Transparent)
  1409. .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.8 })
  1410. .onClick(() => {
  1411. console.info('heanup', '点击网盘账户:', account.name)
  1412. this.selectWebDavAccount(account)
  1413. })
  1414. .bindContextMenu(this.MenuDavBuilder(account), ResponseType.LongPress,
  1415. {
  1416. preview: MenuPreviewMode.IMAGE,
  1417. previewAnimationOptions: { scale: [0.8, 1.0] },
  1418. })
  1419. .bindContextMenu(this.MenuDavBuilder(account), ResponseType.RightClick,
  1420. {
  1421. preview: MenuPreviewMode.IMAGE,
  1422. previewAnimationOptions: { scale: [0.8, 1.0] },
  1423. })
  1424. }
  1425. .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
  1426. .animation({ duration: 600, curve: Curve.Ease, delay: 60 * index }))
  1427. })
  1428. // 如果没有账户,显示提示信息
  1429. if (this.webDavAccounts.length === 0) {
  1430. ListItem() {
  1431. Text(`暂无${getRemoteDriveAccountLabel()},点击上方按钮添加`)
  1432. .fontSize(14)
  1433. .fontColor($r('app.color.index_tab_font_color'))
  1434. .opacity(0.6)
  1435. .textAlign(TextAlign.Center)
  1436. .width('100%')
  1437. .padding(20)
  1438. }
  1439. }
  1440. }
  1441. @Builder
  1442. AddMenuBuilder() {
  1443. Menu() {
  1444. MenuItem({
  1445. startIcon: $r('app.media.webdav'),
  1446. content: $r('app.string.webdav')
  1447. })
  1448. .onClick(async () => {
  1449. this.showRemoteDriveAccountDialog(false,undefined,RemoteDriveType.WebDav)
  1450. })
  1451. MenuItem({
  1452. startIcon: $r('app.media.smb'),
  1453. content: $r('app.string.smb')
  1454. })
  1455. .onClick(async () => {
  1456. this.showRemoteDriveAccountDialog(false,undefined,RemoteDriveType.Smb)
  1457. })
  1458. MenuItem({
  1459. startIcon: $r('app.media.ftp'),
  1460. content: $r('app.string.ftp')
  1461. })
  1462. .onClick(async () => {
  1463. this.showRemoteDriveAccountDialog(false,undefined,RemoteDriveType.Ftp)
  1464. })
  1465. MenuItem({
  1466. startIcon: $r('app.media.navidrome'),
  1467. content: $r('app.string.navidrome')
  1468. })
  1469. .onClick(async () => {
  1470. this.showRemoteDriveAccountDialog(false,undefined,RemoteDriveType.Navidrome)
  1471. })
  1472. MenuItem({
  1473. startIcon: $r('app.media.cloudDisk'),
  1474. content: 'Jellyfin'
  1475. })
  1476. .onClick(async () => {
  1477. this.showRemoteDriveAccountDialog(false, undefined, RemoteDriveType.Jellyfin)
  1478. })
  1479. MenuItem({
  1480. startIcon: $r('app.media.baiduwp'),
  1481. content: '百度网盘'
  1482. })
  1483. .onClick(async () => {
  1484. this.showRemoteDriveAccountDialog(false, undefined, RemoteDriveType.Baidu)
  1485. })
  1486. }.attributeModifier(new MenuModifier())
  1487. }
  1488. @Builder
  1489. MenuBuilder(playlist: Playlist) {
  1490. Menu(){
  1491. MenuItem({
  1492. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
  1493. content: '编辑歌单'
  1494. })
  1495. .onClick(async() => {
  1496. this.openPlaylist(playlist)
  1497. })
  1498. MenuItem({
  1499. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
  1500. content: '删除歌单'
  1501. })
  1502. .onClick(async() => {
  1503. this.deletePlaylist(playlist)
  1504. })
  1505. }
  1506. }
  1507. @Builder
  1508. MenuDavBuilder(account: WebDavAccount) {
  1509. Menu(){
  1510. MenuItem({
  1511. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
  1512. content: '编辑'
  1513. })
  1514. .onClick(async() => {
  1515. this.showRemoteDriveAccountDialog(true,account)
  1516. })
  1517. MenuItem({
  1518. symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),
  1519. content: '删除'
  1520. })
  1521. .onClick(async() => {
  1522. this.deleteWebDavAccount(account)
  1523. })
  1524. }
  1525. }
  1526. /**
  1527. * 删除网盘账户
  1528. */
  1529. async deleteWebDavAccount(account: WebDavAccount) {
  1530. try {
  1531. // 显示确认对话框
  1532. this.getUIContext().showAlertDialog({
  1533. title: '删除账户',
  1534. message: `确定要删除webdav账户"${account.name}"吗?`,
  1535. primaryButton: {
  1536. value: '取消',
  1537. action: () => {}
  1538. },
  1539. secondaryButton: {
  1540. value: '删除',
  1541. fontColor: Color.Red,
  1542. action: async () => {
  1543. try {
  1544. await this.webdavManager.removeAccount(account)
  1545. ToastUtil.showToast('网盘账户删除成功')
  1546. // 重新加载网盘账户列表
  1547. await this.loadWebDavAccounts()
  1548. LogUtil.info('heanup NewIndex', '网盘账户删除成功:', account.name)
  1549. this.logAccount('info', `网盘账户删除成功: ${account.name}`)
  1550. } catch (error) {
  1551. LogUtil.error('heanup NewIndex', `删除网盘账户失败: ${(error as Error).message}`)
  1552. ToastUtil.showToast('删除失败')
  1553. this.logAccount('error', `删除网盘账户失败: ${(error as Error).message}`)
  1554. }
  1555. }
  1556. }
  1557. })
  1558. } catch (error) {
  1559. LogUtil.error('heanup NewIndex', `删除网盘账户操作失败: ${(error as Error).message}`)
  1560. ToastUtil.showToast('操作失败')
  1561. this.logAccount('error', `删除网盘账户操作失败: ${(error as Error).message}`)
  1562. }
  1563. }
  1564. /**
  1565. * 删除歌单
  1566. */
  1567. async deletePlaylist(playlist: Playlist) {
  1568. if (playlist&&this.playlistTable) {
  1569. // 显示确认对话框
  1570. AlertDialog.show({
  1571. title: '删除歌单',
  1572. message: `确定要删除歌单"${playlist.name}"吗?此操作不可撤销。`,
  1573. primaryButton: {
  1574. value: '取消',
  1575. action: () => {}
  1576. },
  1577. secondaryButton: {
  1578. value: '删除',
  1579. fontColor: Color.Red,
  1580. action: async () => {
  1581. if (this.playlistTable) {
  1582. const success = await this.playlistTable.deletePlaylist(playlist.id)
  1583. if (success) {
  1584. ToastUtil.showToast('歌单删除成功')
  1585. // 发送刷新事件
  1586. emitter.emit({ eventId: EventConstants.EVENT_PLAYLIST_REFRESH }, {})
  1587. } else {
  1588. ToastUtil.showToast('歌单删除失败')
  1589. }
  1590. }
  1591. }
  1592. }
  1593. })
  1594. }
  1595. }
  1596. /**
  1597. * 显示创建歌单对话框
  1598. */
  1599. showCreatePlaylistDialog() {
  1600. if (!this.playlistTable) {
  1601. ToastUtil.showToast('歌单功能初始化中,请稍后再试')
  1602. return
  1603. }
  1604. // 使用新的歌单对话框,支持自定义封面
  1605. showCreatePlaylistDialog(
  1606. async (name: string, description: string, coverPath?: string) => {
  1607. // 创建歌单
  1608. const success = await this.playlistTable!.createPlaylist(name, description, coverPath)
  1609. if (success) {
  1610. ToastUtil.showToast('歌单创建成功')
  1611. // 刷新歌单列表
  1612. await this.loadPlaylistList()
  1613. // 发送歌单刷新事件
  1614. emitter.emit({ eventId: EventConstants.EVENT_PLAYLIST_REFRESH }, {})
  1615. } else {
  1616. ToastUtil.showToast('歌单创建失败')
  1617. }
  1618. },
  1619. () => {
  1620. // 取消创建歌单
  1621. }
  1622. )
  1623. }
  1624. /**
  1625. * 打开歌单详情
  1626. */
  1627. openPlaylist(playlist: Playlist) {
  1628. try {
  1629. // 跳转到歌单详情页面
  1630. router.pushUrl({
  1631. url: 'pages/PlaylistDetailPage',
  1632. params: {
  1633. playlist: playlist
  1634. }
  1635. }).catch((err: Error) => {
  1636. console.error('跳转到歌单详情页面失败:', err.message);
  1637. ToastUtil.showToast('打开歌单失败');
  1638. });
  1639. } catch (error) {
  1640. console.error('打开歌单失败:', error);
  1641. ToastUtil.showToast('打开歌单失败');
  1642. }
  1643. }
  1644. /**
  1645. * 初始化歌单数据库
  1646. */
  1647. async initPlaylistTable() {
  1648. try {
  1649. this.playlistTable = new PlaylistTable(this.context)
  1650. console.info('onecold 歌单数据库初始化成功')
  1651. // 等待数据库初始化完成后再加载数据
  1652. setTimeout(async () => {
  1653. await this.loadPlaylistList()
  1654. }, 500) // 延迟500ms确保数据库初始化完成
  1655. } catch (error) {
  1656. console.error('初始化歌单数据库失败:', error)
  1657. }
  1658. }
  1659. /**
  1660. * 加载歌单列表
  1661. */
  1662. async loadPlaylistList() {
  1663. try {
  1664. LogUtil.info('heanup NewIndex', '开始加载歌单列表')
  1665. if (this.playlistTable) {
  1666. const playlists = await this.playlistTable.queryAllPlaylists()
  1667. // 强制触发UI更新
  1668. this.playlistList = playlists.slice()
  1669. LogUtil.info('heanup NewIndex', `成功加载 ${playlists.length} 个歌单`)
  1670. } else {
  1671. LogUtil.warn('heanup NewIndex', '歌单表未初始化')
  1672. }
  1673. this.isRefreshing = false
  1674. } catch (error) {
  1675. LogUtil.error('heanup NewIndex', `加载歌单列表失败: ${(error as Error).message}`)
  1676. this.isRefreshing = false
  1677. }
  1678. }
  1679. /**
  1680. * 初始化WebDAV管理器
  1681. */
  1682. private logAccount(level: 'info' | 'warn' | 'error', message: string) {
  1683. const tag = 'AccountCenter';
  1684. switch (level) {
  1685. case 'info':
  1686. void ServerLogUtil.info(tag, message);
  1687. break;
  1688. case 'warn':
  1689. void ServerLogUtil.warn(tag, message);
  1690. break;
  1691. case 'error':
  1692. void ServerLogUtil.error(tag, message);
  1693. break;
  1694. default:
  1695. break;
  1696. }
  1697. }
  1698. private logHiCar(level: 'info' | 'warn' | 'error', message: string) {
  1699. const tag = 'HiCarEntry';
  1700. switch (level) {
  1701. case 'info':
  1702. void ServerLogUtil.info(tag, message);
  1703. break;
  1704. case 'warn':
  1705. void ServerLogUtil.warn(tag, message);
  1706. break;
  1707. case 'error':
  1708. void ServerLogUtil.error(tag, message);
  1709. break;
  1710. default:
  1711. break;
  1712. }
  1713. }
  1714. async initWebDavManager() {
  1715. try {
  1716. // 设置WebDAV管理器的上下文
  1717. this.webdavManager.setContext(this.context)
  1718. // 创建网盘账户表
  1719. await this.webdavManager.createWebDavTableInDB()
  1720. // 订阅WebDAV管理器事件
  1721. this.webdavManager.subscribe((event: string) => {
  1722. LogUtil.info('heanup NewIndex', '收到WebDAV事件:', event)
  1723. this.logAccount('info', `收到WebDAV事件: ${event}`)
  1724. if (event === 'QueryAccountsSucceed') {
  1725. this.webDavAccounts = this.webdavManager.getAllWebDavAccounts().slice()
  1726. }
  1727. })
  1728. // 首页EntryAblility去加载网盘账户了。所以这边不加载
  1729. // await this.loadWebDavAccounts()
  1730. LogUtil.info('heanup NewIndex', 'WebDAV管理器初始化成功')
  1731. this.logAccount('info', 'WebDAV管理器初始化成功')
  1732. } catch (error) {
  1733. LogUtil.error('heanup NewIndex', `初始化WebDAV管理器失败: ${(error as Error).message}`)
  1734. this.logAccount('error', `初始化WebDAV管理器失败: ${(error as Error).message}`)
  1735. }
  1736. }
  1737. /**
  1738. * 加载网盘账户列表
  1739. */
  1740. async loadWebDavAccounts() {
  1741. try {
  1742. LogUtil.info('heanup NewIndex', '开始加载网盘账户列表')
  1743. this.logAccount('info', '开始加载网盘账户列表')
  1744. await this.webdavManager.queryWebDavAccountsFromDB()
  1745. // 强制触发UI更新
  1746. this.webDavAccounts = this.webdavManager.getAllWebDavAccounts().slice()
  1747. this.isRefreshing = false
  1748. LogUtil.info('heanup NewIndex', `成功加载 ${this.webDavAccounts.length} 个网盘账户`)
  1749. this.logAccount('info', `成功加载 ${this.webDavAccounts.length} 个网盘账户`)
  1750. } catch (error) {
  1751. this.isRefreshing = false
  1752. LogUtil.error('heanup NewIndex', `加载网盘账户列表失败: ${(error as Error).message}`)
  1753. this.logAccount('error', `加载网盘账户列表失败: ${(error as Error).message}`)
  1754. }
  1755. }
  1756. /**
  1757. * 选择网盘账户
  1758. */
  1759. selectWebDavAccount(account: WebDavAccount) {
  1760. try {
  1761. LogUtil.info('heanup NewIndex', '选择网盘账户:', account.name)
  1762. this.logAccount('info', `选择网盘账户: ${account.name} (id=${account.id ?? 'unknown'})`)
  1763. // 如果账户未激活,先激活它
  1764. if (!account.isActivate) {
  1765. // 先将所有账户设为未激活
  1766. this.webDavAccounts.forEach(acc => {
  1767. acc.isActivate = false
  1768. })
  1769. // 激活选中的账户
  1770. account.isActivate = true
  1771. // 更新数据库中的激活状态
  1772. this.webdavManager.editAccount(account).then(() => {
  1773. LogUtil.info('heanup NewIndex', '网盘账户编辑成功:', account.name)
  1774. this.logAccount('info', `网盘账户编辑成功: ${account.name}`)
  1775. }).catch((error: Error) => {
  1776. LogUtil.error('heanup NewIndex', `编辑网盘账户失败: ${error.message}`)
  1777. ToastUtil.showToast('编辑账户失败')
  1778. this.logAccount('error', `编辑网盘账户失败: ${error.message}`)
  1779. })
  1780. }
  1781. this.selectedAccount = account
  1782. console.info('onecold selectWebDavAccount account.webType='+account.webType)
  1783. // 切换到WebDAV页面
  1784. if(account.webType==RemoteDriveType.Navidrome){
  1785. this.mType = 7
  1786. }else{
  1787. this.mType = 6
  1788. }
  1789. this.doShowDrawer()
  1790. } catch (error) {
  1791. LogUtil.error('heanup NewIndex', `选择网盘账户失败: ${(error as Error).message}`)
  1792. ToastUtil.showToast('选择账户失败')
  1793. this.logAccount('error', `选择网盘账户失败: ${(error as Error).message}`)
  1794. }
  1795. }
  1796. /**
  1797. * 显示添加网盘账户对话框
  1798. */
  1799. @State addDavDialogId:number = 1
  1800. showRemoteDriveAccountDialog(isEditMode?: boolean,account?: WebDavAccount,driveType?:number) {
  1801. const node: FrameNode | null = this.getUIContext().getFrameNodeById("test_text") || null;
  1802. this.getUIContext().getPromptAction().openCustomDialog({
  1803. builder: () => {
  1804. this.webDavAccountBuilder(isEditMode,account,driveType)
  1805. },
  1806. levelMode: LevelMode.EMBEDDED, // 启用页面级弹出框
  1807. levelUniqueId: node?.getUniqueId(), // 设置页面级弹出框所在页面的任意节点ID
  1808. immersiveMode: ImmersiveMode.EXTEND, // 设置页面级弹出框蒙层的显示模式
  1809. }).then((dialogId: number) => {
  1810. this.addDavDialogId = dialogId;
  1811. })
  1812. }
  1813. @Builder
  1814. webDavAccountBuilder(isEditMode?: boolean,account?: WebDavAccount,driveType?:number) {
  1815. RemoteDriveAccountDialog({
  1816. isEditMode: isEditMode,
  1817. account: account,
  1818. initialDriveType: driveType,
  1819. onCancel: () => {
  1820. // 取消添加
  1821. this.getUIContext().getPromptAction().closeCustomDialog(this.addDavDialogId)
  1822. },
  1823. onConfirm: (account: WebDavAccount) => {
  1824. this.getUIContext().getPromptAction().closeCustomDialog(this.addDavDialogId)
  1825. if (isEditMode && account?.id) {
  1826. // 编辑模式:更新现有账户
  1827. this.webdavManager.editAccount(account).then(() => {
  1828. ToastUtil.showToast('修改成功')
  1829. // 重新加载网盘账户列表,观察着模式去更新了,所以这里不需要更新,先注释掉
  1830. // this.loadWebDavAccounts()
  1831. LogUtil.info('heanup NewIndex', '网盘账户修改成功:', account.name)
  1832. this.logAccount('info', `网盘账户修改成功: ${account.name}`)
  1833. }).catch((error: Error) => {
  1834. LogUtil.error('heanup NewIndex', `修改网盘账户失败: ${error.message}`)
  1835. ToastUtil.showToast('修改失败')
  1836. this.logAccount('error', `修改网盘账户失败: ${error.message}`)
  1837. })
  1838. } else {
  1839. // 添加模式:创建新账户
  1840. this.webdavManager.insertAccount(
  1841. account.name,
  1842. account.host,
  1843. account.localHost,
  1844. account.isUseLocalHost,
  1845. account.port,
  1846. account.filepath,
  1847. account.lyricFilePath,
  1848. account.uploadFilePath,
  1849. account.imageFilePath,
  1850. account.account,
  1851. account.password,
  1852. account.enableHttps,
  1853. account.coverPath,
  1854. account.webType,
  1855. account.smbShare,
  1856. account.smbDomain,
  1857. account.navidromeBasePath,
  1858. account.jellyfinBasePath,
  1859. account.ftpEncoding,
  1860. account.baiduAccessToken,
  1861. account.baiduRefreshToken,
  1862. account.baiduTokenExpiresAt
  1863. ).then(() => {
  1864. ToastUtil.showToast('添加成功')
  1865. // 重新加载网盘账户列表 观察着模式去更新了,所以这里不需要更新,先注释掉
  1866. // this.loadWebDavAccounts()
  1867. LogUtil.info('heanup NewIndex', '网盘账户添加成功:', account.name)
  1868. this.logAccount('info', `网盘账户添加成功: ${account.name}`)
  1869. }).catch((error: Error) => {
  1870. LogUtil.error('heanup NewIndex', `添加网盘账户失败: ${error.message}`)
  1871. ToastUtil.showToast('添加失败')
  1872. this.logAccount('error', `添加网盘账户失败: ${error.message}`)
  1873. })
  1874. }
  1875. }
  1876. });
  1877. }
  1878. }
  1879. // 1. 工具函数:将 #RRGGBB 字符串和透明度转为 'rgba(r,g,b,a)' 字符串,深色模式下可返回深色变体
  1880. function themeColorWithAlpha(themeColor: string, alpha: number, isDarkMode: boolean = false): string {
  1881. if (isDarkMode) {
  1882. // 深色模式下返回更深的灰色或半透明黑色
  1883. return `rgba(34,34,34,${alpha + 0.2 > 1 ? 1 : alpha + 0.2})`;
  1884. }
  1885. const color = themeColor.replace('#', '');
  1886. const r = parseInt(color.substring(0, 2), 16);
  1887. const g = parseInt(color.substring(2, 4), 16);
  1888. const b = parseInt(color.substring(4, 6), 16);
  1889. return `rgba(${r},${g},${b},${alpha})`;
  1890. }
  1891. // 定义接口
  1892. interface HiCarAspectRatio {
  1893. context: Context;
  1894. playlistId: string;
  1895. }