fixed bug

This commit is contained in:
2025-09-09 10:24:33 +08:00
parent 363f7d1a2f
commit 35ebacc326
6 changed files with 158 additions and 39 deletions

View File

@@ -248,10 +248,11 @@ export default {
methods: {
async initProjects() {
try {
let options = []
if (this.isProjectAdmin) {
// 管理员/项目管理员:读取全部可管理项目
const { rows } = await listProject({ pageNum: 1, pageSize: 9999 })
this.projectOptions = rows || []
options = rows || []
} else if (this.isNormalUser) {
// 普通用户:从“我的模块”汇总所属项目
const { rows } = await getMyModules({ pageNum: 1, pageSize: 9999 })
@@ -261,7 +262,35 @@ export default {
map.set(m.projectId, { projectId: m.projectId, projectName: m.projectName })
}
})
this.projectOptions = Array.from(map.values())
options = Array.from(map.values())
}
// 兼容:若管理员接口无数据,则回退到“我的模块”聚合
if ((!options || options.length === 0)) {
const { rows } = await getMyModules({ pageNum: 1, pageSize: 9999 })
const map = new Map()
;(rows || []).forEach(m => {
if (m.projectId && m.projectName && !map.has(m.projectId)) {
map.set(m.projectId, { projectId: m.projectId, projectName: m.projectName })
}
})
options = Array.from(map.values())
}
// 如果路由带有项目上下文,但下拉没有,补入一项,避免空列表
if ((this.currentContext.projectId && this.currentContext.projectName) && !options.some(p => String(p.projectId) === String(this.currentContext.projectId))) {
options.unshift({ projectId: this.currentContext.projectId, projectName: this.currentContext.projectName })
}
this.projectOptions = options
// 预选项目(优先使用路由上下文),并联动加载模块下拉
if (!this.upload.meta.projectId) {
if (this.currentContext.projectId) {
this.upload.meta.projectId = this.currentContext.projectId
} else if (this.projectOptions && this.projectOptions.length > 0) {
this.upload.meta.projectId = this.projectOptions[0].projectId
}
}
if (this.upload.meta.projectId) {
await this.handleProjectChange(this.upload.meta.projectId)
}
} catch (e) {
this.projectOptions = []
@@ -287,7 +316,8 @@ export default {
this.currentContext.moduleName = query.moduleName;
}
if (query.projectId) {
this.currentContext.projectId = query.projectId;
// 统一为数字,避免 el-select 由于类型不一致显示原始ID
this.currentContext.projectId = parseInt(query.projectId);
}
if (query.projectName) {
this.currentContext.projectName = query.projectName;
@@ -364,12 +394,30 @@ export default {
this.multiple = !selection.length;
},
/** 上传按钮操作 */
handleUpload() {
async handleUpload() {
if (this.currentContext.moduleName) {
this.uploadTitle = `上传文档 - ${this.currentContext.moduleName}`;
} else {
this.uploadTitle = "上传文档";
}
// 确保项目选项已加载再设置默认值避免首次显示为纯ID
if (!this.projectOptions || this.projectOptions.length === 0) {
await this.initProjects()
}
// 预选:优先使用路由上下文;否则选第一项
if (this.currentContext.projectId) {
this.upload.meta.projectId = this.currentContext.projectId
} else {
// 默认不选任何项目避免显示成固定ID
this.upload.meta.projectId = null
}
if (this.upload.meta.projectId) {
await this.handleProjectChange(this.upload.meta.projectId)
} else {
// 无默认项目时清空模块下拉
this.moduleOptions = []
this.upload.meta.moduleId = null
}
this.uploadOpen = true;
},
/** 下载按钮操作 */