Blame view

stores/counter.js 1.06 KB
46b6767c   刘淇   init 提交到库
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
  import { defineStore } from 'pinia'
  import Cache from '@/utils/cache'
  import { TOKEN, USER_INFO, CONFIG } from '@/config/cachekey'
  
  export const useCounterStore = defineStore('useCounter', {
  	state: () => ({
  		// 用户登录状态
  		isLogin: !!Cache.get(TOKEN), 
  		// 用户token
  		userToken: Cache.get(TOKEN) || '', 
  		// 用户信息
  		userInfo: Cache.get(USER_INFO) || {},
  		// 系统配置
  		config: Cache.get(CONFIG) || {},
  		// 系统消息数量
  		noticeNum: 0
  	}),
  	actions: {
  		// 登录
  		login(data) {
  			// 用户登录状态
  			this.isLogin = true
  			// 设置用户token
  			this.userToken = data.token
  			Cache.set(TOKEN, data.token)
  		},
  		// 退出
  		loginOut() {
  			// 用户登录状态
  			this.isLogin = false
  			// 设置用户token
  			this.userToken = ''
  			Cache.remove(TOKEN)
  			// 设置用户信息
  			this.userInfo = {}
  			Cache.remove(USER_INFO)
  		},
  		// 设置用户信息
  		setUserInfo(data) {
  			this.userInfo = data
  			Cache.set(USER_INFO, data)
  		},
  		// 系统设置
  		setConfig(data) {
  			this.config = data
  			Cache.set(CONFIG, data)
  		}
  	}
  })