jrs-react 1.1.4 → 1.1.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/build/index.es.js +1325 -19
- package/build/index.js +1325 -19
- package/package.json +1 -1
- package/src/components/JRFrame/JRFrame.jsx +1 -2
- package/src/components/JRSubmit.jsx +286 -17
- package/src/components/LoadingBar.jsx +143 -0
package/package.json
CHANGED
|
@@ -14,7 +14,6 @@ const FreeType=({tag:Tag,config,me,className})=>{
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export default class JRFrame extends JRSubmit {
|
|
17
|
-
|
|
18
17
|
renderer(){
|
|
19
18
|
return <StyledJRFrame style={this.props.style} className={`${this.props.className} jr-frame`} >
|
|
20
19
|
<FreeType tag='div' config={this.props.start} me={this} className={'start'}/>
|
|
@@ -32,7 +31,7 @@ export default class JRFrame extends JRSubmit {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
renderMe(){
|
|
35
|
-
return <div style={{flex:1}}>Render
|
|
34
|
+
return <div style={{flex:1}}>Render JRFrame main</div>
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
}
|
|
@@ -1,27 +1,296 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import axios from 'axios'
|
|
3
|
-
|
|
3
|
+
import { colonValueString, flexType, po } from './JRUtils'
|
|
4
|
+
import { displaySpinner } from './LoadingBar'
|
|
5
|
+
// import msg from '../jrx/IMessage'
|
|
6
|
+
import styled from 'styled-components'
|
|
4
7
|
|
|
5
|
-
// const axiosSubmit = axios.create({
|
|
6
|
-
// authorization: ``
|
|
7
|
-
// ,timeout: 120000
|
|
8
|
-
// ,maxBodyLength: 104857600 //100mb 104857600
|
|
9
|
-
// ,maxContentLength: 104857600 //100mb
|
|
10
|
-
// })
|
|
11
8
|
|
|
9
|
+
const axiosSubmit = axios.create({
|
|
10
|
+
authorization: `Bearer ${localStorage.getItem("accessToken")}`
|
|
11
|
+
,timeout: 120000
|
|
12
|
+
,maxBodyLength: 104857600 //100mb 104857600
|
|
13
|
+
,maxContentLength: 104857600 //100mb
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const StyledCover=styled.div`
|
|
17
|
+
border:2px solid red;
|
|
18
|
+
`
|
|
19
|
+
const Cover=({children})=>{
|
|
20
|
+
return <StyledCover>{children}</StyledCover>
|
|
21
|
+
}
|
|
12
22
|
|
|
13
23
|
export default class JRSubmit extends React.Component {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
#methods = ['get', 'post', 'put','patch','delete','download']
|
|
25
|
+
|
|
26
|
+
constructor(props) {
|
|
27
|
+
super(props)
|
|
28
|
+
if(this.props.value===undefined && this.props.initValue!==undefined ){
|
|
29
|
+
if(this.props.onChange===undefined){
|
|
30
|
+
this.state={
|
|
31
|
+
value:props.initValue
|
|
32
|
+
,rawValue:JSON.parse(JSON.stringify(props.initValue))
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
componentDidMount() {
|
|
38
|
+
this.#methods
|
|
39
|
+
.filter((method) => this[method] && this.props[method] && this.props[method].autoRun)
|
|
40
|
+
.forEach((method) => {
|
|
41
|
+
this[method]()
|
|
22
42
|
})
|
|
23
43
|
}
|
|
24
|
-
|
|
25
|
-
|
|
44
|
+
get(_config = {}) {
|
|
45
|
+
const config = Object.assign(
|
|
46
|
+
{
|
|
47
|
+
method:'get'
|
|
48
|
+
,updateValue:true
|
|
49
|
+
// ,updateRawValue:true
|
|
50
|
+
}
|
|
51
|
+
,this.props['get']
|
|
52
|
+
,_config
|
|
53
|
+
)
|
|
54
|
+
this.submit(config)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
post(config = {}) {
|
|
58
|
+
config = Object.assign(
|
|
59
|
+
{
|
|
60
|
+
method:'post'
|
|
61
|
+
,updateValue:false
|
|
62
|
+
}
|
|
63
|
+
,this.props['post']
|
|
64
|
+
,config
|
|
65
|
+
)
|
|
66
|
+
this.submit(config)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
put(config = {}) {
|
|
70
|
+
config = Object.assign(
|
|
71
|
+
{
|
|
72
|
+
method:'put'
|
|
73
|
+
,updateValue:false
|
|
74
|
+
}
|
|
75
|
+
,this.props['put']
|
|
76
|
+
,config
|
|
77
|
+
)
|
|
78
|
+
this.submit(config)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
delete(config = {}) {
|
|
82
|
+
config = Object.assign(
|
|
83
|
+
{
|
|
84
|
+
method:'delete'
|
|
85
|
+
,updateValue:false
|
|
86
|
+
}
|
|
87
|
+
,this.props['delete']
|
|
88
|
+
,config
|
|
89
|
+
)
|
|
90
|
+
this.submit(config)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get from(){
|
|
94
|
+
return this.props.value===undefined?'state':'props'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get isDirty(){
|
|
98
|
+
return this.state?.isDirty
|
|
99
|
+
}
|
|
100
|
+
set isDirty(isDirty){
|
|
101
|
+
this.setState({isDirty})
|
|
102
|
+
}
|
|
103
|
+
get rawValue(){
|
|
104
|
+
return this.state?.rawValue
|
|
105
|
+
}
|
|
106
|
+
setRawValue(rawValue){
|
|
107
|
+
this.setState({rawValue:JSON.parse(JSON.stringify(rawValue??''))})
|
|
108
|
+
}
|
|
109
|
+
reset(){
|
|
110
|
+
this.setValue(this.rawValue,true)
|
|
111
|
+
}
|
|
112
|
+
setValue(value,reset=false){
|
|
113
|
+
if(this.props.onChange){
|
|
114
|
+
this.props.onChange(value)
|
|
115
|
+
}else{
|
|
116
|
+
this.setState({value})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if(reset){
|
|
120
|
+
this.setRawValue(value)
|
|
121
|
+
}
|
|
122
|
+
this.isDirty=!reset
|
|
123
|
+
}
|
|
124
|
+
setRes(isSuccess,response,config){
|
|
125
|
+
if (isSuccess && config.updateValue) {
|
|
126
|
+
const value=config.formatValue?.bind(this)(response.data)??response.data
|
|
127
|
+
response.data=value
|
|
128
|
+
this.setValue(value,true)
|
|
129
|
+
} else if(config.updateValue){
|
|
130
|
+
this.setValue(null,true)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
#getValueByName(fullnamList,record){
|
|
134
|
+
const name=fullnamList.shift()
|
|
135
|
+
if(fullnamList.length==0){
|
|
136
|
+
return record?.[name]
|
|
137
|
+
}else if(record?.[name]!=null){
|
|
138
|
+
return this.#getValueByName(fullnamList,record[name])
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getValue(fullname){
|
|
143
|
+
if(fullname){
|
|
144
|
+
const fullnamList=fullname.split('.')
|
|
145
|
+
return this.#getValueByName(fullnamList,this[this.from]?.value)
|
|
146
|
+
}else{
|
|
147
|
+
return flexType(this[this.from]?.value,this,null,null)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getSubmitValue(){
|
|
152
|
+
return this.getValue()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
getAxiosParams({url,method,value,extraValue,sendValue,transformValue,...params}){
|
|
156
|
+
const _extraValue=extraValue?.bind?.(this)() ?? extraValue
|
|
157
|
+
// let payload=typeof value === 'function'
|
|
158
|
+
// ?value.bind(this)({
|
|
159
|
+
// ...this.getSubmitValue()
|
|
160
|
+
// ,..._extraValue
|
|
161
|
+
// })
|
|
162
|
+
// :value==null
|
|
163
|
+
// ?{
|
|
164
|
+
// ...this.getSubmitValue()
|
|
165
|
+
// ,..._extraValue
|
|
166
|
+
// }
|
|
167
|
+
// :{
|
|
168
|
+
// ...value
|
|
169
|
+
// ,..._extraValue
|
|
170
|
+
// }
|
|
171
|
+
let payload=value?.bind?.(this)({
|
|
172
|
+
...this.getSubmitValue()
|
|
173
|
+
,..._extraValue
|
|
174
|
+
})
|
|
175
|
+
?? value==null
|
|
176
|
+
?{
|
|
177
|
+
...this.getSubmitValue()
|
|
178
|
+
,..._extraValue
|
|
179
|
+
}
|
|
180
|
+
:{
|
|
181
|
+
...value
|
|
182
|
+
,..._extraValue
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if(transformValue){
|
|
186
|
+
payload=transformValue.bind(this)(payload)
|
|
187
|
+
}
|
|
188
|
+
const headers={
|
|
189
|
+
authorization: `Bearer ${localStorage.getItem("accessToken")}`
|
|
190
|
+
}
|
|
191
|
+
let params1={}
|
|
192
|
+
const params2={}
|
|
193
|
+
if(method=='get'){
|
|
194
|
+
if(sendValue==null || sendValue)params1.params=payload
|
|
195
|
+
params1.headers=headers
|
|
196
|
+
}else if(method=='delete'){
|
|
197
|
+
if(sendValue==null || sendValue)params1.data=payload
|
|
198
|
+
params1.headers=headers
|
|
199
|
+
}else{
|
|
200
|
+
if(sendValue==null || sendValue){
|
|
201
|
+
params1=payload
|
|
202
|
+
}else{
|
|
203
|
+
params1=null
|
|
204
|
+
}
|
|
205
|
+
params2.headers=headers
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
url:colonValueString(url,payload)
|
|
209
|
+
,method
|
|
210
|
+
,params1
|
|
211
|
+
,params2
|
|
212
|
+
,payload
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
reload(){
|
|
217
|
+
po('reload 還沒有做 ')
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
submit(config){
|
|
221
|
+
const me=this
|
|
222
|
+
displaySpinner({mask:config.mask})
|
|
223
|
+
this.setState({loading:true})
|
|
224
|
+
let _payload
|
|
225
|
+
;(()=>{
|
|
226
|
+
if (Array.isArray(config.url)) {
|
|
227
|
+
_payload=[]
|
|
228
|
+
return Promise.allSettled(
|
|
229
|
+
config.url.map((_url) => {
|
|
230
|
+
const urlParams=typeof _url === 'object'
|
|
231
|
+
?_url
|
|
232
|
+
:{url: _url}
|
|
233
|
+
const finalConfig=Object.assign(config,urlParams)
|
|
234
|
+
const {url,method,params1,params2,payload}=this.getAxiosParams(finalConfig)
|
|
235
|
+
_payload.push(payload)
|
|
236
|
+
return axiosSubmit[method](url,params1,params2)
|
|
237
|
+
})
|
|
238
|
+
)
|
|
239
|
+
}else{
|
|
240
|
+
const {url,method,params1,params2,payload}=this.getAxiosParams(config)
|
|
241
|
+
_payload=payload
|
|
242
|
+
return axiosSubmit[method](url,params1,params2)
|
|
243
|
+
}
|
|
244
|
+
})()
|
|
245
|
+
.then((res)=>{
|
|
246
|
+
this.handleResponse(res,_payload,config)
|
|
247
|
+
})
|
|
248
|
+
.catch((res)=>{
|
|
249
|
+
this.handleResponse(res,_payload,config)
|
|
250
|
+
})
|
|
251
|
+
.finally(function (a,b,c) {
|
|
252
|
+
me.setState({loading:false})
|
|
253
|
+
// displaySpinner({mask:false})
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
handleResponse=(response,payload,config)=>{
|
|
258
|
+
if(Array.isArray(response)){
|
|
259
|
+
response=response.map((re,index)=>{
|
|
260
|
+
if(re.value){
|
|
261
|
+
re.value.payload=payload[index]
|
|
262
|
+
}else if(re.reason){
|
|
263
|
+
re.reason.payload=payload[index]
|
|
264
|
+
}
|
|
265
|
+
return re
|
|
266
|
+
})
|
|
267
|
+
}else{
|
|
268
|
+
response.payload=payload
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
response = config?.response?.bind(this)(response,payload) ?? response
|
|
272
|
+
const isSuccess = response.status >= 200 && response.status <= 299
|
|
273
|
+
|
|
274
|
+
this.setRes(isSuccess,response,config)
|
|
275
|
+
if (isSuccess) {
|
|
276
|
+
if (config.successMessage) {
|
|
277
|
+
// msg.success({ message:config.successMessage });+++++++++++++++++++++
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
if (config.failedMessage) {
|
|
281
|
+
// msg.error({ message:config.failedMessage });+++++++++++++++++++++++
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
config.callback?.bind(this)(isSuccess,response,payload)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
renderer(){
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
render() {
|
|
292
|
+
return this.props.cover!=null && this.state?.lodaing
|
|
293
|
+
?<Cover>{flexType(this.props.cover,this,null,null)}</Cover>
|
|
294
|
+
:this.renderer()
|
|
26
295
|
}
|
|
27
296
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
// import { IconSpinner } from '../assets/image';
|
|
3
|
+
|
|
4
|
+
const Loadingspin = styled.div`
|
|
5
|
+
user-select: none;
|
|
6
|
+
cursor: wait;
|
|
7
|
+
display: none;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
11
|
+
position: fixed;
|
|
12
|
+
width: 100vw;
|
|
13
|
+
height: 100vh;
|
|
14
|
+
background-color: #000000aa;
|
|
15
|
+
z-index: 20000;
|
|
16
|
+
color: ${({theme})=>theme.colorPrimary};
|
|
17
|
+
|
|
18
|
+
svg{
|
|
19
|
+
width: 80px;
|
|
20
|
+
height: 80px;
|
|
21
|
+
path, circle{
|
|
22
|
+
fill: ${({theme})=>theme.colorPrimary};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.cs-loader-inner {
|
|
27
|
+
transform: translateY(-30%);
|
|
28
|
+
width: calc(100% - 200xpx);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.cs-loader-inner label {
|
|
32
|
+
font-size: 20px;
|
|
33
|
+
opacity: 0;
|
|
34
|
+
display:inline-block;
|
|
35
|
+
color:${({theme})=>theme.colorPrimary};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@keyframes lol {
|
|
39
|
+
0% {
|
|
40
|
+
opacity: 0;
|
|
41
|
+
transform: translateX(-300px);
|
|
42
|
+
}
|
|
43
|
+
33% {
|
|
44
|
+
opacity: 1;
|
|
45
|
+
transform: translateX(0px);
|
|
46
|
+
}
|
|
47
|
+
66% {
|
|
48
|
+
opacity: 1;
|
|
49
|
+
transform: translateX(0px);
|
|
50
|
+
}
|
|
51
|
+
100% {
|
|
52
|
+
opacity: 0;
|
|
53
|
+
transform: translateX(300px);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@-webkit-keyframes lol {
|
|
58
|
+
0% {
|
|
59
|
+
opacity: 0;
|
|
60
|
+
-webkit-transform: translateX(-300px);
|
|
61
|
+
}
|
|
62
|
+
33% {
|
|
63
|
+
opacity: 1;
|
|
64
|
+
-webkit-transform: translateX(0px);
|
|
65
|
+
}
|
|
66
|
+
66% {
|
|
67
|
+
opacity: 1;
|
|
68
|
+
-webkit-transform: translateX(0px);
|
|
69
|
+
}
|
|
70
|
+
100% {
|
|
71
|
+
opacity: 0;
|
|
72
|
+
-webkit-transform: translateX(300px);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.cs-loader-inner label:nth-child(6) {
|
|
77
|
+
-webkit-animation: lol 3s infinite ease-in-out;
|
|
78
|
+
animation: lol 3s infinite ease-in-out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.cs-loader-inner label:nth-child(5) {
|
|
82
|
+
-webkit-animation: lol 3s 100ms infinite ease-in-out;
|
|
83
|
+
animation: lol 3s 100ms infinite ease-in-out;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.cs-loader-inner label:nth-child(4) {
|
|
87
|
+
-webkit-animation: lol 3s 200ms infinite ease-in-out;
|
|
88
|
+
animation: lol 3s 200ms infinite ease-in-out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.cs-loader-inner label:nth-child(3) {
|
|
92
|
+
-webkit-animation: lol 3s 300ms infinite ease-in-out;
|
|
93
|
+
animation: lol 3s 300ms infinite ease-in-out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.cs-loader-inner label:nth-child(2) {
|
|
97
|
+
-webkit-animation: lol 3s 400ms infinite ease-in-out;
|
|
98
|
+
animation: lol 3s 400ms infinite ease-in-out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.cs-loader-inner label:nth-child(1) {
|
|
102
|
+
-webkit-animation: lol 3s 500ms infinite ease-in-out;
|
|
103
|
+
animation: lol 3s 500ms infinite ease-in-out;
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
export const displaySpinner=({mask})=>{
|
|
109
|
+
const spin = document.getElementById("loadingBar")
|
|
110
|
+
const text = document.getElementById("loadingText")
|
|
111
|
+
|
|
112
|
+
if (spin == null ) {
|
|
113
|
+
//alert("Spin or msgSpan is not initialized")
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (mask) {
|
|
118
|
+
spin.style.display = "flex"
|
|
119
|
+
text.innerText = mask
|
|
120
|
+
} else {
|
|
121
|
+
spin.style.display = "none"
|
|
122
|
+
text.innerText = ''
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const LoadingBar=()=>{
|
|
128
|
+
return <Loadingspin id={'loadingBar'}>
|
|
129
|
+
{/* <IconSpinner /> */}
|
|
130
|
+
<b id={'loadingText'}></b>
|
|
131
|
+
<div className="cs-loader-inner">
|
|
132
|
+
<label>●</label>
|
|
133
|
+
<label>●</label>
|
|
134
|
+
<label>●</label>
|
|
135
|
+
<label>●</label>
|
|
136
|
+
<label>●</label>
|
|
137
|
+
<label>●</label>
|
|
138
|
+
</div>
|
|
139
|
+
<br/><br/><br/><br/>
|
|
140
|
+
</Loadingspin>
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export default LoadingBar
|