Skip to content

Commit 78698d3

Browse files
committed
fix: console.clear command exec
1 parent 77911f3 commit 78698d3

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/App.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ class App extends Component {
103103
}
104104
// 绑定监听事件
105105
on('network', data => addNetworkLog(data));
106-
on('console', data => sessionLog.push(data));
106+
on('console', data => {
107+
const { type } = data;
108+
if (type === 'clear') {
109+
sessionLog.splice(0, sessionLog.length);
110+
return;
111+
}
112+
sessionLog.push(data)
113+
});
107114
on('addPlugin', plugin => this.updatePlugin(plugin));
108115
on('removePlugin', pluginId => this.removePlugin(pluginId));
109116
on('clearproxy', () => {

src/panels/console/index.jsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { noop } from '@/utils/shared';
66
import MdebugPrinter from '@/components/printer';
77
import { change } from '@/utils/console';
88

9-
const { off, on } = emitter;
9+
const { off, on, trigger: emit } = emitter;
1010

1111
class Console extends PureComponent {
1212
constructor(props) {
@@ -21,7 +21,7 @@ class Console extends PureComponent {
2121
commandKeyWords: '',
2222
};
2323
this.updateLog = this.updateLog.bind(this);
24-
this.updateUnShiftLog = this.updateUnShiftLog.bind(this);
24+
this.updateCommandLog = this.updateCommandLog.bind(this);
2525
this.onSelectTab = this.onSelectTab.bind(this);
2626
this.onChange = this.onChange.bind(this);
2727
this.getSubSelected = this.getSubSelected.bind(this);
@@ -38,8 +38,8 @@ class Console extends PureComponent {
3838
tabName,
3939
});
4040
}
41-
updateUnShiftLog() {
42-
const { consolelog, commandKeyWords } = this.state;
41+
updateCommandLog() {
42+
const { commandKeyWords } = this.state;
4343
if (!commandKeyWords) {
4444
return;
4545
}
@@ -49,14 +49,10 @@ class Console extends PureComponent {
4949
} catch (err) {
5050
evalValue = commandKeyWords;
5151
}
52-
const data = {
52+
emit('console', {
5353
type: 'info',
5454
value: [evalValue],
5555
timestamp: new Date().getTime(),
56-
};
57-
sessionLog.unshift(data);
58-
this.setState({
59-
consolelog: [data, ...consolelog],
6056
});
6157
}
6258
updateLog() {
@@ -134,7 +130,7 @@ class Console extends PureComponent {
134130
</div>
135131
<div
136132
className={styles.mdebugConsoleCommandTag}
137-
onClick={this.updateUnShiftLog}
133+
onClick={this.updateCommandLog}
138134
style={{
139135
color: command === 'command' ? '#000' : undefined,
140136
}}>

src/polyfill.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const proxyConsole = () => {
3636
fakeConsole[method].apply(window.console, rest);
3737
};
3838
});
39+
40+
// 处理清除函数
41+
console.clear = () => {
42+
emit('console', {
43+
type: 'clear',
44+
timestamp: new Date().getTime(),
45+
});
46+
fakeConsole.clear.apply(window.console);
47+
}
3948
};
4049
const proxyAjax = () => {
4150
const fakeAjax = Object.create(null);
@@ -451,4 +460,4 @@ export const init = () => {
451460
proxyError();
452461
proxyResources();
453462
proxyWebSocket();
454-
};
463+
};

0 commit comments

Comments
 (0)