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.

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