apple.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <view>
  3. <button @click="login">apple登录</button>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. }
  11. },
  12. methods: {
  13. login(){
  14. let self = this;
  15. uni.login({
  16. provider: 'apple',
  17. success: function (loginRes) {
  18. // 登录成功
  19. uni.getUserInfo({
  20. provider: 'apple',
  21. success(res) {
  22. if (res.errMsg !== 'getUserInfo:ok') {
  23. return false;
  24. }
  25. uni.showLoading({
  26. title: "正在登录",
  27. mask: true
  28. });
  29. self._post('user.userapple/login', {
  30. invitation_id: self.invitation_id,
  31. openId: res.userInfo.openId,
  32. nickName: res.userInfo.fullName.giveName?res.userInfo.fullName.giveName:'',
  33. referee_id: uni.getStorageSync('referee_id'),
  34. source: 'apple'
  35. }, result => {
  36. // 记录token user_id
  37. uni.setStorageSync('token', result.data.token);
  38. uni.setStorageSync('user_id', result.data.user_id);
  39. // 执行回调函数
  40. uni.navigateBack();
  41. }, false, () => {
  42. uni.hideLoading();
  43. });
  44. }
  45. })
  46. },
  47. fail: function (err) {
  48. // 登录失败
  49. console.log('登录失败');
  50. console.log(err);
  51. }
  52. });
  53. }
  54. }
  55. }
  56. </script>
  57. <style>
  58. </style>