mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-28 23:46: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 = () => {
|
const run = () => {
|
||||||
setLog('');
|
setLog('');
|
||||||
request
|
autoSave.save().then(() => {
|
||||||
.put(`${config.apiPrefix}scripts/run`, {
|
request
|
||||||
data: {
|
.put(`${config.apiPrefix}scripts/run`, {
|
||||||
filename: cNode.value,
|
data: {
|
||||||
path: cNode.parent || '',
|
filename: cNode.value,
|
||||||
},
|
path: cNode.parent || '',
|
||||||
})
|
},
|
||||||
.then((data) => {
|
})
|
||||||
setIsRunning(true);
|
.then((data) => {
|
||||||
});
|
setIsRunning(true);
|
||||||
|
});
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user