Files
nademitex_admin/dist/assets/BannersView-bUbLqnD2.js
T

1 line
6.6 KiB
JavaScript
Raw Normal View History

2026-09-24 22:29:28 +03:30
import{B as e,Dt as t,O as n,Ot as r,T as i,Tt as a,V as o,Y as s,Z as c,c as l,d as u,g as ee,h as d,j as f,l as p,m,r as h,s as g,t as _,u as v}from"./_plugin-vue_export-helper-OaxA6A2f.js";import{a as y,f as b,t as x}from"./http-Djf2pGxE.js";import{V as S,f as C}from"./index-CznUUXv3.js";import{t as te}from"./AdminPageSkeleton-CTgUqaAu.js";import{t as w}from"./BaseSwitch-TV5Yvtf7.js";import{t as T}from"./BaseEmptyState-D6sk-aI_.js";import{t as E}from"./AdminImagePicker-C4toq7MG.js";import{t as D}from"./AdminSelect-DK-_otkw.js";var O={class:`banners-page`},k={key:2,class:`admin-card`},A={class:`admin-table`},j={key:0,class:`banner-sub`},M={class:`actions`},N=[`onClick`],P=[`onClick`],F={class:`field`},I={class:`field`},L={class:`field__head`},R={class:`field`},z={class:`field__head`},B={class:`field`},ne={class:`field__head`},V={class:`field`},H={class:`field`},U=[`disabled`],W=_(ee({__name:`BannersView`,setup(ee){let _=[{value:`home_hero`,label:`خانه — بنر اصلی`},{value:`products_hero`,label:`لیست محصولات`},{value:`categories_hero`,label:`دسته‌بندی‌ها`}],W=c([]),G=c(!0),K=c(!1),q=c(!1),J=c(null),Y=y(),X=s({slot:`home_hero`,title:``,subtitle:``,ctaLabel:``,ctaLink:`/categories`,imageUrl:null,displayOrder:0,isActive:!0,showTitle:!0,showSubtitle:!0,showCta:!0}),Z=g(()=>J.value?`ویرایش بنر`:`افزودن بنر`);function re(e){return _.find(t=>t.value===e)?.label??e}async function Q(){G.value=!0;try{W.value=await C.list()}catch(e){Y.error(e instanceof x?e.message:`بارگذاری بنرها ناموفق بود.`)}finally{G.value=!1}}function $(){J.value=null,Object.assign(X,{slot:`home_hero`,title:``,subtitle:``,ctaLabel:`مشاهده کالکشن`,ctaLink:`/categories`,imageUrl:null,displayOrder:W.value.length,isActive:!0,showTitle:!0,showSubtitle:!0,showCta:!0}),q.value=!0}function ie(e){J.value=e.id,Object.assign(X,{slot:e.slot,title:e.title,subtitle:e.subtitle,ctaLabel:e.ctaLabel,ctaLink:e.ctaLink||`/categories`,imageUrl:e.imageUrl||null,displayOrder:e.displayOrder,isActive:e.isActive,showTitle:e.showTitle!==!1,showSubtitle:e.showSubtitle!==!1,showCta:e.showCta!==!1}),q.value=!0}async function ae(){if(X.title.trim()){K.value=!0;try{let e={slot:X.slot,title:X.title.trim(),subtitle:X.subtitle.trim()||null,ctaLabel:X.ctaLabel.trim()||null,ctaLink:X.ctaLink.trim()||null,imageUrl:X.imageUrl,displayOrder:X.displayOrder,isActive:X.isActive,showTitle:X.showTitle,showSubtitle:X.showSubtitle,showCta:X.showCta};J.value?await C.update(J.value,e):await C.create(e),q.value=!1,Y.success(`بنر ذخیره شد.`),await Q()}catch(e){Y.error(e instanceof x?e.message:`ذخیره بنر ناموفق بود.`)}finally{K.value=!1}}}async function oe(e){if(window.confirm(`بنر «${e.title}» حذف شود؟`))try{await C.remove(e.id),Y.success(`بنر حذف شد.`),await Q()}catch(e){Y.error(e instanceof x?e.message:`حذف بنر ناموفق بود.`)}}return i(()=>{Q()}),(i,s)=>(n(),u(`div`,O,[l(`div`,{class:`admin-page-header`},[s[13]||=l(`div`,null,[l(`h1`,{class:`admin-page-header__title`},`بنرها`),l(`p`,{class:`admin-page-header__sub`},`بنر بخش‌های مختلف اپ کاربر را از اینجا مدیریت کنید.`)],-1),l(`button`,{type:`button`,class:`admin-btn admin-btn--primary`,onClick:$},`افزودن بنر`)]),G.value?(n(),p(te,{key:0,variant:`table`})):W.value.length?(n(),u(`div`,k,[l(`table`,A,[s[14]||=l(`thead`,null,[l(`tr`,null,[l(`th`,null,`تصویر`),l(`th`,null,`عنوان`),l(`th`,null,`بخش`),l(`th`,null,`دکمه`),l(`th`,null,`فعال`),l(`th`,{class:`actions`},`عملیات`)])],-1),l(`tbody`,null,[(n(!0),u(h,null,f(W.value,e=>(n(),u(`tr`,{key:e.id},[l(`td`,null,[l(`span`,{class:a([`banner-thumb`,{"banner-thumb--empty":!e.imageUrl}]),style:t(e.imageUrl?{backgroundImage:`url(${e.imageUrl})`}:void 0)},null,6)]),l(`td`,null,[l(`strong`,null,r(e.title),1),e.subtitle?(n(),u(`p`,j,r(e.subtitle),1)):v(``,!0)]),l(`td`,null,r(re(e.slot)),1),l(`td`,null,r(e.ctaLabel||`—`),1),l(`td`,null,r(e.isActive?`بله`:`خیر`),1),l(`td`,M,[l(`button`,{t