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.
 
 
 

35 lines
1.0 KiB

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
export const useStaffStore = defineStore('staff', () => {
const token = ref(uni.getStorageSync('staffToken') || '')
const nickname = ref(uni.getStorageSync('staffNickname') || '')
const staffId = ref(uni.getStorageSync('staffId') || '')
const unread = ref(0)
const isLoggedIn = computed(() => !!token.value)
function login(t, nick, id) {
token.value = t
nickname.value = nick
staffId.value = id
uni.setStorageSync('staffToken', t)
uni.setStorageSync('staffNickname', nick)
uni.setStorageSync('staffId', id)
}
function logout() {
token.value = ''
nickname.value = ''
staffId.value = ''
unread.value = 0
uni.removeStorageSync('staffToken')
uni.removeStorageSync('staffNickname')
uni.removeStorageSync('staffId')
}
function incrementUnread(n = 1) { unread.value += n }
function clearUnread() { unread.value = 0 }
return { token, nickname, staffId, unread, isLoggedIn, login, logout, incrementUnread, clearUnread }
})