Commit 27fd8140 by zhangleyuan

feat:处理页面401和403的状况

parent 613f0595
......@@ -2,7 +2,7 @@
* @Author: 吴文洁
* @Date: 2020-08-31 09:34:31
* @LastEditors: zhangleyuan
* @LastEditTime: 2020-12-22 15:23:36
* @LastEditTime: 2020-12-22 15:24:03
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -23,9 +23,13 @@ interface FetchParams {
interface FetchOptions {
requestType: string // 请求类型 form为表单类型 json为json类型,默认json类型
}
interface HeadersType{
storeId?:any,
storeUserId?:any,
userId?:any,
token?:any
}
class Axios {
static post(
method: string,
url: string,
......@@ -34,15 +38,24 @@ class Axios {
): Promise<any> {
const _url = `${url}?storeId=${User.getStoreId()}&token=${User.getToken()}&storeUserId=${User.getStoreUserId()}&userId=${User.getUserId()}`;
return new Promise((resolve, reject) => {
let headerObject:HeadersType={};
if(User.getStoreId()){
headerObject.storeId = User.getStoreId();
}
if(User.getStoreUserId()){
headerObject.storeUserId = User.getStoreUserId();
}
if(User.getUserId()){
headerObject.userId = User.getUserId();
}
if(User.getToken()){
headerObject.token = User.getToken();
}
const instance: AxiosInstance = axios.create({
timeout: TIME_OUT,
responseType: 'json',
headers: {
storeId: User.getStoreId(),
storeUserId: User.getStoreUserId(),
userId: User.getUserId(),
token: User.getToken(),
...headerObject,
product: "xmCloudClass",
'Content-Type': options.requestType === 'form' ? 'application/x-www-form-urlencoded' : 'application/json; charset=UTF-8',
}
......@@ -78,17 +91,23 @@ class Axios {
message.error(ResMessage || resultMsg);
return Promise.reject(response.data);
}, (error): AxiosPromise => {
console.log("error222",error)
// 403退出登录
if(error.message.indexOf("403")){
const requestStatus = error.request.status
switch (requestStatus){
case 401:
User.removeUserId();
User.removeToken();
message.error('请登录');
window.RCHistory.replace('/login');
break;
case 403:
message.error('暂无查看权限');
window.RCHistory.replace('/login');
return Promise.reject();
break;
default:
message.error(error.message);
break;
}
// if(error.request.status===403 || error.request.status===401){
// window.RCHistory.replace('/login');
// }else{
// }
message.error(error.message)
return Promise.reject(error.message);
});
......
......@@ -103,6 +103,7 @@ function IdentificationModal(props: IdentificationModalProps) {
确认
</Button>
]}
maskClosable={false}
>
<div className="desc">为了你的账户安全,请验证身份。验证成功后进行下一步操作</div>
......
/*
* @Author: 吴文洁
* @Date: 2019-07-10 10:30:49
* @LastEditors: wufan
* @LastEditTime: 2020-12-09 16:50:18
* @LastEditors: zhangleyuan
* @LastEditTime: 2020-12-22 15:24:20
* @Description:
*/
import React, { useContext, useEffect, useState } from 'react';
......@@ -33,6 +33,7 @@ const App: React.FC = (props: any) => {
}
function getStoreGroupAndStoreList() {
BaseService.getUserStore({ userId }).then((res) => {
const { storeGroupVOS = [], storeVOS = [] } = res.result;
......
......@@ -36,6 +36,7 @@ function CourseCatalogPage() {
const [secondCatalogModalVisible,setSecondCatalogModalVisible] = useState(false);
const [secondCatalogModalType,setSecondCatalogModalType] = useState('');
const [parentCatalogId,setParentCatalogId] = useState('');
const [parentCatalogName,setParentCatalogName] = useState('');
const [choosedItem, setChooseItem] = useState({});
useEffect(() => {
getCourseCatalogList();
......@@ -49,6 +50,7 @@ function CourseCatalogPage() {
function addSecondCatalog(record:any){
setChooseItem({});
setParentCatalogId(record.id);
setParentCatalogName(record.categoryName);
setSecondCatalogModalVisible(true);
setSecondCatalogModalType('add');
}
......@@ -150,6 +152,7 @@ function CourseCatalogPage() {
setCatalogModalVisible(true);
}else{
setParentCatalogId(record.parentId);
setParentCatalogName(record.parentName);
setSecondCatalogModalType('edit');
setSecondCatalogModalVisible(true);
}
......@@ -204,7 +207,7 @@ function CourseCatalogPage() {
catalogModalVisible && <CatalogAddOrEditModal modalType={catalogModalType} onClose={()=>{setCatalogModalVisible(false)}} refreshCatalogList={getCourseCatalogList} choosedItem={choosedItem}/>
}
{
secondCatalogModalVisible && <SecondCatalogAddOrEditModal modalType={secondCatalogModalType} parentId={parentCatalogId} onClose={()=>{setSecondCatalogModalVisible(false)}} choosedItem={choosedItem} refreshCatalogList={getCourseCatalogList} />
secondCatalogModalVisible && <SecondCatalogAddOrEditModal modalType={secondCatalogModalType} parentId={parentCatalogId} parentName={parentCatalogName} onClose={()=>{setSecondCatalogModalVisible(false)}} choosedItem={choosedItem} refreshCatalogList={getCourseCatalogList} />
}
</div>
</div>
......
/*
* @Author: wufan
* @Date: 2020-11-27 16:21:49
* @LastEditors: wufan
* @LastEditTime: 2020-12-09 20:01:24
* @LastEditors: zhangleyuan
* @LastEditTime: 2020-12-10 18:03:06
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
......@@ -22,28 +22,43 @@ interface SecondCatalogAddOrEditModalProps {
parentId:string;
choosedItem:any;
refreshCatalogList:any;
parentName:string
}
function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) {
const {onClose,modalType,parentId,refreshCatalogList,choosedItem} = props;
const {onClose,modalType,parentId,refreshCatalogList,choosedItem,parentName} = props;
console.log('choosedItem',choosedItem);
const [secondCatalogName,setSecondCatalogName] = useState(choosedItem.categoryName);
const [selectParentId,setSelectParentId] = useState(parentId);
const [optionList,setOptionList] = useState([]);
const [hasNext,setHasNext] = useState(false);
const [query, setQuery] = useState({
current: 0,
size: 100,
size:10,
storeId: User.getStoreId(),
});
useEffect(() => {
getOptionList();
},[query]);
function handleScroll(e:any){
const container = e.target;
const scrollToBottom = container && container.scrollHeight <= container.clientHeight + container.scrollTop;
if (scrollToBottom && hasNext) {
let _query = _.clone(query);
_query.current = query.current + 1;
setQuery(_query);
}
}
function getOptionList():any {
let _query = _.clone(query);
_query.current = query.current + 1;
StoreService.getCourseCatalogList(_query).then((res: any) => {
let resultData = handleCatalogListData(res.result.records)
setOptionList(resultData);
let resultData = handleCatalogListData(res.result.records);
let listData:any = [...optionList,...resultData]
setHasNext(res.result.hasNext);
setOptionList(listData);
});
}
function handleCatalogListData(listData:any){
......@@ -53,7 +68,7 @@ function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) {
if(item.sonCategoryList){
item.sonCategoryList.map((_item:any,_index:any) =>{
_item.type = "child";
_item.key=_item.id
_item.key="child" + _item.id
return _item
});
}
......@@ -142,7 +157,8 @@ function SecondCatalogAddOrEditModal(props: SecondCatalogAddOrEditModalProps) {
>
<Select
style={{ width: 240 }}
defaultValue={parentId}
defaultValue={parentName}
onPopupScroll={handleScroll}
onChange={(value) => {
setSelectParentId(String(value))
}}
......
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