租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
825 B

6 months ago
6 months ago
  1. import { getInfo } from "@/common/api.js"
  2. export default {
  3. state: {
  4. token:"",
  5. userInfo : {}, //用户信息
  6. },
  7. mutations: {
  8. onAuth(state){
  9. },
  10. setUserInfo(state,obj){
  11. state.userInfo = obj.userInfo
  12. state.token = obj.token
  13. },
  14. getUserInfo(state){
  15. if(!uni.getStorageSync('token')){
  16. return
  17. }
  18. getInfo({}).then(result=>{
  19. if(result.result.nickName){
  20. state.userInfo = result.result
  21. }else{
  22. uni.navigateTo({
  23. url:"/pages/login/index"
  24. })
  25. }
  26. })
  27. },
  28. logout(state){
  29. uni.showModal({
  30. title: '确认退出登录吗',
  31. success(r) {
  32. if(r.confirm){
  33. state.userInfo = {}
  34. state.token = ""
  35. uni.removeStorageSync('token')
  36. uni.redirectTo({
  37. url: '/pages/index/index'
  38. })
  39. }
  40. }
  41. })
  42. },
  43. },
  44. actions: {}
  45. }