index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Apple v1.0.0
  3. * @Class Apple
  4. * @description shopro-apple 1.0.0 apple第三方登录组件
  5. * @Author lidongtony
  6. * @Date 2020-02-19
  7. * @Email lidongtony@qq.com
  8. */
  9. import api from '@/shopro/request/index';
  10. export default {
  11. eventMap(event) {
  12. let map = '';
  13. switch (event) {
  14. case 'login':
  15. map = '登录中...';
  16. break;
  17. case 'refresh':
  18. map = '更新中...';
  19. break;
  20. case 'bind':
  21. map = '绑定中...';
  22. break;
  23. }
  24. return map;
  25. },
  26. // #ifdef APP-PLUS
  27. // 微信开放平台登录
  28. appleIdOauth(event = 'login') {
  29. let that = this;
  30. return new Promise((resolve, reject) => {
  31. uni.login({
  32. provider: 'apple',
  33. success: function(loginRes) {
  34. if (loginRes.errMsg === "login:ok") {
  35. // 登录成功
  36. uni.getUserInfo({
  37. provider: 'apple',
  38. success(res) {
  39. if(res.errMsg === 'getUserInfo:ok') {
  40. let userInfo = res.userInfo;
  41. api('user.appleIdOauth', {
  42. userInfo,
  43. event
  44. }, that.eventMap(event)).then(res => {
  45. if (res.code === 1) {
  46. resolve(res.data.token);
  47. } else {
  48. resolve(false);
  49. }
  50. });
  51. }
  52. // 获取用户信息成功
  53. }
  54. })
  55. }
  56. },
  57. fail: function(res) {
  58. uni.showToast({
  59. title: '请稍后再试'
  60. });
  61. resolve(false);
  62. api('common.debug', {
  63. info: res
  64. })
  65. },
  66. complete: function(res) {
  67. }
  68. });
  69. });
  70. },
  71. // #endif
  72. }