@jiangood/admin-spring-boot-starter 0.2.4 → 0.2.6
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
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// logger.js
|
|
2
|
+
export class Logger {
|
|
3
|
+
|
|
4
|
+
private readonly module: string;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
constructor(module) {
|
|
8
|
+
this.module = module;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public static getLogger(module) {
|
|
12
|
+
return new Logger(module);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
debug(...args) {
|
|
16
|
+
this._log( console.log, args);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
info(...args) {
|
|
20
|
+
this._log( console.info, args);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
warn(...args) {
|
|
24
|
+
this._log(console.warn, args);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
error(...args) {
|
|
28
|
+
this._log(console.error, args);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private _log( consoleMethod, args) {
|
|
32
|
+
const time = new Date().toLocaleTimeString();
|
|
33
|
+
consoleMethod(`[${time}] [${this.module}] `, ...args);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
@@ -3,6 +3,7 @@ import type {ModalFuncProps} from 'antd/es/modal/interface';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import {MessageInstance} from "antd/lib/message/interface";
|
|
5
5
|
import {HookAPI} from "antd/lib/modal/useModal";
|
|
6
|
+
import {Logger} from "./Logger";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
@@ -57,22 +58,24 @@ export class MessageUtils {
|
|
|
57
58
|
const isNumber = typeof initialValue === 'number';
|
|
58
59
|
return new Promise((resolve) => {
|
|
59
60
|
const ref = React.createRef()
|
|
61
|
+
let element:any = isNumber ? <InputNumber placeholder={placeholder}/> : <Input placeholder={placeholder}/>;
|
|
62
|
+
const content:any = <div>
|
|
63
|
+
<div style={{marginBottom: 4}}>{message}</div>
|
|
64
|
+
<Form ref={ref}>
|
|
65
|
+
<Form.Item name='inputValue' initialValue={initialValue}>
|
|
66
|
+
{element}
|
|
67
|
+
</Form.Item>
|
|
68
|
+
</Form>
|
|
69
|
+
</div>;
|
|
60
70
|
this.modalApi.confirm({
|
|
61
71
|
icon: null,
|
|
62
72
|
title: '提示',
|
|
63
|
-
content:
|
|
64
|
-
<div style={{marginBottom: 4}}>{message}</div>
|
|
65
|
-
<Form ref={ref}>
|
|
66
|
-
<Form.Item name='inputValue' initialValue={initialValue}>
|
|
67
|
-
{isNumber ? <InputNumber placeholder={placeholder}/> : <Input placeholder={placeholder}/>}
|
|
68
|
-
</Form.Item>
|
|
69
|
-
</Form>
|
|
70
|
-
</div>,
|
|
73
|
+
content:content,
|
|
71
74
|
okText: '确定',
|
|
72
75
|
cancelText: '取消',
|
|
73
76
|
onOk: () => {
|
|
74
77
|
const form = ref.current;
|
|
75
|
-
|
|
78
|
+
const values = form.getFieldsValue()
|
|
76
79
|
resolve(values.inputValue)
|
|
77
80
|
},
|
|
78
81
|
onCancel: () => {
|
|
@@ -89,6 +92,10 @@ export class MessageUtils {
|
|
|
89
92
|
* 成功消息
|
|
90
93
|
*/
|
|
91
94
|
static success(content: String, duration: number = 3) {
|
|
95
|
+
if(!this.messageApi){
|
|
96
|
+
alert(content)
|
|
97
|
+
return
|
|
98
|
+
}
|
|
92
99
|
this.messageApi.success(content, duration);
|
|
93
100
|
}
|
|
94
101
|
|
|
@@ -96,6 +103,11 @@ export class MessageUtils {
|
|
|
96
103
|
* 错误消息
|
|
97
104
|
*/
|
|
98
105
|
static error(content: String, duration: number = 3) {
|
|
106
|
+
console.log('调用 MessageUtils.error',content)
|
|
107
|
+
if(!this.messageApi){
|
|
108
|
+
alert(content)
|
|
109
|
+
return
|
|
110
|
+
}
|
|
99
111
|
this.messageApi.error(content, duration);
|
|
100
112
|
}
|
|
101
113
|
|
|
@@ -103,6 +115,10 @@ export class MessageUtils {
|
|
|
103
115
|
* 警告消息
|
|
104
116
|
*/
|
|
105
117
|
static warning(content: String, duration: number = 3) {
|
|
118
|
+
if(!this.messageApi){
|
|
119
|
+
alert(content)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
106
122
|
this.messageApi.warning(content, duration);
|
|
107
123
|
}
|
|
108
124
|
|
|
@@ -110,6 +126,10 @@ export class MessageUtils {
|
|
|
110
126
|
* 通用消息
|
|
111
127
|
*/
|
|
112
128
|
static info(content: React.ReactNode, duration: number = 3) {
|
|
129
|
+
if(!this.messageApi){
|
|
130
|
+
alert(content)
|
|
131
|
+
return
|
|
132
|
+
}
|
|
113
133
|
this.messageApi.info(content, duration);
|
|
114
134
|
}
|
|
115
135
|
|
|
@@ -135,10 +155,15 @@ export class MessageUtils {
|
|
|
135
155
|
* antd6 推荐使用这个hooks,这里统一设置, 供公共layout使用
|
|
136
156
|
* @constructor
|
|
137
157
|
*/
|
|
138
|
-
export function MessageHolder(){
|
|
158
|
+
export function MessageHolder(props){
|
|
139
159
|
const [modalApi, modalContextHolder] = Modal.useModal();
|
|
140
160
|
const [messageApi, messageContextHolder] = message.useMessage();
|
|
141
|
-
|
|
161
|
+
|
|
162
|
+
React.useEffect(()=>{
|
|
163
|
+
Logger.getLogger("MessageHolder").debug('Rendered')
|
|
164
|
+
MessageUtils.config(messageApi,modalApi);
|
|
165
|
+
props.onFinish()
|
|
166
|
+
},[])
|
|
142
167
|
return <>
|
|
143
168
|
{modalContextHolder} {messageContextHolder}
|
|
144
169
|
</>
|
package/src/layouts/index.jsx
CHANGED
|
@@ -5,12 +5,21 @@ import {ConfigProvider} from "antd";
|
|
|
5
5
|
|
|
6
6
|
import {Outlet, withRouter} from "umi";
|
|
7
7
|
import zhCN from 'antd/locale/zh_CN';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ArrUtils,
|
|
10
|
+
HttpUtils,
|
|
11
|
+
MessageHolder,
|
|
12
|
+
PageLoading,
|
|
13
|
+
PageUtils,
|
|
14
|
+
SysUtils,
|
|
15
|
+
ThemeUtils,
|
|
16
|
+
} from "../framework";
|
|
9
17
|
import dayjs from 'dayjs';
|
|
10
18
|
import 'dayjs/locale/zh-cn';
|
|
11
19
|
|
|
12
20
|
import '../style/global.less'
|
|
13
21
|
import './index.less'
|
|
22
|
+
import {Logger} from "../framework/utils/Logger";
|
|
14
23
|
|
|
15
24
|
dayjs.locale('zh-cn');
|
|
16
25
|
|
|
@@ -19,26 +28,31 @@ const SIMPLE_URLS = ['/login', '/test']
|
|
|
19
28
|
|
|
20
29
|
class _Layouts extends React.Component {
|
|
21
30
|
|
|
31
|
+
log = Logger.getLogger('Layouts')
|
|
22
32
|
|
|
23
33
|
state = {
|
|
34
|
+
messageHolderInit:false,
|
|
24
35
|
siteInfoLoading: true,
|
|
25
36
|
loginInfoFinish: false
|
|
26
37
|
}
|
|
27
38
|
|
|
39
|
+
onMessageHolderFinish = () => {
|
|
40
|
+
this.loadSiteInfo()
|
|
41
|
+
this.setState({messageHolderInit:true});
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
|
|
29
|
-
|
|
45
|
+
loadSiteInfo = () => {
|
|
30
46
|
HttpUtils.get("/admin/public/site-info").then(rs => {
|
|
31
47
|
SysUtils.setSiteInfo(rs)
|
|
32
48
|
this.setState({siteInfoLoading: false})
|
|
33
|
-
|
|
34
49
|
this.loadLoginInfo()
|
|
35
50
|
})
|
|
36
|
-
}
|
|
51
|
+
};
|
|
37
52
|
|
|
38
53
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
39
54
|
const pre = prevProps.location.pathname
|
|
40
55
|
const cur = this.props.location.pathname
|
|
41
|
-
|
|
42
56
|
if (pre !== cur) {
|
|
43
57
|
this.loadLoginInfo()
|
|
44
58
|
}
|
|
@@ -46,7 +60,10 @@ class _Layouts extends React.Component {
|
|
|
46
60
|
|
|
47
61
|
isSimplePage() {
|
|
48
62
|
let {pathname} = this.props.location;
|
|
49
|
-
|
|
63
|
+
let isSimplePage = ArrUtils.contains(SIMPLE_URLS, pathname);
|
|
64
|
+
console.log('简单页面列表定义', SIMPLE_URLS)
|
|
65
|
+
console.log('当前页面是否简单页面',pathname,isSimplePage)
|
|
66
|
+
return isSimplePage
|
|
50
67
|
}
|
|
51
68
|
|
|
52
69
|
loadLoginInfo = () => {
|
|
@@ -74,11 +91,6 @@ class _Layouts extends React.Component {
|
|
|
74
91
|
})
|
|
75
92
|
}
|
|
76
93
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
94
|
render() {
|
|
83
95
|
return <ConfigProvider
|
|
84
96
|
input={{autoComplete: 'off'}}
|
|
@@ -115,15 +127,23 @@ class _Layouts extends React.Component {
|
|
|
115
127
|
}
|
|
116
128
|
}
|
|
117
129
|
}}>
|
|
118
|
-
|
|
130
|
+
|
|
131
|
+
<MessageHolder onFinish={this.onMessageHolderFinish} />
|
|
119
132
|
{this.renderContent()}
|
|
120
133
|
</ConfigProvider>
|
|
121
134
|
}
|
|
122
135
|
|
|
136
|
+
|
|
123
137
|
renderContent = () => {
|
|
138
|
+
if(!this.state.messageHolderInit) {
|
|
139
|
+
this.log.info('加载message holder...')
|
|
140
|
+
return <PageLoading message='加载消息组件...'/>
|
|
141
|
+
}
|
|
142
|
+
|
|
124
143
|
if (this.state.siteInfoLoading) {
|
|
125
144
|
return <PageLoading message='加载站点信息...'/>
|
|
126
145
|
}
|
|
146
|
+
|
|
127
147
|
let {params = {}} = this.props.location;
|
|
128
148
|
console.log('layout: params', params)
|
|
129
149
|
let simple = this.isSimplePage();
|
|
@@ -135,14 +155,11 @@ class _Layouts extends React.Component {
|
|
|
135
155
|
return <PageLoading message='加载登录信息...'/>
|
|
136
156
|
}
|
|
137
157
|
|
|
138
|
-
|
|
139
158
|
return <AdminLayout path={this.state.path} logo={this.props.logo}/>
|
|
140
159
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
160
|
}
|
|
145
161
|
|
|
162
|
+
|
|
146
163
|
export const Layouts = withRouter(_Layouts);
|
|
147
164
|
export default Layouts
|
|
148
165
|
export * from './PageRender'
|