Browse Source

(*)处理冲突

master
ww664853070 2 years ago
parent
commit
8cd2f9cbea
  1. 113
      api/app/lib/controllers/resourceRepository/index.js
  2. 6
      api/app/lib/models/training_information_level.js
  3. 9
      api/app/lib/routes/resourceRepository/index.js
  4. 5
      web/client/src/sections/humanAffairs/actions/index.js
  5. 54
      web/client/src/sections/humanAffairs/actions/resourceRepository.js
  6. 48
      web/client/src/sections/humanAffairs/containers/resourceRepository.jsx
  7. 8
      web/client/src/utils/webapi.js

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

@ -0,0 +1,113 @@
'use strict';
const moment = require('moment')
async function getResourceClassify(ctx) {
try {
const { models } = ctx.fs.dc;
const { limit, offset } = ctx.query;
let rlst = [];
const findObj = {}
if (Number(limit) > 0 && Number(offset) >= 0) {
findObj.limit = Number(limit);
findObj.offset = Number(offset);
}
const trainingInformationLevel = await models.TrainingInformationLevel.findAll(findObj);
if (trainingInformationLevel.length) {
rlst = [{
label: "公司培训资料", value: "company", key: "company", operation: true,
}, { label: "部门培训资料", value: 'dept', key: 'dept', operation: false }];
for (let level of trainingInformationLevel) {
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级是否记录
if (rlst[arrIndex].children) {
const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname);
if (depIndex > -1) {
if (rlst[arrIndex].children[depIndex].children) {
rlst[arrIndex].children[depIndex].children.push({
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,
operation
}]
}
} else {
rlst[arrIndex].children.push({
label: departmentname,
children: [{
label: moment(traindate).format('YYYY-MM'),
value: id,
key: id,
operation
}]
});
}
} else {
rlst[arrIndex].children = [{
label: departmentname,
children: [{
label: moment(traindate).format('YYYY-MM'),
value: id,
key: id,
operation
}]
}]
}
} else {
if (rlst[arrIndex].children) {
const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname);
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({
label: departmentname,
value: id,
key: id,
operation
})
}
} else {
rlst[arrIndex].children = [{
label: departmentname,
value: id,
key: id,
operation
}]
}
}
}
}
}
}
ctx.status = 200;
ctx.body = rlst;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: '查询培训资源储备库分类目录失败'
}
}
}
module.exports = {
getResourceClassify
}

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

@ -28,16 +28,16 @@ module.exports = dc => {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: null,
comment: '部门(2级目录)',
primaryKey: false,
field: "departmentname",
autoIncrement: false
},
traindate: {
type: DataTypes.DATE,
allowNull: false,
allowNull: true,
defaultValue: null,
comment: null,
comment: '培训时间(3级目录)',
primaryKey: false,
field: "traindate",
autoIncrement: false

9
api/app/lib/routes/resourceRepository/index.js

@ -0,0 +1,9 @@
'use strict';
/**培训资料库 */
const resourceRepository = require('../../controllers/resourceRepository');
module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/train/trainFiles/resourceRepository/classify'] = { content: '查询培训资源储备库分类目录', visible: false };
router.get('/train/trainFiles/resourceRepository/classify', resourceRepository.getResourceClassify);
};

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

@ -5,10 +5,13 @@ import * as employeeInformation from './employeeInformation'
import * as salesDistribution from './salesDistribution'
import * as departmentTrain from './departmentTrain'
import * as personalTrainRecord from './personalTrainRecord'
import * as resourceRepository from './resourceRepository'
export default {
...personnelFiles,
...employeeInformation,
...salesDistribution,
...departmentTrain,
...personalTrainRecord
...personalTrainRecord,
...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: {},
});
}

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

@ -1,19 +1,27 @@
import React, { useEffect, useState } from 'react';
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>
<span>亚洲</span>
<span className='tree-icon'>
<IconEditStroked size='default' onClick={() => alert("bianji")} />
<IconMinusCircleStroked size='default' onClick={() => alert("sahnchu")}/>
<IconPlusCircleStroked size='default' onClick={() => alert("+")}/></span>
<IconMinusCircleStroked size='default' onClick={() => alert("sahnchu")} />
<IconPlusCircleStroked size='default' onClick={() => alert("+")} /></span>
</div>
),
value: 'Asia',
@ -46,17 +54,17 @@ const ResourceRepository = (props) => {
{
label: '中国',
value: 'China',
key: '0-0',
key: '1-0',
children: [
{
label: '北京',
value: 'Beijing',
key: '0-0-0',
value: 'Beijing2',
key: '1-0-0',
},
{
label: '上海',
value: 'Shanghai',
key: '0-0-1',
key: '1-0-1',
},
],
},
@ -183,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 (
<>
@ -207,12 +225,17 @@ const ResourceRepository = (props) => {
<Col className='left' span={6}>
<Button theme='solid' type='primary' >新建文件夹</Button>
<br />
<Input suffix={<IconSearch />} showClear placeholder="请输入"></Input>
<Input suffix={<IconSearch />} showClear onChange={v => ref.current.search(v)} placeholder="请输入"></Input>
<Tree
treeData={treeData}
ref={ref}
treeData={resourceClassify}
defaultExpandAll
filterTreeNode
searchRender={false}
blockNode={false}
directory
style={style}
renderLabel={renderLabel}
/>
</Col>
{/* 右侧内容 */}
@ -238,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 || []
};
}

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

@ -43,8 +43,16 @@ export const ApiTable = {
importDepartmentTrainRecord: 'department/train/record/bulk',
modifyDepartmentTrainRecord: 'department/train/record/modify',
//个人培训记录
getPersonalTrainRecord: 'personal/train/record/list',
//-培训资料库
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