列表页添加选择条件提示信息

dev_forge
tangjiang 5 years ago
parent 090354b5a4
commit c875bb9bd1

@ -8,8 +8,8 @@
import './index.scss'; import './index.scss';
import React, { Component } from 'react'; import React from 'react';
import { Table, Button, Dropdown, Icon, Menu, Card, Input, Select, Tag, Divider } from 'antd'; import { Table, Button, Dropdown, Icon, Menu, Card, Input, Select, Tag } from 'antd';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import actions from '../../redux/actions'; import actions from '../../redux/actions';
import MultipTags from './components/multiptags'; import MultipTags from './components/multiptags';
@ -28,63 +28,63 @@ const maps = {
{ {
'key': '0', 'key': '0',
'name': '全部', 'name': '全部',
'vlaue': '0' 'value': '0'
}, },
{ {
'key': '1', 'key': '1',
'name': '程序设计基础', 'name': '程序设计基础',
'vlaue': '1' 'value': '1'
}, },
{ {
'key': '2', 'key': '2',
'name': '数据结构与计算', 'name': '数据结构与计算',
'vlaue': '2' 'value': '2'
} }
], ],
'hardMenu': [ 'difficultMenu': [
{ {
'key': '1', 'key': '1',
'name': '简单', 'name': '简单',
'vlaue': '1' 'value': '1'
}, },
{ {
'key': '2', 'key': '2',
'name': '中等', 'name': '中等',
'vlaue': '2' 'value': '2'
}, },
{ {
'key': '3', 'key': '3',
'name': '困难', 'name': '困难',
'vlaue': '3' 'value': '3'
} }
], ],
'statusMenu': [ 'statusMenu': [
{ {
'key': '-1', 'key': '-1',
'name': '未做', 'name': '未做',
'vlaue': '-1' 'value': '-1'
}, },
{ {
'key': '0', 'key': '0',
'name': '未通过', 'name': '未通过',
'vlaue': '0' 'value': '0'
}, },
{ {
'key': '1', 'key': '1',
'name': '已通过', 'name': '已通过',
'vlaue': '1' 'value': '1'
} }
], ],
'originMenu': [ 'come_fromMenu': [
{ {
'key': 'all', 'key': 'all',
'name': '全部', 'name': '全部',
'vlaue': 'all' 'value': 'all'
}, },
{ {
'key': 'mine', 'key': 'mine',
'name': '我创建的', 'name': '我创建的',
'vlaue': 'mine' 'value': 'mine'
} }
] ]
}; };
@ -151,19 +151,13 @@ const columns = [
sorter: true, sorter: true,
align:'right', align:'right',
width: '10%', width: '10%',
render: val => <span>{`${val}%`}</span> render: val => <span>{`${val}%`}</span>
}, },
]; ];
class DeveloperHome extends Component { class DeveloperHome extends React.PureComponent {
state = { state = {
data: [], data: [],
pagination: {
total: 1, // 总条数
pageSize: 10, // 每页显示条数
current: 1, // 当前页数
showQuickJumper: true
},
loading: false, loading: false,
searchParams: { searchParams: {
search: '', // 查询关键字 search: '', // 查询关键字
@ -172,15 +166,18 @@ class DeveloperHome extends Component {
status: '', // 未做 status: '', // 未做
category: '', // 分类 category: '', // 分类
'sort_by': '', // 排序 'sort_by': '', // 排序
'sort_direction': '' // 排序方向 'sort_direction': '', // 排序方向
page: 1, // 当前页数
limit: 10 // 每页显示条件
}, },
columns: columns columns: columns,
searchInfo: []
}; };
componentDidMount() { componentDidMount() {
// 是否是我的,如果是我的 显示编辑按钮
const { isMySource } = this.props; const { isMySource } = this.props;
if (isMySource) { if (isMySource) {
// this.handleFilterSearch()
this.handleFilterSearch({come_from: 'mine'}); this.handleFilterSearch({come_from: 'mine'});
let _columns = columns.concat([options]); let _columns = columns.concat([options]);
this.setState({ this.setState({
@ -199,9 +196,15 @@ class DeveloperHome extends Component {
} }
handleTableChange = (pagination, filters, sorter) => { handleTableChange = (pagination, filters, sorter) => {
// console.log(pagination, filters, sorter);
const {field, order} = sorter; const {field, order} = sorter;
this.handleFilterSearch({sort_by: field, sort_direction: order === 'descend' ? 'desc' : 'asc'}); const {current, pageSize} = pagination;
this.handleFilterSearch({
sort_by: field,
sort_direction: order === 'descend' ? 'desc' : 'asc',
page: current,
limit: pageSize
});
this.props.changePaginationInfo(pagination);
}; };
fetchData = () => { fetchData = () => {
@ -228,6 +231,7 @@ class DeveloperHome extends Component {
</Menu> </Menu>
) )
}; };
getOptionsItem = (type) => { getOptionsItem = (type) => {
return maps[type].map(item => { return maps[type].map(item => {
return <Option key={item.key} value={item.value}>{item.name}</Option> return <Option key={item.key} value={item.value}>{item.name}</Option>
@ -242,6 +246,21 @@ class DeveloperHome extends Component {
this.fetchData(); this.fetchData();
}); });
} }
// 添加显示搜索条件
addShowFilterCtx = (obj) => {
const {searchInfo} = this.state
const index = searchInfo.findIndex(item => item.type === obj.type);
let tempArr = [...searchInfo];
if (index > -1) {
tempArr[index] = obj;
} else {
tempArr.push(obj);
}
this.setState({
searchInfo: tempArr
});
}
/** /**
* 搜索输入框 * 搜索输入框
* @param value 输入框值 * @param value 输入框值
@ -257,18 +276,36 @@ class DeveloperHome extends Component {
// } // }
// 下拉类别菜单 // 下拉类别菜单
handleCategoryMenuClick = (item) => { handleCategoryMenuClick = (item) => {
this.addShowFilterCtx({
type: 'category',
key: item.key
});
this.handleFilterSearch({category: +item.key === 0 ? '' : +item.key}); this.handleFilterSearch({category: +item.key === 0 ? '' : +item.key});
} }
// 难度下拉 // 难度下拉
handleHardMenuClick = (item) => { handleHardMenuClick = (item) => {
this.addShowFilterCtx({
type: 'difficult',
key: item.key
});
this.handleFilterSearch({difficult: +item.key}); this.handleFilterSearch({difficult: +item.key});
} }
// 状态下拉 // 状态下拉
handleSatusMenuClick = (item) => { handleSatusMenuClick = (item) => {
this.addShowFilterCtx({
type: 'status',
key: item.key
});
this.handleFilterSearch({status: +item.key}); this.handleFilterSearch({status: +item.key});
} }
// 来源下拉 // 来源下拉
handleOriginMenuClick = (item) => { handleOriginMenuClick = (item) => {
this.addShowFilterCtx({
type: 'come_from',
key: item.key
});
this.handleFilterSearch({come_from: item.key === 'all' ? '' : item.key}); this.handleFilterSearch({come_from: item.key === 'all' ? '' : item.key});
if (item.key !== 'all') { if (item.key !== 'all') {
@ -283,11 +320,49 @@ class DeveloperHome extends Component {
} }
} }
handleTagClose = (info) => {
this.handleFilterSearch({[info.type]: ''});
// 移除 searcInfo 中的数据
const { type } = info;
let tempArr = [...this.state.searchInfo];
const index = tempArr.findIndex(item => item.type === type);
if (index > -1) tempArr.splice(index, 1);
this.setState({
searchInfo: tempArr
});
if (info.type === 'come_from' && info.key === 'mine') {
this.setState({
columns: columns
});
}
}
render () { render () {
// const { testReducer, handleClick } = this.props; // const { testReducer, handleClick } = this.props;
const { ojListReducer: {hacks_list, top_data, hacks_count} } = this.props; const {
ojListReducer: {hacks_list, top_data, hacks_count},
pagination
} = this.props;
const {passed_count = 0, simple_count = 0, medium_count = 0, diff_count = 0} = top_data; const {passed_count = 0, simple_count = 0, medium_count = 0, diff_count = 0} = top_data;
const { columns } = this.state; const { columns } = this.state;
// 渲染条件内容
const renderSearch = () => {
return this.state.searchInfo.map(info => {
let ctx = '';
const arrs = maps[`${info.type}Menu`];
arrs.forEach(item => {
if (item.key === info.key) ctx = item.name;
});
return (
<Tag
closable
key={info.type}
onClose={() => this.handleTagClose(info)}
>{ctx}</Tag>
)});
};
return ( return (
<div className="developer-list"> <div className="developer-list">
<div className="ant-spin-container"> <div className="ant-spin-container">
@ -307,34 +382,39 @@ class DeveloperHome extends Component {
</div> </div>
</div> </div>
<div className={'card-table'}> <div className={'card-table'}>
<Card bordered={false}> <div bordered={false} className={'filter_ctx_area'}>
<Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('categoryMenu', this.handleCategoryMenuClick)}> <div>
<span className={'dropdown-span'}>分类 <Icon type="down"/></span> <Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('categoryMenu', this.handleCategoryMenuClick)}>
</Dropdown> <span className={'dropdown-span'}>分类 <Icon type="down"/></span>
<Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('hardMenu', this.handleHardMenuClick)}> </Dropdown>
<span className={'dropdown-span'}>难度 <Icon type="down"/></span> <Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('difficultMenu', this.handleHardMenuClick)}>
</Dropdown> <span className={'dropdown-span'}>难度 <Icon type="down"/></span>
<Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('statusMenu', this.handleSatusMenuClick)}> </Dropdown>
<span className={'dropdown-span'}>状态 <Icon type="down"/></span> <Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('statusMenu', this.handleSatusMenuClick)}>
</Dropdown> <span className={'dropdown-span'}>状态 <Icon type="down"/></span>
<Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('originMenu', this.handleOriginMenuClick)}> </Dropdown>
<span className={'dropdown-span'}>来源 <Icon type="down"/></span> <Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('come_fromMenu', this.handleOriginMenuClick)}>
</Dropdown> <span className={'dropdown-span'}>来源 <Icon type="down"/></span>
</Dropdown>
</div>
<div className={'choice_ctx'}>
{renderSearch()}
</div>
<Search <Search
placeholder="输入标题进行搜索" placeholder="输入标题进行搜索"
onChange={this.handleSearchChange} onChange={this.handleSearchChange}
onSearch={value => this.handleInputSearch(value)} onSearch={value => this.handleInputSearch(value)}
style={{ width: 320, float: 'right' }} style={{ width: 320, float: 'right' }}
/> />
</Card> </div>
<Card bordered={false} style={{ marginTop: '2px'}}> <Card bordered={false} style={{ marginTop: '2px'}}>
<Table <Table
columns={columns} columns={columns}
rowKey={record => Math.random()} rowKey={record => Math.random()}
dataSource={hacks_list} dataSource={hacks_list}
pagination={this.state.pagination} pagination={pagination}
onChange={this.handleTableChange} onChange={this.handleTableChange}
/> />
</Card> </Card>
@ -350,16 +430,28 @@ class DeveloperHome extends Component {
* @param {*} state store * @param {*} state store
* @param {*} ownProps DeveloperHome 中的 props * @param {*} ownProps DeveloperHome 中的 props
*/ */
const mapStateToProps = (state, ownProps) => ({ const mapStateToProps = (state, ownProps) => {
testReducer: state.testReducer, const {
ojListReducer: state.ojListReducer, testReducer,
isMySource: state.commonReducer.isMySource ojListReducer,
}); commonReducer
} = state;
const { pagination } = ojListReducer;
return {
testReducer,
ojListReducer,
isMySource: commonReducer.isMySource,
pagination
}
};
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
handleClick: () => dispatch(actions.toggleTodo()), handleClick: () => dispatch(actions.toggleTodo()),
fetchOJList: (params) => dispatch(actions.getOJList(params)), fetchOJList: (params) => dispatch(actions.getOJList(params)),
changePaginationInfo: (obj) => dispatch(actions.changePaginationInfo(obj)),
}); });
export default connect( export default connect(

@ -38,12 +38,23 @@
.card-table{ .card-table{
margin-top: 10px; margin-top: 10px;
.filter_ctx_area{
display: flex;
justify-content: space-between;
padding: 10px 30px;
background: #fff;
align-items: center;
}
.choice_ctx{
flex: 1;
}
.ant-card-body{ .ant-card-body{
padding: 10px 30px; padding: 10px 30px;
// width: 100%;
} }
.dropdown-span{ .dropdown-span{
position: relative; position: relative;
top: 5px; top: 2px;
} }
.dropdonw-style{ .dropdonw-style{
margin-right: 50px; margin-right: 50px;
@ -53,4 +64,5 @@
} }
} }
} }
} }

@ -43,11 +43,9 @@ const RightPaneCode = (props) => {
}, [props.language]); }, [props.language]);
useEffect(() => { useEffect(() => {
console.log('测试用例更改');
}, [props.testCases]); }, [props.testCases]);
useEffect(() => { useEffect(() => {
console.log('编辑器内容变化时');
}, [editCode]); }, [editCode]);
// 监听store中编辑器内容变化 // 监听store中编辑器内容变化

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-11-23 11:33:41 * @Date: 2019-11-23 11:33:41
* @LastEditors: tangjiang * @LastEditors: tangjiang
* @LastEditTime: 2019-11-28 16:12:58 * @LastEditTime: 2019-11-29 11:10:57
// */ // */
import './index.scss'; import './index.scss';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
@ -30,7 +30,6 @@ const LeftPane = (props) => {
]; ];
useEffect(() => { useEffect(() => {
console.log('==========>>>>>', userCodeTab)
setDefaultActiveKey(userCodeTab); setDefaultActiveKey(userCodeTab);
}, [userCodeTab]) }, [userCodeTab])

