getPhoneButton.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // components/getPhoneButton/getPhoneButton.js
  2. import {
  3. wxSetSessionKey
  4. } from "../../utils/wxUtils"
  5. import {
  6. postApi
  7. } from "../../apis/api"
  8. import cloudApi from "../../apis/cloudApi"
  9. Component({
  10. /**
  11. * 组件的属性列表
  12. */
  13. properties: {
  14. style: String,
  15. type: String
  16. },
  17. data: {
  18. },
  19. methods: {
  20. async getPhoneNumber(e) {
  21. try {
  22. if (e.detail.errMsg == "getPhoneNumber:ok") {
  23. let session_key = wx.getStorageSync('session_key')
  24. let {
  25. result
  26. } = await cloudApi("getWxPhoneNumber", {
  27. ...e.detail,
  28. session_key
  29. })
  30. let {
  31. phone,
  32. } = result
  33. let res = await postApi("/user/wx/login", {
  34. openId: wx.getStorageSync('openId'),
  35. phone
  36. })
  37. this.triggerEvent('loginEvent', res)
  38. } else {
  39. console.log(e)
  40. wx.showToast({
  41. title: '请授权以登录',
  42. icon: "error"
  43. })
  44. }
  45. } catch (error) {
  46. console.log(error)
  47. wxSetSessionKey()
  48. wx.showToast({
  49. icon: "none",
  50. title: '请重试或联系管理员',
  51. })
  52. }
  53. }
  54. }
  55. })