mirror of
https://github.com/nuxt/ui.git
synced 2026-09-14 19:51:10 +08:00
15d32cea98
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
82 lines
1.7 KiB
Vue
82 lines
1.7 KiB
Vue
<script setup lang="ts">
|
|
import { h, resolveComponent } from 'vue'
|
|
import type { TableColumn } from '@nuxt/ui'
|
|
|
|
const UBadge = resolveComponent('UBadge')
|
|
|
|
type Payment = {
|
|
id: string
|
|
date: string
|
|
status: 'paid' | 'failed' | 'refunded'
|
|
email: string
|
|
amount: number
|
|
}
|
|
|
|
const data = ref<Payment[]>(Array(1000).fill(0).map((_, i) => ({
|
|
id: `4600-${i}`,
|
|
date: '2024-03-11T15:30:00',
|
|
status: 'paid',
|
|
email: 'james.anderson@example.com',
|
|
amount: 594
|
|
})))
|
|
|
|
const columns: TableColumn<Payment>[] = [{
|
|
accessorKey: 'id',
|
|
header: '#',
|
|
cell: ({ row }) => `#${row.getValue('id')}`
|
|
}, {
|
|
accessorKey: 'date',
|
|
header: 'Date',
|
|
cell: ({ row }) => {
|
|
return new Date(row.getValue('date')).toLocaleString('en-US', {
|
|
day: 'numeric',
|
|
month: 'short',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
hour12: false
|
|
})
|
|
}
|
|
}, {
|
|
accessorKey: 'status',
|
|
header: 'Status',
|
|
cell: ({ row }) => {
|
|
const color = ({
|
|
paid: 'success' as const,
|
|
failed: 'error' as const,
|
|
refunded: 'neutral' as const
|
|
})[row.getValue('status') as string]
|
|
|
|
return h(UBadge, { class: 'capitalize', variant: 'subtle', color }, () => row.getValue('status'))
|
|
}
|
|
}, {
|
|
accessorKey: 'email',
|
|
header: 'Email'
|
|
}, {
|
|
accessorKey: 'amount',
|
|
header: 'Amount',
|
|
meta: {
|
|
class: {
|
|
th: 'text-right',
|
|
td: 'text-right font-medium'
|
|
}
|
|
},
|
|
cell: ({ row }) => {
|
|
const amount = Number.parseFloat(row.getValue('amount'))
|
|
return new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency: 'EUR'
|
|
}).format(amount)
|
|
}
|
|
}]
|
|
</script>
|
|
|
|
<template>
|
|
<UTable
|
|
sticky
|
|
virtualize
|
|
:data="data"
|
|
:columns="columns"
|
|
class="flex-1 h-80"
|
|
/>
|
|
</template>
|