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.

74 lines
1.7 KiB

4 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
3 months ago
3 months ago
4 months ago
3 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
3 months ago
  1. // stores/counterStore.js
  2. import { defineStore, createPinia } from 'pinia';
  3. const store = createPinia();
  4. export const userStore = defineStore({
  5. id: 'userStore',
  6. state: () => ({
  7. token: uni.getStorageSync('token')?uni.getStorageSync('token'):'',
  8. loginInfo: uni.getStorageSync('loginInfo')?uni.getStorageSync('loginInfo'):{},
  9. userInfo: {
  10. idCard: '',
  11. name: '',
  12. myHouse: null
  13. },
  14. chooseHouse: {
  15. "roomNum": "",
  16. "houseType": '',
  17. "houseTypeName": '',
  18. "communityId": '',
  19. "communityName": '',
  20. "userName": '',
  21. "idNo": "",
  22. "houseId": '',
  23. },
  24. timer: null,
  25. }),
  26. actions: {
  27. upDateToken(token) {
  28. console.log('没到storeToken么?')
  29. this.token = token
  30. console.log(this.token)
  31. uni.setStorageSync('token', token)
  32. },
  33. upDateLoginInfo(info) {
  34. this.loginInfo = info
  35. uni.setStorageSync('loginInfo', info)
  36. },
  37. upDateHouse(key, value) {
  38. this.chooseHouse[key] = value
  39. console.log(this.chooseHouse)
  40. },
  41. upDateUseInfo(key, value) {
  42. this.userInfo[key] = value
  43. console.log(this.userInfo)
  44. },
  45. goLogin() {
  46. this.openid = ''
  47. this.token = ''
  48. this.loginInfo = {}
  49. for (let key in this.loginInfo) {
  50. this.chooseHouse[key] = ''
  51. }
  52. uni.clearStorage();
  53. const pages = getCurrentPages();
  54. const page = pages[pages.length - 1].$page.fullPath; //完整路由地址
  55. let url = '/pages/subPage/login/login'
  56. if(page!= url) {
  57. console.log('当前页面')
  58. console.log(page)
  59. if(this.timer) clearTimeout(this.timer)
  60. this.timer = setTimeout(()=>{
  61. uni.navigateTo({
  62. url: url+'?redirect='+ page
  63. })
  64. this.timer = null
  65. },1000)
  66. }
  67. }
  68. },
  69. });
  70. export function useUserStoreHook() {
  71. return userStore(store);
  72. }