This commit is contained in:
2025-09-07 17:29:59 +08:00
parent 0cb1c34755
commit f080c0c4a7
7 changed files with 293 additions and 234 deletions

View File

@@ -161,9 +161,19 @@ import { listModulesByProject, getMyModules } from '@/api/project/module'
export default {
name: "Doc",
computed: {
// 是否项目管理员/平台管理员
isProjectAdmin() {
const roles = this.$store.state.user.roles || []
return roles.some(r => {
const key = typeof r === 'string' ? r : r.roleKey
return key === 'project_admin' || key === 'platform_admin'
})
},
// 是否普通用户(且不是管理员)
isNormalUser() {
const roles = this.$store.state.user.roles || []
return roles.some(r => (typeof r === 'string' ? r : r.roleKey) === 'normal_user')
const hasNormal = roles.some(r => (typeof r === 'string' ? r : r.roleKey) === 'normal_user')
return hasNormal && !this.isProjectAdmin
}
},
data() {
@@ -238,7 +248,11 @@ export default {
methods: {
async initProjects() {
try {
if (this.isNormalUser) {
if (this.isProjectAdmin) {
// 管理员/项目管理员:读取全部可管理项目
const { rows } = await listProject({ pageNum: 1, pageSize: 9999 })
this.projectOptions = rows || []
} else if (this.isNormalUser) {
// 普通用户:从“我的模块”汇总所属项目
const { rows } = await getMyModules({ pageNum: 1, pageSize: 9999 })
const map = new Map()
@@ -248,10 +262,6 @@ export default {
}
})
this.projectOptions = Array.from(map.values())
} else {
// 管理员/项目管理员:读取全部可管理项目
const { rows } = await listProject({ pageNum: 1, pageSize: 9999 })
this.projectOptions = rows || []
}
} catch (e) {
this.projectOptions = []
@@ -297,7 +307,7 @@ export default {
this.upload.meta.moduleId = null;
if (!projectId) { this.moduleOptions = []; return; }
try {
if (this.isNormalUser) {
if (!this.isProjectAdmin && this.isNormalUser) {
// 从“我的模块”中过滤出所选项目的可见模块
const { rows } = await getMyModules({ pageNum: 1, pageSize: 9999 })
this.moduleOptions = (rows || []).filter(m => String(m.projectId) === String(projectId))