mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-17 09:34:31 +08:00
移除任务执行前后的脚本参数
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import intl from 'react-intl-universal';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import CodeMirror from '@uiw/react-codemirror';
|
||||
import { Button, DatePicker, Empty, message, Spin } from 'antd';
|
||||
@@ -9,6 +10,13 @@ import { request } from '@/utils/http';
|
||||
import config from '@/utils/config';
|
||||
import { useRequest } from 'ahooks';
|
||||
import moment from 'moment';
|
||||
import {
|
||||
systemLogDebugHighlightPlugin,
|
||||
systemLogErrorHighlightPlugin,
|
||||
systemLogInfoHighlightPlugin,
|
||||
systemLogTheme,
|
||||
systemLogWarnHighlightPlugin,
|
||||
} from '@/utils/codemirror/systemLog';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
@@ -83,7 +91,7 @@ const SystemLog = ({ height, theme }: any) => {
|
||||
deleteLog();
|
||||
}}
|
||||
>
|
||||
清空日志
|
||||
{intl.get('清空日志')}
|
||||
</Button>
|
||||
</div>
|
||||
{systemLogData ? (
|
||||
@@ -94,6 +102,13 @@ const SystemLog = ({ height, theme }: any) => {
|
||||
onCreateEditor={(view) => {
|
||||
editorRef.current = view;
|
||||
}}
|
||||
extensions={[
|
||||
systemLogDebugHighlightPlugin,
|
||||
systemLogErrorHighlightPlugin,
|
||||
systemLogInfoHighlightPlugin,
|
||||
systemLogWarnHighlightPlugin,
|
||||
systemLogTheme,
|
||||
]}
|
||||
readOnly={true}
|
||||
theme={theme.includes('dark') ? 'dark' : 'light'}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import {
|
||||
Decoration,
|
||||
EditorView,
|
||||
ViewPlugin,
|
||||
ViewUpdate,
|
||||
} from '@codemirror/view';
|
||||
import { RangeSet, RangeSetBuilder } from '@codemirror/state';
|
||||
|
||||
const infoWord = /\[\ue6f5info\]/g;
|
||||
const debugWord = /\[\ue67fdebug\]/g;
|
||||
const warnWord = /\[\ue880warn\]/g;
|
||||
const errorWord = /\[\ue602error\]/g;
|
||||
|
||||
const customWordClassMap = {
|
||||
info: 'system-log-info',
|
||||
warn: 'system-warn-info',
|
||||
error: 'system-error-info',
|
||||
debug: 'system-debug-info',
|
||||
};
|
||||
|
||||
export const systemLogInfoHighlightPlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: RangeSet<Decoration>;
|
||||
|
||||
constructor(view: EditorView) {
|
||||
this.decorations = this.getDecorations(view);
|
||||
}
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (update.docChanged) {
|
||||
this.decorations = this.getDecorations(update.view);
|
||||
}
|
||||
}
|
||||
|
||||
getDecorations(view: EditorView) {
|
||||
const builder = new RangeSetBuilder<Decoration>();
|
||||
const doc = view.state.doc.toString();
|
||||
let match;
|
||||
|
||||
while ((match = infoWord.exec(doc)) !== null) {
|
||||
const deco = Decoration.mark({
|
||||
class: customWordClassMap.info,
|
||||
});
|
||||
|
||||
builder.add(match.index, match.index + match[0].length, deco);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
},
|
||||
{
|
||||
decorations: (v) => v.decorations,
|
||||
},
|
||||
);
|
||||
|
||||
export const systemLogWarnHighlightPlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: RangeSet<Decoration>;
|
||||
|
||||
constructor(view: EditorView) {
|
||||
this.decorations = this.getDecorations(view);
|
||||
}
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (update.docChanged) {
|
||||
this.decorations = this.getDecorations(update.view);
|
||||
}
|
||||
}
|
||||
|
||||
getDecorations(view: EditorView) {
|
||||
const builder = new RangeSetBuilder<Decoration>();
|
||||
const doc = view.state.doc.toString();
|
||||
let match;
|
||||
|
||||
while ((match = warnWord.exec(doc)) !== null) {
|
||||
const deco = Decoration.mark({
|
||||
class: customWordClassMap.warn,
|
||||
});
|
||||
|
||||
builder.add(match.index, match.index + match[0].length, deco);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
},
|
||||
{
|
||||
decorations: (v) => v.decorations,
|
||||
},
|
||||
);
|
||||
|
||||
export const systemLogDebugHighlightPlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: RangeSet<Decoration>;
|
||||
|
||||
constructor(view: EditorView) {
|
||||
this.decorations = this.getDecorations(view);
|
||||
}
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (update.docChanged) {
|
||||
this.decorations = this.getDecorations(update.view);
|
||||
}
|
||||
}
|
||||
|
||||
getDecorations(view: EditorView) {
|
||||
const builder = new RangeSetBuilder<Decoration>();
|
||||
const doc = view.state.doc.toString();
|
||||
let match;
|
||||
|
||||
while ((match = debugWord.exec(doc)) !== null) {
|
||||
const deco = Decoration.mark({
|
||||
class: customWordClassMap.debug,
|
||||
});
|
||||
|
||||
builder.add(match.index, match.index + match[0].length, deco);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
},
|
||||
{
|
||||
decorations: (v) => v.decorations,
|
||||
},
|
||||
);
|
||||
|
||||
export const systemLogErrorHighlightPlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
decorations: RangeSet<Decoration>;
|
||||
|
||||
constructor(view: EditorView) {
|
||||
this.decorations = this.getDecorations(view);
|
||||
}
|
||||
|
||||
update(update: ViewUpdate) {
|
||||
if (update.docChanged) {
|
||||
this.decorations = this.getDecorations(update.view);
|
||||
}
|
||||
}
|
||||
|
||||
getDecorations(view: EditorView) {
|
||||
const builder = new RangeSetBuilder<Decoration>();
|
||||
const doc = view.state.doc.toString();
|
||||
let match;
|
||||
|
||||
while ((match = errorWord.exec(doc)) !== null) {
|
||||
const deco = Decoration.mark({
|
||||
class: customWordClassMap.error,
|
||||
});
|
||||
|
||||
builder.add(match.index, match.index + match[0].length, deco);
|
||||
}
|
||||
|
||||
return builder.finish();
|
||||
}
|
||||
},
|
||||
{
|
||||
decorations: (v) => v.decorations,
|
||||
},
|
||||
);
|
||||
|
||||
export const systemLogTheme = EditorView.baseTheme({
|
||||
'.system-log-info': {
|
||||
color: '#2196F3',
|
||||
},
|
||||
'.system-warn-info': {
|
||||
color: '#FFB827',
|
||||
},
|
||||
'.system-error-info': {
|
||||
color: '#FA5151',
|
||||
},
|
||||
'.system-debug-info': {
|
||||
color: '#009A29',
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user