Commit 71ee201d authored by cellee's avatar cellee

cookies消失,从local获取 id

Signed-off-by: cellee's avatarcellee <893264950@qq.com>
parent 40f6f5e8
import React from 'react';
import { PageLoading } from '@ant-design/pro-layout';
import { Redirect, connect, ConnectProps, StateType, history, Link } from 'umi';
import { stringify } from 'querystring';
import { ConnectState } from '@/models/connect';
import { CurrentUser } from '@/models/user';
import { getCookie } from '@/utils/method';
import { message } from 'antd';
import moment from 'moment';
import { logOut } from '@/utils/log';
interface SecurityLayoutProps extends ConnectProps {
loading?: boolean;
currentUser?: CurrentUser;
login?: StateType;
}
interface SecurityLayoutState {
token: String;
isReady: boolean;
}
class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayoutState> {
state: SecurityLayoutState = {
isReady: false,
token: '',
};
render() {
const { children, loading } = this.props;
// You can replace it to your authentication rule (such as check token exists)
// 你可以把它替换成你自己的登录认证规则(比如判断 token 是否存在)
const perList = [
{ key: '1', path: '/UserManagement/LIFEUserManagement' },
{ key: '18', path: '/UserManagement/ServiceProviderManagement' },
{ key: '15', path: '/PropertyManagement' },
{ key: '17', path: '/CommercialService/CommunityMaintenance' },
{ key: '20', path: '/CommercialService/OwnerComplaints' },
{ key: '23', path: '/CommercialService/ProblemFeedback' },
{ key: '26', path: '/CommercialService/RenovationApplication' },
{ key: '29', path: '/CommercialService/AccessCardApplication' },
{ key: '33', path: '/CommercialService/ReportOnline' },
{ key: '36', path: '/CommercialService/ShelfLifeService' },
// cellee 负责部分
// 合同
{ key: '39', path: '/ContractManagement' },
{ key: '40', path: '/ContractManagement/Detail' },
{ key: '41', path: '/ContractManagement/Add' },
{ key: '42', path: '/ContractManagement/Edit' },
// 小区
{ path: '/CommunityManagement/CellList', title: '小区列表', key: '44' },
{ path: '/CommunityManagement/CellList/Detail', title: '查看小区', key: '44' },
{ path: '/CommunityManagement/CellList/Add', title: '编辑小区', key: '45' },
{ path: '/CommunityManagement/CellList/Add', title: '添加小区', key: '46' },
// 小区公告
{ path: '/CommunityManagement/CommunityAnnouncement', title: '小区公告', key: '48' },
{ path: '/CommunityManagement/CommunityAnnouncement/Detail', title: '查看公告', key: '49' },
{ path: '/CommunityManagement/CommunityAnnouncement/Edit', title: '编辑公告', key: '50' },
{ path: '/CommunityManagement/CommunityAnnouncement/Add', title: '添加公告', key: '51' },
// 小区设施
{ path: '/CommunityManagement/FacilityBookings', title: '小区设施', key: '52' },
{ path: '/CommunityManagement/FacilityBookings/Detail', title: '查看预约设施', key: '53' },
{ path: '/CommunityManagement/FacilityBookings/Booking', title: '添加预约设施', key: '54' },
{
path: '/CommunityManagement/FacilityBookings/FacilityApply',
title: '添加预约设施',
key: '54',
},
{
path: '/CommunityManagement/FacilityBookings/FacilityDetail',
title: '查看设施',
key: '57',
},
{ path: '/CommunityManagement/FacilityBookings/FacilityEdit', title: '编辑设施', key: '58' },
{ path: '/CommunityManagement/FacilityBookings/Adding', title: '添加设施', key: '59' },
// 访客记录
{ path: '/CommunityManagement/VisitorRecord', title: '访客记录', key: '60' },
// 账号管理
{ path: '/AccountManagement/account', title: '账号管理', key: '62' },
{ path: '/AccountManagement/account/Detail', title: '查看账号', key: '63' },
{ path: '/AccountManagement/account/edit', title: '编辑账号', key: '64' },
{ path: '/AccountManagement/account/Add', title: '添加账号', key: '65' },
];
// 用户重新打开需要重新登录
let time = localStorage.getItem('loginTime');
const tokenLogin = time ? JSON.parse(time) : '';
if (history.location.pathname == '/') {
// const isLogin = currentUser && currentUser.name;//isLogin为关键点
var isLogin = false;
if (getCookie('token').length != 0) {
isLogin = true;
}
const queryString = stringify({
redirect: window.location.href,
});
if (!isLogin && loading) {
return <PageLoading />;
}
if (!isLogin && window.location.pathname !== '/user/login') {
return <Redirect to={`/user/login?${queryString}`} />;
}
return children;
} else if (tokenLogin && moment().diff(moment(tokenLogin), 'minutes') < 30) {
// 刷新时间
localStorage.setItem('loginTime', JSON.stringify(moment().format('YYYY-MM-DD HH:mm:ss')));
// 在判断权限
const permission = JSON.parse(localStorage.getItem('permission') || '[]');
let perObj = perList.filter((obj) => {
return obj.path === location.pathname;
});
if (perObj.length !== 0) {
if (permission.indexOf(perObj[0].key) < 0) {
history.push('/403');
}
}
return children;
} else {
// 退出登录
message.warning('Expired login !');
setTimeout(function () {
logOut();
}, 1000);
return false;
}
}
}
export default connect(({ user, loading, login }: ConnectState) => ({
currentUser: user.currentUser,
loading: loading.models.user,
login: login,
}))(SecurityLayout);
...@@ -87,8 +87,8 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout ...@@ -87,8 +87,8 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout
let time = localStorage.getItem('loginTime'); let time = localStorage.getItem('loginTime');
const tokenLogin = time ? JSON.parse(time) : ''; const tokenLogin = time ? JSON.parse(time) : '';
// 登录
if (history.location.pathname == '/') { if (history.location.pathname == '/') {
// const isLogin = currentUser && currentUser.name;//isLogin为关键点
var isLogin = false; var isLogin = false;
if (getCookie('token').length != 0) { if (getCookie('token').length != 0) {
isLogin = true; isLogin = true;
...@@ -102,32 +102,29 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout ...@@ -102,32 +102,29 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout
if (!isLogin && window.location.pathname !== '/user/login') { if (!isLogin && window.location.pathname !== '/user/login') {
return <Redirect to={`/user/login?${queryString}`} />; return <Redirect to={`/user/login?${queryString}`} />;
} }
return children;
} else if (tokenLogin && moment().diff(moment(tokenLogin), 'minutes') < 30) { } else if (tokenLogin && moment().diff(moment(tokenLogin), 'minutes') < 30) {
// 在判断权限
const permission = JSON.parse(localStorage.getItem('permission') || '[]');
let perObj = perList.filter((obj) => {
return obj.path === location.pathname;
});
if (perObj.length !== 0) {
if (permission.indexOf(perObj[0].key) < 0) {
history.push('/403');
}
}
// 刷新时间 // 刷新时间
localStorage.setItem('loginTime', JSON.stringify(moment().format('YYYY-MM-DD HH:mm:ss'))); localStorage.setItem('loginTime', JSON.stringify(moment().format('YYYY-MM-DD HH:mm:ss')));
} else { } else if (tokenLogin && moment().diff(moment(tokenLogin), 'minutes') >= 30) {
// 退出登录 // 退出登录
message.warning('Expired login !'); message.warning('Expired login !');
setTimeout(function () { setTimeout(function () {
logOut(); logOut();
}, 1000); }, 1000);
return false;
} }
// 在判断权限
const permission = JSON.parse(localStorage.getItem('permission') || '[]');
let perObj = perList.filter((obj) => {
return obj.path === location.pathname;
});
if (perObj.length !== 0) {
if (permission.indexOf(perObj[0].key) < 0) {
history.push('/403');
}
}
return children; return children;
} }
} }
......
...@@ -78,6 +78,8 @@ const Account = (props: any) => { ...@@ -78,6 +78,8 @@ const Account = (props: any) => {
// 保存提交 // 保存提交
const onFinishContract = async (value: any) => { const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
if ( if (
value.tosAccountName.length <= 2 && value.tosAccountName.length <= 2 &&
value.tosUserPhone.length != 8 && value.tosUserPhone.length != 8 &&
...@@ -104,7 +106,7 @@ const Account = (props: any) => { ...@@ -104,7 +106,7 @@ const Account = (props: any) => {
value.tosUserEmail = value.tosUserName; // 邮箱就是账号 value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别 value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号 value.creatorName = getCookie('name'); //新建者账号
value.creatorId = getCookie('id'); //新建者ID value.creatorId = id; //新建者ID
delete value.community; delete value.community;
// console.log(checkedKeys); // console.log(checkedKeys);
......
...@@ -102,6 +102,8 @@ const Account = (props: any) => { ...@@ -102,6 +102,8 @@ const Account = (props: any) => {
// 保存提交 // 保存提交
const onFinishContract = async (value: any) => { const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
// console.log(value); // console.log(value);
if (checkedKeys.length == 0) { if (checkedKeys.length == 0) {
// 权限 // 权限
...@@ -120,7 +122,7 @@ const Account = (props: any) => { ...@@ -120,7 +122,7 @@ const Account = (props: any) => {
value.tosUserEmail = value.tosUserName; // 邮箱就是账号 value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别 value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号 value.creatorName = getCookie('name'); //新建者账号
value.creatorId = getCookie('id'); //新建者ID value.creatorId = id; //新建者ID
delete value.community; delete value.community;
// console.log(value); // console.log(value);
......
...@@ -116,7 +116,8 @@ const Account = (props: any) => { ...@@ -116,7 +116,8 @@ const Account = (props: any) => {
// 保存提交 // 保存提交
const onFinishContract = async (value: any) => { const onFinishContract = async (value: any) => {
// console.log(value); const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
if ( if (
value.tosAccountName.length <= 2 && value.tosAccountName.length <= 2 &&
value.tosUserPhone.length != 8 && value.tosUserPhone.length != 8 &&
...@@ -142,7 +143,7 @@ const Account = (props: any) => { ...@@ -142,7 +143,7 @@ const Account = (props: any) => {
value.tosUserEmail = value.tosUserName; // 邮箱就是账号 value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别 value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号 value.creatorName = getCookie('name'); //新建者账号
value.creatorId = getCookie('id'); //新建者ID value.creatorId = id; //新建者ID
delete value.community; delete value.community;
value.id = DataSave.id; value.id = DataSave.id;
......
...@@ -56,11 +56,14 @@ const CardDetail = (props: any) => { ...@@ -56,11 +56,14 @@ const CardDetail = (props: any) => {
return; return;
} }
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
let tmp = { let tmp = {
communityId: listData.communityId, communityId: listData.communityId,
id: listData.id, id: listData.id,
ownerId: listData.ownerId, ownerId: listData.ownerId,
replyId: getCookie('id'), replyId: id,
applyStatus: values.applyStatus, applyStatus: values.applyStatus,
replyContent: replyContent:
listData.apply_status !== 0 && values.applyStatus === '3' listData.apply_status !== 0 && values.applyStatus === '3'
......
...@@ -83,7 +83,9 @@ const CellLists = (props: any) => { ...@@ -83,7 +83,9 @@ const CellLists = (props: any) => {
}; };
setTerm(obj); // 存进搜索条件 setTerm(obj); // 存进搜索条件
} else { } else {
RA(55, { id: getCookie('id') }, module, dispatch); const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
RA(55, { id: id }, module, dispatch);
} }
}, [Data]); }, [Data]);
......
...@@ -112,6 +112,9 @@ const Add = (props: any) => { ...@@ -112,6 +112,9 @@ const Add = (props: any) => {
// 提交 // 提交
const onFinish = (values: any) => { const onFinish = (values: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
if (values.community.value.length == 0) { if (values.community.value.length == 0) {
message.error('Please select community!'); message.error('Please select community!');
return false; return false;
...@@ -120,7 +123,7 @@ const Add = (props: any) => { ...@@ -120,7 +123,7 @@ const Add = (props: any) => {
if (DataSave != null) { if (DataSave != null) {
tmp.id = DataSave.id; // 如果是修改传递的 修改ID tmp.id = DataSave.id; // 如果是修改传递的 修改ID
} }
tmp.creatorId = getCookie('id'); // 管理员 ID tmp.creatorId = id; // 管理员 ID
tmp.communityNum = values.community.value; tmp.communityNum = values.community.value;
tmp.noticScope = '' + values.community.index; tmp.noticScope = '' + values.community.index;
// 文件名 如果动了。 新增删除 就传新的, 否则传旧的 // 文件名 如果动了。 新增删除 就传新的, 否则传旧的
......
...@@ -34,31 +34,21 @@ const VisitorRecord = (props: any) => { ...@@ -34,31 +34,21 @@ const VisitorRecord = (props: any) => {
// 表头 // 表头
const columns: any = [ const columns: any = [
{ title: 'Invitees Name', dataIndex: 'inviterName' }, { title: 'Invitee', dataIndex: 'inviterName' },
{ title: 'Visitor Name', dataIndex: 'visitorsName' }, { title: 'Visitor', dataIndex: 'visitorsName' },
{ title: 'Security Guard', dataIndex: 'securityGuardName' }, { title: 'Security Guard', dataIndex: 'securityGuardName' },
{ title: 'Number Plate', dataIndex: 'numberPlate' }, { title: 'Car Number', dataIndex: 'numberPlate' },
{ title: 'Telephone', dataIndex: 'inviterPhone' },
// 隐藏的搜索框 // 隐藏的搜索框
{ {
title: 'Visitor Time', title: 'Visiting Time',
dataIndex: 'updateTime', dataIndex: 'updateTime',
valueType: 'date', valueType: 'date',
render: (text: any, record: any) => {
if (record.linkStatus == 1) {
return text;
} else {
return (
<>
{text} <Tag color="red">Temporary</Tag>
</>
);
}
},
}, },
{ title: 'Community', dataIndex: 'visitorCommunity' }, { title: 'Community', dataIndex: 'visitorCommunity' },
// { title: 'Unit', dataIndex: 'inviterAddress' }, // { title: 'Unit', dataIndex: 'inviterAddress' },
{ {
title: 'Unit', title: 'Unit No',
dataIndex: 'inviterAddress', dataIndex: 'inviterAddress',
render: (text: any) => <span>{text}</span>, render: (text: any) => <span>{text}</span>,
}, },
......
...@@ -34,31 +34,21 @@ const VisitorRecord = (props: any) => { ...@@ -34,31 +34,21 @@ const VisitorRecord = (props: any) => {
// 表头 // 表头
const columns: any = [ const columns: any = [
{ title: 'Invitees Name', dataIndex: 'inviterName' }, { title: 'Invitee', dataIndex: 'inviterName' },
{ title: 'Visitor Name', dataIndex: 'visitorsName' }, { title: 'Visitor', dataIndex: 'visitorsName' },
{ title: 'Security Guard', dataIndex: 'securityGuardName' }, { title: 'Security Guard', dataIndex: 'securityGuardName' },
{ title: 'Number Plate', dataIndex: 'numberPlate' }, { title: 'Car Number', dataIndex: 'numberPlate' },
{ title: 'Telephone', dataIndex: 'inviterPhone' },
// 隐藏的搜索框 // 隐藏的搜索框
{ {
title: 'Visitor Time', title: 'Visiting Time',
dataIndex: 'updateTime', dataIndex: 'updateTime',
valueType: 'date', valueType: 'date',
render: (text: any, record: any) => {
if (record.linkStatus == 1) {
return text;
} else {
return (
<>
{text} <Tag color="red">Temporary</Tag>
</>
);
}
},
}, },
{ title: 'Community', dataIndex: 'visitorCommunity' }, { title: 'Community', dataIndex: 'visitorCommunity' },
// { title: 'Unit', dataIndex: 'inviterAddress' }, // { title: 'Unit', dataIndex: 'inviterAddress' },
{ {
title: 'Unit', title: 'Unit No',
dataIndex: 'inviterAddress', dataIndex: 'inviterAddress',
render: (text: any) => <span>{text}</span>, render: (text: any) => <span>{text}</span>,
}, },
......
...@@ -49,6 +49,9 @@ const Users = (props: any) => { ...@@ -49,6 +49,9 @@ const Users = (props: any) => {
const [fileUploading, setFileUploading] = useState(false); const [fileUploading, setFileUploading] = useState(false);
const [compent, setCompent] = useState({ loading: false, fileUploading: false }); const [compent, setCompent] = useState({ loading: false, fileUploading: false });
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
// 表格模块 // 表格模块
const columns = [ const columns = [
{ title: username, dataIndex: 'owerName' }, { title: username, dataIndex: 'owerName' },
...@@ -93,7 +96,7 @@ const Users = (props: any) => { ...@@ -93,7 +96,7 @@ const Users = (props: any) => {
name: 'file', name: 'file',
action: () => { action: () => {
// return 'http://47.74.233.180:8651/tos/excel/upload?userId=' + getCookie('id'); // return 'http://47.74.233.180:8651/tos/excel/upload?userId=' + getCookie('id');
return 'http://192.168.1.28:8651/tos/excel/upload?userId=' + getCookie('id'); return 'http://192.168.1.28:8651/tos/excel/upload?userId=' + id;
}, },
beforeUpload: (file: any) => { beforeUpload: (file: any) => {
if (file.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') { if (file.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
......
/* /*
* @Author: your name * @Author: your name
* @Date: 2020-11-19 16:54:53 * @Date: 2020-11-19 16:54:53
* @LastEditTime: 2020-12-10 10:09:27 * @LastEditTime: 2020-12-11 17:23:30
* @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
*/ */
import request from '@/utils/request'; import request from '@/utils/request';
import { getCookie } from '@/utils/method';
// 新加的根据权限 获取小区的接口 // 新加的根据权限 获取小区的接口
export function tosCommunityget(values: any) { export function tosCommunityget(values: any) {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
return request('/tos/tosCommunity/get/user', { return request('/tos/tosCommunity/get/user', {
method: 'POST', method: 'POST',
body: JSON.stringify(values), body: JSON.stringify(values),
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
data: { id: getCookie('id') }, data: { mangerId: id },
}); });
} }
......
...@@ -106,13 +106,13 @@ function requestAuto(url: string, values: any) { ...@@ -106,13 +106,13 @@ function requestAuto(url: string, values: any) {
} }
export function RA(playload: any) { export function RA(playload: any) {
// console.log('playload参数===========================================', playload);
var url = requestList[playload.index][0].toString(); var url = requestList[playload.index][0].toString();
// console.log(playload.index + '》【发送请求】' + url + ' ' + requestList[playload.index][1]);
// console.log('参数如下:'); // 新增ID
// console.log(playload.body); const userInfo = localStorage.getItem('userInfo') || '';
// console.log(JSON.stringify(playload.body)) const id = { mangerId: JSON.parse(userInfo).userModel.id };
return requestAuto(url, playload.body); let newData = { ...playload.body, ...id };
return requestAuto(url, newData);
} }
//新增小区公告接口文件上传 http://47.74.233.180:8651/tos/image/upload imageType 参数值为 tosNotice //新增小区公告接口文件上传 http://47.74.233.180:8651/tos/image/upload imageType 参数值为 tosNotice
/* /*
* @Author: your name * @Author: your name
* @Date: 2020-11-19 16:54:53 * @Date: 2020-11-19 16:54:53
* @LastEditTime: 2020-12-10 17:29:08 * @LastEditTime: 2020-12-11 14:22:27
* @LastEditors: Please set LastEditors * @LastEditors: Please set LastEditors
* @Description: In User Settings Edit * @Description: In User Settings Edit
* @FilePath: \tostumi\src\utils\log.ts * @FilePath: \tostumi\src\utils\log.ts
......
...@@ -49,7 +49,11 @@ export const getCookie = (key: string) => { ...@@ -49,7 +49,11 @@ export const getCookie = (key: string) => {
}; };
export const setCookie = (key: string, value: string) => { export const setCookie = (key: string, value: string) => {
document.cookie = key + '=' + value + '; '; // cookie 设置时间,防止刷新就丢失
var d = new Date();
d.setTime(d.getTime() + 1 * 24 * 60 * 60 * 1000);
var expires = 'expires=' + d.toUTCString();
document.cookie = key + '=' + value + '; ' + expires;
}; };
export const RA = (index: number, values: object, module: string, dispatch: any) => { export const RA = (index: number, values: object, module: string, dispatch: any) => {
......
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