index.js 914 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Created by JianJia.Zhou<jianjia.zhou> on 2022/8/14.
  3. */
  4. import { getToken } from '../../utils/auth'
  5. const request = uni.$u.http
  6. export async function login() {
  7. return new Promise(resolve => {
  8. uni.showLoading({
  9. title: '数据加载中...',
  10. mask: true
  11. })
  12. uni.login({
  13. provider: uni.$u.platform,
  14. success: loginRes => {
  15. console.log('-->data', loginRes)
  16. uni.hideLoading()
  17. return request.post(
  18. '/auth/bytedance',
  19. { code: loginRes.code, anonymousCode: loginRes.anonymousCode }
  20. ).then(res => {
  21. resolve(res)
  22. })
  23. }
  24. })
  25. })
  26. }
  27. export function update(data) {
  28. return request.post(
  29. 'user/update',
  30. data
  31. )
  32. }
  33. export async function info() {
  34. return request.get(
  35. 'user/info'
  36. )
  37. }
  38. export function isLogin() {
  39. return !!getToken()
  40. }
  41. export default {
  42. login,
  43. update,
  44. info,
  45. isLogin
  46. }