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.
 
 
 

75 lines
1.7 KiB

// stores/counterStore.js
import { defineStore, createPinia } from 'pinia';
const store = createPinia();
export const userStore = defineStore({
id: 'userStore',
state: () => ({
token: uni.getStorageSync('token')?uni.getStorageSync('token'):'',
loginInfo: uni.getStorageSync('loginInfo')?uni.getStorageSync('loginInfo'):{},
userInfo: {
idCard: '',
name: '',
myHouse: null
},
chooseHouse: {
"roomNum": "",
"houseType": '',
"houseTypeName": '',
"communityId": '',
"communityName": '',
"userName": '',
"idNo": "",
"houseId": '',
},
timer: null,
}),
actions: {
upDateToken(token) {
console.log('没到storeToken么?')
this.token = token
console.log(this.token)
uni.setStorageSync('token', token)
},
upDateLoginInfo(info) {
this.loginInfo = info
uni.setStorageSync('loginInfo', info)
},
upDateHouse(key, value) {
this.chooseHouse[key] = value
console.log(this.chooseHouse)
},
upDateUseInfo(key, value) {
this.userInfo[key] = value
console.log(this.userInfo)
},
goLogin() {
this.openid = ''
this.token = ''
this.loginInfo = {}
for (let key in this.loginInfo) {
this.chooseHouse[key] = ''
}
uni.clearStorage();
const pages = getCurrentPages();
const page = pages[pages.length - 1].$page.fullPath; //完整路由地址
let url = '/pages/subPage/login/login'
if(page!= url) {
console.log('当前页面')
console.log(page)
if(this.timer) clearTimeout(this.timer)
this.timer = setTimeout(()=>{
uni.navigateTo({
url: url+'?redirect='+ page
})
this.timer = null
},1000)
}
}
},
});
export function useUserStoreHook() {
return userStore(store);
}