v4.0 权限组重构与导出/个人查询优化
1. 权限重构:自定义权限组(14项功能权限+允许加分/加分上限/允许扣分/扣分上限),管理员账号绑定权限组,预置六组且班主任组锁定;全站前后端改为权限驱动,权限变更60秒内自动生效 2. 新增班主任导出学生名单(导出前自选字段) 3. 加减分/考勤上限改为按权限组动态校验,弹窗实时提示并限制输入 4. 导出按学期隔离(默认当前学期,可选历史/全部),历史导出不再受1000条限制 5. 新增管理端个人查询:基础分/加分/扣分/月度分/月度理由汇总及明细导出 6. 版本升级至4.0(sql/upgrades/v4.0.sql)
This commit is contained in:
1 parent
3067542e53
commit
3588b4c28c
55 files changed
+2846
-801
No files matched your search
@@ -112,6 +112,161 @@ function apiDelete(url) {
|
||||
return apiRequest(url, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页拉取接口全部记录(用于导出等需要完整数据的场景)
|
||||
* @param {string} url 接口地址
|
||||
* @param {object} params 查询参数(page/page_size 会被自动覆盖)
|
||||
* @returns {Promise<Array>} 全部记录
|
||||
*/
|
||||
async function apiGetAll(url, params = {}) {
|
||||
const allRecords = [];
|
||||
const pageSize = 1000;
|
||||
let page = 1;
|
||||
while (page <= 100) {
|
||||
const pageParams = { ...params, page: page, page_size: pageSize };
|
||||
const res = await apiGet(url, pageParams);
|
||||
if (!res || !res.success || !res.data || !Array.isArray(res.data.records)) {
|
||||
break;
|
||||
}
|
||||
allRecords.push(...res.data.records);
|
||||
const total = res.data.total || 0;
|
||||
if (allRecords.length >= total || res.data.records.length < pageSize) {
|
||||
break;
|
||||
}
|
||||
page++;
|
||||
}
|
||||
return allRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* CSV字段转义
|
||||
*/
|
||||
function csvEscape(value) {
|
||||
if (value === null || value === undefined) return '';
|
||||
let str = String(value).replace(/[\r\n]+/g, ' ');
|
||||
str = str.replace(/"/g, '""');
|
||||
if (/[\,\;\"\s]/.test(str)) {
|
||||
str = '"' + str + '"';
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载CSV文件(自动添加BOM以兼容Excel)
|
||||
*/
|
||||
function downloadCsv(filename, csvContent) {
|
||||
const blob = new Blob(['\uFEFF' + csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载学期下拉选项
|
||||
* @param {string|HTMLElement} select 下拉框DOM或ID
|
||||
* @param {object} options { includeAll: 是否包含"全部学期", selectedValue: 默认选中值 }
|
||||
* @returns {Promise<Array>} 学期列表
|
||||
*/
|
||||
async function loadSemesterOptions(select, options = {}) {
|
||||
const el = typeof select === 'string' ? document.getElementById(select) : select;
|
||||
if (!el) return [];
|
||||
const res = await apiGet('/api/semester/options');
|
||||
const semesters = (res && res.success && Array.isArray(res.data)) ? res.data : [];
|
||||
const sorted = semesters.slice().sort((a, b) => (b.is_active ? 1 : 0) - (a.is_active ? 1 : 0));
|
||||
const includeAll = options.includeAll !== false;
|
||||
let html = includeAll ? '<option value="">全部学期</option>' : '';
|
||||
sorted.forEach(s => {
|
||||
const suffix = s.is_active ? '(当前)' : (s.is_archived ? '(已归档)' : '');
|
||||
html += '<option value="' + s.semester_id + '">' + escapeHtml(s.semester_name + suffix) + '</option>';
|
||||
});
|
||||
el.innerHTML = html;
|
||||
let value = options.selectedValue;
|
||||
if (value === undefined) {
|
||||
const active = sorted.find(s => s.is_active);
|
||||
value = active ? active.semester_id : '';
|
||||
}
|
||||
el.value = (value === null || value === undefined) ? '' : String(value);
|
||||
return semesters;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前用户是否拥有指定权限
|
||||
*/
|
||||
function hasPermission(perm) {
|
||||
return !!(window.USER_PERMISSIONS && window.USER_PERMISSIONS[perm]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前权限组加减分上限配置
|
||||
*/
|
||||
function getScoreLimits() {
|
||||
return window.USER_SCORE_LIMITS || {
|
||||
can_add: true, max_add: null,
|
||||
can_subtract: true, max_subtract: null
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成加减分上限提示文本
|
||||
*/
|
||||
function describeScoreLimits() {
|
||||
const limits = getScoreLimits();
|
||||
if (!limits.can_add && !limits.can_subtract) return '当前权限组不允许加减分';
|
||||
if (!limits.can_add) {
|
||||
return '仅限扣分' + (limits.max_subtract ? (',单次最多扣' + limits.max_subtract + '分') : '');
|
||||
}
|
||||
if (!limits.can_subtract) {
|
||||
return '仅限加分' + (limits.max_add ? (',单次最多加' + limits.max_add + '分') : '');
|
||||
}
|
||||
const parts = [];
|
||||
parts.push(limits.max_add ? ('单次加分上限' + limits.max_add + '分') : '加分无限制');
|
||||
parts.push(limits.max_subtract ? ('单次扣分上限' + limits.max_subtract + '分') : '扣分无限制');
|
||||
return parts.join(',');
|
||||
}
|
||||
|
||||
/**
|
||||
* 将权限组上限应用到分数输入框(min/max)
|
||||
*/
|
||||
function applyScoreLimits(inputEl) {
|
||||
if (!inputEl) return;
|
||||
const limits = getScoreLimits();
|
||||
if (limits.max_add !== null && limits.max_add !== undefined) {
|
||||
inputEl.max = limits.max_add;
|
||||
} else {
|
||||
inputEl.removeAttribute('max');
|
||||
}
|
||||
if (limits.max_subtract !== null && limits.max_subtract !== undefined) {
|
||||
inputEl.min = -limits.max_subtract;
|
||||
} else {
|
||||
inputEl.removeAttribute('min');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验分值是否符合权限组上限,返回错误信息(空字符串表示通过)
|
||||
*/
|
||||
function validateScoreChange(value) {
|
||||
const limits = getScoreLimits();
|
||||
if (!value || value === 0) return '分值不能为0';
|
||||
if (value > 0) {
|
||||
if (!limits.can_add) return '当前权限组仅允许扣分';
|
||||
if (limits.max_add !== null && limits.max_add !== undefined && value > limits.max_add) {
|
||||
return '单次加分不能超过' + limits.max_add + '分';
|
||||
}
|
||||
} else {
|
||||
if (!limits.can_subtract) return '当前权限组仅允许加分';
|
||||
if (limits.max_subtract !== null && limits.max_subtract !== undefined && Math.abs(value) > limits.max_subtract) {
|
||||
return '单次扣分不能超过' + limits.max_subtract + '分';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function showToast(message, type = 'success') {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast toast-${type}`;
|
||||
|
||||
Reference in new issue
Block a user