Browse Source

培训资源库:左侧引入真实数据

master
周沫沫历险记 2 years ago
parent
commit
f80c453745
  1. 28
      api/app/lib/controllers/resourceRepository/index.js
  2. 5
      web/client/src/sections/humanAffairs/actions/index.js
  3. 54
      web/client/src/sections/humanAffairs/actions/resourceRepository.js
  4. 26
      web/client/src/sections/humanAffairs/containers/resourceRepository.jsx
  5. 5
      web/client/src/utils/webapi.js

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

@ -6,7 +6,7 @@ async function getResourceClassify(ctx) {
const { models } = ctx.fs.dc;
const { limit, offset } = ctx.query;
let rlst = [];
const findObj = { plain: false, group: ["type", "id"] }
const findObj = {}
if (Number(limit) > 0 && Number(offset) >= 0) {
findObj.limit = Number(limit);
findObj.offset = Number(offset);
@ -14,14 +14,15 @@ async function getResourceClassify(ctx) {
const trainingInformationLevel = await models.TrainingInformationLevel.findAll(findObj);
if (trainingInformationLevel.length) {
rlst = [{
label: "公司培训资料", value: "company", operation: true,
}, { label: "部门培训资料", value: 'dept', operation: false }];
label: "公司培训资料", value: "company", key: "company", operation: true,
}, { label: "部门培训资料", value: 'dept', key: 'dept', operation: false }];
for (let level of trainingInformationLevel) {
const { id, type, departmentname, traindate } = level;
const { id, type, departmentname, traindate, origin } = level;
/**type:1级, departmentname:2级,traindate:3级 */
const arrIndex = rlst.findIndex(item => item.label == type)
if (arrIndex > -1) {//一级分类名称正确
const operation = "import" == origin ? true : false;
if (departmentname) {
if (traindate) {
//区分2级是否记录
@ -33,22 +34,25 @@ async function getResourceClassify(ctx) {
label: moment(traindate).format('YYYY-MM'),
value: id,
key: id,
operation
})
} else {
rlst[arrIndex].children[depIndex].children = [{
label: moment(traindate).format('YYYY-MM'),
value: id,
key: id
key: id,
operation
}]
}
} else {
rlst[arrIndex].children.push({
label: departmentname,
children: {
children: [{
label: moment(traindate).format('YYYY-MM'),
value: id,
key: id
}
key: id,
operation
}]
});
}
} else {
@ -58,6 +62,7 @@ async function getResourceClassify(ctx) {
label: moment(traindate).format('YYYY-MM'),
value: id,
key: id,
operation
}]
}]
}
@ -68,19 +73,22 @@ async function getResourceClassify(ctx) {
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({
label: departmentname,
value: id,
key: id
key: id,
operation
})
}
} else {
rlst[arrIndex].children = [{
label: departmentname,
value: id,
key: id
key: id,
operation
}]
}
}

5
web/client/src/sections/humanAffairs/actions/index.js

@ -4,9 +4,12 @@ import * as personnelFiles from './personnelFiles'
import * as employeeInformation from './employeeInformation'
import * as salesDistribution from './salesDistribution'
import * as departmentTrain from './departmentTrain'
import * as resourceRepository from './resourceRepository'
export default {
...personnelFiles,
...employeeInformation,
...salesDistribution,
...departmentTrain
...departmentTrain,
...resourceRepository
}

54
web/client/src/sections/humanAffairs/actions/resourceRepository.js

