weapps-plugin-jingtong-verify 1.5.8 → 1.6.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/README.md CHANGED
@@ -1,2 +1,2 @@
1
1
  # SDK #
2
- 1.5.8
2
+ 1.6.0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "weapps-plugin-jingtong-verify",
3
3
  "pluginName": "weapps-plugin-jingtong-verify",
4
4
  "pluginType": "mp",
5
- "version": "1.5.8",
5
+ "version": "1.6.0",
6
6
  "description": "",
7
7
  "main": "sdk.js",
8
8
  "author": "tongyirenzheng",
@@ -732,7 +732,8 @@ Page({
732
732
 
733
733
  this.setData({
734
734
  submitSafeMode: 'other',
735
- formSafeData: tempFormSafeData
735
+ formSafeData: tempFormSafeData,
736
+ _tempVerificationCode: tempCode // 临时保存验证码
736
737
  })
737
738
 
738
739
  const form = this.selectComponent('#formSafe')
@@ -742,14 +743,16 @@ Page({
742
743
  // 恢复 verification_code
743
744
  this.setData({
744
745
  formSafeData: { ...this.data.formSafeData, verification_code: tempCode },
745
- submitSafeMode: ''
746
+ submitSafeMode: '',
747
+ _tempVerificationCode: '' // 清空临时验证码
746
748
  })
747
749
  }
748
750
  } catch (error) {
749
751
  // 恢复 verification_code
750
752
  this.setData({
751
753
  formSafeData: { ...this.data.formSafeData, verification_code: tempCode },
752
- submitSafeMode: ''
754
+ submitSafeMode: '',
755
+ _tempVerificationCode: '' // 清空临时保存验证码
753
756
  })
754
757
  }
755
758
  },
@@ -927,15 +930,31 @@ Page({
927
930
  const formErrList = e.detail.value
928
931
  // 如果表单校验有问题,自定义校验没问题,则显示表单校验错误提示
929
932
  if (!formValid && customValid.valid) {
933
+ // 校验通过,恢复 verification_code 并发送验证码
934
+ const tempCode = this.data._tempVerificationCode || ''
935
+ this.setData({
936
+ formSafeData: { ...this.data.formSafeData, verification_code: tempCode }
937
+ })
930
938
  return
931
939
  }
932
940
  // 如果表单校验没有问题,自定义校验有问题,则显示自定义校验错误提示
933
941
  if (formValid && !customValid.valid) {
942
+ // 校验通过,恢复 verification_code 并发送验证码
943
+ const tempCode = this.data._tempVerificationCode || ''
944
+ this.setData({
945
+ formSafeData: { ...this.data.formSafeData, verification_code: tempCode }
946
+ })
934
947
  return
935
948
  }
936
949
  return
937
950
  }
938
951
  const { formData, formSafeData } = this.data
952
+
953
+ // 校验通过,恢复 verification_code 并发送验证码
954
+ const tempCode = this.data._tempVerificationCode || ''
955
+ this.setData({
956
+ formSafeData: { ...this.data.formSafeData, verification_code: tempCode }
957
+ })
939
958
  let params = {
940
959
  'id_card_number': formSafeData.id_card_number, // 证件号码
941
960
  'name': formData.name,
@@ -1014,7 +1033,7 @@ Page({
1014
1033
  if (errcode === 0) {
1015
1034
  if(!res.data.success){
1016
1035
  wx.showToast({
1017
- title: errmsg || '验证码校验失败,请重新输入。',
1036
+ title: '验证码校验失败,请重新输入。',
1018
1037
  icon: 'none',
1019
1038
  duration: 2000
1020
1039
  })
@@ -44,9 +44,9 @@ Page({
44
44
  // 新增验证码验证
45
45
  verification_code(value) {
46
46
  // 如果 source_type 为 2,跳过验证
47
- if (this.data.source_type === '2') {
48
- return true
49
- }
47
+ // if (this.data.source_type === '2') {
48
+ // return true
49
+ // }
50
50
  // 验证码不能为空
51
51
  if (!value || value.trim() === '') {
52
52
  return false
@@ -106,7 +106,8 @@ Page({
106
106
  showNotGetVerificationCodeTipModal: false,
107
107
  submitMode: '',
108
108
  // 防重复点击标记 - 基于接口返回状态
109
- isSubmitting: false
109
+ isSubmitting: false,
110
+ _tempVerificationCode: '', // 临时存储验证码
110
111
  },
111
112
 
112
113
  /**
@@ -132,6 +133,29 @@ Page({
132
133
  source_type: options.source_type
133
134
  })
134
135
  }
136
+ // 修复 validateType.verification_code 中的 this 指向
137
+ const that = this
138
+ this.setData({
139
+ 'validateType.verification_code': function(value, formData) {
140
+ // 通过闭包访问 Page 实例的 source_type
141
+ // if (that.data.source_type === '2') {
142
+ // return true
143
+ // }
144
+ if (!value || value.trim() === '') {
145
+ return false
146
+ }
147
+ return utils.validate.checkVerificationCode(value).data
148
+ }
149
+ })
150
+
151
+ // 如果 source_type === '2',从 rules 中移除 verification_code
152
+ if (this.data.source_type === '2') {
153
+ // const tempRules = { ...this.data.rules }
154
+ // delete tempRules.verification_code
155
+ // this.setData({
156
+ // rules: tempRules
157
+ // })
158
+ }
135
159
  },
136
160
  // 在 bank-card-verify.js 中添加
137
161
  preventInput: function(e) {
@@ -197,7 +221,10 @@ Page({
197
221
  // 如果表单校验有问题,自定义校验没问题,则显示表单校验错误提示
198
222
  if (!formValid && customValid.valid) {
199
223
  this.showCuntomErrTip(formErrList[0].message)
224
+ // 恢复 verification_code
225
+ const tempCode = this.data._tempVerificationCode || ''
200
226
  this.setData({
227
+ formData: { ...this.data.formData, verification_code: tempCode },
201
228
  isSubmitting: false
202
229
  })
203
230
  return
@@ -205,7 +232,10 @@ Page({
205
232
  // 如果表单校验没有问题,自定义校验有问题,则显示自定义校验错误提示
206
233
  if (formValid && !customValid.valid) {
207
234
  this.showCuntomErrTip(customValid.msg)
235
+ // 恢复 verification_code
236
+ const tempCode = this.data._tempVerificationCode || ''
208
237
  this.setData({
238
+ formData: { ...this.data.formData, verification_code: tempCode },
209
239
  isSubmitting: false
210
240
  })
211
241
  return
@@ -217,21 +247,41 @@ Page({
217
247
  } else {
218
248
  lastMsg = customValid.msg
219
249
  }
250
+ // 恢复 verification_code
251
+ const tempCode = this.data._tempVerificationCode || ''
220
252
  this.setData({
253
+ formData: { ...this.data.formData, verification_code: tempCode },
221
254
  submitMode: '',
222
255
  isSubmitting: false
223
256
  })
224
257
  this.showCuntomErrTip(lastMsg)
225
258
  wx.hideLoading()
226
259
  return
227
- }
260
+ }
261
+ // 校验通过,恢复 verification_code 并发送验证码
262
+ const tempCode = this.data._tempVerificationCode || ''
228
263
  this.setData({
264
+ formData: { ...this.data.formData, verification_code: tempCode },
229
265
  submitMode: '',
230
266
  isSubmitting: false
231
267
  })
232
268
  this.sendVerificationCode()
233
269
  return
234
270
  }
271
+ // if(this.data.source_type === 2){
272
+ // // 临时保存并移除 verification_code
273
+ // const tempCode = this.data.formData.verification_code
274
+ // const tempFormData = { ...this.data.formData }
275
+ // delete tempFormData.verification_code
276
+ // // 同时从 rules 中移除 verification_code 的校验规则
277
+ // const tempRules = { ...this.data.rules }
278
+ // delete tempRules.verification_code
279
+ // this.setData({
280
+ // formData: tempFormData,
281
+ // rules: tempRules, // 使用不包含 verification_code 的 rules
282
+ // _tempVerificationCode: tempCode // 临时保存验证码
283
+ // })
284
+ // }
235
285
  const customValid = this.data.language !== 'en' ? { valid: true, msg: '' } : this.validateFullname()
236
286
  if (!formValid || !customValid.valid) {
237
287
  // 自定义校验字段有问题,获取表单错误列表
@@ -296,71 +346,119 @@ Page({
296
346
  // return
297
347
  // }
298
348
  // 接口验证短信验证码
299
- if(source_type !== '2'){
349
+ let isVerifySmsCode = false
350
+ console.log('验证码参数')
351
+ console.log(formData)
300
352
  const verSmsCodeParam = {
301
353
  "mobile": formData.bank_phone,
302
- "monbileCode": formData.verification_code
354
+ "mobileCode": formData.verification_code
303
355
  }
304
356
  jingtongVerifyRequest.verifySmsCode(verSmsCodeParam).then(res => {
305
357
  const { errcode, errmsg } = res
358
+ console.log('返回状态码')
359
+ console.log(errcode)
306
360
  if(errcode !== 0){
361
+ console.log('进入了')
307
362
  wx.showToast({
308
363
  title: errmsg,
309
364
  icon: 'none',
310
365
  duration: 2000
311
366
  })
312
- return
367
+ isVerifySmsCode = true
313
368
  } else{
314
369
  if(!res.data.success) {
315
370
  wx.showToast({
316
- title: errmsg || '验证码校验失败,请重新输入。',
371
+ title: '验证码校验失败,请重新输入。',
317
372
  icon: 'none',
318
373
  duration: 2000
319
374
  })
375
+ isVerifySmsCode = true
320
376
  return
377
+ } else {
378
+ this.toOpera()
321
379
  }
322
380
  }
381
+ console.log('没有返回')
323
382
  })
324
- }
383
+ // if(source_type !== '2'){
384
+ // console.log('验证码参数')
385
+ // console.log(formData)
386
+ // const verSmsCodeParam = {
387
+ // "mobile": formData.bank_phone,
388
+ // "mobileCode": formData.verification_code
389
+ // }
390
+ // jingtongVerifyRequest.verifySmsCode(verSmsCodeParam).then(res => {
391
+ // const { errcode, errmsg } = res
392
+ // console.log('返回状态码')
393
+ // console.log(errcode)
394
+ // if(errcode !== 0){
395
+ // console.log('进入了')
396
+ // wx.showToast({
397
+ // title: errmsg,
398
+ // icon: 'none',
399
+ // duration: 2000
400
+ // })
401
+ // isVerifySmsCode = true
402
+ // } else{
403
+ // if(!res.data.success) {
404
+ // wx.showToast({
405
+ // title: '验证码校验失败,请重新输入。',
406
+ // icon: 'none',
407
+ // duration: 2000
408
+ // })
409
+ // isVerifySmsCode = true
410
+ // return
411
+ // } else {
412
+ // this.toOpera()
413
+ // }
414
+ // }
415
+ // console.log('没有返回')
416
+ // })
417
+ // } else {
418
+ // setTimeout(() => {
419
+ // this.toOpera()
420
+ // }, 1200)
421
+ // }
422
+ },
423
+ toOpera() {
424
+ const { formData, idCardType, source_type } = this.data
325
425
  const param = {
326
426
  'id_card_number': formData.id_card_number,
327
427
  'type': 2,
328
428
  'isCount': true
329
429
  }
330
430
  // 接口返回验证成功出现这个提示
331
- setTimeout(() => {
332
- // 接口验证有没有超出限制次数
333
- jingtongVerifyRequest.getVerifyLimit(param).then(res => {
334
- console.log(res)
335
- if (res.errcode === 0){
336
- const { data } = res
337
- if(data.times >= 3){
338
- wx.hideLoading()
339
- this.setData({
340
- showToOtherModal: true
341
- })
342
- } else {
343
- console.log(idCardType)
344
- console.log(idCardType[formData.cid_type])
345
- console.log('来源类型')
346
- console.log(source_type)
347
- wx.hideLoading()
348
- if(source_type === '2'){
349
- this.forgotVerify()
350
- } else {
351
- this.setPwdVerify()
352
- }
353
- }
354
- } else {
431
+ // 接口验证有没有超出限制次数
432
+ jingtongVerifyRequest.getVerifyLimit(param).then(res => {
433
+ console.log(res)
434
+ if (res.errcode === 0){
435
+ const { data } = res
436
+ if(data.times >= 3){
355
437
  wx.hideLoading()
356
- wx.showToast({
357
- title: res.timeLimit,
358
- icon: 'none',
359
- duration: 1500
438
+ this.setData({
439
+ showToOtherModal: true
360
440
  })
441
+ } else {
442
+ console.log(idCardType)
443
+ console.log(idCardType[formData.cid_type])
444
+ console.log('来源类型')
445
+ console.log(source_type)
446
+ wx.hideLoading()
447
+ if(source_type === '2'){
448
+ this.forgotVerify()
449
+ } else {
450
+ this.setPwdVerify()
451
+ }
361
452
  }
362
- })
363
- }, 100)
453
+ } else {
454
+ wx.hideLoading()
455
+ wx.showToast({
456
+ title: res.timeLimit,
457
+ icon: 'none',
458
+ duration: 1500
459
+ })
460
+ }
461
+ })
364
462
  },
365
463
  // 设置密码进入
366
464
  setPwdVerify(){
@@ -467,7 +565,7 @@ Page({
467
565
 
468
566
  console.log('银行卡校验')
469
567
  console.log(res)
470
- wx.hideLoading()
568
+ // wx.hideLoading()
471
569
  if(res.errcode === 0){
472
570
  // 保存银行卡核验成功时间戳
473
571
  let timeStamp = new Date().getTime()
@@ -626,7 +724,8 @@ Page({
626
724
 
627
725
  this.setData({
628
726
  submitMode: 'other',
629
- formData: tempFormData
727
+ formData: tempFormData,
728
+ _tempVerificationCode: tempCode // 临时保存验证码
630
729
  })
631
730
 
632
731
  const form = this.selectComponent('#form')
@@ -637,7 +736,8 @@ Page({
637
736
  this.setData({
638
737
  formData: { ...this.data.formData, verification_code: tempCode },
639
738
  submitMode: '',
640
- isSubmitting: false
739
+ isSubmitting: false,
740
+ _tempVerificationCode: '' // 清空临时值
641
741
  })
642
742
  }
643
743
  } catch (error) {
@@ -645,7 +745,8 @@ Page({
645
745
  this.setData({
646
746
  formData: { ...this.data.formData, verification_code: tempCode },
647
747
  submitMode: '',
648
- isSubmitting: false
748
+ isSubmitting: false,
749
+ _tempVerificationCode: '' // 清空临时值
649
750
  })
650
751
  }
651
752
  },
@@ -82,7 +82,7 @@
82
82
  />
83
83
  </view>
84
84
  <!-- 验证码 -->
85
- <view class="form-item-wrap" wx:if="{{source_type != 2}}">
85
+ <view class="form-item-wrap">
86
86
  <g-input
87
87
  id="verification_code"
88
88
  label="验证码"