add debounce

This commit is contained in:
lhx-666-cool
2025-04-25 21:35:35 +08:00
parent c8ced21ae7
commit 37320b982c
2 changed files with 16 additions and 6 deletions

View File

@@ -1,2 +0,0 @@
VITE_BACKEND="https://example.com"
VITE_LSP_SERVER="wss://example.com/cpp"

View File

@@ -23,8 +23,9 @@
</div> </div>
<div class="flex-1 min-h-0 "> <div class="flex-1 min-h-0 ">
<div class="w-full h-full overflow-hidden"> <div class="w-full h-full overflow-hidden">
<textarea name="stdin" id="stdin" class="w-full h-full resize-none outline-none border-0 p-2 whitespace-nowrap" <textarea name="stdin" id="stdin"
placeholder="请输入测试样例" v-model="stdin"></textarea> class="w-full h-full resize-none outline-none border-0 p-2 whitespace-nowrap" placeholder="请输入测试样例"
v-model="stdin"></textarea>
</div> </div>
</div> </div>
</div> </div>
@@ -82,8 +83,10 @@ const status = ref('completed')
const stderr = ref('') const stderr = ref('')
const time = ref(0) const time = ref(0)
const log = ref('') const log = ref('')
const serverUri = window.CONFIG.LSP_SERVER !== '__LSP_SERVER_URL_PLACEHOLDER__'? window.CONFIG.LSP_SERVER : import.meta.env.VITE_LSP_SERVER; const isLoading = ref(false)
const backend = window.CONFIG.BACKEND !== '__BACKEND_URL_PLACEHOLDER__'? window.CONFIG.BACKEND : import.meta.env.VITE_BACKEND;
const serverUri = window.CONFIG.LSP_SERVER !== '__LSP_SERVER_URL_PLACEHOLDER__' ? window.CONFIG.LSP_SERVER : import.meta.env.VITE_LSP_SERVER;
const backend = window.CONFIG.BACKEND !== '__BACKEND_URL_PLACEHOLDER__' ? window.CONFIG.BACKEND : import.meta.env.VITE_BACKEND;
const ls = languageServer({ const ls = languageServer({
serverUri, serverUri,
rootUri: 'file:///main.cpp', rootUri: 'file:///main.cpp',
@@ -136,6 +139,7 @@ onMounted(() => {
}) })
console.log(props.id) console.log(props.id)
if (props.id !== null && props.id !== undefined && props.id !== '') { if (props.id !== null && props.id !== undefined && props.id !== '') {
isLoading.value = true
fetch(backend + `/api/pastes/${props.id}`) fetch(backend + `/api/pastes/${props.id}`)
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
@@ -157,8 +161,11 @@ onMounted(() => {
getStatus(props.id) getStatus(props.id)
if (status.value !== 'pending' && status.value !== 'running') { if (status.value !== 'pending' && status.value !== 'running') {
clearInterval(timer) clearInterval(timer)
isLoading.value = false
} }
}, 1000) }, 1000)
}else {
isLoading.value = false
} }
}) })
.catch(err => { .catch(err => {
@@ -169,6 +176,11 @@ onMounted(() => {
}) })
const handleRun = (isRun: boolean) => { const handleRun = (isRun: boolean) => {
if (isLoading.value) {
console.log("别急")
return
}
isLoading.value = true
console.log('run') console.log('run')
fetch(backend + '/api/pastes', { fetch(backend + '/api/pastes', {
method: 'POST', method: 'POST',