main.js 1.11 KB
/*
 * @Date: 2022-04-18 15:59:42
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2024-01-30 15:26:30
 * @FilePath: /xyxBooking-weapp/src/stores/main.js
 * @Description: 文件描述
 */
import { defineStore } from 'pinia';

export const mainStore = defineStore('main', {
  state: () => {
    return {
      msg: 'Hello world',
      count: 0,
      auth: false,
      // keepPages: ['default'], // 小程序不支持这种 keep-alive 机制
      appUserInfo: null, // 用户信息
    };
  },
  getters: {
    // 判断是否为义工 (基于 appUserInfo 中的 role 字段)
    isVolunteer: (state) => {
      return state.appUserInfo && state.appUserInfo.role === 'volunteer';
    },
  },
  actions: {
    changeState (state) {
      this.auth = state;
    },
    // setVolunteerStatus(status) {
    //   this.isVolunteer = status;
    // },
    // changeKeepPages () {
    //   this.keepPages = ['default'];
    // },
    // keepThisPage () {
    //   // 小程序路由缓存由框架控制
    // },
    // removeThisPage () {
    // },
    changeUserInfo (info) {
      this.appUserInfo = info;
    }
  },
});