zhengpengju 4 years ago
parent d82dbc7f92
commit 77637f401f

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

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

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

@ -2,12 +2,6 @@
/* eslint-disable */
import { request } from 'umi';
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 */
export async function schemaExamination(
@ -56,7 +50,10 @@ export async function dataExamination(
}
/** 新建考点 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', {
data,
method: 'PUT',
@ -65,7 +62,10 @@ export async function updateExamination(data: { [key: string]: any }, options?:
}
/** 新建考点 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', {
data,
method: 'POST',

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

Loading…
Cancel
Save