diff --git a/platform-code/config/proxy.ts b/platform-code/config/proxy.ts index e1cbb48..1b97151 100644 --- a/platform-code/config/proxy.ts +++ b/platform-code/config/proxy.ts @@ -8,103 +8,108 @@ */ const bsc = { - '/baseApi': { - target: 'http://192.168.10.91:8090/api/', - pathRewrite: { '^/baseApi': '' }, - changeOrigin: true, - }, - '/api': { - target: 'http://192.168.10.91:8090/api/', - pathRewrite: { '^/api': '' }, - changeOrigin: true, - }, - '/statics': { - target: 'http://192.168.10.92/statics/', - pathRewrite: { '^/statics': '' }, - changeOrigin: true, - }, - '/sso/oauth': { - target: 'http://192.168.10.91:8015/api/oauth/', - pathRewrite: { '^/sso/oauth': '' }, - changeOrigin: true, - }, + '/baseApi': { + target: 'http://192.168.10.91:8090/api/', + pathRewrite: { '^/baseApi': '' }, + changeOrigin: true, + }, + '/api': { + target: 'http://192.168.10.91:8090/api/', + pathRewrite: { '^/api': '' }, + changeOrigin: true, + }, + '/statics': { + target: 'http://192.168.10.92/statics/', + pathRewrite: { '^/statics': '' }, + changeOrigin: true, + }, + '/sso/oauth': { + target: 'http://192.168.10.91:8015/api/oauth/', + pathRewrite: { '^/sso/oauth': '' }, + changeOrigin: true, + }, }; const huadong = { - '/baseApi': { - target: 'http://192.168.10.91:8090/api/', - pathRewrite: { '^/baseApi': '' }, - changeOrigin: true, - }, - // '/api/oauth/': { - // target: 'http://192.168.10.91:8060/oauth/', - // pathRewrite: { '^/api/oauth/': '' }, - // changeOrigin: true, - // }, - '/api': { - target: 'http://192.168.10.91:8090/api/', - pathRewrite: { '^/api': '' }, - changeOrigin: true, - }, - '/statics': { - target: 'http://192.168.10.92/statics/', - pathRewrite: { '^/statics': '' }, - changeOrigin: true, - }, - '/download': { - target: 'http://192.168.10.92/download/', - pathRewrite: { '^/download': '' }, - changeOrigin: true, - }, - '/sso/oauth': { - target: 'http://192.168.10.91:8090/api/oauth/', - pathRewrite: { '^/sso/oauth': '' }, - changeOrigin: true, - }, + '/baseApi': { + target: 'http://192.168.10.91:8090/api/', + pathRewrite: { '^/baseApi': '' }, + changeOrigin: true, + }, + // '/api/oauth/': { + // target: 'http://192.168.10.91:8060/oauth/', + // pathRewrite: { '^/api/oauth/': '' }, + // changeOrigin: true, + // }, + '/api': { + target: 'http://192.168.10.91:8090/api/', + pathRewrite: { '^/api': '' }, + changeOrigin: true, + }, + '/statics': { + target: 'http://192.168.10.92/statics/', + pathRewrite: { '^/statics': '' }, + changeOrigin: true, + }, + '/download': { + target: 'http://192.168.10.92/download/', + pathRewrite: { '^/download': '' }, + changeOrigin: true, + }, + '/sso/oauth': { + target: 'http://192.168.10.91:8090/api/oauth/', + pathRewrite: { '^/sso/oauth': '' }, + changeOrigin: true, + }, }; const daye460 = { - '/baseApi': { - target: 'http://172.15.199.55:8090/api/', - pathRewrite: { '^/baseApi': '' }, - changeOrigin: true, - }, - '/api/oauth/': { - target: 'http://172.15.89.246:8060/oauth/', - pathRewrite: { '^/api/oauth/': '' }, - changeOrigin: true, - }, - '/api': { - target: 'http://172.15.89.222:80/api/', - pathRewrite: { '^/api': '' }, - changeOrigin: true, - }, - '/statics': { - target: 'http://172.15.199.56/statics/', - pathRewrite: { '^/statics': '' }, - changeOrigin: true, - }, - '/download': { - target: 'http://172.15.199.56/download/', - pathRewrite: { '^/download': '' }, - changeOrigin: true, - }, - '/sso/oauth': { - target: 'http://172.15.199.55:8090/api/oauth/', - pathRewrite: { '^/sso/oauth': '' }, - changeOrigin: true, - }, - '/CZapi': { - target: 'http://172.15.89.232:8081/api/',//材智接口 - pathRewrite: { '^/CZapi': '' }, - changeOrigin: true, - }, - '/openapi': { - target: 'http://172.15.89.232:8081/openapi/',//材智接口 - pathRewrite: { '^/openapi': '' }, - changeOrigin: true, - }, + '/baseApi': { + target: 'http://172.15.199.55:8090/api/', + pathRewrite: { '^/baseApi': '' }, + changeOrigin: true, + }, + '/api/oauth/': { + target: 'http://172.15.89.246:8060/oauth/', + pathRewrite: { '^/api/oauth/': '' }, + changeOrigin: true, + }, + // '/api': { + // target: 'http://172.15.89.222:80/api/', + // pathRewrite: { '^/api': '' }, + // changeOrigin: true, + // }, + '/api': { + target: 'https://craft.dayesteel.com.cn/api/', + pathRewrite: { '^/api': '' }, + changeOrigin: true, + }, + '/statics': { + target: 'http://172.15.199.56/statics/', + pathRewrite: { '^/statics': '' }, + changeOrigin: true, + }, + '/download': { + target: 'http://172.15.199.56/download/', + pathRewrite: { '^/download': '' }, + changeOrigin: true, + }, + '/sso/oauth': { + target: 'http://172.15.199.55:8090/api/oauth/', + pathRewrite: { '^/sso/oauth': '' }, + changeOrigin: true, + }, + '/CZapi': { + target: 'http://172.15.89.232:8081/api/',//材智接口 + pathRewrite: { '^/CZapi': '' }, + changeOrigin: true, + }, + '/openapi': { + target: 'http://172.15.89.232:8081/openapi/',//材智接口 + pathRewrite: { '^/openapi': '' }, + changeOrigin: true, + }, }; diff --git a/platform-code/src/pages/plat/management/accounts/form.tsx b/platform-code/src/pages/plat/management/accounts/form.tsx index 12f9b8c..c84160b 100644 --- a/platform-code/src/pages/plat/management/accounts/form.tsx +++ b/platform-code/src/pages/plat/management/accounts/form.tsx @@ -1,8 +1,8 @@ import React, { useState, useEffect, useRef } from 'react' import RowBox from '@/components/Box/RowBox' -import { Button, Card, Divider, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Tooltip, Tree, TreeSelect, Upload } from 'antd' +import { Button, Card, Divider, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Tooltip, Tree, TreeSelect, Upload } from 'antd' import EditableTable from '@/components/NR_TableEditRow' -import { DeleteOutlined, UploadOutlined, KeyOutlined, EditOutlined, EyeTwoTone, EyeInvisibleOutlined, EyeOutlined ,PictureOutlined,ClearOutlined } from '@ant-design/icons' +import { DeleteOutlined, UploadOutlined, KeyOutlined, EditOutlined, EyeTwoTone, EyeInvisibleOutlined, EyeOutlined, PictureOutlined, ClearOutlined } from '@ant-design/icons' import CryptoJs, { MD5, SHA256 } from 'crypto-js'; import { User, Module, Role, Organ } from '@/interfaces/interface' import ImportAndExport from '@/components/NR_ImportAndExport' @@ -15,444 +15,446 @@ import Events from '../events' import ModuleService from '@/services/modules' import { addOrganization, addUser, addUserToRole, deleteOrganization, deleteUser, getOrganizations, getRoles, getRolesByAccount, query, removeUserFromRole, updateOrganization, updateUser, updateUserList } from '../../user/role/service' import FormSelectorInput from '@/components/iBKLinker/form/selector-input' -import { getTreeData,getTreeSelectData } from '@/utils/commoTool' +import { getTreeData, getTreeSelectData } from '@/utils/commoTool' import { history } from 'umi' import { isArray } from 'lodash' interface IManagementAccountEditor { - visible: boolean, - data?: any, - modules?: any[], - onComplete: (result: any) => void, + visible: boolean, + data?: any, + modules?: any[], + onComplete: (result: any) => void, } /** * 账户表单 */ -const ManagementAccountEditor : React.FC = (props) => { - const thisViewName = "ManagementAccountEditor" - const $emitter: EventView = new EventView(thisViewName) - const encoder = useRef<"md5"|"sha256">(history.location.query?.encoder ? history.location.query?.encoder : "sha256") - const [isLoading, setIsLoading] = useState(false) - const [thisForm] = Form.useForm() - const activeData = useRef(undefined) - const [roleList, setRoleList] = useState([]) - const [organList, setOrganList] = useState([]) - const originRoles = useRef([]) - const selectOrgan = useRef() - const multiTeamname = useRef() - - useEffect(() => { - - $emitter.subscribe(Events.accounts.org.selected, (organ?: Organ) => { - selectOrgan.current = organ - - thisForm.setFieldsValue({ - OrganName: selectOrgan.current ? selectOrgan.current.Name : undefined, - OrganID: selectOrgan.current ? selectOrgan.current.Guid : undefined, - }) - }) - - return () => { - $emitter.dispose() - } - }, []) - - useEffect(() => { - if(!props.data){ - thisForm.resetFields() - thisForm.setFieldsValue({ - OrganName: selectOrgan.current ? selectOrgan.current.Name : undefined, - }) - } - else{ - thisForm.setFieldsValue({ - ...props.data, - }) - - getUserRole(props.data.LoginID) - } - - activeData.current = {...props.data} - }, [props.data]) - - useEffect(() => { - if(props.visible){ - getRoleList() - } - }, [props.visible]) - - - useEffect(() => { - - prepareData() - - return () => { - $emitter.dispose() - } - }, []) - - - - const getUserRole = async (loginId: string) => { - setIsLoading(true) - let roles: any[] = await getRolesByAccount(loginId) - setIsLoading(false) - roles = !roles ? [] : roles - originRoles.current = [...roles] - - if(roles.length > 0){ - thisForm.setFieldsValue({ - role: roles.map((rr) => rr.RoleName), - }) - } - else{ - thisForm.setFieldsValue({ - role: undefined, - }) - } - } - - const getRoleList = async () => { - setIsLoading(true) - const roles: Role[] = await getRoles() - setIsLoading(false) - - if (roles.length != 0) { - roles.map((item: any) => { - item.label = item.Name - item.value = item.Name - }) - } - setRoleList(roles) - } - - const prepareData = async () => { - setIsLoading(true) - let organs = await getOrganizations() - setIsLoading(false) - - organs = !organs ? [] : organs - setOrganList(organs.length != 0 ? getTreeSelectData(organs, '00000000-0000-0000-0000-000000000000','Guid', 'ParentID', 'Name','Name'): []) - - - } - - - const userColumns = [ - { - "title": '序号', - "key": 'userId', - "dataIndex": 'userId', - "editable": false, - "ellipsis": true, - "render": (userId: string, record: User, index: number) => { - return (index + 1).toString() - } - }, { - "title": '用户名', - "key": 'Name', - "dataIndex": 'Name', - "ellipsis": true, - "editable": true, - "rules": [{ required: true }, { - pattern: '^[\u4e00-\u9fa5]{0,}$', - message: '用户名必须为汉字' - }], - ...getColumnSearchProps('Name') - }, { - "title": '账号', - "key": 'LoginID', - "dataIndex": 'LoginID', - "ellipsis": true, - "editable": true, - "rules": [{ required: true }, { - pattern: /^[a-zA-Z\d]+$/, - message: '账号为小写字母或数字' - }] - }, { - "title": '密码', - "key": 'Password2', - "dataIndex": 'Password2', - "ellipsis": true, - "editable": true, - "render": (Password: string) => { - if (Password == null || Password.length == 0) { - return '暂无' - } else { - return null - } - }, - "rules": [{ - pattern: '^[A-Za-z0-9]+$', - message: '密码只能由英文字母和数字组成' - }], - "inputComponent": (visible ? : )} - /> - }, { - "title": '邮箱', - "key": 'Email', - "dataIndex": 'Email', - "ellipsis": true, - "editable": true, - "rules": [ - { - pattern: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/, - message: '邮箱格式不正确', - }, { - max: 50, - message: '邮箱不得超过50字符', - - }, - ] - }, - { - "title": '用户群组', - "key": 'OrganName', - "dataIndex": 'OrganName', - "editable": false, - "ellipsis": true, - // "inputComponent": , - "filters": [ - { - text: '是', - value: 1, - }, - { - text: '否', - value: 0, - }, - ], - "filterMultiple": false, - "onFilter": (value: any, record: any) => record.Leader != undefined && record.Leader === value, - }, { - "title": '登录次数', - "key": 'LoginCount', - "dataIndex": 'LoginCount', - "ellipsis": true, - }, { - "title": '在线状态', - "key": 'LineState', - "dataIndex": 'LineState', - "ellipsis": true, - "render": (LineState: any) => { - return parseInt(LineState) == 1 ? '在线' : '离线' - }, - "filters": [ - { - text: '在线', - value: 1, - }, - { - text: '离线', - value: 0, - }, - ], - "filterMultiple": false, - "onFilter": (value: any, record: any) => record.LineState != undefined && record.LineState === value, - } - ] - - const submitData = async () => { - if(!activeData.current){ - message.error("请选择一个账号") - return - } - - await thisForm.validateFields() - - let subvals = thisForm.getFieldsValue() - let values = {...activeData.current} - //let oldData = values.role ? (values.role.value ? values.role.value : values.role) : undefined - - for(let s in subvals){ - values[s] = subvals[s] - } - - if(subvals.Uid){ - if(subvals.Password2 && subvals.Password2.length > 0){ - - switch(encoder.current){ - case "md5": - values.Password = CryptoJs.enc.Base64.stringify(MD5(subvals.Password2)) - break - case "sha256": - default: - values.Password = CryptoJs.enc.Base64.stringify(SHA256(subvals.Password2)) - break - } - - } - await updateUser(values) - } - else{ - values.LineState = 0 - values.LoginCount = 0 - values.Attributes = 0 - //先用MD5加密 再用base64编码 - // values.Password = CryptoJs.enc.Base64.stringify(MD5(values.Password)) - switch(encoder.current){ - case "md5": - values.Password = CryptoJs.enc.Base64.stringify(MD5(values.Password2)) - break - case "sha256": - default: - values.Password = CryptoJs.enc.Base64.stringify(SHA256(values.Password2)) - break - } - - await addUser(values) - } - // values.Password2 = CryptoJs.enc.Base64.stringify(SHA256(values.Password2)) - - //console.log("add user", values) - - // await addUser(values) - - //console.log("update list", values, subvals, roleList) - if (subvals.role != undefined && roleList) { - if(originRoles.current && originRoles.current.length > 0){ - for(let ri = 0; ri < originRoles.current.length; ri++){ - await removeUserFromRole({ - LoginId: values.LoginID, - RoleName: originRoles.current[ri].RoleName, - }) - } - } - - if(isArray(subvals.role)){ - for(let ri = 0; ri < subvals.role.length; ri++){ - let subrole = subvals.role[ri] - let roleData = subrole.value ? subrole.value : subrole//{...values.role} - - await addUserToRole({ - "role": { - "Name": roleData, - "Description": roleData, - }, - "accountRoleList": [ - { - "LoginId": values.LoginID, - "RoleName": roleData - } - ] - }) - } - } - else{ - let roleData = subvals.role.value ? subvals.role.value : subvals.role//{...values.role} - - await addUserToRole({ - "role": { - "Name": roleData, - "Description": roleData, - }, - "accountRoleList": [ - { - "LoginId": values.LoginID, - "RoleName": roleData - } - ] - }) - } - } - - props.onComplete && props.onComplete(true) - } - - - - return ( - props.onComplete(false)} confirmLoading={isLoading} onOk={() => { - let subvals = thisForm.getFieldsValue() - let values = {...activeData.current} - - console.log("submit data", subvals, values) - submitData() - }}> -
- { - userColumns.slice(1, 9).map((col: any) => ( - - {col.inputComponent != undefined ? col.inputComponent : } - - )) - } - - - - - - - - - - - { - let val: any = value && value.length > 0 ? value[0] : null - multiTeamname.current = val - }} - /> - -
-
- ) +const ManagementAccountEditor: React.FC = (props) => { + const thisViewName = "ManagementAccountEditor" + const $emitter: EventView = new EventView(thisViewName) + const encoder = useRef<"md5" | "sha256">(history.location.query?.encoder ? history.location.query?.encoder : "sha256") + const [isLoading, setIsLoading] = useState(false) + const [thisForm] = Form.useForm() + const activeData = useRef(undefined) + const [roleList, setRoleList] = useState([]) + const [organList, setOrganList] = useState([]) + const originRoles = useRef([]) + const selectOrgan = useRef() + const multiTeamname = useRef() + + useEffect(() => { + + $emitter.subscribe(Events.accounts.org.selected, (organ?: Organ) => { + selectOrgan.current = organ + + thisForm.setFieldsValue({ + OrganName: selectOrgan.current ? selectOrgan.current.Name : undefined, + OrganID: selectOrgan.current ? selectOrgan.current.Guid : undefined, + }) + }) + + return () => { + $emitter.dispose() + } + }, []) + + useEffect(() => { + if (!props.data) { + thisForm.resetFields() + thisForm.setFieldsValue({ + OrganName: selectOrgan.current ? selectOrgan.current.Name : undefined, + }) + } + else { + thisForm.setFieldsValue({ + ...props.data, + }) + + getUserRole(props.data.LoginID) + } + + activeData.current = { ...props.data } + }, [props.data]) + + useEffect(() => { + if (props.visible) { + getRoleList() + } + }, [props.visible]) + + + useEffect(() => { + + prepareData() + + return () => { + $emitter.dispose() + } + }, []) + + + + const getUserRole = async (loginId: string) => { + setIsLoading(true) + let roles: any[] = await getRolesByAccount(loginId) + setIsLoading(false) + roles = !roles ? [] : roles + originRoles.current = [...roles] + + if (roles.length > 0) { + thisForm.setFieldsValue({ + role: roles.map((rr) => rr.RoleName), + }) + } + else { + thisForm.setFieldsValue({ + role: undefined, + }) + } + } + + const getRoleList = async () => { + setIsLoading(true) + const roles: Role[] = await getRoles() + setIsLoading(false) + + if (roles.length != 0) { + roles.map((item: any) => { + item.label = item.Name + item.value = item.Name + }) + } + setRoleList(roles) + } + + const prepareData = async () => { + setIsLoading(true) + let organs = await getOrganizations() + setIsLoading(false) + + organs = !organs ? [] : organs + setOrganList(organs.length != 0 ? getTreeSelectData(organs, '00000000-0000-0000-0000-000000000000', 'Guid', 'ParentID', 'Name', 'Name') : []) + + + } + + + const userColumns = [ + { + "title": '序号', + "key": 'userId', + "dataIndex": 'userId', + "editable": false, + "ellipsis": true, + "render": (userId: string, record: User, index: number) => { + return (index + 1).toString() + } + }, { + "title": '用户名', + "key": 'Name', + "dataIndex": 'Name', + "ellipsis": true, + "editable": true, + "rules": [{ required: true }, { + pattern: '^[\u4e00-\u9fa5]{0,}$', + message: '用户名必须为汉字' + }], + ...getColumnSearchProps('Name') + }, { + "title": '账号', + "key": 'LoginID', + "dataIndex": 'LoginID', + "ellipsis": true, + "editable": true, + "rules": [{ required: true }, { + pattern: /^[a-zA-Z\d]+$/, + message: '账号为小写字母或数字' + }] + }, { + "title": '密码', + "key": 'Password2', + "dataIndex": 'Password2', + "ellipsis": true, + "editable": true, + "render": (Password: string) => { + if (Password == null || Password.length == 0) { + return '暂无' + } else { + return null + } + }, + "rules": [{ + // pattern: '^[A-Za-z0-9]+$', + pattern: '^[A-Za-z0-9@!-]+$', + // message: '密码只能由英文字母和数字组成' + message: '密码只能包含数字字母和@!-' + }], + "inputComponent": (visible ? : )} + /> + }, { + "title": '邮箱', + "key": 'Email', + "dataIndex": 'Email', + "ellipsis": true, + "editable": true, + "rules": [ + { + pattern: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/, + message: '邮箱格式不正确', + }, { + max: 50, + message: '邮箱不得超过50字符', + + }, + ] + }, + { + "title": '用户群组', + "key": 'OrganName', + "dataIndex": 'OrganName', + "editable": false, + "ellipsis": true, + // "inputComponent": , + "filters": [ + { + text: '是', + value: 1, + }, + { + text: '否', + value: 0, + }, + ], + "filterMultiple": false, + "onFilter": (value: any, record: any) => record.Leader != undefined && record.Leader === value, + }, { + "title": '登录次数', + "key": 'LoginCount', + "dataIndex": 'LoginCount', + "ellipsis": true, + }, { + "title": '在线状态', + "key": 'LineState', + "dataIndex": 'LineState', + "ellipsis": true, + "render": (LineState: any) => { + return parseInt(LineState) == 1 ? '在线' : '离线' + }, + "filters": [ + { + text: '在线', + value: 1, + }, + { + text: '离线', + value: 0, + }, + ], + "filterMultiple": false, + "onFilter": (value: any, record: any) => record.LineState != undefined && record.LineState === value, + } + ] + + const submitData = async () => { + if (!activeData.current) { + message.error("请选择一个账号") + return + } + + await thisForm.validateFields() + + let subvals = thisForm.getFieldsValue() + let values = { ...activeData.current } + //let oldData = values.role ? (values.role.value ? values.role.value : values.role) : undefined + + for (let s in subvals) { + values[s] = subvals[s] + } + + if (subvals.Uid) { + if (subvals.Password2 && subvals.Password2.length > 0) { + + switch (encoder.current) { + case "md5": + values.Password = CryptoJs.enc.Base64.stringify(MD5(subvals.Password2)) + break + case "sha256": + default: + values.Password = CryptoJs.enc.Base64.stringify(SHA256(subvals.Password2)) + break + } + + } + await updateUser(values) + } + else { + values.LineState = 0 + values.LoginCount = 0 + values.Attributes = 0 + //先用MD5加密 再用base64编码 + // values.Password = CryptoJs.enc.Base64.stringify(MD5(values.Password)) + switch (encoder.current) { + case "md5": + values.Password = CryptoJs.enc.Base64.stringify(MD5(values.Password2)) + break + case "sha256": + default: + values.Password = CryptoJs.enc.Base64.stringify(SHA256(values.Password2)) + break + } + + await addUser(values) + } + // values.Password2 = CryptoJs.enc.Base64.stringify(SHA256(values.Password2)) + + //console.log("add user", values) + + // await addUser(values) + + //console.log("update list", values, subvals, roleList) + if (subvals.role != undefined && roleList) { + if (originRoles.current && originRoles.current.length > 0) { + for (let ri = 0; ri < originRoles.current.length; ri++) { + await removeUserFromRole({ + LoginId: values.LoginID, + RoleName: originRoles.current[ri].RoleName, + }) + } + } + + if (isArray(subvals.role)) { + for (let ri = 0; ri < subvals.role.length; ri++) { + let subrole = subvals.role[ri] + let roleData = subrole.value ? subrole.value : subrole//{...values.role} + + await addUserToRole({ + "role": { + "Name": roleData, + "Description": roleData, + }, + "accountRoleList": [ + { + "LoginId": values.LoginID, + "RoleName": roleData + } + ] + }) + } + } + else { + let roleData = subvals.role.value ? subvals.role.value : subvals.role//{...values.role} + + await addUserToRole({ + "role": { + "Name": roleData, + "Description": roleData, + }, + "accountRoleList": [ + { + "LoginId": values.LoginID, + "RoleName": roleData + } + ] + }) + } + } + + props.onComplete && props.onComplete(true) + } + + + + return ( + props.onComplete(false)} confirmLoading={isLoading} onOk={() => { + let subvals = thisForm.getFieldsValue() + let values = { ...activeData.current } + + console.log("submit data", subvals, values) + submitData() + }}> +
+ { + userColumns.slice(1, 9).map((col: any) => ( + + {col.inputComponent != undefined ? col.inputComponent : } + + )) + } + + + + + + + + + + + { + let val: any = value && value.length > 0 ? value[0] : null + multiTeamname.current = val + }} + /> + +
+
+ ) } -export default ManagementAccountEditor \ No newline at end of file +export default ManagementAccountEditor diff --git a/platform-code/src/pages/plat/user/manager/index.tsx b/platform-code/src/pages/plat/user/manager/index.tsx index 903bfcd..2844d20 100644 --- a/platform-code/src/pages/plat/user/manager/index.tsx +++ b/platform-code/src/pages/plat/user/manager/index.tsx @@ -19,516 +19,517 @@ let selectUsers: User[] = []; const UserManager = (props: any) => { - const { confirm } = Modal; - const [addForm] = Form.useForm(); - const [addOrganForm] = Form.useForm(); - const [editFlag, setEditFlag] = useState(false); - const [addOrganVisibility, setAddOrganVisibility] = useState(false) - const [addVisibility, setAddVisibility] = useState(false) - const [userList, setUserList] = useState([]) - const [roleList, setRoleList] = useState([]) - const [organList, setOrganList] = useState([]) + const { confirm } = Modal; + const [addForm] = Form.useForm(); + const [addOrganForm] = Form.useForm(); + const [editFlag, setEditFlag] = useState(false); + const [addOrganVisibility, setAddOrganVisibility] = useState(false) + const [addVisibility, setAddVisibility] = useState(false) + const [userList, setUserList] = useState([]) + const [roleList, setRoleList] = useState([]) + const [organList, setOrganList] = useState([]) - useEffect(() => { - init() - }, []) + useEffect(() => { + init() + }, []) - const init = () => { - getUserList() - getRoleList() - getOrganizationList() - } + const init = () => { + getUserList() + getRoleList() + getOrganizationList() + } - const getUserList = async () => { - const users: User[] = await query() - allUsers = users - setUserList(users) - } + const getUserList = async () => { + const users: User[] = await query() + allUsers = users + setUserList(users) + } - const getRoleList = async () => { - const roles: Role[] = await getRoles() - if (roles.length != 0) { - roles.map((item: any) => { - item.label = item.Name - item.value = item.Name - }) - } - setRoleList(roles) - } + const getRoleList = async () => { + const roles: Role[] = await getRoles() + if (roles.length != 0) { + roles.map((item: any) => { + item.label = item.Name + item.value = item.Name + }) + } + setRoleList(roles) + } - const getOrganizationList = async () => { - const organs: Organ[] = await getOrganizations() - setOrganList(organs.length != 0 ? getTreeData(organs, '00000000-0000-0000-0000-000000000000', 'Guid', 'ParentID', 'Name', 'Guid') : []) - } + const getOrganizationList = async () => { + const organs: Organ[] = await getOrganizations() + setOrganList(organs.length != 0 ? getTreeData(organs, '00000000-0000-0000-0000-000000000000', 'Guid', 'ParentID', 'Name', 'Guid') : []) + } - const userColumns = [ - { - "title": '序号', - "key": 'userId', - "dataIndex": 'userId', - "editable": false, - "ellipsis": true, - "render": (userId: string, record: User, index: number) => { - return (index + 1).toString() - } - }, { - "title": '用户名', - "key": 'Name', - "dataIndex": 'Name', - "ellipsis": true, - "editable": true, - "rules": [{ required: true }, { - pattern: '^[\u4e00-\u9fa5]{0,}$', - message: '用户名必须为汉字' - }], - ...getColumnSearchProps('Name') - }, { - "title": '账号', - "key": 'LoginID', - "dataIndex": 'LoginID', - "ellipsis": true, - "editable": true, - "rules": [{ required: true }, { - pattern: /^[a-zA-Z\d]+$/, - message: '账号为小写字母或数字' - }] - }, { - "title": '密码', - "key": 'Password2', - "dataIndex": 'Password2', - "ellipsis": true, - "editable": true, - "render": (Password: string) => { - if (Password == null || Password.length == 0) { - return '暂无' - } else { - return null - } - }, - "rules": [{ required: true }, { - pattern: '^[A-Za-z0-9]+$', - message: '密码只能由英文字母和数字组成' - }], - "inputComponent": (visible ? : )} - /> - }, { - "title": '邮箱', - "key": 'Email', - "dataIndex": 'Email', - "ellipsis": true, - "editable": true, - "rules": [ - { - pattern: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/, - message: '邮箱格式不正确', - }, { - max: 50, - message: '邮箱不得超过50字符', + const userColumns = [ + { + "title": '序号', + "key": 'userId', + "dataIndex": 'userId', + "editable": false, + "ellipsis": true, + "render": (userId: string, record: User, index: number) => { + return (index + 1).toString() + } + }, { + "title": '用户名', + "key": 'Name', + "dataIndex": 'Name', + "ellipsis": true, + "editable": true, + "rules": [{ required: true }, { + pattern: '^[\u4e00-\u9fa5]{0,}$', + message: '用户名必须为汉字' + }], + ...getColumnSearchProps('Name') + }, { + "title": '账号', + "key": 'LoginID', + "dataIndex": 'LoginID', + "ellipsis": true, + "editable": true, + "rules": [{ required: true }, { + pattern: /^[a-zA-Z\d]+$/, + message: '账号为小写字母或数字' + }] + }, { + "title": '密码', + "key": 'Password2', + "dataIndex": 'Password2', + "ellipsis": true, + "editable": true, + "render": (Password: string) => { + if (Password == null || Password.length == 0) { + return '暂无' + } else { + return null + } + }, + "rules": [{ required: true }, { + pattern: '^[A-Za-z0-9@!-]+$', + // pattern: /^(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z]).{8,}$/, + message: '密码只能包含数字字母和@!-' + }], + "inputComponent": (visible ? : )} + /> + }, { + "title": '邮箱', + "key": 'Email', + "dataIndex": 'Email', + "ellipsis": true, + "editable": true, + "rules": [ + { + pattern: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/, + message: '邮箱格式不正确', + }, { + max: 50, + message: '邮箱不得超过50字符', - }, - ] - }, { - "title": '用户群组', - "key": 'OrganName', - "dataIndex": 'OrganName', - "editable": false, - "ellipsis": true, - "inputComponent": , - "rules": [{ required: true }], - "filters": getFilterItem(userList, 'OrganName'), - "onFilter": (value: any, record: any) => record.OrganName != undefined && record.OrganName == value, - }, { - "title": '地址', - "key": 'Address', - "dataIndex": 'Address', - "ellipsis": true, - "editable": true, - }, { - "title": '备注', - "key": 'Description', - "dataIndex": 'Description', - "editable": true, - "ellipsis": true, - "render": (Description: string) => { - if (Description == null || Description.length == 0) { - return '无' - } else { - return Description - } - } - }, { - "title": '是否主管', - "key": 'Leader', - "dataIndex": 'Leader', - "ellipsis": true, - "inputComponent": { - record.Leader = value - await updateUser(record).then(async (res: any) => { - await getUserList() - if (Object.keys(currentOrgan).length != 0) { - setUserList(allUsers.filter((user: User) => (user.OrganName == currentOrgan.title)).slice()) - } - }) - }} /> - }, - "filters": [ - { - text: '是', - value: 1, - }, - { - text: '否', - value: 0, - }, - ], - "filterMultiple": false, - "onFilter": (value: any, record: any) => record.Leader != undefined && record.Leader === value, - }, { - "title": '登录次数', - "key": 'LoginCount', - "dataIndex": 'LoginCount', - "ellipsis": true, - }, { - "title": '在线状态', - "key": 'LineState', - "dataIndex": 'LineState', - "ellipsis": true, - "render": (LineState: any) => { - return parseInt(LineState) == 1 ? '在线' : '离线' - }, - "filters": [ - { - text: '在线', - value: 1, - }, - { - text: '离线', - value: 0, - }, - ], - "filterMultiple": false, - "onFilter": (value: any, record: any) => record.LineState != undefined && record.LineState === value, - } - ] + }, + ] + }, { + "title": '用户群组', + "key": 'OrganName', + "dataIndex": 'OrganName', + "editable": false, + "ellipsis": true, + "inputComponent": , + "rules": [{ required: true }], + "filters": getFilterItem(userList, 'OrganName'), + "onFilter": (value: any, record: any) => record.OrganName != undefined && record.OrganName == value, + }, { + "title": '地址', + "key": 'Address', + "dataIndex": 'Address', + "ellipsis": true, + "editable": true, + }, { + "title": '备注', + "key": 'Description', + "dataIndex": 'Description', + "editable": true, + "ellipsis": true, + "render": (Description: string) => { + if (Description == null || Description.length == 0) { + return '无' + } else { + return Description + } + } + }, { + "title": '是否主管', + "key": 'Leader', + "dataIndex": 'Leader', + "ellipsis": true, + "inputComponent": { + record.Leader = value + await updateUser(record).then(async (res: any) => { + await getUserList() + if (Object.keys(currentOrgan).length != 0) { + setUserList(allUsers.filter((user: User) => (user.OrganName == currentOrgan.title)).slice()) + } + }) + }} /> + }, + "filters": [ + { + text: '是', + value: 1, + }, + { + text: '否', + value: 0, + }, + ], + "filterMultiple": false, + "onFilter": (value: any, record: any) => record.Leader != undefined && record.Leader === value, + }, { + "title": '登录次数', + "key": 'LoginCount', + "dataIndex": 'LoginCount', + "ellipsis": true, + }, { + "title": '在线状态', + "key": 'LineState', + "dataIndex": 'LineState', + "ellipsis": true, + "render": (LineState: any) => { + return parseInt(LineState) == 1 ? '在线' : '离线' + }, + "filters": [ + { + text: '在线', + value: 1, + }, + { + text: '离线', + value: 0, + }, + ], + "filterMultiple": false, + "onFilter": (value: any, record: any) => record.LineState != undefined && record.LineState === value, + } + ] - const userTable = { - dataSource: userList, - columns: userColumns,//.filter((item: any) => (item.title != '密码')), - size: "small", - defaultPageSize: 15, - // loading: loadingProduct, - rowKey: 'LoginID', - className: 'productList', - // selectedRowKeys: currentClickProductKey, - onSave: async (user: User) => { - //console.log(user) - if(user.Password2 && user.Password2.length > 0){ - user.Password = CryptoJs.enc.Base64.stringify(SHA256(user.Password2)) - } - // user.Password = CryptoJs.enc.Base64.stringify(MD5(user.Password)) - // user.Password = CryptoJs.enc.Base64.stringify(SHA256(user.Password)) - // console.log("密码",Base64.stringify(Utf8.parse(user.Password))) - await updateUser(user).then((res: any) => { - getUserList() - }) - }, - onRowClick: async (rowdata: any) => { + const userTable = { + dataSource: userList, + columns: userColumns,//.filter((item: any) => (item.title != '密码')), + size: "small", + defaultPageSize: 15, + // loading: loadingProduct, + rowKey: 'LoginID', + className: 'productList', + // selectedRowKeys: currentClickProductKey, + onSave: async (user: User) => { + //console.log(user) + if (user.Password2 && user.Password2.length > 0) { + user.Password = CryptoJs.enc.Base64.stringify(SHA256(user.Password2)) + } + // user.Password = CryptoJs.enc.Base64.stringify(MD5(user.Password)) + // user.Password = CryptoJs.enc.Base64.stringify(SHA256(user.Password)) + // console.log("密码",Base64.stringify(Utf8.parse(user.Password))) + await updateUser(user).then((res: any) => { + getUserList() + }) + }, + onRowClick: async (rowdata: any) => { - }, - onRowSelect: (record: User, _: boolean, selectedRows: any[]) => { - selectUsers = selectedRows - }, - }; + }, + onRowSelect: (record: User, _: boolean, selectedRows: any[]) => { + selectUsers = selectedRows + }, + }; - const userImportAndExportConf = { - importLabel: '导入用户', - importFlag: true, - exportLabel: '导出用户', - exportFlag: true, - exportColumns: userColumns.filter((item: any) => (item.title != '密码')), - exportDatas: userList, - exportFileName: '系统用户信息.xlsx', - doImport: (users: User[]) => { - message.error('暂无批量添加用户接口') - // addUser(users).then((res:any)=>{ - // getUserList() - // }) - } - } + const userImportAndExportConf = { + importLabel: '导入用户', + importFlag: true, + exportLabel: '导出用户', + exportFlag: true, + exportColumns: userColumns.filter((item: any) => (item.title != '密码')), + exportDatas: userList, + exportFileName: '系统用户信息.xlsx', + doImport: (users: User[]) => { + message.error('暂无批量添加用户接口') + // addUser(users).then((res:any)=>{ + // getUserList() + // }) + } + } - const handleAddOk = (values: any) => { - addForm.submit() - setAddVisibility(false) - } + const handleAddOk = (values: any) => { + addForm.submit() + setAddVisibility(false) + } - const handleAddCancel = () => { - setAddVisibility(false) - } + const handleAddCancel = () => { + setAddVisibility(false) + } - //添加用户 - const handleAddUser = () => { - if (Object.keys(currentOrgan).length != 0) { - setAddVisibility(true) - addForm.resetFields() - addForm.setFieldsValue({ 'OrganName': currentOrgan.Name }) - addForm.setFieldsValue({ 'OrganID': currentOrgan.Guid }) - } else { - message.warn('请先选择一个机构') - } - } + //添加用户 + const handleAddUser = () => { + if (Object.keys(currentOrgan).length != 0) { + setAddVisibility(true) + addForm.resetFields() + addForm.setFieldsValue({ 'OrganName': currentOrgan.Name }) + addForm.setFieldsValue({ 'OrganID': currentOrgan.Guid }) + } else { + message.warn('请先选择一个机构') + } + } - //删除用户 - const handleDeleteUser = () => { - console.log("selectUsers", selectUsers.length) - if (selectUsers.length == 1) { - confirm({ - title: `确认删除用户${selectUsers[0].Name}吗?`, - icon: , - onOk() { - deleteUser(selectUsers[0]).then((res: any) => { - getUserList() - selectUsers = [] - }) - }, - onCancel() { + //删除用户 + const handleDeleteUser = () => { + console.log("selectUsers", selectUsers.length) + if (selectUsers.length == 1) { + confirm({ + title: `确认删除用户${selectUsers[0].Name}吗?`, + icon: , + onOk() { + deleteUser(selectUsers[0]).then((res: any) => { + getUserList() + selectUsers = [] + }) + }, + onCancel() { - }, - }); - } else { - message.warn("请先选择一位要删除的用户") - } - } + }, + }); + } else { + message.warn("请先选择一位要删除的用户") + } + } - const organOptions = ( - - { - setEditFlag(false) - setAddOrganVisibility(true) - addOrganForm.setFieldsValue({ 'ParentName': currentOrgan.Name }) - addOrganForm.setFieldsValue({ 'ParentID': currentOrgan.Guid }) - }}>添加机构 - { - setEditFlag(true) - addOrganForm.resetFields() - addOrganForm.setFieldsValue(currentOrgan) - setAddOrganVisibility(true) - }}>修改机构 - { }}> - { - await deleteOrganization(currentOrgan).then((response: any) => { - init() - }) - }} - onCancel={() => { + const organOptions = ( + + { + setEditFlag(false) + setAddOrganVisibility(true) + addOrganForm.setFieldsValue({ 'ParentName': currentOrgan.Name }) + addOrganForm.setFieldsValue({ 'ParentID': currentOrgan.Guid }) + }}>添加机构 + { + setEditFlag(true) + addOrganForm.resetFields() + addOrganForm.setFieldsValue(currentOrgan) + setAddOrganVisibility(true) + }}>修改机构 + { }}> + { + await deleteOrganization(currentOrgan).then((response: any) => { + init() + }) + }} + onCancel={() => { - }} - okText="删除" - cancelText="取消" - > - 删除机构 - - - - ); + }} + okText="删除" + cancelText="取消" + > + 删除机构 + + + + ); - const handleAddOrganOk = () => { - addOrganForm.submit() - setAddOrganVisibility(false) - } + const handleAddOrganOk = () => { + addOrganForm.submit() + setAddOrganVisibility(false) + } - const handleAddOrganCancel = () => { - addOrganForm.resetFields() - setAddOrganVisibility(false) - } + const handleAddOrganCancel = () => { + addOrganForm.resetFields() + setAddOrganVisibility(false) + } - return ( - <> - - - - - } - showLine={ - { - showLeafIcon: false - } - } - treeData={organList} - onSelect={(selectedKeys: string[], e: any) => { - currentOrgan = e.node - if (allUsers.length != 0) { - setUserList(allUsers.filter((user: User) => (user.OrganName == e.node.title)).slice()) - } - }} /> - - - - - - - - - - - }> - - - - - -
{ - values.LineState = 0 - values.LoginCount = 0 - values.Attributes = 0 - //先用MD5加密 再用base64编码 - // values.Password = CryptoJs.enc.Base64.stringify(MD5(values.Password)) - values.Password = CryptoJs.enc.Base64.stringify(SHA256(values.Password2)) - // values.Password2 = CryptoJs.enc.Base64.stringify(SHA256(values.Password2)) + return ( + <> + + + + + } + showLine={ + { + showLeafIcon: false + } + } + treeData={organList} + onSelect={(selectedKeys: string[], e: any) => { + currentOrgan = e.node + if (allUsers.length != 0) { + setUserList(allUsers.filter((user: User) => (user.OrganName == e.node.title)).slice()) + } + }} /> + + + + + + + + + + + }> + + + + + + { + values.LineState = 0 + values.LoginCount = 0 + values.Attributes = 0 + //先用MD5加密 再用base64编码 + // values.Password = CryptoJs.enc.Base64.stringify(MD5(values.Password)) + values.Password = CryptoJs.enc.Base64.stringify(SHA256(values.Password2)) + // values.Password2 = CryptoJs.enc.Base64.stringify(SHA256(values.Password2)) - //console.log("add user", values) + //console.log("add user", values) - await addUser(values).then((res: any) => { - getUserList() - }) - if (values.role != undefined) { - await addUserToRole({ - "role": { - "Name": values.role.label, - "Description": values.role.value, - }, - "accountRoleList": [ - { - "LoginId": values.LoginID, - "RoleName": values.role.label - } - ] - }) - } - }} - onFinishFailed={() => { - setAddVisibility(true) - }}> - { - userColumns.slice(1, 9).map((col: any) => ( - - {col.inputComponent != undefined ? col.inputComponent : } - - )) - } - - - - -
- -
{ - if (!editFlag) { - values.Guid=uuidGenerator() - await addOrganization(values).then((response: any) => { - init() - }) - } else { - await updateOrganization(values).then((response: any) => { - init() - }) - } - }} - onFinishFailed={() => { - setAddOrganVisibility(true) - }}> - - { - if (e.target.value.length == 0) { - addOrganForm.setFieldsValue({ 'ParentID': '00000000-0000-0000-0000-000000000000' }) - } - }} /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - ) + await addUser(values).then((res: any) => { + getUserList() + }) + if (values.role != undefined) { + await addUserToRole({ + "role": { + "Name": values.role.label, + "Description": values.role.value, + }, + "accountRoleList": [ + { + "LoginId": values.LoginID, + "RoleName": values.role.label + } + ] + }) + } + }} + onFinishFailed={() => { + setAddVisibility(true) + }}> + { + userColumns.slice(1, 9).map((col: any) => ( + + {col.inputComponent != undefined ? col.inputComponent : } + + )) + } + + + + +
+ +
{ + if (!editFlag) { + values.Guid = uuidGenerator() + await addOrganization(values).then((response: any) => { + init() + }) + } else { + await updateOrganization(values).then((response: any) => { + init() + }) + } + }} + onFinishFailed={() => { + setAddOrganVisibility(true) + }}> + + { + if (e.target.value.length == 0) { + addOrganForm.setFieldsValue({ 'ParentID': '00000000-0000-0000-0000-000000000000' }) + } + }} /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + ) }; //export default UserManager; export default () => { - return + return }