前端 - 调试 - 运行脚本时自动保存

This commit is contained in:
langren1353 2022-03-08 22:25:05 +08:00
parent 75012189c3
commit 4b23d25e0a
2 changed files with 46 additions and 10 deletions

View File

@ -72,8 +72,42 @@ const EditModal = ({
}); });
}; };
class AutoSave {
private id: any;
constructor() {
this.id = ''
}
start() {
this.id = setInterval(async() => await this.save, 3000)
}
stop() {
clearInterval(this.id)
}
async save() {
const payload = {
content: editorRef.current && editorRef.current.getValue().replace(/\r\n/g, '\n'),
filename: cNode?.value,
originFilename: cNode?.value,
path: cNode?.parent
}
return request.post(`${config.apiPrefix}scripts`, {
data: payload,
})
}
}
const autoSave = new AutoSave();
if (visible) {
autoSave.start()
} else {
autoSave.stop()
}
const run = () => { const run = () => {
setLog(''); setLog('');
autoSave.save().then(() => {
request request
.put(`${config.apiPrefix}scripts/run`, { .put(`${config.apiPrefix}scripts/run`, {
data: { data: {
@ -84,6 +118,7 @@ const EditModal = ({
.then((data) => { .then((data) => {
setIsRunning(true); setIsRunning(true);
}); });
})
}; };
const stop = () => { const stop = () => {

View File

@ -552,6 +552,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => {
socketMessage={socketMessage} socketMessage={socketMessage}
handleCancel={() => { handleCancel={() => {
setIsLogModalVisible(false); setIsLogModalVisible(false);
getDetail(currentNode);
}} }}
/> />
<EditScriptNameModal <EditScriptNameModal