Browse Source

(*)部门资源库逻辑重新调整

master
周沫沫历险记 2 years ago
parent
commit
44c5295d18
  1. 116
      api/app/lib/controllers/resourceRepository/index.js
  2. 61
      api/app/lib/models/training_information_level.js
  3. 60
      api/app/lib/models/training_information_record.js
  4. 70
      web/client/src/sections/humanAffairs/containers/resourceRepository.jsx

116
api/app/lib/controllers/resourceRepository/index.js

@ -4,92 +4,94 @@ const moment = require('moment')
async function getResourceClassify(ctx) { async function getResourceClassify(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { limit, offset } = ctx.query; // const { limit, offset } = ctx.query;
let rlst = []; let rlst = [];
const findObj = {} // const findObj = {}
if (Number(limit) > 0 && Number(offset) >= 0) { // if (Number(limit) > 0 && Number(offset) >= 0) {
findObj.limit = Number(limit); // findObj.limit = Number(limit);
findObj.offset = Number(offset); // findObj.offset = Number(offset);
} // }
rlst = [{ rlst = [{
label: "公司培训资料", value: "company", key: "company", operation: true, children: [] label: "公司培训资料", value: "company", key: "公司培训资料", operation: true, children: []
}, { label: "部门培训资料", value: 'dept', key: 'dept', operation: false, children: [] }]; }, { label: "部门培训资料", value: 'dept', key: '部门培训资料', operation: false, children: [] }];
const trainingInformationLevel = await models.TrainingInformationLevel.findAll(findObj); const filterData = (arrayData, arrIndex, operation) => {
if (trainingInformationLevel.length) { if (arrayData.length) {
for (let level of arrayData) {
const { departmentName, trainDate } = level.dataValues;
for (let level of trainingInformationLevel) { /** departmentName:2级,trainDate:3级 */
const { id, type, departmentname, traindate, origin } = level; if (departmentName) {
/**type:1级, departmentname:2级,traindate:3级 */ if (trainDate) {
const arrIndex = rlst.findIndex(item => item.label == type) const depKey = rlst[arrIndex].label + '/' + departmentName
if (arrIndex > -1) {//一级分类名称正确
const operation = "import" == origin ? true : false;
if (departmentname) {
if (traindate) {
//区分2级是否记录 //区分2级是否记录
if (rlst[arrIndex].children) { if (rlst[arrIndex].children) {
const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname); const depIndex = rlst[arrIndex].children.findIndex(r => r.key == depKey);
if (depIndex > -1) { if (depIndex > -1) {
const dateKey = rlst[arrIndex].label + '/' + rlst[arrIndex].children[depIndex].label + '/' + moment(trainDate).format('YYYY-MM');
if (rlst[arrIndex].children[depIndex].children) { if (rlst[arrIndex].children[depIndex].children) {
const dateIndex = rlst[arrIndex].children[depIndex].children.findIndex(r => r.key == dateKey);
if (dateIndex == -1) {
rlst[arrIndex].children[depIndex].children.push({ rlst[arrIndex].children[depIndex].children.push({
label: moment(traindate).format('YYYY-MM'), label: moment(trainDate).format('YYYY-MM'),
value: id, value: dateKey,
key: id, key: dateKey,
operation operation
}) });
}
} else { } else {
rlst[arrIndex].children[depIndex].children = [{ rlst[arrIndex].children[depIndex].children = [{
label: moment(traindate).format('YYYY-MM'), label: moment(trainDate).format('YYYY-MM'),
value: id, value: dateKey,
key: id, key: dateKey,
operation operation
}] }]
} }
} else { } else {
rlst[arrIndex].children.push({ rlst[arrIndex].children.push({
label: departmentname, label: departmentName,
value: depKey,
key: depKey,
operation,
children: [{ children: [{
label: moment(traindate).format('YYYY-MM'), label: moment(trainDate).format('YYYY-MM'),
value: id, value: depKey + '/' + moment(trainDate).format('YYYY-MM'),
key: id, key: depKey + '/' + moment(trainDate).format('YYYY-MM'),
operation operation
}] }]
}); });
} }
} else { } else {
rlst[arrIndex].children = [{ rlst[arrIndex].children = [{
label: departmentname, label: departmentName,
value: depKey,
key: depKey,
operation,
children: [{ children: [{
label: moment(traindate).format('YYYY-MM'), label: moment(trainDate).format('YYYY-MM'),
value: id, value: depKey + '/' + moment(trainDate).format('YYYY-MM'),
key: id, key: depKey + '/' + moment(trainDate).format('YYYY-MM'),
operation operation
}] }]
}] }]
} }
} else { } else {
//只有2级目录的情况
if (rlst[arrIndex].children) { if (rlst[arrIndex].children) {
const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname); const depIndex = rlst[arrIndex].children.findIndex(r => r.key == rlst[arrIndex].label + '/' + departmentName);
if (depIndex > -1) { if (depIndex == -1) {
if (!rlst[arrIndex].children[depIndex].value) {
rlst[arrIndex].children[depIndex].value = id;
rlst[arrIndex].children[depIndex].key = id;
rlst[arrIndex].children[depIndex].operation = operation;
}
} else {
rlst[arrIndex].children.push({ rlst[arrIndex].children.push({
label: departmentname, label: departmentName,
value: id, value: rlst[arrIndex].label + '/' + departmentName,
key: id, key: rlst[arrIndex].label + '/' + departmentName,
operation operation,
children: []
}) })
} }
} else { } else {
rlst[arrIndex].children = [{ rlst[arrIndex].children = [{
label: departmentname, value: rlst[arrIndex].label + '/' + departmentName,
value: id, key: rlst[arrIndex].label + '/' + departmentName,
key: id, operation,
operation children: []
}] }]
} }
} }
@ -97,6 +99,16 @@ async function getResourceClassify(ctx) {
} }
} }
} }
const deptTraining = await models.DeptTraining.findAll({});
if (deptTraining.length) {
filterData(deptTraining, 1, false);
}
const trainingInformation = await models.TrainingInformation.findAll({});
if (trainingInformation.length) {
filterData(trainingInformation, 0, true);
}
ctx.status = 200; ctx.status = 200;
ctx.body = rlst; ctx.body = rlst;

61
api/app/lib/models/training_information_level.js

@ -1,61 +0,0 @@
/* eslint-disable*/
'use strict';
module.exports = dc => {
const DataTypes = dc.ORM;
const sequelize = dc.orm;
const TrainingInformationLevel = sequelize.define("trainingInformationLevel", {
id: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: true,
field: "id",
autoIncrement: true
},
type: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "type",
autoIncrement: false
},
departmentname: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: '部门(2级目录)',
primaryKey: false,
field: "departmentname",
autoIncrement: false
},
traindate: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: null,
comment: '培训时间(3级目录)',
primaryKey: false,
field: "traindate",
autoIncrement: false
},
origin: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "origin",
autoIncrement: false
}
}, {
tableName: "training_information_level",
comment: "",
indexes: []
});
dc.models.TrainingInformationLevel = TrainingInformationLevel;
return TrainingInformationLevel;
};

