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' :
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;
export function initAxiosInterceptors(props) {

View File

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

View File

@ -64,10 +64,17 @@ function Sign(props){
function arrayList(e){
const { eventKey , value , children , createName } = e.item.props;
setPage(1);
setOrderName(createName);
setOrderType(value);
setArrayName(children);
setKey(eventKey);
if(value === order_type && createName === order_name){
setOrderName(undefined);
setOrderType(undefined);
setArrayName("标记");
setKey("0");
}else{
setOrderName(createName);
setOrderType(value);
setArrayName(children);
setKey(eventKey);
}
}
const menu = (
@ -204,7 +211,7 @@ function Sign(props){
<div className="between bluebar">
<span className="font-17">项目标记({total || 0})</span>
<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>
</div>
{