@ -0,0 +1,54 @@
'use strict';
import { ApiTable, basicAction } from '$utils'
export function getResourceClassify() {//查询籍贯列表
return (dispatch) => basicAction({
type: "get",
dispatch: dispatch,
actionType: "GET_RESOURCE_CLASSIFY",
// query: query,
url: `${ApiTable.getResourceClassify}`,
msg: { option: "查询培训资料库目录" },
reducer: { name: "resourceClassify" },
});
}
export function postResourceClassify(data) {
return (dispatch) =>
basicAction({
type: "post",
dispatch: dispatch,
data,
actionType: "POST_RESOURCE_CLASSIFY",
url: `${ApiTable.postResourceClassify}`,
msg: { option: "新增" },
reducer: { name: "" },
});
}
export function putResourceClassify(data) {
return (dispatch) =>
basicAction({
type: "put",
dispatch: dispatch,
data,
actionType: "PUT_RESOURCE_CLASSIFY",
url: `${ApiTable.putResourceClassify}`,
msg: { option: "修改" },
reducer: {},
});
}
export function delResourceClassify(data) {
return (dispatch) =>
basicAction({
type: "del",
query: data,
dispatch: dispatch,
actionType: "DEL_RESOURCE_CLASSIFY",
url: `${ApiTable.delResourceClassify}`,
msg: { option: "删除" }, //删除
reducer: {},
});
}

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

@ -1,13 +1,19 @@
import React, { useEffect, useState, useRef } from 'react';
import { connect } from 'react-redux';
import { Button, Col, Row, Input, Tree, Table, Space } from '@douyinfe/semi-ui';
import { Button, Col, Row, Input, Tree, Table, Space, Tooltip } from '@douyinfe/semi-ui';
import { IconSearch, IconEditStroked, IconMinusCircleStroked, IconPlusCircleStroked } from '@douyinfe/semi-icons';
import { getResourceClassify } from '../actions/resourceRepository';
import '../style.less'
const ResourceRepository = (props) => {
const { dispatch, actions, clientHeight } = props;
const { dispatch, actions, clientHeight, resourceClassify } = props;
const ref = useRef();
useEffect(() => {
dispatch(getResourceClassify());
}, [])
const treeData = [
{
label: (<div>
@ -185,6 +191,16 @@ const ResourceRepository = (props) => {
avatarBg: 'light-blue',
}
];
const renderLabel = (label, data) => (<div>
<Tooltip content={label}><span >{label.length > 8 ? label.substring(0, 8) + '...' : label}</span></Tooltip>
{true == data.operation ?
<span className='tree-icon'>
<IconEditStroked size='default' onClick={() => alert("bianji")} />
<IconMinusCircleStroked size='default' onClick={() => alert("sahnchu")} />
<IconPlusCircleStroked size='default' onClick={() => alert("+")} /></span>
: ''}
</div>
)
return (
<>
@ -212,13 +228,14 @@ const ResourceRepository = (props) => {
<Input suffix={<IconSearch />} showClear onChange={v => ref.current.search(v)} placeholder="请输入"></Input>
<Tree
ref={ref}
treeData={treeData}
treeData={resourceClassify}
defaultExpandAll
filterTreeNode
searchRender={false}
blockNode={false}
directory
style={style}
renderLabel={renderLabel}
/>
</Col>
{/* 右侧内容 */}
@ -244,11 +261,12 @@ const ResourceRepository = (props) => {
}
function mapStateToProps(state) {
const { auth, global } = state;
const { auth, global, resourceClassify } = state;
return {
user: auth.user,
actions: global.actions,
clientHeight: global.clientHeight,
resourceClassify: resourceClassify.data || []
};
}

5
web/client/src/utils/webapi.js

@ -42,6 +42,11 @@ export const ApiTable = {
getDepartmentTrainRecord: 'department/train/record/list',
importDepartmentTrainRecord: 'department/train/record/bulk',
modifyDepartmentTrainRecord: 'department/train/record/modify',
//-培训资料库
getResourceClassify: 'train/trainFiles/resourceRepository/classify',
postResourceClassify: 'train/trainFiles/resourceRepository/classify',
putResourceClassify: 'train/trainFiles/resourceRepository/classify/{id}',
delResourceClassify: 'train/trainFiles/resourceRepository/classify/{id}',
};
export const RouteTable = {
apiRoot: "/api/root",

Loading…
Cancel
Save