Commit afd861aa authored by lvxiaowu's avatar lvxiaowu

接口

parent 05bcca5b
...@@ -47,15 +47,15 @@ export function api(url: string, options: Options) { ...@@ -47,15 +47,15 @@ export function api(url: string, options: Options) {
res.json().then((r: any) => { res.json().then((r: any) => {
let msg = r.error || r.msg || 'error'; let msg = r.error || r.msg || 'error';
message.error(msg); message.error(msg);
// if (r.error) { if (r.error) {
// if (r.error.match(/token/)) { if (r.error.match(/token/)) {
// message.error('登录过期,请重新登录'); message.error('登录过期,请重新登录');
// window.location.href = '/inclass-partners/login'; window.location.href = '/inclass-partners/login';
// } }
// } }
// if (options.error && typeof options.error === 'function') { if (options.error && typeof options.error === 'function') {
// options.error(r); options.error(r);
// } }
}); });
} }
}) })
......
...@@ -13,26 +13,28 @@ const FormItem = Form.Item; ...@@ -13,26 +13,28 @@ const FormItem = Form.Item;
const PAGE_SIZE = 10; const PAGE_SIZE = 10;
const ExchangeCode: React.FC = () => { const ExchangeCode: React.FC = () => {
const [courseName, set_courseName] = useState(''); const [dataSource, set_dataSource] = useState([]);
const [totalCount, set_totalCount] = useState(0); const [totalCount, set_totalCount] = useState(0);
const [current, set_current] = useState(1);
const [class_name, set_className] = useState('');
const [page, set_page] = useState(1);
const [limit, set_limit] = useState(PAGE_SIZE); const [limit, set_limit] = useState(PAGE_SIZE);
useEffect(() => { useEffect(() => {
getList(courseName, current, limit); getList(class_name, page, limit);
}, []); }, []);
const getList = (courseName: string, current: number, limit: number) => { const getList = (class_name: string, page: number, limit: number) => {
api(`/51business/api/course/back/redeem`, { api(`/51business/api/course/back/redeem`, {
type: 'GET', type: 'GET',
data: { data: {
courseName: courseName, class_name: class_name,
limit: limit, limit: limit,
page: current page: page
} }
}).then(r => { }).then(r => {
console.log(r); set_dataSource(r.list);
// set_totalCount(r.total_count); set_totalCount(r.total_count);
}); });
}; };
...@@ -49,33 +51,22 @@ const ExchangeCode: React.FC = () => { ...@@ -49,33 +51,22 @@ const ExchangeCode: React.FC = () => {
}; };
const submitData = () => { const submitData = () => {
getList(courseName, 1, limit); getList(class_name, page, limit);
}; };
const resetData = () => { const resetData = () => {
// set_current(1); set_className('');
// set_pageSize(pageSize); set_page(1);
// set_courseName(''); set_limit(PAGE_SIZE);
getList('', 1, limit); getList(class_name, page, limit);
}; };
const handleTableChange = (args: any) => { const handleTableChange = (args: any) => {
// set_current(args.current); set_page(args.current);
// set_pageSize(args.pageSize); set_limit(args.pageSize);
getList(courseName, args.current, args.pageSize); getList(class_name, args.current, args.pageSize);
}; };
let dataSource = [];
for (let i = 0; i < 25; i++) {
dataSource.push({
id: i,
courseName: '我都唔',
code: 'woeopwr',
status: 1,
date: '2020-05-20'
});
}
return ( return (
<BasicPage> <BasicPage>
<div className="content"> <div className="content">
...@@ -83,10 +74,10 @@ const ExchangeCode: React.FC = () => { ...@@ -83,10 +74,10 @@ const ExchangeCode: React.FC = () => {
<Col md={6} sm={12}> <Col md={6} sm={12}>
<FormItem label="已购课程名称:"> <FormItem label="已购课程名称:">
<Input <Input
value={courseName} value={class_name}
placeholder="请输入" placeholder="请输入"
onChange={e => { onChange={e => {
set_courseName(e.target.value); set_className(e.target.value);
}} }}
/> />
</FormItem> </FormItem>
...@@ -126,8 +117,8 @@ const ExchangeCode: React.FC = () => { ...@@ -126,8 +117,8 @@ const ExchangeCode: React.FC = () => {
dataSource={dataSource} dataSource={dataSource}
handleTableChange={handleTableChange} handleTableChange={handleTableChange}
pageSize={limit} pageSize={limit}
current={page}
totalCount={totalCount} totalCount={totalCount}
current={current}
/> />
</BasicPage> </BasicPage>
); );
......
...@@ -4,10 +4,11 @@ const { Column } = Table; ...@@ -4,10 +4,11 @@ const { Column } = Table;
interface DeatilI { interface DeatilI {
id: string | number; id: string | number;
courseName: string | number; class_name: string | number;
code: string | number; code: string | number;
status: string | number; channel: string | number;
date: string; is_used: string | number;
created_time: string | number;
} }
interface ColsI { interface ColsI {
...@@ -32,8 +33,8 @@ const columns = [ ...@@ -32,8 +33,8 @@ const columns = [
}, },
{ {
title: '课程名称', title: '课程名称',
dataIndex: 'courseName', dataIndex: 'class_name',
key: 'courseName' key: 'class_name'
}, },
{ {
title: '兑换码', title: '兑换码',
...@@ -41,14 +42,22 @@ const columns = [ ...@@ -41,14 +42,22 @@ const columns = [
key: 'code' key: 'code'
}, },
{ {
title: '生成渠道',
dataIndex: 'channel',
key: 'channel'
},
{
title: '兑换情况', title: '兑换情况',
dataIndex: 'status', dataIndex: 'is_used',
key: 'status' key: 'is_used',
render: (row: any) => {
return <span>{row ? '已使用' : '未使用'}</span>;
}
}, },
{ {
title: '兑换时间', title: '兑换时间',
dataIndex: 'date', dataIndex: 'created_time',
key: 'date' key: 'created_time'
} }
]; ];
...@@ -68,9 +77,10 @@ const List: React.FC<DataSourceI> = props => { ...@@ -68,9 +77,10 @@ const List: React.FC<DataSourceI> = props => {
pagination={{ pagination={{
pageSize: props.pageSize, pageSize: props.pageSize,
current: props.current, current: props.current,
total: props.totalCount,
showSizeChanger: true, showSizeChanger: true,
showTotal: (total, range) => showTotal: (total, range) =>
`${range[1] - range[0] + 1} of ${total} items` `每页${range[1] - range[0] + 1}条,总计${total} 条`
}} }}
> >
{Cols(columns)} {Cols(columns)}
......
import React from 'react'; import React, { useState, useEffect } from 'react';
import { Form, Input, Button, Select, message } from 'antd'; import { Form, Input, Button, Select, message } from 'antd';
import BasicPage from '../../layout/basicPage'; import BasicPage from '../../layout/basicPage';
import { api } from '../../common/fetch'; import { api } from '../../common/fetch';
...@@ -14,8 +14,24 @@ const tailLayout = { ...@@ -14,8 +14,24 @@ const tailLayout = {
}; };
const GenerateCode: React.FC = () => { const GenerateCode: React.FC = () => {
const [courseData, set_courseData] = useState([]);
const [classData, set_classData] = useState([]);
const [institution_name, set_institutionName] = useState('');
const [form] = Form.useForm(); const [form] = Form.useForm();
useEffect(() => {
getClassData(institution_name);
}, []);
const getClassData = (institution_name?: string | number) => {
api(`/51business/api/course/back/class`, {
data: { institution_name, page: 1, limit: 20 },
type: 'GET'
}).then((r: any) => {
set_courseData(r.list);
});
};
const onFinish = (values: any) => { const onFinish = (values: any) => {
api(`/51business/api/course/back/redeem`, { api(`/51business/api/course/back/redeem`, {
type: 'POST', type: 'POST',
...@@ -32,27 +48,33 @@ const GenerateCode: React.FC = () => { ...@@ -32,27 +48,33 @@ const GenerateCode: React.FC = () => {
form.resetFields(); form.resetFields();
}; };
const It = [ const onChange = (val: any) => {
{ form.resetFields(['class_id']);
name: '趣选课', let d: any = courseData[val - 1];
id: 1 set_classData((d && d.class) || []);
}, };
{ const onSearch = (val: string) => {
name: '我连网', getClassData(val);
id: 2 };
}
];
return ( return (
<BasicPage> <BasicPage>
<Form {...layout} form={form} name="control-hooks" onFinish={onFinish}> <Form {...layout} form={form} name="control-hooks" onFinish={onFinish}>
{/* <Form.Item <Form.Item
name="institution" name="institution"
label="机构名称:" label="机构名称:"
rules={[{ required: true, message: '请选择机构' }]} rules={[{ required: true, message: '请选择机构' }]}
> >
<Select placeholder="请选择机构" allowClear> <Select
{It.map(item => { placeholder="请选择机构"
allowClear
showSearch
onChange={onChange}
onSearch={onSearch}
filterOption={(input, option: any) =>
option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
>
{courseData.map((item: any) => {
return ( return (
<Option value={item.id} key={item.id}> <Option value={item.id} key={item.id}>
{item.name} {item.name}
...@@ -60,14 +82,14 @@ const GenerateCode: React.FC = () => { ...@@ -60,14 +82,14 @@ const GenerateCode: React.FC = () => {
); );
})} })}
</Select> </Select>
</Form.Item> */} </Form.Item>
<Form.Item <Form.Item
name="class_id" name="class_id"
label="课程名称:" label="课程名称:"
rules={[{ required: true, message: '请选择课程' }]} rules={[{ required: true, message: '请选择课程' }]}
> >
<Select placeholder="请选择课程名称" allowClear> <Select placeholder="请选择课程名称" allowClear>
{It.map(item => { {classData.map((item: any) => {
return ( return (
<Option value={item.id} key={item.id}> <Option value={item.id} key={item.id}>
{item.name} {item.name}
......
import React, { useState, useMemo } from 'react'; import React, { useState, useMemo, useRef } from 'react';
import { Input, message, Button, Modal } from 'antd'; import { Input, message, Button, Modal } from 'antd';
import { UserOutlined, UnlockOutlined } from '@ant-design/icons'; import { UserOutlined, UnlockOutlined } from '@ant-design/icons';
import { withRouter, RouteComponentProps } from 'react-router-dom'; import { withRouter, RouteComponentProps } from 'react-router-dom';
...@@ -16,6 +16,9 @@ const Login: React.FC<RouteComponentProps> = () => { ...@@ -16,6 +16,9 @@ const Login: React.FC<RouteComponentProps> = () => {
const [password, set_password] = useState(''); const [password, set_password] = useState('');
const [isEnable, set_Enable] = useState(false); const [isEnable, set_Enable] = useState(false);
const [showModal, set_showModal] = useState(false); const [showModal, set_showModal] = useState(false);
const loginBtnRef = useRef(null);
const onChangeInp = (e: any, name: string) => { const onChangeInp = (e: any, name: string) => {
let obj: any = { let obj: any = {
passport: (e: string) => { passport: (e: string) => {
...@@ -83,7 +86,7 @@ const Login: React.FC<RouteComponentProps> = () => { ...@@ -83,7 +86,7 @@ const Login: React.FC<RouteComponentProps> = () => {
? ['btn', 'loginItem', 'btn_act'] ? ['btn', 'loginItem', 'btn_act']
: ['btn', 'loginItem']; : ['btn', 'loginItem'];
return ( return (
<button className={styleBtn.join(' ')} onClick={submit}> <button className={styleBtn.join(' ')} onClick={submit} ref={loginBtnRef}>
{props.title} {props.title}
</button> </button>
); );
...@@ -110,7 +113,7 @@ const Login: React.FC<RouteComponentProps> = () => { ...@@ -110,7 +113,7 @@ const Login: React.FC<RouteComponentProps> = () => {
fontWeight: 'bold' fontWeight: 'bold'
}} }}
> >
趣选课供销后台 趣选课合作后台
</h3> </h3>
</div> </div>
<div className="loginItem"> <div className="loginItem">
...@@ -128,6 +131,10 @@ const Login: React.FC<RouteComponentProps> = () => { ...@@ -128,6 +131,10 @@ const Login: React.FC<RouteComponentProps> = () => {
placeholder="请输入你的密码" placeholder="请输入你的密码"
value={password} value={password}
autoComplete="new-password" autoComplete="new-password"
onPressEnter={() => {
let cur = loginBtnRef.current;
console.log(cur);
}}
onChange={(e: any) => onChangeInp(e, 'password')} onChange={(e: any) => onChangeInp(e, 'password')}
prefix={<UnlockOutlined />} prefix={<UnlockOutlined />}
/> />
......
...@@ -15,13 +15,13 @@ const FormItem = Form.Item; ...@@ -15,13 +15,13 @@ const FormItem = Form.Item;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
moment.locale('zh-cn'); moment.locale('zh-cn');
const PAGE_SIZE = 2; const PAGE_SIZE = 10;
interface FilterData { interface FilterData {
class_name?: string; class_name?: string;
user_name?: string; user_name?: string;
start_date?: string; start_time?: string;
end_date?: string; end_time?: string;
current?: number; current?: number;
limit?: number; limit?: number;
} }
...@@ -29,8 +29,8 @@ interface FilterData { ...@@ -29,8 +29,8 @@ interface FilterData {
const OrderList: React.FC = () => { const OrderList: React.FC = () => {
const [class_name, set_className] = useState(''); const [class_name, set_className] = useState('');
const [user_name, set_userName] = useState(''); const [user_name, set_userName] = useState('');
const [start_date, set_startDate] = useState(''); const [start_time, set_startTime] = useState('');
const [end_date, set_endDate] = useState(''); const [end_time, set_endTime] = useState('');
const [dataSource, set_dataSource] = useState([]); const [dataSource, set_dataSource] = useState([]);
const [totalCount, set_totalCount] = useState(0); const [totalCount, set_totalCount] = useState(0);
...@@ -55,8 +55,8 @@ const OrderList: React.FC = () => { ...@@ -55,8 +55,8 @@ const OrderList: React.FC = () => {
getList({ getList({
class_name, class_name,
user_name, user_name,
start_date, start_time,
end_date, end_time,
current, current,
limit limit
}); });
...@@ -65,23 +65,22 @@ const OrderList: React.FC = () => { ...@@ -65,23 +65,22 @@ const OrderList: React.FC = () => {
const getList = ({ const getList = ({
class_name = '', class_name = '',
user_name = '', user_name = '',
start_date = '', start_time = '',
end_date = '', end_time = '',
current = 1, current = 1,
limit = PAGE_SIZE limit = PAGE_SIZE
}: FilterData) => { }: FilterData) => {
api(`/51business/api/course/back/order`, { api(`/51business/api/course/back/order`, {
type: 'GET', type: 'GET',
data: { data: {
// class_name, class_name,
// user_name, user_name,
// start_date, start_time: start_time ? start_time + ' 00:00:00' : '',
// end_date, end_time: end_time ? end_time + ' 23:59:59' : '',
page: current, page: current,
limit: limit limit: limit
} }
}).then(r => { }).then(r => {
console.log(r);
set_dataSource(r.list); set_dataSource(r.list);
set_totalCount(r.total_count); set_totalCount(r.total_count);
}); });
...@@ -93,13 +92,13 @@ const OrderList: React.FC = () => { ...@@ -93,13 +92,13 @@ const OrderList: React.FC = () => {
data: { data: {
class_name, class_name,
user_name, user_name,
start_date, start_time,
end_date, end_time,
product: 'JSON.stringify(info.product)' product: 'JSON.stringify(info.product)'
}, },
responseType: 'arrayBuffer' responseType: 'arrayBuffer'
}).then(r => { }).then(r => {
excelFn(r, `分析明细${start_date}_${end_date}`); excelFn(r, `分析明细${start_time}_${end_time}`);
}); });
}; };
...@@ -108,10 +107,10 @@ const OrderList: React.FC = () => { ...@@ -108,10 +107,10 @@ const OrderList: React.FC = () => {
class_name: () => set_className(val), class_name: () => set_className(val),
user_name: () => set_userName(val), user_name: () => set_userName(val),
dates: () => { dates: () => {
let start_date = (val && moment(val[0]).format('YYYY-MM-DD')) || ''; let start_time = (val && moment(val[0]).format('YYYY-MM-DD')) || '';
let end_date = (val && moment(val[1]).format('YYYY-MM-DD')) || ''; let end_time = (val && moment(val[1]).format('YYYY-MM-DD')) || '';
set_startDate(start_date); set_startTime(start_time);
set_endDate(end_date); set_endTime(end_time);
} }
}; };
obj[type] && obj[type](); obj[type] && obj[type]();
...@@ -132,8 +131,8 @@ const OrderList: React.FC = () => { ...@@ -132,8 +131,8 @@ const OrderList: React.FC = () => {
getList({ getList({
class_name, class_name,
user_name, user_name,
start_date, start_time,
end_date, end_time,
current: args.current, current: args.current,
limit: args.pageSize limit: args.pageSize
}); });
...@@ -145,8 +144,8 @@ const OrderList: React.FC = () => { ...@@ -145,8 +144,8 @@ const OrderList: React.FC = () => {
getList({ getList({
class_name, class_name,
user_name, user_name,
start_date, start_time,
end_date, end_time,
current: 1, current: 1,
limit: PAGE_SIZE limit: PAGE_SIZE
}); });
...@@ -172,7 +171,7 @@ const OrderList: React.FC = () => { ...@@ -172,7 +171,7 @@ const OrderList: React.FC = () => {
<Input <Input
placeholder="请输入" placeholder="请输入"
onChange={e => { onChange={e => {
changeValue('userName', e.target.value); changeValue('user_name', e.target.value);
}} }}
/> />
</FormItem> </FormItem>
......
...@@ -98,7 +98,7 @@ const List: React.FC<DataSourceI> = props => { ...@@ -98,7 +98,7 @@ const List: React.FC<DataSourceI> = props => {
total: props.totalCount, total: props.totalCount,
showSizeChanger: true, showSizeChanger: true,
showTotal: (total, range) => showTotal: (total, range) =>
`${range[1] - range[0] + 1} of ${total} items` `每页${range[1] - range[0] + 1}条,总计${total} 条`
}} }}
> >
{Cols(columns)} {Cols(columns)}
......
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