index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Created by JianJia.Zhou<jianjia.zhou> on 2022/8/14.
  3. */
  4. import { getAuthorize, getToken } from '../../utils/auth'
  5. const request = uni.$u.http
  6. export async function authorize() {
  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. uni.hideLoading()
  16. return request.post(
  17. '/auth/wechat/minni/code',
  18. { code: loginRes.code }
  19. ).then(res => {
  20. resolve(res)
  21. })
  22. }
  23. })
  24. })
  25. }
  26. export async function login(account, password, code) {
  27. return new Promise((resolve, reject) => {
  28. return request.post(
  29. '/auth/login',
  30. { account, password, code }
  31. ).then(res => {
  32. resolve(res)
  33. }).catch(err => {
  34. reject(err)
  35. })
  36. })
  37. }
  38. export async function phoneQuickLogin(data) {
  39. return new Promise(resolve => {
  40. return request.post(
  41. '/auth/wechat/minni/phone',
  42. data
  43. ).then(res => {
  44. resolve(res)
  45. })
  46. })
  47. }
  48. export async function info() {
  49. return request.get(
  50. 'user/info'
  51. )
  52. }
  53. export function isLogin() {
  54. return !!getToken()
  55. }
  56. export function isAuthorize() {
  57. return !!getAuthorize()
  58. }
  59. export default {
  60. authorize,
  61. login,
  62. info,
  63. isLogin,
  64. isAuthorize,
  65. phoneQuickLogin
  66. }