功能更新:新增Bug管理模块,完善用户角色分配,优化项目设置

This commit is contained in:
qiaoxinjiu
2026-05-07 19:43:05 +08:00
parent 916248483c
commit f8211673ee
44 changed files with 10410 additions and 437 deletions

73
src/utils/bugHistory.js Normal file
View File

@@ -0,0 +1,73 @@
import { addBugHistory } from '@/api/bugApi'
/** 将任意值转为接口可接受的字符串(空用 '' */
export function toHistoryValue(v) {
if (v === undefined || v === null) return ''
if (typeof v === 'object') {
try {
return JSON.stringify(v)
} catch (e) {
return String(v)
}
}
return String(v)
}
/**
* 写入 Bug 操作历史POST /bug/history/add
* 失败不抛错、不阻断主流程,仅静默忽略(可后续接日志)
*/
export function recordBugHistory(store, { bugId, fieldName, oldValue, newValue, operatorId }) {
if (!bugId || !fieldName) return Promise.resolve()
const uid =
operatorId !== undefined && operatorId !== null && operatorId !== ''
? operatorId
: store && store.state && store.state.currentUser && store.state.currentUser.id
if (uid === undefined || uid === null || uid === '') return Promise.resolve()
return addBugHistory({
bugId: Number(bugId),
fieldName: String(fieldName),
oldValue: toHistoryValue(oldValue),
newValue: toHistoryValue(newValue),
operatorId: Number(uid)
}).catch(() => {})
}
/** 编辑页:与接口 fieldName 对齐的表单字段(用于对比写历史) */
export const BUG_EDIT_HISTORY_FIELDS = [
{ formKey: 'title', fieldName: 'title' },
{ formKey: 'bugType', fieldName: 'bug_type' },
{ formKey: 'severity', fieldName: 'severity' },
{ formKey: 'priority', fieldName: 'priority' },
{ formKey: 'status', fieldName: 'status' },
{ formKey: 'reporterId', fieldName: 'reporter_id' },
{ formKey: 'assigneeId', fieldName: 'assignee_id' },
{ formKey: 'moduleId', fieldName: 'module_id' },
{ formKey: 'caseId', fieldName: 'case_id' },
{ formKey: 'planId', fieldName: 'plan_id' },
{ formKey: 'environment', fieldName: 'environment' },
{ formKey: 'steps', fieldName: 'steps' },
{ formKey: 'reproduceRate', fieldName: 'reproduce_rate' }
]
export function buildBugEditBaseline(form) {
const f = form || {}
const o = {}
BUG_EDIT_HISTORY_FIELDS.forEach(({ formKey }) => {
o[formKey] = f[formKey]
})
return o
}
/** 对比编辑前后并逐字段写历史(仅变更字段) */
export function recordBugEditDiff(store, bugId, baseline, current) {
if (!bugId || !baseline || !current) return Promise.resolve()
const tasks = []
BUG_EDIT_HISTORY_FIELDS.forEach(({ formKey, fieldName }) => {
const ov = baseline[formKey]
const nv = current[formKey]
if (toHistoryValue(ov) === toHistoryValue(nv)) return
tasks.push(recordBugHistory(store, { bugId, fieldName, oldValue: ov, newValue: nv }))
})
return Promise.all(tasks)
}