mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
修复 editor 判断语言
This commit is contained in:
parent
b1a242c8ee
commit
a2e33d1ed4
|
@ -30,7 +30,7 @@ import config from '@/utils/config';
|
||||||
import CronLogModal from './logModal';
|
import CronLogModal from './logModal';
|
||||||
import Editor from '@monaco-editor/react';
|
import Editor from '@monaco-editor/react';
|
||||||
import IconFont from '@/components/iconfont';
|
import IconFont from '@/components/iconfont';
|
||||||
import { getCommandScript } from '@/utils';
|
import { getCommandScript, getEditorMode } from '@/utils';
|
||||||
import VirtualList from 'rc-virtual-list';
|
import VirtualList from 'rc-virtual-list';
|
||||||
import useScrollHeight from '@/hooks/useScrollHeight';
|
import useScrollHeight from '@/hooks/useScrollHeight';
|
||||||
|
|
||||||
|
@ -46,13 +46,6 @@ const tabList = [
|
||||||
tab: intl.get('脚本'),
|
tab: intl.get('脚本'),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const LangMap: any = {
|
|
||||||
'.py': 'python',
|
|
||||||
'.js': 'javascript',
|
|
||||||
'.mjs': 'typescript',
|
|
||||||
'.sh': 'shell',
|
|
||||||
'.ts': 'typescript',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface LogItem {
|
interface LogItem {
|
||||||
directory: string;
|
directory: string;
|
||||||
|
@ -110,7 +103,7 @@ const CronDetailModal = ({
|
||||||
),
|
),
|
||||||
script: scriptInfo.filename && (
|
script: scriptInfo.filename && (
|
||||||
<Editor
|
<Editor
|
||||||
language={LangMap[scriptInfo.filename.slice(-3)] || ''}
|
language={getEditorMode(scriptInfo.filename)}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
value={value}
|
value={value}
|
||||||
options={{
|
options={{
|
||||||
|
|
8
src/pages/env/index.tsx
vendored
8
src/pages/env/index.tsx
vendored
|
@ -186,7 +186,7 @@ const Env = () => {
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={
|
title={
|
||||||
isPc ? (record.status === Status.已intl.get('禁用') ? intl.get('启用') : intl.get('禁用')) : ''
|
isPc ? (record.status === Status.已禁用 ? intl.get('启用') : intl.get('禁用')) : ''
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<a onClick={() => enabledOrDisabledEnv(record, index)}>
|
<a onClick={() => enabledOrDisabledEnv(record, index)}>
|
||||||
|
@ -232,10 +232,10 @@ const Env = () => {
|
||||||
|
|
||||||
const enabledOrDisabledEnv = (record: any, index: number) => {
|
const enabledOrDisabledEnv = (record: any, index: number) => {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: `确认${record.status === Status.已intl.get('禁用') ? intl.get('启用') : intl.get('禁用')}`,
|
title: `确认${record.status === Status.已禁用 ? intl.get('启用') : intl.get('禁用')}`,
|
||||||
content: (
|
content: (
|
||||||
<>
|
<>
|
||||||
{intl.get('确认')}{record.status === Status.已intl.get('禁用') ? intl.get('启用') : intl.get('禁用')}
|
{intl.get('确认')}{record.status === Status.已禁用 ? intl.get('启用') : intl.get('禁用')}
|
||||||
Env{' '}
|
Env{' '}
|
||||||
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
<Text style={{ wordBreak: 'break-all' }} type="warning">
|
||||||
{record.value}
|
{record.value}
|
||||||
|
@ -254,7 +254,7 @@ const Env = () => {
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success(
|
message.success(
|
||||||
`${record.status === Status.已intl.get('禁用') ? intl.get('启用') : intl.get('禁用')}成功`,
|
`${record.status === Status.已禁用 ? intl.get('启用') : intl.get('禁用')}${intl.get('成功')}`,
|
||||||
);
|
);
|
||||||
const newStatus =
|
const newStatus =
|
||||||
record.status === Status.已禁用 ? Status.已启用 : Status.已禁用;
|
record.status === Status.已禁用 ? Status.已启用 : Status.已禁用;
|
||||||
|
|
|
@ -8,22 +8,9 @@ import Editor from '@monaco-editor/react';
|
||||||
import SaveModal from './saveModal';
|
import SaveModal from './saveModal';
|
||||||
import SettingModal from './setting';
|
import SettingModal from './setting';
|
||||||
import { useTheme } from '@/utils/hooks';
|
import { useTheme } from '@/utils/hooks';
|
||||||
import { logEnded } from '@/utils';
|
import { getEditorMode, logEnded } from '@/utils';
|
||||||
|
|
||||||
const { Option } = Select;
|
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 = ({
|
const EditModal = ({
|
||||||
treeData,
|
treeData,
|
||||||
|
@ -66,7 +53,7 @@ const EditModal = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMode = LangMap[value.slice(-3)] || '';
|
const newMode = getEditorMode(value);
|
||||||
setCNode(node);
|
setCNode(node);
|
||||||
setLanguage(newMode);
|
setLanguage(newMode);
|
||||||
getDetail(node);
|
getDetail(node);
|
||||||
|
@ -146,7 +133,7 @@ const EditModal = ({
|
||||||
setCNode(currentNode);
|
setCNode(currentNode);
|
||||||
setValue(content as string);
|
setValue(content as string);
|
||||||
setSelectedKey(currentNode.key);
|
setSelectedKey(currentNode.key);
|
||||||
const newMode = LangMap[currentNode.title.slice(-3)] || '';
|
const newMode = getEditorMode(currentNode.title);
|
||||||
setLanguage(newMode);
|
setLanguage(newMode);
|
||||||
}
|
}
|
||||||
}, [content, currentNode]);
|
}, [content, currentNode]);
|
||||||
|
|
|
@ -37,7 +37,7 @@ import EditScriptNameModal from './editNameModal';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
import { history, useOutletContext, useLocation } from '@umijs/max';
|
import { history, useOutletContext, useLocation } from '@umijs/max';
|
||||||
import { parse } from 'query-string';
|
import { parse } from 'query-string';
|
||||||
import { depthFirstSearch, findNode } from '@/utils';
|
import { depthFirstSearch, findNode, getEditorMode } from '@/utils';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
import useFilterTreeData from '@/hooks/useFilterTreeData';
|
import useFilterTreeData from '@/hooks/useFilterTreeData';
|
||||||
import uniq from 'lodash/uniq';
|
import uniq from 'lodash/uniq';
|
||||||
|
@ -46,14 +46,6 @@ import RenameModal from './renameModal';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
const LangMap: any = {
|
|
||||||
'.py': 'python',
|
|
||||||
'.js': 'javascript',
|
|
||||||
'.mjs': 'typescript',
|
|
||||||
'.sh': 'shell',
|
|
||||||
'.ts': 'typescript',
|
|
||||||
};
|
|
||||||
|
|
||||||
const Script = () => {
|
const Script = () => {
|
||||||
const { headerStyle, isPhone, theme, socketMessage } =
|
const { headerStyle, isPhone, theme, socketMessage } =
|
||||||
useOutletContext<SharedContext>();
|
useOutletContext<SharedContext>();
|
||||||
|
@ -134,7 +126,7 @@ const Script = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMode = value ? LangMap[value.slice(-3)] : '';
|
const newMode = getEditorMode(value);
|
||||||
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode);
|
||||||
setValue(intl.get('加载中...'));
|
setValue(intl.get('加载中...'));
|
||||||
getDetail(node);
|
getDetail(node);
|
||||||
|
|
|
@ -1 +1,9 @@
|
||||||
export const LOG_END_SYMBOL = ' ';
|
export const LOG_END_SYMBOL = ' ';
|
||||||
|
|
||||||
|
export const LANG_MAP = {
|
||||||
|
'.py': 'python',
|
||||||
|
'.js': 'javascript',
|
||||||
|
'.mjs': 'javascript',
|
||||||
|
'.sh': 'shell',
|
||||||
|
'.ts': 'typescript',
|
||||||
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { LOG_END_SYMBOL } from './const';
|
import { LANG_MAP, LOG_END_SYMBOL } from './const';
|
||||||
import cron_parser from 'cron-parser';
|
import cron_parser from 'cron-parser';
|
||||||
|
|
||||||
export default function browserType() {
|
export default function browserType() {
|
||||||
|
@ -154,9 +154,9 @@ export default function browserType() {
|
||||||
shell === 'none'
|
shell === 'none'
|
||||||
? {}
|
? {}
|
||||||
: {
|
: {
|
||||||
shell, // wechat qq uc 360 2345 sougou liebao maxthon
|
shell, // wechat qq uc 360 2345 sougou liebao maxthon
|
||||||
shellVs,
|
shellVs,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -335,7 +335,18 @@ export function parseCrontab(schedule: string): Date {
|
||||||
if (time) {
|
if (time) {
|
||||||
return time.next().toDate();
|
return time.next().toDate();
|
||||||
}
|
}
|
||||||
} catch (error) {}
|
} catch (error) { }
|
||||||
|
|
||||||
return new Date('1970');
|
return new Date('1970');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getExtension(filename: string) {
|
||||||
|
if (!filename) return '';
|
||||||
|
const arr = filename.split('.');
|
||||||
|
return `.${arr[arr.length - 1]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getEditorMode(filename: string) {
|
||||||
|
const extension = getExtension(filename) as keyof typeof LANG_MAP;
|
||||||
|
return LANG_MAP[extension];
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user