|
|
"use strict"; const common_vendor = require("../common/vendor.js"); const store = common_vendor.createPinia(); const userStore = common_vendor.defineStore({ id: "userStore", state: () => ({ token: common_vendor.index.getStorageSync("token") ? common_vendor.index.getStorageSync("token") : "", loginInfo: common_vendor.index.getStorageSync("loginInfo") ? common_vendor.index.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); common_vendor.index.setStorageSync("token", token); }, upDateLoginInfo(info) { this.loginInfo = info; common_vendor.index.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] = ""; } common_vendor.index.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(() => { common_vendor.index.navigateTo({ url: url + "?redirect=" + page }); this.timer = null; }, 1e3); } } } }); function useUserStoreHook() { return userStore(store); } exports.useUserStoreHook = useUserStoreHook; exports.userStore = userStore;
|