feat: login page

This commit is contained in:
jialin
2024-06-03 09:06:41 +08:00
parent 69f354b278
commit d2212fe949
15 changed files with 147 additions and 23 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ export default (initialState: API.UserInfo) => {
initialState && initialState.name !== 'dontHaveAccess'
);
return {
canSeeAdmin
canSeeAdmin,
canDelete: true
};
};
+11 -4
View File
@@ -1,20 +1,27 @@
import { Button, Space } from 'antd';
type FormButtonsProps = {
onOk: () => void;
onCancel: () => void;
onOk?: () => void;
onCancel?: () => void;
cancelText?: string;
okText?: string;
htmlType?: 'submit' | 'button';
};
const FormButtons: React.FC<FormButtonsProps> = ({
onOk,
onCancel,
cancelText,
okText
okText,
htmlType = 'button'
}) => {
return (
<Space size={40} style={{ marginTop: '80px' }}>
<Button type="primary" onClick={onOk} style={{ width: '120px' }}>
<Button
type="primary"
onClick={onOk}
style={{ width: '120px' }}
htmlType={htmlType}
>
{okText || '保存'}
</Button>
<Button onClick={onCancel} style={{ width: '98px' }}>
@@ -1,6 +1,7 @@
:local(.wrapper) {
@wrapheight: 54px;
@inputheight: 32px;
@borderRadius: 24px;
position: relative;
display: flex;
flex-direction: column;
@@ -9,7 +10,7 @@
border-width: var(--ant-line-width);
border-style: var(--ant-line-type);
border-color: var(--ant-color-border);
border-radius: 28px;
border-radius: @borderRadius;
padding-inline: 12px;
padding-block: 20px 0;
@@ -121,6 +122,13 @@
height: @inputheight !important;
}
:global(.ant-input-outlined) {
display: flex;
align-items: center;
border: none;
box-shadow: none;
padding-block: 5px;
padding-inline: 12px;
height: @inputheight !important;
&.seal-textarea {
min-height: 100px !important;
}
@@ -138,7 +146,7 @@
}
:global(.ant-input-group-addon) {
inset-inline-start: unset !important;
border-radius: 0 28px 28px 0;
border-radius: 0 @borderRadius @borderRadius 0;
width: 30px;
background-color: transparent;
}
@@ -155,7 +163,7 @@
position: absolute;
top: -20px;
right: -11px;
border-radius: 0 28px 28px 0 !important;
border-radius: 0 @borderRadius @borderRadius 0 !important;
overflow: hidden;
border: none;
height: 52px;
@@ -170,4 +178,9 @@
:global(.ant-input-group-addon) {
border: none;
}
:global(.ant-input-prefix) {
position: absolute;
top: 1px;
left: -4px;
}
}
+3 -1
View File
@@ -20,7 +20,9 @@ const SealInputNumber: React.FC<InputNumberProps & SealFormItemProps> = (
const handleClickWrapper = () => {
if (!props.disabled && !isFocus) {
inputRef.current?.focus?.();
inputRef.current?.focus?.({
cursor: 'all'
});
setIsFocus(true);
}
};
+3 -1
View File
@@ -18,7 +18,9 @@ const SealPassword: React.FC<InputProps & SealFormItemProps> = (props) => {
const handleClickWrapper = () => {
if (!props.disabled && !isFocus) {
inputRef.current?.focus?.();
inputRef.current?.focus?.({
cursor: 'all'
});
setIsFocus(true);
}
};
+6 -2
View File
@@ -33,7 +33,9 @@ const SealTextArea: React.FC<TextAreaProps & SealFormItemProps> = (props) => {
const handleClickWrapper = useCallback(() => {
if (!props.disabled && !isFocus) {
inputRef.current?.focus?.();
inputRef.current?.focus?.({
cursor: 'all'
});
setIsFocus(true);
}
}, [props.disabled, isFocus]);
@@ -109,7 +111,9 @@ const SealInput: React.FC<InputProps & SealFormItemProps> = (props) => {
const handleClickWrapper = () => {
if (!props.disabled && !isFocus) {
inputRef.current?.focus?.();
inputRef.current?.focus?.({
cursor: 'all'
});
setIsFocus(true);
}
};
+8
View File
@@ -8,6 +8,7 @@ import { ProLayout } from '@ant-design/pro-components';
import {
Link,
Outlet,
history,
matchRoutes,
useAppData,
useLocation,
@@ -21,6 +22,8 @@ import Logo from './Logo';
import { getRightRenderContent } from './rightRender';
import { patchRoutes } from './runtime';
const loginPath = '/login';
// 过滤出需要显示的路由, 这里的filterFn 指 不希望显示的层级
const filterRoutes = (
routes: IRoute[],
@@ -150,6 +153,11 @@ export default (props: any) => {
}}
onPageChange={(route) => {
console.log('onRouteChange', route);
const { location } = history;
// 如果没有登录,重定向到 login
// if (!initialState?.currentUser && location.pathname !== loginPath) {
// history.push(loginPath);
// }
}}
formatMessage={userConfig.formatMessage || formatMessage}
menu={{ locale: userConfig.locale }}
+12 -9
View File
@@ -10,7 +10,7 @@ import {
WechatWorkOutlined
} from '@ant-design/icons';
import { PageContainer } from '@ant-design/pro-components';
import { useIntl, useNavigate } from '@umijs/max';
import { Access, useAccess, useIntl, useNavigate } from '@umijs/max';
import {
App,
Button,
@@ -48,6 +48,7 @@ const dataSource = [
const Models: React.FC = () => {
const { modal } = App.useApp();
const access = useAccess();
const intl = useIntl();
const navigate = useNavigate();
const rowSelection = useTableRowSelection();
@@ -164,14 +165,16 @@ const Models: React.FC = () => {
>
{intl?.formatMessage?.({ id: 'models.button.deploy' })}
</Button>
<Button
icon={<DeleteOutlined />}
danger
onClick={handleDelete}
disabled={!rowSelection.selectedRowKeys.length}
>
Delete
</Button>
<Access accessible={access.canDelete}>
<Button
icon={<DeleteOutlined />}
danger
onClick={handleDelete}
disabled={!rowSelection.selectedRowKeys.length}
>
Delete
</Button>
</Access>
</Space>
}
></PageTools>
+61
View File
@@ -0,0 +1,61 @@
import LogoIcon from '@/assets/images/logo.png';
import SealInput from '@/components/seal-form/seal-input';
import { LockOutlined, UserOutlined } from '@ant-design/icons';
import { Button, Checkbox, Form } from 'antd';
const renderLogo = () => {
return (
<div
style={{
width: '400px',
display: 'flex',
marginBottom: 24,
justifyContent: 'center',
alignItems: 'center'
}}
>
<img src={LogoIcon} alt="logo" style={{ width: '44px' }} />
<span style={{ fontSize: 34, marginLeft: 12 }}>SEAL</span>
</div>
);
};
const Login = () => {
return (
<Form style={{ width: '400px', margin: '5% auto 0' }}>
<div>{renderLogo()}</div>
<Form.Item
name="username"
rules={[
{
required: true,
message: 'Please input your Username!'
}
]}
>
<SealInput.Input label="Username" prefix={<UserOutlined />} />
</Form.Item>
<Form.Item
name="password"
rules={[
{
required: true,
message: 'Please input your Password!'
}
]}
>
<SealInput.Password prefix={<LockOutlined />} label="Password" />
</Form.Item>
<Form.Item name="autoLogin">
<div style={{ paddingLeft: 10 }}>
<Checkbox>Auto login</Checkbox>
</div>
</Form.Item>
<Button htmlType="submit" type="primary" block>
Login
</Button>
</Form>
);
};
export default Login;
@@ -1,3 +1,4 @@
import SealInput from '@/components/seal-form/seal-input';
import { PageContainer } from '@ant-design/pro-components';
import { useState } from 'react';
import '../style/ground-left.less';
@@ -54,6 +55,9 @@ const MessageList: React.FC = () => {
return (
<div className="ground-left">
<PageContainer title={false} className="message-list-wrap">
<div style={{ marginBottom: '40px' }}>
<SealInput.TextArea label="Message"></SealInput.TextArea>
</div>
<div>
{messageList.map((item, index) => {
return (
+4 -1
View File
@@ -21,6 +21,9 @@ const Profile: React.FC = () => {
const handleOnFinishFailed = (errorInfo: any) => {
console.log('handleOnFinishFailed', errorInfo);
};
const handleCancel = () => {
form.resetFields();
};
return (
<StrictMode>
@@ -69,8 +72,8 @@ const Profile: React.FC = () => {
style={{ width: INPUT_WIDTH.default }}
></SealInput.Password>
</Form.Item>
<FormButtons htmlType="submit" onCancel={handleCancel}></FormButtons>
</Form>
<FormButtons></FormButtons>
</PageContainer>
</StrictMode>
);