main.js
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* @Date: 2022-04-18 15:59:42
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-14 20:43:54
* @FilePath: /xyxBooking-weapp/src/stores/main.js
* @Description: 文件描述
*/
import { defineStore } from 'pinia'
/**
* @description 全局主状态
* - 存储用户信息与授权态等全局数据
*/
export const mainStore = defineStore('main', {
state: () => {
return {
msg: 'Hello world',
count: 0,
auth: false,
// keepPages: ['default'], // 小程序不支持这种 keep-alive 机制
appUserInfo: null // 用户信息
}
},
getters: {
/**
* @description 是否具备义工核销权限
* @returns {boolean} true=义工,false=非义工
*/
isVolunteer: state => {
return !!(state.appUserInfo && state.appUserInfo.can_redeem === true)
}
},
actions: {
/**
* @description 更新授权状态
* @param {boolean} state 是否已授权
* @returns {void} 无返回值
*/
changeState(state) {
this.auth = state
},
// setVolunteerStatus(status) {
// this.isVolunteer = status;
// },
// changeKeepPages () {
// this.keepPages = ['default'];
// },
// keepThisPage () {
// // 小程序路由缓存由框架控制
// },
// removeThisPage () {
// },
/**
* @description 更新全局用户信息
* @param {Object|null} info 用户信息对象
* @returns {void} 无返回值
*/
changeUserInfo(info) {
this.appUserInfo = info
}
}
})