Skip to content

Multiple identical requests appear when requesting the backend to obtain data #197

@YL-Zhang1

Description

@YL-Zhang1
Image

saveButton.addEventListener('click', async () => {
if (isSaving) return; // 如果正在保存,直接返回
isSaving = true; // 开始保存,设置请求锁
const dc = dcInput.value;
const node = nodeInput.value;
const subSystem = subSystemInput.value;
const faultPoint = faultPointInput.value;
const errTime = errTimeInput.value;
const dealTime = dealTimeInput.value;
const statusRadio = htmlNode.querySelector('input[name="status"]:checked').value;
const comments = commentsInput.value;
if (!dc) {
alert('电厂不能为空,请填写完整。');
isSaving = false; // 解除请求锁
return;
}

if (!node) {
    alert('节点不能为空,请填写完整。');
    isSaving = false; // 解除请求锁
    return;
}
if (statusRadio!=="0"&& !dealTime){
    alert('请选择处理时间');
    isSaving = false; // 解除请求锁
    return;
}
if (!errTime) {
    alert('请选择故障时间');
    isSaving = false; // 解除请求锁
    return;
}
if (!statusRadio) {
    alert('请选择处理状态');
    isSaving = false; // 解除请求锁
    return;
}
if (modalTitle.textContent === '新增记录') {
    const manufacturer = manufacturerInput.value;
    if (!manufacturer) {
        alert('机器型号不能为空,请填写完整。');
        isSaving = false; // 解除请求锁
        return;
    }
    const node_type = nodeTypeSelect.value;
    try {
        const response = await fetch('/v1/module/node_rsc_unhealth_manager', {
            method: 'POST',
            headers: {
                'token': `wkqyssr32Wz4orxoWsmj1ec7uulhfy`,
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                type: "add",
                dc: dc,
                node: node,
                manufacturer: manufacturer,
                node_type: node_type,
                status: statusRadio,
                operation_user: statusRadio !== '0' ? window.grafanaBootData.user.name  : '',
                sub_system: subSystem,
                err_time: errTime,
                deal_time: dealTime,
                comments: comments,
                fault_point: faultPoint
            })
        });
        if (!response.ok) {
            const return_data = await response.json()
            const errmsg = return_data.err
            throw new Error(errmsg);
        }
        fetchData()
    } catch (error) {
        alert('新增记录时出错:' + error.message);
        closeModal()
        fetchData()
        return;
    } finally {
        isSaving = false; // 解除请求锁
    }
} else {
    const editId = sessionStorage.getItem('editId');
    try {
        const response = await fetch('/v1/module/node_rsc_unhealth_manager', {
            method: 'POST',
            headers: {
                'token': `wkqyssr32Wz4orxoWsmj1ec7uulhfy`,
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                type: "edit",
                id: editId,
                dc: dc,
                node: node,
                status: statusRadio,
                operation_user: statusRadio !== '0' ? window.grafanaBootData.user.name  : '',
                apply_user: window.grafanaBootData.user.name,
                sub_system: subSystem,
                err_time: errTime,
                deal_time: dealTime,
                comments: comments,
                fault_point: faultPoint
            })
        });
        if (!response.ok) {
            const return_data = await response.json()
            const errmsg = return_data.err
            throw new Error(errmsg);
        }
        fetchData(currentPage)
    } catch (error) {
        alert('修改记录时出错:' + error.message);
        closeModal()
        fetchData()
        return;
    } finally {
        isSaving = false; // 解除请求锁
    }
}

closeModal();
renderTable();
renderPagination();

});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions