Merge branch 'main' of http://git.miaospring.top:3000/539943419/miaoDirectory
This commit is contained in:
commit
d0bad77387
11 files changed
+765
-69
No files matched your search
+1
-1
@@ -327,7 +327,7 @@ $tag-width: 170px;
|
||||
display: flex;
|
||||
// flex-direction: column;
|
||||
height: calc(100% - $controller-height);
|
||||
overflow-y: overlay;
|
||||
overflow-y: hidden;
|
||||
overflow-x: overlay;
|
||||
|
||||
.view-container-item {
|
||||
|
||||
+30
-15
@@ -1,5 +1,5 @@
|
||||
import useViretualPages from "@/hooks/useVirtualPages"
|
||||
import VirtualDirectory, { VirtualFile } from "./VirtualDirectory"
|
||||
import useVirtualPages from '@/hooks/useVirtualPages'
|
||||
import VirtualDirectory, { VirtualFile } from './VirtualDirectory'
|
||||
|
||||
type plugin = {
|
||||
// 用于显示的名字
|
||||
@@ -18,43 +18,58 @@ export default class PluginCenter {
|
||||
[key: string]: plugin
|
||||
}
|
||||
|
||||
register(key: string, plugin: plugin){
|
||||
register(key: string, plugin: plugin) {
|
||||
this.pluginsMap[key] = plugin
|
||||
console.log(this.pluginsMap)
|
||||
}
|
||||
|
||||
/**
|
||||
* 便捷地注册一个组件为插件,触发时直接用新页面打开
|
||||
*/
|
||||
registerComponent(key: string,name: string, component: any, filter:(VDirectorys: VirtualDirectory[], VFiles: VirtualFile[]) => boolean): void {
|
||||
registerComponent(
|
||||
key: string,
|
||||
name: string,
|
||||
getComponent: () => Promise<any>,
|
||||
filter: (
|
||||
VDirectorys: VirtualDirectory[],
|
||||
VFiles: VirtualFile[]
|
||||
) => boolean
|
||||
): void {
|
||||
let _component: any
|
||||
const views = useVirtualPages()
|
||||
this.register(key, {
|
||||
name,
|
||||
filter,
|
||||
func: (VDirectorys: VirtualDirectory[], VFiles: VirtualFile[]) => {
|
||||
if(filter(VDirectorys, VFiles) === false){
|
||||
func: async (
|
||||
VDirectorys: VirtualDirectory[],
|
||||
VFiles: VirtualFile[]
|
||||
) => {
|
||||
if (filter(VDirectorys, VFiles) === false) {
|
||||
return
|
||||
}
|
||||
const views = useViretualPages()
|
||||
views.push(component, VDirectorys, VFiles)
|
||||
if (_component === undefined) _component = await getComponent()
|
||||
views.push(_component, VDirectorys, VFiles)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
getUsablePlugin(VDirectorys: VirtualDirectory[], VFiles: VirtualFile[]) {
|
||||
const usableList = []
|
||||
for(let key of Object.keys(this.pluginsMap)) {
|
||||
if(this.pluginsMap[key].filter(VDirectorys, VFiles)) {
|
||||
for (let key of Object.keys(this.pluginsMap)) {
|
||||
if (this.pluginsMap[key].filter(VDirectorys, VFiles)) {
|
||||
usableList.push(key)
|
||||
}
|
||||
}
|
||||
return usableList.map(key=>({
|
||||
return usableList.map((key) => ({
|
||||
key,
|
||||
...this.pluginsMap[key]
|
||||
}))
|
||||
}
|
||||
|
||||
usePlugin(key: string, VDirectorys: VirtualDirectory[], VFiles: VirtualFile[]) {
|
||||
usePlugin(
|
||||
key: string,
|
||||
VDirectorys: VirtualDirectory[],
|
||||
VFiles: VirtualFile[]
|
||||
) {
|
||||
this.pluginsMap[key].func(VDirectorys, VFiles)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+47
-9
@@ -1,15 +1,12 @@
|
||||
import MiaoDirectory from '@/views/miaoDirectory.vue'
|
||||
import usePluginCenter from './usePluginCenter'
|
||||
import MiaoVideoPlayer from '@/views/miaoVideoPlayer.vue'
|
||||
import MiaoIframe from '@/views/miaoIframe.vue'
|
||||
import MiaoPDF from '@/views/miaoPDF.vue'
|
||||
|
||||
export default function init() {
|
||||
const pluginCenter = usePluginCenter()
|
||||
pluginCenter.registerComponent(
|
||||
'miaoDirectory',
|
||||
'文件夹',
|
||||
MiaoDirectory,
|
||||
async () => MiaoDirectory,
|
||||
(vDirs, vFiles) => {
|
||||
if (vFiles.length) {
|
||||
return false
|
||||
@@ -20,7 +17,7 @@ export default function init() {
|
||||
pluginCenter.registerComponent(
|
||||
'miaoVideoPlayer',
|
||||
'视频',
|
||||
MiaoVideoPlayer,
|
||||
async () => (await import('@/views/miaoVideoPlayer.vue')).default,
|
||||
(vDirs, vFiles) => {
|
||||
if (vDirs.length !== 0) {
|
||||
return false
|
||||
@@ -41,15 +38,21 @@ export default function init() {
|
||||
pluginCenter.registerComponent(
|
||||
'miaoIframe',
|
||||
'框架',
|
||||
MiaoIframe,
|
||||
() => {
|
||||
return false
|
||||
async () => (await import('@/views/miaoIframe.vue')).default,
|
||||
(vDirs, vFiles) => {
|
||||
if (vDirs.length !== 0) {
|
||||
return false
|
||||
}
|
||||
if (vFiles.length !== 1) {
|
||||
return false
|
||||
}
|
||||
return vFiles[0].name.endsWith('html')
|
||||
}
|
||||
)
|
||||
pluginCenter.registerComponent(
|
||||
'miaoPDF',
|
||||
'PDF浏览',
|
||||
MiaoPDF,
|
||||
async () => (await import('@/views/miaoPDF.vue')).default,
|
||||
(vDirs, vFiles) => {
|
||||
if (vDirs.length !== 0) {
|
||||
return false
|
||||
@@ -60,4 +63,39 @@ export default function init() {
|
||||
return vFiles[0].name.endsWith('pdf')
|
||||
}
|
||||
)
|
||||
pluginCenter.registerComponent(
|
||||
'miaoCodeMirror',
|
||||
'代码编辑',
|
||||
async () => (await import('@/views/miaoCodeMirror.vue')).default,
|
||||
(vDirs, vFiles) => {
|
||||
if (vDirs.length !== 0) {
|
||||
return false
|
||||
}
|
||||
if (vFiles.length !== 1) {
|
||||
return false
|
||||
}
|
||||
for (let end of [
|
||||
'js',
|
||||
'ts',
|
||||
'jsx',
|
||||
'tsx',
|
||||
'py',
|
||||
'html',
|
||||
'css',
|
||||
'scss',
|
||||
'go',
|
||||
'json',
|
||||
'md',
|
||||
'yaml',
|
||||
'txt',
|
||||
'xml',
|
||||
'vue',
|
||||
]) {
|
||||
if (vFiles[0].name.endsWith(end)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -67,9 +67,30 @@ const miaoFetchApi = {
|
||||
return response.data
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取对应文件夹下的数据
|
||||
*/
|
||||
async getFile(
|
||||
vFile: VirtualFile,
|
||||
option?: getOption
|
||||
): Promise<getResponse> {
|
||||
// const { baseUrl, api } = Config
|
||||
const url = vFile.url
|
||||
const retry = option?.retry ?? 0
|
||||
const axiosOption = option?.axiosOption ?? {}
|
||||
|
||||
const { miaoFetch } = useMiaoFetch({
|
||||
retry
|
||||
})
|
||||
const response = await miaoFetch({
|
||||
url, ...axiosOption
|
||||
})
|
||||
return response.data
|
||||
},
|
||||
|
||||
/**
|
||||
* 上传单个文件到对应文件夹, 后续要将data类型改成buffer以支持分片上传
|
||||
* 正常上传文件请使用uploadQueue
|
||||
* 正常上传文件请使用uploadQueue
|
||||
*/
|
||||
upload(data: File, targetVDir: VirtualDirectory, option?: uploadOption) {
|
||||
const { baseUrl, api } = Config
|
||||
|
||||
+4
-2
@@ -1,8 +1,10 @@
|
||||
import { AxiosRequestConfig } from "axios";
|
||||
import { directory, file } from "./type";
|
||||
|
||||
export type miaoFetchConfig = {
|
||||
retry?: number;
|
||||
};
|
||||
retry?: number
|
||||
axiosOption?: AxiosRequestConfig<any>
|
||||
}
|
||||
|
||||
export type getOption = {} & miaoFetchConfig;
|
||||
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
<template>
|
||||
<div
|
||||
class="codemirror-container"
|
||||
ref="rootRef"
|
||||
:class="`codemirror-container-${theme}`">
|
||||
<div class="codemirror-container-top">
|
||||
<button @click="handleSave">保存</button>
|
||||
<button @click="switchTheme">切换主题</button>
|
||||
</div>
|
||||
<!-- <NScrollbar :key="_key"> -->
|
||||
<codemirror
|
||||
v-model="codeData"
|
||||
:extensions="extensions"
|
||||
:style="{ height: '100%' }" />
|
||||
<!-- </NScrollbar> -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { VirtualFile } from '@/class/VirtualDirectory'
|
||||
import useMiaoFetchApi from '@/hooks/useMiaoFetchApi'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { Codemirror } from 'vue-codemirror'
|
||||
import { NScrollbar } from 'naive-ui'
|
||||
import { vscodeDark, vscodeLight } from '@uiw/codemirror-theme-vscode'
|
||||
|
||||
const miaoFetchApi = useMiaoFetchApi()
|
||||
|
||||
const currentFiles = defineModel<VirtualFile[]>('currentFiles', {
|
||||
required: true
|
||||
})
|
||||
|
||||
const vFile = ref<VirtualFile>()
|
||||
const rootRef = ref<HTMLDivElement>()
|
||||
const _key = ref(Math.random())
|
||||
const codeData = ref<string>()
|
||||
// 第一次点击保存时自动备份data,暂时懒得做
|
||||
const bakData = ref<string>()
|
||||
const extensions = ref<any[]>([])
|
||||
const theme = ref<'light' | 'dark'>('light')
|
||||
|
||||
const handleSave = async () => {
|
||||
if (bakData.value === codeData.value || !vFile.value) {
|
||||
return
|
||||
}
|
||||
const parentDir = vFile.value?.parent
|
||||
const file_bak = new File(
|
||||
[new Blob([bakData.value ?? ''])],
|
||||
`${vFile.value?.name}.bak`
|
||||
)
|
||||
const file = new File([new Blob([codeData.value ?? ''])], vFile.value.name)
|
||||
bakData.value = codeData.value
|
||||
miaoFetchApi.upload(file, parentDir)
|
||||
false && miaoFetchApi.upload(file_bak, parentDir)
|
||||
}
|
||||
|
||||
const switchTheme = async () => {
|
||||
if (!vFile.value) {
|
||||
return
|
||||
}
|
||||
theme.value = theme.value === 'dark' ? 'light' : 'dark'
|
||||
extensions.value = [
|
||||
...(await getLangExtensions(vFile.value?.name)),
|
||||
theme.value === 'dark' ? vscodeDark : vscodeLight
|
||||
]
|
||||
_key.value = Math.random()
|
||||
}
|
||||
|
||||
const getLangExtensions = async (fileName: string) => {
|
||||
const ext = fileName.split('.').pop()?.toLocaleLowerCase()
|
||||
switch (ext) {
|
||||
case 'js':
|
||||
case 'jsx':
|
||||
case 'ts':
|
||||
case 'tsx':
|
||||
const { javascript } = await import('@codemirror/lang-javascript')
|
||||
return [javascript()]
|
||||
break
|
||||
case 'css':
|
||||
case 'scss':
|
||||
const { sass } = await import('@codemirror/lang-sass')
|
||||
return [sass()]
|
||||
break
|
||||
case 'html':
|
||||
const { html } = await import('@codemirror/lang-html')
|
||||
return [html()]
|
||||
break
|
||||
case 'py':
|
||||
const { python } = await import('@codemirror/lang-python')
|
||||
return [python()]
|
||||
break
|
||||
case 'go':
|
||||
const { go } = await import('@codemirror/lang-go')
|
||||
return [go()]
|
||||
break
|
||||
case 'json':
|
||||
const { json } = await import('@codemirror/lang-json')
|
||||
return [json()]
|
||||
break
|
||||
case 'md':
|
||||
const { markdown } = await import('@codemirror/lang-markdown')
|
||||
return [markdown()]
|
||||
break
|
||||
case 'yaml':
|
||||
const { yaml } = await import('@codemirror/lang-yaml')
|
||||
return [yaml()]
|
||||
break
|
||||
case 'vue':
|
||||
const { vue } = await import('@codemirror/lang-vue')
|
||||
return [vue()]
|
||||
break
|
||||
case 'xml':
|
||||
const { xml } = await import('@codemirror/lang-xml')
|
||||
return [xml()]
|
||||
break
|
||||
default:
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
vFile.value = currentFiles.value[0]
|
||||
const fileName = currentFiles.value[0].name
|
||||
codeData.value = (
|
||||
await miaoFetchApi.getFile(currentFiles.value[0], {
|
||||
axiosOption: { responseType: 'text' }
|
||||
})
|
||||
).toString()
|
||||
bakData.value = codeData.value
|
||||
extensions.value = [...(await getLangExtensions(fileName)), vscodeLight]
|
||||
|
||||
rootRef.value?.addEventListener('keydown', (event) => {
|
||||
if (event.ctrlKey && event.key === 's') {
|
||||
event.preventDefault()
|
||||
handleSave()
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.codemirror-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
&-top {
|
||||
background-color: aqua;
|
||||
}
|
||||
}
|
||||
.codemirror-container-dark {
|
||||
background-color: rgb(30, 30, 30);
|
||||
}
|
||||
.codemirror-container-light {
|
||||
background-color: rgb(255, 255, 255);
|
||||
}
|
||||
</style>
|
||||
@@ -13,7 +13,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</NScrollbar>
|
||||
<div class="miao-container-loading" v-if="isLoading">{{ loadingPercent === -1 ? '缓存中' :
|
||||
<div class="miao-container-loading" v-if="isLoading">{{ loadingPercent === -1 ? '加载插件中' :
|
||||
`渲染进度:${canvasList.length}/${pdfPageCount}` }}</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -103,7 +103,7 @@ onMounted(async () => {
|
||||
.miao-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgb(53, 53, 53);
|
||||
background-color: rgb(201, 201, 201);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
Reference in new issue
Block a user