zhengpengju 4 years ago
parent d82dbc7f92
commit 77637f401f

@ -1,7 +1,6 @@
// @ts-ignore // @ts-ignore
import { request } from 'umi'; import { request } from 'umi';
import { TableListItem } from './data'; import { TableListItem } from './data';
import type { ProFormColumnsType } from '@ant-design/pro-form';
/** 获取考点数据结构 GET /api/dataSource?key=examination&schema=true&data=false */ /** 获取考点数据结构 GET /api/dataSource?key=examination&schema=true&data=false */
export async function schemaExamination( export async function schemaExamination(

@ -62,7 +62,7 @@
"@antv/l7-react": "^2.1.9", "@antv/l7-react": "^2.1.9",
"@umijs/block-sdk": "^2.3.0", "@umijs/block-sdk": "^2.3.0",
"@umijs/route-utils": "^1.0.36", "@umijs/route-utils": "^1.0.36",
"ahooks": "^2.0.0", "ahooks": "^3.0.5",
"ahooks-v2": "^2.10.15", "ahooks-v2": "^2.10.15",
"antd": "^4.14.0", "antd": "^4.14.0",
"bizcharts": "^3.5.3-beta.0", "bizcharts": "^3.5.3-beta.0",
@ -81,7 +81,7 @@
"react-fittext": "^1.0.0", "react-fittext": "^1.0.0",
"react-helmet-async": "^1.0.4", "react-helmet-async": "^1.0.4",
"react-router": "^4.3.1", "react-router": "^4.3.1",
"umi": "^3.5.0", "umi": "^3.5.20",
"umi-block-convertor": "^1.0.1", "umi-block-convertor": "^1.0.1",
"umi-request": "^1.4.0", "umi-request": "^1.4.0",
"umi-serve": "^1.9.10" "umi-serve": "^1.9.10"

@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import { useRequest } from 'ahooks-v2'; import { useRequest } from 'umi';
import type { ActionType } from '@ant-design/pro-table'; import type { ActionType } from '@ant-design/pro-table';
// import type { ProFormColumnsType } from '@ant-design/pro-form'; // import type { ProFormColumnsType } from '@ant-design/pro-form';
@ -7,7 +7,7 @@ import { PageContainer } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions';
import ProDescriptions from '@ant-design/pro-descriptions'; import ProDescriptions from '@ant-design/pro-descriptions';
import { BetaSchemaForm} from '@ant-design/pro-form'; import { BetaSchemaForm } from '@ant-design/pro-form';
import { Button, Col, Modal, Row, Space } from 'antd'; import { Button, Col, Modal, Row, Space } from 'antd';
import { MobileOutlined, PhoneOutlined, PlusOutlined } from '@ant-design/icons'; import { MobileOutlined, PhoneOutlined, PlusOutlined } from '@ant-design/icons';
@ -18,7 +18,7 @@ import type { DataItem } from '../dashboard/analysis/data';
export type TableListItem = { export type TableListItem = {
id: string; id: string;
code: number; code: number;
name: string; name: string;
creator: string; creator: string;
status: string; status: string;
createdAt: number; createdAt: number;
@ -41,82 +41,110 @@ export default () => {
useEffect(() => { useEffect(() => {
const _data = data || []; const _data = data || [];
let idx = -1; let idx = -1;
idx = _data?.findIndex((val: { dataIndex: string; })=>{ return val.dataIndex === 'publicTelephone' }) || -1; idx =
if(idx !== -1){ _data?.findIndex((val: { dataIndex: string }) => {
_data[idx] = {..._data[idx], renderText: (val: string) => `${(val || '').replace(/(\d{2})(\d{2})(\d{4})/,"$1**$3")}`} return val.dataIndex === 'publicTelephone';
}) || -1;
if (idx !== -1) {
_data[idx] = {
..._data[idx],
renderText: (val: string) => `${(val || '').replace(/(\d{2})(\d{2})(\d{4})/, '$1**$3')}`,
};
} }
/** 渲染复合数据项 */ /** 渲染复合数据项 */
idx = _data?.findIndex((val: { dataIndex: string; })=>{ return val.dataIndex === 'examiner' }) || -1; idx =
if(idx !== -1){ _data?.findIndex((val: { dataIndex: string }) => {
return val.dataIndex === 'examiner';
}) || -1;
if (idx !== -1) {
_data[idx] = { _data[idx] = {
..._data[idx], ..._data[idx],
render: (text: any) => ( render: (text: any) => (
<> <>
<span style={{ display: 'block' }}>{text?.realname}</span> <span style={{ display: 'block' }}>{text?.realname}</span>
<small style={{ display: 'inline-block', marginRight: 5 }}><PhoneOutlined /> {text?.tel}</small> <small style={{ display: 'inline-block', marginRight: 5 }}>
<small style={{ display: 'inline-block', marginRight: 5 }}><MobileOutlined /> {text?.mobile}</small> <PhoneOutlined /> {text?.tel}
</small>
<small style={{ display: 'inline-block', marginRight: 5 }}>
<MobileOutlined /> {text?.mobile}
</small>
</> </>
) ),
} };
} }
/** 添加序号和操作列 */ /** 添加序号和操作列 */
setColumns( setColumns([
[ {
{ title: '序号',
title: '序号', key: 'index',
key: 'index', valueType: 'indexBorder',
valueType: 'indexBorder', render: (text: React.ReactNode, _: any, index: number) => {
render: (text: React.ReactNode, _: any, index: number) =>{ if (ref && ref?.current && ref?.current?.pageInfo) {
if(ref && ref?.current && ref?.current?.pageInfo){ return `${
return `${(ref?.current?.pageInfo?.current - 1) * (ref.current.pageInfo?.pageSize) + (index + 1)}`; (ref?.current?.pageInfo?.current - 1) * ref.current.pageInfo?.pageSize + (index + 1)
}else{ }`;
return ''; } else {
} return '';
}, }
width: 48,
}, },
..._data, width: 48,
{ },
title: '操作', ..._data,
width: 180, {
key: 'option', title: '操作',
valueType: 'option', width: 180,
render: (_dom: any, entity: React.SetStateAction<TableListItem | undefined>) => [ key: 'option',
<a key="detail" onClick={() => { valueType: 'option',
render: (_dom: any, entity: React.SetStateAction<TableListItem | undefined>) => [
<a
key="detail"
onClick={() => {
console.log('entity', entity); console.log('entity', entity);
setCurrentRow(entity); setCurrentRow(entity);
setShowDetail(true); setShowDetail(true);
}} ></a>, }}
<a key="update" onClick={() => { >
console.log('columns1', columns)
</a>,
<a
key="update"
onClick={() => {
console.log('columns1', columns);
setCurrentRow(entity); setCurrentRow(entity);
setShowUpdate(true); setShowUpdate(true);
console.log('columns2', columns) console.log('columns2', columns);
}} ></a>, }}
<a key="delete" onClick={() => { >
</a>,
<a
key="delete"
onClick={() => {
// //
}} ></a>, }}
], >
}
] </a>,
); ],
},
]);
}, [data]); }, [data]);
/** 获取列数据初始值 */ /** 获取列数据初始值 */
const getInitialValues = (cols: any[], vals: any) => { const getInitialValues = (cols: any[], vals: any) => {
console.log('getInitialValues-columns', columns) console.log('getInitialValues-columns', columns);
console.log('getInitialValues-values', vals) console.log('getInitialValues-values', vals);
const initialValues: any[] = []; const initialValues: any[] = [];
cols.forEach((column: { dataIndex: string; }) => { cols.forEach((column: { dataIndex: string }) => {
const key: any = column?.dataIndex || ''; const key: any = column?.dataIndex || '';
initialValues.push({...column, initialValue: key ? vals[key] : ''}) initialValues.push({ ...column, initialValue: key ? vals[key] : '' });
}) });
console.log('initialValues::',initialValues) console.log('initialValues::', initialValues);
return initialValues || [] return initialValues || [];
} };
return ( return (
<PageContainer> <PageContainer>
<ProTable<TableListItem | any> <ProTable<TableListItem | any>
@ -135,43 +163,52 @@ export default () => {
/*toolbar={{ /*toolbar={{
title: '高级表格', title: '高级表格',
tooltip: '这是一个标题提示', tooltip: '这是一个标题提示',
}}*/ }}*/
toolBarRender={() => [ toolBarRender={() => [
<Button type="primary" key="primary" onClick={() => { <Button
console.log('columns::::', columns); type="primary"
setShowCreate(true) key="primary"
}}><PlusOutlined /> </Button> onClick={() => {
console.log('columns::::', columns);
setShowCreate(true);
}}
>
<PlusOutlined /> {' '}
</Button>,
]} ]}
/> />
<Modal <Modal
title={currentRow?.name || '详细'} title={currentRow?.name || '详细'}
width='60%' width="60%"
visible={showDetail} visible={showDetail}
onCancel={() => { onCancel={() => {
setCurrentRow(undefined); // 设置当前行 setCurrentRow(undefined); // 设置当前行
setShowDetail(false); setShowDetail(false);
}} }}
footer={null}> footer={null}
>
{currentRow?.name && ( {currentRow?.name && (
<ProDescriptions<TableListItem> <ProDescriptions<TableListItem>
column={2} column={2}
/* title={currentRow?.name} */ /* title={currentRow?.name} */
dataSource={currentRow} dataSource={currentRow}
/* /*
request={async () => ({ request={async () => ({
data: currentRow || {}, data: currentRow || {},
})}*/ })}*/
params={{ params={{
id: currentRow?.id, id: currentRow?.id,
}} }}
columns={columns.slice(0, columns.length - 1) as ProDescriptionsItemProps<TableListItem>[]} columns={
/> columns.slice(0, columns.length - 1) as ProDescriptionsItemProps<TableListItem>[]
)} }
/>
)}
</Modal> </Modal>
<Modal <Modal
title='新建考点' title="新建考点"
// //
width='60%' width="60%"
visible={showCreate} visible={showCreate}
destroyOnClose destroyOnClose
onCancel={() => { onCancel={() => {
@ -179,10 +216,10 @@ export default () => {
}} }}
footer={null} footer={null}
> >
<BetaSchemaForm<DataItem> <BetaSchemaForm<DataItem>
layout = 'horizontal' layout="horizontal"
layoutType = 'Form' layoutType="Form"
labelCol = {{ span: 8 }} labelCol={{ span: 8 }}
wrapperCol={{ span: 12 }} wrapperCol={{ span: 12 }}
onFinish={async (values) => { onFinish={async (values) => {
console.log(values); console.log(values);
@ -197,45 +234,45 @@ export default () => {
), ),
}} }}
// action = '' // action = ''
title = "新建" title="新建"
columns = {columns} columns={columns}
/> />
</Modal> </Modal>
<Modal <Modal
title='编辑' title="编辑"
width='60%' width="60%"
visible={showUpdate} visible={showUpdate}
destroyOnClose destroyOnClose
onCancel={() => { onCancel={() => {
setShowUpdate(false); setShowUpdate(false);
}} }}
footer={null}> footer={null}
>
{currentRow?.name && ( {currentRow?.name && (
<BetaSchemaForm<DataItem> <BetaSchemaForm<DataItem>
layout = 'horizontal' layout="horizontal"
layoutType = 'Form' layoutType="Form"
labelCol = {{ span: 8 }} labelCol={{ span: 8 }}
wrapperCol={{ span: 12 }} wrapperCol={{ span: 12 }}
onFinish={async (values) => { onFinish={async (values) => {
console.log(values); console.log(values);
}} }}
submitter={{ submitter={{
render: (props, doms) => ( render: (props, doms) => (
<Row> <Row>
<Col span={12} offset={8}> <Col span={12} offset={8}>
<Space>{doms}</Space> <Space>{doms}</Space>
</Col> </Col>
</Row> </Row>
), ),
}} }}
// action = '' // action = ''
title = "编辑" title="编辑"
columns = {getInitialValues(columns, currentRow)} columns={getInitialValues(columns, currentRow)}
/> />
)} )}
</Modal> </Modal>
</PageContainer>
</PageContainer>
); );
}; };

