user.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { API_LOGIN, API_REGISTER, API_LOGOUT, API_CLEAR_USER, API_USER_INFO } from './http/api'
  2. import { request } from './http/request'
  3. import { clearSuccess, getInfoSuccess, loginSuccess, logoutSuccess, registerSuccess, updateSuccess } from '@/store/user'
  4. export const login = (username: string, password: string) => (dispatch: any) => {
  5. request({
  6. url: API_LOGIN, method: 'POST', data: { username, password }
  7. }).then(res => {
  8. dispatch(loginSuccess(res));
  9. })
  10. }
  11. export const wxLogin = (code: string, encryptedData: string, iv: string) => (dispatch: any)=> {
  12. request({
  13. url: API_LOGIN, method: 'POST',
  14. data: {
  15. code: code,
  16. type: 'WX_MP',
  17. app_version: '1',
  18. client_version: '1',
  19. client_type: 'WX_MP',
  20. extra: {
  21. encryptedData: encryptedData,
  22. iv: iv
  23. }
  24. }
  25. }).then(res => {
  26. dispatch(loginSuccess(res));
  27. })
  28. };
  29. /*
  30. export const wxLogin = (code: string) => (dispatch: any) => {
  31. request({
  32. url: API_LOGIN, method: 'POST', data: { code,type:'WX_MP',app_version:'1',client_version:'1',client_type:'WXP_MP' }
  33. }).then(res => {
  34. console.log(res);
  35. dispatch(loginSuccess(res));
  36. })
  37. }*/
  38. export const register = (name: string, email: string, password: string) => (dispatch: any) => {
  39. request({
  40. url: API_REGISTER, method: 'POST', data: { client_type: 'IOS', username: name, email: email, password: password }
  41. }).then(res => {
  42. dispatch(registerSuccess(res));
  43. })
  44. }
  45. export const logout = () => (dispatch: any) => {
  46. request({
  47. url: API_LOGOUT, method: 'GET', data: {}
  48. }).then(_ => {
  49. dispatch(logoutSuccess());
  50. })
  51. }
  52. export const clear = () => (dispatch: any) => {
  53. request({
  54. url: API_CLEAR_USER, method: 'POST', data: {}
  55. }).then(_ => {
  56. dispatch(clearSuccess());
  57. })
  58. }
  59. export const getInfo = () => (dispatch: any) => {
  60. request({
  61. url: API_USER_INFO, method: 'GET', data: {}
  62. }).then(res => {
  63. dispatch(getInfoSuccess(res));
  64. })
  65. }
  66. export const update = () => (dispatch: any) => {
  67. request({
  68. url: API_USER_INFO, method: 'POST', data: {}
  69. }).then(res => {
  70. dispatch(updateSuccess(res));
  71. })
  72. }