diff --git a/api/app/lib/controllers/resourceRepository/index.js b/api/app/lib/controllers/resourceRepository/index.js index d5ec279..cd70a08 100644 --- a/api/app/lib/controllers/resourceRepository/index.js +++ b/api/app/lib/controllers/resourceRepository/index.js @@ -6,7 +6,7 @@ async function getResourceClassify(ctx) { const { models } = ctx.fs.dc; let rlst = []; rlst = [{ - label: "公司培训资料", value: "company", key: "公司培训资料", operation: true, children: [] + label: "公司培训资料", value: "company", key: "公司培训资料", operation: false, children: [] }, { label: "部门培训资料", value: 'dept', key: '部门培训资料', operation: false, children: [] }]; const findObj = { order: [["departmentName", "asc"]] } const filterData = (arrayData, arrIndex, operation) => { @@ -173,20 +173,50 @@ async function postResourceClassify(ctx) { if (trainDate && '' != trainDate) { where.trainDate = trainDate; } - const oldData = await models.TrainingInformation.findOne(where); + const oldData = await models.TrainingInformation.findOne({ where }); + if (oldData) { + ctx.throw("该文件夹已存在"); + } else { + await models.TrainingInformation.create({ + departmentName: departmentName, + trainDate: trainDate + }) + } + } + ctx.status = 204; + } catch (err) { + ctx.status = 400; + ctx.body = { message: err.message || '新增培训资源储备库文件夹失败' } + } +} +async function putResourceClassify(ctx) { + try { + const { models } = ctx.fs.dc; + const { oldDepName, oldTrainDate, departmentName, trainDate } = ctx.request.body; + if (departmentName && '' != departmentName && oldDepName && '' != oldDepName) { + const where = { departmentName: oldDepName }; + + if (trainDate && '' != trainDate && oldTrainDate && '' != oldTrainDate) { + where.trainDate = oldTrainDate; + await models.TrainingInformation.update({ trainDate: trainDate }, { where }); + //三级目录 + } else { + //二级目录 + await models.TrainingInformation.update({ departmentName: departmentName }, { where }); + } } ctx.status = 204; } catch (err) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; - ctx.body = { message: err.message || '查询培训资源储备库文件列表失败' } + ctx.body = { message: err.message || '编辑培训资源储备库文件夹失败' }; } } module.exports = { getResourceClassify, getResourceFileList, - postResourceClassify + postResourceClassify, + putResourceClassify } \ No newline at end of file diff --git a/api/app/lib/routes/resourceRepository/index.js b/api/app/lib/routes/resourceRepository/index.js index 6a152e1..59f5727 100644 --- a/api/app/lib/routes/resourceRepository/index.js +++ b/api/app/lib/routes/resourceRepository/index.js @@ -9,4 +9,11 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/train/trainFiles/resourceRepository/fileList'] = { content: '查询培训资源储备库文件列表', visible: false }; router.get('/train/trainFiles/resourceRepository/fileList', resourceRepository.getResourceFileList); + + app.fs.api.logAttr['POST/train/trainFiles/resourceRepository/classify'] = { content: '新增培训资源储备库文件夹', visible: false }; + router.post('/train/trainFiles/resourceRepository/classify', resourceRepository.postResourceClassify); + + app.fs.api.logAttr['PUT/train/trainFiles/resourceRepository/classify'] = { content: '编辑培训资源储备库文件夹', visible: false }; + router.put('/train/trainFiles/resourceRepository/classify', resourceRepository.putResourceClassify); + }; \ No newline at end of file diff --git a/web/client/src/sections/humanAffairs/actions/resourceRepository.js b/web/client/src/sections/humanAffairs/actions/resourceRepository.js index 970f1da..054831d 100644 --- a/web/client/src/sections/humanAffairs/actions/resourceRepository.js +++ b/web/client/src/sections/humanAffairs/actions/resourceRepository.js @@ -32,8 +32,7 @@ export function postResourceClassify(data) { data, actionType: "POST_RESOURCE_CLASSIFY", url: `${ApiTable.postResourceClassify}`, - msg: { option: "新增" }, - reducer: { name: "" }, + msg: { success: "新建成功" }, }); } @@ -45,8 +44,7 @@ export function putResourceClassify(data) { data, actionType: "PUT_RESOURCE_CLASSIFY", url: `${ApiTable.putResourceClassify}`, - msg: { option: "修改" }, - reducer: {}, + msg: { option: "编辑" }, }); } @@ -58,7 +56,6 @@ export function delResourceClassify(data) { dispatch: dispatch, actionType: "DEL_RESOURCE_CLASSIFY", url: `${ApiTable.delResourceClassify}`, - msg: { option: "删除" }, //删除 - reducer: {}, + msg: { option: "删除" }, }); } \ No newline at end of file diff --git a/web/client/src/sections/humanAffairs/components/resourceRepository/folder-model.jsx b/web/client/src/sections/humanAffairs/components/resourceRepository/folder-model.jsx new file mode 100644 index 0000000..eaa7178 --- /dev/null +++ b/web/client/src/sections/humanAffairs/components/resourceRepository/folder-model.jsx @@ -0,0 +1,99 @@ +import React, { useRef } from 'react'; +import { Modal, Form, Button, Input } from '@douyinfe/semi-ui'; + +const FolderModal = (props) => { + const { modalData, oldData, onCancel, onOk } = props; + const { title, childFolder, departmentName, trainDate } = modalData; + const add = title.includes("新建"); + + const form = useRef();//表单 + const validatName = (val) => { + if (val && '' == val.trim()) { + return '不可以为空'; + } else + if (val.length > 20) { + return '最大20字符'; + } else { + if (oldData.children) { + if (childFolder) {//三级目录 + let deptChild = oldData.children.find(r => r.label == departmentName).children; + if (!add) { + deptChild = deptChild.filter(r => trainDate != r.label); + } + const old = deptChild.find(r => r.label == val.trim()); + if (old) { + return ("该文件已存在"); + } else { + return ''; + } + } else { //二级目录 + let deptData = oldData.children; + if (!add) { + deptData = deptData.filter(r => departmentName != r.label); + } + const old = deptData.find(r => r.label == val.trim()); + if (old) { + return ("该文件已存在"); + } else { + return ''; + } + } + } + } + return ''; + } + const handleOk = () => { + + form.current.validate().then((values) => { + if (!add) { + values.oldDepName = departmentName; + values.oldTrainDate = trainDate; + } + onOk(add, values); + }); + } + return ( +
(form.current = formApi)} + labelPosition={'left'} + labelAlign={'right'} + labelCol={{ span: 6 }} + wrapperCol={{ span: 18 }} + > + {!childFolder && } + + {childFolder && + < Form.Input + field="trainDate" + label="子文件夹" + initValue={trainDate} + validate={validatName} + trigger='blur' + rules={[{ required: true, message: "请输入子文件夹" }]} + />} + +
+ ) +} +export default FolderModal \ No newline at end of file diff --git a/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx b/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx index 5fa3ef8..2f38afc 100644 --- a/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx +++ b/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx @@ -1,8 +1,9 @@ import React, { useEffect, useState, useRef } from 'react'; import { connect } from 'react-redux'; -import { Button, Col, Row, Input, Tree, Table, Space, Tooltip, Spin } from '@douyinfe/semi-ui'; +import { Button, Col, Row, Input, Tree, Table, Space, Tooltip, Spin, Notification } from '@douyinfe/semi-ui'; import { IconSearch, IconEditStroked, IconMinusCircleStroked, IconPlusCircleStroked } from '@douyinfe/semi-icons'; -import { getResourceClassify, getResourceFileList } from '../actions/resourceRepository'; +import { getResourceClassify, getResourceFileList, postResourceClassify, putResourceClassify, delResourceClassify } from '../actions/resourceRepository'; +import FolderModal from '../components/resourceRepository/folder-model'; import '../style.less'; const ResourceRepository = (props) => { @@ -10,27 +11,12 @@ const ResourceRepository = (props) => { const [treeData, setTreeData] = useState([]); const [currentSelect, setCurrentSelect] = useState(); const [defaultExpandedKey, setDefaultExpandedKey] = useState(); + const [modelVisiable, setModelVisiable] = useState(false); + const [modalData, setModalData] = useState(); const ref = useRef(); useEffect(() => { - dispatch(getResourceClassify()).then(res => { - const { success, payload } = res; - if (success) { - let defaultKey = ""; - if (payload.data.length) { - if (payload.data[0].children && payload.data[0].children.length) { - defaultKey = payload.data[0].children[0].key; - setDefaultExpandedKey([payload.data[0].key, payload.data[0].children[0].key]); - } else { - defaultKey = payload.data[0].key; - setDefaultExpandedKey([payload.data[0].key]); - } - } - setCurrentSelect([defaultKey]); - setTreeData(payload.data); - getFile(defaultKey); - } - }); + getClassify(); }, []) const style = { @@ -60,21 +46,50 @@ const ResourceRepository = (props) => { } ]; - const renderLabel = (label, data) => (
- {label.length > 8 ? label.substring(0, 8) + '...' : label} - {true == data.operation ? - - alert("bianji")} /> - alert("sahnchu")} /> - {data.children ? alert("+")} /> : ''} - - : ''} -
- ); + const renderLabel = (label, data) => { + const child = data.children ? true : false; + const key = data.key.split('/'); + return (
+ {label.length > 8 ? label.substring(0, 8) + '...' : label} + {true == data.operation ? + + handleFolderClick(child ? '编辑' : '编辑子', !child, key[1], key[2] || undefined)} /> + alert("sahnchu")} /> + {child ? + handleFolderClick('新建子', true, label, undefined)} + /> : ''} + + : ''} +
) + }; + const handleFolderClick = (title, childFolder, departmentName, trainDate) => { + setModelVisiable(true); + setModalData({ title, childFolder, departmentName, trainDate }); + } const handleSelect = (e) => { setCurrentSelect(e); getFile(e); } + const handleDataToSave = (add, body) => { + if (add) { + dispatch(postResourceClassify(body)).then(res => { + if (res.success) { + getClassify(); + setModelVisiable(false); + } + }); + } else { + dispatch(putResourceClassify(body)).then(res => { + if (res.success) { + getClassify(); + setModelVisiable(false); + } + }); + } + + } const getFile = (e) => { const arr = e.split("/"); const query = { type: arr[0] }; @@ -82,6 +97,26 @@ const ResourceRepository = (props) => { if (arr[2]) { query.trainDate = arr[2]; } dispatch(getResourceFileList(query)); } + const getClassify = () => { + dispatch(getResourceClassify()).then(res => { + const { success, payload } = res; + if (success) { + let defaultKey = ""; + if (payload.data.length) { + if (payload.data[0].children && payload.data[0].children.length) { + defaultKey = payload.data[0].children[0].key; + setDefaultExpandedKey([payload.data[0].key, payload.data[0].children[0].key]); + } else { + defaultKey = payload.data[0].key; + setDefaultExpandedKey([payload.data[0].key]); + } + } + setCurrentSelect([defaultKey]); + setTreeData(payload.data); + getFile(defaultKey); + } + }); + } return ( <> @@ -105,7 +140,7 @@ const ResourceRepository = (props) => { {/* 左侧 */} - +
} showClear onChange={v => ref.current.search(v)} placeholder="请输入"> {
+ {modelVisiable ? + '公司培训资料' == r.label)} + modalData={modalData} + onOk={handleDataToSave} + onCancel={() => { setModelVisiable(false) }} + /> : null + } ) diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index 2c03b45..d27794f 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -51,8 +51,8 @@ export const ApiTable = { //-培训资料库 getResourceClassify: 'train/trainFiles/resourceRepository/classify', postResourceClassify: 'train/trainFiles/resourceRepository/classify', - putResourceClassify: 'train/trainFiles/resourceRepository/classify/{id}', - delResourceClassify: 'train/trainFiles/resourceRepository/classify/{id}', + putResourceClassify: 'train/trainFiles/resourceRepository/classify', + delResourceClassify: 'train/trainFiles/resourceRepository/classify', getResourceFileList: 'train/trainFiles/resourceRepository/fileList', };