60
api/app/lib/models/training_information_record.js

@ -5,7 +5,7 @@
module.exports = dc => { module.exports = dc => {
const DataTypes = dc.ORM; const DataTypes = dc.ORM;
const sequelize = dc.orm; const sequelize = dc.orm;
const TrainingInformationRecord = sequelize.define("trainingInformationRecord", { const TrainingInformation = sequelize.define("training_information", {
id: { id: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: false, allowNull: false,
@ -15,16 +15,7 @@ module.exports = dc => {
field: "id", field: "id",
autoIncrement: true autoIncrement: true
}, },
type: { departmentName: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "type",
autoIncrement: false
},
departmentname: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
@ -33,52 +24,52 @@ module.exports = dc => {
field: "departmentname", field: "departmentname",
autoIncrement: false autoIncrement: false
}, },
traindate: { trainDate: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: true,
defaultValue: null, defaultValue: null,
comment: null, comment: null,
primaryKey: false, primaryKey: false,
field: "traindate", field: "traindate",
autoIncrement: false autoIncrement: false
}, },
filetype: { fileType: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: true,
defaultValue: null, defaultValue: null,
comment: null, comment: null,
primaryKey: false, primaryKey: false,
field: "filetype", field: "filetype",
autoIncrement: false autoIncrement: false
}, },
filename: { fileName: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: true,
defaultValue: null, defaultValue: null,
comment: null, comment: null,
primaryKey: false, primaryKey: false,
field: "filename", field: "filename",
autoIncrement: false autoIncrement: false
}, },
filesize: { fileSize: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: true,
defaultValue: null, defaultValue: null,
comment: null, comment: null,
primaryKey: false, primaryKey: false,
field: "filesize", field: "filesize",
autoIncrement: false autoIncrement: false
}, },
updatedate: { updateDate: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: false, allowNull: true,
defaultValue: null, defaultValue: null,
comment: null, comment: null,
primaryKey: false, primaryKey: false,
field: "updatedate", field: "updatedate",
autoIncrement: false autoIncrement: false
}, },
attachpath: { attachPath: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
@ -86,30 +77,13 @@ module.exports = dc => {
primaryKey: false, primaryKey: false,
field: "attachpath", field: "attachpath",
autoIncrement: false autoIncrement: false
},
origin: {
type: DataTypes.STRING,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "origin",
autoIncrement: false
},
traininginformationlevelid: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: null,
comment: null,
primaryKey: false,
field: "traininginformationlevelid",
autoIncrement: false
} }
}, { }, {
tableName: "training_information_record", tableName: "training_information",
comment: "", comment: "",
indexes: [] indexes: []
}); });
dc.models.TrainingInformationRecord = TrainingInformationRecord;
return TrainingInformationRecord; dc.models.TrainingInformation = TrainingInformation;
return TrainingInformation;
}; };

