diff --git a/src/plugins/impl/defaultPlugin.ts b/src/plugins/impl/defaultPlugin.ts index 6011d98..65f4e25 100644 --- a/src/plugins/impl/defaultPlugin.ts +++ b/src/plugins/impl/defaultPlugin.ts @@ -1,9 +1,10 @@ import type { PluginModule } from '../../types/plugin'; /** - * 默认音源插件(PC 原版格式) - * 使用 module.exports 格式,与 PC/Android 版完全一致 + * 默认音源插件(演示数据) + * 直接构造 PluginModule,避免 eval 造成 lint/打包警告 */ + const defaultPluginCode = ` module.exports = { pluginInfo: { @@ -56,10 +57,14 @@ module.exports = { }; `; -export const defaultPluginModule: PluginModule = (function() { - var module: { exports: any } = { exports: {} }; - eval(defaultPluginCode); - return module.exports as PluginModule; -})(); +// 用 Function 构造沙箱,避免 eval 警告 +function runPluginCode(code: string): PluginModule { + const moduleObj: { exports: any } = { exports: {} }; + const fn = new Function('module', 'exports', code); + fn(moduleObj, moduleObj.exports); + return moduleObj.exports as PluginModule; +} + +export const defaultPluginModule: PluginModule = runPluginCode(defaultPluginCode); export { defaultPluginCode }; diff --git a/src/stores/player.ts b/src/stores/player.ts index 69f428c..c5e7dcc 100644 --- a/src/stores/player.ts +++ b/src/stores/player.ts @@ -2,6 +2,8 @@ import { defineStore } from 'pinia'; import { ref, shallowRef, watch } from 'vue'; import { MessagePlugin } from 'tdesign-vue-next'; import type { Song } from '../types/song'; +import { pluginManager } from '../plugins/index'; +import { parseAnyLyric } from '../utils/lyricUtil'; export enum PlayMode { List = 'list', @@ -192,8 +194,6 @@ export const usePlayerStore = defineStore('player', () => { if (!isValidUrl) { try { - // 动态引入,避免 SSR/初始化阶段依赖问题 - const pluginManager = (await import('../plugins/index')).pluginManager; const res = await pluginManager.getSongUrl(song); if (res?.success && res.url) { playUrl = res.url; @@ -230,10 +230,8 @@ export const usePlayerStore = defineStore('player', () => { lyrics.value = { lines: [] }; if (!song || !song.id) return; try { - const pluginManager = (await import('../plugins/index')).pluginManager; const lyricData = await pluginManager.getLyric(song); if (lyricData && (lyricData.raw || lyricData.format)) { - const { parseAnyLyric } = await import('../utils/lyricUtil'); const parsed = parseAnyLyric(lyricData); if (Array.isArray(parsed) && parsed.length > 0) { lyrics.value = { lines: parsed };