Browse Source

删除巡检模板

master
巴林闲侠 2 years ago
parent
commit
59ca5889c7
  1. 7
      api/app/lib/controllers/patrolManage/patrolTemplate.js
  2. 3
      api/app/lib/index.js
  3. 2
      web/client/src/sections/patrolManage/containers/patrolTemplate.js

7
api/app/lib/controllers/patrolManage/patrolTemplate.js

@ -12,6 +12,9 @@ async function getPatrolTemplate (ctx, next) {
attributes: ['id', 'name'],
}, {
model: models.CheckItems,
}, {
model: models.PatrolPlan,
attributes: ['name'],
}]
};
if (limit) {
@ -129,11 +132,11 @@ async function delPatrolTemplate (ctx, next) {
const { id } = ctx.params;
const record = await models.PatrolPlan.findOne({
where: { patrolTemplateId: id }
where: { templateId: id }
});
if (record) {
errMsg = '不能删除有巡检记录的模板';
errMsg = '不能删除已绑定巡检计划的模板';
throw errMsg;
}

3
api/app/lib/index.js

@ -61,6 +61,9 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
UserResource.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' });
User.hasMany(UserResource, { foreignKey: 'userId', sourceKey: 'id' });
PatrolPlan.belongsTo(PatrolTemplate, { foreignKey: 'templateId', targetKey: 'id' });
PatrolTemplate.hasMany(PatrolPlan, { foreignKey: 'templateId', sourceKey: 'id' });
PatrolTemplate.belongsTo(User, { foreignKey: 'createUserId', targetKey: 'id' });
User.hasMany(PatrolTemplate, { foreignKey: 'createUserId', sourceKey: 'id' });

2
web/client/src/sections/patrolManage/containers/patrolTemplate.js

@ -62,7 +62,7 @@ function PatrolTemplate (props) {
}
})
}}>
<Button type="link" danger>删除</Button>
<Button type="link" danger disabled={record && record.patrolPlans && record.patrolPlans.length}>删除</Button>
</Popconfirm>
</>
},

Loading…
Cancel
Save