mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 11:56:08 +08:00
修复任务脚本快捷跳转
This commit is contained in:
parent
3afb1d18f6
commit
095fcdbe69
|
@ -29,6 +29,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';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
|
@ -147,22 +148,10 @@ const CronDetailModal = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const getScript = () => {
|
const getScript = () => {
|
||||||
const cmd = cron.command.split(' ') as string[];
|
const result = getCommandScript(cron.command);
|
||||||
if (cmd[0] === 'task') {
|
if (Array.isArray(result)) {
|
||||||
setValidTabs(validTabs);
|
setValidTabs(validTabs);
|
||||||
if (cmd[1].startsWith('/ql/data/scripts')) {
|
const [s, p] = result;
|
||||||
cmd[1] = cmd[1].replace('/ql/data/scripts/', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
let p: string, s: string;
|
|
||||||
let index = cmd[1].lastIndexOf('/');
|
|
||||||
if (index >= 0) {
|
|
||||||
s = cmd[1].slice(index + 1);
|
|
||||||
p = cmd[1].slice(0, index);
|
|
||||||
} else {
|
|
||||||
s = cmd[1];
|
|
||||||
p = '';
|
|
||||||
}
|
|
||||||
setScriptInfo({ parent: p, filename: s });
|
setScriptInfo({ parent: p, filename: s });
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`)
|
.get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`)
|
||||||
|
@ -171,7 +160,7 @@ const CronDetailModal = ({
|
||||||
setValue(data);
|
setValue(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else if (result) {
|
||||||
setValidTabs([validTabs[0]]);
|
setValidTabs([validTabs[0]]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,6 +50,7 @@ import ViewManageModal from './viewManageModal';
|
||||||
import { FilterValue, SorterResult } from 'antd/lib/table/interface';
|
import { FilterValue, SorterResult } from 'antd/lib/table/interface';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
||||||
|
import { getCommandScript } from '@/utils';
|
||||||
|
|
||||||
const { Text, Paragraph } = Typography;
|
const { Text, Paragraph } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
|
@ -390,24 +391,12 @@ const Crontab = () => {
|
||||||
const tableScrollHeight = useTableScrollHeight(tableRef);
|
const tableScrollHeight = useTableScrollHeight(tableRef);
|
||||||
|
|
||||||
const goToScriptManager = (record: any) => {
|
const goToScriptManager = (record: any) => {
|
||||||
const cmd = record.command.split(' ') as string[];
|
const result = getCommandScript(record.command);
|
||||||
if (cmd[0] === 'task') {
|
if (Array.isArray(result)) {
|
||||||
if (cmd[1].startsWith('/ql/data/scripts')) {
|
const [s, p] = result;
|
||||||
cmd[1] = cmd[1].replace('/ql/data/scripts/', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
let p: string, s: string;
|
|
||||||
let index = cmd[1].lastIndexOf('/');
|
|
||||||
if (index >= 0) {
|
|
||||||
s = cmd[1].slice(index + 1);
|
|
||||||
p = cmd[1].slice(0, index);
|
|
||||||
} else {
|
|
||||||
s = cmd[1];
|
|
||||||
p = '';
|
|
||||||
}
|
|
||||||
history.push(`/script?p=${p}&s=${s}`);
|
history.push(`/script?p=${p}&s=${s}`);
|
||||||
} else if (cmd[1] === 'repo') {
|
} else if (result) {
|
||||||
location.href = cmd[2];
|
location.href = result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -276,3 +276,31 @@ export function logEnded(log: string): boolean {
|
||||||
const endTips = [LOG_END_SYMBOL, '执行结束'];
|
const endTips = [LOG_END_SYMBOL, '执行结束'];
|
||||||
return endTips.some((x) => log.includes(x));
|
return endTips.some((x) => log.includes(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCommandScript(
|
||||||
|
command: string,
|
||||||
|
): [string, string] | string | undefined {
|
||||||
|
const cmd = command.split(' ') as string[];
|
||||||
|
if (cmd[0] === 'task') {
|
||||||
|
let scriptsPart = cmd.find((x) =>
|
||||||
|
['.js', '.ts', '.sh', '.py'].some((y) => x.endsWith(y)),
|
||||||
|
);
|
||||||
|
if (!scriptsPart) return;
|
||||||
|
if (scriptsPart.startsWith('/ql/data/scripts')) {
|
||||||
|
scriptsPart = scriptsPart.replace('/ql/data/scripts/', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
let p: string, s: string;
|
||||||
|
let index = scriptsPart.lastIndexOf('/');
|
||||||
|
if (index >= 0) {
|
||||||
|
s = scriptsPart.slice(index + 1);
|
||||||
|
p = scriptsPart.slice(0, index);
|
||||||
|
} else {
|
||||||
|
s = scriptsPart;
|
||||||
|
p = '';
|
||||||
|
}
|
||||||
|
return [s, p];
|
||||||
|
} else if (cmd[1] === 'repo') {
|
||||||
|
return cmd[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user