3ae141ba56
- Fix other members' status not visible due to users collection viewRule restriction - Fix empty status treated as 'away' instead of 'idle' in membersByStatus - Auto-set creator to 'in_team' status when creating team session - Filter current user from idle members invite list - Fix group store isGroupOwner using pb.authStore instead of localStorage - Add nginx no-cache headers for index.html - Add join_requests collection migration and join approval flow - Update groups collection rules and add requireApproval field - Add Memory types for Phase 2 planning Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
89 lines
2.1 KiB
TypeScript
89 lines
2.1 KiB
TypeScript
// src/stores/group.ts
|
|
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import type { Group, User } from '@/types'
|
|
import { pb } from '@/api/pocketbase'
|
|
import { getUserGroups, getGroup, getGroupMembers } from '@/api/groups'
|
|
|
|
export const useGroupStore = defineStore('group', () => {
|
|
// 状态
|
|
const groups = ref<Group[]>([])
|
|
const currentGroup = ref<Group | null>(null)
|
|
const currentMembers = ref<User[]>([])
|
|
const loading = ref(false)
|
|
|
|
// 计算属性
|
|
const currentGroupId = computed(() => currentGroup.value?.id || '')
|
|
const isGroupOwner = computed(() => {
|
|
return currentGroup.value?.owner === pb.authStore.model?.id
|
|
})
|
|
|
|
// 加载用户的群组列表
|
|
async function loadGroups() {
|
|
try {
|
|
loading.value = true
|
|
groups.value = await getUserGroups()
|
|
} catch (error) {
|
|
console.error('加载群组列表失败:', error)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
// 设置当前群组
|
|
async function setCurrentGroup(groupId: string) {
|
|
try {
|
|
loading.value = true
|
|
currentGroup.value = await getGroup(groupId)
|
|
currentMembers.value = await getGroupMembers(groupId) as unknown as User[]
|
|
} catch (error) {
|
|
console.error('加载群组详情失败:', error)
|
|
throw error
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
// 清除当前群组
|
|
function clearCurrentGroup() {
|
|
currentGroup.value = null
|
|
currentMembers.value = []
|
|
}
|
|
|
|
// 更新群组成员列表
|
|
function updateMembers(members: User[]) {
|
|
currentMembers.value = members
|
|
}
|
|
|
|
// 添加群组到列表
|
|
function addGroup(group: Group) {
|
|
groups.value.push(group)
|
|
}
|
|
|
|
// 从列表中移除群组
|
|
function removeGroup(groupId: string) {
|
|
const index = groups.value.findIndex(g => g.id === groupId)
|
|
if (index !== -1) {
|
|
groups.value.splice(index, 1)
|
|
}
|
|
if (currentGroup.value?.id === groupId) {
|
|
clearCurrentGroup()
|
|
}
|
|
}
|
|
|
|
return {
|
|
groups,
|
|
currentGroup,
|
|
currentMembers,
|
|
loading,
|
|
currentGroupId,
|
|
isGroupOwner,
|
|
loadGroups,
|
|
setCurrentGroup,
|
|
clearCurrentGroup,
|
|
updateMembers,
|
|
addGroup,
|
|
removeGroup
|
|
}
|
|
})
|