70
web/client/src/sections/humanAffairs/containers/resourceRepository.jsx

@ -8,70 +8,17 @@ import '../style.less'
const ResourceRepository = (props) => { const ResourceRepository = (props) => {
const { dispatch, actions, clientHeight, resourceClassify } = props; const { dispatch, actions, clientHeight, resourceClassify } = props;
const [treeData, setTreeData] = useState([]);
const ref = useRef(); const ref = useRef();
useEffect(() => { useEffect(() => {
dispatch(getResourceClassify()); dispatch(getResourceClassify()).then(res => {
const { success, payload } = res;
if (success)
setTreeData(payload.data);
});
}, []) }, [])
const treeData = [
{
label: (<div>
<span>亚洲</span>
<span className='tree-icon'>
<IconEditStroked size='default' onClick={() => alert("bianji")} />
<IconMinusCircleStroked size='default' onClick={() => alert("sahnchu")} />
<IconPlusCircleStroked size='default' onClick={() => alert("+")} /></span>
</div>
),
value: 'Asia',
key: '0',
children: [
{
label: '中国',
value: 'China',
key: '0-0',
children: [
{
label: '北京',
value: 'Beijing',
key: '0-0-0',
},
{
label: '上海',
value: 'Shanghai',
key: '0-0-1',
},
],
},
],
},
{
label: '北美洲',
value: 'North America',
key: '1',
children: [
{
label: '中国',
value: 'China',
key: '1-0',
children: [
{
label: '北京',
value: 'Beijing2',
key: '1-0-0',
},
{
label: '上海',
value: 'Shanghai',
key: '1-0-1',
},
],
},
],
}
];
const style = { const style = {
width: 260, width: 260,
height: clientHeight - 294, height: clientHeight - 294,
@ -197,7 +144,8 @@ const ResourceRepository = (props) => {
<span className='tree-icon'> <span className='tree-icon'>
<IconEditStroked size='default' onClick={() => alert("bianji")} /> <IconEditStroked size='default' onClick={() => alert("bianji")} />
<IconMinusCircleStroked size='default' onClick={() => alert("sahnchu")} /> <IconMinusCircleStroked size='default' onClick={() => alert("sahnchu")} />
<IconPlusCircleStroked size='default' onClick={() => alert("+")} /></span> {data.children ? <IconPlusCircleStroked size='default' onClick={() => alert("+")} /> : ''}
</span>
: ''} : ''}
</div> </div>
) )
@ -228,7 +176,7 @@ const ResourceRepository = (props) => {
<Input suffix={<IconSearch />} showClear onChange={v => ref.current.search(v)} placeholder="请输入"></Input> <Input suffix={<IconSearch />} showClear onChange={v => ref.current.search(v)} placeholder="请输入"></Input>
<Tree <Tree
ref={ref} ref={ref}
treeData={resourceClassify} treeData={treeData}
defaultExpandAll defaultExpandAll
filterTreeNode filterTreeNode
searchRender={false} searchRender={false}

Loading…
Cancel
Save