index.js 612 B

123456789101112131415161718192021222324252627
  1. import { axios } from './axios';
  2. import store from '../store/index.js';
  3. // 获取用户信息
  4. export const getUserInfo = async function(userId) {
  5. const result = new Promise((resolve, reject) => {
  6. axios({
  7. url: '/user/user/detail',
  8. method: 'get',
  9. params: {
  10. userId: userId || store.state.userId
  11. }
  12. }).then(res => {
  13. store.commit('changeUserInfo', res.data);
  14. store.commit('changeUserId', res.data.userId);
  15. uni.setStorageSync('userInfo', res.data);
  16. uni.setStorageSync('userId', res.data.userId);
  17. resolve(res.data);
  18. })
  19. })
  20. return result;
  21. }
  22. export default{
  23. axios,
  24. getUserInfo
  25. }