@jiangood/open-admin 1.0.0
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/config/dist/common-plugin.js +148 -0
- package/config/dist/config.js +45 -0
- package/config/dist/index.js +18 -0
- package/package.json +41 -0
- package/src/app.js +1 -0
- package/src/asserts/welcome.png +0 -0
- package/src/forms/demoForm.jsx +16 -0
- package/src/framework/components/DownloadFileButton.d.ts +11 -0
- package/src/framework/components/DownloadFileButton.jsx +33 -0
- package/src/framework/components/Ellipsis.jsx +39 -0
- package/src/framework/components/Ellipsis.less +8 -0
- package/src/framework/components/Gap/index.d.ts +23 -0
- package/src/framework/components/Gap/index.jsx +46 -0
- package/src/framework/components/LinkButton.d.ts +14 -0
- package/src/framework/components/LinkButton.jsx +10 -0
- package/src/framework/components/NamedIcon.tsx +15 -0
- package/src/framework/components/Page/index.d.ts +17 -0
- package/src/framework/components/Page/index.jsx +30 -0
- package/src/framework/components/Page/index.less +10 -0
- package/src/framework/components/PageLoading.tsx +27 -0
- package/src/framework/components/ProModal/index.tsx +66 -0
- package/src/framework/components/ProTable/components/ToolBar/index.jsx +123 -0
- package/src/framework/components/ProTable/components/ToolBar/index.less +53 -0
- package/src/framework/components/ProTable/index.d.ts +42 -0
- package/src/framework/components/ProTable/index.jsx +260 -0
- package/src/framework/components/ProTable/index.less +14 -0
- package/src/framework/components/ProTable/utils/index.js +43 -0
- package/src/framework/components/ValueType/index.jsx +34 -0
- package/src/framework/components/ValueType/registry.jsx +27 -0
- package/src/framework/components/index.ts +17 -0
- package/src/framework/components/system/ButtonList.d.ts +8 -0
- package/src/framework/components/system/ButtonList.jsx +42 -0
- package/src/framework/components/system/HasPerm.tsx +14 -0
- package/src/framework/components/system/index.tsx +29 -0
- package/src/framework/components/view/ViewBooleanEnableDisable.tsx +20 -0
- package/src/framework/components/view/ViewEllipsis.d.ts +11 -0
- package/src/framework/components/view/ViewEllipsis.jsx +30 -0
- package/src/framework/components/view/ViewFile.d.ts +10 -0
- package/src/framework/components/view/ViewFile.jsx +49 -0
- package/src/framework/components/view/ViewFileButton.d.ts +10 -0
- package/src/framework/components/view/ViewFileButton.jsx +0 -0
- package/src/framework/components/view/ViewImage.d.ts +9 -0
- package/src/framework/components/view/ViewImage.jsx +60 -0
- package/src/framework/components/view/ViewRange/index.d.ts +16 -0
- package/src/framework/components/view/ViewRange/index.jsx +20 -0
- package/src/framework/components/view/ViewText.tsx +16 -0
- package/src/framework/components/view/index.ts +10 -0
- package/src/framework/field-components/FieldBoolean.d.ts +13 -0
- package/src/framework/field-components/FieldBoolean.jsx +76 -0
- package/src/framework/field-components/FieldDate.d.ts +27 -0
- package/src/framework/field-components/FieldDate.jsx +114 -0
- package/src/framework/field-components/FieldDateRange.d.ts +6 -0
- package/src/framework/field-components/FieldDateRange.jsx +104 -0
- package/src/framework/field-components/FieldDictSelect.d.ts +13 -0
- package/src/framework/field-components/FieldDictSelect.jsx +16 -0
- package/src/framework/field-components/FieldEditor.d.ts +10 -0
- package/src/framework/field-components/FieldEditor.jsx +58 -0
- package/src/framework/field-components/FieldNumberRange.d.ts +13 -0
- package/src/framework/field-components/FieldNumberRange.jsx +59 -0
- package/src/framework/field-components/FieldPercent.d.ts +12 -0
- package/src/framework/field-components/FieldPercent.jsx +27 -0
- package/src/framework/field-components/FieldRemoteSelect.d.ts +13 -0
- package/src/framework/field-components/FieldRemoteSelect.jsx +87 -0
- package/src/framework/field-components/FieldRemoteSelectMultiple.d.ts +13 -0
- package/src/framework/field-components/FieldRemoteSelectMultiple.jsx +86 -0
- package/src/framework/field-components/FieldRemoteSelectMultipleInline.d.ts +20 -0
- package/src/framework/field-components/FieldRemoteSelectMultipleInline.jsx +86 -0
- package/src/framework/field-components/FieldRemoteTree.d.ts +21 -0
- package/src/framework/field-components/FieldRemoteTree.jsx +45 -0
- package/src/framework/field-components/FieldRemoteTreeCascader.d.ts +23 -0
- package/src/framework/field-components/FieldRemoteTreeCascader.jsx +61 -0
- package/src/framework/field-components/FieldRemoteTreeSelect.d.ts +17 -0
- package/src/framework/field-components/FieldRemoteTreeSelect.jsx +67 -0
- package/src/framework/field-components/FieldRemoteTreeSelectMultiple.d.ts +17 -0
- package/src/framework/field-components/FieldRemoteTreeSelectMultiple.jsx +72 -0
- package/src/framework/field-components/FieldSysOrgTree.d.ts +12 -0
- package/src/framework/field-components/FieldSysOrgTree.jsx +23 -0
- package/src/framework/field-components/FieldSysOrgTreeSelect.d.ts +12 -0
- package/src/framework/field-components/FieldSysOrgTreeSelect.jsx +23 -0
- package/src/framework/field-components/FieldTable.d.ts +17 -0
- package/src/framework/field-components/FieldTable.jsx +108 -0
- package/src/framework/field-components/FieldTable.less +29 -0
- package/src/framework/field-components/FieldTableSelect.d.ts +19 -0
- package/src/framework/field-components/FieldTableSelect.jsx +59 -0
- package/src/framework/field-components/FieldUploadFile.d.ts +34 -0
- package/src/framework/field-components/FieldUploadFile.jsx +141 -0
- package/src/framework/field-components/index.ts +21 -0
- package/src/framework/field-components/system/OrgTree.tsx +61 -0
- package/src/framework/field-components/system/RoleTree.tsx +53 -0
- package/src/framework/field-components/system/index.ts +2 -0
- package/src/framework/index.ts +5 -0
- package/src/framework/pages/LoginPage.d.ts +16 -0
- package/src/framework/pages/LoginPage.jsx +135 -0
- package/src/framework/pages/LoginPage.less +53 -0
- package/src/framework/pages/LoginPageUtils.ts +36 -0
- package/src/framework/pages/index.ts +2 -0
- package/src/framework/utils/ArrUtils.ts +229 -0
- package/src/framework/utils/ColorsUtils.ts +378 -0
- package/src/framework/utils/DateUtils.ts +187 -0
- package/src/framework/utils/DeviceUtils.ts +46 -0
- package/src/framework/utils/DomUtils.ts +50 -0
- package/src/framework/utils/EventBusUtils.ts +144 -0
- package/src/framework/utils/Logger.ts +40 -0
- package/src/framework/utils/MessageUtils.tsx +170 -0
- package/src/framework/utils/ObjectUtils.ts +118 -0
- package/src/framework/utils/StorageUtils.ts +50 -0
- package/src/framework/utils/StringUtils.ts +436 -0
- package/src/framework/utils/TreeUtils.ts +251 -0
- package/src/framework/utils/UrlUtils.ts +152 -0
- package/src/framework/utils/UuidUtils.ts +88 -0
- package/src/framework/utils/ValidateUtils.ts +28 -0
- package/src/framework/utils/index.ts +16 -0
- package/src/framework/utils/system/DictUtils.ts +97 -0
- package/src/framework/utils/system/FormRegistryUtils.ts +77 -0
- package/src/framework/utils/system/HttpUtils.ts +247 -0
- package/src/framework/utils/system/PageUtils.ts +163 -0
- package/src/framework/utils/system/PermUtils.ts +79 -0
- package/src/framework/utils/system/SysUtils.ts +97 -0
- package/src/framework/utils/system/ThemeUtils.ts +27 -0
- package/src/framework/utils/system/index.ts +7 -0
- package/src/framework/view-components/ViewApproveStatus.tsx +26 -0
- package/src/framework/view-components/ViewBoolean.tsx +6 -0
- package/src/framework/view-components/ViewFlowableInstanceProgress.d.ts +12 -0
- package/src/framework/view-components/ViewFlowableInstanceProgress.jsx +97 -0
- package/src/framework/view-components/ViewFlowableInstanceProgressButton.tsx +26 -0
- package/src/framework/view-components/ViewPassword.tsx +25 -0
- package/src/framework/view-components/ViewProps.ts +11 -0
- package/src/framework/view-components/index.ts +6 -0
- package/src/index.ts +2 -0
- package/src/layouts/PageRender.d.ts +22 -0
- package/src/layouts/PageRender.jsx +90 -0
- package/src/layouts/admin/HeaderRight.jsx +104 -0
- package/src/layouts/admin/TabPageRender.jsx +158 -0
- package/src/layouts/admin/index.jsx +161 -0
- package/src/layouts/admin/index.less +65 -0
- package/src/layouts/index.jsx +165 -0
- package/src/layouts/index.less +24 -0
- package/src/loading.jsx +18 -0
- package/src/pages/404.jsx +13 -0
- package/src/pages/about.jsx +14 -0
- package/src/pages/index.jsx +25 -0
- package/src/pages/login.jsx +21 -0
- package/src/pages/system/api/ApiDoc.jsx +144 -0
- package/src/pages/system/api/index.jsx +268 -0
- package/src/pages/system/api/perm.jsx +69 -0
- package/src/pages/system/dict/Dict.jsx +72 -0
- package/src/pages/system/dict/DictItem.jsx +177 -0
- package/src/pages/system/dict/index.jsx +25 -0
- package/src/pages/system/file/index.jsx +160 -0
- package/src/pages/system/job/index.jsx +324 -0
- package/src/pages/system/log/index.jsx +78 -0
- package/src/pages/system/org/index.jsx +262 -0
- package/src/pages/system/role/index.jsx +308 -0
- package/src/pages/system/role/perm.jsx +108 -0
- package/src/pages/system/sysManual/index.jsx +127 -0
- package/src/pages/system/user/UserPerm.jsx +97 -0
- package/src/pages/system/user/index.jsx +258 -0
- package/src/pages/test.jsx +200 -0
- package/src/pages/ureport/index.jsx +16 -0
- package/src/pages/userCenter/ChangePassword.jsx +63 -0
- package/src/pages/userCenter/index.jsx +90 -0
- package/src/pages/userCenter/manual.jsx +59 -0
- package/src/pages/userCenter/message.jsx +105 -0
- package/src/style/global.less +51 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {Alert, Skeleton, Tree} from 'antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import * as Icons from '@ant-design/icons';
|
|
4
|
+
import {HttpUtils} from "../../utils";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class OrgTree extends React.Component<any, any> {
|
|
8
|
+
|
|
9
|
+
state = {
|
|
10
|
+
treeDataLoading: true,
|
|
11
|
+
treeData: [],
|
|
12
|
+
|
|
13
|
+
currentOrgId: null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
HttpUtils.get('admin/sysOrg/deptTree').then(tree => {
|
|
19
|
+
this.setState({treeData: tree,treeDataLoading: false})
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
onSelectOrg = orgIds => {
|
|
25
|
+
let orgId = orgIds[0] || null;
|
|
26
|
+
this.props.onChange(orgId)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
render() {
|
|
31
|
+
let {treeData, treeDataLoading} = this.state
|
|
32
|
+
if (treeDataLoading) {
|
|
33
|
+
return <Skeleton title='加载中...'/>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (treeData.length === 0) {
|
|
37
|
+
return <Alert type={"warning"} message={'组织机构数据为空'}>
|
|
38
|
+
</Alert>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return <Tree
|
|
42
|
+
treeData={treeData}
|
|
43
|
+
defaultExpandAll
|
|
44
|
+
onSelect={this.onSelectOrg}
|
|
45
|
+
showIcon
|
|
46
|
+
blockNode
|
|
47
|
+
icon={item=>{
|
|
48
|
+
const icon = Icons[item.iconName]
|
|
49
|
+
if(icon){
|
|
50
|
+
return React.createElement(icon)
|
|
51
|
+
}
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
</Tree>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {Skeleton, Tree} from 'antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {SolutionOutlined} from '@ant-design/icons';
|
|
4
|
+
import {HttpUtils} from "../../utils";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class RoleTree extends React.Component<any, any> {
|
|
8
|
+
|
|
9
|
+
state = {
|
|
10
|
+
treeDataLoading: true,
|
|
11
|
+
treeData: [],
|
|
12
|
+
|
|
13
|
+
currentOrgId: null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
HttpUtils.get('admin/sysRole/bizTree').then(tree => {
|
|
19
|
+
this.setState({treeData: tree,treeDataLoading: false})
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onSelect = keys => {
|
|
24
|
+
let orgId = keys[0] || null;
|
|
25
|
+
this.props.onSelect(orgId)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
render() {
|
|
30
|
+
let {treeData, treeDataLoading} = this.state
|
|
31
|
+
if (treeDataLoading) {
|
|
32
|
+
return <Skeleton title='加载中...'/>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
return <Tree
|
|
37
|
+
treeData={treeData}
|
|
38
|
+
defaultExpandAll
|
|
39
|
+
onSelect={this.onSelect}
|
|
40
|
+
showIcon
|
|
41
|
+
blockNode
|
|
42
|
+
icon={item=>{
|
|
43
|
+
return <SolutionOutlined />
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
</Tree>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, {ReactNode} from "react";
|
|
2
|
+
|
|
3
|
+
export interface LoginPageProps {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 表单渲染
|
|
7
|
+
* @param origForm 原始表单
|
|
8
|
+
*/
|
|
9
|
+
formRender?: (originalForm: ReactNode) => ReactNode
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class LoginPage extends React.Component<LoginPageProps, any> {
|
|
15
|
+
}
|
|
16
|
+
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {Button, Form, Input, message, Space} from 'antd';
|
|
3
|
+
import {LockOutlined, SafetyCertificateOutlined, UserOutlined, WarningOutlined} from '@ant-design/icons';
|
|
4
|
+
import "./LoginPage.less"
|
|
5
|
+
import {MessageUtils, SysUtils} from "../utils";
|
|
6
|
+
import {JSEncrypt} from "jsencrypt";
|
|
7
|
+
import {LoginPageUtils} from "./LoginPageUtils";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export class LoginPage extends React.Component {
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
state = {
|
|
14
|
+
logging: false,
|
|
15
|
+
|
|
16
|
+
siteInfo: {},
|
|
17
|
+
random: Math.random()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async componentDidMount() {
|
|
21
|
+
console.log('渲染登录页面')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if (localStorage.length === 0) {
|
|
25
|
+
MessageUtils.alert('站点数据缺失,刷新当前页面...')
|
|
26
|
+
window.location.reload()
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const siteInfo = SysUtils.getSiteInfo()
|
|
31
|
+
this.setState({siteInfo})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
submit = values => {
|
|
36
|
+
this.setState({logging: true})
|
|
37
|
+
|
|
38
|
+
const pubkey = this.state.siteInfo.rsaPublicKey;
|
|
39
|
+
if (!pubkey) {
|
|
40
|
+
message.error("未获取密钥,请刷新浏览器再试")
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
// 对密码加密
|
|
44
|
+
const crypt = new JSEncrypt();
|
|
45
|
+
crypt.setPublicKey(pubkey);
|
|
46
|
+
values.password = crypt.encrypt(values.password)
|
|
47
|
+
|
|
48
|
+
LoginPageUtils.postLogin(values).finally(()=>{
|
|
49
|
+
this.setState({logging: false})
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
render() {
|
|
55
|
+
const {siteInfo} = this.state
|
|
56
|
+
|
|
57
|
+
const pageStyle = {}
|
|
58
|
+
if (siteInfo.loginBackground) {
|
|
59
|
+
let url = 'admin/sysFile/preview/' + siteInfo.loginBackground;
|
|
60
|
+
pageStyle.backgroundImage = 'url("' + url + '")'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<section className='login-page' style={pageStyle}>
|
|
65
|
+
<div className="login-content">
|
|
66
|
+
<h1>{siteInfo.title}</h1>
|
|
67
|
+
{this.getForm(siteInfo)}
|
|
68
|
+
|
|
69
|
+
{this.renderFormBottom()}
|
|
70
|
+
|
|
71
|
+
</div>
|
|
72
|
+
</section>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
getForm = siteInfo => {
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
const form = <Form
|
|
81
|
+
name="normal_login"
|
|
82
|
+
className="login-form"
|
|
83
|
+
initialValues={{remember: true}}
|
|
84
|
+
onFinish={this.submit}
|
|
85
|
+
requiredMark={false}
|
|
86
|
+
colon={false}
|
|
87
|
+
>
|
|
88
|
+
|
|
89
|
+
<Form.Item name="username" rules={[{required: true, message: '请输入用户名!'}]}>
|
|
90
|
+
<Input size='large' prefix={<UserOutlined/>} placeholder="用户名" autoComplete="off"/>
|
|
91
|
+
</Form.Item>
|
|
92
|
+
<Form.Item name="password" rules={[{required: true, message: '请输入密码!'}]}>
|
|
93
|
+
<Input autoComplete="off" prefix={<LockOutlined/>} type="password" placeholder="密码"
|
|
94
|
+
size='large'
|
|
95
|
+
/>
|
|
96
|
+
</Form.Item>
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
{siteInfo.captcha && <Form.Item name='captchaCode' rules={[{required: true}]}>
|
|
100
|
+
<Space style={{alignItems: 'center'}}>
|
|
101
|
+
<Input size='large' placeholder='验证码' prefix={<SafetyCertificateOutlined/>}/>
|
|
102
|
+
<img height={36}
|
|
103
|
+
width={100}
|
|
104
|
+
src={"/admin/auth/captchaImage?_random=" + this.state.random}
|
|
105
|
+
onClick={() => {
|
|
106
|
+
this.setState({random: Math.random()})
|
|
107
|
+
}}></img>
|
|
108
|
+
</Space>
|
|
109
|
+
</Form.Item>}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
<Form.Item style={{marginTop: 10}}>
|
|
113
|
+
<Button loading={this.state.logging} type="primary" htmlType="submit"
|
|
114
|
+
block size='large'>
|
|
115
|
+
登录
|
|
116
|
+
</Button>
|
|
117
|
+
</Form.Item>
|
|
118
|
+
</Form>;
|
|
119
|
+
|
|
120
|
+
if(this.props.formRender){
|
|
121
|
+
return this.props.formRender(form);
|
|
122
|
+
}
|
|
123
|
+
return form;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
renderFormBottom() {
|
|
127
|
+
let siteInfo = this.state.siteInfo;
|
|
128
|
+
if (siteInfo.loginBoxBottomTip) {
|
|
129
|
+
return <div style={{color: 'white', marginTop: 50, fontSize: '14px', textAlign: 'center'}}>
|
|
130
|
+
<WarningOutlined/> {siteInfo.loginBoxBottomTip}
|
|
131
|
+
</div>
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
.login-page {
|
|
2
|
+
background-size: cover;
|
|
3
|
+
background-image: url("/admin/public/login_bg.jpg");
|
|
4
|
+
background-repeat: no-repeat;
|
|
5
|
+
background-position: bottom;
|
|
6
|
+
|
|
7
|
+
width: 100vw;
|
|
8
|
+
height: 100vh;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
.login-content {
|
|
12
|
+
padding: 40px;
|
|
13
|
+
background: #15184b44;
|
|
14
|
+
width: 350px;
|
|
15
|
+
position: fixed;
|
|
16
|
+
right: 15%;
|
|
17
|
+
top: 20%;
|
|
18
|
+
|
|
19
|
+
.ant-form-item-label > label{
|
|
20
|
+
color: white !important;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@media screen and (max-width: 768px) {
|
|
26
|
+
.login-page {
|
|
27
|
+
padding-top: 30%;
|
|
28
|
+
|
|
29
|
+
.login-content {
|
|
30
|
+
width: calc(100% - 100px);
|
|
31
|
+
padding: 24px;
|
|
32
|
+
position: static;
|
|
33
|
+
margin: 0 auto;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
.login-form {
|
|
40
|
+
max-width: 300px;
|
|
41
|
+
margin: 0 auto;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
.login-page h1 {
|
|
48
|
+
margin-bottom: 50px;
|
|
49
|
+
text-align: center;
|
|
50
|
+
color: white !important;
|
|
51
|
+
font-size: x-large;
|
|
52
|
+
}
|
|
53
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {history} from 'umi';
|
|
2
|
+
import {EventBusUtils, HttpUtils, PageUtils} from "../utils";
|
|
3
|
+
/**
|
|
4
|
+
* 将登录页面的公共方法提取出来,方便自定义登录页面时使用
|
|
5
|
+
*/
|
|
6
|
+
export class LoginPageUtils {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
static postLogin(values) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
console.log('开始登录')
|
|
12
|
+
HttpUtils.postForm('/admin/auth/login', values).then(rs => {
|
|
13
|
+
console.log('登录结果', rs)
|
|
14
|
+
EventBusUtils.emit('loginSuccess')
|
|
15
|
+
let redirect = LoginPageUtils.getRedirect();
|
|
16
|
+
history.push(redirect)
|
|
17
|
+
resolve(rs)
|
|
18
|
+
}).catch(e => {
|
|
19
|
+
console.log('登录错误', e)
|
|
20
|
+
reject(e)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static getRedirect() {
|
|
27
|
+
let redirect = PageUtils.currentParams()['redirect'];
|
|
28
|
+
if (redirect) {
|
|
29
|
+
console.log('重定向参数', redirect)
|
|
30
|
+
redirect = decodeURIComponent(redirect)
|
|
31
|
+
}else {
|
|
32
|
+
redirect = '/'
|
|
33
|
+
}
|
|
34
|
+
return redirect;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数组工具类
|
|
3
|
+
* 提供了一系列对数组进行操作的静态方法。
|
|
4
|
+
*/
|
|
5
|
+
export class ArrUtils {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 检查数组是否包含某个元素。
|
|
9
|
+
* @param arr 目标数组。
|
|
10
|
+
* @param item 要检查的元素。
|
|
11
|
+
* @returns 如果包含则返回 true,否则返回 false。
|
|
12
|
+
*/
|
|
13
|
+
static contains<T>(arr: T[], item: T): boolean {
|
|
14
|
+
return arr.indexOf(item) !== -1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 检查数组是否包含至少一个指定的元素。
|
|
19
|
+
* 注意:原始实现中的 this.contains(item) 逻辑错误,已修正为检查 arr 是否包含 item。
|
|
20
|
+
*
|
|
21
|
+
* @param arr 目标数组。
|
|
22
|
+
* @param items 要检查的一个或多个元素。
|
|
23
|
+
* @returns 如果包含任意一个元素则返回 true,否则返回 false。
|
|
24
|
+
*/
|
|
25
|
+
static containsAny<T>(arr: T[], ...items: T[]): boolean {
|
|
26
|
+
for (const item of items) {
|
|
27
|
+
// 这里调用自身的静态方法
|
|
28
|
+
if (ArrUtils.contains(arr, item)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 在数组末尾添加一个元素。
|
|
37
|
+
* @param arr 目标数组。
|
|
38
|
+
* @param item 要添加的元素。
|
|
39
|
+
*/
|
|
40
|
+
static add<T>(arr: T[], item: T): void {
|
|
41
|
+
arr.push(item);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 在数组的指定索引处添加一个元素。
|
|
46
|
+
* @param arr 目标数组。
|
|
47
|
+
* @param index 插入位置的索引。
|
|
48
|
+
* @param item 要添加的元素。
|
|
49
|
+
*/
|
|
50
|
+
static addAt<T>(arr: T[], index: number, item: T): void {
|
|
51
|
+
arr.splice(index, 0, item);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 将另一个数组的所有元素追加到目标数组的尾部。
|
|
56
|
+
* @param arr 目标数组。
|
|
57
|
+
* @param items 要追加的元素数组。
|
|
58
|
+
*/
|
|
59
|
+
static addAll<T>(arr: T[], items: T[]): void {
|
|
60
|
+
// 使用 ES6 的 spread 运算符或 push.apply 效率更高
|
|
61
|
+
arr.push(...items);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 移除数组指定索引处的元素。
|
|
66
|
+
* @param arr 目标数组。
|
|
67
|
+
* @param index 要移除元素的索引。
|
|
68
|
+
*/
|
|
69
|
+
static removeAt<T>(arr: T[], index: number): void {
|
|
70
|
+
if (index >= 0 && index < arr.length) {
|
|
71
|
+
arr.splice(index, 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 移除数组中第一个匹配的元素。
|
|
77
|
+
* @param arr 目标数组。
|
|
78
|
+
* @param item 要移除的元素。
|
|
79
|
+
*/
|
|
80
|
+
static remove<T>(arr: T[], item: T): void {
|
|
81
|
+
const index = arr.indexOf(item);
|
|
82
|
+
if (index !== -1) {
|
|
83
|
+
// 这里调用自身的静态方法
|
|
84
|
+
ArrUtils.removeAt(arr, index);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 清空数组。
|
|
90
|
+
* @param arr 目标数组。
|
|
91
|
+
*/
|
|
92
|
+
static clear<T>(arr: T[]): void {
|
|
93
|
+
arr.length = 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 截取数组的一个子集。
|
|
98
|
+
* @param arr 目标数组。
|
|
99
|
+
* @param fromIndex 开始索引(包含)。
|
|
100
|
+
* @param toIndex 结束索引(不包含)。
|
|
101
|
+
* @returns 截取后的新数组。
|
|
102
|
+
*/
|
|
103
|
+
static sub<T>(arr: T[], fromIndex?: number, toIndex?: number): T[] {
|
|
104
|
+
return arr.slice(fromIndex, toIndex);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 交换数组中两个元素的位置。
|
|
109
|
+
* @param arr 目标数组。
|
|
110
|
+
* @param item1 元素1。
|
|
111
|
+
* @param item2 元素2。
|
|
112
|
+
*/
|
|
113
|
+
static swap<T>(arr: T[], item1: T, item2: T): void {
|
|
114
|
+
const index1 = arr.indexOf(item1);
|
|
115
|
+
const index2 = arr.indexOf(item2);
|
|
116
|
+
|
|
117
|
+
if (index1 !== -1 && index2 !== -1) {
|
|
118
|
+
// 使用解构赋值进行交换,更简洁
|
|
119
|
+
[arr[index1], arr[index2]] = [arr[index2], arr[index1]];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 在数组的指定索引处插入一个元素(与 addAt 相同,保留以兼容原 API)。
|
|
125
|
+
* @param arr 目标数组。
|
|
126
|
+
* @param index 插入位置的索引。
|
|
127
|
+
* @param item 要插入的元素。
|
|
128
|
+
*/
|
|
129
|
+
static insert<T>(arr: T[], index: number, item: T): void {
|
|
130
|
+
ArrUtils.addAt(arr, index, item);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 如果元素不存在于数组中,则将其添加到数组末尾。
|
|
135
|
+
* @param arr 目标数组。
|
|
136
|
+
* @param item 要添加的元素。
|
|
137
|
+
*/
|
|
138
|
+
static pushIfNotExist<T>(arr: T[], item: T): void {
|
|
139
|
+
if (!ArrUtils.contains(arr, item)) {
|
|
140
|
+
arr.push(item);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 将新数组中的所有元素添加到目标数组的末尾。
|
|
146
|
+
* @param arr 目标数组。
|
|
147
|
+
* @param newArr 要添加的元素数组。
|
|
148
|
+
*/
|
|
149
|
+
static pushAll<T>(arr: T[], newArr: T[]): void {
|
|
150
|
+
ArrUtils.addAll(arr, newArr);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 获取对象数组中某一属性值最大的对象。
|
|
155
|
+
* 使用泛型 K 约束 key 必须是 T 的属性,并确保属性值可以进行数值比较。
|
|
156
|
+
*
|
|
157
|
+
* @param arr 对象数组。
|
|
158
|
+
* @param key 用于比较的属性名。
|
|
159
|
+
* @returns 属性值最大的对象,如果数组为空则返回 undefined。
|
|
160
|
+
*/
|
|
161
|
+
static maxBy<T extends Record<K, any>, K extends keyof T>(
|
|
162
|
+
arr: T[],
|
|
163
|
+
key: K
|
|
164
|
+
): T | undefined {
|
|
165
|
+
if (arr == null || arr.length === 0) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let maxElement: T | undefined = undefined;
|
|
170
|
+
let maxValue: number = -Infinity;
|
|
171
|
+
|
|
172
|
+
for (const element of arr) {
|
|
173
|
+
// 运行时类型检查(虽然 TS 层面已约束 K,但值可能不是数字)
|
|
174
|
+
const value = element[key];
|
|
175
|
+
|
|
176
|
+
// 确保比较的是数字类型
|
|
177
|
+
if (typeof value === 'number' && value > maxValue) {
|
|
178
|
+
maxValue = value;
|
|
179
|
+
maxElement = element;
|
|
180
|
+
} else if (typeof value !== 'number') {
|
|
181
|
+
// 可选:如果遇到非数字,可以跳过或根据需求抛出错误/记录警告
|
|
182
|
+
// console.warn(`Element with key ${String(key)} has non-numeric value: ${value}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return maxElement;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 对数组进行去重。
|
|
191
|
+
* @param arr 目标数组。
|
|
192
|
+
* @returns 去重后的新数组。
|
|
193
|
+
*/
|
|
194
|
+
static unique<T>(arr: T[]): T[] {
|
|
195
|
+
return [...new Set(arr)];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 示例用法(可选)
|
|
200
|
+
/*
|
|
201
|
+
interface User {
|
|
202
|
+
id: number;
|
|
203
|
+
score: number;
|
|
204
|
+
name: string;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const users: User[] = [
|
|
208
|
+
{ id: 1, score: 90, name: 'Alice' },
|
|
209
|
+
{ id: 2, score: 95, name: 'Bob' },
|
|
210
|
+
{ id: 3, score: 88, name: 'Charlie' },
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
const maxUser = ArrUtil.maxBy(users, 'score');
|
|
214
|
+
console.log(maxUser); // { id: 2, score: 95, name: 'Bob' }
|
|
215
|
+
|
|
216
|
+
const numbers = [1, 2, 2, 3, 4, 1];
|
|
217
|
+
const uniqueNumbers = ArrUtil.unique(numbers);
|
|
218
|
+
console.log(uniqueNumbers); // [1, 2, 3, 4]
|
|
219
|
+
|
|
220
|
+
let list = [10, 20];
|
|
221
|
+
ArrUtil.register(list, 30);
|
|
222
|
+
console.log(list); // [10, 20, 30]
|
|
223
|
+
|
|
224
|
+
ArrUtil.remove(list, 20);
|
|
225
|
+
console.log(list); // [10, 30]
|
|
226
|
+
|
|
227
|
+
ArrUtil.addAll(list, [40, 50]);
|
|
228
|
+
console.log(list); // [10, 30, 40, 50]
|
|
229
|
+
*/
|