Browse Source

(*)培训资料库优化左侧默认选中

master
周沫沫历险记 2 years ago
parent
commit
f7ebed19c5
  1. 58
      api/app/lib/controllers/resourceRepository/index.js
  2. 2
      api/app/lib/models/training_information.js
  3. 1
      web/client/src/sections/humanAffairs/containers/resourceRepository.jsx

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

@ -8,6 +8,7 @@ async function getResourceClassify(ctx) {
rlst = [{ rlst = [{
label: "公司培训资料", value: "company", key: "公司培训资料", operation: true, children: [] label: "公司培训资料", value: "company", key: "公司培训资料", operation: true, children: []
}, { label: "部门培训资料", value: 'dept', key: '部门培训资料', operation: false, children: [] }]; }, { label: "部门培训资料", value: 'dept', key: '部门培训资料', operation: false, children: [] }];
const findObj = { order: [["departmentName", "asc"]] }
const filterData = (arrayData, arrIndex, operation) => { const filterData = (arrayData, arrIndex, operation) => {
if (arrayData.length) { if (arrayData.length) {
for (let level of arrayData) { for (let level of arrayData) {
@ -15,17 +16,18 @@ async function getResourceClassify(ctx) {
/** departmentName:2级,trainDate:3级 */ /** departmentName:2级,trainDate:3级 */
if (departmentName) { if (departmentName) {
if (trainDate) { if (trainDate) {
const trainDateLabel = 'object' == typeof trainDate ? moment(trainDate).format('YYYY-MM') : trainDate;
const depKey = rlst[arrIndex].label + '/' + departmentName const depKey = rlst[arrIndex].label + '/' + departmentName
//区分2级是否记录 //区分2级是否记录
if (rlst[arrIndex].children) { if (rlst[arrIndex].children) {
const depIndex = rlst[arrIndex].children.findIndex(r => r.key == depKey); 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'); const dateKey = rlst[arrIndex].label + '/' + rlst[arrIndex].children[depIndex].label + '/' + trainDateLabel;
if (rlst[arrIndex].children[depIndex].children) { if (rlst[arrIndex].children[depIndex].children) {
const dateIndex = rlst[arrIndex].children[depIndex].children.findIndex(r => r.key == dateKey); const dateIndex = rlst[arrIndex].children[depIndex].children.findIndex(r => r.key == dateKey);
if (dateIndex == -1) { if (dateIndex == -1) {
rlst[arrIndex].children[depIndex].children.push({ rlst[arrIndex].children[depIndex].children.push({
label: moment(trainDate).format('YYYY-MM'), label: trainDateLabel,
value: dateKey, value: dateKey,
key: dateKey, key: dateKey,
operation operation
@ -33,7 +35,7 @@ async function getResourceClassify(ctx) {
} }
} else { } else {
rlst[arrIndex].children[depIndex].children = [{ rlst[arrIndex].children[depIndex].children = [{
label: moment(trainDate).format('YYYY-MM'), label: trainDateLabel,
value: dateKey, value: dateKey,
key: dateKey, key: dateKey,
operation operation
@ -46,9 +48,9 @@ async function getResourceClassify(ctx) {
key: depKey, key: depKey,
operation, operation,
children: [{ children: [{
label: moment(trainDate).format('YYYY-MM'), label: trainDateLabel,
value: depKey + '/' + moment(trainDate).format('YYYY-MM'), value: depKey + '/' + trainDateLabel,
key: depKey + '/' + moment(trainDate).format('YYYY-MM'), key: depKey + '/' + trainDateLabel,
operation operation
}] }]
}); });
@ -60,9 +62,9 @@ async function getResourceClassify(ctx) {
key: depKey, key: depKey,
operation, operation,
children: [{ children: [{
label: moment(trainDate).format('YYYY-MM'), label: trainDateLabel,
value: depKey + '/' + moment(trainDate).format('YYYY-MM'), value: depKey + '/' + trainDateLabel,
key: depKey + '/' + moment(trainDate).format('YYYY-MM'), key: depKey + '/' + trainDateLabel,
operation operation
}] }]
}] }]
@ -94,11 +96,11 @@ async function getResourceClassify(ctx) {
} }
} }
const deptTraining = await models.DeptTraining.findAll({}); const deptTraining = await models.DeptTraining.findAll(findObj);
if (deptTraining.length) { if (deptTraining.length) {
filterData(deptTraining, 1, false); filterData(deptTraining, 1, false);
} }
const trainingInformation = await models.TrainingInformation.findAll({}); const trainingInformation = await models.TrainingInformation.findAll(findObj);
if (trainingInformation.length) { if (trainingInformation.length) {
filterData(trainingInformation, 0, true); filterData(trainingInformation, 0, true);
} }
@ -113,7 +115,13 @@ async function getResourceClassify(ctx) {
} }
} }
} }
/**
* query
* limitoffset
* type : 文件分类必填{公司培训资料/部门培训资料}
* departmentName二级目录
* trainDate三级目录
*/
async function getResourceFileList(ctx, next) { async function getResourceFileList(ctx, next) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
@ -122,6 +130,7 @@ async function getResourceFileList(ctx, next) {
if (["公司培训资料", "部门培训资料"].includes(type)) { if (["公司培训资料", "部门培训资料"].includes(type)) {
const findObj = { const findObj = {
attributes: ["id", "fileType", "fileName", "fileSize", "updateDate", "attachPath"], attributes: ["id", "fileType", "fileName", "fileSize", "updateDate", "attachPath"],
order: [["departmentName", "desc"]]
}; };
if (Number(limit) > 0 && Number(offset) >= 0) { if (Number(limit) > 0 && Number(offset) >= 0) {
findObj.limit = Number(limit); findObj.limit = Number(limit);
@ -153,8 +162,31 @@ async function getResourceFileList(ctx, next) {
ctx.body = { message: err.message || '查询培训资源储备库文件列表失败' } ctx.body = { message: err.message || '查询培训资源储备库文件列表失败' }
} }
} }
async function postResourceClassify(ctx) {
try {
const { models } = ctx.fs.dc;
const { departmentName, trainDate } = ctx.request.body;
if (departmentName && '' != departmentName) {
const where = {
departmentName: departmentName
};
if (trainDate && '' != trainDate) {
where.trainDate = trainDate;
}
const oldData = await models.TrainingInformation.findOne(where);
}
ctx.status = 204;
} catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: err.message || '查询培训资源储备库文件列表失败' }
}
}
module.exports = { module.exports = {
getResourceClassify, getResourceClassify,
getResourceFileList getResourceFileList,
postResourceClassify
} }

2
api/app/lib/models/training_information.js

@ -25,7 +25,7 @@ module.exports = dc => {
autoIncrement: false autoIncrement: false
}, },
trainDate: { trainDate: {
type: DataTypes.DATE, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: null, comment: null,

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

@ -113,6 +113,7 @@ const ResourceRepository = (props) => {
defaultExpandAll={true} defaultExpandAll={true}
treeData={treeData} treeData={treeData}
style={style} style={style}
value={currentSelect}
expandedKeys={defaultExpandedKey} expandedKeys={defaultExpandedKey}
filterTreeNode={true} filterTreeNode={true}
searchRender={false} searchRender={false}

Loading…
Cancel
Save