user.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // 用户服务 - 对应 supermart-mini/service/user.js
  2. import { get, postL, setToken } from './http';
  3. const apis = {
  4. LOGIN: '/api/account/login',
  5. USER_INFO: '/api/myProfile/get',
  6. UPDATE_INFO: '/api/myProfile/basicInfo/update',
  7. UPDATE_AVATAR: '/api/myProfile/avatar/update',
  8. UPDATE_NICKNAME: '/api/myProfile/nickname/update',
  9. REAL_NAME: '/api/authentication/submit',
  10. SEND_CODE: '/api/verifycode/send',
  11. PARAM_CONFIG: '/param/paramConfig',
  12. WALLET_AMOUNT: '/api/wallet/ranking/walletAmount',
  13. WALLET_INFO: '/api/wallet/info',
  14. LOGOFF: '/api/removeAccount/submit',
  15. GET_HIDE: '/api/luckOrder/hide',
  16. SIGN_IN: '/credit/signIn',
  17. CREDIT_RECORD: '/credit/selectCreditRecord',
  18. CREDIT_SHOW: '/credit_show',
  19. ISLAND_SIGN_IN: '/api/activity/activityIsland/signIn',
  20. DISPLAY_REWARDS: '/api/activity/activityIsland/displayRewards',
  21. ACTIVITY_TA_LIST: '/api/activity/activityTa/list',
  22. ACTIVITY_TA_LEVEL: '/api/activity/activityTa/level',
  23. CLAIM_DAILY_REWARD: '/api/wallet/recharge/claimDailyReward',
  24. NEW_USER_NUM: '/api/wallet/ranking/newUserNum',
  25. LOGOUT: '/api/account/logout',
  26. };
  27. export interface UserInfo {
  28. id: string;
  29. userId?: string;
  30. nickname: string;
  31. avatar: string;
  32. phone?: string;
  33. realName?: string;
  34. idNum?: string;
  35. balance?: number;
  36. }
  37. export interface LoginParams {
  38. loginWay: string;
  39. mobile: string;
  40. verifycode: string;
  41. }
  42. export interface ParamConfig {
  43. code: string;
  44. data: string;
  45. state: number;
  46. }
  47. export interface LoginResult {
  48. success: boolean;
  49. needInfo?: boolean;
  50. }
  51. // 账号登录
  52. export const login = async (params: LoginParams): Promise<LoginResult> => {
  53. const res = await postL<{ tokenInfo: { tokenValue: string }; needPerfectProfile?: boolean }>(apis.LOGIN, params);
  54. if (res.success && res.data?.tokenInfo?.tokenValue) {
  55. setToken(res.data.tokenInfo.tokenValue);
  56. return {
  57. success: true,
  58. needInfo: res.data.needPerfectProfile,
  59. };
  60. }
  61. return { success: false };
  62. };
  63. // 退出登录
  64. export const logout = async (): Promise<boolean> => {
  65. const res = await get(apis.LOGOUT);
  66. return res.success;
  67. };
  68. // 获取用户信息
  69. export const getUserInfo = async (): Promise<UserInfo | null> => {
  70. const res = await get<UserInfo>(apis.USER_INFO);
  71. return res.data;
  72. };
  73. // 更新用户信息
  74. export const updateUserInfo = async (params: Partial<UserInfo>): Promise<boolean> => {
  75. const res = await postL(apis.UPDATE_INFO, params);
  76. return res.success;
  77. };
  78. // 更新头像
  79. export const updateAvatar = async (avatar: string): Promise<boolean> => {
  80. const res = await postL(apis.UPDATE_AVATAR, { avatar });
  81. return res.success;
  82. };
  83. // 更新昵称
  84. export const updateNickname = async (nickname: string): Promise<boolean> => {
  85. const res = await postL(apis.UPDATE_NICKNAME, { nickname });
  86. return res.success;
  87. };
  88. // 实名认证
  89. export const realNameAuth = async (idName: string, idNum: string): Promise<boolean> => {
  90. const res = await postL(apis.REAL_NAME, { idName, idNum });
  91. return res.success;
  92. };
  93. // 发送验证码
  94. export const sendVerifyCode = async (mobile: string, scene = 'LOGIN'): Promise<boolean> => {
  95. const res = await postL(apis.SEND_CODE, { mobile, scene });
  96. return res.success;
  97. };
  98. // 获取参数配置
  99. export const getParamConfig = async (code: string): Promise<ParamConfig | null> => {
  100. const res = await get<ParamConfig>(apis.PARAM_CONFIG, { code });
  101. return res.data;
  102. };
  103. // 获取钱包余额
  104. export const getWalletAmount = async () => {
  105. const res = await get(apis.WALLET_AMOUNT);
  106. return res;
  107. };
  108. // 获取钱包信息(积分等)
  109. export const getWalletInfo = async (type: string) => {
  110. const res = await get(apis.WALLET_INFO, { type });
  111. return res.data;
  112. };
  113. // 注销账号
  114. export const logoff = async (): Promise<boolean> => {
  115. const res = await postL(apis.LOGOFF);
  116. return res.success;
  117. };
  118. // 获取隐藏状态 (1: 没消费,0: 消费)
  119. export const getHide = async () => {
  120. const res = await get(apis.GET_HIDE);
  121. return res.data;
  122. };
  123. // 签到
  124. export const signIn = async () => {
  125. const res = await postL(apis.SIGN_IN);
  126. return res;
  127. };
  128. // 岛屿签到
  129. export const islandSignIn = async () => {
  130. const res = await postL(apis.ISLAND_SIGN_IN);
  131. return res;
  132. };
  133. // 获取积分记录
  134. export const getCreditRecord = async (params?: any) => {
  135. const res = await get(apis.CREDIT_RECORD, params);
  136. return res;
  137. };
  138. // 获取积分显示配置
  139. export const creditShow = async () => {
  140. const res = await get(apis.CREDIT_SHOW);
  141. return res;
  142. };
  143. // 获取展示奖励
  144. export const displayRewards = async () => {
  145. const res = await get(apis.DISPLAY_REWARDS);
  146. return res;
  147. };
  148. // 获取活动列表
  149. export const activityTaList = async () => {
  150. const res = await get(apis.ACTIVITY_TA_LIST);
  151. return res;
  152. };
  153. // 获取活动等级
  154. export const activityTaLevel = async (params?: any) => {
  155. const res = await get(apis.ACTIVITY_TA_LEVEL, params);
  156. return res;
  157. };
  158. // 领取每日奖励
  159. export const claimDailyReward = async (params?: any) => {
  160. const res = await postL(apis.CLAIM_DAILY_REWARD, params);
  161. return res;
  162. };
  163. // 获取新用户数量
  164. export const getNewUserNum = async (params?: any) => {
  165. const res = await get(apis.NEW_USER_NUM, params);
  166. return res;
  167. };
  168. export default {
  169. login,
  170. logout,
  171. getUserInfo,
  172. updateUserInfo,
  173. updateAvatar,
  174. updateNickname,
  175. realNameAuth,
  176. sendVerifyCode,
  177. getParamConfig,
  178. getWalletAmount,
  179. getWalletInfo,
  180. logoff,
  181. getHide,
  182. signIn,
  183. islandSignIn,
  184. getCreditRecord,
  185. creditShow,
  186. displayRewards,
  187. activityTaList,
  188. activityTaLevel,
  189. claimDailyReward,
  190. getNewUserNum,
  191. };