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