c5d3ac01ca
- Group polls with option/rollcall modes, edit by creator, auto-settle - Multimedia memories with upload, preview, inline video playback - In-app notifications for poll/team/group events - Points system and group stats dashboard - Group detail tabs with icons (activity/polls/memories/stats) - Fix: nginx file upload size, static cache blocking API, timezone, auto-cancel Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
// src/stores/memory.ts
|
|
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import type { Memory } from '@/types'
|
|
import {
|
|
listMemories,
|
|
uploadMemory,
|
|
deleteMemory,
|
|
getGroupStorageUsed,
|
|
getGroupStorageLimit
|
|
} from '@/api/memories'
|
|
|
|
export const useMemoryStore = defineStore('memory', () => {
|
|
const memories = ref<Memory[]>([])
|
|
const storageUsed = ref(0)
|
|
const storageLimit = ref(getGroupStorageLimit())
|
|
const loading = ref(false)
|
|
|
|
// 计算属性:已用/总容量百分比
|
|
const storagePercent = computed(() => {
|
|
if (storageLimit.value === 0) return 0
|
|
return Math.round((storageUsed.value / storageLimit.value) * 10000) / 100
|
|
})
|
|
|
|
// 加载记忆列表
|
|
async function loadMemories(groupId: string, fileType?: string) {
|
|
try {
|
|
loading.value = true
|
|
const result = await listMemories(groupId, { fileType })
|
|
memories.value = result.items
|
|
// 同时刷新存储用量
|
|
storageUsed.value = await getGroupStorageUsed(groupId)
|
|
} catch (error) {
|
|
console.error('加载记忆列表失败:', error)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
// 上传记忆文件
|
|
async function upload(groupId: string, file: File, meta?: { title?: string; description?: string; tags?: string[] }) {
|
|
try {
|
|
loading.value = true
|
|
await uploadMemory(groupId, file, meta)
|
|
// 上传后刷新列表和容量
|
|
await loadMemories(groupId)
|
|
} catch (error) {
|
|
console.error('上传记忆失败:', error)
|
|
throw error
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
// 删除记忆
|
|
async function remove(memoryId: string, groupId: string) {
|
|
try {
|
|
await deleteMemory(memoryId)
|
|
// 从本地列表中移除
|
|
const index = memories.value.findIndex(m => m.id === memoryId)
|
|
if (index !== -1) {
|
|
memories.value.splice(index, 1)
|
|
}
|
|
// 刷新容量
|
|
storageUsed.value = await getGroupStorageUsed(groupId)
|
|
} catch (error) {
|
|
console.error('删除记忆失败:', error)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
return {
|
|
memories,
|
|
storageUsed,
|
|
storageLimit,
|
|
loading,
|
|
storagePercent,
|
|
loadMemories,
|
|
upload,
|
|
remove
|
|
}
|
|
})
|