pop-right.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import dayjs from 'dayjs'
  2. import AuthApi from '../../services/auth'
  3. import { isLogin } from '../../utils/util'
  4. // components/pop-right/pop-right.ts
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {},
  10. data: {
  11. innerShow: false,
  12. loading: false,
  13. },
  14. lifetimes: {
  15. ready: function () {
  16. const status = isLogin()
  17. const self = this
  18. if (!status) {
  19. // self.setData({
  20. // innerShow: true,
  21. // })
  22. // return
  23. wx.login({
  24. async success(res) {
  25. if (res.code) {
  26. AuthApi.Authenticate({
  27. providerAccessCode: res.code,
  28. }).then((rsp) => {
  29. if (rsp.result) {
  30. if (rsp.result.signature) {
  31. self.okfunc(rsp.result)
  32. } else {
  33. self.setData({
  34. innerShow: true,
  35. })
  36. }
  37. }
  38. })
  39. }
  40. },
  41. })
  42. } else {
  43. this.triggerEvent('ok')
  44. }
  45. },
  46. },
  47. /**
  48. * 组件的方法列表
  49. */
  50. methods: {
  51. close() {
  52. this.setData({
  53. innerShow: false,
  54. })
  55. },
  56. disagree() {
  57. this.triggerEvent('disagree')
  58. },
  59. getPhoneNumber(
  60. e: WechatMiniprogram.CustomEvent<{ encryptedData: string; iv: string; errMsg: string }>,
  61. ) {
  62. if (e.detail.errMsg !== 'getPhoneNumber:ok') {
  63. return
  64. }
  65. const self = this
  66. wx.login({
  67. async success(res) {
  68. if (res.code) {
  69. AuthApi.Authenticate({
  70. providerAccessCode: res.code,
  71. }).then((rsp) => {
  72. if (rsp.result) {
  73. if (rsp.result.providerKey) {
  74. const providerKey = rsp.result.providerKey
  75. console.log('get Authenticate', providerKey)
  76. AuthApi.Entrance({
  77. seCode: providerKey,
  78. encryptedData: e.detail.encryptedData,
  79. iv: e.detail.iv,
  80. }).then((rsp2) => {
  81. console.log('get Entrance', rsp2)
  82. if (rsp2.result) {
  83. self.okfunc(rsp2.result)
  84. return
  85. }
  86. self.setData({
  87. loading: false,
  88. prepare: 'need',
  89. })
  90. })
  91. } else if (rsp.result.signature) {
  92. self.okfunc(rsp.result)
  93. }
  94. }
  95. })
  96. } else {
  97. self.setData({
  98. loading: false,
  99. })
  100. }
  101. },
  102. })
  103. },
  104. okfunc(info: any) {
  105. info.expiration = dayjs().add(info.expiration, 'second') as any
  106. wx.setStorageSync('__uvx', JSON.stringify(info))
  107. this.triggerEvent('ok')
  108. this.setData({
  109. loading: false,
  110. innerShow: false,
  111. })
  112. },
  113. openPrivacyContract() {
  114. wx.openPrivacyContract({
  115. success: (res) => {
  116. console.log('openPrivacyContract success')
  117. },
  118. fail: (res) => {
  119. console.error('openPrivacyContract fail', res)
  120. },
  121. })
  122. },
  123. },
  124. })