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

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

@ -1,13 +1,19 @@
import React, { useEffect, useState ,useRef} from 'react'; import React, { useEffect, useState, useRef } from 'react';
import { connect } from 'react-redux'; 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 { IconSearch, IconEditStroked, IconMinusCircleStroked, IconPlusCircleStroked } from '@douyinfe/semi-icons';
import { getResourceClassify } from '../actions/resourceRepository';
import '../style.less' import '../style.less'
const ResourceRepository = (props) => { const ResourceRepository = (props) => {
const { dispatch, actions, clientHeight } = props; const { dispatch, actions, clientHeight, resourceClassify } = props;
const ref = useRef(); const ref = useRef();
useEffect(() => {
dispatch(getResourceClassify());
}, [])
const treeData = [ const treeData = [
{ {
label: (<div> label: (<div>
@ -185,6 +191,16 @@ const ResourceRepository = (props) => {
avatarBg: 'light-blue', 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 ( return (
<> <>
@ -212,13 +228,14 @@ 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={treeData} treeData={resourceClassify}
defaultExpandAll defaultExpandAll
filterTreeNode filterTreeNode
searchRender={false} searchRender={false}
blockNode={false} blockNode={false}
directory directory
style={style} style={style}
renderLabel={renderLabel}
/> />
</Col> </Col>
{/* 右侧内容 */} {/* 右侧内容 */}
@ -244,11 +261,12 @@ const ResourceRepository = (props) => {
} }
function mapStateToProps(state) { function mapStateToProps(state) {
const { auth, global } = state; const { auth, global, resourceClassify } = state;
return { return {
user: auth.user, user: auth.user,
actions: global.actions, actions: global.actions,
clientHeight: global.clientHeight, clientHeight: global.clientHeight,
resourceClassify: resourceClassify.data || []
}; };
} }

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

@ -37,11 +37,16 @@ export const ApiTable = {
editSalesMember: 'sales/member/modify', editSalesMember: 'sales/member/modify',
delSalesMember: 'sales/member/del', delSalesMember: 'sales/member/del',
addSalesMemberBulk: 'add/sales/members/bulk', addSalesMemberBulk: 'add/sales/members/bulk',
//部门培训记录 //部门培训记录
getDepartmentTrainRecord: 'department/train/record/list', getDepartmentTrainRecord: 'department/train/record/list',
importDepartmentTrainRecord: 'department/train/record/bulk', importDepartmentTrainRecord: 'department/train/record/bulk',
modifyDepartmentTrainRecord: 'department/train/record/modify', 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 = { export const RouteTable = {
apiRoot: "/api/root", apiRoot: "/api/root",

Loading…
Cancel
Save