index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const app = getApp(),
  2. {
  3. globalData: {
  4. util: {
  5. regeneratorRuntime,
  6. api: { login },
  7. showTip,
  8. request: {
  9. post
  10. },
  11. navigateBack
  12. }
  13. }
  14. } = app
  15. Page({
  16. data: {
  17. tab: ['个人', '法人']
  18. },
  19. onLoad() {
  20. const identity = wx.getStorageSync("identity") | 0
  21. this.setData({
  22. identity: this.identity = identity
  23. })
  24. },
  25. select: function ({ currentTarget: { dataset: { identity } } }) {
  26. this.setData({ identity })
  27. },
  28. async wxLogin({ detail: { userInfo } }) {
  29. const { data: { identity = 0 } } = this,
  30. code = await new Promise(_ => wx.login({ success: ({ code }) => _(code) })),
  31. { userId, _err } = await post(login, { userInfo: { ...userInfo, identity }, code });
  32. if (_err) return _err.status && showTip('登录失败');
  33. showTip('登录成功')
  34. wx.setStorageSync('userId', app.globalData.userId = userId)
  35. identity != this.identity && wx.setStorageSync('identity', identity)
  36. navigateBack()
  37. },
  38. })