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

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,18 +72,53 @@ 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 = () => {
setLog('');
request
.put(`${config.apiPrefix}scripts/run`, {
data: {
filename: cNode.value,
path: cNode.parent || '',
},
})
.then((data) => {
setIsRunning(true);
});
autoSave.save().then(() => {
request
.put(`${config.apiPrefix}scripts/run`, {
data: {
filename: cNode.value,
path: cNode.parent || '',
},
})
.then((data) => {
setIsRunning(true);
});
})
};
const stop = () => {

View File

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