diff --git a/api/app/lib/controllers/patrolManage/patrolTemplate.js b/api/app/lib/controllers/patrolManage/patrolTemplate.js index ed33026..fbeda4b 100644 --- a/api/app/lib/controllers/patrolManage/patrolTemplate.js +++ b/api/app/lib/controllers/patrolManage/patrolTemplate.js @@ -10,7 +10,9 @@ async function getPatrolTemplate (ctx, next) { required: true, model: models.User, attributes: ['id', 'name'], - },] + }, { + model: models.CheckItems, + }] }; if (limit) { options.limit = Number(limit); diff --git a/api/app/lib/index.js b/api/app/lib/index.js index dab112e..4b465c3 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -54,7 +54,8 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq }); const { Department, User, UserResource, Resource, Project, Point, PatrolPlan, - CheckItems, CheckItemsGroup, PatrolTemplate + CheckItems, CheckItemsGroup, + PatrolTemplate, PatrolTemplateCheckItems } = dc.models; UserResource.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' }); @@ -63,6 +64,9 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq PatrolTemplate.belongsTo(User, { foreignKey: 'createUserId', targetKey: 'id' }); User.hasMany(PatrolTemplate, { foreignKey: 'createUserId', sourceKey: 'id' }); + CheckItems.belongsToMany(PatrolTemplate, { through: PatrolTemplateCheckItems, foreignKey: 'templateId', otherKey: 'checkItemsId' }); + PatrolTemplate.belongsToMany(CheckItems, { through: PatrolTemplateCheckItems, foreignKey: 'templateId', otherKey: 'checkItemsId' }); + UserResource.belongsTo(Resource, { foreignKey: 'resourceId', targetKey: 'code' }); Resource.hasMany(UserResource, { foreignKey: 'resourceId', sourceKey: 'code' }); Resource.hasMany(Resource, { foreignKey: 'parentResource', sourceKey: 'code' }); diff --git a/web/client/src/sections/patrolManage/containers/patrolTemplate.js b/web/client/src/sections/patrolManage/containers/patrolTemplate.js index 29723d8..5338668 100644 --- a/web/client/src/sections/patrolManage/containers/patrolTemplate.js +++ b/web/client/src/sections/patrolManage/containers/patrolTemplate.js @@ -1,6 +1,6 @@ import React, { useState, useRef } from 'react'; import { connect } from 'react-redux'; -import { Button, Popconfirm } from 'antd'; +import { Button, Popconfirm, Tag } from 'antd'; import ProTable from '@ant-design/pro-table'; import PlanTemplateModal from '../components/planTemplateModal'; import { createPatrolTemplate, delPatrolTemplate, updatePatrolTemplate, getPatrolTemplate } from '../actions/template'; @@ -38,7 +38,7 @@ function PatrolTemplate (props) { key: 'checkItems', ellipsis: true, render: (_, r) => { - return + return r?.check_items ? r?.check_items.map(c => {c.name}) : '-' } }, { title: '操作',