user.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import {
  2. post,
  3. get,
  4. postL
  5. } from '@/utils/http'
  6. import {
  7. trans
  8. } from './base'
  9. import {
  10. SERVICE_URL,
  11. WX_APP_ID
  12. } from '@/utils/config'
  13. import store from '@/store'
  14. import {
  15. SET_THIRD,
  16. SET_TOKEN,
  17. SET_USER_INFO,
  18. SET_HIDE
  19. } from '@/store/mutation-types'
  20. import cache from '../utils/cache'
  21. export default {
  22. apis: {
  23. WX_SESSION: SERVICE_URL + '/api/wechatMa/getSessionInfo',
  24. Login: SERVICE_URL + '/api/wechatMa/loginV2',
  25. MOBILE_BIND: SERVICE_URL + '/api/wechatMa/bindUserPhone',
  26. USER_INFO: SERVICE_URL + '/api/myProfile/get',
  27. USER_UPDATE: SERVICE_URL + '/api/myProfile/basicInfo/update',
  28. UPDATE_AVATAR: SERVICE_URL + '/api/myProfile/avatar/update',
  29. UPDATE_NICKNAME: SERVICE_URL + '/api/myProfile/nickname/update',
  30. USER_COMPLETE_BIND: SERVICE_URL + '/api/wechatMa/bindUserInfo',
  31. REAL_NAME_APPLY: SERVICE_URL + '/api/authentication/submit',
  32. GETHIDE: SERVICE_URL + '/api/luckOrder/hide'
  33. },
  34. async updateSession(code, loading) {
  35. const res = await trans(post(this.apis.WX_SESSION, {
  36. code
  37. }, {
  38. loading
  39. }))
  40. if (res.data && res.data.session) {
  41. store.commit(SET_THIRD, res.data.session)
  42. }
  43. return res.success
  44. },
  45. async login(encryptedData, iv, session) {
  46. const res = await trans(
  47. postL(this.apis.Login, {
  48. encryptedData,
  49. iv,
  50. sessionKey: session.sessionKey,
  51. session
  52. })
  53. )
  54. if (!res.success) {
  55. return false
  56. }
  57. store.commit(SET_TOKEN, res.data.tokenInfo.tokenValue)
  58. return {
  59. needInfo: res.data.needPerfectProfile,
  60. token: res.data.tokenInfo.tokenValue
  61. }
  62. },
  63. async getInfo() {
  64. const res = await trans(get(this.apis.USER_INFO))
  65. return res.data
  66. },
  67. async info() {
  68. const res = await trans(get(this.apis.USER_INFO))
  69. if (res.success) {
  70. store.commit(SET_USER_INFO, res.data)
  71. }
  72. return res.success
  73. },
  74. async bindMobile(param) {
  75. param.sessionKey = store.state.sessionKey
  76. const res = await trans(postL(this.apis.MOBILE_BIND, param))
  77. return res.success
  78. },
  79. async complete(encryptedData, iv, signature, rawData) {
  80. let param = {
  81. encryptedData,
  82. iv,
  83. sessionKey: store.state.sessionKey,
  84. signature,
  85. rawData
  86. }
  87. const res = await trans(postL(this.apis.USER_COMPLETE_BIND, param))
  88. return res.success
  89. },
  90. async realNameApply(idName, idNum) {
  91. const res = await trans(postL(this.apis.REAL_NAME_APPLY, {
  92. idName,
  93. idNum
  94. }))
  95. return res.success
  96. },
  97. async updateInfo(nickname, avatar) {
  98. const res = await trans(postL(this.apis.USER_UPDATE, {
  99. nickname,
  100. avatar
  101. }))
  102. return res.success
  103. },
  104. async updateAvatar(avatar) {
  105. const res = await trans(postL(this.apis.UPDATE_AVATAR, {
  106. avatar
  107. }))
  108. return res.success
  109. },
  110. async updateNickname(nickname) {
  111. const res = await trans(postL(this.apis.UPDATE_NICKNAME, {
  112. nickname
  113. }))
  114. return res.success
  115. },
  116. async getHide() {
  117. const res = await trans(get(this.apis.GETHIDE))
  118. // 1: 没消费,0 :消费
  119. store.commit(SET_HIDE, res.data)
  120. return res.success
  121. },
  122. async getVerifycode(param) {
  123. const res = await trans(postL(SERVICE_URL + '/api/verifycode/send', param))
  124. return res.success
  125. },
  126. async accountLogin(param) {
  127. const res = await trans(postL(SERVICE_URL + '/api/account/login', param))
  128. if (!res.success) {
  129. return false
  130. }
  131. store.commit(SET_TOKEN, res.data.tokenInfo.tokenValue)
  132. return res.success
  133. },
  134. async getParamConfig(code) {
  135. const res = await trans(get(SERVICE_URL + '/param/paramConfig', {
  136. code
  137. }))
  138. return res.data
  139. },
  140. async logoff() {
  141. const res = await trans(postL(SERVICE_URL + '/api/removeAccount/submit'))
  142. return res.success
  143. }
  144. }