@wzyjs/pages 0.2.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +20 -0
- package/src/Login/index.tsx +134 -0
- package/src/Login/utils.ts +21 -0
- package/src/NotFound/index.tsx +17 -0
- package/src/index.ts +2 -0
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wzyjs/pages",
|
|
3
|
+
"version": "0.2.41",
|
|
4
|
+
"description": "description",
|
|
5
|
+
"author": "wzy",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"@wzyjs/antd": "^0.2.37",
|
|
12
|
+
"@wzyjs/hooks": "^0.2.37",
|
|
13
|
+
"@wzyjs/types": "^0.2.37",
|
|
14
|
+
"@wzyjs/utils": "^0.2.37"
|
|
15
|
+
},
|
|
16
|
+
"gitHead": "22795bdb9c670d3e37e9a6e83b544f916bab3c16",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useRef } from 'react'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
// Spin,
|
|
7
|
+
Alert,
|
|
8
|
+
LockOutlined,
|
|
9
|
+
UserOutlined,
|
|
10
|
+
ProFormInstance,
|
|
11
|
+
LoginForm,
|
|
12
|
+
ProCard,
|
|
13
|
+
ProFormCheckbox,
|
|
14
|
+
ProFormText,
|
|
15
|
+
} from '@wzyjs/antd'
|
|
16
|
+
|
|
17
|
+
import { md5 } from '@wzyjs/utils'
|
|
18
|
+
import { useAsyncEffect } from '@wzyjs/hooks'
|
|
19
|
+
import { defaultBackgroundImageUrl, getRememberUserInfo, rememberUserInfo, Values } from './utils'
|
|
20
|
+
import React from 'react'
|
|
21
|
+
|
|
22
|
+
export interface LoginPageProps<U> {
|
|
23
|
+
backgroundImageUrl?: string | false,
|
|
24
|
+
onSuccess?: (userInfo: U) => void,
|
|
25
|
+
apis: {
|
|
26
|
+
login: (values: Values) => Promise<any>,
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const LoginPage = <U extends any>(props: LoginPageProps<U>) => {
|
|
31
|
+
const {
|
|
32
|
+
apis,
|
|
33
|
+
onSuccess,
|
|
34
|
+
backgroundImageUrl = defaultBackgroundImageUrl,
|
|
35
|
+
} = props
|
|
36
|
+
|
|
37
|
+
const formRef = useRef<ProFormInstance<Values>>(null)
|
|
38
|
+
|
|
39
|
+
// const { runAsync, loading } = useRequestPro(apis.login, {
|
|
40
|
+
// manual: true,
|
|
41
|
+
// alertSuccessMessage: true,
|
|
42
|
+
// })
|
|
43
|
+
|
|
44
|
+
// 读取本地账号密码填充到表单
|
|
45
|
+
useAsyncEffect(async () => {
|
|
46
|
+
formRef.current?.setFieldsValue(await getRememberUserInfo())
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
// 点击登录
|
|
50
|
+
const onFinish = async (values: Values) => {
|
|
51
|
+
values.name = values.name.trim()
|
|
52
|
+
values.password = md5(values.password.trim())
|
|
53
|
+
|
|
54
|
+
// const res = await runAsync(values)
|
|
55
|
+
// if (!res?.data || !res?.success) {
|
|
56
|
+
// return false
|
|
57
|
+
// }
|
|
58
|
+
|
|
59
|
+
// onSuccess?.(res.data)
|
|
60
|
+
rememberUserInfo(values)
|
|
61
|
+
return true
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div
|
|
66
|
+
style={{
|
|
67
|
+
position: 'fixed',
|
|
68
|
+
top: 0,
|
|
69
|
+
left: 0,
|
|
70
|
+
bottom: 0,
|
|
71
|
+
right: 0,
|
|
72
|
+
background: backgroundImageUrl ? `url('${backgroundImageUrl}') round` : '',
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
<ProCard
|
|
76
|
+
hoverable
|
|
77
|
+
bodyStyle={{ padding: 0 }}
|
|
78
|
+
style={{
|
|
79
|
+
backgroundColor: '#fff',
|
|
80
|
+
width: 500,
|
|
81
|
+
padding: 50,
|
|
82
|
+
margin: '15% auto',
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
{/*<Spin spinning={loading}>*/}
|
|
86
|
+
<LoginForm
|
|
87
|
+
formRef={formRef}
|
|
88
|
+
title={(
|
|
89
|
+
<div style={{ marginBlockEnd: 20 }}>登录</div>
|
|
90
|
+
)}
|
|
91
|
+
onFinish={onFinish}
|
|
92
|
+
message={(
|
|
93
|
+
<Alert style={{ marginBlockEnd: 24 }} message='tip: 未注册的账号登录将会自动注册' />
|
|
94
|
+
)}
|
|
95
|
+
>
|
|
96
|
+
<ProFormText
|
|
97
|
+
name='name'
|
|
98
|
+
fieldProps={{
|
|
99
|
+
size: 'large',
|
|
100
|
+
prefix: <UserOutlined rev={undefined} />,
|
|
101
|
+
}}
|
|
102
|
+
placeholder='用户名'
|
|
103
|
+
rules={[
|
|
104
|
+
{
|
|
105
|
+
required: true,
|
|
106
|
+
message: '请输入用户名!',
|
|
107
|
+
},
|
|
108
|
+
]}
|
|
109
|
+
/>
|
|
110
|
+
<ProFormText.Password
|
|
111
|
+
name='password'
|
|
112
|
+
fieldProps={{
|
|
113
|
+
size: 'large',
|
|
114
|
+
prefix: <LockOutlined rev={undefined} />,
|
|
115
|
+
}}
|
|
116
|
+
placeholder='密码'
|
|
117
|
+
rules={[
|
|
118
|
+
{
|
|
119
|
+
required: true,
|
|
120
|
+
message: '请输入密码!',
|
|
121
|
+
},
|
|
122
|
+
]}
|
|
123
|
+
/>
|
|
124
|
+
<div style={{ marginBlockEnd: 24 }}>
|
|
125
|
+
<ProFormCheckbox noStyle name='remember'>
|
|
126
|
+
30天内自动登录
|
|
127
|
+
</ProFormCheckbox>
|
|
128
|
+
</div>
|
|
129
|
+
</LoginForm>
|
|
130
|
+
{/*</Spin>*/}
|
|
131
|
+
</ProCard>
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { localforage } from '@wzyjs/utils'
|
|
2
|
+
|
|
3
|
+
export interface Values {
|
|
4
|
+
name: string,
|
|
5
|
+
password: string,
|
|
6
|
+
remember?: boolean,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const localStorageKey = 'loginInfo'
|
|
10
|
+
|
|
11
|
+
export const defaultBackgroundImageUrl = 'https://www.helloweba.net/demo/2018/logins/v1/images/bg-01.jpg'
|
|
12
|
+
|
|
13
|
+
export const rememberUserInfo = (values: Values) => {
|
|
14
|
+
localforage.setItem(localStorageKey, { name: values.name })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getRememberUserInfo = async (): Promise<Values> => {
|
|
18
|
+
const values = await localforage.getItem<Values | null>(localStorageKey) || {} as Values
|
|
19
|
+
values.remember = true
|
|
20
|
+
return values
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { Button, Result } from 'antd'
|
|
5
|
+
|
|
6
|
+
export const NotFound = () => (
|
|
7
|
+
<Result
|
|
8
|
+
status='404'
|
|
9
|
+
title='404'
|
|
10
|
+
subTitle='Sorry, 这个页面找不到啦~'
|
|
11
|
+
extra={
|
|
12
|
+
<Button type='primary' onClick={() => window.location.href = '/'}>
|
|
13
|
+
回到首页
|
|
14
|
+
</Button>
|
|
15
|
+
}
|
|
16
|
+
/>
|
|
17
|
+
)
|
package/src/index.ts
ADDED