jrs-react 1.2.47 → 1.2.48
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 +119 -118
- package/build/index.js +119 -118
- package/package.json +60 -60
- package/src/components/JRFields/JRFields.jsx +1 -0
- package/src/components/JRFrame/Slider.jsx +8 -0
- package/src/components/JRSubmit.jsx +266 -265
- package/src/components/JRWindow/JRWindow.jsx +115 -108
- package/src/components/JRWindow/TitleBar.jsx +2 -4
|
@@ -5,306 +5,307 @@ import styled from 'styled-components'
|
|
|
5
5
|
import { showMask } from './JRMask/JRMask'
|
|
6
6
|
|
|
7
7
|
const axiosSubmit = axios.create({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
authorization: `Bearer ${localStorage.getItem("accessToken")}`
|
|
9
|
+
, timeout: 120000
|
|
10
|
+
, maxBodyLength: 104857600 //100mb 104857600
|
|
11
|
+
, maxContentLength: 104857600 //100mb
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
const StyledCover=styled.div`
|
|
14
|
+
const StyledCover = styled.div`
|
|
15
15
|
border:2px solid red;
|
|
16
16
|
`
|
|
17
|
-
const Cover=({children})=>{
|
|
18
|
-
|
|
17
|
+
const Cover = ({ children }) => {
|
|
18
|
+
return <StyledCover>{children}</StyledCover>
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export default class JRSubmit extends React.Component {
|
|
22
|
-
|
|
22
|
+
#methods = ['get', 'post', 'put', 'patch', 'delete', 'download']
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
}
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props)
|
|
26
|
+
if (this.props.value === undefined && this.props.initValue !== undefined) {
|
|
27
|
+
if (this.props.onChange === undefined) {
|
|
28
|
+
this.state = {
|
|
29
|
+
value: props.initValue
|
|
30
|
+
, rawValue: JSON.parse(JSON.stringify(props.initValue))
|
|
33
31
|
}
|
|
32
|
+
}
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
post(config = {}) {
|
|
62
|
-
config = Object.assign(
|
|
63
|
-
{
|
|
64
|
-
method:'post'
|
|
65
|
-
,updateValue:false
|
|
66
|
-
}
|
|
67
|
-
,this.props['post']
|
|
68
|
-
,config
|
|
69
|
-
)
|
|
70
|
-
this.submit(config)
|
|
71
|
-
}
|
|
34
|
+
}
|
|
35
|
+
componentDidMount() {
|
|
36
|
+
this.#methods
|
|
37
|
+
.filter((method) => this[method] && this.props[method] && this.props[method].autoRun)
|
|
38
|
+
.forEach((method) => {
|
|
39
|
+
if (this.props[method].autoRun === true) {
|
|
40
|
+
this[method]()
|
|
41
|
+
} else if (this.props[method].autoRun > -1) {
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
this[method]()
|
|
44
|
+
}, this.props[method].autoRun)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
get(_config = {}) {
|
|
49
|
+
const config = Object.assign(
|
|
50
|
+
{
|
|
51
|
+
method: 'get'
|
|
52
|
+
, updateValue: true
|
|
53
|
+
// ,updateRawValue:true
|
|
54
|
+
}
|
|
55
|
+
, this.props['get']
|
|
56
|
+
, _config
|
|
57
|
+
)
|
|
58
|
+
this.submit(config)
|
|
59
|
+
}
|
|
72
60
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
61
|
+
post(config = {}) {
|
|
62
|
+
config = Object.assign(
|
|
63
|
+
{
|
|
64
|
+
method: 'post'
|
|
65
|
+
, updateValue: false
|
|
66
|
+
}
|
|
67
|
+
, this.props['post']
|
|
68
|
+
, config
|
|
69
|
+
)
|
|
70
|
+
this.submit(config)
|
|
71
|
+
}
|
|
84
72
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
put(config = {}) {
|
|
74
|
+
config = Object.assign(
|
|
75
|
+
{
|
|
76
|
+
method: 'put'
|
|
77
|
+
, updateValue: false
|
|
78
|
+
}
|
|
79
|
+
, this.props['put']
|
|
80
|
+
, config
|
|
81
|
+
)
|
|
82
|
+
this.submit(config)
|
|
83
|
+
}
|
|
96
84
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
delete(config = {}) {
|
|
86
|
+
config = Object.assign(
|
|
87
|
+
{
|
|
88
|
+
method: 'delete'
|
|
89
|
+
, updateValue: false
|
|
90
|
+
}
|
|
91
|
+
, this.props['delete']
|
|
92
|
+
, config
|
|
93
|
+
)
|
|
94
|
+
this.submit(config)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get from() {
|
|
98
|
+
return this.props.value === undefined ? 'state' : 'props'
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get isDirty() {
|
|
102
|
+
return this.state?.isDirty
|
|
103
|
+
}
|
|
104
|
+
set isDirty(isDirty) {
|
|
105
|
+
this.setState({ isDirty })
|
|
106
|
+
}
|
|
107
|
+
get rawValue() {
|
|
108
|
+
return this.state?.rawValue
|
|
109
|
+
}
|
|
110
|
+
setRawValue(rawValue) {
|
|
111
|
+
this.setState({ rawValue: rawValue != null ? JSON.parse(JSON.stringify(rawValue)) : null })
|
|
112
|
+
}
|
|
113
|
+
reset() {
|
|
114
|
+
this.setValue(this.rawValue, true)
|
|
115
|
+
}
|
|
116
|
+
setValue(value, reset = false) {
|
|
117
|
+
if (this.props.onChange) {
|
|
118
|
+
this.props.onChange(value)
|
|
119
|
+
} else {
|
|
120
|
+
this.setState({ value })
|
|
103
121
|
}
|
|
104
|
-
|
|
105
|
-
|
|
122
|
+
|
|
123
|
+
if (reset) {
|
|
124
|
+
this.setRawValue(value)
|
|
106
125
|
}
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
this.isDirty = !reset
|
|
127
|
+
}
|
|
128
|
+
setRes(isSuccess, response, config) {
|
|
129
|
+
if (isSuccess && config.updateValue) {
|
|
130
|
+
const value = config.formatValue?.bind(this)(response.data) ?? response.data
|
|
131
|
+
response.data = value
|
|
132
|
+
this.setValue(value, true)
|
|
133
|
+
} else if (config.updateValue) {
|
|
134
|
+
this.setValue(null, true)
|
|
109
135
|
}
|
|
110
|
-
|
|
111
|
-
|
|
136
|
+
}
|
|
137
|
+
#getValueByName(fullnamList, record) {
|
|
138
|
+
const name = fullnamList.shift()
|
|
139
|
+
if (fullnamList.length == 0) {
|
|
140
|
+
return record?.[name]
|
|
141
|
+
} else if (record?.[name] != null) {
|
|
142
|
+
return this.#getValueByName(fullnamList, record[name])
|
|
112
143
|
}
|
|
113
|
-
|
|
114
|
-
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getValue(fullname) {
|
|
147
|
+
if (fullname) {
|
|
148
|
+
const fullnamList = fullname.split('.')
|
|
149
|
+
return this.#getValueByName(fullnamList, this[this.from]?.value)
|
|
150
|
+
} else {
|
|
151
|
+
// 忘記為甚麼這樣寫了 XDD
|
|
152
|
+
return flexType(this[this.from]?.value, this, null, null)
|
|
115
153
|
}
|
|
116
|
-
|
|
117
|
-
if(this.props.onChange){
|
|
118
|
-
this.props.onChange(value)
|
|
119
|
-
}else{
|
|
120
|
-
this.setState({value})
|
|
121
|
-
}
|
|
154
|
+
}
|
|
122
155
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
156
|
+
getSubmitValue() {
|
|
157
|
+
return this.getValue()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getAxiosParams({ url, method, value, extraValue, sendValue, transformValue, responseType = 'json', ...params }) {
|
|
161
|
+
|
|
162
|
+
const _extraValue = extraValue?.bind?.(this)() ?? extraValue
|
|
163
|
+
// let payload=typeof value === 'function'
|
|
164
|
+
// ?value.bind(this)({
|
|
165
|
+
// ...this.getSubmitValue()
|
|
166
|
+
// ,..._extraValue
|
|
167
|
+
// })
|
|
168
|
+
// :value==null
|
|
169
|
+
// ?{
|
|
170
|
+
// ...this.getSubmitValue()
|
|
171
|
+
// ,..._extraValue
|
|
172
|
+
// }
|
|
173
|
+
// :{
|
|
174
|
+
// ...value
|
|
175
|
+
// ,..._extraValue
|
|
176
|
+
// }
|
|
177
|
+
let payload = value?.bind?.(this)({
|
|
178
|
+
...this.getSubmitValue()
|
|
179
|
+
, ..._extraValue
|
|
180
|
+
})
|
|
181
|
+
?? value == null
|
|
182
|
+
? {
|
|
183
|
+
...this.getSubmitValue()
|
|
184
|
+
, ..._extraValue
|
|
185
|
+
}
|
|
186
|
+
: {
|
|
187
|
+
...value
|
|
188
|
+
, ..._extraValue
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (transformValue) {
|
|
192
|
+
payload = transformValue.bind(this)(payload)
|
|
127
193
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const value=config.formatValue?.bind(this)(response.data)??response.data
|
|
131
|
-
response.data=value
|
|
132
|
-
this.setValue(value,true)
|
|
133
|
-
} else if(config.updateValue){
|
|
134
|
-
this.setValue(null,true)
|
|
135
|
-
}
|
|
194
|
+
const headers = {
|
|
195
|
+
authorization: `Bearer ${localStorage.getItem("accessToken")}`
|
|
136
196
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
197
|
+
let params1 = { responseType }
|
|
198
|
+
const params2 = {}
|
|
199
|
+
if (method == 'get') {
|
|
200
|
+
if (sendValue == null || sendValue) params1.params = payload
|
|
201
|
+
params1.headers = headers
|
|
202
|
+
} else if (method == 'delete') {
|
|
203
|
+
if (sendValue == null || sendValue) params1.data = payload
|
|
204
|
+
params1.headers = headers
|
|
205
|
+
} else {
|
|
206
|
+
if (sendValue == null || sendValue) {
|
|
207
|
+
params1 = payload
|
|
208
|
+
} else {
|
|
209
|
+
params1 = null
|
|
210
|
+
}
|
|
211
|
+
params2.headers = headers
|
|
144
212
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// 忘記為甚麼這樣寫了 XDD
|
|
152
|
-
return flexType(this[this.from]?.value,this,null,null)
|
|
153
|
-
}
|
|
213
|
+
return {
|
|
214
|
+
url: colonValueString(url, payload)
|
|
215
|
+
, method
|
|
216
|
+
, params1
|
|
217
|
+
, params2
|
|
218
|
+
, payload
|
|
154
219
|
}
|
|
220
|
+
}
|
|
155
221
|
|
|
156
|
-
|
|
157
|
-
|
|
222
|
+
reload() {
|
|
223
|
+
po('reload 還沒有做 ')
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
submit(config) {
|
|
227
|
+
if (config.mask) {
|
|
228
|
+
config.removeMaskFunction = showMask(config.mask, this.maskId ?? 'jr-mask')
|
|
158
229
|
}
|
|
159
230
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
})
|
|
180
|
-
?? value==null
|
|
181
|
-
?{
|
|
182
|
-
...this.getSubmitValue()
|
|
183
|
-
,..._extraValue
|
|
184
|
-
}
|
|
185
|
-
:{
|
|
186
|
-
...value
|
|
187
|
-
,..._extraValue
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if(transformValue){
|
|
191
|
-
payload=transformValue.bind(this)(payload)
|
|
192
|
-
}
|
|
193
|
-
const headers={
|
|
194
|
-
authorization: `Bearer ${localStorage.getItem("accessToken")}`
|
|
195
|
-
}
|
|
196
|
-
let params1={}
|
|
197
|
-
const params2={}
|
|
198
|
-
if(method=='get'){
|
|
199
|
-
if(sendValue==null || sendValue)params1.params=payload
|
|
200
|
-
params1.headers=headers
|
|
201
|
-
}else if(method=='delete'){
|
|
202
|
-
if(sendValue==null || sendValue)params1.data=payload
|
|
203
|
-
params1.headers=headers
|
|
204
|
-
}else{
|
|
205
|
-
if(sendValue==null || sendValue){
|
|
206
|
-
params1=payload
|
|
207
|
-
}else{
|
|
208
|
-
params1=null
|
|
209
|
-
}
|
|
210
|
-
params2.headers=headers
|
|
231
|
+
let _payload
|
|
232
|
+
; (() => {
|
|
233
|
+
if (Array.isArray(config.url)) {
|
|
234
|
+
_payload = []
|
|
235
|
+
return Promise.allSettled(
|
|
236
|
+
config.url.map((_url) => {
|
|
237
|
+
const urlParams = typeof _url === 'object'
|
|
238
|
+
? _url
|
|
239
|
+
: { url: _url }
|
|
240
|
+
const finalConfig = Object.assign(config, urlParams)
|
|
241
|
+
const { url, method, params1, params2, payload } = this.getAxiosParams(finalConfig)
|
|
242
|
+
_payload.push(payload)
|
|
243
|
+
return axiosSubmit[method](url, params1, params2)
|
|
244
|
+
})
|
|
245
|
+
)
|
|
246
|
+
} else {
|
|
247
|
+
const { url, method, params1, params2, payload } = this.getAxiosParams(config)
|
|
248
|
+
_payload = payload
|
|
249
|
+
return axiosSubmit[method](url, params1, params2)
|
|
211
250
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
251
|
+
})()
|
|
252
|
+
.then((res) => {
|
|
253
|
+
this.handleResponse(res, _payload, config)
|
|
254
|
+
})
|
|
255
|
+
.catch((res) => {
|
|
256
|
+
this.handleResponse(res, _payload, config)
|
|
257
|
+
})
|
|
258
|
+
// .finally(()=> {
|
|
259
|
+
// config.removeMaskFunction?.()
|
|
260
|
+
// })
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
handleResponse = (response, payload, config) => {
|
|
264
|
+
if (Array.isArray(response)) {
|
|
265
|
+
response = response.map((re, index) => {
|
|
266
|
+
if (re.value) {
|
|
267
|
+
re.value.payload = payload[index]
|
|
268
|
+
} else if (re.reason) {
|
|
269
|
+
re.reason.payload = payload[index]
|
|
218
270
|
}
|
|
271
|
+
return re
|
|
272
|
+
})
|
|
273
|
+
} else {
|
|
274
|
+
response.payload = payload
|
|
219
275
|
}
|
|
220
276
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
277
|
+
response = config?.response?.bind(this)(response, payload) ?? response
|
|
278
|
+
const isSuccess = response.status >= 200 && response.status <= 299
|
|
224
279
|
|
|
225
|
-
|
|
226
|
-
if(config.mask) {
|
|
227
|
-
config.removeMaskFunction=showMask(config.mask,this.maskId??'jr-mask')
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
let _payload
|
|
231
|
-
;(()=>{
|
|
232
|
-
if (Array.isArray(config.url)) {
|
|
233
|
-
_payload=[]
|
|
234
|
-
return Promise.allSettled(
|
|
235
|
-
config.url.map((_url) => {
|
|
236
|
-
const urlParams=typeof _url === 'object'
|
|
237
|
-
?_url
|
|
238
|
-
:{url: _url}
|
|
239
|
-
const finalConfig=Object.assign(config,urlParams)
|
|
240
|
-
const {url,method,params1,params2,payload}=this.getAxiosParams(finalConfig)
|
|
241
|
-
_payload.push(payload)
|
|
242
|
-
return axiosSubmit[method](url,params1,params2)
|
|
243
|
-
})
|
|
244
|
-
)
|
|
245
|
-
}else{
|
|
246
|
-
const {url,method,params1,params2,payload}=this.getAxiosParams(config)
|
|
247
|
-
_payload=payload
|
|
248
|
-
return axiosSubmit[method](url,params1,params2)
|
|
249
|
-
}
|
|
250
|
-
})()
|
|
251
|
-
.then((res)=>{
|
|
252
|
-
this.handleResponse(res,_payload,config)
|
|
253
|
-
})
|
|
254
|
-
.catch((res)=>{
|
|
255
|
-
this.handleResponse(res,_payload,config)
|
|
256
|
-
})
|
|
257
|
-
// .finally(()=> {
|
|
258
|
-
// config.removeMaskFunction?.()
|
|
259
|
-
// })
|
|
260
|
-
}
|
|
280
|
+
this.setRes(isSuccess, response, config)
|
|
261
281
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
response.payload=payload
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
response = config?.response?.bind(this)(response,payload) ?? response
|
|
277
|
-
const isSuccess = response.status >= 200 && response.status <= 299
|
|
278
|
-
|
|
279
|
-
this.setRes(isSuccess,response,config)
|
|
282
|
+
if (config.delay != null) {
|
|
283
|
+
setTimeout(() => {
|
|
284
|
+
this.showMessage(isSuccess, isSuccess ? config.successMessage : config.failedMessage)
|
|
285
|
+
config.callback?.bind(this)(isSuccess, response, payload)
|
|
286
|
+
config.removeMaskFunction?.()
|
|
287
|
+
}, config.delay)
|
|
288
|
+
} else {
|
|
289
|
+
this.showMessage(isSuccess, isSuccess ? config.successMessage : config.failedMessage)
|
|
290
|
+
config.callback?.bind(this)(isSuccess, response, payload)
|
|
291
|
+
config.removeMaskFunction?.()
|
|
292
|
+
}
|
|
280
293
|
|
|
281
|
-
if(config.delay!=null){
|
|
282
|
-
setTimeout(()=>{
|
|
283
|
-
this.showMessage(isSuccess,isSuccess?config.successMessage:config.failedMessage)
|
|
284
|
-
config.callback?.bind(this)(isSuccess,response,payload)
|
|
285
|
-
config.removeMaskFunction?.()
|
|
286
|
-
},config.delay)
|
|
287
|
-
}else{
|
|
288
|
-
this.showMessage(isSuccess,isSuccess?config.successMessage:config.failedMessage)
|
|
289
|
-
config.callback?.bind(this)(isSuccess,response,payload)
|
|
290
|
-
config.removeMaskFunction?.()
|
|
291
|
-
}
|
|
292
294
|
|
|
295
|
+
}
|
|
293
296
|
|
|
297
|
+
showMessage(success, message) {
|
|
298
|
+
if (message) {
|
|
299
|
+
po('success', success)
|
|
300
|
+
po('message', message)
|
|
294
301
|
}
|
|
302
|
+
}
|
|
295
303
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
renderer(){
|
|
304
|
-
return
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
render() {
|
|
308
|
-
return this.renderer()
|
|
309
|
-
}
|
|
304
|
+
renderer() {
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
render() {
|
|
309
|
+
return this.renderer()
|
|
310
|
+
}
|
|
310
311
|
}
|