Commit 5009f838 by zhangleyuan

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

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