starmusic-mobile
1<script>
2import { initUserApi } from './common/user-api/api-executor.js'
3import { initApiSource } from './common/api-source.js'
4import { initList } from './common/playlist.js'
5import { initPlayer } from './common/player.js'
6import { initAutoBackup } from './common/account.js'
7import { checkUpdate, promptUpdate } from './common/update.js'
8import { fetchEasterEggs } from './common/easter-egg.js'
9import { isRemote } from './common/tv.js'
10import { createFocusEngine } from './common/tv-focus.js'
11import { applyTabBarTheme } from './common/theme.js'
12import event from './common/event.js'
13
14export default {
15 onLaunch() {
16 // 初始化数据列表
17 initList()
18 // 初始化自定义源引擎
19 initUserApi()
20 // 恢复上次音源
21 initApiSource()
22 // 初始化播放器
23 initPlayer()
24 // 初始化自动备份(开启且已登录时,歌单/音源变化后自动上传云端)
25 initAutoBackup()
26 // 同步原生 tabBar 主题(页面内的主题变量由 theme-mixin 注入)
27 applyTabBarTheme()
28 // 主题切换时同步 tabBar
29 event.on('settingUpdated', (keys) => {
30 if (!keys || keys.indexOf('common.theme') >= 0) applyTabBarTheme()
31 })
32 console.log('starmusic launched')
33
34 // 拉取彩蛋配置(静默;失败自动回退上次缓存,不影响正常使用)
35 fetchEasterEggs()
36
37 // 在线更新检查:每次启动检查一次。
38 // 延迟到初始化与启动页(2.6s)展示结束后再执行,避免抢占启动资源;
39 // 检查失败静默处理,不影响正常使用。
40 setTimeout(() => {
41 checkUpdate().then((info) => {
42 if (info) promptUpdate(info)
43 })
44 }, 3000)
45
46 // 电视/车机(H5 端):挂载遥控器焦点导航引擎。
47 // 仅在遥控设备生效;延迟到页面首帧渲染后,确保能采集到 data-navid 节点。
48 // App 端逻辑层无 DOM(document 为 undefined),引擎自动不工作,
49 // 由各页面 renderjs 在视图层接管(见 pages/*.vue)。
50 if (isRemote() && typeof document !== 'undefined') {
51 // 先同步占位再延迟挂载:标记必须是同步的,否则在 800ms 窗口内打开的页面
52 // (如直接以子页 URL 访问)会让 tv-nav 的 renderjs 也挂一个引擎,两个引擎抢按键
53 if (!window.__tvFocusEngine) window.__tvFocusEngine = {}
54 setTimeout(() => {
55 window.__tvFocusEngine = createFocusEngine({ doc: document })
56 }, 800)
57 }
58 },
59 onShow() {
60 console.log('starmusic show')
61 },
62}
63</script>
64
65<style lang="scss">
66/* 全局样式 */
67page {
68 background-color: $bg-color;
69 color: $text-color;
70 font-size: 28rpx;
71 /* 主题色默认变量(兜底):页面根元素由 theme-mixin 注入当前主题,未注入时回退默认主色 */
72 --theme-color: #31c27c;
73 --theme-color-rgb: 49, 194, 124;
74 --theme-color-dark: #1ba56a;
75 --theme-color-soft: #e8f8f0;
76}
77
78/*
79 * 页面根容器:建立独立层叠上下文。
80 * .bg-image 用 z-index: -1 绘制背景图,若根容器不是层叠上下文,
81 * 负 z-index 子元素会逃逸到更外层并被页面自身背景色遮挡(表现为"设置了背景图却不显示")。
82 * isolation 不改变布局与定位参照,只创建层叠上下文。
83 */
84.page,
85.play-detail,
86.splash {
87 isolation: isolate;
88}
89
90/*
91 * 自定义背景图层(除播放详情页外的页面使用)
92 * z-index: -1 使其绘制在页面背景色之上、页面内容之下,无需改动各页面的层叠关系
93 */
94.bg-image {
95 position: fixed;
96 top: 0;
97 right: 0;
98 bottom: 0;
99 left: 0;
100 z-index: -1;
101 background-size: cover;
102 background-position: center;
103 background-repeat: no-repeat;
104 /* 轻微放大,避免 blur 后边缘透出底色 */
105 transform: scale(1.08);
106 pointer-events: none;
107}
108
109/*
110 * 输入框提示文字:开启背景图时随 --text-muted 加深,
111 * 未注入变量时回退到接近原生默认的灰色(不影响默认外观)
112 */
113input::placeholder,
114textarea::placeholder {
115 color: var(--text-muted, #999);
116}
117
118/*
119 * 手机横屏:修正 rem 基准 + 内容居中限宽
120 *
121 * 原理:uni-app 把 rpx 编译为 rem(32rpx = 1rem),并在运行时按窗口宽度设置 html 字号
122 * (宽度 ≤ 960 时直接用宽度,超过则固定 375 基准)。手机横屏后窗口宽度接近翻倍,
123 * 于是所有 rpx 尺寸被整体放大近 2 倍,看起来就像"竖屏页面被拉伸"。
124 * 这里在横屏时改用视口短边(≈ 竖屏时的宽度)重算字号,让 rpx 元素恢复竖屏大小;
125 * 同时限制内容宽度并居中(横向空间充裕而高度有限,避免内容被拉成通栏)。
126 * 注:播放页自带横屏分栏布局且不使用 .page,不受限宽规则影响。
127 */
128@media (orientation: landscape) and (max-width: 959px) {
129 html {
130 /* 100vmin = 视口短边;横屏时即屏幕高度,等价于竖屏时的宽度,除以 23.4375 得到原基准值 */
131 font-size: calc(100vmin / 23.4375) !important;
132 }
133
134 .page {
135 max-width: 640px !important;
136 margin: 0 auto !important;
137 }
138}
139
140/* ============ 全局通用动效(供所有页面复用) ============ */
141
142/* 按压反馈:可点击元素按压缩放,跟手 */
143.d-press {
144 transition: transform $duration-fast $ease-out;
145}
146.d-press:active {
147 transform: scale(0.96);
148}
149
150/* 轻量按压:更轻微的反馈(如 tab、chip) */
151.d-press-sm {
152 transition: transform $duration-fast $ease-out;
153}
154.d-press-sm:active {
155 transform: scale(0.97);
156}
157
158/* 列表项渐入上移(配合 style="--delay: xxms" 使用) */
159.d-fade-up {
160 animation: dFadeUp 0.4s $ease-out both;
161 animation-delay: var(--delay, 0ms);
162}
163@keyframes dFadeUp {
164 from {
165 opacity: 0;
166 transform: translateY(24rpx);
167 }
168 to {
169 opacity: 1;
170 transform: translateY(0);
171 }
172}
173
174/* 淡入 */
175.d-fade-in {
176 animation: dFadeIn 0.3s ease both;
177}
178@keyframes dFadeIn {
179 from {
180 opacity: 0;
181 }
182 to {
183 opacity: 1;
184 }
185}
186
187/* 遮罩渐显 */
188.d-mask-in {
189 animation: dMaskIn 0.25s ease both;
190}
191@keyframes dMaskIn {
192 from {
193 opacity: 0;
194 }
195 to {
196 opacity: 1;
197 }
198}
199
200/* 底部弹层滑入(translateY 100% → 0) */
201.d-slide-up {
202 animation: dSlideUp 0.3s $ease-out both;
203}
204@keyframes dSlideUp {
205 from {
206 transform: translateY(100%);
207 }
208 to {
209 transform: translateY(0);
210 }
211}
212
213/* 弹层缩放淡入(居中弹窗用) */
214.d-pop-in {
215 animation: dPopIn 0.28s $ease-spring both;
216}
217@keyframes dPopIn {
218 from {
219 opacity: 0;
220 transform: scale(0.86);
221 }
222 to {
223 opacity: 1;
224 transform: scale(1);
225 }
226}
227
228/* 按钮点击弹性回弹(播放键等主按钮) */
229.d-bounce {
230 animation: dBounce 0.35s $ease-spring both;
231}
232@keyframes dBounce {
233 0% {
234 transform: scale(1);
235 }
236 40% {
237 transform: scale(0.88);
238 }
239 100% {
240 transform: scale(1);
241 }
242}
243
244/* 尊重系统减弱动效设置 */
245@media (prefers-reduced-motion: reduce) {
246 .d-fade-up,
247 .d-slide-up,
248 .d-pop-in,
249 .d-bounce,
250 .d-fade-in,
251 .d-mask-in {
252 animation: none !important;
253 transition: none !important;
254 }
255}
256
257/* ============ 电视 / 车机遥控端自适应(仅在对应设备根容器挂上 tv-ui 时生效) ============ */
258
259/* 遥控设备页面整体:overscan / 屏幕边缘安全区 */
260.tv-ui {
261 padding: 3vh 4vw;
262 box-sizing: border-box;
263}
264
265/* 遥控可聚焦项的最小命中高度(方便遥控器定位) */
266.tv-ui .tv-item {
267 min-height: 54px;
268}
269
270/* 遥控焦点框(由焦点引擎注入 body,position:fixed) */
271.tv-focus-ring {
272 border: 3px solid $primary-color;
273 border-radius: 12px;
274 box-shadow:
275 0 0 0 4px rgba(var(--theme-color-rgb, 49, 194, 124), 0.30),
276 0 0 22px rgba(var(--theme-color-rgb, 49, 194, 124), 0.70);
277}
278
279/* 当前聚焦项的高亮底(配合引擎 .tv-focused) */
280.tv-ui .tv-focused {
281 background-color: rgba(var(--theme-color-rgb, 49, 194, 124), 0.12) !important;
282}
283
284/* 车机竖屏时限制主体最大宽度,避免排版被拉得过宽 */
285.car-ui .tv-ui-inner {
286 max-width: 720px;
287 margin: 0 auto;
288}
289
290@media (prefers-reduced-motion: reduce) {
291 .tv-focus-ring {
292 transition: none !important;
293 }
294}
295</style>