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
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;
......@@ -102,32 +102,29 @@ class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayout
if (!isLogin && window.location.pathname !== '/user/login') {
return <Redirect to={`/user/login?${queryString}`} />;
}
return children;
} 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')));
} else {
} else if (tokenLogin && moment().diff(moment(tokenLogin), 'minutes') >= 30) {
// 退出登录
message.warning('Expired login !');
setTimeout(function () {
logOut();
}, 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;
}
}
......
......@@ -78,6 +78,8 @@ const Account = (props: 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 &&
......@@ -104,7 +106,7 @@ const Account = (props: any) => {
value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号
value.creatorId = getCookie('id'); //新建者ID
value.creatorId = id; //新建者ID
delete value.community;
// console.log(checkedKeys);
......
......@@ -102,6 +102,8 @@ const Account = (props: any) => {
// 保存提交
const onFinishContract = async (value: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
// console.log(value);
if (checkedKeys.length == 0) {
// 权限
......@@ -120,7 +122,7 @@ const Account = (props: any) => {
value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号
value.creatorId = getCookie('id'); //新建者ID
value.creatorId = id; //新建者ID
delete value.community;
// console.log(value);
......
......@@ -116,7 +116,8 @@ const Account = (props: any) => {
// 保存提交
const onFinishContract = async (value: any) => {
// console.log(value);
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
if (
value.tosAccountName.length <= 2 &&
value.tosUserPhone.length != 8 &&
......@@ -142,7 +143,7 @@ const Account = (props: any) => {
value.tosUserEmail = value.tosUserName; // 邮箱就是账号
value.tosUserLevel = values; //级别
value.creatorName = getCookie('name'); //新建者账号
value.creatorId = getCookie('id'); //新建者ID
value.creatorId = id; //新建者ID
delete value.community;
value.id = DataSave.id;
......
......@@ -56,11 +56,14 @@ const CardDetail = (props: any) => {
return;
}
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
let tmp = {
communityId: listData.communityId,
id: listData.id,
ownerId: listData.ownerId,
replyId: getCookie('id'),
replyId: id,
applyStatus: values.applyStatus,
replyContent:
listData.apply_status !== 0 && values.applyStatus === '3'
......
......@@ -83,7 +83,9 @@ const CellLists = (props: any) => {
};
setTerm(obj); // 存进搜索条件
} 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]);
......
......@@ -112,6 +112,9 @@ const Add = (props: any) => {
// 提交
const onFinish = (values: any) => {
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
if (values.community.value.length == 0) {
message.error('Please select community!');
return false;
......@@ -120,7 +123,7 @@ const Add = (props: any) => {
if (DataSave != null) {
tmp.id = DataSave.id; // 如果是修改传递的 修改ID
}
tmp.creatorId = getCookie('id'); // 管理员 ID
tmp.creatorId = id; // 管理员 ID
tmp.communityNum = values.community.value;
tmp.noticScope = '' + values.community.index;
// 文件名 如果动了。 新增删除 就传新的, 否则传旧的
......
......@@ -34,31 +34,21 @@ const VisitorRecord = (props: any) => {
// 表头
const columns: any = [
{ title: 'Invitees Name', dataIndex: 'inviterName' },
{ title: 'Visitor Name', dataIndex: 'visitorsName' },
{ title: 'Invitee', dataIndex: 'inviterName' },
{ title: 'Visitor', dataIndex: 'visitorsName' },
{ 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',
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: 'Unit', dataIndex: 'inviterAddress' },
{
title: 'Unit',
title: 'Unit No',
dataIndex: 'inviterAddress',
render: (text: any) => <span>{text}</span>,
},
......
......@@ -34,31 +34,21 @@ const VisitorRecord = (props: any) => {
// 表头
const columns: any = [
{ title: 'Invitees Name', dataIndex: 'inviterName' },
{ title: 'Visitor Name', dataIndex: 'visitorsName' },
{ title: 'Invitee', dataIndex: 'inviterName' },
{ title: 'Visitor', dataIndex: 'visitorsName' },
{ 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',
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: 'Unit', dataIndex: 'inviterAddress' },
{
title: 'Unit',
title: 'Unit No',
dataIndex: 'inviterAddress',
render: (text: any) => <span>{text}</span>,
},
......
......@@ -49,6 +49,9 @@ const Users = (props: any) => {
const [fileUploading, setFileUploading] = useState(false);
const [compent, setCompent] = useState({ loading: false, fileUploading: false });
const userInfo = localStorage.getItem('userInfo') || '';
const id = JSON.parse(userInfo).userModel.id;
// 表格模块
const columns = [
{ title: username, dataIndex: 'owerName' },
......@@ -93,7 +96,7 @@ const Users = (props: any) => {
name: 'file',
action: () => {
// 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) => {
if (file.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
......
/*
* @Author: your name
* @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
* @Description: In User Settings Edit
* @FilePath: \tostumi\src\services\Init.ts
*/
import request from '@/utils/request';
import { getCookie } from '@/utils/method';
// 新加的根据权限 获取小区的接口
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: { id: getCookie('id') },
data: { mangerId: id },
});
}
......
......@@ -106,13 +106,13 @@ function requestAuto(url: string, values: any) {
}
export function RA(playload: any) {
// console.log('playload参数===========================================', playload);
var url = requestList[playload.index][0].toString();
// console.log(playload.index + '》【发送请求】' + url + ' ' + requestList[playload.index][1]);
// console.log('参数如下:');
// console.log(playload.body);
// console.log(JSON.stringify(playload.body))
return requestAuto(url, playload.body);
// 新增ID
const userInfo = localStorage.getItem('userInfo') || '';
const id = { mangerId: JSON.parse(userInfo).userModel.id };
let newData = { ...playload.body, ...id };
return requestAuto(url, newData);
}
//新增小区公告接口文件上传 http://47.74.233.180:8651/tos/image/upload imageType 参数值为 tosNotice
/*
* @Author: your name
* @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
* @Description: In User Settings Edit
* @FilePath: \tostumi\src\utils\log.ts
......
......@@ -49,7 +49,11 @@ export const getCookie = (key: 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) => {
......
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