Browse Source

巡检模板数据展示

master
巴林闲侠 2 years ago
parent
commit
6782267a2b
  1. 4
      api/app/lib/controllers/patrolManage/patrolTemplate.js
  2. 6
      api/app/lib/index.js
  3. 4
      web/client/src/sections/patrolManage/containers/patrolTemplate.js

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

@ -10,7 +10,9 @@ async function getPatrolTemplate (ctx, next) {
required: true, required: true,
model: models.User, model: models.User,
attributes: ['id', 'name'], attributes: ['id', 'name'],
},] }, {
model: models.CheckItems,
}]
}; };
if (limit) { if (limit) {
options.limit = Number(limit); options.limit = Number(limit);

6
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, const { Department, User, UserResource, Resource, Project, Point, PatrolPlan,
CheckItems, CheckItemsGroup, PatrolTemplate CheckItems, CheckItemsGroup,
PatrolTemplate, PatrolTemplateCheckItems
} = dc.models; } = dc.models;
UserResource.belongsTo(User, { foreignKey: 'userId', targetKey: 'id' }); 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' }); PatrolTemplate.belongsTo(User, { foreignKey: 'createUserId', targetKey: 'id' });
User.hasMany(PatrolTemplate, { foreignKey: 'createUserId', sourceKey: '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' }); UserResource.belongsTo(Resource, { foreignKey: 'resourceId', targetKey: 'code' });
Resource.hasMany(UserResource, { foreignKey: 'resourceId', sourceKey: 'code' }); Resource.hasMany(UserResource, { foreignKey: 'resourceId', sourceKey: 'code' });
Resource.hasMany(Resource, { foreignKey: 'parentResource', sourceKey: 'code' }); Resource.hasMany(Resource, { foreignKey: 'parentResource', sourceKey: 'code' });

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

@ -1,6 +1,6 @@
import React, { useState, useRef } from 'react'; import React, { useState, useRef } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Button, Popconfirm } from 'antd'; import { Button, Popconfirm, Tag } from 'antd';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import PlanTemplateModal from '../components/planTemplateModal'; import PlanTemplateModal from '../components/planTemplateModal';
import { createPatrolTemplate, delPatrolTemplate, updatePatrolTemplate, getPatrolTemplate } from '../actions/template'; import { createPatrolTemplate, delPatrolTemplate, updatePatrolTemplate, getPatrolTemplate } from '../actions/template';
@ -38,7 +38,7 @@ function PatrolTemplate (props) {
key: 'checkItems', key: 'checkItems',
ellipsis: true, ellipsis: true,
render: (_, r) => { render: (_, r) => {
return return r?.check_items ? r?.check_items.map(c => <Tag>{c.name}</Tag>) : '-'
} }
}, { }, {
title: '操作', title: '操作',

Loading…
Cancel
Save