@ -41,7 +41,8 @@ const types = {
CHANGE_USER_CODE_TAB: 'CHANGE_USER_CODE_TAB', // 切换学员测评tab CHANGE_USER_CODE_TAB: 'CHANGE_USER_CODE_TAB', // 切换学员测评tab
SUBMIT_LOADING_STATUS: 'SUBMIT_LOADING_STATUS', // 提交按钮状态值 SUBMIT_LOADING_STATUS: 'SUBMIT_LOADING_STATUS', // 提交按钮状态值
PUBLISH_LOADING_STATUS: 'PUBLISH_LOADING_STATUS', // 发布按钮 PUBLISH_LOADING_STATUS: 'PUBLISH_LOADING_STATUS', // 发布按钮
IS_MY_SOURCE: 'IS_MY_SOURCE' IS_MY_SOURCE: 'IS_MY_SOURCE',
CHANGE_PAGINATION_INFO: 'CHANGE_PAGINATION_INFO', // 改变分页数据
} }
export default types; export default types;

@ -7,7 +7,7 @@
*/ */
import toggleTodo from './testAction.js'; import toggleTodo from './testAction.js';
import {getOJList} from './ojList'; import {getOJList, changePaginationInfo} from './ojList';
import { import {
validateOjForm, validateOjForm,
saveOjFormCode, saveOjFormCode,
@ -50,6 +50,7 @@ import {
export default { export default {
toggleTodo, toggleTodo,
getOJList, getOJList,
changePaginationInfo,
getOJFormById, getOJFormById,
saveOJFormId, saveOJFormId,
clearOJFormStore, clearOJFormStore,

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-11-27 13:42:11 * @Date: 2019-11-27 13:42:11
* @LastEditors: tangjiang * @LastEditors: tangjiang
* @LastEditTime: 2019-11-28 17:32:52 * @LastEditTime: 2019-11-29 11:11:13
*/ */
import types from "./actionTypes"; import types from "./actionTypes";
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
@ -22,7 +22,6 @@ import {
export const startProgramQuestion = (id) => { export const startProgramQuestion = (id) => {
return (dispatch) => { return (dispatch) => {
fetchStartProgram(id).then(res => { fetchStartProgram(id).then(res => {
console.log('调用编程题成功返回的数据: ', res);
const { status, data } = res; const { status, data } = res;
if (status === 200) { if (status === 200) {
const {identifier} = data; const {identifier} = data;
@ -32,7 +31,6 @@ export const startProgramQuestion = (id) => {
}); });
// 调用用户编程详情接口 // 调用用户编程详情接口
fetchUserProgramDetail(identifier).then(res => { fetchUserProgramDetail(identifier).then(res => {
console.log('用户编程题详情: =====>>>>>', res);
const { status, data = {} } = res; const { status, data = {} } = res;
if (status === 200) { if (status === 200) {
dispatch({ dispatch({

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-11-20 10:48:24 * @Date: 2019-11-20 10:48:24
* @LastEditors: tangjiang * @LastEditors: tangjiang
* @LastEditTime: 2019-11-22 16:44:44 * @LastEditTime: 2019-11-29 11:09:54
*/ */
import types from './actionTypes'; import types from './actionTypes';
import { fetchOJList } from '../../services/ojService'; import { fetchOJList } from '../../services/ojService';
@ -12,12 +12,26 @@ import { fetchOJList } from '../../services/ojService';
export const getOJList = (params) => { export const getOJList = (params) => {
return (dispatch) => { return (dispatch) => {
fetchOJList(params).then((res) => { fetchOJList(params).then((res) => {
console.log('获取列表信息成功: ', res);
const { data } = res; const { data } = res;
dispatch({ dispatch({
type: types.GET_OJ_LIST, type: types.GET_OJ_LIST,
payload: data payload: data
}); });
// 改变总页娄
dispatch({
type: types.CHANGE_PAGINATION_INFO,
payload: {
total: data.hacks_count
}
});
}); });
} }
} }
// 改变分页数据
export const changePaginationInfo = (obj) => {
return {
type: types.CHANGE_PAGINATION_INFO,
payload: obj
}
}

@ -4,14 +4,20 @@
* @Github: * @Github:
* @Date: 2019-11-21 22:17:03 * @Date: 2019-11-21 22:17:03
* @LastEditors: tangjiang * @LastEditors: tangjiang
* @LastEditTime: 2019-11-22 09:17:59 * @LastEditTime: 2019-11-29 09:31:04
*/ */
import types from '../actions/actionTypes'; import types from '../actions/actionTypes';
const initialState = { const initialState = {
hacks_list: [], hacks_list: [],
top_data: {}, top_data: {},
hacks_count: 0 // 总条数 hacks_count: 0, // 总条数
pagination: {
current: 1, // 当前页
pageSize: 10, // 每页条数
total: 1, // 总数
showQuickJumper: true // 快速跳转
}
}; };
const ojListReducer = (state = initialState, action) => { const ojListReducer = (state = initialState, action) => {
@ -21,6 +27,11 @@ const ojListReducer = (state = initialState, action) => {
...state, ...state,
...action.payload ...action.payload
} }
case types.CHANGE_PAGINATION_INFO:
return {
...state,
pagination: Object.assign({}, state.pagination, action.payload)
}
default: default:
return state; return state;
} }

Loading…
Cancel
Save