mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 22:18:07 +08:00
feat: 修改 code-editor 样式
This commit is contained in:
parent
8b3d84d667
commit
c332d0284b
@ -15,3 +15,62 @@ export const Mimetypes = new Map([
|
|||||||
['gzip/document', CompressType.TarGz],
|
['gzip/document', CompressType.TarGz],
|
||||||
['application/x-xz', CompressType.Xz],
|
['application/x-xz', CompressType.Xz],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
export const Languages = [
|
||||||
|
{
|
||||||
|
label: 'go',
|
||||||
|
value: 'go',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'html',
|
||||||
|
value: 'html',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'javascript',
|
||||||
|
value: 'javascript',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'java',
|
||||||
|
value: 'java',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'kotlin',
|
||||||
|
value: 'kotlin',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'markdown',
|
||||||
|
value: 'markdown',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'mysql',
|
||||||
|
value: 'mysql',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'php',
|
||||||
|
value: 'php',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'redis',
|
||||||
|
value: 'redis',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'shell',
|
||||||
|
value: 'shell',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'sql',
|
||||||
|
value: 'sql',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'yaml',
|
||||||
|
value: 'yaml',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'json',
|
||||||
|
value: 'json',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'css',
|
||||||
|
value: 'css',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
@ -748,6 +748,8 @@ export default {
|
|||||||
list: 'File List',
|
list: 'File List',
|
||||||
sub: 'Include subdirectory',
|
sub: 'Include subdirectory',
|
||||||
downlodSuccess: 'Download Success',
|
downlodSuccess: 'Download Success',
|
||||||
|
theme: 'Theme',
|
||||||
|
language: 'Language',
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
all: 'All',
|
all: 'All',
|
||||||
|
@ -755,6 +755,8 @@ export default {
|
|||||||
list: '文件列表',
|
list: '文件列表',
|
||||||
sub: '包含子目录',
|
sub: '包含子目录',
|
||||||
downlodSuccess: '下载完成',
|
downlodSuccess: '下载完成',
|
||||||
|
theme: '主题',
|
||||||
|
language: '语言',
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
all: '全部',
|
all: '全部',
|
||||||
|
@ -6,9 +6,20 @@
|
|||||||
destroy-on-close
|
destroy-on-close
|
||||||
width="70%"
|
width="70%"
|
||||||
@opened="onOpen"
|
@opened="onOpen"
|
||||||
class="coder-dialog"
|
|
||||||
>
|
>
|
||||||
<div v-loading="loading">
|
<el-form :inline="true" :model="config">
|
||||||
|
<el-form-item :label="$t('file.theme')">
|
||||||
|
<el-select v-model="config.theme" @change="initEditor()">
|
||||||
|
<el-option v-for="item in themes" :key="item.label" :value="item.value" :label="item.label" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item :label="$t('file.language')">
|
||||||
|
<el-select v-model="config.language" @change="initEditor()">
|
||||||
|
<el-option v-for="lang in Languages" :key="lang.label" :value="lang.value" :label="lang.label" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<div class="coder-editor" v-loading="loading">
|
||||||
<div id="codeBox" style="height: 60vh"></div>
|
<div id="codeBox" style="height: 60vh"></div>
|
||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@ -25,7 +36,8 @@ import { SaveFileContent } from '@/api/modules/files';
|
|||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { MsgSuccess } from '@/utils/message';
|
import { MsgSuccess } from '@/utils/message';
|
||||||
import * as monaco from 'monaco-editor';
|
import * as monaco from 'monaco-editor';
|
||||||
import { ref } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
|
import { Languages } from '@/global/mimetype';
|
||||||
|
|
||||||
let editor: monaco.editor.IStandaloneCodeEditor | undefined;
|
let editor: monaco.editor.IStandaloneCodeEditor | undefined;
|
||||||
|
|
||||||
@ -36,9 +48,33 @@ interface EditProps {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EditorConfig {
|
||||||
|
theme: string;
|
||||||
|
language: string;
|
||||||
|
}
|
||||||
|
|
||||||
let open = ref(false);
|
let open = ref(false);
|
||||||
let loading = ref(false);
|
let loading = ref(false);
|
||||||
let language = ref('json');
|
|
||||||
|
let config = reactive<EditorConfig>({
|
||||||
|
theme: 'vs-dark',
|
||||||
|
language: 'json',
|
||||||
|
});
|
||||||
|
|
||||||
|
const themes = [
|
||||||
|
{
|
||||||
|
label: 'Visual Studio',
|
||||||
|
value: 'vs',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Visual Studio Dark',
|
||||||
|
value: 'vs-dark',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'High Contrast Dark',
|
||||||
|
value: 'hc-black',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
let form = ref({
|
let form = ref({
|
||||||
content: '',
|
content: '',
|
||||||
@ -61,11 +97,11 @@ const initEditor = () => {
|
|||||||
}
|
}
|
||||||
const codeBox = document.getElementById('codeBox');
|
const codeBox = document.getElementById('codeBox');
|
||||||
editor = monaco.editor.create(codeBox as HTMLElement, {
|
editor = monaco.editor.create(codeBox as HTMLElement, {
|
||||||
theme: 'vs-dark', //官方自带三种主题vs, hc-black, or vs-dark
|
theme: config.theme, //官方自带三种主题vs, hc-black, or vs-dark
|
||||||
value: form.value.content,
|
value: form.value.content,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
automaticLayout: true,
|
automaticLayout: true,
|
||||||
language: language.value,
|
language: config.language,
|
||||||
folding: true, //代码折叠
|
folding: true, //代码折叠
|
||||||
roundedSelection: false, // 右侧不显示编辑器预览框
|
roundedSelection: false, // 右侧不显示编辑器预览框
|
||||||
});
|
});
|
||||||
@ -95,6 +131,7 @@ const saveContent = (closePage: boolean) => {
|
|||||||
const acceptParams = (props: EditProps) => {
|
const acceptParams = (props: EditProps) => {
|
||||||
form.value.content = props.content;
|
form.value.content = props.content;
|
||||||
form.value.path = props.path;
|
form.value.path = props.path;
|
||||||
|
config.language = props.language;
|
||||||
open.value = true;
|
open.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,7 +143,7 @@ defineExpose({ acceptParams });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.coder-dialog {
|
.coder-editor {
|
||||||
--el-dialog-margin-top: 10vh;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -165,7 +165,7 @@ import CodeEditor from './code-editor/index.vue';
|
|||||||
import Wget from './wget/index.vue';
|
import Wget from './wget/index.vue';
|
||||||
import Move from './move/index.vue';
|
import Move from './move/index.vue';
|
||||||
import Download from './download/index.vue';
|
import Download from './download/index.vue';
|
||||||
import { Mimetypes } from '@/global/mimetype';
|
import { Mimetypes, Languages } from '@/global/mimetype';
|
||||||
import Process from './process/index.vue';
|
import Process from './process/index.vue';
|
||||||
// import Detail from './detail/index.vue';
|
// import Detail from './detail/index.vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
@ -196,7 +196,7 @@ let pathWidth = ref(0);
|
|||||||
const fileCreate = reactive({ path: '/', isDir: false, mode: 0o755 });
|
const fileCreate = reactive({ path: '/', isDir: false, mode: 0o755 });
|
||||||
const fileCompress = reactive({ files: [''], name: '', dst: '', operate: 'compress' });
|
const fileCompress = reactive({ files: [''], name: '', dst: '', operate: 'compress' });
|
||||||
const fileDeCompress = reactive({ path: '', name: '', dst: '', mimeType: '' });
|
const fileDeCompress = reactive({ path: '', name: '', dst: '', mimeType: '' });
|
||||||
const fileEdit = reactive({ content: '', path: '', name: '' });
|
const fileEdit = reactive({ content: '', path: '', name: '', language: 'json' });
|
||||||
const codeReq = reactive({ path: '', expand: false, page: 1, pageSize: 100 });
|
const codeReq = reactive({ path: '', expand: false, page: 1, pageSize: 100 });
|
||||||
const fileUpload = reactive({ path: '' });
|
const fileUpload = reactive({ path: '' });
|
||||||
const fileRename = reactive({ path: '', oldName: '' });
|
const fileRename = reactive({ path: '', oldName: '' });
|
||||||
@ -382,12 +382,25 @@ const openDeCompress = (item: File.File) => {
|
|||||||
const openCodeEditor = (row: File.File) => {
|
const openCodeEditor = (row: File.File) => {
|
||||||
codeReq.path = row.path;
|
codeReq.path = row.path;
|
||||||
codeReq.expand = true;
|
codeReq.expand = true;
|
||||||
GetFileContent(codeReq).then((res) => {
|
|
||||||
fileEdit.content = res.data.content;
|
if (row.extension != '') {
|
||||||
fileEdit.path = res.data.path;
|
Languages.forEach((language) => {
|
||||||
fileEdit.name = res.data.name;
|
const ext = row.extension.substring(1);
|
||||||
codeEditorRef.value.acceptParams(fileEdit);
|
if (language.value == ext) {
|
||||||
});
|
fileEdit.language = language.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
GetFileContent(codeReq)
|
||||||
|
.then((res) => {
|
||||||
|
fileEdit.content = res.data.content;
|
||||||
|
fileEdit.path = res.data.path;
|
||||||
|
fileEdit.name = res.data.name;
|
||||||
|
|
||||||
|
codeEditorRef.value.acceptParams(fileEdit);
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
const openUpload = () => {
|
const openUpload = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user