mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-28 07:06:06 +08:00
前端 - 调试 - 运行脚本时自动保存
This commit is contained in:
parent
75012189c3
commit
4b23d25e0a
|
@ -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 = () => {
|
||||
|
|
|
@ -552,6 +552,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => {
|
|||
socketMessage={socketMessage}
|
||||
handleCancel={() => {
|
||||
setIsLogModalVisible(false);
|
||||
getDetail(currentNode);
|
||||
}}
|
||||
/>
|
||||
<EditScriptNameModal
|
||||
|
|
Loading…
Reference in New Issue
Block a user