This commit is contained in:
2025-09-12 10:35:17 +08:00
parent 141299fcaa
commit 914c04c240
14 changed files with 388 additions and 1520 deletions

View File

@@ -174,6 +174,11 @@ export default {
const roles = this.$store.state.user.roles || []
const hasNormal = roles.some(r => (typeof r === 'string' ? r : r.roleKey) === 'normal_user')
return hasNormal && !this.isProjectAdmin
},
// 当前用户ID用于前端过滤项目管理员仅看见自己创建的项目
currentUserId() {
const u = this.$store.state.user || {}
return u.userId || u.user_id || u.id || null
}
},
data() {
@@ -248,43 +253,35 @@ export default {
methods: {
async initProjects() {
try {
// 并行获取:管理员可见项目 + 我参与的模块聚合项目,取并集,避免有时显示有时不显示
const tasks = []
if (this.isProjectAdmin) {
tasks.push(listProject({ pageNum: 1, pageSize: 9999 }))
// 项目管理员:仅显示自己创建的项目
const projRes = await listProject({ pageNum: 1, pageSize: 9999 })
const owned = (projRes && Array.isArray(projRes.rows))
? projRes.rows.filter(p => String(p.ownerId) === String(this.currentUserId))
: []
this.projectOptions = owned.map(p => ({ projectId: p.projectId, projectName: p.projectName || (`项目#${p.projectId}`) }))
} else {
// 也许用户具备项目管理员角色但权限范围有限,这里仍保留 getMyModules 以保证兜底
tasks.push(Promise.resolve({ rows: [] }))
// 普通用户:根据“我的模块”推导可见项目
const myModRes = await getMyModules({ pageNum: 1, pageSize: 9999 })
const map = new Map()
if (myModRes && Array.isArray(myModRes.rows)) {
myModRes.rows.forEach(m => {
if (m.projectId && !map.has(m.projectId)) {
map.set(m.projectId, { projectId: m.projectId, projectName: m.projectName || (`项目#${m.projectId}`) })
}
})
}
// 注:普通用户可保留路由上下文补入,管理员不补入非本人项目
if (this.currentContext.projectId && !map.has(this.currentContext.projectId)) {
map.set(this.currentContext.projectId, { projectId: this.currentContext.projectId, projectName: this.currentContext.projectName || (`项目#${this.currentContext.projectId}`) })
}
this.projectOptions = Array.from(map.values())
}
tasks.push(getMyModules({ pageNum: 1, pageSize: 9999 }))
const [projRes, myModRes] = await Promise.all(tasks)
const map = new Map()
// 管理员项目
if (projRes && Array.isArray(projRes.rows)) {
projRes.rows.forEach(p => {
if (p.projectId && !map.has(p.projectId)) {
map.set(p.projectId, { projectId: p.projectId, projectName: p.projectName || (`项目#${p.projectId}`) })
}
})
}
// 我参与的模块所在项目
if (myModRes && Array.isArray(myModRes.rows)) {
myModRes.rows.forEach(m => {
if (m.projectId && !map.has(m.projectId)) {
map.set(m.projectId, { projectId: m.projectId, projectName: m.projectName || (`项目#${m.projectId}`) })
}
})
}
// 路由上下文一定补入
if (this.currentContext.projectId && !map.has(this.currentContext.projectId)) {
map.set(this.currentContext.projectId, { projectId: this.currentContext.projectId, projectName: this.currentContext.projectName || (`项目#${this.currentContext.projectId}`) })
}
this.projectOptions = Array.from(map.values())
// 如果之前没选过,按上下文预选
// 如果之前没选过,按上下文预选(仅当选项中存在)
if (!this.upload.meta.projectId && this.currentContext.projectId) {
this.upload.meta.projectId = this.currentContext.projectId
const exists = this.projectOptions.some(p => String(p.projectId) === String(this.currentContext.projectId))
this.upload.meta.projectId = exists ? this.currentContext.projectId : null
}
if (this.upload.meta.projectId) {
await this.handleProjectChange(this.upload.meta.projectId)
@@ -402,6 +399,10 @@ export default {
}
// 每次打开均刷新一次项目集合,避免角色/指派变更导致的偶发不显示
await this.initProjects()
// 普通用户默认选择“模块文档”,并禁用“项目文档”的单选
if (this.isNormalUser && !this.isProjectAdmin) {
this.upload.meta.kindType = 1
}
// 预选:优先使用路由上下文;否则选第一项
if (this.currentContext.projectId) {
this.upload.meta.projectId = this.currentContext.projectId