Commit 34977cee authored by cellee's avatar cellee

账号权限需求变更

Signed-off-by: cellee's avatarcellee <893264950@qq.com>
parent 6b46650b
...@@ -90,6 +90,8 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout ...@@ -90,6 +90,8 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout
// 登录 // 登录
if (history.location.pathname == '/') { if (history.location.pathname == '/') {
var isLogin = false; var isLogin = false;
console.log(getCookie('token'));
if (getCookie('token').length != 0) { if (getCookie('token').length != 0) {
isLogin = true; isLogin = true;
} }
......
...@@ -138,7 +138,7 @@ export default { ...@@ -138,7 +138,7 @@ export default {
}, },
*SA({ DataSave }, { call, put }) { *SA({ DataSave }, { call, put }) {
console.log(DataSave); // console.log(DataSave);
yield put({ type: 'returnDataSave', DataSave }); yield put({ type: 'returnDataSave', DataSave });
}, },
......
...@@ -7,19 +7,18 @@ import './Account.less'; ...@@ -7,19 +7,18 @@ import './Account.less';
import { zhCnFaci, enUsFaci } from '@/utils/power'; import { zhCnFaci, enUsFaci } from '@/utils/power';
import { AccountTip } from '@/utils/tip'; import { AccountTip } from '@/utils/tip';
import SelectCommunity from '@/components/SelectCommunity/Tow';
import { getNumber } from '@/utils/string'; // 正则 import { getNumber } from '@/utils/string'; // 正则
import { RA } from '@/utils/method'; import { RA } from '@/utils/method';
const Account = (props: any) => { const Account = (props: any) => {
const module = 'Account'; const module = 'Account';
const { dispatch, SubResult, CommunityList, loading, user, Info } = props; const { dispatch, SubResult, loading, user, Info } = props;
// 权限列表 // 权限列表
const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci; const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci;
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目 const [expandedKeys, setExpandedKeys] = useState<string[]>(['0']); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目 const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点 const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭 const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭
...@@ -29,8 +28,6 @@ const Account = (props: any) => { ...@@ -29,8 +28,6 @@ const Account = (props: any) => {
const [disab, setdisab] = useState(false); // 是否禁止选择二级 const [disab, setdisab] = useState(false); // 是否禁止选择二级
const [towAccountId, settowAccountId] = useState(null); // 二级账户id const [towAccountId, settowAccountId] = useState(null); // 二级账户id
const [treeDataList, settreeDataList] = useState(treeData); // 权限列表 const [treeDataList, settreeDataList] = useState(treeData); // 权限列表
//默认选中的小区
const [community, setCommunity] = useState(CommunityList); // 默认全选
// 表单标识 // 表单标识
const [form] = Form.useForm(); const [form] = Form.useForm();
...@@ -103,7 +100,6 @@ const Account = (props: any) => { ...@@ -103,7 +100,6 @@ const Account = (props: any) => {
// 二级管辖小区和权限 // 二级管辖小区和权限
useEffect(() => { useEffect(() => {
if (Info != null) { if (Info != null) {
setCommunity(Info.community);
power(Info.permissions); power(Info.permissions);
setCheckedKeys([]); setCheckedKeys([]);
} }
...@@ -162,10 +158,6 @@ const Account = (props: any) => { ...@@ -162,10 +158,6 @@ const Account = (props: any) => {
// 权限 // 权限
message.error('Please Select Permission!'); message.error('Please Select Permission!');
return false; return false;
} else if (value.community.value == null || value.community.value.length == 0) {
// 小区
message.error('Please Select The Jurisdiction Area!');
return false;
} else if (value.tosUserName.length < 6) { } else if (value.tosUserName.length < 6) {
// 账号长度 // 账号长度
message.error('The Account Password is Greater Than 6 Digits!'); message.error('The Account Password is Greater Than 6 Digits!');
...@@ -175,7 +167,6 @@ const Account = (props: any) => { ...@@ -175,7 +167,6 @@ const Account = (props: any) => {
message.error('Please select affiliated account !'); message.error('Please select affiliated account !');
return false; return false;
} else { } else {
value.tosUserServiceCellList = value.community.value; // 管辖小区
value.tosUserEmail = value.tosUserName; // 邮箱就是账号 value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别 value.tosUserLevel = values; //级别
value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号 value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号
...@@ -210,10 +201,11 @@ const Account = (props: any) => { ...@@ -210,10 +201,11 @@ const Account = (props: any) => {
// 另传权限 // 另传权限
let obj = { let obj = {
userName: value.tosUserName, userName: value.tosUserName,
userPassword: value.tosUserPwd,
permissionArray: newData, permissionArray: newData,
}; };
console.log(value);
console.log(obj);
RA(38, value, module, dispatch); // 信息上传 RA(38, value, module, dispatch); // 信息上传
RA(42, obj, module, dispatch); // 权限上传 RA(42, obj, module, dispatch); // 权限上传
return true; return true;
...@@ -258,7 +250,6 @@ const Account = (props: any) => { ...@@ -258,7 +250,6 @@ const Account = (props: any) => {
if (e.target.value == 2) { if (e.target.value == 2) {
//否则打开 //否则打开
settowAccountId(null); settowAccountId(null);
setCommunity(CommunityList);
} }
}; };
...@@ -281,8 +272,6 @@ const Account = (props: any) => { ...@@ -281,8 +272,6 @@ const Account = (props: any) => {
// 选择哪个二级账号 // 选择哪个二级账号
const handleChange = (value: any) => { const handleChange = (value: any) => {
console.log(`selected ${value}`);
RA(57, { tosUserLevelId: value }, module, dispatch); // 根据用户id获取用户管辖小区名和权限 RA(57, { tosUserLevelId: value }, module, dispatch); // 根据用户id获取用户管辖小区名和权限
settowAccountId(value); settowAccountId(value);
}; };
...@@ -310,15 +299,12 @@ const Account = (props: any) => { ...@@ -310,15 +299,12 @@ const Account = (props: any) => {
name="contract" name="contract"
onFinish={onFinishContract} onFinish={onFinishContract}
> >
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}> <Descriptions column={{ xs: 1, sm: 1, md: 2, xl: 3 }}>
<Descriptions.Item> <Descriptions.Item>
<Form.Item name="tosUserName" label="Account ID" rules={AccountTip[0] as any}> <Form.Item name="tosUserName" label="Account ID" rules={AccountTip[0] as any}>
<Input placeholder="Login Account" className="input" /> <Input placeholder="Login Account" className="input" />
</Form.Item> </Form.Item>
</Descriptions.Item> </Descriptions.Item>
</Descriptions>
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}>
<Descriptions.Item> <Descriptions.Item>
<Form.Item name="tosAccountName" label="Name" rules={AccountTip[1] as any}> <Form.Item name="tosAccountName" label="Name" rules={AccountTip[1] as any}>
<Input placeholder="Name Of Administrator" className="input" /> <Input placeholder="Name Of Administrator" className="input" />
...@@ -336,13 +322,6 @@ const Account = (props: any) => { ...@@ -336,13 +322,6 @@ const Account = (props: any) => {
</Descriptions.Item> </Descriptions.Item>
</Descriptions> </Descriptions>
<Form.Item name="community" label="Community">
<SelectCommunity
checklist={community ? community : null}
list={community ? community : []}
/>
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}> <div className="diy" style={{ marginBottom: '14px' }}>
<div className="label"> <div className="label">
<span className="title">Privilege Level:</span> <span className="title">Privilege Level:</span>
...@@ -407,7 +386,6 @@ const Account = (props: any) => { ...@@ -407,7 +386,6 @@ const Account = (props: any) => {
const AccountProps = (state: any) => { const AccountProps = (state: any) => {
const { Data, DataSave, DataSaveDetail, Result, SubResult, Info } = state.Account; const { Data, DataSave, DataSaveDetail, Result, SubResult, Info } = state.Account;
const { CommunityList } = state.Init; // 小区列表
const loading = state.loading.models.Account || false; const loading = state.loading.models.Account || false;
const { user } = state; const { user } = state;
return { return {
...@@ -416,7 +394,6 @@ const AccountProps = (state: any) => { ...@@ -416,7 +394,6 @@ const AccountProps = (state: any) => {
DataSaveDetail, DataSaveDetail,
Result, Result,
loading, loading,
CommunityList,
user, // 获取当前账户信息 user, // 获取当前账户信息
SubResult, SubResult,
Info, Info,
......
import React, { useState, useEffect, useRef } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, Spin, message, Descriptions, Modal, Tree, Tag } from 'antd'; import { Form, Input, Button, message, Descriptions, Spin, Tree, Radio, Select, Modal } from 'antd';
import { connect, history } from 'umi'; import { connect, history } from 'umi';
import { import {
EditOutlined, EditOutlined,
LeftOutlined, LeftOutlined,
ExclamationCircleOutlined,
PoweroffOutlined, PoweroffOutlined,
RightOutlined,
CheckCircleOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { getCookie } from '@/utils/method';
import './Account.less'; import './Account.less';
import { zhCnFaci, enUsFaci } from '@/utils/power'; import { zhCnFaci, enUsFaci } from '@/utils/power';
import { AccountTip } from '@/utils/tip'; import { AccountTip } from '@/utils/tip';
// import SelectCommunity from '@/components/SelectCommunity';
import ShowOptions from '@/components/ShowOptions/index';
import { getNumber } from '@/utils/string'; // 正则 import { getNumber } from '@/utils/string'; // 正则
import { RA } from '@/utils/method'; import { RA } from '@/utils/method';
import moment from 'moment';
const Account = (props: any) => { const Account = (props: any) => {
const module = 'Account'; const module = 'Account';
const { Option } = Select;
const { dispatch, Data, DataSave, DataSaveDetail, Result, loading, Permission, user } = props; const { dispatch, SubResult, loading, user, DataSave, Permission, Result } = props;
// 权限列表 // 权限列表
const treeData = enUsFaci || zhCnFaci; const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci;
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目 const [expandedKeys, setExpandedKeys] = useState<string[]>(['0']); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState<string[]>([]); // 默认已选栏目 const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点 const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭 const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭
const [treeDataList, settreeDataList] = useState(treeData); // 权限列表
// 单选 二级还是三级管理员 // 单选 二级还是三级管理员
const [values, setvalues] = useState(2); // 树形菜单展开关闭 const [values, setvalues] = useState(2); // 树形菜单展开关闭
const [towAccountId, settowAccountId] = useState(null); // 二级账户id
const [over, setOver] = useState(false); // 关闭账号确认弹窗 //提醒次数
const [frequency, setfrequency] = useState(0); // 权限列表
// 表单标识 // 表单标识
const [form] = Form.useForm(); const [form] = Form.useForm();
const formRef = useRef(null); const formRef = useRef(null);
// // 数据 // 当前编辑账户的数据
useEffect(() => { useEffect(() => {
if (DataSave != null) { if (DataSave != null && user != null) {
// 赋值 // 赋值
form.setFieldsValue({ form.setFieldsValue({
tosUserName: DataSave.tosUserName, tosUserName: DataSave.tosUserName,
...@@ -56,18 +52,59 @@ const Account = (props: any) => { ...@@ -56,18 +52,59 @@ const Account = (props: any) => {
setvalues(DataSave.tosUserLevel); // 等级 setvalues(DataSave.tosUserLevel); // 等级
// 当前登录的不是admin 就 给默认id
if (user.currentUser.userModel.tosUserLevel > 1) {
settowAccountId(DataSave.userLeader); // 二级账户id
}
if (DataSave.tosUserLevel == 3) {
settowAccountId(DataSave.userLeader); //上级id
}
// 发起获取权限请求 // 发起获取权限请求
RA(54, { tosUserName: DataSave.tosUserName }, module, dispatch); // 发起获取权限请求 RA(54, { tosUserName: DataSave.tosUserName }, module, dispatch); // 发起获取权限请求
} else {
history.push('/AccountManagement/account');
} }
}, [DataSave]); }, [DataSave, user]);
// 当前账户权限 // 提交信息结果
useEffect(() => { useEffect(() => {
if (user != null) { if (SubResult != null) {
let treeDatas = treeData; if (SubResult.statr == 0 && SubResult.desc == 0) {
let _a = user.currentUser.permission; // 当前账户权限 // 保存成功, 清掉原来数据 并且跳转
let _p = treeDatas[0].children; // 所有权限列表 message.success('Submitted Successfully !');
dispatch({ type: module + '/ReData' });
dispatch({ type: module + '/AccountClear' });
history.go(-1);
}
}
}, [SubResult]);
// 已选权限
useEffect(() => {
if (Permission != null) {
// 当前权限
let newPer = eval('(' + Permission.curUserPermission + ')');
// 上级或者下级权限
let newPerTow = eval('(' + Permission.beloginPermission + ')');
let data: any = []; // 当前权限-- 字符串
let dataTow: any = []; // 上级或者下级权限 (可编辑权限)-- 字符串
// 转字符串
for (let i in newPer) {
data[i] = newPer[i] + '';
}
for (let i in newPerTow) {
dataTow[i] = newPerTow[i] + '';
}
// 深拷贝权限列表
let treeDatas = JSON.parse(JSON.stringify(treeData));
// 如果是三级账户 可编辑的就是 上级权限,否者是登录的账户权限
let _a = DataSave.tosUserLevel == 3 ? dataTow : user.currentUser.permission; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限 let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限 let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加 // 循环一级 判断当前账户有没有权限修改增加
...@@ -86,32 +123,19 @@ const Account = (props: any) => { ...@@ -86,32 +123,19 @@ const Account = (props: any) => {
} }
} }
} }
// 赋值改变 // 赋值 可勾选的权限
treeDatas[0].children = _p; treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表 settreeDataList([...treeDatas]);
}
}, [user]);
// 已选权限 //-----------------分割--------------------
useEffect(() => {
if (Permission != null) {
let newPer = eval('(' + Permission + ')');
let data: any = []; // 编辑的账户的权限
for (let i in newPer) {
data[i] = newPer[i] + '';
}
let _p = treeData[0].children; // 所有权限列表
// console.log(_p); // 所有权限列表
// 在解决默认已勾选的值
for (let i in _p) { for (let i in _p) {
let arr = _p[i].children; // 每个权限 let arr = _p[i].children; // 每个权限
let newArr = []; // 每个权限下的子权限列表 let newArr = []; // 每个权限下的子权限列表
for (let j in arr) { for (let j in arr) {
newArr.push(arr[j].key); newArr.push(arr[j].key);
} }
// console.log(newArr);
if (!newArr.every((val) => data.includes(val))) { if (!newArr.every((val) => data.includes(val))) {
// 判断数组是否包含另一个数组 // 判断数组是否包含另一个数组
// console.log('不包含' + _p[i].key); // console.log('不包含' + _p[i].key);
...@@ -120,58 +144,144 @@ const Account = (props: any) => { ...@@ -120,58 +144,144 @@ const Account = (props: any) => {
if (index > -1) { if (index > -1) {
data.splice(index, 1); data.splice(index, 1);
} }
} else {
// console.log('包含' + _p[i].key);
} }
} }
// 再赋值给列表 // 再赋值给列表
// data.push('0'); if (DataSave.tosUserLevel == 3) {
// 且禁用最后两个账户管理
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
}
setCheckedKeys(data); setCheckedKeys(data);
} }
}, [Permission]); }, [Permission, DataSave]);
// 保存提交 // 保存提交
const onFinishContract = async (value: any) => { const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || ''; const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id; const id = JSON.parse(userInfo).userModel.id;
// console.log(value); if (
if (checkedKeys.length == 0) { value.tosAccountName.length <= 2 &&
value.tosUserPhone.length != 8 &&
value.tosUserPhone.length != 11
) {
// 姓名联系方式
message.error('Please enter the correct name and contact information!');
return false;
} else if (checkedKeys[0].key) {
// 如果存在key 就是没有选择
// 权限 // 权限
message.error('Please Select Permission!'); message.error('Please Select Permission!');
return false; return false;
} else if (value.community.value == null || value.community.value.length == 0) {
// 小区
message.error('Please Select The Jurisdiction Area!');
return false;
} else if (value.tosUserName.length < 6) { } else if (value.tosUserName.length < 6) {
// 账号长度 // 账号长度
message.error('The Account Password is Greater Than 6 Digits!'); message.error('The Account Password is Greater Than 6 Digits!');
return false; return false;
} else if (values == 3 && towAccountId == null) {
// 如果创建的是三级账号就要判断是否选择了绑定的二级账户
message.error('Please select affiliated account !');
return false;
} else { } else {
value.tosUserServiceCellList = value.community.value; // 管辖小区
value.tosUserEmail = value.tosUserName; // 邮箱就是账号 value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别 value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号 // value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号
value.creatorId = id; //新建者ID value.creatorId = id; //新建者ID
if (values == 3) {
value.userLeader = towAccountId;
}
delete value.community; delete value.community;
// console.log(value); DataSave ? (value.id = DataSave.id) : '';
// 判断有没有 0 有就删除
for (var i in checkedKeys) {
checkedKeys[i] == '0' ? checkedKeys.splice(i, 1) : '';
}
// 追加到上级id
let Obj = treeData[0].children;
for (let i in Obj) {
for (let j in checkedKeys) {
if (JSON.stringify(Obj[i].children).indexOf(JSON.stringify(checkedKeys[j])) != -1) {
// 提取出上级id 并且追加
checkedKeys.push(Obj[i].key);
}
}
}
// 去重后在排序
let newData = Array.from(new Set(checkedKeys)).sort((n1: any, n2: any) => {
return parseInt(n1) - parseInt(n2);
});
//新旧权限比对
let subPermissionArray = [];
if (values == 2) {
let newPer = eval('(' + Permission.curUserPermission + ')');
let data: any = []; // 当前权限-- 字符串
// 转字符串
for (let i in newPer) {
data[i] = newPer[i] + '';
}
let Deleted = compare(data, newData); // 当前删除的权限有哪些
subPermissionArray = compares(Deleted); // 当前删除的三级权限有哪些
}
// 另传权限 // 另传权限
let obj = { let obj = {
userName: value.tosUserName, userName: value.tosUserName,
userPassword: value.tosUserPwd, userPassword: value.tosUserPwd,
permissionArray: checkedKeys.sort((n1, n2) => { permissionArray: newData,
return parseInt(n1) - parseInt(n2); subPermissionArray,
}),
}; };
// console.log(obj);
RA(38, value, module, dispatch); // 信息上传 RA(38, value, module, dispatch); // 信息上传
RA(42, obj, module, dispatch); // 权限上传 RA(42, obj, module, dispatch); // 权限上传
} }
}; };
// 保存前看看那些权限是增加或者减少
function compare(beforeArr: any, afterArr: any) {
let add = [];
let del = [];
let cenObj = {};
//把beforeArr数组去重放入cenObj
for (let i = 0; i < beforeArr.length; i++) {
cenObj[beforeArr[i]] = beforeArr[i];
}
//遍历afterArr,查看其元素是否在cenObj中
for (let j = 0; j < afterArr.length; j++) {
if (!cenObj[afterArr[j]]) {
add.push(afterArr[j]);
} else {
delete cenObj[afterArr[j]];
}
}
for (let k in cenObj) {
del.push(k);
}
// 只返回删除的
return del;
}
// 看看是不是动了三级权限的东西
function compares(afterArr: any) {
// 下级权限
let newPerTow = eval('(' + Permission.beloginPermission + ')');
let dataTow: any = []; // 上级或者下级权限 (可编辑权限)-- 字符串
let del = [];
for (let i in newPerTow) {
dataTow[i] = newPerTow[i] + '';
}
for (let i of afterArr) {
if (dataTow.indexOf(i) !== -1) {
del.push(i);
}
}
return del;
}
//goToReturn //goToReturn
const goToReturn = () => { const goToReturn = () => {
history.go(-1); history.go(-1);
...@@ -185,27 +295,64 @@ const Account = (props: any) => { ...@@ -185,27 +295,64 @@ const Account = (props: any) => {
// 点击单个触发 // 点击单个触发
const onCheck = (checkedKeys: any) => { const onCheck = (checkedKeys: any) => {
// 如果是二级账户就要判断去掉的有没有三级账户的权限
if (DataSave.tosUserLevel == 2) {
let checkers = (arr: any, target: any) => target.every((v: any) => arr.includes(v));
// 上级或者下级权限
let newPerTow = eval('(' + Permission.beloginPermission + ')');
// 列表权限
let treeDatas = JSON.parse(JSON.stringify(treeData));
// 列表的二级权限
let TowLev = treeDatas[0].children.map((v: any) => v.key);
let dataTow: any = [];
for (let i in newPerTow) {
// 如果不是二级就添加进去
if (TowLev.indexOf(newPerTow[i] + '') == -1) {
dataTow.push(newPerTow[i] + '');
}
}
// true 就是没有勾选到三级 false 就是勾选到三级了
if (!checkers(checkedKeys, dataTow)) {
showDeleteConfirm(checkedKeys);
return false;
}
}
setCheckedKeys(checkedKeys); setCheckedKeys(checkedKeys);
}; };
const { confirm } = Modal;
// 弹窗
function showDeleteConfirm(checkedKeys: any) {
// 如果没有提醒过的话就开启 否则直接设置
// if (frequency < 1) {
confirm({
title: 'Are you sure you want to delete this permission?',
icon: <ExclamationCircleOutlined />,
content:
'Cancel permission has been given to level 3 account. Do you want to delete it together!',
okText: 'Yes',
okType: 'danger',
cancelText: 'No',
onOk() {
setCheckedKeys(checkedKeys);
setfrequency(1);
},
onCancel() {},
});
// } else {
// setCheckedKeys(checkedKeys);
// }
}
// 点击树节点触发 - 大栏目 // 点击树节点触发 - 大栏目
const onSelect = (selectedKeys: any, info: any) => { const onSelect = (selectedKeys: any, info: any) => {
// console.log('onSelect', info);
setSelectedKeys(selectedKeys); setSelectedKeys(selectedKeys);
}; };
// 监听改变状态提交结果
useEffect(() => {
if (Result != null) {
message.success('Successful Operation !');
setOver(false);
// 清除结果
dispatch({ type: 'Account/ResultClear' });
dispatch({ type: 'Account/ReData' });
// 退回列表
history.push('/AccountManagement/account');
}
}, [Result]);
//手机号 //手机号
const keyup_communityManagerFee = (e: any) => { const keyup_communityManagerFee = (e: any) => {
e.target.value = keyup_tool(e.target.value); e.target.value = keyup_tool(e.target.value);
...@@ -213,9 +360,28 @@ const Account = (props: any) => { ...@@ -213,9 +360,28 @@ const Account = (props: any) => {
const keyup_tool = (value: any) => { const keyup_tool = (value: any) => {
return getNumber(value.replace(/[^\d^\.]+/g, '')); return getNumber(value.replace(/[^\d^\.]+/g, ''));
}; };
// 选择小区名字并赋值
// 管理员级别样式
const radioStyle = {
display: 'block',
height: '30px',
lineHeight: '30px',
marginBottom: '15px',
};
//级别切换
const onRadio = (e: any) => {
setvalues(e.target.value);
// setCheckedKeys([]);
if (e.target.value == 2) {
//否则打开
settowAccountId(null);
}
};
// 停用账号弹窗 // 停用账号弹窗
const [over, setOver] = useState(false); // 关闭账号确认弹窗
const lockS = () => { const lockS = () => {
// 先判断是不是自己 // 先判断是不是自己
const userInfo = JSON.parse(localStorage.getItem('userInfo') || '[]'); const userInfo = JSON.parse(localStorage.getItem('userInfo') || '[]');
...@@ -226,7 +392,6 @@ const Account = (props: any) => { ...@@ -226,7 +392,6 @@ const Account = (props: any) => {
setOver(true); setOver(true);
} }
}; };
// 关闭弹窗 // 关闭弹窗
const handleCancel = (e: any) => { const handleCancel = (e: any) => {
setOver(false); setOver(false);
...@@ -236,7 +401,6 @@ const Account = (props: any) => { ...@@ -236,7 +401,6 @@ const Account = (props: any) => {
const handleOk = (e: any) => { const handleOk = (e: any) => {
// //
let obj = { let obj = {
// userStatus: DataSave.userStatus == 0 ? 1 : 0,
userStatus: 1, userStatus: 1,
userID: DataSave.tosUserId, userID: DataSave.tosUserId,
}; };
...@@ -244,6 +408,19 @@ const Account = (props: any) => { ...@@ -244,6 +408,19 @@ const Account = (props: any) => {
// setOver(false); // setOver(false);
}; };
// 监听改变状态提交结果
useEffect(() => {
if (Result != null) {
message.success('Successful Operation !');
setOver(false);
// 清除结果
dispatch({ type: 'Account/ResultClear' });
dispatch({ type: 'Account/ReData' });
// 退回列表
history.push('/AccountManagement/account');
}
}, [Result]);
return ( return (
<Spin spinning={loading}> <Spin spinning={loading}>
<div className="contop" style={{ padding: '12px 20px' }}> <div className="contop" style={{ padding: '12px 20px' }}>
...@@ -266,7 +443,6 @@ const Account = (props: any) => { ...@@ -266,7 +443,6 @@ const Account = (props: any) => {
</div> </div>
</h3> </h3>
<hr></hr> <hr></hr>
<Form <Form
ref={formRef} ref={formRef}
form={form} form={form}
...@@ -276,15 +452,12 @@ const Account = (props: any) => { ...@@ -276,15 +452,12 @@ const Account = (props: any) => {
name="contract" name="contract"
onFinish={onFinishContract} onFinish={onFinishContract}
> >
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}> <Descriptions column={{ xs: 1, sm: 1, md: 2, xl: 3 }}>
<Descriptions.Item> <Descriptions.Item>
<Form.Item name="tosUserName" label="Account ID" rules={AccountTip[0] as any}> <Form.Item name="tosUserName" label="Account ID" rules={AccountTip[0] as any}>
<Input placeholder="Login Account" className="input" disabled /> <Input placeholder="Login Account" className="input" disabled />
</Form.Item> </Form.Item>
</Descriptions.Item> </Descriptions.Item>
</Descriptions>
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}>
<Descriptions.Item> <Descriptions.Item>
<Form.Item name="tosAccountName" label="Name" rules={AccountTip[1] as any}> <Form.Item name="tosAccountName" label="Name" rules={AccountTip[1] as any}>
<Input placeholder="Name Of Administrator" className="input" disabled /> <Input placeholder="Name Of Administrator" className="input" disabled />
...@@ -303,39 +476,36 @@ const Account = (props: any) => { ...@@ -303,39 +476,36 @@ const Account = (props: any) => {
</Descriptions.Item> </Descriptions.Item>
</Descriptions> </Descriptions>
<Form.Item name="community" label="Community">
{/* <SelectCommunity
checklist={DataSave == null ? null : DataSave.tosUserServiceCell.split(',')}
/> */}
<ShowOptions
list={DataSave ? DataSave.tosUserServiceCell.split(',') : []}
defaultValue={'Put It Away'}
></ShowOptions>
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}> <div className="diy" style={{ marginBottom: '14px' }}>
<div className="label"> <div className="label">
<span className="title">Privilege Level:</span> <span className="title">Privilege Level:</span>
</div> </div>
<div className="label"> <div className="label">
<Tag <Radio.Group value={values} onChange={onRadio}>
icon={<CheckCircleOutlined />} <Radio style={radioStyle} disabled value={2}>
color="success" Two Level Administrator
style={{ verticalAlign: 'sub', fontSize: 14, padding: '4px 7px' }} </Radio>
> <Radio style={radioStyle} disabled value={3}>
{DataSave && DataSave.tosUserLevel == 2 Three Level Administrator
? 'Two Level Administrator ' </Radio>
: 'Three Level Administrator'} </Radio.Group>
</Tag>
{DataSave && DataSave.tosUserLevel == 3 ? ( {/* 选择挂靠的二级菜单 */}
<Tag {values === 3 && user.currentUser.userModel.tosUserLevel <= 1 ? (
icon={<RightOutlined />} <Select
color="processing" style={{ width: 260 }}
style={{ verticalAlign: 'sub', fontSize: 14, padding: '4px 7px' }} placeholder="Please select affiliated account"
disabled
defaultValue={DataSave.userLeader}
> >
Superiors:{DataSave.userLeaderAccountName} - {DataSave.userLeaderName} {DataSave ? (
</Tag> <Option key={DataSave.userLeader} value={DataSave.userLeader}>
{DataSave.userLeaderAccountName}-{DataSave.userLeaderName}
</Option>
) : (
''
)}
</Select>
) : ( ) : (
'' ''
)} )}
...@@ -356,7 +526,7 @@ const Account = (props: any) => { ...@@ -356,7 +526,7 @@ const Account = (props: any) => {
checkedKeys={checkedKeys} checkedKeys={checkedKeys}
onSelect={onSelect} onSelect={onSelect}
selectedKeys={selectedKeys} selectedKeys={selectedKeys}
treeData={treeData} treeData={treeDataList}
disabled disabled
/> />
</div> </div>
...@@ -370,35 +540,35 @@ const Account = (props: any) => { ...@@ -370,35 +540,35 @@ const Account = (props: any) => {
</Button> </Button>
</div> </div>
</div> </div>
</Form>
{/* 确认关闭账号 */} {/* 确认关闭账号 */}
<Modal <Modal
title="Operation Tips" title="Operation Tips"
visible={over} visible={over}
okText={'Confirm'} okText={'Confirm'}
cancelText={'Cancel'} cancelText={'Cancel'}
onOk={handleOk} onOk={handleOk}
onCancel={handleCancel} onCancel={handleCancel}
confirmLoading={loading} confirmLoading={loading}
> >
{DataSave != null ? ( {DataSave != null ? (
<p> <p>
Are You Sure To{' '} Are You Sure To{' '}
<span style={{ color: 'red' }}>{DataSave.userStatus != 1 ? 'Close' : 'Open'}</span>{' '} <span style={{ color: 'red' }}>{DataSave.userStatus != 1 ? 'Close' : 'Open'}</span>{' '}
The Account '<span style={{ color: 'red' }}> {DataSave.tosUserName} </span>' ? The Account '<span style={{ color: 'red' }}> {DataSave.tosUserName} </span>' ?
</p> </p>
) : ( ) : (
'' ''
)} )}
</Modal> </Modal>
</Form>
</div> </div>
</Spin> </Spin>
); );
}; };
const AccountProps = (state: any) => { const AccountProps = (state: any) => {
const { Data, DataSave, DataSaveDetail, Result, Permission } = state.Account; const { Data, DataSave, DataSaveDetail, Result, SubResult, Permission, Info } = state.Account;
const loading = state.loading.models.Account || false; const loading = state.loading.models.Account || false;
const { user } = state; const { user } = state;
return { return {
...@@ -408,7 +578,9 @@ const AccountProps = (state: any) => { ...@@ -408,7 +578,9 @@ const AccountProps = (state: any) => {
Result, Result,
loading, loading,
Permission, Permission,
user, user, // 获取当前账户信息
SubResult,
Info,
}; };
}; };
......
import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, message, Descriptions, Spin, Tree, Radio, Select } from 'antd';
import { connect, history } from 'umi';
import { EditOutlined, LeftOutlined } from '@ant-design/icons';
import './Account.less';
import { zhCnFaci, enUsFaci } from '@/utils/power';
import { AccountTip } from '@/utils/tip';
import SelectCommunity from '@/components/SelectCommunity';
import { getNumber } from '@/utils/string'; // 正则
import { RA } from '@/utils/method';
const Account = (props: any) => {
const module = 'Account';
const { dispatch, SubResult, CommunityList, loading, user, DataSave, Permission, Info } = props;
// 权限列表
const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci;
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭
const [treeDataList, settreeDataList] = useState(treeData); // 权限列表
// 单选 二级还是三级管理员
const [values, setvalues] = useState(2); // 树形菜单展开关闭
const [disab, setdisab] = useState(false); // 是否禁止选择二级
const [towAccountId, settowAccountId] = useState(null); // 二级账户id
//默认选中的小区
const [community, setCommunity] = useState([] as any);
// 表单标识
const [form] = Form.useForm();
const formRef = useRef(null);
const { Option } = Select;
//二级账户列表
const towAccount = JSON.parse(localStorage.getItem('towAccount') || '[]');
// 当前账户权限
useEffect(() => {
if (user != null || values == 2) {
let _tmp = JSON.stringify(treeData); //将对象转换为json字符串形式
let treeDatas = JSON.parse(_tmp); //将转换而来的字符串转换为原生js对
let _a = user.currentUser.permission; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
for (let i of _a) {
for (let j in _p) {
if (_p[j].key == i) {
arr.push(_p[j].key);
_p[j].disabled = false;
}
// 二级权限
for (let k in _p[j].children) {
if (_p[j].children[k].key == i) {
erArr.push(_p[j].children[k].key);
_p[j].children[k].disableCheckbox = false;
}
}
}
}
// 当当前账户是二级以上禁用创建二级菜单
if (user.currentUser.userModel.tosUserLevel > 1) {
setvalues(3);
setdisab(true);
settowAccountId(user.currentUser.userModel.id);
// 且禁用最后两个账户管理
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
} else {
// 如果是一级账户获取挂靠的二级账户名称
RA(56, {}, module, dispatch); // 权限上传
}
// 赋值改变
treeDatas[0].children = _p;
settreeDataList(treeDatas as any); // 可勾选列表
}
}, [user, values]);
// 当前编辑账户的数据
useEffect(() => {
if (DataSave != null && user != null) {
// 赋值
form.setFieldsValue({
tosUserName: DataSave.tosUserName,
tosUserPhone: DataSave.tosUserPhone,
tosAccountName: DataSave.tosAccountName,
});
setvalues(DataSave.tosUserLevel); // 等级
setCommunity([...DataSave.tosUserServiceCell.split(',')]); // 默认小区
// 当前登录的不是admin 就 给默认id
if (user.currentUser.userModel.tosUserLevel > 1) {
settowAccountId(DataSave.userLeader); // 二级账户id
}
// 如果是3级,取消后面两个选择
if (DataSave.tosUserLevel == 3) {
let treeDatas = treeData;
let _p = treeDatas[0].children; // 所有权限列表
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
}
// 发起获取权限请求
RA(54, { tosUserName: DataSave.tosUserName }, module, dispatch); // 发起获取权限请求
}
}, [DataSave, user]);
// 提交信息结果
useEffect(() => {
if (SubResult != null) {
if (SubResult.statr == 0 && SubResult.desc == 0) {
// 保存成功, 清掉原来数据 并且跳转
message.success('Submitted Successfully !');
dispatch({ type: module + '/ReData' });
dispatch({ type: module + '/AccountClear' });
history.go(-1);
}
}
}, [SubResult]);
// 已选权限
useEffect(() => {
if (Permission != null) {
let newPer = eval('(' + Permission + ')');
let data: any = []; // 编辑的账户的权限
for (let i in newPer) {
data[i] = newPer[i] + '';
}
let _p = treeData[0].children; // 所有权限列表
// console.log(_p); // 所有权限列表
for (let i in _p) {
let arr = _p[i].children; // 每个权限
let newArr = []; // 每个权限下的子权限列表
for (let j in arr) {
newArr.push(arr[j].key);
}
// console.log(newArr);
if (!newArr.every((val) => data.includes(val))) {
// 判断数组是否包含另一个数组
// console.log('不包含' + _p[i].key);
// 不全部包含就删除数组的元素
var index = data.indexOf(_p[i].key);
if (index > -1) {
data.splice(index, 1);
}
} else {
// console.log('包含' + _p[i].key);
}
}
// 再赋值给列表
setCheckedKeys(data);
}
}, [Permission]);
// 二级管辖小区和权限
useEffect(() => {
if (Info != null) {
setCommunity(Info.community);
power(Info.permissions);
}
}, [Info]);
//权限赋值
const power = (val: any) => {
let _tmp = JSON.stringify(treeData); //将对象转换为json字符串形式
let treeDatas = JSON.parse(_tmp); //将转换而来的字符串转换为原生js对
let _a = val; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
for (let i of _a) {
for (let j in _p) {
if (_p[j].key == i) {
arr.push(_p[j].key);
_p[j].disabled = false;
}
// 二级权限
for (let k in _p[j].children) {
if (_p[j].children[k].key == i) {
erArr.push(_p[j].children[k].key);
_p[j].children[k].disableCheckbox = false;
}
}
}
}
// 且禁用最后两个账户管理
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 赋值改变
treeDatas[0].children = _p;
settreeDataList(treeDatas as any); // 可勾选列表
};
// 保存提交
const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
if (
value.tosAccountName.length <= 2 &&
value.tosUserPhone.length != 8 &&
value.tosUserPhone.length != 11
) {
// 姓名联系方式
message.error('Please enter the correct name and contact information!');
return false;
} else if (checkedKeys[0].key) {
// 如果存在key 就是没有选择
// 权限
message.error('Please Select Permission!');
return false;
} else if (value.community.value == null || value.community.value.length == 0) {
// 小区
message.error('Please Select The Jurisdiction Area!');
return false;
} else if (value.tosUserName.length < 6) {
// 账号长度
message.error('The Account Password is Greater Than 6 Digits!');
return false;
} else if (values == 3 && towAccountId == null) {
// 如果创建的是三级账号就要判断是否选择了绑定的二级账户
message.error('Please select affiliated account !');
return false;
} else {
value.tosUserServiceCellList = value.community.value; // 管辖小区
value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别
// value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号
value.creatorId = id; //新建者ID
if (values == 3) {
value.userLeader = towAccountId;
}
delete value.community;
DataSave ? (value.id = DataSave.id) : '';
// 判断有没有 0 有就删除
for (var i in checkedKeys) {
checkedKeys[i] == '0' ? checkedKeys.splice(i, 1) : '';
}
// 追加到上级id
let Obj = treeData[0].children;
console.log(Obj);
for (let i in Obj) {
for (let j in checkedKeys) {
if (JSON.stringify(Obj[i].children).indexOf(JSON.stringify(checkedKeys[j])) != -1) {
// 提取出上级id 并且追加
checkedKeys.push(Obj[i].key);
}
}
}
// 去重后在排序
let newData = Array.from(new Set(checkedKeys)).sort((n1: any, n2: any) => {
return parseInt(n1) - parseInt(n2);
});
// 另传权限
let obj = {
userName: value.tosUserName,
userPassword: value.tosUserPwd,
permissionArray: newData,
};
RA(38, value, module, dispatch); // 信息上传
RA(42, obj, module, dispatch); // 权限上传
return true;
}
};
//goToReturn
const goToReturn = () => {
history.go(-1);
};
// 展开/收起树形菜单触发
const onExpand = (expandedKeys: any) => {
setExpandedKeys(expandedKeys);
setAutoExpandParent(false);
};
// 点击单个触发
const onCheck = (checkedKeys: any) => {
// console.log('onCheck', checkedKeys);
setCheckedKeys(checkedKeys);
};
// 点击树节点触发 - 大栏目
const onSelect = (selectedKeys: any, info: any) => {
// console.log('onSelect', info);
setSelectedKeys(selectedKeys);
};
// 管理员级别样式
const radioStyle = {
display: 'block',
height: '30px',
lineHeight: '30px',
marginBottom: '15px',
};
//级别切换
const onRadio = (e: any) => {
// 当编辑自己的时候不能切换
if (user.currentUser.userModel.id === DataSave.id) {
message.info('You cannot modify your own level!');
return false;
} else {
setvalues(e.target.value);
// 如果是3级,取消后面两个选择
let treeDatas = treeData;
let _p = treeDatas[0].children; // 所有权限列表
// 禁用最后两个
if (e.target.value == 3) {
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
} else {
//否则打开
_p[_p.length - 1].children[2].disableCheckbox = false;
_p[_p.length - 1].children[3].disableCheckbox = false;
settowAccountId(null);
}
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
return;
}
};
//手机号
const keyup_communityManagerFee = (e: any) => {
e.target.value = keyup_tool(e.target.value);
};
const keyup_tool = (value: any) => {
return getNumber(value.replace(/[^\d^\.]+/g, ''));
};
// 二级账户
const listItems = towAccount.map((item: any) => {
return (
<Option key={item.id} value={item.id}>
{item.tosAccountName}-{item.tosUserEmail}
</Option>
);
});
// 选择哪个二级账号
const handleChange = (value: any) => {
RA(57, { tosUserLevelId: value }, module, dispatch); // 根据用户id获取用户管辖小区名和权限
settowAccountId(value);
};
return (
<Spin spinning={loading}>
<div className="contop" style={{ padding: '12px 20px' }}>
<h3 className="capi">
<EditOutlined />
&nbsp; Edit Account
<div className="back">
<Button onClick={goToReturn}>
<LeftOutlined />
Back
</Button>
</div>
</h3>
<hr></hr>
<Form
ref={formRef}
form={form}
autoComplete="off"
// layout="inline"
layout="horizontal"
name="contract"
onFinish={onFinishContract}
>
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}>
<Descriptions.Item>
<Form.Item name="tosUserName" label="Account ID" rules={AccountTip[0] as any}>
<Input placeholder="Login Account" className="input" />
</Form.Item>
</Descriptions.Item>
</Descriptions>
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}>
<Descriptions.Item>
<Form.Item name="tosAccountName" label="Name" rules={AccountTip[1] as any}>
<Input placeholder="Name Of Administrator" className="input" />
</Form.Item>
</Descriptions.Item>
<Descriptions.Item>
<Form.Item name="tosUserPhone" label="Phone" rules={AccountTip[2] as any}>
<Input
placeholder="Contact Information"
className="input"
maxLength={11}
onKeyUp={keyup_communityManagerFee}
/>
</Form.Item>
</Descriptions.Item>
</Descriptions>
<Form.Item name="community" label="Community">
<SelectCommunity checklist={community} />
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}>
<div className="label">
<span className="title">Privilege Level:</span>
</div>
<div className="label">
<Radio.Group value={values} onChange={onRadio}>
<Radio style={radioStyle} disabled={disab} value={2}>
Two Level Administrator
</Radio>
<Radio style={radioStyle} value={3}>
Three Level Administrator
</Radio>
</Radio.Group>
{/* 选择挂靠的二级菜单 */}
{values === 3 && user.currentUser.userModel.tosUserLevel <= 1 ? (
<Select
style={{ width: 260 }}
onChange={handleChange}
placeholder="Please select affiliated account"
defaultValue={towAccountId as any}
>
{towAccount ? listItems : ''}
</Select>
) : (
''
)}
</div>
</div>
<div className="diy" style={{ marginBottom: '24px' }}>
<div className="label">
<span className="title">Permission List:</span>
</div>
<div className="label">
<Tree
checkable
onExpand={onExpand}
expandedKeys={expandedKeys}
autoExpandParent={autoExpandParent}
onCheck={onCheck}
checkedKeys={checkedKeys}
onSelect={onSelect}
selectedKeys={selectedKeys}
treeData={treeDataList}
/>
</div>
</div>
<div className="diy">
<div className="label"></div>
<div className="label">
<Button type="primary" htmlType="submit" loading={loading}>
Submit
</Button>
</div>
</div>
</Form>
</div>
</Spin>
);
};
const AccountProps = (state: any) => {
const { Data, DataSave, DataSaveDetail, Result, SubResult, Permission, Info } = state.Account;
const { CommunityList } = state.Init; // 小区列表
const loading = state.loading.models.Account || false;
const { user } = state;
return {
Data,
DataSave,
DataSaveDetail,
Result,
loading,
Permission,
CommunityList,
user, // 获取当前账户信息
SubResult,
Info,
};
};
export default connect(AccountProps)(Account);
import React, { useState, useEffect, useRef } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, message, Descriptions, Spin, Tree, Tag, Select } from 'antd'; import { Form, Input, Button, message, Descriptions, Spin, Tree, Radio, Select, Modal } from 'antd';
import { connect, history } from 'umi'; import { connect, history } from 'umi';
import { EditOutlined, LeftOutlined, CheckCircleOutlined, RightOutlined } from '@ant-design/icons'; import { EditOutlined, LeftOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
import './Account.less'; import './Account.less';
import { zhCnFaci, enUsFaci } from '@/utils/power'; import { zhCnFaci, enUsFaci } from '@/utils/power';
import { AccountTip } from '@/utils/tip'; import { AccountTip } from '@/utils/tip';
import SelectCommunity from '@/components/SelectCommunity/Tow';
import { getNumber } from '@/utils/string'; // 正则 import { getNumber } from '@/utils/string'; // 正则
import { RA } from '@/utils/method'; import { RA } from '@/utils/method';
const Account = (props: any) => { const Account = (props: any) => {
const module = 'Account'; const module = 'Account';
const { Option } = Select;
const { dispatch, SubResult, CommunityList, loading, user, DataSave, Permission, Info } = props; const { dispatch, SubResult, loading, user, DataSave, Permission } = props;
// 权限列表 // 权限列表
const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci; const treeData = localStorage.getItem('umi_locale') == 'zh-CN' ? zhCnFaci : enUsFaci;
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目 const [expandedKeys, setExpandedKeys] = useState<string[]>(['0']); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目 const [checkedKeys, setCheckedKeys] = useState([] as any); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点 const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭 const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭
...@@ -29,44 +28,13 @@ const Account = (props: any) => { ...@@ -29,44 +28,13 @@ const Account = (props: any) => {
const [values, setvalues] = useState(2); // 树形菜单展开关闭 const [values, setvalues] = useState(2); // 树形菜单展开关闭
const [towAccountId, settowAccountId] = useState(null); // 二级账户id const [towAccountId, settowAccountId] = useState(null); // 二级账户id
//默认选中的小区 //提醒次数
const [community, setCommunity] = useState([] as any); const [frequency, setfrequency] = useState(0); // 权限列表
// 表单标识 // 表单标识
const [form] = Form.useForm(); const [form] = Form.useForm();
const formRef = useRef(null); const formRef = useRef(null);
// 当前账户权限
useEffect(() => {
if (user != null) {
let treeDatas = treeData;
let _a = user.currentUser.permission; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
for (let i of _a) {
for (let j in _p) {
if (_p[j].key == i) {
arr.push(_p[j].key);
_p[j].disabled = false;
}
// 二级权限
for (let k in _p[j].children) {
if (_p[j].children[k].key == i) {
erArr.push(_p[j].children[k].key);
_p[j].children[k].disableCheckbox = false;
}
}
}
}
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
}
}, [user]);
// 当前编辑账户的数据 // 当前编辑账户的数据
useEffect(() => { useEffect(() => {
if (DataSave != null && user != null) { if (DataSave != null && user != null) {
...@@ -78,7 +46,6 @@ const Account = (props: any) => { ...@@ -78,7 +46,6 @@ const Account = (props: any) => {
}); });
setvalues(DataSave.tosUserLevel); // 等级 setvalues(DataSave.tosUserLevel); // 等级
setCommunity([...DataSave.tosUserServiceCell.split(',')]); // 默认小区
// 当前登录的不是admin 就 给默认id // 当前登录的不是admin 就 给默认id
if (user.currentUser.userModel.tosUserLevel > 1) { if (user.currentUser.userModel.tosUserLevel > 1) {
...@@ -112,23 +79,58 @@ const Account = (props: any) => { ...@@ -112,23 +79,58 @@ const Account = (props: any) => {
// 已选权限 // 已选权限
useEffect(() => { useEffect(() => {
if (Permission != null) { if (Permission != null) {
let newPer = eval('(' + Permission + ')'); // 当前权限
let data: any = []; // 编辑的账户的权限 let newPer = eval('(' + Permission.curUserPermission + ')');
// 上级或者下级权限
let newPerTow = eval('(' + Permission.beloginPermission + ')');
let data: any = []; // 当前权限-- 字符串
let dataTow: any = []; // 上级或者下级权限 (可编辑权限)-- 字符串
// 转字符串
for (let i in newPer) { for (let i in newPer) {
data[i] = newPer[i] + ''; data[i] = newPer[i] + '';
} }
for (let i in newPerTow) {
dataTow[i] = newPerTow[i] + '';
}
// 深拷贝权限列表
let treeDatas = JSON.parse(JSON.stringify(treeData));
// 如果是三级账户 可编辑的就是 上级权限,否者是登录的账户权限
let _a = DataSave.tosUserLevel == 3 ? dataTow : user.currentUser.permission; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
for (let i of _a) {
for (let j in _p) {
if (_p[j].key == i) {
arr.push(_p[j].key);
_p[j].disabled = false;
}
// 二级权限
for (let k in _p[j].children) {
if (_p[j].children[k].key == i) {
erArr.push(_p[j].children[k].key);
_p[j].children[k].disableCheckbox = false;
}
}
}
}
// 赋值 可勾选的权限
treeDatas[0].children = _p;
settreeDataList([...treeDatas]);
let _p = treeData[0].children; // 所有权限列表 //-----------------分割--------------------
// console.log(_p); // 所有权限列表
// 在解决默认已勾选的值
for (let i in _p) { for (let i in _p) {
let arr = _p[i].children; // 每个权限 let arr = _p[i].children; // 每个权限
let newArr = []; // 每个权限下的子权限列表 let newArr = []; // 每个权限下的子权限列表
for (let j in arr) { for (let j in arr) {
newArr.push(arr[j].key); newArr.push(arr[j].key);
} }
// console.log(newArr);
if (!newArr.every((val) => data.includes(val))) { if (!newArr.every((val) => data.includes(val))) {
// 判断数组是否包含另一个数组 // 判断数组是否包含另一个数组
// console.log('不包含' + _p[i].key); // console.log('不包含' + _p[i].key);
...@@ -137,58 +139,19 @@ const Account = (props: any) => { ...@@ -137,58 +139,19 @@ const Account = (props: any) => {
if (index > -1) { if (index > -1) {
data.splice(index, 1); data.splice(index, 1);
} }
} else {
// console.log('包含' + _p[i].key);
} }
} }
// 再赋值给列表 // 再赋值给列表
// data.push('0'); if (DataSave.tosUserLevel == 3) {
setCheckedKeys(data); // 且禁用最后两个账户管理
} _p[_p.length - 1].children[2].disableCheckbox = true;
}, [Permission]); _p[_p.length - 1].children[3].disableCheckbox = true;
// 二级管辖小区和权限
useEffect(() => {
if (Info != null) {
setCommunity(Info.community);
power(Info.permissions);
}
}, [Info]);
//权限赋值
const power = (val: any) => {
let _tmp = JSON.stringify(treeData); //将对象转换为json字符串形式
let treeDatas = JSON.parse(_tmp); //将转换而来的字符串转换为原生js对
let _a = val; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
for (let i of _a) {
for (let j in _p) {
if (_p[j].key == i) {
arr.push(_p[j].key);
_p[j].disabled = false;
}
// 二级权限
for (let k in _p[j].children) {
if (_p[j].children[k].key == i) {
erArr.push(_p[j].children[k].key);
_p[j].children[k].disableCheckbox = false;
}
}
} }
setCheckedKeys(data);
} }
// 且禁用最后两个账户管理 }, [Permission, DataSave]);
_p[_p.length - 1].children[2].disableCheckbox = true;
_p[_p.length - 1].children[3].disableCheckbox = true;
// 赋值改变
treeDatas[0].children = _p;
settreeDataList(treeDatas as any); // 可勾选列表
};
// 保存提交 // 保存提交
const onFinishContract = async (value: any) => { const onFinishContract = async (value: any) => {
...@@ -207,10 +170,6 @@ const Account = (props: any) => { ...@@ -207,10 +170,6 @@ const Account = (props: any) => {
// 权限 // 权限
message.error('Please Select Permission!'); message.error('Please Select Permission!');
return false; return false;
} else if (value.community.value == null || value.community.value.length == 0) {
// 小区
message.error('Please Select The Jurisdiction Area!');
return false;
} else if (value.tosUserName.length < 6) { } else if (value.tosUserName.length < 6) {
// 账号长度 // 账号长度
message.error('The Account Password is Greater Than 6 Digits!'); message.error('The Account Password is Greater Than 6 Digits!');
...@@ -220,7 +179,6 @@ const Account = (props: any) => { ...@@ -220,7 +179,6 @@ const Account = (props: any) => {
message.error('Please select affiliated account !'); message.error('Please select affiliated account !');
return false; return false;
} else { } else {
value.tosUserServiceCellList = value.community.value; // 管辖小区
value.tosUserEmail = value.tosUserName; // 邮箱就是账号 value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别 value.tosUserLevel = values; //级别
// value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号 // value.creatorName = JSON.parse(userInfo).userModel.tosUserName; //新建者账号
...@@ -238,7 +196,7 @@ const Account = (props: any) => { ...@@ -238,7 +196,7 @@ const Account = (props: any) => {
// 追加到上级id // 追加到上级id
let Obj = treeData[0].children; let Obj = treeData[0].children;
console.log(Obj);
for (let i in Obj) { for (let i in Obj) {
for (let j in checkedKeys) { for (let j in checkedKeys) {
if (JSON.stringify(Obj[i].children).indexOf(JSON.stringify(checkedKeys[j])) != -1) { if (JSON.stringify(Obj[i].children).indexOf(JSON.stringify(checkedKeys[j])) != -1) {
...@@ -252,19 +210,73 @@ const Account = (props: any) => { ...@@ -252,19 +210,73 @@ const Account = (props: any) => {
return parseInt(n1) - parseInt(n2); return parseInt(n1) - parseInt(n2);
}); });
//新旧权限比对
let subPermissionArray = [];
if (values == 2) {
let newPer = eval('(' + Permission.curUserPermission + ')');
let data: any = []; // 当前权限-- 字符串
// 转字符串
for (let i in newPer) {
data[i] = newPer[i] + '';
}
let Deleted = compare(data, newData); // 当前删除的权限有哪些
subPermissionArray = compares(Deleted); // 当前删除的三级权限有哪些
}
// 另传权限 // 另传权限
let obj = { let obj = {
userName: value.tosUserName, userName: value.tosUserName,
userPassword: value.tosUserPwd, userPassword: value.tosUserPwd,
permissionArray: newData, permissionArray: newData,
subPermissionArray,
}; };
RA(38, value, module, dispatch); // 信息上传 RA(38, value, module, dispatch); // 信息上传
RA(42, obj, module, dispatch); // 权限上传 RA(42, obj, module, dispatch); // 权限上传
return true;
} }
}; };
// 保存前看看那些权限是增加或者减少
function compare(beforeArr: any, afterArr: any) {
let add = [];
let del = [];
let cenObj = {};
//把beforeArr数组去重放入cenObj
for (let i = 0; i < beforeArr.length; i++) {
cenObj[beforeArr[i]] = beforeArr[i];
}
//遍历afterArr,查看其元素是否在cenObj中
for (let j = 0; j < afterArr.length; j++) {
if (!cenObj[afterArr[j]]) {
add.push(afterArr[j]);
} else {
delete cenObj[afterArr[j]];
}
}
for (let k in cenObj) {
del.push(k);
}
// 只返回删除的
return del;
}
// 看看是不是动了三级权限的东西
function compares(afterArr: any) {
// 下级权限
let newPerTow = eval('(' + Permission.beloginPermission + ')');
let dataTow: any = []; // 上级或者下级权限 (可编辑权限)-- 字符串
let del = [];
for (let i in newPerTow) {
dataTow[i] = newPerTow[i] + '';
}
for (let i of afterArr) {
if (dataTow.indexOf(i) !== -1) {
del.push(i);
}
}
return del;
}
//goToReturn //goToReturn
const goToReturn = () => { const goToReturn = () => {
history.go(-1); history.go(-1);
...@@ -278,10 +290,58 @@ const Account = (props: any) => { ...@@ -278,10 +290,58 @@ const Account = (props: any) => {
// 点击单个触发 // 点击单个触发
const onCheck = (checkedKeys: any) => { const onCheck = (checkedKeys: any) => {
// console.log('onCheck', checkedKeys); // 如果是二级账户就要判断去掉的有没有三级账户的权限
if (DataSave.tosUserLevel == 2) {
let checkers = (arr: any, target: any) => target.every((v: any) => arr.includes(v));
// 上级或者下级权限
let newPerTow = eval('(' + Permission.beloginPermission + ')');
// 列表权限
let treeDatas = JSON.parse(JSON.stringify(treeData));
// 列表的二级权限
let TowLev = treeDatas[0].children.map((v: any) => v.key);
let dataTow: any = [];
for (let i in newPerTow) {
// 如果不是二级就添加进去
if (TowLev.indexOf(newPerTow[i] + '') == -1) {
dataTow.push(newPerTow[i] + '');
}
}
// true 就是没有勾选到三级 false 就是勾选到三级了
if (!checkers(checkedKeys, dataTow)) {
showDeleteConfirm(checkedKeys);
return false;
}
}
setCheckedKeys(checkedKeys); setCheckedKeys(checkedKeys);
}; };
const { confirm } = Modal;
// 弹窗
function showDeleteConfirm(checkedKeys: any) {
// 如果没有提醒过的话就开启 否则直接设置
// if (frequency < 1) {
confirm({
title: 'Are you sure you want to delete this permission?',
icon: <ExclamationCircleOutlined />,
content:
'Cancel permission has been given to level 3 account. Do you want to delete it together!',
okText: 'Yes',
okType: 'danger',
cancelText: 'No',
onOk() {
setCheckedKeys(checkedKeys);
setfrequency(1);
},
onCancel() {},
});
// } else {
// setCheckedKeys(checkedKeys);
// }
}
// 点击树节点触发 - 大栏目 // 点击树节点触发 - 大栏目
const onSelect = (selectedKeys: any, info: any) => { const onSelect = (selectedKeys: any, info: any) => {
// console.log('onSelect', info); // console.log('onSelect', info);
...@@ -296,6 +356,24 @@ const Account = (props: any) => { ...@@ -296,6 +356,24 @@ const Account = (props: any) => {
return getNumber(value.replace(/[^\d^\.]+/g, '')); return getNumber(value.replace(/[^\d^\.]+/g, ''));
}; };
// 管理员级别样式
const radioStyle = {
display: 'block',
height: '30px',
lineHeight: '30px',
marginBottom: '15px',
};
//级别切换
const onRadio = (e: any) => {
setvalues(e.target.value);
// setCheckedKeys([]);
if (e.target.value == 2) {
//否则打开
settowAccountId(null);
}
};
return ( return (
<Spin spinning={loading}> <Spin spinning={loading}>
<div className="contop" style={{ padding: '12px 20px' }}> <div className="contop" style={{ padding: '12px 20px' }}>
...@@ -319,15 +397,12 @@ const Account = (props: any) => { ...@@ -319,15 +397,12 @@ const Account = (props: any) => {
name="contract" name="contract"
onFinish={onFinishContract} onFinish={onFinishContract}
> >
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}> <Descriptions column={{ xs: 1, sm: 1, md: 2, xl: 3 }}>
<Descriptions.Item> <Descriptions.Item>
<Form.Item name="tosUserName" label="Account ID" rules={AccountTip[0] as any}> <Form.Item name="tosUserName" label="Account ID" rules={AccountTip[0] as any}>
<Input placeholder="Login Account" className="input" /> <Input placeholder="Login Account" className="input" />
</Form.Item> </Form.Item>
</Descriptions.Item> </Descriptions.Item>
</Descriptions>
<Descriptions column={{ xs: 1, sm: 2, md: 3 }}>
<Descriptions.Item> <Descriptions.Item>
<Form.Item name="tosAccountName" label="Name" rules={AccountTip[1] as any}> <Form.Item name="tosAccountName" label="Name" rules={AccountTip[1] as any}>
<Input placeholder="Name Of Administrator" className="input" /> <Input placeholder="Name Of Administrator" className="input" />
...@@ -345,39 +420,36 @@ const Account = (props: any) => { ...@@ -345,39 +420,36 @@ const Account = (props: any) => {
</Descriptions.Item> </Descriptions.Item>
</Descriptions> </Descriptions>
<Form.Item name="community" label="Community">
<SelectCommunity
checklist={community}
list={
DataSave && DataSave.userLeaderCommunityNames
? DataSave.userLeaderCommunityNames
: CommunityList
}
/>
</Form.Item>
<div className="diy" style={{ marginBottom: '14px' }}> <div className="diy" style={{ marginBottom: '14px' }}>
<div className="label"> <div className="label">
<span className="title">Privilege Level:</span> <span className="title">Privilege Level:</span>
</div> </div>
<div className="label"> <div className="label">
<Tag <Radio.Group value={values} onChange={onRadio}>
icon={<CheckCircleOutlined />} <Radio style={radioStyle} disabled value={2}>
color="success" Two Level Administrator
style={{ verticalAlign: 'sub', fontSize: 14, padding: '4px 7px' }} </Radio>
> <Radio style={radioStyle} disabled value={3}>
{DataSave && DataSave.tosUserLevel == 2 Three Level Administrator
? 'Two Level Administrator ' </Radio>
: 'Three Level Administrator'} </Radio.Group>
</Tag>
{DataSave && DataSave.tosUserLevel == 3 ? ( {/* 选择挂靠的二级菜单 */}
<Tag {values === 3 && user.currentUser.userModel.tosUserLevel <= 1 ? (
icon={<RightOutlined />} <Select
color="processing" style={{ width: 260 }}
style={{ verticalAlign: 'sub', fontSize: 14, padding: '4px 7px' }} placeholder="Please select affiliated account"
disabled
defaultValue={DataSave.userLeader}
> >
Superiors:{DataSave.userLeaderAccountName} - {DataSave.userLeaderName} {DataSave ? (
</Tag> <Option key={DataSave.userLeader} value={DataSave.userLeader}>
{DataSave.userLeaderAccountName}-{DataSave.userLeaderName}
</Option>
) : (
''
)}
</Select>
) : ( ) : (
'' ''
)} )}
...@@ -399,7 +471,7 @@ const Account = (props: any) => { ...@@ -399,7 +471,7 @@ const Account = (props: any) => {
onSelect={onSelect} onSelect={onSelect}
selectedKeys={selectedKeys} selectedKeys={selectedKeys}
treeData={treeDataList} treeData={treeDataList}
disabled disabled={user && user.currentUser.userModel.tosUserLevel != 1 ? true : false}
/> />
</div> </div>
</div> </div>
...@@ -420,7 +492,6 @@ const Account = (props: any) => { ...@@ -420,7 +492,6 @@ const Account = (props: any) => {
const AccountProps = (state: any) => { const AccountProps = (state: any) => {
const { Data, DataSave, DataSaveDetail, Result, SubResult, Permission, Info } = state.Account; const { Data, DataSave, DataSaveDetail, Result, SubResult, Permission, Info } = state.Account;
const { CommunityList } = state.Init; // 小区列表
const loading = state.loading.models.Account || false; const loading = state.loading.models.Account || false;
const { user } = state; const { user } = state;
return { return {
...@@ -430,7 +501,6 @@ const AccountProps = (state: any) => { ...@@ -430,7 +501,6 @@ const AccountProps = (state: any) => {
Result, Result,
loading, loading,
Permission, Permission,
CommunityList,
user, // 获取当前账户信息 user, // 获取当前账户信息
SubResult, SubResult,
Info, Info,
......
...@@ -78,7 +78,7 @@ const CellLists = (props: any) => { ...@@ -78,7 +78,7 @@ const CellLists = (props: any) => {
useEffect(() => { useEffect(() => {
if (village == null) { if (village == null) {
const obj = { const obj = {
communityNameList: JSON.parse(localStorage.getItem('CommunityList') as any), communityNameList: Init.CommunityList,
pageNum: 1, pageNum: 1,
}; };
setTerm(obj); setTerm(obj);
...@@ -134,7 +134,7 @@ const CellLists = (props: any) => { ...@@ -134,7 +134,7 @@ const CellLists = (props: any) => {
<TitleSearch <TitleSearch
username={['label', 'Please Enter Administrator']} username={['label', 'Please Enter Administrator']}
community={'communityName'} community={'communityName'}
checklist={curString.communityNameList != null ? curString.communityNameList : null} checklist={Init ? Init.CommunityList : null}
onSubmit={CallBackTitleSearch} onSubmit={CallBackTitleSearch}
/> />
</div> </div>
......
...@@ -206,18 +206,17 @@ const FacilityBookings = (props: any) => { ...@@ -206,18 +206,17 @@ const FacilityBookings = (props: any) => {
QA(tmp); QA(tmp);
if (tab == 1) { if (tab == 1) {
RA(9, { RA(9, {
communityNameList: JSON.parse(localStorage.getItem('CommunityList') as any), communityNameList: CommunityList,
userToken: token, userToken: token,
status: curString.status, status: curString.status,
subscribeDate: curString.subscribeDate, subscribeDate: curString.subscribeDate,
pageNum: curString.curPage, pageNum: curString.curPage,
// communityNameList: curString.communityNameList,
}); });
} else { } else {
RA(8, { RA(8, {
userToken: token, userToken: token,
pageNum: curString.curPage2, pageNum: curString.curPage2,
communityNameList: JSON.parse(localStorage.getItem('CommunityList') as any), communityNameList: CommunityList,
}); });
} }
} }
...@@ -231,9 +230,7 @@ const FacilityBookings = (props: any) => { ...@@ -231,9 +230,7 @@ const FacilityBookings = (props: any) => {
pageNum: current, pageNum: current,
subscribeDate: curString.subscribeDate, subscribeDate: curString.subscribeDate,
status: curString.status, status: curString.status,
communityNameList: curString.communityNameList communityNameList: CommunityList,
? curString.communityNameList
: JSON.parse(localStorage.getItem('CommunityList') as any),
}); });
} else { } else {
var tmp = curString; var tmp = curString;
......
...@@ -12,23 +12,18 @@ import SelectCommunity from '@/components/SelectCommunity'; ...@@ -12,23 +12,18 @@ import SelectCommunity from '@/components/SelectCommunity';
const module = 'VisitorRecord'; const module = 'VisitorRecord';
const VisitorRecord = (props: any) => { const VisitorRecord = (props: any) => {
const { dispatch, Data, DataSave, loading } = props; const { dispatch, Data, DataSave, loading, CommunityList } = props;
// 新增搜索的时间 原来时间是时间戳格式 // 新增搜索的时间 原来时间是时间戳格式
useEffect(() => { useEffect(() => {
if (Data != null) { if (Data != null && CommunityList != null) {
Data.forEach((item: any) => { Data.forEach((item: any) => {
item.showTime = moment(item.updateTime).format('YYYY-MM-DD'); item.showTime = moment(item.updateTime).format('YYYY-MM-DD');
}); });
} else { } else {
RA( RA(26, { communityNames: CommunityList }, module, dispatch);
26,
{ communityNames: JSON.parse(localStorage.getItem('CommunityList') as any) },
module,
dispatch,
);
} }
}, [Data]); }, [Data, CommunityList]);
// 表头 // 表头
const columns: any = [ const columns: any = [
...@@ -261,8 +256,9 @@ const VisitorRecord = (props: any) => { ...@@ -261,8 +256,9 @@ const VisitorRecord = (props: any) => {
function map(state: any) { function map(state: any) {
const { Data, DataSave } = state[module]; const { Data, DataSave } = state[module];
const { CommunityList } = state['Init'];
const loading = state.loading.models.VisitorRecord; const loading = state.loading.models.VisitorRecord;
return { Data, DataSave, loading }; return { Data, DataSave, loading, CommunityList };
} }
export default connect(map)(VisitorRecord); export default connect(map)(VisitorRecord);
// 备注 // 备注
......
...@@ -12,23 +12,18 @@ import SelectCommunity from '@/components/SelectCommunity'; ...@@ -12,23 +12,18 @@ import SelectCommunity from '@/components/SelectCommunity';
const module = 'VisitorRecord'; const module = 'VisitorRecord';
const VisitorRecord = (props: any) => { const VisitorRecord = (props: any) => {
const { dispatch, Data, DataSave, loading } = props; const { dispatch, Data, DataSave, loading, CommunityList } = props;
// 新增搜索的时间 原来时间是时间戳格式 // 新增搜索的时间 原来时间是时间戳格式
useEffect(() => { useEffect(() => {
if (Data != null) { if (Data != null && CommunityList != null) {
Data.forEach((item: any) => { Data.forEach((item: any) => {
item.showTime = moment(item.updateTime).format('YYYY-MM-DD'); item.showTime = moment(item.updateTime).format('YYYY-MM-DD');
}); });
} else { } else {
RA( RA(26, { communityNames: CommunityList }, module, dispatch);
26,
{ communityNames: JSON.parse(localStorage.getItem('CommunityList') as any) },
module,
dispatch,
);
} }
}, [Data]); }, [Data, CommunityList]);
// 表头 // 表头
const columns: any = [ const columns: any = [
...@@ -261,8 +256,9 @@ const VisitorRecord = (props: any) => { ...@@ -261,8 +256,9 @@ const VisitorRecord = (props: any) => {
function map(state: any) { function map(state: any) {
const { Data, DataSave } = state[module]; const { Data, DataSave } = state[module];
const { CommunityList } = state['Init'];
const loading = state.loading.models.VisitorRecord; const loading = state.loading.models.VisitorRecord;
return { Data, DataSave, loading }; return { Data, DataSave, loading, CommunityList };
} }
export default connect(map)(VisitorRecord); export default connect(map)(VisitorRecord);
// 备注 // 备注
......
/* /*
* @Author: your name * @Author: your name
* @Date: 2020-11-19 16:54:53 * @Date: 2020-11-19 16:54:53
* @LastEditTime: 2020-12-11 17:23:30 * @LastEditTime: 2020-12-31 17:40:10
* @LastEditors: Please set LastEditors * @LastEditors: Please set LastEditors
* @Description: In User Settings Edit * @Description: In User Settings Edit
* @FilePath: \tostumi\src\services\Init.ts * @FilePath: \tostumi\src\services\Init.ts
...@@ -9,22 +9,25 @@ ...@@ -9,22 +9,25 @@
import request from '@/utils/request'; import request from '@/utils/request';
// 新加的根据权限 获取小区的接口 // 新加的根据权限 获取小区的接口
// export function tosCommunityget(values: any) {
// const userInfo = localStorage.getItem('userInfo') || '';
// const id = JSON.parse(userInfo).userModel.id;
// return request('/tos/tosCommunity/get/user', {
// method: 'POST',
// body: JSON.stringify(values),
// headers: { 'Content-Type': 'application/json' },
// data: { mangerId: id },
// });
// }
// 原来的获取小区接口
export function tosCommunityget(values: any) { export function tosCommunityget(values: any) {
const userInfo = localStorage.getItem('userInfo') || ''; const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id; const id = JSON.parse(userInfo).userModel.id;
return request('/tos/tosCommunity/get/user', { return request('/tos/tosCommunity/get', {
method: 'POST', method: 'POST',
body: JSON.stringify(values), body: JSON.stringify(values),
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
data: { mangerId: id }, data: { mangerId: id },
}); });
} }
// 原来的获取小区接口
// export function tosCommunityget(values: any) {
// return request('/tos/tosCommunity/get', {
// method: 'POST',
// body: JSON.stringify(values),
// headers: { 'Content-Type': 'application/json' },
// });
// }
/*
* @Author: your name
* @Date: 2020-11-19 20:34:18
* @LastEditTime: 2020-12-30 10:02:48
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: \tostumi\src\utils\params.ts
*/
export const validateMessages = { export const validateMessages = {
required: '*it is required!', required: '*it is required!',
types: { types: {
...@@ -29,8 +37,6 @@ export const requestList = [ ...@@ -29,8 +37,6 @@ export const requestList = [
['/tos/community/categories/subscribe/fuzzy/query', '9 预订列表模糊查询', {}], ['/tos/community/categories/subscribe/fuzzy/query', '9 预订列表模糊查询', {}],
['/tos/user/newCurrentUser', '10 后台用户信息', {}], ['/tos/user/newCurrentUser', '10 后台用户信息', {}],
['/tos/community/facilities/categories/subscribe', '11 预订', {}], ['/tos/community/facilities/categories/subscribe', '11 预订', {}],
// ['/tos/tosOwner/getAll', '12 业主查询', {}],
['/tos/owner/query/fuuzy', '12 业主查询', {}], ['/tos/owner/query/fuuzy', '12 业主查询', {}],
['/tos/tosOwner/getDetailAll', '13 业主查询详细', {}], ['/tos/tosOwner/getDetailAll', '13 业主查询详细', {}],
['/tos/tosOwner/save', '14 业主添加', {}], ['/tos/tosOwner/save', '14 业主添加', {}],
...@@ -38,7 +44,6 @@ export const requestList = [ ...@@ -38,7 +44,6 @@ export const requestList = [
['/tos/life/community/account/unit/del', '16 删除单元', {}], ['/tos/life/community/account/unit/del', '16 删除单元', {}],
['/tos/bookingService/edit', '17 编辑小区设施', {}], ['/tos/bookingService/edit', '17 编辑小区设施', {}],
['/tos/tosOwner/info/update', '18 编辑业主信息', {}], ['/tos/tosOwner/info/update', '18 编辑业主信息', {}],
['/tos/contract/list', '19 获取合同列表', {}], ['/tos/contract/list', '19 获取合同列表', {}],
['/tos/contract/detail/query', '20 获取合同列表详情', {}], ['/tos/contract/detail/query', '20 获取合同列表详情', {}],
['/tos/community/service/get/detail', '21 小区服务获取详情', {}], ['/tos/community/service/get/detail', '21 小区服务获取详情', {}],
...@@ -48,20 +53,7 @@ export const requestList = [ ...@@ -48,20 +53,7 @@ export const requestList = [
['/tos/tosCommunityNotic/get', '25 获取小区公告列表', {}], ['/tos/tosCommunityNotic/get', '25 获取小区公告列表', {}],
['/tos/tosVisitorRecord/get', '26 获取访客记录列表', {}], ['/tos/tosVisitorRecord/get', '26 获取访客记录列表', {}],
['/tos/contract/add', '27 合同新增和编辑', {}], ['/tos/contract/add', '27 合同新增和编辑', {}],
[ ['/tos/tosCommunityNotic/add', '28 新增小区公告接口', {}],
'/tos/tosCommunityNotic/add',
'28 新增小区公告接口',
{
noticTitle: 'Garden公告',
communityNum: '珠江丽景小区',
noticText: '今晚晚上停水4小时',
noticScope: '1',
noticStartTime: '2020-07-01 12:30:00',
noticEndTime: '2020-08-01 9:30:00',
file: ['A.jpg'],
},
],
// ['/tos/tosManageCommunity/save', '29 新建一个小区', {}],
['/tos/tosCommunity/save', '29 新建一个小区', {}], ['/tos/tosCommunity/save', '29 新建一个小区', {}],
['/tos/tosOrder/get', '30 获取订单详情', {}], ['/tos/tosOrder/get', '30 获取订单详情', {}],
['/tos/property/community/houseCard/query', '31 获取住户卡列表', {}], ['/tos/property/community/houseCard/query', '31 获取住户卡列表', {}],
...@@ -81,44 +73,11 @@ export const requestList = [ ...@@ -81,44 +73,11 @@ export const requestList = [
}, },
], ],
['/tos/community/service/get', '40 获取小区服务回复列表', {}], ['/tos/community/service/get', '40 获取小区服务回复列表', {}],
[ ['/tos/users/save', '41 添加后台账号', {}],
'/tos/users/save', ['/tos/account/permission/savePermission', '42 添加后台权限', {}],
'41 添加后台账号',
{
id: 'null',
oneself: 0,
tosUserEmail: 'sales@huahui.com',
tosUserName: '小赵2',
tosUserPhone: '020-8888-4444',
tosUserPwd: '123456',
tosUserToCompany: '1',
tosUserServiceCell: '',
tosuserLevel: 1,
userStatus: 1,
},
],
[
'/tos/account/permission/savePermission',
'42 添加后台权限',
{
userName: '小赵2',
userPassword: '123456',
permissionArray: ['2', '1', '3', '4'],
},
],
['/tos/tosServiceScope/get', '43 获取服务范围'], ['/tos/tosServiceScope/get', '43 获取服务范围'],
['/tos/tosServiceScope/save', '44 添加服务范围'], ['/tos/tosServiceScope/save', '44 添加服务范围'],
[ ['/tos/user/getAllInfrom', '45 获取后台列表', {}],
'/tos/user/getAllInfrom',
'45 获取后台列表',
{
id: '',
moment: [],
name: '',
leaderID: '1',
userPhone: '',
},
],
['/tos/tosServiceProvider/get', '46 获取服务商', {}], ['/tos/tosServiceProvider/get', '46 获取服务商', {}],
['/tos/fileAndImage/preview', '47 获取附件地址', {}], ['/tos/fileAndImage/preview', '47 获取附件地址', {}],
['/tos/tosCommunity/get/list', '48 修改获取小区列表', {}], ['/tos/tosCommunity/get/list', '48 修改获取小区列表', {}],
......
import React, { useState, useEffect,useRef} from 'react';
import { Input ,Tabs,Table,Space, Button} from 'antd';
const { TabPane } = Tabs;
import {connect,history} from 'umi';
import { RA } from '@/utils/method';
const module="XXX"
const XXX = (props:any) => {
const { dispatch, Data } = props;
const formRef = useRef(null)
return (
<div style={{ width: "100%", minWidth: 1020, padding: 34, backgroundColor: "#ffffff" }}>
</div>
);
};
function map(state:any) {
const { Data} = state[module]
return { Data}
}
export default connect(map)(XXX);
\ No newline at end of file
import * as service from '../../services/tos';
import { message } from 'antd';
import { Link, useIntl, connect, Dispatch, history } from 'umi';
import { routerRedux } from 'dva/router'
import { printf } from '@/utils/log';
export default {
namespace: 'XXX',
state: {
Data: null,
Result: null,
DataSave: null,
DataSaveDetail:null,
},
reducers: {
returnPage(state, { Data}) {
return { ...state, Data };
},
returnResult(state, { Result}) {
return { ...state, Result};
},
returnDataSave(state, { DataSave }) {
return {...state,DataSave}
},
returnDataSaveDetail(state, { DataSaveDetail }) {
return {...state,DataSaveDetail}
},
},
effects: {
//标准请求
*RA({ playload }, { call, put }) {
const resp = yield call(service.RA, playload);
console.log(resp)
if (resp.code == 500||resp.error_code!="0000") {
}
if (resp.error_code != "0000") {
printf(playload, resp)
}
else {
switch (playload.index) {
case 24: {
let Data = resp.data;
yield put({ type: 'returnPage', Data });
} break;
}
}
},
*ResultClear({ }, { put }) {
var tmp=null
yield put({type: 'returnResult', tmp} )
},
*SA({ playload }, { call, put }) {
var DataSave = playload
yield put({type: 'returnDataSave', DataSave} )
},
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment