var currentStep = 1; var hasNewVer = false; //步骤 function dedeAlter(msg, t = 'info', loading = false) { let loadingStr = loading ? '' : ''; return `
${loadingStr} ${msg}
`; } //显示步骤区域 function showStepArea(step) { $(".stepArea").hide(); $(".btnStep").hide(); $("#stepArea" + step).show(); $("#btnStep" + step).show(); } function update() { $.get("api.php?action=update", function (rs) { if (rs.code === 0) { $("#_updateMsg").html(rs.msg); if (rs.data.finish === false) { setTimeout(() => { update(); }, 500); } else { currentStep++ $("#_msgInfo").html(''); $("#_msgInfo").hide(); showStepArea(currentStep); } } }) } function hasNewVersion() { $.get("api.php?action=has_new_version", function (rs) { try { if (rs.code === 0) { if (rs.result.HasNew === true) { hasNewVer = true; $(".updates-dot").show(); } else { hasNewVer = false; $(".updates-dot").hide(); } } else { $(".updates-dot").hide(); showStepArea(0); } } catch (error) { console.log("获取软件信息失败") } }) } $(document).ready(function () { hasNewVersion(); $("#btnCancel").click(function () { currentStep = 1; $("#_fileList").html(``); }) $("#btnBackup").click(function () { let alertMsg = dedeAlter("正在备份差异文件", 'info', true); $("#_msgInfo").html(alertMsg); $("#_msgInfo").show(); $.get("api.php?action=update_backup", function (rs) { if (rs.code === 0) { alertMsg = dedeAlter(`成功备份差异文件,目录:${rs.data.backupdir}`, 'success'); $("#_msgInfo").html(alertMsg); } }) }) $("#systemUpdate").click(function () { if (hasNewVer === false) { currentStep = 5; showStepArea(currentStep); $('#mdlUpdate').modal('show'); return; } $('#mdlUpdate').modal('show'); showStepArea(currentStep); currentStep++; $.get("api.php?action=get_changed_files", function (rs) { if (rs.code === 0) { let fstr = ''; $("#_fileList").html(fstr); showStepArea(currentStep); } else { showStepArea(0); } }) }) $('#mdlUpdate').on('hidden.bs.modal', function (event) { currentStep = 1; $("#_msgInfo").html(''); $("#_msgInfo").hide(); }) $("#btnGoStep3").click(function () { currentStep++ $("#_msgInfo").html(''); $("#_msgInfo").hide(); showStepArea(currentStep); $.get("api.php?action=get_update_versions", function (rs) { if (rs.code === 0) { let fstr = ''; $("#_verList").html(fstr); } else { showStepArea(0); } }) }) $("#btnGoStep4").click(function () { currentStep++ $("#_msgInfo").html(''); $("#_msgInfo").hide(); showStepArea(currentStep); update(); }) $("#btnOK").click(function () { hasNewVersion(); }) })