NewIndex.ets 78 KB

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