feat: polish admin UI, phone login, and product details

Switch admin auth to mobile, restyle shell/login with Vuesax icons, and add product detail fields plus public product pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
S. Esmaeili
2026-10-22 17:18:17 +03:30
co-authored by Cursor
parent 789d224ea0
commit 49f30a96b1
54 changed files with 3632 additions and 574 deletions
+7 -14
View File
@@ -1,15 +1,8 @@
<script setup lang="ts">
import {
ArrowDownOutlined,
ArrowUpOutlined,
DeleteOutlined,
EditOutlined,
ExportOutlined,
PlusOutlined,
} from "@ant-design/icons-vue";
import { message } from "ant-design-vue";
import { onMounted, ref } from "vue";
import { api, errorMessage } from "@/api/http";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import type { AdminCategory } from "@/api/types";
import PageHeader from "@/components/PageHeader.vue";
import { faNumber, SITE_URL } from "@/utils/format";
@@ -68,7 +61,7 @@ onMounted(load);
<PageHeader title="دسته‌بندی‌ها" subtitle="ترتیب دسته‌ها همان ترتیب نمایش در سایت است">
<RouterLink :to="{ name: 'category-new' }">
<a-button type="primary">
<template #icon><PlusOutlined /></template>
<template #icon><VuesaxIcon name="add" :size="16" /></template>
دسته جدید
</a-button>
</RouterLink>
@@ -99,20 +92,20 @@ onMounted(load);
<template v-else-if="column.key === 'order'">
<a-space :size="4">
<a-button size="small" :disabled="index === 0" @click="move(index, -1)">
<template #icon><ArrowUpOutlined /></template>
<template #icon><VuesaxIcon name="arrow-up" :size="16" /></template>
</a-button>
<a-button size="small" :disabled="index === rows.length - 1" @click="move(index, 1)">
<template #icon><ArrowDownOutlined /></template>
<template #icon><VuesaxIcon name="arrow-down" :size="16" /></template>
</a-button>
</a-space>
</template>
<template v-else-if="column.key === 'actions'">
<a-space :size="4">
<RouterLink :to="{ name: 'category-edit', params: { id: record.id } }">
<a-button size="small"><template #icon><EditOutlined /></template></a-button>
<a-button size="small"><template #icon><VuesaxIcon name="edit-2" :size="16" /></template></a-button>
</RouterLink>
<a :href="`${SITE_URL}/categories/${record.slug}`" target="_blank" rel="noopener">
<a-button size="small" title="مشاهده در سایت"><template #icon><ExportOutlined /></template></a-button>
<a-button size="small" title="مشاهده در سایت"><template #icon><VuesaxIcon name="export" :size="16" /></template></a-button>
</a>
<a-popconfirm
title="این دسته حذف شود؟"
@@ -121,7 +114,7 @@ onMounted(load);
@confirm="remove(record as AdminCategory)"
>
<a-button size="small" danger :disabled="record.productCount > 0" :title="record.productCount > 0 ? 'ابتدا محصولات این دسته را حذف یا جابه‌جا کنید' : 'حذف'">
<template #icon><DeleteOutlined /></template>
<template #icon><VuesaxIcon name="trash" :size="16" /></template>
</a-button>
</a-popconfirm>
</a-space>
+2 -2
View File
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { SaveOutlined } from "@ant-design/icons-vue";
import { categoryInputSchema, type MediaDto } from "@imen/shared";
import { message } from "ant-design-vue";
import { computed, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import type { z } from "zod";
import { api, errorMessage } from "@/api/http";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import type { AdminCategoryDetail } from "@/api/types";
import FormField from "@/components/FormField.vue";
import IconSelect from "@/components/IconSelect.vue";
@@ -108,7 +108,7 @@ onMounted(load);
<template>
<PageHeader :title="id ? `ویرایش دسته: ${model.name}` : 'دسته جدید'" back="/categories">
<a-button type="primary" :loading="saving" @click="save">
<template #icon><SaveOutlined /></template>
<template #icon><VuesaxIcon name="save-2" :size="16" /></template>
ذخیره
</a-button>
</PageHeader>
+2 -2
View File
@@ -1,9 +1,9 @@
<script setup lang="ts">
import { PlusOutlined } from "@ant-design/icons-vue";
import { type DashboardDto, MESSAGE_STATUS_LABELS } from "@imen/shared";
import { message } from "ant-design-vue";
import { onMounted, ref } from "vue";
import { api, errorMessage } from "@/api/http";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import PageHeader from "@/components/PageHeader.vue";
import { activityLabel, faNumber, jalali } from "@/utils/format";
@@ -22,7 +22,7 @@ onMounted(async () => {
<PageHeader title="داشبورد" subtitle="خلاصه وضعیت محتوای سایت">
<RouterLink :to="{ name: 'product-new' }">
<a-button type="primary">
<template #icon><PlusOutlined /></template>
<template #icon><VuesaxIcon name="add" :size="16" /></template>
محصول جدید
</a-button>
</RouterLink>
+174 -21
View File
@@ -1,16 +1,16 @@
<script setup lang="ts">
import { LockOutlined, MailOutlined } from "@ant-design/icons-vue";
import { loginSchema } from "@imen/shared";
import { ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import FormField from "@/components/FormField.vue";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import { useZodForm } from "@/composables/useZodForm";
import { useAuthStore } from "@/stores/auth";
const auth = useAuthStore();
const router = useRouter();
const route = useRoute();
const { model, validate, handleError } = useZodForm(loginSchema, { email: "", password: "" });
const { model, validate, handleError } = useZodForm(loginSchema, { phone: "", password: "" });
const loading = ref(false);
async function submit() {
@@ -30,26 +30,179 @@ async function submit() {
</script>
<template>
<div class="flex min-h-screen items-center justify-center bg-[#0b1224] p-4">
<div class="w-full max-w-sm rounded-2xl bg-white p-8 shadow-2xl">
<div class="mb-8 text-center">
<img src="/favicon.svg" alt="" class="mx-auto size-12" />
<h1 class="mt-4 text-xl font-bold text-gray-800">پنل مدیریت ایمن پیشگامان</h1>
<p class="mt-1 text-sm text-gray-500">برای ادامه وارد شوید</p>
<div class="login-page relative flex min-h-screen overflow-hidden text-[#edede6]">
<!-- atmosphere -->
<div class="pointer-events-none absolute inset-0 bg-[#0b1224]" />
<div class="login-grid pointer-events-none absolute inset-0 opacity-50" />
<div
class="pointer-events-none absolute -start-24 top-1/4 size-[420px] rounded-full bg-[#ff5a00]/15 blur-[120px]"
/>
<div
class="pointer-events-none absolute -end-16 bottom-0 size-[360px] rounded-full bg-[#ffb800]/10 blur-[100px]"
/>
<div class="login-tape pointer-events-none absolute bottom-0 end-0 z-10 h-48 w-1.5 opacity-70" />
<div class="login-noise pointer-events-none absolute inset-0 z-[5]" />
<div
class="relative z-10 mx-auto grid w-full max-w-[1120px] flex-1 items-center gap-10 px-5 py-12 md:px-8 lg:grid-cols-12 lg:gap-16"
>
<!-- form column -->
<div class="login-fade-3 lg:col-span-6">
<div
class="login-panel w-full max-w-md border border-[#2a3d63]/70 bg-[#1a2744]/80 p-7 backdrop-blur-md md:p-8 lg:me-auto"
>
<div class="mb-7 text-center">
<div class="font-mono text-[10px] tracking-[0.28em] text-[#8e9ab0]">SIGN IN</div>
<h2 class="mt-2 text-xl font-bold text-[#edede6]">ورود به پنل</h2>
<p class="mt-1.5 text-sm text-[#8e9ab0]">شماره موبایل و رمز عبور خود را وارد کنید</p>
</div>
<a-form class="login-form" layout="vertical" @submit.prevent="submit">
<FormField path="phone" label="شماره موبایل">
<a-input
v-model:value="model.phone"
size="large"
class="ltr-input"
autocomplete="tel"
autofocus
inputmode="tel"
placeholder="09121234567"
>
<template #prefix><VuesaxIcon name="mobile" :size="16" class="text-[#8e9ab0]" /></template>
</a-input>
</FormField>
<FormField path="password" label="رمز عبور">
<a-input-password
v-model:value="model.password"
size="large"
class="ltr-input"
autocomplete="current-password"
placeholder="••••••••"
>
<template #prefix><VuesaxIcon name="lock" :size="16" class="text-[#8e9ab0]" /></template>
</a-input-password>
</FormField>
<a-button
type="primary"
html-type="submit"
size="large"
block
:loading="loading"
class="!mt-2 !h-12 !rounded-full !font-bold !shadow-[0_8px_32px_rgba(255,90,0,0.35)]"
>
ورود به پنل
</a-button>
</a-form>
</div>
</div>
<!-- brand column -->
<div class="login-fade-1 lg:col-span-6">
<div
class="inline-flex items-center gap-2.5 rounded-full border border-[#ff5a00]/30 bg-[#ff5a00]/10 px-4 py-2 backdrop-blur"
>
<span class="size-1.5 animate-pulse rounded-full bg-[#ff5a00]" />
<span class="text-xs font-medium text-[#ff5a00]">پنل مدیریت ایمن پیشگامان</span>
</div>
<div class="mt-8 flex items-center gap-4">
<span
class="flex size-14 items-center justify-center rounded-xl bg-white shadow-[0_0_28px_rgba(10,30,92,0.45)]"
>
<img src="/logo.png" alt="ایمن پیشگامان" class="size-9 object-contain" />
</span>
<div class="leading-tight">
<div class="text-2xl font-black tracking-tight md:text-3xl">ایمن پیشگامان</div>
<div class="mt-1 font-mono text-[10px] tracking-[0.32em] text-[#8e9ab0]">
IMEN PISHGAMAN CO.
</div>
</div>
</div>
<h1 class="mt-8 text-3xl font-black leading-[1.25] md:text-5xl md:leading-[1.2]">
ورود امن
<span
class="mt-2 inline-block -rotate-1 rounded-lg bg-[#ffb800] px-3 py-1 text-[#0b1224] shadow-[0_10px_40px_rgba(255,184,0,0.22)]"
>
به سامانه
</span>
</h1>
<p class="mt-6 max-w-md text-sm leading-8 text-[#edede6]/70 md:text-base md:leading-9">
مدیریت محصولات، محتوا و پیام‌های سایت — فقط برای کاربران مجاز.
</p>
</div>
<a-form layout="vertical" @submit.prevent="submit">
<FormField path="email" label="ایمیل">
<a-input v-model:value="model.email" size="large" class="ltr-input" autocomplete="username" autofocus>
<template #prefix><MailOutlined class="text-gray-400" /></template>
</a-input>
</FormField>
<FormField path="password" label="رمز عبور">
<a-input-password v-model:value="model.password" size="large" class="ltr-input" autocomplete="current-password">
<template #prefix><LockOutlined class="text-gray-400" /></template>
</a-input-password>
</FormField>
<a-button type="primary" html-type="submit" size="large" block :loading="loading">ورود</a-button>
</a-form>
</div>
</div>
</template>
<style scoped>
.login-grid {
background-image:
linear-gradient(to left, rgba(237, 237, 230, 0.045) 1px, transparent 1px),
linear-gradient(to bottom, rgba(237, 237, 230, 0.045) 1px, transparent 1px);
background-size: 72px 72px;
}
.login-tape {
background-image: repeating-linear-gradient(45deg, #ffb800 0 10px, #0b1224 10px 20px);
}
.login-noise {
opacity: 0.045;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.login-fade-1,
.login-fade-3 {
animation: login-fade-up 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.login-fade-1 {
animation-delay: 0.12s;
}
.login-fade-3 {
animation-delay: 0.28s;
}
@keyframes login-fade-up {
from {
opacity: 0;
transform: translateY(36px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.login-panel :deep(.ant-form-item-label > label) {
color: #edede6 !important;
}
.login-panel :deep(.ant-input-affix-wrapper),
.login-panel :deep(.ant-input) {
background: #152038 !important;
border-color: #2a3d63 !important;
color: #edede6 !important;
}
.login-panel :deep(.ant-input-affix-wrapper:hover),
.login-panel :deep(.ant-input-affix-wrapper-focused),
.login-panel :deep(.ant-input-affix-wrapper:focus-within) {
border-color: #ff5a00 !important;
box-shadow: 0 0 0 2px rgba(255, 90, 0, 0.15) !important;
}
.login-panel :deep(.ant-input::placeholder) {
color: #8e9ab0 !important;
}
.login-panel :deep(.ant-input-password-icon) {
color: #8e9ab0 !important;
}
.login-panel :deep(.ant-form-item-explain-error) {
color: #ff7a2a;
}
</style>
+4 -4
View File
@@ -1,9 +1,9 @@
<script setup lang="ts">
import { CopyOutlined, DeleteOutlined, UploadOutlined } from "@ant-design/icons-vue";
import type { MediaDto, Paginated } from "@imen/shared";
import { message } from "ant-design-vue";
import { onMounted, ref } from "vue";
import { api, errorMessage } from "@/api/http";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import PageHeader from "@/components/PageHeader.vue";
import { faNumber, fileSize, jalali } from "@/utils/format";
@@ -89,7 +89,7 @@ onMounted(load);
<PageHeader title="کتابخانه رسانه" :subtitle="`${faNumber(total)} تصویر`">
<a-upload accept="image/jpeg,image/png,image/webp,image/avif,image/gif" multiple :show-upload-list="false" :before-upload="upload">
<a-button type="primary" :loading="uploading > 0">
<template #icon><UploadOutlined /></template>
<template #icon><VuesaxIcon name="document-upload" :size="16" /></template>
آپلود تصویر
</a-button>
</a-upload>
@@ -140,9 +140,9 @@ onMounted(load);
</a-form-item>
<a-space wrap>
<a-button type="primary" @click="saveAlt">ذخیره</a-button>
<a-button @click="copyUrl(selected.url)"><template #icon><CopyOutlined /></template>کپی آدرس</a-button>
<a-button @click="copyUrl(selected.url)"><template #icon><VuesaxIcon name="copy" :size="16" /></template>کپی آدرس</a-button>
<a-popconfirm title="این تصویر حذف شود؟" ok-text="حذف" cancel-text="انصراف" @confirm="remove">
<a-button danger><template #icon><DeleteOutlined /></template>حذف</a-button>
<a-button danger><template #icon><VuesaxIcon name="trash" :size="16" /></template>حذف</a-button>
</a-popconfirm>
</a-space>
</a-form>
+2 -2
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { DeleteOutlined } from "@ant-design/icons-vue";
import {
type ContactMessageDto,
MESSAGE_STATUS_LABELS,
@@ -11,6 +10,7 @@ import { message } from "ant-design-vue";
import { onMounted, ref, watch } from "vue";
import { useRoute } from "vue-router";
import { api, errorMessage } from "@/api/http";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import PageHeader from "@/components/PageHeader.vue";
import { faNumber, jalali } from "@/utils/format";
@@ -117,7 +117,7 @@ onMounted(load);
</template>
<template v-else-if="column.key === 'actions'">
<a-popconfirm title="این پیام حذف شود؟" ok-text="حذف" cancel-text="انصراف" @confirm="remove(record as ContactMessageDto)">
<a-button size="small" danger><template #icon><DeleteOutlined /></template></a-button>
<a-button size="small" danger><template #icon><VuesaxIcon name="trash" :size="16" /></template></a-button>
</a-popconfirm>
</template>
</template>
+114 -13
View File
@@ -1,14 +1,16 @@
<script setup lang="ts">
import { CloseOutlined, PlusOutlined, SaveOutlined } from "@ant-design/icons-vue";
import { type MediaDto, productInputSchema } from "@imen/shared";
import { type MediaDto, type ProductAttribute, productInputSchema } from "@imen/shared";
import { message } from "ant-design-vue";
import { computed, onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import type { z } from "zod";
import { api, errorMessage } from "@/api/http";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import type { AdminCategory, AdminCategoryDetail, AdminProductDetail } from "@/api/types";
import FormField from "@/components/FormField.vue";
import ImageField from "@/components/ImageField.vue";
import LinesInput from "@/components/LinesInput.vue";
import ListEditor from "@/components/ListEditor.vue";
import MediaPicker from "@/components/MediaPicker.vue";
import PageHeader from "@/components/PageHeader.vue";
import { useZodForm } from "@/composables/useZodForm";
@@ -31,6 +33,18 @@ const empty = (): Form => ({
desc: "",
specs: [],
variants: [],
details: "",
brand: "",
origin: "",
sizes: [],
standards: [],
features: [],
applications: [],
attributes: [],
packaging: "",
minOrder: "",
seoTitle: "",
seoDescription: "",
imageId: null,
galleryIds: [],
isPublished: true,
@@ -51,6 +65,7 @@ const groupId = computed({
get: () => model.value.groupId ?? undefined,
set: (v: number | undefined) => (model.value.groupId = v ?? null),
});
const newAttribute = (): ProductAttribute => ({ name: "", value: "" });
async function loadGroups(clear: boolean) {
if (clear) model.value.groupId = null;
@@ -75,6 +90,18 @@ async function load() {
desc: p.desc,
specs: p.specs,
variants: p.variants,
details: p.details,
brand: p.brand,
origin: p.origin,
sizes: p.sizes,
standards: p.standards,
features: p.features,
applications: p.applications,
attributes: p.attributes ?? [],
packaging: p.packaging,
minOrder: p.minOrder,
seoTitle: p.seoTitle,
seoDescription: p.seoDescription,
imageId: p.imageId,
galleryIds: p.gallery.map((g) => g.id),
isPublished: p.isPublished,
@@ -135,15 +162,15 @@ onMounted(load);
<template>
<PageHeader :title="id ? `ویرایش محصول: ${model.name}` : 'محصول جدید'" back="/products">
<a
v-if="id && category && model.isPublished"
:href="`${SITE_URL}/categories/${category.slug}`"
v-if="id && category?.isPublished && model.isPublished"
:href="`${SITE_URL}/products/${model.slug}`"
target="_blank"
rel="noopener"
>
<a-button>مشاهده در سایت</a-button>
</a>
<a-button type="primary" :loading="saving" @click="save">
<template #icon><SaveOutlined /></template>
<template #icon><VuesaxIcon name="save-2" :size="16" /></template>
ذخیره
</a-button>
</PageHeader>
@@ -163,26 +190,78 @@ onMounted(load);
<FormField path="code" label="کد محصول" required hint="یکتا، مثلاً IP-G20">
<a-input v-model:value="model.code" class="ltr-input" />
</FormField>
<FormField path="slug" label="اسلاگ" required>
<FormField path="slug" label="اسلاگ (آدرس صفحه)" required :hint="`آدرس: /products/${model.slug || '...'}`">
<a-input v-model:value="model.slug" class="ltr-input">
<template #suffix>
<a class="text-xs" @click="model.slug = toSlug(model.code || model.nameEn || '')">ساخت از کد</a>
</template>
</a-input>
</FormField>
<FormField path="desc" label="توضیحات" class="md:col-span-2">
<a-textarea v-model:value="model.desc" :auto-size="{ minRows: 3, maxRows: 8 }" />
<FormField path="desc" label="توضیح کوتاه" hint="زیر عنوان صفحه محصول و روی کارت محصول نمایش داده می‌شود" class="md:col-span-2">
<a-textarea v-model:value="model.desc" :auto-size="{ minRows: 2, maxRows: 5 }" />
</FormField>
<FormField path="specs" label="ویژگی‌ها" hint="هر ویژگی را بنویسید و Enter بزنید" class="md:col-span-2">
<FormField path="specs" label="برچسب‌های کوتاه" hint="ویژگی‌های یک‌کلمه‌ای روی کارت؛ هر مورد را بنویسید و Enter بزنید" class="md:col-span-2">
<a-select v-model:value="model.specs" mode="tags" :open="false" placeholder="مثلاً: ضد برش" />
</FormField>
<FormField path="variants" label="مدل‌ها / رنگ‌ها" hint="اختیاری — هر مورد را بنویسید و Enter بزنید" class="md:col-span-2">
</div>
</a-card>
<a-card title="توضیحات کامل (صفحه محصول)">
<FormField path="details" hint="برای شروع پاراگراف جدید یک خط خالی بگذارید. اگر خالی بماند، توضیح دسته نمایش داده می‌شود.">
<a-textarea
v-model:value="model.details"
:auto-size="{ minRows: 6, maxRows: 20 }"
placeholder="معرفی محصول، جنس و ساختار، مزایا، نکات نگهداری و ..."
/>
</FormField>
</a-card>
<a-card title="ویژگی‌ها و کاربردها">
<FormField path="features" label="ویژگی‌های کلیدی" hint="هر ویژگی در یک خط">
<LinesInput v-model="model.features" :rows="4" placeholder="مثلاً: زیره ضد لغزش و مقاوم در برابر روغن" />
</FormField>
<FormField path="applications" label="کاربردها / محیط‌های مناسب" hint="هر مورد را بنویسید و Enter بزنید">
<a-select v-model:value="model.applications" mode="tags" :open="false" placeholder="مثلاً: پالایشگاه" />
</FormField>
</a-card>
<a-card title="مشخصات فنی" :body-style="{ background: '#fafafa' }">
<p class="mb-4 text-sm text-gray-500">
ردیف‌های جدول مشخصات صفحه محصول (مثلاً «جنس رویه» ← «چرم طبیعی»). کد، دسته، برند و موارد زیر به‌صورت خودکار به جدول اضافه می‌شوند.
</p>
<ListEditor
v-model="model.attributes"
:create="newAttribute"
:max="40"
add-label="افزودن ردیف مشخصات"
:item-title="(a) => a.name"
>
<template #default="{ item, index }">
<div class="grid gap-x-4 md:grid-cols-5">
<FormField :path="`attributes.${index}.name`" label="عنوان" required class="md:col-span-2">
<a-input v-model:value="item.name" placeholder="مثلاً: جنس رویه" />
</FormField>
<FormField :path="`attributes.${index}.value`" label="مقدار" required class="md:col-span-3">
<a-input v-model:value="item.value" placeholder="مثلاً: چرم طبیعی گاوی" />
</FormField>
</div>
</template>
</ListEditor>
<div class="mt-6 grid gap-x-4 md:grid-cols-2">
<FormField path="standards" label="استانداردها و گواهی‌ها" hint="مثلاً EN 388 — هر مورد + Enter">
<a-select v-model:value="model.standards" mode="tags" :open="false" class="ltr-input" />
</FormField>
<FormField path="sizes" label="سایزها" hint="مثلاً 40، 41، XL — هر مورد + Enter">
<a-select v-model:value="model.sizes" mode="tags" :open="false" />
</FormField>
<FormField path="variants" label="مدل‌ها / رنگ‌ها" hint="هر مورد + Enter" class="md:col-span-2">
<a-select v-model:value="model.variants" mode="tags" :open="false" placeholder="مثلاً: مشکی/زرد" />
</FormField>
</div>
</a-card>
<a-card title="گالری تصاویر (اختیاری)">
<a-card title="گالری تصاویر">
<p class="mb-4 text-sm text-gray-500">تصاویر بیشتر محصول؛ در صفحه محصول بعد از تصویر اصلی نمایش داده می‌شوند.</p>
<div class="flex flex-wrap gap-3">
<div v-for="m in gallery" :key="m.id" class="relative size-24 overflow-hidden rounded-lg border border-gray-200 bg-gray-50">
<img :src="m.url" alt="" class="size-full object-contain" />
@@ -192,7 +271,7 @@ onMounted(load);
title="حذف از گالری"
@click="removeFromGallery(m.id)"
>
<CloseOutlined class="text-xs" />
<VuesaxIcon name="close-circle" :size="16" class="text-xs" />
</button>
</div>
<button
@@ -200,7 +279,7 @@ onMounted(load);
class="flex size-24 items-center justify-center rounded-lg border border-dashed border-gray-300 text-gray-400 hover:border-[#ff5a00] hover:text-[#ff5a00]"
@click="galleryPicker = true"
>
<PlusOutlined />
<VuesaxIcon name="add" :size="16" />
</button>
</div>
<MediaPicker v-model:open="galleryPicker" @select="addToGallery" />
@@ -238,6 +317,28 @@ onMounted(load);
<ImageField :url="image?.url" clearable @pick="pickImage" @clear="image = null; model.imageId = null" />
</FormField>
</a-card>
<a-card title="برند و سفارش">
<FormField path="brand" label="برند">
<a-input v-model:value="model.brand" />
</FormField>
<FormField path="origin" label="کشور سازنده">
<a-input v-model:value="model.origin" placeholder="مثلاً: ایران" />
</FormField>
<FormField path="packaging" label="بسته‌بندی">
<a-input v-model:value="model.packaging" placeholder="مثلاً: کارتن ۱۲ جفتی" />
</FormField>
<FormField path="minOrder" label="حداقل سفارش">
<a-input v-model:value="model.minOrder" placeholder="مثلاً: ۱ کارتن" />
</FormField>
</a-card>
<a-card title="سئو">
<FormField path="seoTitle" label="عنوان صفحه" hint="خالی = نام محصول">
<a-input v-model:value="model.seoTitle" :maxlength="120" show-count />
</FormField>
<FormField path="seoDescription" label="توضیحات متا" hint="خالی = توضیح کوتاه">
<a-textarea v-model:value="model.seoDescription" :maxlength="300" show-count :auto-size="{ minRows: 3 }" />
</FormField>
</a-card>
</div>
</div>
</a-form>
+316 -130
View File
@@ -1,31 +1,41 @@
<script setup lang="ts">
import {
ArrowDownOutlined,
ArrowUpOutlined,
CopyOutlined,
DeleteOutlined,
EditOutlined,
PlusOutlined,
} from "@ant-design/icons-vue";
import type { Paginated } from "@imen/shared";
import { message } from "ant-design-vue";
import { computed, onMounted, reactive, ref, watch } from "vue";
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { api, errorMessage } from "@/api/http";
import type { AdminCategory, AdminCategoryDetail, AdminProduct } from "@/api/types";
import PageHeader from "@/components/PageHeader.vue";
import { faNumber } from "@/utils/format";
import AdminPage from "@/components/AdminPage.vue";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
const route = useRoute();
const router = useRouter();
const tableShell = ref<HTMLElement | null>(null);
const scrollY = ref(360);
let tableResizeObserver: ResizeObserver | null = null;
function measureTableScroll() {
const el = tableShell.value;
if (!el) return;
const pagination = el.querySelector(".ant-table-pagination") as HTMLElement | null;
const header = el.querySelector(".ant-table-thead") as HTMLElement | null;
const paginationH = pagination?.offsetHeight ?? (reorderable.value ? 0 : 48);
const headerH = header?.offsetHeight ?? 55;
const gap = 16;
scrollY.value = Math.max(180, el.clientHeight - paginationH - headerH - gap);
}
const num = (v: unknown) => (v ? Number(v) : undefined);
const PAGE_SIZE_OPTIONS = ["10", "20", "50", "100"];
const DEFAULT_PAGE_SIZE = 20;
const filters = reactive({
categoryId: num(route.query.categoryId),
groupId: num(route.query.groupId),
status: (route.query.status as "published" | "draft" | undefined) || undefined,
q: typeof route.query.q === "string" ? route.query.q : "",
page: num(route.query.page) ?? 1,
pageSize: num(route.query.pageSize) ?? DEFAULT_PAGE_SIZE,
});
const rows = ref<AdminProduct[]>([]);
@@ -33,26 +43,67 @@ const total = ref(0);
const loading = ref(false);
const categories = ref<AdminCategory[]>([]);
const groups = ref<AdminCategoryDetail["groups"]>([]);
const filtersOpen = ref(false);
const activeFilterCount = computed(
() => [filters.categoryId, filters.groupId, filters.status].filter(Boolean).length,
);
/** products without their own photo show the category cover (same fallback as the website) */
const thumbOf = (row: AdminProduct) =>
row.image ? { url: row.image.url, fallback: false } : {
url: categories.value.find((c) => c.id === row.categoryId)?.coverImage?.url ?? null,
fallback: true,
};
row.image
? { url: row.image.url, fallback: false }
: {
url: categories.value.find((c) => c.id === row.categoryId)?.coverImage?.url ?? null,
fallback: true,
};
/** with a single category selected (and no other filter) the whole list is shown and can be reordered */
const reorderable = computed(() => !!filters.categoryId && !filters.groupId && !filters.status && !filters.q);
const pageSize = computed(() => (reorderable.value ? 200 : 30));
const reorderable = computed(
() => !!filters.categoryId && !filters.groupId && !filters.status && !filters.q,
);
const requestPageSize = computed(() => (reorderable.value ? 200 : filters.pageSize));
const tablePagination = computed(() => {
if (reorderable.value) return false;
return {
current: filters.page,
pageSize: filters.pageSize,
total: total.value,
showSizeChanger: true,
pageSizeOptions: PAGE_SIZE_OPTIONS,
showQuickJumper: true,
showTotal: (t: number) => `${t.toLocaleString("fa-IR")} محصول`,
onChange: (page: number, size: number) => {
filters.page = page;
if (size !== filters.pageSize) {
filters.pageSize = size;
filters.page = 1;
}
void load();
},
};
});
async function load() {
loading.value = true;
void router.replace({
query: Object.fromEntries(Object.entries(filters).filter(([k, v]) => v && !(k === "page" && v === 1))),
query: Object.fromEntries(
Object.entries({
...filters,
page: filters.page === 1 ? undefined : filters.page,
pageSize: filters.pageSize === DEFAULT_PAGE_SIZE ? undefined : filters.pageSize,
}).filter(([, v]) => v),
),
});
try {
const res = await api<Paginated<AdminProduct>>("/admin/products", {
query: { ...filters, q: filters.q || undefined, pageSize: pageSize.value },
query: {
...filters,
q: filters.q || undefined,
pageSize: requestPageSize.value,
},
});
rows.value = res.items;
total.value = res.total;
@@ -96,7 +147,9 @@ async function togglePublish(row: AdminProduct, isPublished: boolean) {
async function duplicate(row: AdminProduct) {
try {
const copy = await api<{ id: number }>(`/admin/products/${row.id}/duplicate`, { method: "POST" });
const copy = await api<{ id: number }>(`/admin/products/${row.id}/duplicate`, {
method: "POST",
});
void message.success("کپی پیش‌نویس ساخته شد");
await router.push({ name: "product-edit", params: { id: copy.id } });
} catch (e) {
@@ -136,6 +189,11 @@ const columns = computed(() => [
{ title: "", key: "actions", width: 130 },
]);
watch([reorderable, loading, rows], async () => {
await nextTick();
measureTableScroll();
});
onMounted(async () => {
try {
categories.value = await api<AdminCategory[]>("/admin/categories");
@@ -144,123 +202,251 @@ onMounted(async () => {
void message.error(errorMessage(e));
}
await load();
await nextTick();
if (tableShell.value) {
tableResizeObserver = new ResizeObserver(() => measureTableScroll());
tableResizeObserver.observe(tableShell.value);
measureTableScroll();
}
});
onBeforeUnmount(() => {
tableResizeObserver?.disconnect();
tableResizeObserver = null;
});
</script>
<template>
<PageHeader title="محصولات" :subtitle="`${faNumber(total)} محصول`">
<RouterLink :to="{ name: 'product-new', query: filters.categoryId ? { categoryId: filters.categoryId } : {} }">
<a-button type="primary">
<template #icon><PlusOutlined /></template>
محصول جدید
</a-button>
</RouterLink>
</PageHeader>
<AdminPage lock-body>
<template #head>
<div class="toolbar">
<div class="toolbar__start">
<a-popover
v-model:open="filtersOpen"
trigger="click"
placement="bottomLeft"
:overlay-style="{ width: '280px' }"
>
<template #content>
<div class="filter-panel">
<a-select
v-model:value="filters.categoryId"
allow-clear
style="width: 100%"
placeholder="همه دسته‌ها"
:options="categories.map((c) => ({ value: c.id, label: c.name }))"
/>
<a-select
v-model:value="filters.groupId"
allow-clear
style="width: 100%"
placeholder="همه زیرگروه‌ها"
:disabled="!groups.length"
:options="groups.map((g) => ({ value: g.id, label: g.name }))"
/>
<a-select
v-model:value="filters.status"
allow-clear
style="width: 100%"
placeholder="همه وضعیت‌ها"
:options="[
{ value: 'published', label: 'منتشرشده' },
{ value: 'draft', label: 'پیش‌نویس / مخفی' },
]"
/>
<p v-if="filters.categoryId && !reorderable" class="filter-panel__hint">
برای تغییر ترتیب، فقط فیلتر دسته را نگه دارید.
</p>
</div>
</template>
<a-badge :count="activeFilterCount" :offset="[-4, 4]" color="#ff5a00">
<a-button>
<template #icon><VuesaxIcon name="filter" :size="16" /></template>
فیلتر
</a-button>
</a-badge>
</a-popover>
<a-card class="mb-4" :body-style="{ padding: '16px' }">
<div class="grid gap-3 md:grid-cols-4">
<a-select
v-model:value="filters.categoryId"
allow-clear
placeholder="همه دسته‌ها"
:options="categories.map((c) => ({ value: c.id, label: c.name }))"
/>
<a-select
v-model:value="filters.groupId"
allow-clear
placeholder="همه زیرگروه‌ها"
:disabled="!groups.length"
:options="groups.map((g) => ({ value: g.id, label: g.name }))"
/>
<a-select
v-model:value="filters.status"
allow-clear
placeholder="همه وضعیت‌ها"
:options="[
{ value: 'published', label: 'منتشرشده' },
{ value: 'draft', label: 'پیش‌نویس / مخفی' },
]"
/>
<a-input-search
v-model:value="filters.q"
allow-clear
placeholder="جستجوی نام یا کد"
@search="() => { filters.page = 1; load(); }"
/>
</div>
<p v-if="filters.categoryId && !reorderable" class="mt-3 text-xs text-gray-400">
برای تغییر ترتیب محصولات، فقط فیلتر دسته را نگه دارید.
</p>
</a-card>
<a-input-search
v-model:value="filters.q"
allow-clear
class="toolbar__search"
placeholder="جستجوی نام یا کد"
@search="
() => {
filters.page = 1;
load();
}
"
/>
</div>
<a-card :body-style="{ padding: 0 }">
<a-table
:columns="columns"
:data-source="rows"
:loading="loading"
row-key="id"
:scroll="{ x: 760 }"
:pagination="reorderable ? false : {
current: filters.page,
pageSize,
total,
showSizeChanger: false,
onChange: (p: number) => { filters.page = p; load(); },
}"
>
<template #bodyCell="{ column, record, index }">
<template v-if="column.key === 'image'">
<template v-if="thumbOf(record as AdminProduct).url">
<img
:src="thumbOf(record as AdminProduct).url!"
alt=""
:title="thumbOf(record as AdminProduct).fallback ? 'این محصول عکس ندارد؛ کاور دسته نمایش داده شده' : undefined"
:class="['size-12 rounded bg-gray-50 object-contain', thumbOf(record as AdminProduct).fallback && 'opacity-40 grayscale']"
<RouterLink
class="toolbar__new"
:to="{
name: 'product-new',
query: filters.categoryId ? { categoryId: filters.categoryId } : {},
}"
>
<a-button type="primary">
<template #icon><VuesaxIcon name="add" :size="16" /></template>
محصول جدید
</a-button>
</RouterLink>
</div>
</template>
<div ref="tableShell" class="table-shell">
<a-table
class="table-shell__table"
:columns="columns"
:data-source="rows"
:loading="loading"
row-key="id"
:scroll="{ x: 760, y: scrollY }"
:pagination="tablePagination"
>
<template #bodyCell="{ column, record, index }">
<template v-if="column.key === 'image'">
<template v-if="thumbOf(record as AdminProduct).url">
<img
:src="thumbOf(record as AdminProduct).url!"
alt=""
:title="
thumbOf(record as AdminProduct).fallback
? 'این محصول عکس ندارد؛ کاور دسته نمایش داده شده'
: undefined
"
:class="[
'size-12 rounded bg-gray-50 object-contain',
thumbOf(record as AdminProduct).fallback && 'opacity-40 grayscale',
]"
/>
</template>
<div v-else class="size-12 rounded bg-gray-100" />
</template>
<template v-else-if="column.key === 'name'">
<RouterLink
:to="{ name: 'product-edit', params: { id: record.id } }"
class="font-bold text-[#0f172a] hover:text-[#ff5a00]"
>
{{ record.name }}
</RouterLink>
<div class="text-xs text-gray-400" dir="ltr">{{ record.code }}</div>
</template>
<template v-else-if="column.key === 'category'">
<div>{{ record.category.name }}</div>
<div v-if="record.group" class="text-xs text-gray-400">{{ record.group.name }}</div>
</template>
<template v-else-if="column.key === 'status'">
<a-switch
:checked="record.isPublished"
size="small"
@change="(v: unknown) => togglePublish(record as AdminProduct, !!v)"
/>
</template>
<div v-else class="size-12 rounded bg-gray-100" />
<template v-else-if="column.key === 'order'">
<a-space :size="4">
<a-button size="small" :disabled="index === 0" @click="move(index, -1)">
<template #icon><VuesaxIcon name="arrow-up" :size="14" /></template>
</a-button>
<a-button size="small" :disabled="index === rows.length - 1" @click="move(index, 1)">
<template #icon><VuesaxIcon name="arrow-down" :size="14" /></template>
</a-button>
</a-space>
</template>
<template v-else-if="column.key === 'actions'">
<a-space :size="4">
<RouterLink :to="{ name: 'product-edit', params: { id: record.id } }">
<a-button size="small" title="ویرایش"
><template #icon><VuesaxIcon name="edit-2" :size="14" /></template
></a-button>
</RouterLink>
<a-button size="small" title="کپی" @click="duplicate(record as AdminProduct)">
<template #icon><VuesaxIcon name="copy" :size="14" /></template>
</a-button>
<a-popconfirm
title="این محصول حذف شود؟"
ok-text="حذف"
cancel-text="انصراف"
@confirm="remove(record as AdminProduct)"
>
<a-button size="small" danger title="حذف"
><template #icon><VuesaxIcon name="trash" :size="14" /></template
></a-button>
</a-popconfirm>
</a-space>
</template>
</template>
<template v-else-if="column.key === 'name'">
<RouterLink :to="{ name: 'product-edit', params: { id: record.id } }" class="font-bold">
{{ record.name }}
</RouterLink>
<div class="text-xs text-gray-400" dir="ltr">{{ record.code }}</div>
</template>
<template v-else-if="column.key === 'category'">
<div>{{ record.category.name }}</div>
<div v-if="record.group" class="text-xs text-gray-400">{{ record.group.name }}</div>
</template>
<template v-else-if="column.key === 'status'">
<a-switch
:checked="record.isPublished"
size="small"
@change="(v: unknown) => togglePublish(record as AdminProduct, !!v)"
/>
</template>
<template v-else-if="column.key === 'order'">
<a-space :size="4">
<a-button size="small" :disabled="index === 0" @click="move(index, -1)">
<template #icon><ArrowUpOutlined /></template>
</a-button>
<a-button size="small" :disabled="index === rows.length - 1" @click="move(index, 1)">
<template #icon><ArrowDownOutlined /></template>
</a-button>
</a-space>
</template>
<template v-else-if="column.key === 'actions'">
<a-space :size="4">
<RouterLink :to="{ name: 'product-edit', params: { id: record.id } }">
<a-button size="small" title="ویرایش"><template #icon><EditOutlined /></template></a-button>
</RouterLink>
<a-button size="small" title="کپی" @click="duplicate(record as AdminProduct)">
<template #icon><CopyOutlined /></template>
</a-button>
<a-popconfirm title="این محصول حذف شود؟" ok-text="حذف" cancel-text="انصراف" @confirm="remove(record as AdminProduct)">
<a-button size="small" danger title="حذف"><template #icon><DeleteOutlined /></template></a-button>
</a-popconfirm>
</a-space>
</template>
</template>
</a-table>
</a-card>
</a-table>
</div>
</AdminPage>
</template>
<style scoped>
.table-shell {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
height: 100%;
}
.table-shell :deep(.ant-table-wrapper),
.table-shell :deep(.ant-spin-nested-loading),
.table-shell :deep(.ant-spin-container) {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
height: 100%;
}
.table-shell :deep(.ant-table) {
flex: 1;
min-height: 0;
}
.table-shell :deep(.ant-table-pagination) {
flex-shrink: 0;
margin: 12px 0 0 !important;
}
.toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.toolbar__start {
display: flex;
flex: 1;
align-items: center;
gap: 16px;
min-width: 0;
}
.toolbar__search {
flex: 1;
min-width: 200px;
max-width: 360px;
}
.toolbar__new {
margin-inline-start: auto;
}
.filter-panel {
display: flex;
flex-direction: column;
gap: 10px;
}
.filter-panel__hint {
margin: 0;
font-size: 12px;
color: #94a3b8;
line-height: 1.6;
}
</style>
+1 -1
View File
@@ -37,7 +37,7 @@ async function save() {
<a-card title="مشخصات">
<a-descriptions :column="1">
<a-descriptions-item label="نام">{{ auth.user?.name }}</a-descriptions-item>
<a-descriptions-item label="ایمیل"><span dir="ltr">{{ auth.user?.email }}</span></a-descriptions-item>
<a-descriptions-item label="موبایل"><span dir="ltr">{{ auth.user?.phone }}</span></a-descriptions-item>
<a-descriptions-item label="نقش">{{ auth.user && ROLE_LABELS[auth.user.role] }}</a-descriptions-item>
</a-descriptions>
</a-card>
+2 -2
View File
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { SaveOutlined } from "@ant-design/icons-vue";
import { isSectionKey, SECTION_LABELS, type SectionKey, sectionSchemas } from "@imen/shared";
import { message } from "ant-design-vue";
import { type Component, computed, ref } from "vue";
import { useRoute } from "vue-router";
import { api, errorMessage } from "@/api/http";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import type { SectionResponse } from "@/api/types";
import PageHeader from "@/components/PageHeader.vue";
import { useZodForm } from "@/composables/useZodForm";
@@ -92,7 +92,7 @@ if (valid) void load();
>
<a :href="SITE_URL" target="_blank" rel="noopener"><a-button>مشاهده سایت</a-button></a>
<a-button type="primary" :loading="saving" :disabled="!loaded" @click="save">
<template #icon><SaveOutlined /></template>
<template #icon><VuesaxIcon name="save-2" :size="16" /></template>
ذخیره
</a-button>
</PageHeader>
+16 -10
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { DeleteOutlined, EditOutlined, PlusOutlined } from "@ant-design/icons-vue";
import {
type AdminUserDto,
ROLE_LABELS,
@@ -12,6 +11,7 @@ import { message } from "ant-design-vue";
import { computed, onMounted, type Ref, ref } from "vue";
import type { z } from "zod";
import { api, errorMessage } from "@/api/http";
import VuesaxIcon from "@/components/VuesaxIcon.vue";
import FormField from "@/components/FormField.vue";
import PageHeader from "@/components/PageHeader.vue";
import { useZodForm } from "@/composables/useZodForm";
@@ -28,7 +28,7 @@ const saving = ref(false);
// one form model for both create and update; the matching schema validates on save
type Form = z.input<typeof userCreateSchema> & { isActive: boolean };
const empty: Form = { email: "", name: "", role: "EDITOR", password: "", isActive: true };
const empty: Form = { phone: "", name: "", role: "EDITOR", password: "", isActive: true };
const form = useZodForm(userCreateSchema, empty);
const model = form.model as unknown as Ref<Form>;
const isNew = computed(() => editing.value === 0);
@@ -50,7 +50,7 @@ function openNew() {
editing.value = 0;
}
function openEdit(u: AdminUserDto) {
form.reset({ email: u.email, name: u.name, role: u.role, isActive: u.isActive, password: "" } as Form);
form.reset({ phone: u.phone, name: u.name, role: u.role, isActive: u.isActive, password: "" } as Form);
editing.value = u.id;
}
@@ -92,7 +92,7 @@ async function remove(u: AdminUserDto) {
const columns = [
{ title: "نام", dataIndex: "name" },
{ title: "ایمیل", key: "email" },
{ title: "موبایل", key: "phone" },
{ title: "نقش", key: "role", width: 110 },
{ title: "وضعیت", key: "active", width: 100 },
{ title: "آخرین ورود", key: "login", width: 170 },
@@ -105,7 +105,7 @@ onMounted(load);
<template>
<PageHeader title="کاربران پنل" subtitle="مدیر کل به همه بخش‌ها دسترسی دارد؛ ویرایشگر به جز کاربران و تنظیمات سایت">
<a-button type="primary" @click="openNew">
<template #icon><PlusOutlined /></template>
<template #icon><VuesaxIcon name="add" :size="16" /></template>
کاربر جدید
</a-button>
</PageHeader>
@@ -113,7 +113,7 @@ onMounted(load);
<a-card :body-style="{ padding: 0 }">
<a-table :columns="columns" :data-source="rows" :loading="loading" row-key="id" :pagination="false" :scroll="{ x: 700 }">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'email'"><span dir="ltr">{{ record.email }}</span></template>
<template v-if="column.key === 'phone'"><span dir="ltr">{{ record.phone }}</span></template>
<template v-else-if="column.key === 'role'">
<a-tag :color="record.role === 'ADMIN' ? 'orange' : 'blue'">{{ ROLE_LABELS[record.role as keyof typeof ROLE_LABELS] }}</a-tag>
</template>
@@ -123,7 +123,7 @@ onMounted(load);
<template v-else-if="column.key === 'login'">{{ jalali(record.lastLoginAt) }}</template>
<template v-else-if="column.key === 'actions'">
<a-space :size="4">
<a-button size="small" @click="openEdit(record as AdminUserDto)"><template #icon><EditOutlined /></template></a-button>
<a-button size="small" @click="openEdit(record as AdminUserDto)"><template #icon><VuesaxIcon name="edit-2" :size="16" /></template></a-button>
<a-popconfirm
v-if="record.id !== auth.user?.id"
title="این کاربر حذف شود؟"
@@ -131,7 +131,7 @@ onMounted(load);
cancel-text="انصراف"
@confirm="remove(record as AdminUserDto)"
>
<a-button size="small" danger><template #icon><DeleteOutlined /></template></a-button>
<a-button size="small" danger><template #icon><VuesaxIcon name="trash" :size="16" /></template></a-button>
</a-popconfirm>
</a-space>
</template>
@@ -150,8 +150,14 @@ onMounted(load);
@cancel="editing = null"
>
<a-form layout="vertical" class="mt-4" @submit.prevent="save">
<FormField path="email" label="ایمیل" required>
<a-input v-model:value="model.email" class="ltr-input" :disabled="!isNew" />
<FormField path="phone" label="شماره موبایل" required>
<a-input
v-model:value="model.phone"
class="ltr-input"
:disabled="!isNew"
inputmode="tel"
placeholder="09121234567"
/>
</FormField>
<FormField path="name" label="نام" required>
<a-input v-model:value="model.name" />