修复 editor 判断语言

This commit is contained in:
whyour
2023-08-05 13:18:28 +08:00
parent b1a242c8ee
commit a2e33d1ed4
6 changed files with 35 additions and 44 deletions
+2 -9
View File
@@ -30,7 +30,7 @@ import config from '@/utils/config';
import CronLogModal from './logModal';
import Editor from '@monaco-editor/react';
import IconFont from '@/components/iconfont';
import { getCommandScript } from '@/utils';
import { getCommandScript, getEditorMode } from '@/utils';
import VirtualList from 'rc-virtual-list';
import useScrollHeight from '@/hooks/useScrollHeight';
@@ -46,13 +46,6 @@ const tabList = [
tab: intl.get('脚本'),
},
];
const LangMap: any = {
'.py': 'python',
'.js': 'javascript',
'.mjs': 'typescript',
'.sh': 'shell',
'.ts': 'typescript',
};
interface LogItem {
directory: string;
@@ -110,7 +103,7 @@ const CronDetailModal = ({
),
script: scriptInfo.filename && (
<Editor
language={LangMap[scriptInfo.filename.slice(-3)] || ''}
language={getEditorMode(scriptInfo.filename)}
theme={theme}
value={value}
options={{
+4 -4
View File
@@ -186,7 +186,7 @@ const Env = () => {
</Tooltip>
<Tooltip
title={
isPc ? (record.status === Status.intl.get('禁用') ? intl.get('启用') : intl.get('禁用')) : ''
isPc ? (record.status === Status. ? intl.get('启用') : intl.get('禁用')) : ''
}
>
<a onClick={() => enabledOrDisabledEnv(record, index)}>
@@ -232,10 +232,10 @@ const Env = () => {
const enabledOrDisabledEnv = (record: any, index: number) => {
Modal.confirm({
title: `确认${record.status === Status.intl.get('禁用') ? intl.get('启用') : intl.get('禁用')}`,
title: `确认${record.status === Status. ? intl.get('启用') : intl.get('禁用')}`,
content: (
<>
{intl.get('确认')}{record.status === Status.intl.get('禁用') ? intl.get('启用') : intl.get('禁用')}
{intl.get('确认')}{record.status === Status. ? intl.get('启用') : intl.get('禁用')}
Env{' '}
<Text style={{ wordBreak: 'break-all' }} type="warning">
{record.value}
@@ -254,7 +254,7 @@ const Env = () => {
.then(({ code, data }) => {
if (code === 200) {
message.success(
`${record.status === Status.intl.get('禁用') ? intl.get('启用') : intl.get('禁用')}成功`,
`${record.status === Status. ? intl.get('启用') : intl.get('禁用')}${intl.get('成功')}`,
);
const newStatus =
record.status === Status. ? Status.已启用 : Status.已禁用;
+3 -16
View File
@@ -8,22 +8,9 @@ import Editor from '@monaco-editor/react';
import SaveModal from './saveModal';
import SettingModal from './setting';
import { useTheme } from '@/utils/hooks';
import { logEnded } from '@/utils';
import { getEditorMode, logEnded } from '@/utils';
const { Option } = Select;
const LangMap: any = {
'.py': 'python',
'.js': 'javascript',
'.mjs': 'typescript',
'.sh': 'shell',
'.ts': 'typescript',
};
const prefixMap: any = {
python: '.py',
javascript: '.js',
shell: '.sh',
typescript: '.ts',
};
const EditModal = ({
treeData,
@@ -66,7 +53,7 @@ const EditModal = ({
return;
}
const newMode = LangMap[value.slice(-3)] || '';
const newMode = getEditorMode(value);
setCNode(node);
setLanguage(newMode);
getDetail(node);
@@ -146,7 +133,7 @@ const EditModal = ({
setCNode(currentNode);
setValue(content as string);
setSelectedKey(currentNode.key);
const newMode = LangMap[currentNode.title.slice(-3)] || '';
const newMode = getEditorMode(currentNode.title);
setLanguage(newMode);
}
}, [content, currentNode]);
+2 -10
View File
@@ -37,7 +37,7 @@ import EditScriptNameModal from './editNameModal';
import debounce from 'lodash/debounce';
import { history, useOutletContext, useLocation } from '@umijs/max';
import { parse } from 'query-string';
import { depthFirstSearch, findNode } from '@/utils';
import { depthFirstSearch, findNode, getEditorMode } from '@/utils';
import { SharedContext } from '@/layouts';
import useFilterTreeData from '@/hooks/useFilterTreeData';
import uniq from 'lodash/uniq';
@@ -46,14 +46,6 @@ import RenameModal from './renameModal';
const { Text } = Typography;
const LangMap: any = {
'.py': 'python',
'.js': 'javascript',
'.mjs': 'typescript',
'.sh': 'shell',
'.ts': 'typescript',
};
const Script = () => {
const { headerStyle, isPhone, theme, socketMessage } =
useOutletContext<SharedContext>();
@@ -134,7 +126,7 @@ const Script = () => {
return;
}
const newMode = value ? LangMap[value.slice(-3)] : '';
const newMode = getEditorMode(value);
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
setValue(intl.get('加载中...'));
getDetail(node);