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;
},
/** 下载按钮操作 */

View File

@@ -43,7 +43,7 @@
</div>
</el-form>
<el-table v-loading="loading" :data="moduleList" @selection-change="handleSelectionChange" @row-click="handleRowClick" @cell-click="handleCellClick">
<el-table v-loading="loading" :data="moduleList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="模块ID" align="center" prop="moduleId" />
<el-table-column label="模块名称" align="center" prop="moduleName">

View File

@@ -322,7 +322,6 @@ import { assignModule } from "@/api/project/module";
import { listUser } from "@/api/system/user";
import Cookies from "js-cookie";
import {getUserRole} from "@/api/system/role";
import {getSysUser} from "@/api/system/user";
import moment from "moment";
import { downloadDoc } from "@/api/doc/doc";
import { getToken } from "@/utils/auth";
@@ -401,7 +400,11 @@ export default {
{required: true, message: "模块名称不能为空", trigger: "blur"}
],
deadline: [
{required: true, message: "截止日期不能为空", trigger: "blur"}
{required: true, message: "截止日期不能为空", trigger: "blur"},
{ validator: (rule, value, callback) => { try { const st = this.form.startTime ? moment(this.form.startTime, 'YYYY-MM-DD') : null; const dl = value ? moment(value, 'YYYY-MM-DD') : null; if (st && dl && st.isAfter(dl)) { callback(new Error('截止日期不能早于起始日期')); } else { callback(); } } catch(e){ callback(); } }, trigger: 'change' }
],
startTime: [
{ validator: (rule, value, callback) => { try { const st = value ? moment(value, 'YYYY-MM-DD') : null; const dl = this.form.deadline ? moment(this.form.deadline, 'YYYY-MM-DD') : null; if (st && dl && st.isAfter(dl)) { callback(new Error('起始日期不能晚于截止日期')); } else { callback(); } } catch(e){ callback(); } }, trigger: 'change' }
]
},
@@ -576,21 +579,36 @@ export default {
})
},
//添加模块
// 添加/修改模块(根据是否存在 moduleId 判断)
subMitModel() {
this.modelsForm.projectId = this.projectId;
this.modelsForm.status = 0;//待接取
getSysUser(Cookies.get("username")).then(res => {
this.modelsForm.create_by = res.sysUser.nickName;
})
addModels(this.modelsForm).then(res => {
if (res.code === 200) {
this.$message.success("添加完成");
location.reload();
} else {
this.$message.error("添加失败,请重试")
}
})
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("修改失败,请重试")
}
})
}
},
//接取模块
@@ -598,13 +616,11 @@ export default {
this.modelsForm.moduleId = row.moduleId
//修改状态
this.modelsForm.status = 1; //已接取
getSysUser(Cookies.get("username")).then(res => {
this.modelsForm.assignee = res.sysUser.nickName;
this.modelsForm.assignTime = moment().format('YYYY-MM-DD HH:mm:ss');
updateModels(this.modelsForm).then(ress => {
this.$message.success("已接取")
location.reload();
})
this.modelsForm.assignee = (this.$store && this.$store.state && this.$store.state.user && this.$store.state.user.name) || undefined;
this.modelsForm.assignTime = moment().format('YYYY-MM-DD HH:mm:ss');
updateModels(this.modelsForm).then(ress => {
this.$message.success("已接取")
location.reload();
})
},
@@ -725,6 +741,13 @@ export default {
this.$refs["form"].validate(valid => {
this.finishDialog = false;
if (valid) {
// 运行时校验:起始日期不得晚于截止日期
const st = this.form.startTime ? moment(this.form.startTime, 'YYYY-MM-DD') : null
const dl = this.form.deadline ? moment(this.form.deadline, 'YYYY-MM-DD') : null
if (st && dl && st.isAfter(dl)) {
this.$modal.msgError('起始日期不能晚于截止日期')
return
}
if (this.form.projectId != null) {
console.log(this.form)
// this.form.status = (this.form.status === '已完成' ? '1' : '0');
@@ -824,7 +847,17 @@ export default {
},
// 编辑模块
editModule(row) {
this.modelsForm = { ...this.modelsForm, ...row }
// 只拷贝前端可编辑字段,避免误传无关数据导致新增
this.modelsForm = {
moduleId: row.moduleId,
projectId: this.projectId,
moduleName: row.moduleName,
deadline: row.deadline,
status: row.status,
assignee: row.assignee,
assignTime: row.assignTime,
finishTime: row.finishTime
}
this.Models = true
this.title = '修改模块'
},