feat: 优化部分代码实现,添加导入外部插件功能
This commit is contained in:
1 parent
d6816925ed
commit
6d550505a0
6 files changed
+58
-35
No files matched your search
@@ -4,7 +4,7 @@ import { alertTipType, PluginExportType } from "@/types/type";
|
||||
|
||||
const initPlugin = async (globalAlertTip: alertTipType) => {
|
||||
initPluginCenter(globalAlertTip);
|
||||
const modulesFiles = import.meta.glob("@/plugins/**/export.ts", { eager: true });
|
||||
const modulesFiles = import.meta.glob("@/plugins/**/export*.ts", { eager: true });
|
||||
const pluginCenter = usePluginCenter();
|
||||
const promiseArray = [];
|
||||
for (let pluginConfig of Object.values(modulesFiles)) {
|
||||
|
||||
@@ -73,6 +73,7 @@ const mainRef = ref<HTMLDivElement>()
|
||||
const draggable = ref(true)
|
||||
|
||||
// 使用ResizeObserver实现
|
||||
// 什么?性能问题?这玩意性能问题多着呢,轮不到它。
|
||||
const clientWidth = ref<number>(666)
|
||||
|
||||
const name = props.name ?? props.item.name
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,29 @@
|
||||
import { Plugin, PluginGroup } from "@/class/PluginCenter";
|
||||
import { LogoGithub } from "@vicons/ionicons5";
|
||||
import { PluginExportType } from "@/types/type";
|
||||
import { shallowRef } from "vue";
|
||||
import registerExternalPlugin from "./registerExternalPlugin";
|
||||
|
||||
const pluginConfig: Plugin = {
|
||||
name: "导入插件",
|
||||
icon: shallowRef(LogoGithub),
|
||||
filter: (vDirs, vFiles) => {
|
||||
if (vDirs.length !== 0) {
|
||||
return false;
|
||||
}
|
||||
if (vFiles.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
return vFiles[0].name.endsWith('js')
|
||||
},
|
||||
disable: false,
|
||||
group: [PluginGroup.default],
|
||||
func: registerExternalPlugin,
|
||||
priority: -1
|
||||
};
|
||||
|
||||
export default pluginConfig;
|
||||
|
||||
export const type = PluginExportType.default;
|
||||
|
||||
export const key = 'registerExternalPlugin';
|
||||
@@ -0,0 +1,25 @@
|
||||
import VirtualDirectory, { VirtualFile } from "@/class/VirtualDirectory";
|
||||
// import useMiaoFetchApi from "@/hooks/useMiaoFetchApi";
|
||||
import { PluginExportType, usePluginHooksType } from "@/types/type";
|
||||
import type { Plugin, registerComponentOption } from "@/class/PluginCenter";
|
||||
|
||||
// const miaoFetchApi = useMiaoFetchApi()
|
||||
|
||||
export default async function registerExternalPlugin(_VDirectories: VirtualDirectory[], VFiles: VirtualFile[], hooks: usePluginHooksType) {
|
||||
const targetPluginVFile = VFiles[0] as VirtualFile
|
||||
// const pluginU8iArr = await miaoFetchApi.getFile(targetPluginVFile).response
|
||||
// const pluginText = new TextDecoder().decode(pluginU8iArr)
|
||||
// const plugin = await import(/* @vite-ignore */'')
|
||||
const plugin = await import(/* @vite-ignore */ targetPluginVFile.url) as {
|
||||
default: registerComponentOption | Plugin;
|
||||
type: PluginExportType;
|
||||
key?: string;
|
||||
}
|
||||
// console.log(plugin)
|
||||
const pc = hooks.getPluginCenter()
|
||||
if(plugin.type === PluginExportType.default) {
|
||||
pc.register(`${Math.random()}`, plugin.default as Plugin)
|
||||
} else {
|
||||
pc.registerComponent(plugin.default as registerComponentOption)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user