index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { $wuxKeyBoard } from '../../dist/index'
  2. import ad from '../index/ad'
  3. ad({
  4. data: {},
  5. onLoad() {},
  6. open() {
  7. $wuxKeyBoard().show({
  8. callback(value) {
  9. console.log(`输入的密码是:${value}`)
  10. return true
  11. },
  12. })
  13. },
  14. openWitdhDisorder() {
  15. $wuxKeyBoard().show({
  16. disorder: true,
  17. callback(value) {
  18. console.log(`输入的密码是:${value}`)
  19. return false
  20. },
  21. })
  22. },
  23. openWithPromiseCallback() {
  24. const http = (obj) => {
  25. return new Promise((resolve, reject) => {
  26. obj.success = (res) => resolve(res)
  27. obj.fail = (res) => reject(res)
  28. wx.request(obj)
  29. })
  30. }
  31. $wuxKeyBoard().show({
  32. callback(value) {
  33. console.log(`输入的密码是:${value}`)
  34. wx.showLoading({
  35. title: '验证支付密码',
  36. })
  37. return http({
  38. url: 'your_server_address/api/xxx',
  39. method: 'POST',
  40. data: {
  41. username: 'admin',
  42. password: value,
  43. },
  44. })
  45. .then(res => {
  46. const data = res.data
  47. console.log(data)
  48. wx.hideLoading()
  49. wx.showToast({
  50. title: data.meta.message,
  51. duration: 3000,
  52. })
  53. if (data.meta.code !== 0) {
  54. return Promise.reject(data.meta.message)
  55. }
  56. })
  57. },
  58. })
  59. },
  60. openPlain() {
  61. const fn = (title) => {
  62. wx.hideLoading()
  63. wx.showToast({
  64. title,
  65. duration: 3000,
  66. })
  67. }
  68. $wuxKeyBoard().show({
  69. className: 'className',
  70. titleText: '安全键盘',
  71. cancelText: '取消',
  72. inputText: '输入数字密码',
  73. showCancel: true,
  74. disorder: false,
  75. maxlength: 4,
  76. closeOnReject: false,
  77. callback(value) {
  78. console.log(`输入的密码是:${value}`)
  79. wx.showLoading({
  80. title: '验证支付密码',
  81. })
  82. return new Promise((resolve, reject) => {
  83. setTimeout(() => Math.ceil(Math.random() * 10) >= 6 ? resolve(fn('密码正确')) : reject(fn('密码错误')), 3000)
  84. })
  85. },
  86. })
  87. },
  88. openTimed() {
  89. clearTimeout(this.timeout)
  90. const hide = $wuxKeyBoard().show({
  91. password: false,
  92. maxlength: -1,
  93. onChange(value) {
  94. console.log(`输入的密码是:${value}`)
  95. },
  96. onClose(value) {
  97. return false
  98. },
  99. })
  100. this.timeout = setTimeout(hide, 3000)
  101. },
  102. })