user.js 552 B

12345678910111213141516171819202122232425262728
  1. export default {
  2. namespaced: true,
  3. state: {
  4. userInfo: {}
  5. },
  6. mutations: {
  7. SET_USER_INFO: (state, userInfo) => {
  8. state.userInfo = userInfo
  9. }
  10. },
  11. actions: {
  12. getUserInfo ({commit}) {
  13. const db = uniCloud.database()
  14. return db
  15. .collection('uni-id-users')
  16. .where('_id==$cloudEnv_uid')
  17. .field('username,nickname')
  18. .get()
  19. .then(({result}) => {
  20. const [userInfo] = result.data
  21. commit('SET_USER_INFO', userInfo)
  22. return Promise.resolve(userInfo)
  23. })
  24. }
  25. }
  26. }