up
This commit is contained in:
@@ -15,7 +15,6 @@ const usersStore = useUsersStore()
|
||||
|
||||
const calendars = ref([])
|
||||
const loading = ref(false)
|
||||
const eventCounts = ref({}) // calendarId -> event count
|
||||
|
||||
// 编辑相关
|
||||
const showEditModal = ref(false)
|
||||
@@ -54,8 +53,6 @@ async function fetchCalendars() {
|
||||
usersStore.fetchUser(cal.UserID)
|
||||
}
|
||||
})
|
||||
// 获取每个日历的事件数量
|
||||
fetchEventCounts()
|
||||
}
|
||||
} catch {
|
||||
// 拦截器已处理
|
||||
@@ -64,35 +61,6 @@ async function fetchCalendars() {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchEventCounts() {
|
||||
// 获取一年前到现在的事件,用于统计
|
||||
const now = new Date()
|
||||
const oneYearAgo = new Date()
|
||||
oneYearAgo.setFullYear(now.getFullYear() - 1)
|
||||
|
||||
const startStr = oneYearAgo.toISOString().split('T')[0]
|
||||
const endStr = now.toISOString().split('T')[0]
|
||||
|
||||
try {
|
||||
const { errCode, data } = await calendarApi.getEvents({
|
||||
start_date: startStr,
|
||||
end_date: endStr
|
||||
})
|
||||
if (errCode === 0 && data.list) {
|
||||
// 按日历ID统计事件数量
|
||||
const counts = {}
|
||||
data.list.forEach(event => {
|
||||
if (event.CalendarID) {
|
||||
counts[event.CalendarID] = (counts[event.CalendarID] || 0) + 1
|
||||
}
|
||||
})
|
||||
eventCounts.value = counts
|
||||
}
|
||||
} catch {
|
||||
// 忽略错误
|
||||
}
|
||||
}
|
||||
|
||||
function getCreatorName(userID) {
|
||||
return usersStore.getUsernameFromUserID(userID) || '...'
|
||||
}
|
||||
@@ -304,7 +272,7 @@ onMounted(fetchCalendars)
|
||||
<td class="whitespace-nowrap px-6 py-4 text-center">
|
||||
<div class="inline-flex items-center gap-1 text-gray-900 dark:text-dk-text">
|
||||
<IconCalendar :size="16" class="text-gray-400" />
|
||||
<span class="font-medium">{{ eventCounts[calendar.ID] || 0 }}</span>
|
||||
<span class="font-medium">{{ calendar.event_count ?? 0 }}</span>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
import { usePageTitle } from '@/composables/usePageTitle'
|
||||
import { calendarApi } from '@/api/calendar'
|
||||
import { IconPlus, IconCalendar, IconTrash, IconEdit } from '@tabler/icons-vue'
|
||||
import { IconPlus, IconCalendar, IconTrash, IconEdit, IconSettings } from '@tabler/icons-vue'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import ConfirmDialog from '@/components/ConfirmDialog.vue'
|
||||
|
||||
usePageTitle('appname.calendar')
|
||||
const { t } = useI18n()
|
||||
const router = useRouter()
|
||||
const toast = useToastStore()
|
||||
const userStore = useUserStore()
|
||||
const isCalendarAdmin = computed(() => userStore.isCalendarAdmin)
|
||||
|
||||
const calendars = ref([])
|
||||
const loading = ref(false)
|
||||
@@ -148,13 +151,23 @@ onMounted(fetchCalendars)
|
||||
<!-- Header -->
|
||||
<div class="flex items-center justify-between border-b border-gray-100 px-6 py-4 dark:border-dk-muted">
|
||||
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">{{ t('calendar.calendars') }}</h3>
|
||||
<button
|
||||
@click="openCreateModal"
|
||||
class="inline-flex items-center gap-1.5 rounded-lg bg-blue-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-blue-700"
|
||||
>
|
||||
<IconPlus :size="16" />
|
||||
{{ t('calendar.create_calendar') }}
|
||||
</button>
|
||||
<div class="flex items-center gap-2">
|
||||
<RouterLink
|
||||
v-if="isCalendarAdmin"
|
||||
to="/calendars/admin"
|
||||
class="inline-flex items-center gap-1.5 rounded-lg border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-dk-muted dark:text-gray-300 dark:hover:bg-dk-muted"
|
||||
>
|
||||
<IconSettings :size="16" />
|
||||
{{ t('calendar.admin_panel') }}
|
||||
</RouterLink>
|
||||
<button
|
||||
@click="openCreateModal"
|
||||
class="inline-flex items-center gap-1.5 rounded-lg bg-blue-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-blue-700"
|
||||
>
|
||||
<IconPlus :size="16" />
|
||||
{{ t('calendar.create_calendar') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Calendar List -->
|
||||
|
||||
Reference in New Issue
Block a user