仰望星辰工作室

starmusic-mobile

starmusic-mobile/ pages/setting/setting.vue 35.2 KB · 1,270 行 原始文件
1<template>
2 <view :class="['page', tvCls]" :style="themeStyle">
3 <!-- 自定义背景图(绘制在页面内容之下) -->
4 <view v-if="bgStyle" class="bg-image" :style="bgStyle" />
5 <tv-nav />
6 <scroll-view scroll-y class="setting-scroll">
7 <!-- 账号卡片 -->
8 <view class="account-card d-press" @click="goAccount">
9 <view class="account-left">
10 <view class="account-avatar">
11 <text>{{ avatarChar }}</text>
12 </view>
13 <view class="account-info">
14 <text class="account-name">{{ accountName || '未登录' }}</text>
15 <text class="account-desc">{{ accountDesc }}</text>
16 </view>
17 </view>
18 <view class="account-right">
19 <view v-if="accountName && accountInfo.has_backup" class="account-badge">
20 <lx-icon name="check" :size="24" color="#ffffff" />
21 </view>
22 <lx-icon name="arrow" :size="32" color="rgba(255, 255, 255, 0.7)" />
23 </view>
24 </view>
25
26 <!-- 音源设置 -->
27 <view class="section">
28 <view class="section-title">音源</view>
29 <view class="section-body">
30 <view class="setting-item d-press" @click="handleShowSourceList">
31 <text class="item-label">当前音源</text>
32 <text class="item-value">{{ currentSourceName }}</text>
33 <lx-icon name="arrow" :size="32" color="#c0c4cc" />
34 </view>
35 <view class="setting-item">
36 <text class="item-label">多音源兜底</text>
37 <switch :checked="fallbackEnabled" :color="themeColor" @change="handleFallbackToggle" />
38 </view>
39 <view v-if="fallbackEnabled" class="setting-item">
40 <text class="item-label">备用音源</text>
41 <view class="mode-picker">
42 <text
43 v-for="s in sourceOptions"
44 :key="s.id"
45 class="mode-chip d-press-sm"
46 :class="{ active: fallbackSources.includes(s.id) }"
47 @click="handleToggleFallbackSource(s.id)"
48 >
49 {{ s.name }}
50 </text>
51 </view>
52 </view>
53 <view class="setting-item d-press" @click="showImport = true">
54 <text class="item-label">导入自定义音源</text>
55 <lx-icon name="arrow" :size="32" color="#c0c4cc" />
56 </view>
57 </view>
58 </view>
59
60 <!-- 播放设置 -->
61 <view class="section">
62 <view class="section-title">播放</view>
63 <view class="section-body">
64 <view class="setting-item">
65 <text class="item-label">播放模式</text>
66 <view class="mode-picker">
67 <text
68 v-for="mode in playModes"
69 :key="mode.id"
70 class="mode-chip d-press-sm"
71 :class="{ active: playMethod === mode.id }"
72 @click="handleModeChange(mode.id)"
73 >
74 {{ mode.name }}
75 </text>
76 </view>
77 </view>
78 <view class="setting-item">
79 <text class="item-label">播放音质</text>
80 <view class="mode-picker">
81 <text
82 v-for="q in qualitys"
83 :key="q.id"
84 class="mode-chip d-press-sm"
85 :class="{ active: playQuality === q.id }"
86 @click="handleQualityChange(q.id)"
87 >
88 {{ q.name }}
89 </text>
90 </view>
91 </view>
92 </view>
93 </view>
94
95 <!-- 外观设置 -->
96 <view class="section">
97 <view class="section-title">外观</view>
98 <view class="section-body">
99 <view class="setting-item theme-item">
100 <text class="item-label">主题色</text>
101 <view class="theme-picker">
102 <view
103 v-for="t in themes"
104 :key="t.id"
105 class="theme-chip d-press-sm"
106 :class="{ active: themeId === t.id }"
107 :style="{ background: t.color }"
108 :data-navid="'theme-' + t.id"
109 @click="handleThemeChange(t.id)"
110 >
111 <lx-icon v-if="themeId === t.id" name="check" :size="30" color="#ffffff" />
112 </view>
113 </view>
114 </view>
115 <!-- 背景图片 -->
116 <view class="setting-item">
117 <text class="item-label">背景图片</text>
118 <switch :checked="bgEnabled" :color="themeColor" @change="handleBgToggle" />
119 </view>
120 <view v-if="bgEnabled" class="setting-item d-press" @click="handleChooseBg">
121 <text class="item-label">选择背景图</text>
122 <text class="item-value">{{ bgImage ? '已设置,点击更换' : '未设置' }}</text>
123 <lx-icon name="arrow" :size="32" color="#c0c4cc" />
124 </view>
125 <view v-if="bgEnabled" class="setting-item">
126 <text class="item-label">模糊程度</text>
127 <slider
128 class="bg-blur-slider"
129 :value="bgBlur"
130 min="0"
131 max="30"
132 step="1"
133 :activeColor="themeColor"
134 :block-color="themeColor"
135 :block-size="16"
136 @changing="handleBgBlurChanging"
137 @change="handleBgBlurChange"
138 />
139 <text class="bg-blur-value">{{ bgBlur }}</text>
140 </view>
141 <view v-if="bgEnabled && bgImage" class="setting-item d-press" @click="handleRemoveBg">
142 <text class="item-label danger">移除背景图</text>
143 <lx-icon name="arrow" :size="32" color="#c0c4cc" />
144 </view>
145 </view>
146 </view>
147
148 <!-- 自定义源列表 -->
149 <view v-if="userApiList.length" class="section">
150 <view class="section-title">已导入的自定义源({{ userApiList.length }}/20)</view>
151 <view class="section-body">
152 <view v-for="api in userApiList" :key="api.id" class="user-api-item">
153 <view class="api-main">
154 <view class="api-name-row">
155 <text class="api-name">{{ api.name }}</text>
156 <text v-if="api.version" class="api-version">v{{ api.version }}</text>
157 <view class="api-status" :class="'status-' + (apiStatusMap[api.id] || 'initing')">
158 <lx-icon
159 :name="apiStatusMap[api.id] === 'success' ? 'check' : apiStatusMap[api.id] === 'failed' ? 'cross' : 'more'"
160 :size="26"
161 :color="statusColor(apiStatusMap[api.id])"
162 />
163 <text>{{ statusText(apiStatusMap[api.id]) }}</text>
164 </view>
165 </view>
166 <text v-if="api.author" class="api-author">{{ api.author }}</text>
167 <text v-if="api.description" class="api-desc">{{ api.description }}</text>
168 </view>
169 <view class="api-actions">
170 <text class="api-action d-press-sm" @click="handleUseSource(api.id)">启用</text>
171 <text class="api-action danger d-press-sm" @click="handleRemoveSource(api)">删除</text>
172 </view>
173 </view>
174 </view>
175 </view>
176
177 <!-- 诊断 -->
178 <view class="section">
179 <view class="section-title">诊断</view>
180 <view class="section-body">
181 <view class="setting-item d-press" @click="handleShowLogs">
182 <text class="item-label">自定义源运行日志</text>
183 <text class="item-value">{{ logCount ? logCount + ' 条' : '暂无' }}</text>
184 <lx-icon name="arrow" :size="32" color="#c0c4cc" />
185 </view>
186 <view class="setting-item column">
187 <text class="item-desc">记录脚本 lx.log 输出、播放地址 / 歌词 / 封面的请求结果,以及脚本内部的网络请求,用于排查自定义源问题。仅保留本次运行(最多 400 条)</text>
188 </view>
189 </view>
190 </view>
191
192 <!-- 关于 -->
193 <view class="section">
194 <view class="section-title">关于</view>
195 <view class="section-body">
196 <view class="setting-item">
197 <text class="item-label">版本</text>
198 <text class="item-value">{{ appVersion }}</text>
199 </view>
200 <view class="setting-item d-press" @click="handleCheckUpdate">
201 <text class="item-label">检查更新</text>
202 <text class="item-value">在线检查新版本</text>
203 <lx-icon name="arrow" :size="32" color="#c0c4cc" />
204 </view>
205 <view class="setting-item d-press" @click="goAbout">
206 <text class="item-label">说明</text>
207 <text class="item-value">关于 starmusic</text>
208 <lx-icon name="arrow" :size="32" color="#c0c4cc" />
209 </view>
210 <view class="setting-item d-press" @click="handleShowSponsor">
211 <text class="item-label">赞助项目</text>
212 <lx-icon name="arrow" :size="32" color="#c0c4cc" />
213 </view>
214 </view>
215 </view>
216 </scroll-view>
217
218 <!-- 底部导航(液态玻璃,自绘替代原生 tabBar) -->
219 <app-tab-bar />
220
221 <!-- 自定义源运行日志弹层 -->
222 <view v-if="showLogs" class="mask d-mask-in" @click="showLogs = false">
223 <view class="log-modal d-pop-in" data-nav-scope @click.stop>
224 <view class="modal-header">
225 <text class="modal-title">自定义源运行日志</text>
226 <view class="modal-close d-press" @click="showLogs = false">
227 <lx-icon name="close" :size="32" color="#909399" />
228 </view>
229 </view>
230 <scroll-view scroll-y class="log-scroll">
231 <view v-if="!logList.length" class="log-empty">暂无日志</view>
232 <view v-for="item in logList" :key="item.id" class="log-item">
233 <view class="log-head">
234 <text class="log-time">{{ item.time }}</text>
235 <text class="log-type" :class="'type-' + item.type">{{ logTypeText(item.type) }}</text>
236 </view>
237 <text class="log-text">{{ item.message }}</text>
238 <text v-if="item.detail" class="log-detail">{{ item.detail }}</text>
239 </view>
240 </scroll-view>
241 <view class="log-actions">
242 <text class="api-action d-press-sm" @click="handleCopyLogs">复制全部</text>
243 <text class="api-action danger d-press-sm" @click="handleClearLogs">清空</text>
244 </view>
245 </view>
246 </view>
247
248 <!-- 赞助弹窗 -->
249 <view v-if="showSponsor" class="mask d-mask-in" @click="showSponsor = false">
250 <view class="sponsor-modal d-pop-in" data-nav-scope @click.stop>
251 <view class="modal-header">
252 <text class="modal-title">赞助项目</text>
253 <view class="modal-close d-press" @click="showSponsor = false">
254 <lx-icon name="close" :size="32" color="#909399" />
255 </view>
256 </view>
257 <scroll-view scroll-y class="sponsor-body">
258 <image
259 class="sponsor-image"
260 :src="sponsorImageUrl"
261 mode="widthFix"
262 show-menu-by-longpress
263 />
264 </scroll-view>
265 </view>
266 </view>
267
268 <!-- 自定义源导入弹层 -->
269 <custom-source-import v-if="showImport" @close="showImport = false" @imported="handleImported" />
270
271 <!-- 音源选择弹层 -->
272 <view v-if="showSourceList" class="mask d-mask-in" @click="showSourceList = false">
273 <view class="source-modal d-pop-in" data-nav-scope @click.stop>
274 <view class="modal-header">
275 <text class="modal-title">选择音源</text>
276 <view class="modal-close" data-navid="source-close" @click="showSourceList = false">
277 <lx-icon name="close" :size="32" color="#909399" />
278 </view>
279 </view>
280 <scroll-view scroll-y class="modal-body">
281 <view
282 v-for="source in allSources"
283 :key="source.id"
284 class="source-item d-press"
285 :class="{ active: apiSource === source.id }"
286 @click="handleSelectSource(source.id)"
287 >
288 <text class="source-name">{{ source.name }}</text>
289 <text v-if="source.isUserApi" class="source-tag">自定义</text>
290 <lx-icon v-if="apiSource === source.id" name="check" :size="32" color="theme" />
291 </view>
292 <view v-if="!allSources.length" class="modal-empty">暂无可用音源,请先导入自定义源</view>
293 </scroll-view>
294 </view>
295 </view>
296 </view>
297</template>
298
299<script>
300import CustomSourceImport from '../../components/custom-source-import.vue'
301import LxIcon from '../../components/lx-icon/lx-icon.vue'
302import * as dataApi from '../../common/data.js'
303import { getSetting, updateSetting } from '../../common/setting.js'
304import { setApiSource } from '../../common/api-source.js'
305import event from '../../common/event.js'
306import { PLAY_MODE, PLAY_MODE_LIST, SOURCES } from '../../common/constants.js'
307import { setPlayMethod } from '../../common/player.js'
308import { checkUpdateDetail, promptUpdate, getAppVersion } from '../../common/update.js'
309import { getLocalAccount } from '../../common/account.js'
310import { deviceClass } from '../../common/tv.js'
311import { THEMES, setTheme, getThemeId } from '../../common/theme.js'
312import { chooseBgImage, clearBgImage, getBgImage } from '../../common/background.js'
313import AppTabBar from '../../components/app-tab-bar.vue'
314import { getLogs, getLogCount, clearLogs as clearSourceLogs, onLogChange, formatLogsForCopy } from '../../common/user-api/logger.js'
315
316export default {
317 components: { CustomSourceImport, AppTabBar, LxIcon },
318 data() {
319 return {
320 showImport: false,
321 showSourceList: false,
322 showSponsor: false,
323 sponsorImageUrl: 'https://clearlove.kazx.top/%E6%8D%90%E8%B5%A0.webp',
324 apiSource: '',
325 apiSourceName: '',
326 // 多音源兜底:备用源 id 列表(非空即开启,顺序即尝试优先级)
327 fallbackSources: [],
328 sourceOptions: SOURCES.map((s) => ({ id: s.id, name: s.name })),
329 userApiList: [],
330 apiStatusMap: {},
331 playModes: PLAY_MODE_LIST.map((id) => ({ id, name: PLAY_MODE[id] })),
332 playMethod: 'listLoop',
333 qualitys: [
334 { id: '128k', name: '标准' },
335 { id: '320k', name: '高品质' },
336 { id: 'flac', name: '无损' },
337 { id: 'flac24bit', name: 'Hi-Res' },
338 ],
339 playQuality: '128k',
340 // 主题色(预设见 common/theme.js)
341 themes: THEMES,
342 themeId: 'green',
343 // 背景图片
344 bgEnabled: false,
345 bgImage: '',
346 bgBlur: 12,
347 // 自定义源运行日志
348 showLogs: false,
349 logList: [],
350 logCount: 0,
351 // 版本号在 onLoad 中由 getAppVersion() 赋值,这里仅作占位
352 appVersion: '',
353 accountName: '',
354 accountInfo: {},
355 // 遥控设备端 UI 类名
356 tvCls: '',
357 }
358 },
359 computed: {
360 /** 账号头像字符(未登录显示 +) */
361 avatarChar() {
362 return this.accountName ? this.accountName.slice(0, 1).toUpperCase() : '+'
363 },
364 /** 账号卡片副标题 */
365 accountDesc() {
366 if (!this.accountName) return '登录后可同步歌单与音源到云端'
367 if (!this.accountInfo.has_backup) return '云端暂无备份,去备份一下'
368 const relative = this.formatRelativeTime(this.accountInfo.sync_time)
369 return relative ? `上次备份:${relative}` : '已开启云同步'
370 },
371 allSources() {
372 const sources = [{ id: '', name: '内置搜索源(播放需自定义源)' }]
373 for (const api of this.userApiList) {
374 sources.push({ id: api.id, name: api.name, isUserApi: true })
375 }
376 return sources
377 },
378 currentSourceName() {
379 if (this.apiSource) {
380 const api = this.userApiList.find((a) => a.id === this.apiSource)
381 if (api) return api.name
382 return '未知源'
383 }
384 return '内置源'
385 },
386 /** 多音源兜底是否开启(列表非空即开启) */
387 fallbackEnabled() {
388 return this.fallbackSources.length > 0
389 },
390 },
391 onLoad() {
392 this.tvCls = deviceClass()
393 this.appVersion = getAppVersion()
394 this.loadSetting()
395 this.loadUserApiList()
396 this.bindEvents()
397 },
398 onShow() {
399 this.loadUserApiList()
400 this.refreshAccountName()
401 },
402 onUnload() {
403 this.unbindEvents()
404 if (this._offLog) {
405 this._offLog()
406 this._offLog = null
407 }
408 if (this._logTimer) {
409 clearTimeout(this._logTimer)
410 this._logTimer = null
411 }
412 },
413 onBackPress() {
414 // 遥控/实体返回键:优先关闭弹层,而不是直接退出设置页
415 if (this.showLogs) {
416 this.showLogs = false
417 return true
418 }
419 if (this.showImport) {
420 this.showImport = false
421 return true
422 }
423 if (this.showSourceList) {
424 this.showSourceList = false
425 return true
426 }
427 if (this.showSponsor) {
428 this.showSponsor = false
429 return true
430 }
431 return false
432 },
433 methods: {
434 /** 打开「关于」页(品牌信息 + 星辰彩蛋小游戏) */
435 goAbout() {
436 uni.navigateTo({ url: '/pages/about/about' })
437 },
438 loadSetting() {
439 const setting = getSetting()
440 this.apiSource = setting['common.apiSource'] || ''
441 this.fallbackSources = setting['common.fallbackSources'] || []
442 this.playMethod = setting['player.togglePlayMethod'] || 'listLoop'
443 this.playQuality = setting['player.playQuality'] || '128k'
444 this.themeId = getThemeId()
445 this.bgEnabled = !!setting['common.bgImageEnabled']
446 this.bgBlur = Number(setting['common.bgImageBlur']) || 0
447 this.bgImage = getBgImage()
448 this.logCount = getLogCount()
449 },
450 loadUserApiList() {
451 this.userApiList = dataApi.getUserApiList()
452 this.apiStatusMap = {}
453 // 当前启用的源标记状态
454 const setting = getSetting()
455 if (setting['common.apiSource'] && /^user_api/.test(setting['common.apiSource'])) {
456 this.apiStatusMap[setting['common.apiSource']] = 'success'
457 }
458 },
459 bindEvents() {
460 const eventBus = event
461 this._offStatus = eventBus.on('userApiStatusChanged', (data) => {
462 if (data.id) {
463 this.apiStatusMap = { ...this.apiStatusMap, [data.id]: data.status }
464 }
465 })
466 this._offList = eventBus.on('userApiListChanged', (list) => {
467 this.userApiList = list
468 })
469 this._offAccount = eventBus.on('accountChanged', () => this.refreshAccountName())
470 },
471 unbindEvents() {
472 if (this._offStatus) this._offStatus()
473 if (this._offList) this._offList()
474 if (this._offAccount) this._offAccount()
475 },
476 refreshAccountName() {
477 const account = getLocalAccount()
478 this.accountInfo = account || {}
479 this.accountName = (account && account.username) || ''
480 },
481 /** 相对时间(用于展示上次备份) */
482 formatRelativeTime(ts) {
483 if (!ts) return ''
484 const diff = Math.floor(Date.now() / 1000) - ts
485 if (diff < 60) return '刚刚'
486 if (diff < 3600) return `${Math.floor(diff / 60)} 分钟前`
487 if (diff < 86400) return `${Math.floor(diff / 3600)} 小时前`
488 if (diff < 172800) return '昨天'
489 if (diff < 2592000) return `${Math.floor(diff / 86400)} 天前`
490 const d = new Date(ts * 1000)
491 return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`
492 },
493 goAccount() {
494 uni.navigateTo({ url: '/pages/account/account' })
495 },
496 statusText(status) {
497 switch (status) {
498 case 'success':
499 return '可用'
500 case 'initing':
501 return '加载中'
502 case 'failed':
503 return '失败'
504 default:
505 return '未知'
506 }
507 },
508 statusColor(status) {
509 switch (status) {
510 case 'success':
511 return '#67c23a'
512 case 'initing':
513 return '#909399'
514 case 'failed':
515 return '#f56c6c'
516 default:
517 return '#909399'
518 }
519 },
520 handleShowSourceList() {
521 this.showSourceList = true
522 },
523 handleShowSponsor() {
524 this.showSponsor = true
525 },
526 handleSelectSource(id) {
527 setApiSource(id)
528 this.apiSource = id
529 this.showSourceList = false
530 this.loadUserApiList()
531 },
532 /** 多音源兜底开关:开启时默认全部内置平台作为备用源 */
533 handleFallbackToggle(e) {
534 const on = e && e.detail ? e.detail.value : false
535 this.fallbackSources = on ? this.sourceOptions.map((s) => s.id) : []
536 updateSetting({ 'common.fallbackSources': [...this.fallbackSources] })
537 uni.showToast({ title: on ? '已开启多音源兜底' : '已关闭多音源兜底', icon: 'none' })
538 },
539 /** 增删备用源(数组顺序即尝试优先级) */
540 handleToggleFallbackSource(id) {
541 this.fallbackSources = this.fallbackSources.includes(id)
542 ? this.fallbackSources.filter((s) => s !== id)
543 : [...this.fallbackSources, id]
544 updateSetting({ 'common.fallbackSources': [...this.fallbackSources] })
545 },
546 handleUseSource(id) {
547 setApiSource(id)
548 this.apiSource = id
549 this.loadUserApiList()
550 },
551 handleImported(info) {
552 this.loadUserApiList()
553 // 导入成功后自动启用该源
554 if (info && info.id) {
555 uni.showModal({
556 title: '导入成功',
557 content: `已导入「${info.name}」,是否立即启用?`,
558 confirmText: '启用',
559 cancelText: '稍后',
560 success: (res) => {
561 if (res.confirm) this.handleUseSource(info.id)
562 },
563 })
564 }
565 },
566 handleRemoveSource(api) {
567 uni.showModal({
568 title: '删除自定义源',
569 content: `确定删除「${api.name}」?`,
570 success: (res) => {
571 if (!res.confirm) return
572 dataApi.removeUserApi([api.id])
573 const setting = getSetting()
574 if (setting['common.apiSource'] === api.id) {
575 // 回退内置源
576 setApiSource('')
577 }
578 this.loadUserApiList()
579 },
580 })
581 },
582 handleModeChange(mode) {
583 setPlayMethod(mode)
584 this.playMethod = mode
585 },
586 /** 手动检查更新:有更新弹更新提示,已最新则展示当前版本更新日志 */
587 handleCheckUpdate() {
588 uni.showLoading({ title: '检查更新中...', mask: true })
589 checkUpdateDetail().then(({ update, info }) => {
590 uni.hideLoading()
591 if (update) {
592 promptUpdate(info)
593 return
594 }
595 if (info && info.log) {
596 // 已是最新版本:展示当前版本的更新日志
597 uni.showModal({
598 title: `当前版本 v${info.version || getAppVersion()}`,
599 content: info.log,
600 showCancel: false,
601 confirmText: '知道了',
602 })
603 } else {
604 uni.showToast({ title: '已是最新版本', icon: 'none' })
605 }
606 })
607 },
608 handleQualityChange(quality) {
609 updateSetting({ 'player.playQuality': quality })
610 this.playQuality = quality
611 },
612 /** 切换主题色(写设置并广播,页面样式即时生效) */
613 handleThemeChange(id) {
614 if (this.themeId === id) return
615 const theme = setTheme(id)
616 this.themeId = theme.id
617 uni.showToast({ title: `已切换为${theme.name}`, icon: 'none' })
618 },
619 // ============ 背景图片 ============
620 /** 开关背景图;开启且尚未选图时直接引导选图 */
621 handleBgToggle(e) {
622 const enabled = !!(e && e.detail && e.detail.value)
623 this.bgEnabled = enabled
624 updateSetting({ 'common.bgImageEnabled': enabled })
625 if (enabled && !this.bgImage) this.handleChooseBg()
626 },
627 /** 选择背景图(选择后自动开启) */
628 handleChooseBg() {
629 chooseBgImage()
630 .then((path) => {
631 this.bgImage = path
632 if (!this.bgEnabled) {
633 this.bgEnabled = true
634 updateSetting({ 'common.bgImageEnabled': true })
635 }
636 uni.showToast({ title: '背景图已设置', icon: 'none' })
637 })
638 .catch((err) => {
639 const msg = err && err.message
640 // 用户主动取消选择时不提示
641 if (msg && !/cancel/i.test(msg)) uni.showToast({ title: msg, icon: 'none' })
642 })
643 },
644 /** 拖动中实时预览模糊效果(不落盘) */
645 handleBgBlurChanging(e) {
646 const value = e.detail.value
647 this.bgBlur = value
648 if (this.bgStyle) this.bgStyle = { ...this.bgStyle, filter: `blur(${value}px)` }
649 },
650 /** 松手后写入设置(所有页面同步) */
651 handleBgBlurChange(e) {
652 const value = e.detail.value
653 this.bgBlur = value
654 updateSetting({ 'common.bgImageBlur': value })
655 },
656 /** 移除背景图 */
657 handleRemoveBg() {
658 clearBgImage()
659 this.bgImage = ''
660 uni.showToast({ title: '已移除背景图', icon: 'none' })
661 },
662 // ============ 自定义源运行日志 ============
663 /** 打开日志弹层 */
664 handleShowLogs() {
665 this.refreshLogs()
666 this.showLogs = true
667 },
668 /** 刷新日志列表与条数 */
669 refreshLogs() {
670 this.logList = getLogs()
671 this.logCount = getLogCount()
672 },
673 /** 日志更新节流刷新:播放时多个请求同时写入,避免频繁重渲染 */
674 scheduleLogRefresh() {
675 if (this._logTimer) return
676 this._logTimer = setTimeout(() => {
677 this._logTimer = null
678 if (this.showLogs) this.refreshLogs()
679 else this.logCount = getLogCount()
680 }, 300)
681 },
682 handleClearLogs() {
683 clearSourceLogs()
684 this.refreshLogs()
685 uni.showToast({ title: '日志已清空', icon: 'none' })
686 },
687 handleCopyLogs() {
688 if (!this.logCount) {
689 uni.showToast({ title: '暂无日志', icon: 'none' })
690 return
691 }
692 uni.setClipboardData({
693 data: formatLogsForCopy(),
694 success: () => uni.showToast({ title: '日志已复制', icon: 'none' }),
695 })
696 },
697 /** 日志类型显示名 */
698 logTypeText(type) {
699 return (
700 {
701 log: '脚本',
702 init: '初始化',
703 request: '请求',
704 response: '返回',
705 error: '错误',
706 http: '网络',
707 }[type] || type
708 )
709 },
710 },
711 watch: {
712 // 日志弹层开关:打开时订阅实时更新,关闭时取消订阅
713 showLogs(val) {
714 if (val) {
715 if (!this._offLog) this._offLog = onLogChange(() => this.scheduleLogRefresh())
716 } else if (this._offLog) {
717 this._offLog()
718 this._offLog = null
719 }
720 },
721 },
722}
723</script>
724
725<style lang="scss" scoped>
726.page {
727 display: flex;
728 flex-direction: column;
729 height: 100vh;
730 background: #f5f6f8;
731 /* 大屏(平板/桌面)时内容居中并限制宽度 */
732 width: 100%;
733 max-width: 1100px;
734 margin: 0 auto;
735}
736
737.setting-scroll {
738 /* flex: 1 占满剩余高度,为底部自绘 tabBar 留出空间 */
739 flex: 1;
740 min-height: 0;
741 padding-bottom: 40rpx;
742}
743
744/* ============ 账号卡片 ============ */
745.account-card {
746 position: relative;
747 display: flex;
748 align-items: center;
749 justify-content: space-between;
750 margin: 24rpx;
751 padding: 40rpx 32rpx;
752 border-radius: 24rpx;
753 background: linear-gradient(135deg, var(--theme-color, #3ed18e) 0%, var(--theme-color-dark, #24a86c) 100%);
754 box-shadow: 0 10rpx 28rpx rgba(var(--theme-color-rgb, 49, 194, 124), 0.28);
755 overflow: hidden;
756}
757
758/* 右上角光晕装饰 */
759.account-card::after {
760 content: '';
761 position: absolute;
762 top: -70rpx;
763 right: -40rpx;
764 width: 220rpx;
765 height: 220rpx;
766 border-radius: 50%;
767 background: rgba(255, 255, 255, 0.12);
768 pointer-events: none;
769}
770
771/* 左下角小光晕装饰 */
772.account-card::before {
773 content: '';
774 position: absolute;
775 bottom: -90rpx;
776 left: 100rpx;
777 width: 180rpx;
778 height: 180rpx;
779 border-radius: 50%;
780 background: rgba(255, 255, 255, 0.08);
781 pointer-events: none;
782}
783
784.account-left {
785 position: relative;
786 z-index: 1;
787 display: flex;
788 align-items: center;
789 flex: 1;
790 min-width: 0;
791}
792
793.account-avatar {
794 width: 100rpx;
795 height: 100rpx;
796 border-radius: 50%;
797 background: rgba(255, 255, 255, 0.22);
798 border: 3rpx solid rgba(255, 255, 255, 0.45);
799 display: flex;
800 align-items: center;
801 justify-content: center;
802 flex-shrink: 0;
803}
804
805.account-avatar text {
806 font-size: 44rpx;
807 color: #fff;
808 font-weight: 600;
809 line-height: 1;
810}
811
812.account-info {
813 margin-left: 26rpx;
814 display: flex;
815 flex-direction: column;
816 min-width: 0;
817}
818
819.account-name {
820 font-size: 36rpx;
821 font-weight: 600;
822 color: #fff;
823 overflow: hidden;
824 text-overflow: ellipsis;
825 white-space: nowrap;
826}
827
828.account-desc {
829 margin-top: 8rpx;
830 font-size: 24rpx;
831 color: rgba(255, 255, 255, 0.85);
832 overflow: hidden;
833 text-overflow: ellipsis;
834 white-space: nowrap;
835}
836
837.account-right {
838 position: relative;
839 z-index: 1;
840 display: flex;
841 align-items: center;
842 flex-shrink: 0;
843 margin-left: 16rpx;
844}
845
846/* 已同步徽标 */
847.account-badge {
848 width: 40rpx;
849 height: 40rpx;
850 margin-right: 12rpx;
851 border-radius: 50%;
852 background: rgba(255, 255, 255, 0.25);
853 display: flex;
854 align-items: center;
855 justify-content: center;
856}
857
858.section {
859 margin: 24rpx;
860}
861
862.section-title {
863 font-size: 26rpx;
864 color: var(--text-muted, #909399);
865 padding: 8rpx 8rpx 16rpx;
866}
867
868.section-body {
869 background: var(--card-bg, #fff);
870 border-radius: 16rpx;
871 overflow: hidden;
872}
873
874.setting-item {
875 display: flex;
876 align-items: center;
877 padding: 28rpx;
878 border-bottom: 1rpx solid #f5f6f8;
879}
880
881.setting-item:last-child {
882 border-bottom: none;
883}
884
885.item-label {
886 font-size: 30rpx;
887 color: #303133;
888 flex-shrink: 0;
889}
890
891.item-value {
892 flex: 1;
893 text-align: right;
894 font-size: 28rpx;
895 color: var(--text-muted, #909399);
896 margin: 0 8rpx;
897 overflow: hidden;
898 text-overflow: ellipsis;
899 white-space: nowrap;
900}
901
902/* 说明项:纵向布局,允许换行完整展示 */
903.setting-item.column {
904 flex-direction: column;
905 align-items: flex-start;
906}
907
908.item-desc {
909 margin-top: 8rpx;
910 font-size: 26rpx;
911 color: var(--text-muted, #909399);
912 line-height: 1.6;
913}
914
915.mode-picker {
916 flex: 1;
917 display: flex;
918 justify-content: flex-end;
919 flex-wrap: wrap;
920}
921
922.mode-chip {
923 padding: 8rpx 20rpx;
924 margin: 4rpx 0 4rpx 12rpx;
925 border-radius: 26rpx;
926 font-size: 24rpx;
927 color: var(--text-secondary, #606266);
928 background: var(--fill-bg, #f2f3f5);
929}
930
931.mode-chip.active {
932 background: var(--theme-color, #31c27c);
933 color: #fff;
934}
935
936/* ---- 主题色选择 ---- */
937.theme-picker {
938 flex: 1;
939 display: flex;
940 flex-wrap: wrap;
941 justify-content: flex-end;
942 margin-left: 16rpx;
943}
944
945.theme-chip {
946 width: 56rpx;
947 height: 56rpx;
948 margin: 6rpx 0 6rpx 16rpx;
949 border-radius: 50%;
950 border: 4rpx solid transparent;
951 box-sizing: border-box;
952 display: flex;
953 align-items: center;
954 justify-content: center;
955}
956
957.theme-chip.active {
958 border-color: #303133;
959}
960
961/* ---- 背景图片设置 ---- */
962.bg-blur-slider {
963 flex: 1;
964 margin: 0 16rpx;
965}
966
967.bg-blur-value {
968 width: 56rpx;
969 text-align: right;
970 font-size: 26rpx;
971 color: var(--text-muted, #909399);
972}
973
974.item-label.danger {
975 color: #f56c6c;
976}
977
978.user-api-item {
979 display: flex;
980 align-items: center;
981 padding: 28rpx;
982 border-bottom: 1rpx solid #f5f6f8;
983}
984
985.user-api-item:last-child {
986 border-bottom: none;
987}
988
989.api-main {
990 flex: 1;
991 min-width: 0;
992 display: flex;
993 flex-direction: column;
994}
995
996.api-name-row {
997 display: flex;
998 align-items: center;
999}
1000
1001.api-name {
1002 font-size: 30rpx;
1003 color: #303133;
1004 font-weight: 500;
1005}
1006
1007.api-version {
1008 margin-left: 12rpx;
1009 font-size: 22rpx;
1010 color: var(--text-muted, #909399);
1011}
1012
1013.api-status {
1014 margin-left: 12rpx;
1015 display: flex;
1016 align-items: center;
1017 font-size: 22rpx;
1018}
1019
1020.api-status text {
1021 margin-left: 4rpx;
1022}
1023
1024.status-success {
1025 color: #67c23a;
1026}
1027
1028.status-initing {
1029 color: var(--text-muted, #909399);
1030}
1031
1032.status-failed {
1033 color: #f56c6c;
1034}
1035
1036.api-author {
1037 margin-top: 8rpx;
1038 font-size: 24rpx;
1039 color: var(--text-muted, #909399);
1040}
1041
1042.api-desc {
1043 margin-top: 4rpx;
1044 font-size: 22rpx;
1045 color: var(--text-muted, #c0c4cc);
1046 overflow: hidden;
1047 text-overflow: ellipsis;
1048 white-space: nowrap;
1049}
1050
1051.api-actions {
1052 display: flex;
1053 flex-direction: column;
1054 margin-left: 16rpx;
1055 flex-shrink: 0;
1056}
1057
1058.api-action {
1059 padding: 8rpx 24rpx;
1060 margin: 4rpx 0;
1061 border-radius: 26rpx;
1062 font-size: 24rpx;
1063 color: var(--theme-color, #31c27c);
1064 background: rgba(var(--theme-color-rgb, 49, 194, 124), 0.1);
1065 text-align: center;
1066}
1067
1068.api-action.danger {
1069 color: #ff4d4f;
1070 background: rgba(255, 77, 79, 0.1);
1071}
1072
1073.mask {
1074 position: fixed;
1075 top: 0;
1076 left: 0;
1077 right: 0;
1078 bottom: 0;
1079 background: rgba(0, 0, 0, 0.5);
1080 z-index: 999;
1081 display: flex;
1082 align-items: center;
1083 justify-content: center;
1084}
1085
1086.source-modal {
1087 width: 80%;
1088 max-height: 70vh;
1089 background: var(--card-bg-strong, #fff);
1090 border-radius: 24rpx;
1091 display: flex;
1092 flex-direction: column;
1093 overflow: hidden;
1094}
1095
1096.modal-header {
1097 display: flex;
1098 align-items: center;
1099 justify-content: space-between;
1100 padding: 32rpx;
1101 border-bottom: 1rpx solid #f5f6f8;
1102}
1103
1104.modal-title {
1105 font-size: 32rpx;
1106 font-weight: 600;
1107 color: #303133;
1108}
1109
1110.modal-close {
1111 display: flex;
1112 align-items: center;
1113 justify-content: center;
1114}
1115
1116.modal-body {
1117 max-height: 50vh;
1118}
1119
1120.source-item {
1121 display: flex;
1122 align-items: center;
1123 padding: 28rpx 32rpx;
1124 border-bottom: 1rpx solid #f5f6f8;
1125}
1126
1127.source-item.active {
1128 background: rgba(var(--theme-color-rgb, 49, 194, 124), 0.05);
1129}
1130
1131.source-name {
1132 flex: 1;
1133 font-size: 30rpx;
1134 color: #303133;
1135}
1136
1137.source-tag {
1138 padding: 4rpx 16rpx;
1139 margin-right: 12rpx;
1140 border-radius: 20rpx;
1141 font-size: 20rpx;
1142 color: var(--theme-color, #31c27c);
1143 background: rgba(var(--theme-color-rgb, 49, 194, 124), 0.1);
1144}
1145
1146.modal-empty {
1147 padding: 80rpx 0;
1148 text-align: center;
1149 color: var(--text-muted, #909399);
1150 font-size: 28rpx;
1151}
1152
1153.sponsor-modal {
1154 width: 80%;
1155 max-height: 70vh;
1156 background: var(--card-bg-strong, #fff);
1157 border-radius: 24rpx;
1158 display: flex;
1159 flex-direction: column;
1160 overflow: hidden;
1161}
1162
1163.sponsor-body {
1164 max-height: 60vh;
1165 padding: 16rpx;
1166}
1167
1168.sponsor-image {
1169 width: 100%;
1170 display: block;
1171}
1172
1173/* ============ 自定义源运行日志弹层 ============ */
1174.log-modal {
1175 width: 90%;
1176 max-height: 76vh;
1177 background: var(--card-bg-strong, #fff);
1178 border-radius: 24rpx;
1179 display: flex;
1180 flex-direction: column;
1181 overflow: hidden;
1182}
1183
1184.log-scroll {
1185 flex: 1;
1186 min-height: 0;
1187 max-height: 56vh;
1188 padding: 0 24rpx;
1189}
1190
1191.log-empty {
1192 padding: 80rpx 0;
1193 text-align: center;
1194 font-size: 26rpx;
1195 color: var(--text-muted, #909399);
1196}
1197
1198.log-item {
1199 padding: 14rpx 0;
1200 border-bottom: 1rpx solid #f5f6f8;
1201}
1202
1203.log-head {
1204 display: flex;
1205 align-items: center;
1206 margin-bottom: 6rpx;
1207}
1208
1209.log-time {
1210 font-size: 22rpx;
1211 color: var(--text-muted, #909399);
1212}
1213
1214/* 类型标签:按日志类别着色,便于快速定位错误与网络请求 */
1215.log-type {
1216 margin-left: 12rpx;
1217 padding: 2rpx 10rpx;
1218 border-radius: 6rpx;
1219 font-size: 20rpx;
1220 background: #f2f3f5;
1221 color: #606266;
1222}
1223
1224.log-type.type-init {
1225 background: rgba(249, 115, 22, 0.12);
1226 color: #ea580c;
1227}
1228
1229.log-type.type-request {
1230 background: rgba(59, 130, 246, 0.12);
1231 color: #3b82f6;
1232}
1233
1234.log-type.type-response {
1235 background: rgba(49, 194, 124, 0.14);
1236 color: var(--theme-color-dark, #1ba56a);
1237}
1238
1239.log-type.type-error {
1240 background: rgba(245, 108, 108, 0.12);
1241 color: #f56c6c;
1242}
1243
1244.log-type.type-http {
1245 background: rgba(139, 92, 246, 0.12);
1246 color: #8b5cf6;
1247}
1248
1249.log-text {
1250 font-size: 24rpx;
1251 color: #303133;
1252 word-break: break-all;
1253}
1254
1255.log-detail {
1256 display: block;
1257 margin-top: 4rpx;
1258 font-size: 22rpx;
1259 color: var(--text-secondary, #606266);
1260 word-break: break-all;
1261}
1262
1263.log-actions {
1264 display: flex;
1265 justify-content: flex-end;
1266 padding: 16rpx 24rpx;
1267 border-top: 1rpx solid #f5f6f8;
1268}
1269
1270</style>