Обзор мерчантов
Рейтинг мерчантов на графиках и таблица с поиском, выбором строк, сортировкой по названию и пагинацией.
Состав: Avatar, AvatarLabelGroup, Badge, Button, Card, Chart, Checkbox, DropdownMenu, EmptyState, FeaturedIcon, Field, Filters, IconButton, InputGroup, Kbd, NumberField, PageHeader, Pagination, ProgressBar, QueryContainer, SectionFooter, SectionHeader, Select, Sidebar, Slideout, Table.
vue
<script setup lang="ts">
import type { TableSort } from '@prosper/ui'
import { computed, ref, watch } from 'vue'
import { merchants } from '../data/merchants'
import MerchantsAverage from './MerchantsAverage.vue'
import MerchantsHeader from './MerchantsHeader.vue'
import MerchantsHeading from './MerchantsHeading.vue'
import MerchantsPagination from './MerchantsPagination.vue'
import MerchantsRating from './MerchantsRating.vue'
import MerchantsTable from './MerchantsTable.vue'
import ShellLayout from './ShellLayout.vue'
const query = ref('')
const sort = ref<TableSort>('ascending')
const page = ref(1)
const rows = ref(10)
const matches = computed(() => {
const text = query.value.trim().toLowerCase()
return merchants.filter(({ name, site }) =>
[name, site].some((value) => value.toLowerCase().includes(text)),
)
})
const shown = computed(() => {
const sign = sort.value === 'ascending' ? 1 : -1
const start = (page.value - 1) * rows.value
return [...matches.value]
.sort((first, second) => sign * first.name.localeCompare(second.name))
.slice(start, start + rows.value)
})
watch([query, rows], () => {
page.value = 1
})
const clear = (): void => {
query.value = ''
}
</script>
<template>
<ShellLayout current="Мерчанты">
<MerchantsHeader />
<div class="cards">
<MerchantsRating />
<MerchantsAverage />
</div>
<div class="results">
<MerchantsHeading v-model:query="query" />
<MerchantsTable v-model:sort="sort" :merchants="shown" @clear="clear">
<MerchantsPagination
v-if="matches.length > 0"
v-model:page="page"
v-model:rows="rows"
:total="matches.length"
/>
</MerchantsTable>
</div>
</ShellLayout>
</template>
<style scoped>
.cards,
.results {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: var(--prosper-spacing-3xl);
}
@media (width >= 64rem) {
.cards {
grid-template-columns:
calc(var(--prosper-space-80) + var(--prosper-space-10))
minmax(0, 1fr);
}
}
</style>vue
<script setup lang="ts">
import { IconButton } from '@prosper/ui'
import { Edit01, Trash01 } from '@prosper/ui/icons'
defineProps<{ name: string }>()
</script>
<template>
<div class="actions">
<IconButton variant="tertiary" size="xs" :aria-label="`Удалить ${name}`">
<Trash01 />
</IconButton>
<IconButton variant="tertiary" size="xs" :aria-label="`Изменить ${name}`">
<Edit01 />
</IconButton>
</div>
</template>
<style scoped>
.actions {
display: flex;
gap: var(--prosper-spacing-xxs);
}
</style>vue
<script setup lang="ts">
import {
Card,
Chart,
ChartLegend,
ChartTooltip,
ChartXAxis,
ChartYAxis,
SectionHeader,
SectionHeaderActions,
SectionHeaderContent,
SectionHeaderDescription,
SectionHeaderHeading,
SectionHeaderTitle,
} from '@prosper/ui'
import { ratingHistory } from '../data/merchants'
import MerchantsMenu from './MerchantsMenu.vue'
const series = [
{ key: 'own', name: 'Ваши мерчанты' },
{ key: 'market', name: 'Рынок' },
] as const
</script>
<template>
<Card as="section" class="card" aria-labelledby="average-title">
<SectionHeader>
<SectionHeaderContent>
<SectionHeaderHeading>
<SectionHeaderTitle id="average-title">
Средний рейтинг
</SectionHeaderTitle>
<SectionHeaderDescription>
Как рейтинг ваших мерчантов соотносится с рынком.
</SectionHeaderDescription>
</SectionHeaderHeading>
<SectionHeaderActions>
<MerchantsMenu label="Действия: Средний рейтинг" />
</SectionHeaderActions>
</SectionHeaderContent>
</SectionHeader>
<Chart
class="chart"
:data="ratingHistory"
category-key="month"
:series="series"
variant="line"
aria-labelledby="average-title"
>
<ChartLegend />
<ChartYAxis>Рейтинг надёжности</ChartYAxis>
<ChartXAxis>Месяц</ChartXAxis>
<ChartTooltip />
</Chart>
</Card>
</template>
<style scoped>
.card {
display: flex;
flex-direction: column;
gap: var(--prosper-spacing-3xl);
padding: var(--prosper-spacing-3xl);
}
.chart {
block-size: var(--prosper-space-64);
flex-grow: 1;
}
</style>vue
<script setup lang="ts">
import {
Button,
EmptyState,
EmptyStateActions,
EmptyStateDescription,
EmptyStateMedia,
EmptyStateTitle,
FeaturedIcon,
TableCell,
TableRow,
} from '@prosper/ui'
import { SearchLg } from '@prosper/ui/icons'
defineEmits<{ clear: [] }>()
</script>
<template>
<TableRow>
<TableCell colspan="6">
<EmptyState size="sm">
<EmptyStateMedia>
<FeaturedIcon variant="modern" color="gray" size="lg">
<SearchLg />
</FeaturedIcon>
</EmptyStateMedia>
<EmptyStateTitle>Мерчанты не найдены</EmptyStateTitle>
<EmptyStateDescription>
Измените запрос, чтобы снова увидеть мерчантов.
</EmptyStateDescription>
<EmptyStateActions>
<Button variant="secondary" size="sm" @click="$emit('clear')">
Сбросить поиск
</Button>
</EmptyStateActions>
</EmptyState>
</TableCell>
</TableRow>
</template>vue
<script setup lang="ts">
import {
Button,
ButtonIcon,
Field,
FieldLabel,
Filters,
FiltersBody,
FiltersContent,
FiltersCount,
FiltersTrigger,
PageHeader,
PageHeaderActions,
PageHeaderContent,
PageHeaderHeading,
PageHeaderTitle,
Select,
SelectItem,
} from '@prosper/ui'
import { DownloadCloud02, Sliders02 } from '@prosper/ui/icons'
</script>
<template>
<PageHeader>
<PageHeaderContent>
<PageHeaderHeading>
<PageHeaderTitle>Обзор мерчантов</PageHeaderTitle>
</PageHeaderHeading>
<PageHeaderActions>
<Filters>
<FiltersTrigger>
Фильтры
<FiltersCount>3</FiltersCount>
</FiltersTrigger>
<FiltersContent align="end">
<FiltersBody>
<Field>
<FieldLabel>Статус</FieldLabel>
<Select>
<SelectItem value="all">Все статусы</SelectItem>
<SelectItem value="active">Активен</SelectItem>
<SelectItem value="inactive">Неактивен</SelectItem>
</Select>
</Field>
<Field>
<FieldLabel>Категория</FieldLabel>
<Select>
<SelectItem value="all">Все категории</SelectItem>
<SelectItem value="payments">Платежи</SelectItem>
<SelectItem value="customers">Клиенты</SelectItem>
<SelectItem value="admin">Админ</SelectItem>
<SelectItem value="finance">Финансы</SelectItem>
</Select>
</Field>
</FiltersBody>
</FiltersContent>
</Filters>
<Button variant="secondary" size="sm">
<ButtonIcon><Sliders02 /></ButtonIcon>
Настроить
</Button>
<Button variant="secondary" size="sm">
<ButtonIcon><DownloadCloud02 /></ButtonIcon>
Экспорт
</Button>
</PageHeaderActions>
</PageHeaderContent>
</PageHeader>
</template>vue
<script setup lang="ts">
import {
InputGroup,
InputGroupAddon,
InputGroupInput,
Kbd,
SectionHeader,
SectionHeaderContent,
SectionHeaderDescription,
SectionHeaderHeading,
SectionHeaderTitle,
} from '@prosper/ui'
import { SearchLg } from '@prosper/ui/icons'
const query = defineModel<string>('query', { required: true })
</script>
<template>
<SectionHeader>
<SectionHeaderContent>
<SectionHeaderHeading>
<SectionHeaderTitle>Движение мерчантов</SectionHeaderTitle>
<SectionHeaderDescription>
Следите за мерчантами и их рейтингом надёжности.
</SectionHeaderDescription>
</SectionHeaderHeading>
<InputGroup size="sm" class="search">
<InputGroupAddon><SearchLg /></InputGroupAddon>
<InputGroupInput
v-model="query"
type="search"
aria-label="Поиск мерчантов"
placeholder="Название или сайт"
/>
<InputGroupAddon class="hint" variant="inline" align="end">
<Kbd aria-hidden="true">⌘K</Kbd>
</InputGroupAddon>
</InputGroup>
</SectionHeaderContent>
</SectionHeader>
</template>
<style scoped>
.search {
flex: 0 1 calc(var(--prosper-space-64) + var(--prosper-space-6));
}
@media (width < 40rem) {
.search {
flex-basis: 100%;
}
.search :deep(.hint) {
display: none;
}
}
</style>vue
<script setup lang="ts">
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
IconButton,
} from '@prosper/ui'
import { DotsVertical } from '@prosper/ui/icons'
defineProps<{ label: string }>()
</script>
<template>
<DropdownMenu>
<DropdownMenuTrigger as-child>
<IconButton variant="tertiary" size="md" :aria-label="label">
<DotsVertical />
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>Скачать отчёт</DropdownMenuItem>
<DropdownMenuItem>Настроить период</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</template>vue
<script setup lang="ts">
import { NumberField, NumberFieldInput, Select, SelectItem } from '@prosper/ui'
defineProps<{ pageCount: number }>()
const page = defineModel<number>('page', { required: true })
const rows = defineModel<number>('rows', { required: true })
</script>
<template>
<div class="go">
<span>Страница</span>
<NumberField
size="sm"
:model-value="page"
:min="1"
:max="pageCount"
class="page-field"
@update:model-value="page = $event ?? page"
>
<NumberFieldInput aria-label="Перейти к странице" />
</NumberField>
<span>из {{ pageCount }}</span>
<span>Строк на странице</span>
<Select
size="sm"
aria-label="Строк на странице"
:model-value="rows"
@update:model-value="rows = Number($event)"
>
<SelectItem v-for="option in [10, 20, 50]" :key="option" :value="option">
{{ option }}
</SelectItem>
</Select>
</div>
</template>
<style scoped>
.go {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--prosper-spacing-md);
}
.page-field {
inline-size: var(--prosper-space-16);
}
@media (width < 40rem) {
.go {
display: none;
}
}
</style>vue
<script setup lang="ts">
import {
Button,
ButtonIcon,
Pagination,
PaginationFirst,
PaginationLast,
PaginationList,
PaginationNext,
PaginationPrev,
} from '@prosper/ui'
import { ArrowLeft, ArrowRight } from '@prosper/ui/icons'
import { computed } from 'vue'
import MerchantsPageFields from './MerchantsPageFields.vue'
const props = defineProps<{ total: number }>()
const page = defineModel<number>('page', { required: true })
const rows = defineModel<number>('rows', { required: true })
const pageCount = computed(() => Math.ceil(props.total / rows.value))
</script>
<template>
<div class="bar">
<MerchantsPageFields
v-model:page="page"
v-model:rows="rows"
:page-count="pageCount"
/>
<Pagination
v-model:page="page"
aria-label="Страницы мерчантов"
:total="total"
:items-per-page="rows"
class="pages"
>
<PaginationFirst class="wide" />
<PaginationPrev class="wide" />
<PaginationPrev as-child class="narrow">
<Button variant="secondary" size="sm" aria-label="Предыдущая страница">
<ButtonIcon align="only"><ArrowLeft /></ButtonIcon>
</Button>
</PaginationPrev>
<PaginationList class="wide" />
<span class="narrow">Страница {{ page }} из {{ pageCount }}</span>
<PaginationNext class="wide" />
<PaginationNext as-child class="narrow">
<Button variant="secondary" size="sm" aria-label="Следующая страница">
<ButtonIcon align="only"><ArrowRight /></ButtonIcon>
</Button>
</PaginationNext>
<PaginationLast class="wide" />
</Pagination>
</div>
</template>
<style scoped>
.bar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: var(--prosper-spacing-lg);
border-block-start: 1px solid var(--prosper-color-border-secondary);
padding: var(--prosper-spacing-lg) var(--prosper-spacing-3xl)
var(--prosper-spacing-xl);
}
.pages {
margin-inline-start: auto;
}
@media (width < 40rem) {
.wide {
display: none;
}
.pages {
justify-content: space-between;
inline-size: 100%;
}
}
@media (width >= 40rem) {
.narrow {
display: none;
}
}
</style>vue
<script setup lang="ts">
import {
Button,
Card,
Chart,
ChartLegend,
ChartTooltip,
SectionFooter,
SectionFooterActions,
SectionFooterContent,
SectionFooterDivider,
SectionHeader,
SectionHeaderActions,
SectionHeaderContent,
SectionHeaderHeading,
SectionHeaderTitle,
} from '@prosper/ui'
import { merchants, ratingBands } from '../data/merchants'
import MerchantsMenu from './MerchantsMenu.vue'
const series = [{ key: 'count', name: 'Мерчанты' }] as const
const bands = ratingBands.map(({ label, min, max }) => ({
band: label,
count: merchants.filter(({ rating }) => rating >= min && rating <= max)
.length,
}))
</script>
<template>
<Card as="section" class="card" aria-labelledby="rating-title">
<SectionHeader>
<SectionHeaderContent>
<SectionHeaderHeading>
<SectionHeaderTitle id="rating-title">
Мерчанты по рейтингу
</SectionHeaderTitle>
</SectionHeaderHeading>
<SectionHeaderActions>
<MerchantsMenu label="Действия: Мерчанты по рейтингу" />
</SectionHeaderActions>
</SectionHeaderContent>
</SectionHeader>
<Chart
class="chart"
:data="bands"
category-key="band"
:series="series"
variant="pie"
aria-labelledby="rating-title"
>
<ChartLegend position="right" />
<ChartTooltip />
</Chart>
<SectionFooter>
<SectionFooterDivider />
<SectionFooterContent>
<SectionFooterActions>
<Button variant="secondary" size="sm">Полный отчёт</Button>
</SectionFooterActions>
</SectionFooterContent>
</SectionFooter>
</Card>
</template>
<style scoped>
.card {
display: flex;
flex-direction: column;
gap: var(--prosper-spacing-3xl);
padding: var(--prosper-spacing-3xl);
}
.chart {
block-size: calc(var(--prosper-space-48) + var(--prosper-space-2));
}
</style>vue
<script setup lang="ts">
import {
Avatar,
AvatarFallback,
AvatarLabelGroup,
AvatarLabelGroupDescription,
AvatarLabelGroupName,
Badge,
BadgeIcon,
Checkbox,
ProgressBar,
TableCell,
TableRow,
} from '@prosper/ui'
import { ArrowDown, ArrowUp } from '@prosper/ui/icons'
import { computed } from 'vue'
import type { Merchant } from '../data/merchants'
import MerchantsActions from './MerchantsActions.vue'
import MerchantsTags from './MerchantsTags.vue'
const props = defineProps<{ merchant: Merchant }>()
const selected = defineModel<boolean>('selected', { required: true })
const rising = computed(() => props.merchant.trend > 0)
</script>
<template>
<TableRow :selected="selected">
<TableCell>
<template #leading>
<Checkbox
v-model:checked="selected"
:aria-label="`Выбрать ${merchant.name}`"
/>
</template>
<div class="person">
<AvatarLabelGroup size="md">
<Avatar>
<AvatarFallback>{{ merchant.initials }}</AvatarFallback>
</Avatar>
<AvatarLabelGroupName>{{ merchant.name }}</AvatarLabelGroupName>
<AvatarLabelGroupDescription>
{{ merchant.site }}
</AvatarLabelGroupDescription>
</AvatarLabelGroup>
</div>
</TableCell>
<TableCell>
<div class="rating">
<ProgressBar
:value="merchant.rating"
label-position="right"
:aria-label="`Рейтинг: ${merchant.name}`"
>
{{ merchant.rating }}
</ProgressBar>
</div>
</TableCell>
<TableCell class="detail">
<Badge size="sm" variant="badge" :color="rising ? 'success' : 'error'">
<BadgeIcon><component :is="rising ? ArrowUp : ArrowDown" /></BadgeIcon>
{{ Math.abs(merchant.trend) }} %
</Badge>
</TableCell>
<TableCell class="detail">
<span class="nowrap">{{ merchant.checkedOn }}</span>
</TableCell>
<TableCell class="detail">
<MerchantsTags :tags="merchant.tags" />
</TableCell>
<TableCell class="detail">
<MerchantsActions :name="merchant.name" />
</TableCell>
</TableRow>
</template>
<style scoped>
.person {
min-inline-size: calc(var(--prosper-space-32) + var(--prosper-space-4));
}
.rating {
min-inline-size: var(--prosper-space-16);
}
@media (width >= 40rem) {
.rating {
min-inline-size: var(--prosper-space-40);
}
}
.nowrap {
white-space: nowrap;
}
@media (width < 40rem) {
.detail {
display: none;
}
}
</style>vue
<script setup lang="ts">
import {
Card,
Checkbox,
Table,
TableBody,
TableHead,
TableHeader,
TableRow,
type TableSort,
} from '@prosper/ui'
import { computed, ref } from 'vue'
import type { Merchant } from '../data/merchants'
import MerchantsEmpty from './MerchantsEmpty.vue'
import MerchantsRow from './MerchantsRow.vue'
const props = defineProps<{ merchants: readonly Merchant[] }>()
const sort = defineModel<TableSort>('sort', { required: true })
defineEmits<{ clear: [] }>()
const selected = ref<string[]>([])
const all = computed(
() =>
props.merchants.length > 0 &&
props.merchants.every(({ name }) => selected.value.includes(name)),
)
const some = computed(() =>
props.merchants.some(({ name }) => selected.value.includes(name)),
)
const setAll = (checked: boolean): void => {
const shown = props.merchants.map(({ name }) => name)
const others = selected.value.filter((name) => !shown.includes(name))
selected.value = checked ? [...others, ...shown] : others
}
const setOne = (name: string, checked: boolean): void => {
selected.value = checked
? [...selected.value, name]
: selected.value.filter((value) => value !== name)
}
const flip = (next: TableSort): void => {
sort.value = next === 'descending' ? 'descending' : 'ascending'
}
</script>
<template>
<Card class="table-card">
<Table aria-label="Мерчанты">
<TableHeader>
<TableRow>
<TableHead :sort="sort" @update:sort="flip">
<template #leading>
<Checkbox
aria-label="Выбрать всех мерчантов на странице"
:checked="all"
:indeterminate="some && !all"
@update:checked="setAll"
/>
</template>
Мерчант
</TableHead>
<TableHead>Рейтинг</TableHead>
<TableHead class="detail">Изменение</TableHead>
<TableHead class="detail">Последняя проверка</TableHead>
<TableHead class="detail">Категории</TableHead>
<TableHead class="detail">Действия</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<MerchantsRow
v-for="merchant in merchants"
:key="merchant.name"
:merchant="merchant"
:selected="selected.includes(merchant.name)"
@update:selected="setOne(merchant.name, $event)"
/>
<MerchantsEmpty v-if="merchants.length === 0" @clear="$emit('clear')" />
</TableBody>
</Table>
<slot />
</Card>
</template>
<style scoped>
@container prosper (width < 40rem) {
@media (width < 64rem) {
.table-card {
margin-inline: calc(var(--prosper-spacing-xl) * -1);
}
}
}
@media (width < 40rem) {
.detail {
display: none;
}
}
</style>vue
<script setup lang="ts">
import { Badge, BadgeDot } from '@prosper/ui'
import { computed } from 'vue'
import { type MerchantTag, merchantTags } from '../data/merchants'
const props = defineProps<{ tags: readonly MerchantTag[] }>()
const shown = computed(() => props.tags.slice(0, 2))
const hidden = computed(() => props.tags.length - 2)
</script>
<template>
<div class="tags">
<Badge
v-for="tag in shown"
:key="tag"
size="sm"
variant="pill"
:color="merchantTags[tag].color"
>
<BadgeDot v-if="merchantTags[tag].dot" />
{{ merchantTags[tag].label }}
</Badge>
<Badge v-if="hidden > 0" size="sm" variant="pill" color="gray">
+{{ hidden }}
</Badge>
</div>
</template>
<style scoped>
.tags {
display: flex;
gap: var(--prosper-spacing-xs);
}
</style>ts
import type { BadgeColor } from '@prosper/ui'
export type MerchantTag =
'active' | 'inactive' | 'payments' | 'customers' | 'admin' | 'finance'
export const merchantTags: Record<
MerchantTag,
{ label: string; color: BadgeColor; dot?: boolean }
> = {
active: { label: 'Активен', color: 'success', dot: true },
inactive: { label: 'Неактивен', color: 'gray', dot: true },
payments: { label: 'Платежи', color: 'purple' },
customers: { label: 'Клиенты', color: 'blue' },
admin: { label: 'Админ', color: 'indigo' },
finance: { label: 'Финансы', color: 'pink' },
}
export interface Merchant {
name: string
site: string
initials: string
rating: number
trend: number
checkedOn: string
tags: MerchantTag[]
}
const names =
'Arnara|Tulpar|Sapero|Nurvia|Zhibeka|Alatora|Bayvel|Altyna|Qazora|Samero|Dalara|Kokvel|Irtona|Zhetvo|Ulvera|Tengel|Shymora|Kyzvel|Karvio|Almira|Astrova|Brenvio|Corvanta|Dorvelo|Elvara|Fenora|Gorvin|Hasvela|Ilvara|Jorvado|Kelvora|Lunara|Mirvos|Norvela|Oravel|Pelvana|Rivota|Solvera|Tavrel|Uvarka'.split(
'|',
)
const categories: MerchantTag[][] = [
['payments'],
['payments', 'customers'],
['customers', 'admin'],
['finance', 'admin', 'payments'],
['admin'],
]
const siteOf = (name: string): string => `${name.toLowerCase()}.kz`
const initialsOf = (name: string): string => name.slice(0, 2).toUpperCase()
const checkedOn = (index: number): string =>
new Date(Date.UTC(2026, 8, 1 + ((index * 7) % 71))).toLocaleDateString('ru', {
day: 'numeric',
month: 'short',
year: 'numeric',
timeZone: 'UTC',
})
export const merchants: readonly Merchant[] = names.map((name, index) => ({
name,
site: siteOf(name),
initials: initialsOf(name),
rating: 1 + ((index * 37) % 100),
trend: ((index % 9) + 1) * (index % 3 === 0 ? -1 : 1),
checkedOn: checkedOn(index),
tags: [
index % 6 === 5 ? 'inactive' : 'active',
...categories[index % categories.length],
],
}))
export const ratingBands = [
{ label: '81–100', min: 81, max: 100 },
{ label: '61–80', min: 61, max: 80 },
{ label: '41–60', min: 41, max: 60 },
{ label: '21–40', min: 21, max: 40 },
{ label: '0–20', min: 0, max: 20 },
]
export const ratingHistory = [
{ month: 'янв', own: 60, market: 33 },
{ month: 'фев', own: 63, market: 35 },
{ month: 'мар', own: 62, market: 36 },
{ month: 'апр', own: 65, market: 38 },
{ month: 'май', own: 68, market: 41 },
{ month: 'июн', own: 69, market: 42 },
{ month: 'июл', own: 72, market: 44 },
{ month: 'авг', own: 74, market: 46 },
{ month: 'сен', own: 75, market: 49 },
{ month: 'окт', own: 78, market: 51 },
{ month: 'ноя', own: 80, market: 54 },
{ month: 'дек', own: 84, market: 57 },
]