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
2.1 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const store = common_vendor.createPinia();
  4. const userStore = common_vendor.defineStore({
  5. id: "userStore",
  6. state: () => ({
  7. token: common_vendor.index.getStorageSync("token") ? common_vendor.index.getStorageSync("token") : "",
  8. loginInfo: common_vendor.index.getStorageSync("loginInfo") ? common_vendor.index.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. common_vendor.index.setStorageSync("token", token);
  31. },
  32. upDateLoginInfo(info) {
  33. this.loginInfo = info;
  34. common_vendor.index.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. common_vendor.index.setStorageSync("token", "");
  51. common_vendor.index.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)
  59. clearTimeout(this.timer);
  60. this.timer = setTimeout(() => {
  61. common_vendor.index.navigateTo({
  62. url: url + "?redirect=" + page
  63. });
  64. this.timer = null;
  65. }, 1e3);
  66. }
  67. }
  68. }
  69. });
  70. function useUserStoreHook() {
  71. return userStore(store);
  72. }
  73. exports.useUserStoreHook = useUserStoreHook;
  74. exports.userStore = userStore;