Browse Source

(*)初始加载路由判断,权限配置修改

master
zmh 1 year ago
parent
commit
19c327caca
  1. 15
      api/app/lib/controllers/auth/index.js
  2. 3
      web/client/src/layout/components/header/index.jsx
  3. 21
      web/client/src/layout/containers/layout/index.jsx
  4. 45
      web/client/src/sections/humanAffairs/containers/employeeAuth.jsx
  5. 14
      web/client/src/sections/humanAffairs/nav-item.jsx
  6. 71
      web/client/src/utils/func.js
  7. 27
      web/client/src/utils/index.js

15
api/app/lib/controllers/auth/index.js

@ -82,13 +82,14 @@ async function login(ctx, next) {
}); });
const { adminHr, id } = emisLoginRes; const { adminHr, id } = emisLoginRes;
let codes = []; let codes = [];
let resources = [];
//人资管理员-所有权限 //人资管理员-所有权限
if (adminHr.some(admin => admin.id == id)) { if (adminHr.some(admin => admin.id == id)) {
const resource = await models.Resource.findAll({ resources = await models.Resource.findAll({
attributes: ['code'], attributes: ['id', 'name', 'code', 'parentId'],
order: [['id', 'asc']] order: [['id', 'asc']]
}) })
codes = resource.map(r => r.code); codes = resources.map(r => r.code);
} else { } else {
const userResources = await models.RoleResource.findAll({ const userResources = await models.RoleResource.findAll({
attributes: ['id', 'resId'], attributes: ['id', 'resId'],
@ -104,18 +105,18 @@ async function login(ctx, next) {
}, { }, {
required: true, required: true,
model: models.Resource, model: models.Resource,
attributes: ['id', 'name', 'code'], attributes: ['id', 'name', 'code', 'parentId'],
}], }],
order: [['id', 'asc']] order: [['id', 'asc']]
}); });
let rslt = [];
userResources && userResources.map(ur => { userResources && userResources.map(ur => {
if (!rslt.some(r => r.id === ur.resId)) { if (!resources.some(r => r.id === ur.resId)) {
rslt.push(ur.resource); resources.push(ur.resource);
codes.push(ur.resource.code); codes.push(ur.resource.code);
} }
}) })
} }
emisLoginRes.resources = resources;
emisLoginRes.codes = codes; emisLoginRes.codes = codes;
ctx.status = 200; ctx.status = 200;
ctx.body = emisLoginRes; ctx.body = emisLoginRes;

3
web/client/src/layout/components/header/index.jsx

@ -1,8 +1,7 @@
"use strict"; "use strict";
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { connect } from "react-redux"; import { connect } from "react-redux";
import { SplitButtonGroup, Dropdown, Button, Nav, Avatar } from '@douyinfe/semi-ui'; import { Nav } from '@douyinfe/semi-ui';
import { IconTreeTriangleDown } from '@douyinfe/semi-icons';
import { headerItemsFun } from './contant'; import { headerItemsFun } from './contant';
import "./index.less"; import "./index.less";

21
web/client/src/layout/containers/layout/index.jsx

