主题设置列表、复制、查询

master
xialiang 4 years ago
parent 9d6dd5a2cb
commit c0deedcbda

@ -10,7 +10,7 @@ import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions';
import ProDescriptions from '@ant-design/pro-descriptions'; import ProDescriptions from '@ant-design/pro-descriptions';
import type { FormValueType } from './components/UpdateForm'; import type { FormValueType } from './components/UpdateForm';
import UpdateForm from './components/UpdateForm'; import UpdateForm from './components/UpdateForm';
import { Subject, addSubject, updateSubject, removeSubject, querySubjectList } from './service'; import { copySubject, addSubject, updateSubject, removeSubject, querySubjectList } from './service';
import type { TableListItem, TableListPagination } from './data'; import type { TableListItem, TableListPagination } from './data';
/** /**
* *
@ -91,70 +91,80 @@ const TableList: React.FC = () => {
/** 国际化配置 */ /** 国际化配置 */
const columns: ProColumns<TableListItem>[] = [ const columns: ProColumns<TableListItem>[] = [
{
title: '主题名称',
dataIndex: 'subject_name',
valueType: 'text',
hideInTable: true,
hideInDescriptions: true,
hideInForm: true,
hideInSearch: false,
},
{ {
title: '图片', title: '图片',
dataIndex: 'name', dataIndex: 'name',
tip: '主题名称是唯一的 key', tip: '主题名称是唯一的 key',
hideInSearch: true,
render: (dom, entity) => { render: (dom, entity) => {
// console.log(entity, 'entity')
return ( return (
<img src="https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png" style={{width:'150px', height:'75px'}} /> <img src={entity.attachment_json.url} style={{ width: '150px', height: '75px' }} />
); );
}, },
}, },
{ {
title: '描述', title: '创建日期',
dataIndex: 'desc', dataIndex: 'create_time',
valueType: 'textarea', valueType: 'dateRange',
}, hideInTable: true,
{
title: '考核学时',
dataIndex: 'callNo',
sorter: true,
hideInForm: true, hideInForm: true,
renderText: (val: string) => `${val}`, hideInSearch: false,
}, },
{ {
title: '状态', title: '主题',
dataIndex: 'status', dataIndex: 'subject_describe',
hideInForm: true, valueType: 'textarea',
valueEnum: { hideInSearch: true,
0: { width: "60%",
text: '关闭', render: (dom, entity) => {
status: 'Default',
}, return (
1: {
text: '运行中', <div>
status: 'Processing', <h3>{entity.subject_name}</h3>
}, <div dangerouslySetInnerHTML={{ __html: entity.subject_describe }} />
2: { </div>
text: '已上线',
status: 'Success', );
},
3: {
text: '异常',
status: 'Error',
},
}, },
}, },
{ {
title: '课程数', title: '信息',
dataIndex: 'total_course_minutes',
sorter: true, sorter: true,
dataIndex: 'updatedAt', hideInSearch: true,
valueType: 'dateTime', render: (dom, entity) => {
renderFormItem: (item, { defaultRender, ...rest }, form) => {
const status = form.getFieldValue('status');
if (`${status}` === '0') { return (
return false;
}
if (`${status}` === '3') { <div>
return <Input {...rest} placeholder="请输入异常原因!" />; {entity.total_chapter_number}<br />
} {entity.total_course_number}<br />
{entity.total_course_minutes}
</div>
return defaultRender(item); );
}, },
}, },
// {
// title: '课程数',
// sorter: true,
// dataIndex: 'total_chapter_number',
// },
{ {
title: '操作', title: '操作',
dataIndex: 'option', dataIndex: 'option',
@ -168,16 +178,23 @@ const TableList: React.FC = () => {
> >
</a>, </a>,
<a <a
key="copyAlert" key="copyAlert"
onClick={() => { onClick={async () => {
// handleCopyItem({}); // console.log(e, record, 'copy')
const success = await copySubject({ subject_id: record.subject_id });
if (success) {
// handleModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
}
}} }}
> >
</a>, </a>,
<a <a
key="deleteAlert" key="deleteAlert"
onClick={() => { onClick={() => {
// handleCopyItem({}); // handleCopyItem({});
}} }}
@ -191,7 +208,7 @@ const TableList: React.FC = () => {
return ( return (
<PageContainer> <PageContainer>
<ProTable<TableListItem, TableListPagination> <ProTable<TableListItem, TableListPagination>
headerTitle="查询表格" headerTitle="主题设置"
actionRef={actionRef} actionRef={actionRef}
rowKey="subject_id" rowKey="subject_id"
options={false} options={false}
@ -209,13 +226,25 @@ const TableList: React.FC = () => {
<PlusOutlined /> <PlusOutlined />
</Button>, </Button>,
]} ]}
request={async () => { request={async (value) => {
const { data } = await querySubjectList({page_size: 20}); // 解构后不用套data const { create_time } = value;
//console.log('datalist', data?.list ) if (create_time) {
value.begin_time = create_time[0]
value.end_time = create_time[1]
}
const { data } = await querySubjectList({
...value,
page_number: value.current,
page_size: value.pageSize
}); // 解构后不用套data
// console.log('datalist', dataist)
return { return {
current: data?.page_number,
data: data?.list,
pageSize: data?.page_size,
success: true, success: true,
data: data?.list || [], total: data?.total_row || 0,
total: data?.total_page || 0,
}; };
}} }}
columns={columns} columns={columns}

@ -28,32 +28,65 @@ export async function rule(
}); });
} }
/** 新建规则 PUT /api/rule */
export async function updateRule(data: { [key: string]: any }, options?: { [key: string]: any }) {
return request<TableListItem>('/api/rule', { /** 获取主题详情 GET /dsideal_yy/ypt/careerTraining/subject/getSubjectInfo */
data, export async function getSubjectInfo(
method: 'PUT', params: {
// query
/** 当前的页码 */
id?: number;
},
options?: Record<string, any>,
) {
return request('/dsideal_yy/ypt/careerTraining/subject/getSubjectInfo', {
method: 'GET',
params: {
...params,
},
...(options || {}), ...(options || {}),
}); });
} }
/** 新建规则 POST /api/rule */ /** 复制主题 POST /dsideal_yy/ypt/careerTraining/subject/copySubject */
export async function addRule(data: { [key: string]: any }, options?: { [key: string]: any }) { export async function copySubject(data: { [key: string]: any }, options?: { [key: string]: any }) {
return request<TableListItem>('/api/rule', { return request<TableListItem>('/dsideal_yy/ypt/careerTraining/subject/copySubject', {
data, data,
method: 'POST', method: 'POST',
requestType: "form",
...(options || {}), ...(options || {}),
}); });
} }
/** 删除规则 DELETE /api/rule */
export async function removeRule(data: { key: number[] }, options?: { [key: string]: any }) {
return request<Record<string, any>>('/api/rule', {
data, // /** 新建规则 PUT /api/rule */
method: 'DELETE', // export async function updateRule(data: { [key: string]: any }, options?: { [key: string]: any }) {
...(options || {}), // return request<TableListItem>('/api/rule', {
}); // data,
} // method: 'PUT',
// ...(options || {}),
// });
// }
// /** 新建规则 POST /api/rule */
// export async function addRule(data: { [key: string]: any }, options?: { [key: string]: any }) {
// return request<TableListItem>('/api/rule', {
// data,
// method: 'POST',
// ...(options || {}),
// });
// }
// /** 删除规则 DELETE /api/rule */
// export async function removeRule(data: { key: number[] }, options?: { [key: string]: any }) {
// return request<Record<string, any>>('/api/rule', {
// data,
// method: 'DELETE',
// ...(options || {}),
// });
// }
/** /**
@ -62,7 +95,7 @@ export async function removeRule(data: { key: number[] }, options?: { [key: stri
* @param params * @param params
* @returns * @returns
*/ */
export async function querySubjectList(params: { export async function querySubjectList(params: {
page_size: number; page_size: number;
//count: number; //count: number;
}): Promise<{ data: { list: CardListItemDataType[] } }> { }): Promise<{ data: { list: CardListItemDataType[] } }> {

@ -23,7 +23,7 @@ import ProFormRichEdit from '../components/ProFormRichEdit';
import type { ActionType, ProColumns } from '@ant-design/pro-table'; import type { ActionType, ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import type { TableListItem, TableListPagination } from '../../option/data'; import type { TableListItem, TableListPagination } from '../../option/data';
import { queryCourseList, saveSubject } from '../../option/service'; import { getSubjectInfo, saveSubject } from '../../option/service';
/** 列表项定义 */ /** 列表项定义 */
const columns: ProColumns<TableListItem>[] = [ const columns: ProColumns<TableListItem>[] = [
@ -151,12 +151,31 @@ export default () => {
stepProps={{ stepProps={{
description: false, description: false,
}} }}
request={async () => {
const data = await getSubjectInfo(5);
console.log(data);
// return { data: bean }
}}
onFinish={async (value) => { onFinish={async (value) => {
console.log(value, "vvvvv"); console.log(value, "vvvvv");
console.log(formRef.current?.getFieldsValue()); const _data = await saveSubject({
await waitTime(2000); ...value,
return true; attachment_json: `{ "url": "${value.upload[0].response.url}"}`
});
return {
current: _data?.page_number,
data: _data?.data?.list,
pageSize: _data?.page_size,
total: _data?.total_row || 0,
};
}} }}
> >
<Row gutter={24}> <Row gutter={24}>
@ -270,16 +289,16 @@ export default () => {
]} ]}
request={async (value) => { request={async (value) => {
const _data = await saveSubject({ // const _data = await saveSubject({
...value, // ...value,
attachment_json: `{ "url": "${value.upload[0].response.url}"}` // attachment_json: `{ "url": "${value.upload[0].response.url}"}`
}); // });
return { // return {
current: _data?.page_number, // current: _data?.page_number,
data: _data?.data?.list, // data: _data?.data?.list,
pageSize: _data?.page_size, // pageSize: _data?.page_size,
total: _data?.total_row || 0, // total: _data?.total_row || 0,
}; // };
}} }}
// dataSource={list} // dataSource={list}
columns={columns} columns={columns}
@ -368,7 +387,7 @@ export default () => {
</StepsForm.StepForm> </StepsForm.StepForm>
</StepsForm> </StepsForm>
</ProCard> </ProCard>
</PageContainer> </PageContainer >
); );
}; };

@ -40,7 +40,7 @@ export async function saveRules(data: Record<string, any>, options?: Record<stri
/** 获取考试规则列表 GET /dsideal_yy/zygh/training/examination/getExaminationList */ /** 获取考试规则详情 GET /dsideal_yy/zygh/training/examination/getExaminationList */
export async function queryRulesView( export async function queryRulesView(
params: { params: {
// query // query

Loading…
Cancel
Save