پنلِ مدیریتِ سفارش
پیشنمایش تمامصفحهتیتر و شمارِ سفارش، جستوجو و سفارشِ تازه، جدولِ پرداده با کانالِ برچسبدار و کلیدِ فعال/غیرفعال، و صفحهبندیِ شمارهدار با برو به صفحه و ردیف در صفحه.
۱. نصب کامپوننتها
این بلاک از ۱۲ آیتم دیگ استفاده میکند: badgebuttoncontrol-sizeiconspaginationpersiansearch-fieldselectswitchtabletext-fieldtoast
npx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/switch.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/switch.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/switch.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/switch.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.jsonnpx digdesign@latest add badge button control-size pagination persian search-field select switch table text-field toast --framework vuepnpm dlx digdesign@latest add badge button control-size pagination persian search-field select switch table text-field toast --framework vueyarn dlx digdesign@latest add badge button control-size pagination persian search-field select switch table text-field toast --framework vuebunx --bun digdesign@latest add badge button control-size pagination persian search-field select switch table text-field toast --framework vuenpx digdesign@latest add button --framework sveltepnpm dlx digdesign@latest add button --framework svelteyarn dlx digdesign@latest add button --framework sveltebunx --bun digdesign@latest add button --framework sveltenpx digdesign@latest add badge button control-size icons input pagination persian search-field select switch table text-field toast --framework angularpnpm dlx digdesign@latest add badge button control-size icons input pagination persian search-field select switch table text-field toast --framework angularyarn dlx digdesign@latest add badge button control-size icons input pagination persian search-field select switch table text-field toast --framework angularbunx --bun digdesign@latest add badge button control-size icons input pagination persian search-field select switch table text-field toast --framework angularnpx digdesign@latest add badge button control-size pagination persian search-field select switch table text-field toast --framework androidpnpm dlx digdesign@latest add badge button control-size pagination persian search-field select switch table text-field toast --framework androidyarn dlx digdesign@latest add badge button control-size pagination persian search-field select switch table text-field toast --framework androidbunx --bun digdesign@latest add badge button control-size pagination persian search-field select switch table text-field toast --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client"
import * as React from "react"
import { PlusIcon, SearchIcon } from "@/components/icons"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "@/components/ui/pagination"
import { SearchField } from "@/components/ui/search-field"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Switch } from "@/components/ui/switch"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { TextField } from "@/components/ui/text-field"
import { toast } from "@/components/ui/toast"
import { formatCurrency, toFaDigits, toSearchKey } from "@/lib/persian"
type Channel = "web" | "app" | "store"
const CHANNEL: Record<Channel, { label: string; color: "info" | "violet" | "orange" }> = {
web: { label: "سایت", color: "info" },
app: { label: "اپ", color: "violet" },
store: { label: "حضوری", color: "orange" },
}
const ORDERS: { id: string; customer: string; phone: string; channel: Channel; active: boolean; created: string; due: string; amount: number }[] = [
{ id: "۱۰۴۲", customer: "نگار احمدی", phone: "09123456789", channel: "web", active: true, created: "۱۴۰۵/۰۷/۱۳", due: "۱۴۰۵/۰۷/۱۵", amount: 1_290_000 },
{ id: "۱۰۴۱", customer: "کافه رست", phone: "09121112233", channel: "store", active: true, created: "۱۴۰۵/۰۷/۱۳", due: "۱۴۰۵/۰۷/۱۴", amount: 4_850_000 },
{ id: "۱۰۴۰", customer: "امیر رضایی", phone: "09359876543", channel: "app", active: false, created: "۱۴۰۵/۰۷/۱۲", due: "۱۴۰۵/۰۷/۱۶", amount: 640_000 },
{ id: "۱۰۳۹", customer: "فروشگاهِ بوم", phone: "09127654321", channel: "web", active: true, created: "۱۴۰۵/۰۷/۱۲", due: "۱۴۰۵/۰۷/۱۵", amount: 2_100_000 },
{ id: "۱۰۳۸", customer: "سارا محمدی", phone: "09191234567", channel: "app", active: true, created: "۱۴۰۵/۰۷/۱۱", due: "۱۴۰۵/۰۷/۱۳", amount: 980_000 },
{ id: "۱۰۳۷", customer: "علی کاظمی", phone: "09381239876", channel: "store", active: false, created: "۱۴۰۵/۰۷/۱۱", due: "۱۴۰۵/۰۷/۱۴", amount: 350_000 },
]
const PAGES = 50
/**
* پنلِ مدیریتِ سفارشها با جدولِ پرداده: تیتر و شمارِ سفارشها، جستوجو و «سفارشِ تازه»، جدولی با کانالِ برچسبدار، کلیدِ فعال/غیرفعال روی هر ردیف (با پیامِ تأیید)، و
* صفحهبندیِ شمارهدار با «برو به صفحه» و تعدادِ ردیف در هر صفحه. جدول در موبایل اسکرولِ خودش را دارد.
*/
export default function OrdersAdminBlock() {
const [query, setQuery] = React.useState("")
const [rows, setRows] = React.useState(ORDERS)
const [page, setPage] = React.useState(1)
const [jump, setJump] = React.useState("")
const visible = rows.filter((row) => toSearchKey(row.customer + row.id).includes(toSearchKey(query)))
return (
<ControlSizeProvider size="xl" asChild>
<main className="mx-auto flex w-full max-w-6xl flex-col gap-8 p-4 sm:p-6">
<header className="flex items-start justify-between gap-4">
<div className="flex flex-col gap-1">
<h1 className="text-2xl leading-snug font-black">سفارشها</h1>
<p className="text-muted-foreground">
{toFaDigits(rows.length)} سفارش · {toFaDigits(rows.filter((row) => row.active).length)} فعال
</p>
</div>
<Button className="shrink-0">
<PlusIcon />
سفارشِ تازه
</Button>
</header>
<section aria-label="فهرستِ سفارشها" className="flex flex-col gap-6">
<SearchField aria-label="جستوجو در سفارشها" placeholder="نام مشتری یا شمارهٔ سفارش" value={query} onValueChange={setQuery} className="w-full sm:w-80" icon={<SearchIcon />} />
{/* موبایل: هر سفارش یک کارتِ جمعوجور با همهٔ اطلاعاتِ مهم؛ جدولِ پهن فقط از md به بعد. */}
<ul className="flex flex-col divide-y divide-border rounded-xl border border-border bg-card md:hidden">
{visible.length === 0 ? (
<li className="p-8 text-center text-muted-foreground">سفارشی با «{query}» پیدا نشد.</li>
) : (
visible.map((row) => (
<li key={row.id} className="flex flex-col gap-3 p-4">
<div className="flex items-start justify-between gap-3">
<span className="flex flex-col gap-0.5">
<span className="font-bold">{row.customer}</span>
<span className="text-sm text-muted-foreground tabular-nums">
#{row.id} · تحویل {row.due}
</span>
</span>
<span className="font-bold tabular-nums">{formatCurrency(row.amount)}</span>
</div>
<div className="flex items-center justify-between gap-3">
<Badge variant="soft" color={CHANNEL[row.channel].color} className="rounded-full">
{CHANNEL[row.channel].label}
</Badge>
<label className="flex items-center gap-2 text-sm text-muted-foreground">
{row.active ? "فعال" : "متوقف"}
<Switch
checked={row.active}
aria-label={`فعال بودنِ سفارشِ ${row.id}`}
onCheckedChange={(checked) => {
setRows((list) => list.map((item) => (item.id === row.id ? { ...item, active: checked } : item)))
toast.success(checked ? `سفارشِ ${row.id} فعال شد.` : `سفارشِ ${row.id} متوقف شد.`)
}}
/>
</label>
</div>
</li>
))
)}
</ul>
<div className="hidden rounded-xl border border-border bg-card md:block">
<Table className="min-w-[52rem]">
<TableHeader>
<TableRow className="bg-subtle hover:bg-subtle">
<TableHead>سفارش</TableHead>
<TableHead>مشتری</TableHead>
<TableHead>موبایل</TableHead>
<TableHead>کانال</TableHead>
<TableHead>فعال</TableHead>
<TableHead>ثبت</TableHead>
<TableHead>تحویل</TableHead>
<TableHead className="text-end">مبلغ</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{visible.length === 0 ? (
<TableRow className="hover:bg-card">
<TableCell colSpan={8} className="py-12 text-center text-muted-foreground">
سفارشی با «{query}» پیدا نشد.
</TableCell>
</TableRow>
) : (
visible.map((row) => (
<TableRow key={row.id}>
<TableCell className="font-semibold tabular-nums">#{row.id}</TableCell>
<TableCell className="font-medium">{row.customer}</TableCell>
<TableCell>
<bdi dir="ltr" className="text-muted-foreground tabular-nums">
{toFaDigits(row.phone)}
</bdi>
</TableCell>
<TableCell>
<Badge variant="soft" color={CHANNEL[row.channel].color} className="rounded-full">
{CHANNEL[row.channel].label}
</Badge>
</TableCell>
<TableCell>
<Switch
checked={row.active}
aria-label={`فعال بودنِ سفارشِ ${row.id}`}
onCheckedChange={(checked) => {
setRows((list) => list.map((item) => (item.id === row.id ? { ...item, active: checked } : item)))
toast.success(checked ? `سفارشِ ${row.id} فعال شد.` : `سفارشِ ${row.id} متوقف شد.`)
}}
/>
</TableCell>
<TableCell className="text-muted-foreground tabular-nums">{row.created}</TableCell>
<TableCell className="text-muted-foreground tabular-nums">{row.due}</TableCell>
<TableCell className="text-end font-semibold tabular-nums">{formatCurrency(row.amount)}</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
{/* صفحهبندی: شمارهها، پرش به صفحه و تعدادِ ردیف؛ در موبایل زیرِ هم. */}
<div className="flex flex-col items-center gap-6 lg:flex-row lg:justify-between">
<Pagination className="mx-0 w-auto">
<PaginationContent className="flex-wrap justify-center">
<PaginationItem>
<PaginationPrevious href="#" onClick={(event) => (event.preventDefault(), setPage((value) => Math.max(1, value - 1)))} />
</PaginationItem>
{[1, 2, 3].map((number) => (
<PaginationItem key={number}>
<PaginationLink href="#" isActive={number === page} onClick={(event) => (event.preventDefault(), setPage(number))}>
{toFaDigits(number)}
</PaginationLink>
</PaginationItem>
))}
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#" isActive={page === PAGES} onClick={(event) => (event.preventDefault(), setPage(PAGES))}>
{toFaDigits(PAGES)}
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" onClick={(event) => (event.preventDefault(), setPage((value) => Math.min(PAGES, value + 1)))} />
</PaginationItem>
</PaginationContent>
</Pagination>
<div className="flex items-end justify-center gap-2">
<form
className="flex items-end gap-2"
onSubmit={(event) => {
event.preventDefault()
const target = Number(jump)
if (target >= 1 && target <= PAGES) setPage(target)
else toast.error(`صفحه باید بینِ ۱ و ${toFaDigits(PAGES)} باشد.`)
}}
>
<TextField aria-label="برو به صفحه" placeholder="برو به صفحه" inputMode="numeric" dir="rtl" value={jump} onValueChange={setJump} className="w-28" />
<Button type="submit" variant="outline">
برو
</Button>
</form>
<ControlSizeProvider size="xl" asChild>
<Select defaultValue="10">
<SelectTrigger aria-label="ردیف در هر صفحه" className="w-auto gap-2">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="10">۱۰ ردیف</SelectItem>
<SelectItem value="25">۲۵ ردیف</SelectItem>
<SelectItem value="50">۵۰ ردیف</SelectItem>
</SelectContent>
</Select>
</ControlSizeProvider>
</div>
</div>
</section>
</main>
</ControlSizeProvider>
)
}
<script setup lang="ts">
import { computed, ref } from "vue"
import Badge from "@/components/ui/Badge.vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Pagination from "@/components/ui/Pagination.vue"
import PaginationContent from "@/components/ui/PaginationContent.vue"
import PaginationEllipsis from "@/components/ui/PaginationEllipsis.vue"
import PaginationItem from "@/components/ui/PaginationItem.vue"
import PaginationLink from "@/components/ui/PaginationLink.vue"
import PaginationNext from "@/components/ui/PaginationNext.vue"
import PaginationPrevious from "@/components/ui/PaginationPrevious.vue"
import SearchField from "@/components/ui/SearchField.vue"
import Select from "@/components/ui/Select.vue"
import SelectContent from "@/components/ui/SelectContent.vue"
import SelectItem from "@/components/ui/SelectItem.vue"
import SelectTrigger from "@/components/ui/SelectTrigger.vue"
import SelectValue from "@/components/ui/SelectValue.vue"
import Switch from "@/components/ui/Switch.vue"
import Table from "@/components/ui/Table.vue"
import TableBody from "@/components/ui/TableBody.vue"
import TableCell from "@/components/ui/TableCell.vue"
import TableHead from "@/components/ui/TableHead.vue"
import TableHeader from "@/components/ui/TableHeader.vue"
import TableRow from "@/components/ui/TableRow.vue"
import TextField from "@/components/ui/TextField.vue"
import { toast } from "@/components/ui/Toast.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits, toSearchKey } from "@/lib/persian"
/**
* پنلِ مدیریتِ سفارشها با جدولِ پرداده: تیتر و شمارِ سفارشها، جستوجو و «سفارشِ تازه»، جدولی با کانالِ برچسبدار، کلیدِ فعال/غیرفعال روی هر ردیف (با پیامِ تأیید)، و
* صفحهبندیِ شمارهدار با «برو به صفحه» و تعدادِ ردیف در هر صفحه. جدول در موبایل اسکرولِ خودش را دارد.
*/
type Channel = "web" | "app" | "store"
type Row = { id: string; customer: string; phone: string; channel: Channel; active: boolean; created: string; due: string; amount: number }
const CHANNEL: Record<Channel, { label: string; color: "info" | "violet" | "orange" }> = {
web: { label: "سایت", color: "info" },
app: { label: "اپ", color: "violet" },
store: { label: "حضوری", color: "orange" },
}
const ORDERS: Row[] = [
{ id: "۱۰۴۲", customer: "نگار احمدی", phone: "09123456789", channel: "web", active: true, created: "۱۴۰۵/۰۷/۱۳", due: "۱۴۰۵/۰۷/۱۵", amount: 1_290_000 },
{ id: "۱۰۴۱", customer: "کافه رست", phone: "09121112233", channel: "store", active: true, created: "۱۴۰۵/۰۷/۱۳", due: "۱۴۰۵/۰۷/۱۴", amount: 4_850_000 },
{ id: "۱۰۴۰", customer: "امیر رضایی", phone: "09359876543", channel: "app", active: false, created: "۱۴۰۵/۰۷/۱۲", due: "۱۴۰۵/۰۷/۱۶", amount: 640_000 },
{ id: "۱۰۳۹", customer: "فروشگاهِ بوم", phone: "09127654321", channel: "web", active: true, created: "۱۴۰۵/۰۷/۱۲", due: "۱۴۰۵/۰۷/۱۵", amount: 2_100_000 },
{ id: "۱۰۳۸", customer: "سارا محمدی", phone: "09191234567", channel: "app", active: true, created: "۱۴۰۵/۰۷/۱۱", due: "۱۴۰۵/۰۷/۱۳", amount: 980_000 },
{ id: "۱۰۳۷", customer: "علی کاظمی", phone: "09381239876", channel: "store", active: false, created: "۱۴۰۵/۰۷/۱۱", due: "۱۴۰۵/۰۷/۱۴", amount: 350_000 },
]
const PAGES = 50
const query = ref("")
const rows = ref<Row[]>(ORDERS)
const page = ref(1)
const jump = ref("")
const visible = computed(() => rows.value.filter((row) => toSearchKey(row.customer + row.id).includes(toSearchKey(query.value))))
function setActive(row: Row, checked: boolean) {
rows.value = rows.value.map((item) => (item.id === row.id ? { ...item, active: checked } : item))
toast.success(checked ? `سفارشِ ${row.id} فعال شد.` : `سفارشِ ${row.id} متوقف شد.`)
}
function goJump() {
const target = Number(jump.value)
if (target >= 1 && target <= PAGES) page.value = target
else toast.error(`صفحه باید بینِ ۱ و ${toFaDigits(PAGES)} باشد.`)
}
</script>
<template>
<ControlSize size="xl" as-child>
<main class="mx-auto flex w-full max-w-6xl flex-col gap-8 p-4 sm:p-6">
<header class="flex items-start justify-between gap-4">
<div class="flex flex-col gap-1">
<h1 class="text-2xl leading-snug font-black">سفارشها</h1>
<p class="text-muted-foreground">
{{ toFaDigits(rows.length) }} سفارش · {{ toFaDigits(rows.filter((row) => row.active).length) }} فعال
</p>
</div>
<Button class="shrink-0">
<DigIcon name="plus" />
سفارشِ تازه
</Button>
</header>
<section aria-label="فهرستِ سفارشها" class="flex flex-col gap-6">
<SearchField v-model="query" aria-label="جستوجو در سفارشها" placeholder="نام مشتری یا شمارهٔ سفارش" class="w-full sm:w-80">
<template #icon><DigIcon name="search" /></template>
</SearchField>
<!-- موبایل: هر سفارش یک کارتِ جمعوجور با همهٔ اطلاعاتِ مهم؛ جدولِ پهن فقط از md به بعد. -->
<ul class="flex flex-col divide-y divide-border rounded-xl border border-border bg-card md:hidden">
<li v-if="visible.length === 0" class="p-8 text-center text-muted-foreground">سفارشی با «{{ query }}» پیدا نشد.</li>
<li v-for="row in visible" v-else :key="row.id" class="flex flex-col gap-3 p-4">
<div class="flex items-start justify-between gap-3">
<span class="flex flex-col gap-0.5">
<span class="font-bold">{{ row.customer }}</span>
<span class="text-sm text-muted-foreground tabular-nums">
#{{ row.id }} · تحویل {{ row.due }}
</span>
</span>
<span class="font-bold tabular-nums">{{ formatCurrency(row.amount) }}</span>
</div>
<div class="flex items-center justify-between gap-3">
<Badge variant="soft" :color="CHANNEL[row.channel].color" class="rounded-full">
{{ CHANNEL[row.channel].label }}
</Badge>
<label class="flex items-center gap-2 text-sm text-muted-foreground">
{{ row.active ? "فعال" : "متوقف" }}
<Switch :checked="row.active" :aria-label="`فعال بودنِ سفارشِ ${row.id}`" @update:checked="setActive(row, $event)" />
</label>
</div>
</li>
</ul>
<div class="hidden rounded-xl border border-border bg-card md:block">
<Table class="min-w-[52rem]">
<TableHeader>
<TableRow class="bg-subtle hover:bg-subtle">
<TableHead>سفارش</TableHead>
<TableHead>مشتری</TableHead>
<TableHead>موبایل</TableHead>
<TableHead>کانال</TableHead>
<TableHead>فعال</TableHead>
<TableHead>ثبت</TableHead>
<TableHead>تحویل</TableHead>
<TableHead class="text-end">مبلغ</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-if="visible.length === 0" class="hover:bg-card">
<TableCell :colspan="8" class="py-12 text-center text-muted-foreground">
سفارشی با «{{ query }}» پیدا نشد.
</TableCell>
</TableRow>
<TableRow v-for="row in visible" v-else :key="row.id">
<TableCell class="font-semibold tabular-nums">#{{ row.id }}</TableCell>
<TableCell class="font-medium">{{ row.customer }}</TableCell>
<TableCell>
<bdi dir="ltr" class="text-muted-foreground tabular-nums">
{{ toFaDigits(row.phone) }}
</bdi>
</TableCell>
<TableCell>
<Badge variant="soft" :color="CHANNEL[row.channel].color" class="rounded-full">
{{ CHANNEL[row.channel].label }}
</Badge>
</TableCell>
<TableCell>
<Switch :checked="row.active" :aria-label="`فعال بودنِ سفارشِ ${row.id}`" @update:checked="setActive(row, $event)" />
</TableCell>
<TableCell class="text-muted-foreground tabular-nums">{{ row.created }}</TableCell>
<TableCell class="text-muted-foreground tabular-nums">{{ row.due }}</TableCell>
<TableCell class="text-end font-semibold tabular-nums">{{ formatCurrency(row.amount) }}</TableCell>
</TableRow>
</TableBody>
</Table>
</div>
<!-- صفحهبندی: شمارهها، پرش به صفحه و تعدادِ ردیف؛ در موبایل زیرِ هم. -->
<div class="flex flex-col items-center gap-6 lg:flex-row lg:justify-between">
<Pagination class="mx-0 w-auto">
<PaginationContent class="flex-wrap justify-center">
<PaginationItem>
<PaginationPrevious href="#" @click.prevent="page = Math.max(1, page - 1)" />
</PaginationItem>
<PaginationItem v-for="number in [1, 2, 3]" :key="number">
<PaginationLink href="#" :is-active="number === page" @click.prevent="page = number">
{{ toFaDigits(number) }}
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#" :is-active="page === PAGES" @click.prevent="page = PAGES">
{{ toFaDigits(PAGES) }}
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" @click.prevent="page = Math.min(PAGES, page + 1)" />
</PaginationItem>
</PaginationContent>
</Pagination>
<div class="flex items-end justify-center gap-2">
<form class="flex items-end gap-2" @submit.prevent="goJump">
<TextField v-model="jump" aria-label="برو به صفحه" placeholder="برو به صفحه" inputmode="numeric" dir="rtl" class="w-28" />
<Button type="submit" variant="outline">برو</Button>
</form>
<ControlSize size="xl" as-child>
<Select default-value="10">
<SelectTrigger aria-label="ردیف در هر صفحه" class="w-auto gap-2">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="10">۱۰ ردیف</SelectItem>
<SelectItem value="25">۲۵ ردیف</SelectItem>
<SelectItem value="50">۵۰ ردیف</SelectItem>
</SelectContent>
</Select>
</ControlSize>
</div>
</div>
</section>
</main>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: badgecontrol-sizepaginationpersiansearch-fieldselectswitchtabletext-fieldtoastآیکون plusآیکون search
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import {
Component,
ChangeDetectionStrategy,
signal,
computed,
} from "@angular/core"
import { DigControlSize } from "@/components/ui/control-size"
import { DigButton } from "@/components/ui/button"
import { DigIcon } from "@/lib/icons"
import { DigSearchField } from "@/components/ui/search-field"
import { DigBadge } from "@/components/ui/badge"
import { DigSwitch } from "@/components/ui/switch"
import {
DigTable,
DigTableHeader,
DigTableRow,
DigTableHead,
DigTableBody,
DigTableCell,
} from "@/components/ui/table"
import {
DigPagination,
DigPaginationContent,
DigPaginationItem,
DigPaginationPrevious,
DigPaginationLink,
DigPaginationEllipsis,
DigPaginationNext,
} from "@/components/ui/pagination"
import { DigTextField } from "@/components/ui/text-field"
import { DigInput, DigInputField } from "@/components/ui/input"
import {
DigSelect,
DigSelectTrigger,
DigSelectValue,
DigSelectContent,
DigSelectItem,
} from "@/components/ui/select"
import { toast } from "@/components/ui/toast"
import {
formatCurrency,
toEnDigits,
toFaDigits,
toSearchKey,
} from "@/lib/persian"
type Channel = "web" | "app" | "store"
type Row = {
id: string
customer: string
phone: string
channel: Channel
active: boolean
created: string
due: string
amount: number
}
const CHANNEL: Record<
Channel,
{ label: string; color: "info" | "violet" | "orange" }
> = {
web: { label: "سایت", color: "info" },
app: { label: "اپ", color: "violet" },
store: { label: "حضوری", color: "orange" },
}
const ORDERS: Row[] = [
{
id: "۱۰۴۲",
customer: "نگار احمدی",
phone: "09123456789",
channel: "web",
active: true,
created: "۱۴۰۵/۰۷/۱۳",
due: "۱۴۰۵/۰۷/۱۵",
amount: 1_290_000,
},
{
id: "۱۰۴۱",
customer: "کافه رست",
phone: "09121112233",
channel: "store",
active: true,
created: "۱۴۰۵/۰۷/۱۳",
due: "۱۴۰۵/۰۷/۱۴",
amount: 4_850_000,
},
{
id: "۱۰۴۰",
customer: "امیر رضایی",
phone: "09359876543",
channel: "app",
active: false,
created: "۱۴۰۵/۰۷/۱۲",
due: "۱۴۰۵/۰۷/۱۶",
amount: 640_000,
},
{
id: "۱۰۳۹",
customer: "فروشگاهِ بوم",
phone: "09127654321",
channel: "web",
active: true,
created: "۱۴۰۵/۰۷/۱۲",
due: "۱۴۰۵/۰۷/۱۵",
amount: 2_100_000,
},
{
id: "۱۰۳۸",
customer: "سارا محمدی",
phone: "09191234567",
channel: "app",
active: true,
created: "۱۴۰۵/۰۷/۱۱",
due: "۱۴۰۵/۰۷/۱۳",
amount: 980_000,
},
{
id: "۱۰۳۷",
customer: "علی کاظمی",
phone: "09381239876",
channel: "store",
active: false,
created: "۱۴۰۵/۰۷/۱۱",
due: "۱۴۰۵/۰۷/۱۴",
amount: 350_000,
},
]
const PAGES = 50
@Component({
selector: "dig-block-orders-admin",
imports: [
DigControlSize,
DigButton,
DigIcon,
DigSearchField,
DigBadge,
DigSwitch,
DigTable,
DigTableHeader,
DigTableRow,
DigTableHead,
DigTableBody,
DigTableCell,
DigPagination,
DigPaginationContent,
DigPaginationItem,
DigPaginationPrevious,
DigPaginationLink,
DigPaginationEllipsis,
DigPaginationNext,
DigTextField,
DigInput,
DigInputField,
DigSelect,
DigSelectTrigger,
DigSelectValue,
DigSelectContent,
DigSelectItem,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<main
digControlSize="xl"
class="mx-auto flex w-full max-w-6xl flex-col gap-8 p-4 sm:p-6"
>
<header class="flex items-start justify-between gap-4">
<div class="flex flex-col gap-1">
<h1 class="text-2xl leading-snug font-black">سفارشها</h1>
<p class="text-muted-foreground">
{{ toFaDigits(rows().length) }} سفارش ·
{{ toFaDigits(rows().filter((row) => row.active).length) }} فعال
</p>
</div>
<button digButton type="button" class="shrink-0">
<svg digIcon="plus"></svg>
سفارشِ تازه
</button>
</header>
<section aria-label="فهرستِ سفارشها" class="flex flex-col gap-6">
<div
digSearchField
[value]="query()"
(valueChange)="query.set($event)"
aria-label="جستوجو در سفارشها"
placeholder="نام مشتری یا شمارهٔ سفارش"
class="w-full sm:w-80"
icon="search"
></div>
<!-- موبایل: هر سفارش یک کارتِ جمعوجور با همهٔ اطلاعاتِ مهم؛ جدولِ پهن فقط از md به بعد. -->
<ul
class="flex flex-col divide-y divide-border rounded-xl border border-border bg-card md:hidden"
>
@if (visible().length === 0) {
<li class="p-8 text-center text-muted-foreground">
سفارشی با «{{ query() }}» پیدا نشد.
</li>
} @else {
@for (row of visible(); track row.id) {
<li class="flex flex-col gap-3 p-4">
<div class="flex items-start justify-between gap-3">
<span class="flex flex-col gap-0.5"
><span class="font-bold">{{ row.customer }}</span>
<span class="text-sm text-muted-foreground tabular-nums">
#{{ row.id }} · تحویل {{ row.due }}</span
></span
>
<span class="font-bold tabular-nums">{{
formatCurrency(row.amount)
}}</span>
</div>
<div class="flex items-center justify-between gap-3">
<span
digBadge
variant="soft"
[color]="CHANNEL[row.channel].color"
class="rounded-full"
>{{ CHANNEL[row.channel].label }}</span
>
<label
class="flex items-center gap-2 text-sm text-muted-foreground"
>{{ row.active ? "فعال" : "متوقف" }}
<button
digSwitch
[checked]="row.active"
[attr.aria-label]="\`فعال بودنِ سفارشِ \${row.id}\`"
(checkedChange)="setActive(row, $event)"
></button
></label>
</div>
</li>
}
}
</ul>
<div class="hidden rounded-xl border border-border bg-card md:block">
<dig-table class="min-w-[52rem]"
><thead digTableHeader>
<tr digTableRow class="bg-subtle hover:bg-subtle">
<th digTableHead>سفارش</th>
<th digTableHead>مشتری</th>
<th digTableHead>موبایل</th>
<th digTableHead>کانال</th>
<th digTableHead>فعال</th>
<th digTableHead>ثبت</th>
<th digTableHead>تحویل</th>
<th digTableHead class="text-end">مبلغ</th>
</tr>
</thead>
<tbody digTableBody>
@if (visible().length === 0) {
<tr digTableRow class="hover:bg-card">
<td
digTableCell
[colSpan]="8"
class="py-12 text-center text-muted-foreground"
>
سفارشی با «{{ query() }}» پیدا نشد.
</td>
</tr>
} @else {
@for (row of visible(); track row.id) {
<tr digTableRow>
<td digTableCell class="font-semibold tabular-nums">
#{{ row.id }}
</td>
<td digTableCell class="font-medium">{{ row.customer }}</td>
<td digTableCell>
<bdi
dir="ltr"
class="text-muted-foreground tabular-nums"
>{{ toFaDigits(row.phone) }}</bdi
>
</td>
<td digTableCell>
<span
digBadge
variant="soft"
[color]="CHANNEL[row.channel].color"
class="rounded-full"
>{{ CHANNEL[row.channel].label }}</span
>
</td>
<td digTableCell>
<button
digSwitch
[checked]="row.active"
[attr.aria-label]="\`فعال بودنِ سفارشِ \${row.id}\`"
(checkedChange)="setActive(row, $event)"
></button>
</td>
<td digTableCell class="text-muted-foreground tabular-nums">
{{ row.created }}
</td>
<td digTableCell class="text-muted-foreground tabular-nums">
{{ row.due }}
</td>
<td
digTableCell
class="text-end font-semibold tabular-nums"
>
{{ formatCurrency(row.amount) }}
</td>
</tr>
}
}
</tbody></dig-table
>
</div>
<!-- صفحهبندی: شمارهها، پرش به صفحه و تعدادِ ردیف؛ در موبایل زیرِ هم. -->
<div
class="flex flex-col items-center gap-6 lg:flex-row lg:justify-between"
>
<nav digPagination class="mx-0 w-auto">
<ul digPaginationContent class="flex-wrap justify-center">
<li digPaginationItem>
<a
digPaginationPrevious
href="#"
(click)="
$event.preventDefault(); page.set(math.max(1, page() - 1))
"
></a>
</li>
@for (number of [1, 2, 3]; track number) {
<li digPaginationItem>
<a
digPaginationLink
href="#"
[isActive]="number === page()"
(click)="$event.preventDefault(); page.set(number)"
>{{ toFaDigits(number) }}</a
>
</li>
}
<li digPaginationItem><span digPaginationEllipsis></span></li>
<li digPaginationItem>
<a
digPaginationLink
href="#"
[isActive]="page() === PAGES"
(click)="$event.preventDefault(); page.set(PAGES)"
>{{ toFaDigits(PAGES) }}</a
>
</li>
<li digPaginationItem>
<a
digPaginationNext
href="#"
(click)="
$event.preventDefault();
page.set(math.min(PAGES, page() + 1))
"
></a>
</li>
</ul>
</nav>
<div class="flex items-end justify-center gap-2">
<form
class="flex items-end gap-2"
(submit)="$event.preventDefault(); goJump()"
>
<div digTextField class="w-28">
<dig-input
><input
digInput
[value]="jump()"
(valueChange)="jump.set($event)"
aria-label="برو به صفحه"
placeholder="برو به صفحه"
inputmode="numeric"
dir="rtl"
/></dig-input>
</div>
<button digButton type="submit" variant="outline">برو</button>
</form>
<div digControlSize="xl">
<ng-container digSelect value="10"
><button
digSelectTrigger
aria-label="ردیف در هر صفحه"
class="w-auto gap-2"
>
<span digSelectValue></span>
</button>
<div digSelectContent>
<div digSelectItem value="10">۱۰ ردیف</div>
<div digSelectItem value="25">۲۵ ردیف</div>
<div digSelectItem value="50">۵۰ ردیف</div>
</div></ng-container
>
</div>
</div>
</div>
</section>
</main>
`,
})
export class OrdersAdminBlock {
readonly math = Math
readonly toFaDigits = toFaDigits
readonly formatCurrency = formatCurrency
readonly PAGES = PAGES
readonly CHANNEL = CHANNEL
readonly query = signal("")
readonly rows = signal<Row[]>(ORDERS)
readonly page = signal(1)
readonly jump = signal("")
readonly visible = computed(() =>
this.rows().filter((row) =>
toSearchKey(row.customer + row.id).includes(toSearchKey(this.query()))
)
)
setActive(row: Row, checked: boolean) {
this.rows.set(
this.rows().map((item) =>
item.id === row.id ? { ...item, active: checked } : item
)
)
toast.success(
checked ? `سفارشِ ${row.id} فعال شد.` : `سفارشِ ${row.id} متوقف شد.`
)
}
goJump() {
const target = Number(toEnDigits(this.jump()).trim())
if (Number.isInteger(target) && target >= 1 && target <= PAGES)
this.page.set(target)
else toast.error(`صفحه باید بینِ ۱ و ${toFaDigits(PAGES)} باشد.`)
}
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
همهٔ کامپوننتهای لازم برای Android آمادهاند؛ با MCP میتوانید همین صفحه را از روی نسخهٔ React بسازید.
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.