user.ts 5.1 KB

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