/** * 班级操行分管理系统 - 系统设置页JS * * 开发者: Canglan * 版权归属: Sea Network Technology Studio * * 版权所有 © Sea Network Technology Studio */ (function() { 'use strict'; async function loadPasswordPolicy() { const res = await apiGet('/api/admin/settings/password-policy'); if (!res || !res.success) { showToast((res && res.message) || '获取密码策略失败', 'error'); return; } document.getElementById('pwdMinLength').value = res.data.min_length; document.getElementById('pwdMaxLength').value = res.data.max_length; document.getElementById('pwdMinTypes').value = res.data.min_types; applyPolicyGlobals(res.data); } function applyPolicyGlobals(policy) { window.PASSWORD_MIN_LENGTH = policy.min_length; window.PASSWORD_MAX_LENGTH = policy.max_length; window.PASSWORD_MIN_TYPES = policy.min_types; document.querySelectorAll('.pwd-policy').forEach(function(el) { el.textContent = describePasswordPolicy(); }); } async function savePasswordPolicy() { const minLength = parseInt(document.getElementById('pwdMinLength').value); const maxLength = parseInt(document.getElementById('pwdMaxLength').value); const minTypes = parseInt(document.getElementById('pwdMinTypes').value); if (isNaN(minLength) || isNaN(maxLength) || isNaN(minTypes)) { showToast('请填写完整的密码策略', 'warning'); return; } if (minLength < 4 || minLength > 64) { showToast('最小长度需在4-64之间', 'warning'); return; } if (maxLength < 8 || maxLength > 100) { showToast('最大长度需在8-100之间', 'warning'); return; } if (minLength > maxLength) { showToast('最小长度不能大于最大长度', 'warning'); return; } if (minTypes < 1 || minTypes > 4) { showToast('字符种类数需在1-4之间', 'warning'); return; } const res = await apiPut('/api/admin/settings/password-policy', { min_length: minLength, max_length: maxLength, min_types: minTypes }); if (res && res.success) { applyPolicyGlobals({ min_length: minLength, max_length: maxLength, min_types: minTypes }); showToast(res.message || '密码策略已保存'); } else { showToast((res && res.message) || '保存失败', 'error'); } } document.getElementById('passwordPolicyForm').addEventListener('submit', function(e) { e.preventDefault(); savePasswordPolicy(); }); loadPasswordPolicy(); window.savePasswordPolicy = savePasswordPolicy; })();