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

View File

@@ -156,11 +156,11 @@
</template>
</el-table-column>
<el-table-column label="描述" prop="description" />
<el-table-column label="操作" align="center" width="220">
<el-table-column label="操作" align="center" width="260">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleEditSub(scope.row)" v-if="canOperateSub()">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteSub(scope.row)" v-if="canOperateSub()">删除</el-button>
<el-button size="mini" type="text" icon="el-icon-check" @click="handleCompleteSub(scope.row)" v-if="canOperateSub() && scope.row.status==='1'">完成</el-button>
<el-button size="mini" type="text" icon="el-icon-check" @click="handleCompleteSub(scope.row)" v-if="canOperateSub() && scope.row.status!=='2'">完成</el-button>
</template>
</el-table-column>
</el-table>

View File

@@ -582,33 +582,39 @@ export default {
// 添加/修改模块(根据是否存在 moduleId 判断)
subMitModel() {
this.modelsForm.projectId = this.projectId;
const isEdit = !!this.modelsForm.moduleId;
if (!isEdit) {
// 新增:默认待接取
this.modelsForm.status = 0;
// 使用当前登录用户名作为创建人
this.modelsForm.create_by = (this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.name) || undefined;
addModels(this.modelsForm).then(res => {
if (res.code === 200) {
this.$message.success("添加完成");
this.Models = false;
this.getModuleList();
} else {
this.$message.error("添加失败,请重试")
}
})
} else {
// 修改:保留原状态/接取信息,仅更新可编辑字段
updateModels(this.modelsForm).then(res => {
if (res.code === 200) {
this.$message.success("修改完成");
this.Models = false;
this.getModuleList();
} else {
this.$message.error("修改失败,请重试")
}
})
}
// 表单校验(模块名称、截止日期等必填)
this.$refs["form"].validate(valid => {
if (!valid) {
return;
}
const isEdit = !!this.modelsForm.moduleId;
if (!isEdit) {
// 新增:默认待接取
this.modelsForm.status = 0;
// 使用当前登录用户名作为创建人
this.modelsForm.create_by = (this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.name) || undefined;
addModels(this.modelsForm).then(res => {
if (res.code === 200) {
this.$message.success("添加完成");
this.Models = false;
this.getModuleList();
} else {
this.$message.error("添加失败,请重试")
}
})
} else {
// 修改:保留原状态/接取信息,仅更新可编辑字段
updateModels(this.modelsForm).then(res => {
if (res.code === 200) {
this.$message.success("修改完成");
this.Models = false;
this.getModuleList();
} else {
this.$message.error("修改失败,请重试")
}
})
}
})
},
//接取模块
@@ -635,7 +641,19 @@ export default {
//添加模块
ModelsAdd() {
// 打开模块添加对话框并传递projectId
// 打开模块添加对话框并传递projectId;清空之前编辑残留,确保走新增
this.modelsForm = {
moduleId: null,
projectId: this.projectId,
moduleName: null,
status: 0,
assignee: null,
assignTime: null,
del_flag: null,
create_by: null,
finishTime: null,
deadline: null
}
this.Models = true;
this.title = "添加模块";
},