cookie保存列表查询条件

This commit is contained in:
caishi 2023-02-27 16:52:59 +08:00
parent c7e3de3456
commit cfeef738b5
3 changed files with 75 additions and 29 deletions

View File

@ -25,7 +25,7 @@ if (isDev) {
} }
debugType = window.location.search.indexOf('debug=t') !== -1 ? 'teacher' : debugType = window.location.search.indexOf('debug=t') !== -1 ? 'teacher' :
window.location.search.indexOf('debug=s') !== -1 ? 'student' : window.location.search.indexOf('debug=s') !== -1 ? 'student' :
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || '' window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'admin'
} }
window._debugType = debugType; window._debugType = debugType;
export function initAxiosInterceptors(props) { export function initAxiosInterceptors(props) {

View File

@ -45,7 +45,7 @@ function List(props){
const owner = props.match.params.owner; const owner = props.match.params.owner;
const projectsId = props.match.params.projectsId; const projectsId = props.match.params.projectsId;
const permission = props && props.projectDetail && props.projectDetail.permission; const permission = props && props.projectDetail && props.projectDetail.permission;
const { projectDetail } = props; const { projectDetail , current_user } = props;
useEffect(()=>{ useEffect(()=>{
if(projectDetail){ if(projectDetail){
@ -54,6 +54,23 @@ function List(props){
} }
},[projectDetail]) },[projectDetail])
useEffect(()=>{
const datas = cookie.load('states');
let states = datas === "undefined" ? undefined : datas;
if(states){
setAboutMe(states.participant_category);
setCategory(states.category);
setPage(states.page);
setLimit(states.limit || 10);
setUpdateIds({...states});
setNames(states.names);
if(states.participant_category ==="all" && states.category === "opened" && states.page === 1 && states.limit===10)
Init({...states},states.page,states.names);
}else{
Init();
}
},[])
useEffect(()=>{ useEffect(()=>{
let v = allValue && allValue > 0; let v = allValue && allValue > 0;
if((updateIds && !v && (updateIds.author_id || updateIds.issue_priorities_id || updateIds.issue_tag_ids || updateIds.milestone_id || updateIds.sort_by || updateIds.status_id ||updateIds.assigner_id)) || value){ if((updateIds && !v && (updateIds.author_id || updateIds.issue_priorities_id || updateIds.issue_tag_ids || updateIds.milestone_id || updateIds.sort_by || updateIds.status_id ||updateIds.assigner_id)) || value){
@ -62,11 +79,26 @@ function List(props){
setClearFlag(false); setClearFlag(false);
} }
},[updateIds,value]) },[updateIds,value])
// hook
const useUpdateEffect = (fn, inputs) => {
const didMountRef = useRef(false);
useEffect(() => {
if (didMountRef.current) fn();
else didMountRef.current = true;
}, inputs);
};
//
function handleAllDisabled(){
Init(updateIds,page,names);
}
// 使hook // 使hook
useEffect(()=>{ useUpdateEffect(handleAllDisabled, [aboutMe,keyword,category,limit]);
Init(updateIds,1);
},[aboutMe,keyword,category,limit]) // useEffect(()=>{
// Init(updateIds,page,names);
// },[aboutMe,keyword,category,limit])
function getDirection(id){ function getDirection(id){
if(!id) return undefined; if(!id) return undefined;
@ -89,15 +121,20 @@ function List(props){
// issue // issue
function Init(params,p,names){ function Init(params,p,names){
const datas = cookie.load('states');
let states = datas === "undefined" ? undefined : datas;
if(states){
cookie.remove('states');
}
const url = `/v1/${owner}/${projectsId}/issues`; const url = `/v1/${owner}/${projectsId}/issues`;
axios.get(url,{ axios.get(url,{
params:{ params:{
...params,
page:p || 1,
keyword, keyword,
participant_category:aboutMe, participant_category:aboutMe,
category, category,
limit, limit,
...params,
page:p || page,
sort_direction:getDirection(params && params.sort_by), sort_direction:getDirection(params && params.sort_by),
sort_by:getBy(params && params.sort_by), sort_by:getBy(params && params.sort_by),
} }
@ -111,6 +148,13 @@ function List(props){
setAllIds(ids); setAllIds(ids);
setIssueTotal(result.data.total_issues_count); setIssueTotal(result.data.total_issues_count);
setHas_created_issues(result.data.has_created_issues); setHas_created_issues(result.data.has_created_issues);
const d = {...params,keyword,participant_category:aboutMe,category,limit,page:p || 1,
sort_direction:getDirection(params && params.sort_by),
sort_by:getBy(params && params.sort_by),names:names};
let inFifteenMinutes = new Date(new Date().getTime() + 24 * 3600 * 1000);
cookie.save('states', {...d},{ expires: inFifteenMinutes,path:`/` });
} }
}).then(error=>{}) }).then(error=>{})
} }
@ -140,6 +184,7 @@ function List(props){
setUpdateIds(undefined); setUpdateIds(undefined);
setAllValue([]); setAllValue([]);
setValue(undefined); setValue(undefined);
setNames(undefined);
Init(); Init();
// //
menuRef.current && menuRef.current.clearChoose(); menuRef.current && menuRef.current.clearChoose();
@ -200,7 +245,7 @@ function List(props){
// //
function changepage(p){ function changepage(p){
setPage(p); setPage(p);
Init(updateIds,p); Init(updateIds,p,names);
if (document) { // if (document) { //
if (document.documentElement || document.body) { if (document.documentElement || document.body) {
document.documentElement.scrollTop = document.body.scrollTop = 0; // document.documentElement.scrollTop = document.body.scrollTop = 0; //
@ -241,15 +286,6 @@ function List(props){
setPage(1); setPage(1);
setLimit(p); setLimit(p);
} }
function createBtnFunc(){
if(props.checkIfLogin()===false){
props.showLoginDialog();
return false;
}
props.history.push(`/${owner}/${projectsId}/issues/new`);
}
function changeCategory(value){ function changeCategory(value){
setCategory(value); setCategory(value);
setPage(1); setPage(1);
@ -261,18 +297,21 @@ function List(props){
<DelBox visible={visible} onCancel={()=>setVisible(false)} onSuccess={onSuccess}/> <DelBox visible={visible} onCancel={()=>setVisible(false)} onSuccess={onSuccess}/>
<div className="pageheader"> <div className="pageheader">
<div> <div>
<Dropdown overlay={menu} trigger={['click']} placement="bottomLeft" arrow={{pointAtCenter: true}}> {
<span className="dorpdownButton"> (current_user && current_user.login) &&
<span>{aboutMe === "all" ? "全部":aboutMe === "aboutme"?"与我相关":aboutMe === "assignedme"?"我负责的":aboutMe === "authoredme"?"我创建的":"@我的"}</span> <Dropdown overlay={menu} trigger={['click']} placement="bottomLeft" arrow={{pointAtCenter: true}}>
<Icon type="caret-down" className="ml5 color-grey-6" /> <span className="dorpdownButton mr20">
</span> <span>{aboutMe === "all" ? "全部":aboutMe === "aboutme"?"与我相关":aboutMe === "assignedme"?"我负责的":aboutMe === "authoredme"?"我创建的":"@我的"}</span>
</Dropdown> <Icon type="caret-down" className="ml5 color-grey-6" />
</span>
</Dropdown>
}
<Search <Search
placeholder="输入关键字搜索疑修" placeholder="输入关键字搜索疑修"
value={value} value={value}
onChange={e=>{setValue(e.target.value);}} onChange={e=>{setValue(e.target.value);}}
onSearch={()=>setKeyword(value)} onSearch={()=>setKeyword(value)}
style={{ width: 354 , height : 32 , marginLeft: 20 }} style={{ width: 354 , height : 32 }}
allowClear allowClear
/> />
{ {

View File

@ -64,10 +64,17 @@ function Sign(props){
function arrayList(e){ function arrayList(e){
const { eventKey , value , children , createName } = e.item.props; const { eventKey , value , children , createName } = e.item.props;
setPage(1); setPage(1);
setOrderName(createName); if(value === order_type && createName === order_name){
setOrderType(value); setOrderName(undefined);
setArrayName(children); setOrderType(undefined);
setKey(eventKey); setArrayName("标记");
setKey("0");
}else{
setOrderName(createName);
setOrderType(value);
setArrayName(children);
setKey(eventKey);
}
} }
const menu = ( const menu = (
@ -204,7 +211,7 @@ function Sign(props){
<div className="between bluebar"> <div className="between bluebar">
<span className="font-17">项目标记({total || 0})</span> <span className="font-17">项目标记({total || 0})</span>
<Dropdown overlay={menu} trigger={["click"]} placement="bottomRight"> <Dropdown overlay={menu} trigger={["click"]} placement="bottomRight">
<a>{arrayName}<Icon type="caret-down" className="ml5 color-grey-6" /></a> <span className="cursor">{arrayName}<Icon type="caret-down" className="ml5 color-grey-6" /></span>
</Dropdown> </Dropdown>
</div> </div>
{ {