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) => {
|
const initPlugin = async (globalAlertTip: alertTipType) => {
|
||||||
initPluginCenter(globalAlertTip);
|
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 pluginCenter = usePluginCenter();
|
||||||
const promiseArray = [];
|
const promiseArray = [];
|
||||||
for (let pluginConfig of Object.values(modulesFiles)) {
|
for (let pluginConfig of Object.values(modulesFiles)) {
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ const mainRef = ref<HTMLDivElement>()
|
|||||||
const draggable = ref(true)
|
const draggable = ref(true)
|
||||||
|
|
||||||
// 使用ResizeObserver实现
|
// 使用ResizeObserver实现
|
||||||
|
// 什么?性能问题?这玩意性能问题多着呢,轮不到它。
|
||||||
const clientWidth = ref<number>(666)
|
const clientWidth = ref<number>(666)
|
||||||
|
|
||||||
const name = props.name ?? props.item.name
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-34
@@ -19,42 +19,10 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
'/get': {
|
'^/(get|upload|delete|query|rename|cut|mkdir)': {
|
||||||
target: 'http://127.0.0.1:17705',
|
target: 'http://127.0.0.1:17705',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/get/, '/get')
|
rewrite: (path) => path
|
||||||
},
|
|
||||||
|
|
||||||
'/upload': {
|
|
||||||
target: 'http://127.0.0.1:17705',
|
|
||||||
changeOrigin: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/upload/, '/upload')
|
|
||||||
},
|
|
||||||
|
|
||||||
'/delete': {
|
|
||||||
target: 'http://127.0.0.1:17705',
|
|
||||||
changeOrigin: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/delete/, '/delete')
|
|
||||||
},
|
|
||||||
'/query': {
|
|
||||||
target: 'http://127.0.0.1:17705',
|
|
||||||
changeOrigin: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/query/, '/query')
|
|
||||||
},
|
|
||||||
'/rename': {
|
|
||||||
target: 'http://127.0.0.1:17705',
|
|
||||||
changeOrigin: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/rename/, '/rename')
|
|
||||||
},
|
|
||||||
'/cut': {
|
|
||||||
target: 'http://127.0.0.1:17705',
|
|
||||||
changeOrigin: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/cut/, '/cut')
|
|
||||||
},
|
|
||||||
'/mkdir': {
|
|
||||||
target: 'http://127.0.0.1:17705',
|
|
||||||
changeOrigin: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/mkdir/, '/mkdir')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user