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