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 } })