@ -10,7 +10,7 @@ import { resize } from '../../actions/global';
import * as NProgress from 'nprogress'; import * as NProgress from 'nprogress';
import PerfectScrollbar from 'perfect-scrollbar'; import PerfectScrollbar from 'perfect-scrollbar';
import { useLocation } from "react-router"; import { useLocation } from "react-router";
import { RouteTable } from '$utils'; import { RouteTable, defaultUrl } from '$utils';
import { RouteRequest } from '@peace/utils'; import { RouteRequest } from '@peace/utils';
import Cookie from 'js-cookie'; import Cookie from 'js-cookie';
import { login, LOGIN_SUCCESS } from '../../../sections/auth/actions/auth'; import { login, LOGIN_SUCCESS } from '../../../sections/auth/actions/auth';
@ -207,6 +207,19 @@ const LayoutContainer = props => {
} }
} }
}) })
const getRouteUrl = (resources) => {
let newCodes = [];
let firstParentIds = resources.filter(c => !c.parentId);
firstParentIds = firstParentIds.map(p => p.id);
let resourcesNew = resources.filter(c => c.parentId);
resourcesNew.map(c => {
if (firstParentIds.includes(c.parentId)) {
newCodes.push({ id: c.id, code: c.code });
}
})
newCodes = newCodes.sort((a, b) => (a.id - b.id))
return newCodes;
}
const getUserInfoByToken = () => { const getUserInfoByToken = () => {
if (requestUser) { if (requestUser) {
requestUser = false; requestUser = false;
@ -215,9 +228,11 @@ const LayoutContainer = props => {
dispatch(login({ token })).then(res => { dispatch(login({ token })).then(res => {
if (res.type == 'LOGIN_SUCCESS') { if (res.type == 'LOGIN_SUCCESS') {
const data = res.payload?.user || {} const data = res.payload?.user || {}
if (data.codes && data.codes.length) { let newCodes = getRouteUrl(data.resources);
if (newCodes && newCodes.length) {
let url = defaultUrl[newCodes[0].code].url;
dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token, hrUserId: data.hrUserInfo && hrUserInfo.id })) dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token, hrUserId: data.hrUserInfo && hrUserInfo.id }))
history.push('/humanAffairs/archivesCenter/personnelArchives/personnelFiles') history.push(url)
localStorage.setItem('poms_open_sider', JSON.stringify(["archivesCenter"])) localStorage.setItem('poms_open_sider', JSON.stringify(["archivesCenter"]))
localStorage.setItem('poms_selected_sider', JSON.stringify(["humanAffairs"])) localStorage.setItem('poms_selected_sider', JSON.stringify(["humanAffairs"]))
setLoading(false); setLoading(false);

45
web/client/src/sections/humanAffairs/containers/employeeAuth.jsx

@ -109,17 +109,6 @@ const EmployeeAuth = (props) => {
const dataRangeChange = (e) => { const dataRangeChange = (e) => {
setDataRange(e.target.value); setDataRange(e.target.value);
}; };
const treeList = []
if (resourceList && resourceList.rows) {
resourceList.rows.forEach((item) => {
item.child = resourceList.rows.filter((sec) => {
return sec.parentId === item.id
})
if (item.parentId === null) {
treeList.push(item)
}
})
}
const getValues = () => { const getValues = () => {
let two = {} let two = {}
let checkedList = []; let checkedList = [];
@ -144,6 +133,22 @@ const EmployeeAuth = (props) => {
}) })
return { two, checkedList }; return { two, checkedList };
} }
const treeList = []
if (resourceList && resourceList.rows) {
resourceList.rows.forEach((item) => {
item.child = resourceList.rows.filter((sec) => {
return sec.parentId === item.id
})
if (item.parentId === null) {
treeList.push(item)
}
})
let values = getValues();
if (!Alltwo)
Alltwo = values.two;
if (!AllCheckedList)
AllCheckedList = values.checkedList;
}
const onChangeAll = (value) => { const onChangeAll = (value) => {
if (value.target.checked) { if (value.target.checked) {
setAllChecked(true); setAllChecked(true);
@ -169,7 +174,8 @@ const EmployeeAuth = (props) => {
resourceIdAll = [...values.checkedList, ...resourceIdAll]; resourceIdAll = [...values.checkedList, ...resourceIdAll];
resourceIdAll = resourceIdAll.sort((a, b) => (a - b)); resourceIdAll = resourceIdAll.sort((a, b) => (a - b));
} else { } else {
resourceIdAll = [...AllCheckedList, ...Alltwo]; resourceIdAll = Object.keys(Alltwo);
resourceIdAll = [...AllCheckedList, ...resourceIdAll];
resourceIdAll = resourceIdAll.sort((a, b) => (a - b)); resourceIdAll = resourceIdAll.sort((a, b) => (a - b));
} }
return resourceIdAll; return resourceIdAll;
@ -235,7 +241,7 @@ const EmployeeAuth = (props) => {
setCheckedList([...checkedList, ...selList]) setCheckedList([...checkedList, ...selList])
twos[value.target.value] = true twos[value.target.value] = true
twos[recod.id] = true twos[recod.id] = true
setTwo(two) setTwo(twos)
const resourceIdAll = getResourceIdAll(); const resourceIdAll = getResourceIdAll();
const resourceIds = getResourceIds(two, [...checkedList, ...selList]) const resourceIds = getResourceIds(two, [...checkedList, ...selList])
if (resourceIds.toString() === resourceIdAll.toString()) { if (resourceIds.toString() === resourceIdAll.toString()) {
@ -245,9 +251,10 @@ const EmployeeAuth = (props) => {
} }
} else { } else {
setAllChecked(false); setAllChecked(false);
selList.push(value.target.value);
setCheckedList(getDiffer(checkedList, selList)); setCheckedList(getDiffer(checkedList, selList));
twos[value.target.value] = false twos[value.target.value] = false
setTwo(two) setTwo(twos)
} }
}; };
const checkItem = (e, recod) => { const checkItem = (e, recod) => {
@ -315,9 +322,11 @@ const EmployeeAuth = (props) => {
let two = {} let two = {}
let checkList = [] let checkList = []
if (res.payload.data && res.payload.data.rows.length) { if (res.payload.data && res.payload.data.rows.length) {
checkList = res.payload.data.rows.map(e => { res.payload.data.rows.map(e => {
two[e.resId] = true if (Alltwo[e.resId])
return e.resId two[e.resId] = true
if (AllCheckedList.includes(e.resId))
checkList.push(e.resId)
}) })
setDataRange(res.payload.data.rows[0].role.dataRange || 1); setDataRange(res.payload.data.rows[0].role.dataRange || 1);
setCheckedList(checkList) setCheckedList(checkList)
@ -342,6 +351,8 @@ const EmployeeAuth = (props) => {
for (let item in two) { for (let item in two) {
if (two[item]) { if (two[item]) {
resourceId.push(parseInt(item)); resourceId.push(parseInt(item));
} else {
setCheckedList(getDiffer(checkedList, [parseInt(item)]));
} }
} }
resourceId = [...checkedList, ...resourceId] resourceId = [...checkedList, ...resourceId]

14
web/client/src/sections/humanAffairs/nav-item.jsx

@ -16,7 +16,7 @@ export function getNavItem(user, dispatch) {
text: '人事管理', text: '人事管理',
icon: <IconCode />, icon: <IconCode />,
items: [ items: [
isAuthorized('PERSONNELFILEMANAGEMENT') ? { isAuthorized('PERSONNELFILES') || isAuthorized('EMPLOYEEINFORMATION') || isAuthorized('JOBRATING') ? {
itemKey: 'personnelArchives', itemKey: 'personnelArchives',
text: '人员档案', text: '人员档案',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbrengongdangan"></iconpark-icon>, icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbrengongdangan"></iconpark-icon>,
@ -42,7 +42,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'department', to: '/humanAffairs/archivesCenter/deptArchives/department', text: '部门档案' itemKey: 'department', to: '/humanAffairs/archivesCenter/deptArchives/department', text: '部门档案'
} : {}] } : {}]
} : {}, } : {},
isAuthorized('LEAVEMANAGEMENT') ? { isAuthorized('ATTENDANCESTATISTICS') || isAuthorized('LEAVESTATISTICS') || isAuthorized('OVERTIMESTATISTICS') ? {
itemKey: 'leaveManagement', itemKey: 'leaveManagement',
text: '假勤管理', text: '假勤管理',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbjiaqinguanli"></iconpark-icon>, icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbjiaqinguanli"></iconpark-icon>,
@ -102,7 +102,7 @@ export function getNavItem(user, dispatch) {
} : {} } : {}
] ]
} : {}, } : {},
isAuthorized('TRAININGMANAGEMENT') ? { isAuthorized('PERSONALTRAININGRECORDS') || isAuthorized('DEPARTMENTTRAININGRECORDS') ? {
itemKey: 'trainingManagement', itemKey: 'trainingManagement',
text: '培训管理', text: '培训管理',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="peixgl"></iconpark-icon>, icon: <iconpark-icon style={{ width: 20, height: 20 }} name="peixgl"></iconpark-icon>,
@ -115,7 +115,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'departmentTrainRecord', to: '/humanAffairs/train/trainingManagement/departmentTrainRecord', text: '部门培训记录' itemKey: 'departmentTrainRecord', to: '/humanAffairs/train/trainingManagement/departmentTrainRecord', text: '部门培训记录'
} : {}] } : {}]
} : {}, } : {},
isAuthorized('BASICACTIONMANAGEMENT') ? { isAuthorized('WEEKLYREPORTMANAGEMENT') || isAuthorized('SALESLOG') || isAuthorized('ENGINEERINGLOG') ? {
itemKey: 'basicAction', itemKey: 'basicAction',
text: '基本动作', text: '基本动作',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbjiben"></iconpark-icon>, icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbjiben"></iconpark-icon>,
@ -131,7 +131,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'pmLog', to: '/humanAffairs/achievements/basicAction/pmLog', text: '工程日志' itemKey: 'pmLog', to: '/humanAffairs/achievements/basicAction/pmLog', text: '工程日志'
} : {}] } : {}]
} : {}, } : {},
isAuthorized('EMPLOYEEASSESSMENT') ? { isAuthorized('EMPLOYEEASSESSMENTDURINGPROBATIONARYPERIOD') || isAuthorized('FORMALEMPLOYEEASSESSMENT') ? {
itemKey: 'employeeKPI', itemKey: 'employeeKPI',
text: '员工考核', text: '员工考核',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbyuangongkaohe"></iconpark-icon>, icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbyuangongkaohe"></iconpark-icon>,
@ -144,7 +144,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'regular', to: '/humanAffairs/achievements/employeeKPI/regular', text: '正式员工考核' itemKey: 'regular', to: '/humanAffairs/achievements/employeeKPI/regular', text: '正式员工考核'
} : {}] } : {}]
} : {}, } : {},
isAuthorized('MIDDLELEVELASSESSMENT') ? { isAuthorized('MIDDLELEVELMONTHLYPROCESSASSESSMENT') || isAuthorized('MIDLEVELQUARTERLYASSESSMENT') ? {
itemKey: 'middleKPI', itemKey: 'middleKPI',
text: '中层考核', text: '中层考核',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbzhongceng"></iconpark-icon>, icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbzhongceng"></iconpark-icon>,
@ -157,7 +157,7 @@ export function getNavItem(user, dispatch) {
itemKey: 'quarter', to: '/humanAffairs/achievements/middleKPI/quarter', text: '季度考核' itemKey: 'quarter', to: '/humanAffairs/achievements/middleKPI/quarter', text: '季度考核'
} : {}] } : {}]
} : {}, } : {},
isAuthorized('SENIORASSESSMENT') ? { isAuthorized('MONTHLYPROCESSASSESSMENTFORSENIORMANAGEMENT') || isAuthorized('QUARTERLYASSESSMENTOFSENIORMANAGEMENT') ? {
itemKey: 'highKPI', itemKey: 'highKPI',
text: '高管考核', text: '高管考核',
icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbgaojiguanli"></iconpark-icon>, icon: <iconpark-icon style={{ width: 20, height: 20 }} name="iconcbgaojiguanli"></iconpark-icon>,

71
web/client/src/utils/func.js

@ -6,4 +6,75 @@ export const isAuthorized = (authcode) => {
const { codes } = userInfo const { codes } = userInfo
return codes && codes.includes(authcode); return codes && codes.includes(authcode);
} }
}
export const defaultUrl = {
"PERSONNELFILES": {//人员档案
url: 'humanAffairs/archivesCenter/personnelArchives/personnelFiles'
},
"EMPLOYEEINFORMATION": {//员工信息
url: 'humanAffairs/archivesCenter/personnelArchives/employeeInformation'
},
"JOBRATING": {//岗位评级
url: 'humanAffairs/archivesCenter/personnelArchives/positionRating'
},
"DEPARTMENTARCHIVES": {//部门档案
url: 'humanAffairs/archivesCenter/deptArchives/department'
},
"ATTENDANCESTATISTICS": {//出勤统计
url: 'humanAffairs/employeeRelationship/leaveManagement/attendanceStatistics'
},
"LEAVESTATISTICS": {//请假统计
url: 'humanAffairs/employeeRelationship/leaveManagement/leaveStatistics'
},
"OVERTIMESTATISTICS": {//加班统计
url: 'humanAffairs/employeeRelationship/leaveManagement/overtimeStatistics'
},
"EMPLOYEECOMMUNICATIONSTATISTICS": {//员工沟通统计
url: 'humanAffairs/employeeRelationship/communication/employeeCommunication'
},
"APPOINTMENTRECORD": {//任用记录
url: 'humanAffairs/recruit/recruitRecord/appointmentRecords'
},
"SALESPERSONNELDISTRIBUTION": {//销售人员分布
url: 'humanAffairs/recruit/salesStatistics/personnelDistribution'
},
"TRAININGRESOURCEREPOSITORY": {//培训资源储存库
url: 'humanAffairs/train/trainFiles/resourceRepository'
},
"PERSONALTRAININGRECORDS": {//个人培训记录
url: 'humanAffairs/train/trainingManagement/personalTrainRecord'
},
"DEPARTMENTTRAININGRECORDS": {//部门培训记录
url: 'humanAffairs/train/trainingManagement/departmentTrainRecord'
},
"WEEKLYREPORTMANAGEMENT": {//周报管理
url: 'humanAffairs/achievements/basicAction/weeklyManagement'
},
"SALESLOG": {//销售日志
url: 'humanAffairs/achievements/basicAction/saleLog'
},
"ENGINEERINGLOG": {//工程日志
url: 'humanAffairs/achievements/basicAction/pmLog'
},
"EMPLOYEEASSESSMENTDURINGPROBATIONARYPERIOD": {//试用期员工考核
url: 'humanAffairs/achievements/employeeKPI/probationer'
},
"FORMALEMPLOYEEASSESSMENT": {//正式员工考核
url: 'humanAffairs/achievements/employeeKPI/regular'
},
"MIDDLELEVELMONTHLYPROCESSASSESSMENT": {//中层月度过程考核
url: 'humanAffairs/achievements/middleKPI/monthlyProcess'
},
"MIDLEVELQUARTERLYASSESSMENT": {//中层季度考核
url: 'humanAffairs/achievements/middleKPI/quarter'
},
"MONTHLYPROCESSASSESSMENTFORSENIORMANAGEMENT": {//高层月度过程考核
url: 'humanAffairs/achievements/highKPI/highMonthly'
},
"QUARTERLYASSESSMENTOFSENIORMANAGEMENT": {//高层季度考核
url: 'humanAffairs/achievements/highKPI/Highquarter'
},
"REWARDANDPUNISHMENTINFORMATION": {//奖惩信息
url: 'humanAffairs/achievements/penalties/penaltiesRecord'
}
} }

27
web/client/src/utils/index.js

@ -1,21 +1,22 @@
'use strict'; 'use strict';
import { isAuthorized } from './func'; import { isAuthorized, defaultUrl } from './func';
import { AuthorizationCode } from './authCode'; import { AuthorizationCode } from './authCode';
import { import {
ApiTable, RouteTable, ApiTable, RouteTable,
AxyRequest, EmisRequest, AxyRequest, EmisRequest,
basicAction, RouteRequest basicAction, RouteRequest
} from './webapi' } from './webapi'
import { UserAttribute } from './userAttribute'; import { UserAttribute } from './userAttribute';
export { export {
isAuthorized, isAuthorized,
AuthorizationCode, defaultUrl,
AuthorizationCode,
RouteTable, RouteTable,
ApiTable, ApiTable,
AxyRequest, AxyRequest,
EmisRequest, EmisRequest,
basicAction, basicAction,
RouteRequest, RouteRequest,
UserAttribute UserAttribute
} }
Loading…
Cancel
Save