NewIndex.ets 73 KB

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