@ -2,12 +2,6 @@
/* eslint-disable */ /* eslint-disable */
import { request } from 'umi'; import { request } from 'umi';
import { TableListItem } from './data'; import { TableListItem } from './data';
import type { ProFormColumnsType } from '@ant-design/pro-form';
type DataItem = {
name: string;
state: string;
};
/** 获取考点数据结构 GET /api/dataSource?key=examination&schema=true&data=false */ /** 获取考点数据结构 GET /api/dataSource?key=examination&schema=true&data=false */
export async function schemaExamination( export async function schemaExamination(
@ -56,7 +50,10 @@ export async function dataExamination(
} }
/** 新建考点 PUT /api/dataSource?key=examination */ /** 新建考点 PUT /api/dataSource?key=examination */
export async function updateExamination(data: { [key: string]: any }, options?: { [key: string]: any }) { export async function updateExamination(
data: { [key: string]: any },
options?: { [key: string]: any },
) {
return request<TableListItem>('/api/examination', { return request<TableListItem>('/api/examination', {
data, data,
method: 'PUT', method: 'PUT',
@ -65,7 +62,10 @@ export async function updateExamination(data: { [key: string]: any }, options?:
} }
/** 新建考点 POST /api/dataSource?key=examination */ /** 新建考点 POST /api/dataSource?key=examination */
export async function addExamination(data: { [key: string]: any }, options?: { [key: string]: any }) { export async function addExamination(
data: { [key: string]: any },
options?: { [key: string]: any },
) {
return request<TableListItem>('/api/examination', { return request<TableListItem>('/api/examination', {
data, data,
method: 'POST', method: 'POST',

@ -1,8 +1,4 @@
import { import { LockOutlined, MobileOutlined, UserOutlined } from '@ant-design/icons';
LockOutlined,
MobileOutlined,
UserOutlined,
} from '@ant-design/icons';
import { Alert, message, Tabs } from 'antd'; import { Alert, message, Tabs } from 'antd';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { ProFormCaptcha, ProFormCheckbox, ProFormText, LoginForm } from '@ant-design/pro-form'; import { ProFormCaptcha, ProFormCheckbox, ProFormText, LoginForm } from '@ant-design/pro-form';
@ -48,10 +44,7 @@ const Login: React.FC = () => {
// 登录 // 登录
const msg = await login({ ...values, type }); const msg = await login({ ...values, type });
if (msg.status === 'ok') { if (msg.status === 'ok') {
const defaultLoginSuccessMessage = intl.formatMessage({ const defaultLoginSuccessMessage = '登录成功!';
id: 'pages.login.success',
defaultMessage: '登录成功!',
});
message.success(defaultLoginSuccessMessage); message.success(defaultLoginSuccessMessage);
await fetchUserInfo(); await fetchUserInfo();
/** 此方法会跳转到 redirect 参数所在的位置 */ /** 此方法会跳转到 redirect 参数所在的位置 */
@ -65,10 +58,7 @@ const Login: React.FC = () => {
// 如果失败去设置用户错误信息 // 如果失败去设置用户错误信息
setUserLoginState(msg); setUserLoginState(msg);
} catch (error) { } catch (error) {
const defaultLoginFailureMessage = intl.formatMessage({ const defaultLoginFailureMessage = '登录失败,请重试!';
id: 'pages.login.failure',
defaultMessage: '登录失败,请重试!',
});
message.error(defaultLoginFailureMessage); message.error(defaultLoginFailureMessage);
} }
}; };
@ -82,36 +72,23 @@ const Login: React.FC = () => {
<div className={styles.content}> <div className={styles.content}>
<LoginForm <LoginForm
logo={<img alt="logo" src="/logo.svg" />} logo={<img alt="logo" src="/logo.svg" />}
title="基础数据" title="大数据上报平台"
subTitle="DSBase Universal V1.0" subTitle="考务管理 V1.0.0"
initialValues={{ initialValues={{
autoLogin: true, autoLogin: true,
}} }}
actions={[ actions={[]}
]}
onFinish={async (values) => { onFinish={async (values) => {
await handleSubmit(values as API.LoginParams); await handleSubmit(values as API.LoginParams);
}} }}
> >
<Tabs activeKey={type} onChange={setType}> <Tabs activeKey={type} onChange={setType}>
<Tabs.TabPane <Tabs.TabPane key="account" tab="账户密码登录" />
key="account" <Tabs.TabPane key="mobile" tab="手机号登录" />
tab='账户密码登录'
/>
<Tabs.TabPane
key="mobile"
tab='手机号登录'
/>
</Tabs> </Tabs>
{status === 'error' && loginType === 'account' && ( {status === 'error' && loginType === 'account' && (
<LoginMessage <LoginMessage content="账户或密码错误(admin/ant.design)" />
content={intl.formatMessage({
id: 'pages.login.accountLogin.errorMessage',
defaultMessage: '账户或密码错误(admin/ant.design)',
})}
/>
)} )}
{type === 'account' && ( {type === 'account' && (
<> <>
@ -122,10 +99,7 @@ const Login: React.FC = () => {
size: 'large', size: 'large',
prefix: <UserOutlined className={styles.prefixIcon} />, prefix: <UserOutlined className={styles.prefixIcon} />,
}} }}
placeholder={intl.formatMessage({ placeholder="用户名: admin or user"
id: 'pages.login.username.placeholder',
defaultMessage: '用户名: admin or user',
})}
rules={[ rules={[
{ {
required: true, required: true,
@ -145,10 +119,7 @@ const Login: React.FC = () => {
size: 'large', size: 'large',
prefix: <LockOutlined className={styles.prefixIcon} />, prefix: <LockOutlined className={styles.prefixIcon} />,
}} }}
placeholder={intl.formatMessage({ placeholder="密码: ant.design"
id: 'pages.login.password.placeholder',
defaultMessage: '密码: ant.design',
})}
rules={[ rules={[
{ {
required: true, required: true,
@ -252,14 +223,14 @@ const Login: React.FC = () => {
}} }}
> >
<ProFormCheckbox noStyle name="autoLogin"> <ProFormCheckbox noStyle name="autoLogin">
<FormattedMessage id="pages.login.rememberMe" defaultMessage="自动登录" /> <></>
</ProFormCheckbox> </ProFormCheckbox>
<a <a
style={{ style={{
float: 'right', float: 'right',
}} }}
> >
<FormattedMessage id="pages.login.forgotPassword" defaultMessage="忘记密码" /> <></>
</a> </a>
</div> </div>
</LoginForm> </LoginForm>

Loading…
Cancel
Save