Files
nademitex_admin/dist/assets/CategoriesView-D47o28Jt.js
T
2026-10-29 15:24:44 +03:30

1 line
17 KiB
JavaScript

import{A as e,D as t,N as n,Q as r,U as i,W as a,c as o,d as s,et as c,g as l,h as u,jt as d,l as f,p,r as m,s as h,t as g,u as _}from"./_plugin-vue_export-helper-vx-p5QAT.js";import{a as ee,d as v,t as y}from"./http-CTjL79ty.js";import{D as b,H as x}from"./index-BWgYBNME.js";import{t as te}from"./AdminPageSkeleton-DacAHji8.js";import{t as S}from"./BaseSwitch-Dz4ODUhf.js";import{t as C}from"./AdminImagePicker-DhyB3HhH.js";import{t as w}from"./AdminSelect-hgn_nYC2.js";var T={class:`category-icon`,"aria-hidden":`true`},E=[`width`,`height`,`stroke`,`stroke-width`],D=[`width`,`height`,`stroke`,`stroke-width`],O=[`width`,`height`,`stroke`,`stroke-width`],k=[`width`,`height`,`stroke`],A=[`width`,`height`,`stroke`],j=[`width`,`height`,`stroke`],M=g(l({__name:`CategoryIcon`,props:{name:{},size:{default:18},color:{default:`currentColor`},strokeWidth:{default:1.5}},setup(t){let n=t,r={bolt:`vuesax-linear:flash`,feather:`vuesax-linear:pen-add`,diamond:`vuesax-linear:diamonds`,grid:`vuesax-linear:element-3`,bag:`vuesax-linear:shopping-bag`,weight:`vuesax-linear:shopping-bag`,"id-card":`vuesax-linear:personalcard`,catalog:`vuesax-linear:category`,headset:`vuesax-linear:headphone`,home:`vuesax-linear:home`},i=h(()=>r[n.name]);return(n,r)=>(e(),s(`span`,T,[i.value?(e(),f(x,{key:0,icon:i.value,size:t.size,"stroke-width":t.strokeWidth,color:t.color},null,8,[`icon`,`size`,`stroke-width`,`color`])):t.name===`shirt`?(e(),s(`svg`,{key:1,width:t.size,height:t.size,viewBox:`0 0 24 24`,fill:`none`,stroke:t.color,"stroke-width":t.strokeWidth,"stroke-linecap":`round`,"stroke-linejoin":`round`},[...r[0]||=[o(`path`,{d:`M8.25 5.25 12 7.75l3.75-2.5 2.25 2.75L16 9.5V18.5a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1V9.5L6 8l2.25-2.75Z`},null,-1),o(`path`,{d:`M12 7.75V18.5`},null,-1)]],8,E)):t.name===`suit`?(e(),s(`svg`,{key:2,width:t.size,height:t.size,viewBox:`0 0 24 24`,fill:`none`,stroke:t.color,"stroke-width":t.strokeWidth,"stroke-linecap":`round`,"stroke-linejoin":`round`},[...r[1]||=[o(`path`,{d:`M7.5 5.5h9l2 3v10.5a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1V8.5l2-3Z`},null,-1),o(`path`,{d:`M12 5.5v13`},null,-1),o(`path`,{d:`M7.5 9 12 11.75 16.5 9`},null,-1),o(`path`,{d:`M10.25 5.5V4a1.75 1.75 0 0 1 3.5 0v1.5`},null,-1)]],8,D)):t.name===`trousers`?(e(),s(`svg`,{key:3,width:t.size,height:t.size,viewBox:`0 0 24 24`,fill:`none`,stroke:t.color,"stroke-width":t.strokeWidth,"stroke-linecap":`round`,"stroke-linejoin":`round`},[...r[2]||=[o(`path`,{d:`M8 4.5h8v4.25l-1.75 11H13l-1-9.5-1 9.5H7.75L6 8.75V4.5Z`},null,-1),o(`path`,{d:`M12 8.75v11`},null,-1),o(`path`,{d:`M8 7.25h8`},null,-1)]],8,O)):t.name===`ruler`?(e(),s(`svg`,{key:4,width:t.size,height:t.size,viewBox:`0 0 24 24`,fill:`none`,stroke:t.color,"stroke-width":`1.6`,"stroke-linecap":`round`,"stroke-linejoin":`round`},[...r[3]||=[p(`<rect x="3" y="8" width="18" height="8" rx="1.5" data-v-76e4dc13></rect><path d="M7 8v3" data-v-76e4dc13></path><path d="M10 8v4" data-v-76e4dc13></path><path d="M13 8v3" data-v-76e4dc13></path><path d="M16 8v4" data-v-76e4dc13></path>`,5)]],8,k)):t.name===`composition`?(e(),s(`svg`,{key:5,width:t.size,height:t.size,viewBox:`0 0 24 24`,fill:`none`,stroke:t.color,"stroke-width":`1.6`,"stroke-linecap":`round`,"stroke-linejoin":`round`},[...r[4]||=[o(`path`,{d:`M12 3.5 20 8v8l-8 4.5L4 16V8l8-4.5Z`},null,-1)]],8,A)):t.name===`weave`?(e(),s(`svg`,{key:6,width:t.size,height:t.size,viewBox:`0 0 24 24`,fill:`none`,stroke:t.color,"stroke-width":`1.6`,"stroke-linecap":`round`},[...r[5]||=[p(`<path d="M6 4v16" data-v-76e4dc13></path><path d="M10 4v16" data-v-76e4dc13></path><path d="M14 4v16" data-v-76e4dc13></path><path d="M18 4v16" data-v-76e4dc13></path><path d="M4 8h16" data-v-76e4dc13></path><path d="M4 12h16" data-v-76e4dc13></path><path d="M4 16h16" data-v-76e4dc13></path>`,7)]],8,j)):_(``,!0)]))}}),[[`__scopeId`,`data-v-76e4dc13`]]),ne={class:`categories-admin`},re={class:`admin-page-header`},ie=[`disabled`],ae={key:1,class:`categories-admin__grid`},oe={class:`admin-card categories-panel`},se={class:`categories-panel__head`},ce={key:0,class:`categories-panel__add`},le={key:1,class:`categories-panel__empty`},ue={key:2,class:`categories-panel__list`},N={class:`category-row__fields`},P={class:`category-row__line`},F=[`onUpdate:modelValue`],I={class:`category-row__line`},L=[`onUpdate:modelValue`],R={class:`category-row__line`},z={class:`category-row__id`,dir:`ltr`},B=[`onClick`],V={class:`admin-card categories-panel`},H={class:`categories-panel__head`},U={key:0,class:`categories-panel__add`},W={key:1,class:`categories-panel__empty`},de={key:2,class:`categories-panel__list`},fe={class:`category-row__fields`},pe={class:`category-row__line`},me=[`onUpdate:modelValue`],he={class:`category-row__line`},ge=[`onUpdate:modelValue`],_e={class:`category-row__line`},ve=[`onUpdate:modelValue`],ye={class:`category-row__line`},be={class:`category-row__id`,dir:`ltr`},xe=[`onClick`],G=g(l({__name:`CategoriesView`,setup(l){let p=c([]),g=c([]),x=r({}),T=c(!0),E=c(!1),D=ee(),O=c(!1),k=c(!1),A=[{value:`shirt`,label:`پیراهن`},{value:`suit`,label:`کت‌شلوار`},{value:`trousers`,label:`شلوار`},{value:`bolt`,label:`آذرخش`},{value:`feather`,label:`پر`},{value:`diamond`,label:`الماس`},{value:`grid`,label:`شبکه`},{value:`bag`,label:`کیف`},{value:`id-card`,label:`کارت`},{value:`catalog`,label:`کالیته`},{value:`headset`,label:`پشتیبانی`},{value:`home`,label:`خانه`},{value:`ruler`,label:`عرض`},{value:`composition`,label:`جنس`},{value:`weight`,label:`وزن`},{value:`weave`,label:`نوع بافت`}];function j(e){return e===`shirt`?`shirt`:e===`suit`?`suit`:e===`trousers`?`trousers`:`grid`}function G(e){return e===`summer`?`bolt`:e===`winter`?`feather`:`diamond`}let K=r({id:``,title:``,subtitle:`مشاهده محصولات`,icon:`grid`,showTitle:!0,showSubtitle:!0,showIcon:!0}),q=r({id:``,title:``,description:``,ctaLabel:`مشاهده محصولات`,icon:`diamond`,showTitle:!0,showDescription:!0,showCta:!0,showIcon:!0});function J(e){return e!==!1}let Y=h(()=>p.value.map(e=>e.id)),X=h(()=>g.value.map(e=>e.id));function Z(e){return e.trim().toLowerCase().replace(/\s+/g,`_`).replace(/[^a-z0-9_\u0600-\u06ff-]/gi,``).slice(0,48)}function Q(){let e=[...Y.value,...X.value];for(let t of e)t in x||(x[t]=null);for(let t of Object.keys(x))e.includes(t)||delete x[t]}async function $(){T.value=!0;try{let e=await b.get();p.value=e.categoryDefsJson?.usage?.length?e.categoryDefsJson.usage.map(e=>({id:e.id,title:e.title,subtitle:e.subtitle||`مشاهده محصولات`,icon:e.icon||j(e.id),showTitle:J(e.showTitle),showSubtitle:J(e.showSubtitle),showIcon:J(e.showIcon)})):[{id:`trousers`,title:`پارچه‌های شلواری`,subtitle:`مشاهده محصولات`,icon:`trousers`,showTitle:!0,showSubtitle:!0,showIcon:!0},{id:`suit`,title:`پارچه‌های کت‌شلواری`,subtitle:`مشاهده محصولات`,icon:`suit`,showTitle:!0,showSubtitle:!0,showIcon:!0},{id:`shirt`,title:`پارچه‌های پیراهنی`,subtitle:`مشاهده محصولات`,icon:`shirt`,showTitle:!0,showSubtitle:!0,showIcon:!0}],g.value=e.categoryDefsJson?.seasons?.length?e.categoryDefsJson.seasons.map(e=>({id:e.id,title:e.title,description:e.description||``,ctaLabel:e.ctaLabel||`مشاهده محصولات`,icon:e.icon||G(e.id),showTitle:J(e.showTitle),showDescription:J(e.showDescription),showCta:J(e.showCta),showIcon:J(e.showIcon)})):[{id:`summer`,title:`تابستانه`,description:`سبک، خنک و مناسب فصل گرم`,ctaLabel:`مشاهده محصولات`,icon:`bolt`,showTitle:!0,showDescription:!0,showCta:!0,showIcon:!0},{id:`winter`,title:`زمستانه`,description:`گرم و مناسب فصل سرد`,ctaLabel:`مشاهده محصولات`,icon:`feather`,showTitle:!0,showDescription:!0,showCta:!0,showIcon:!0},{id:`all_season`,title:`چهارفصل`,description:`مناسب استفاده در بیشتر فصل‌های سال`,ctaLabel:`مشاهده محصولات`,icon:`diamond`,showTitle:!0,showDescription:!0,showCta:!0,showIcon:!0}],Q();let t=e.categoryImagesJson??{};for(let e of Object.keys(x))x[e]=t[e]??null}catch(e){D.error(e instanceof y?e.message:`بارگذاری دسته‌ها ناموفق بود.`),p.value.length||(p.value=[{id:`trousers`,title:`پارچه‌های شلواری`,subtitle:`مشاهده محصولات`,icon:`trousers`,showTitle:!0,showSubtitle:!0,showIcon:!0},{id:`suit`,title:`پارچه‌های کت‌شلواری`,subtitle:`مشاهده محصولات`,icon:`suit`,showTitle:!0,showSubtitle:!0,showIcon:!0},{id:`shirt`,title:`پارچه‌های پیراهنی`,subtitle:`مشاهده محصولات`,icon:`shirt`,showTitle:!0,showSubtitle:!0,showIcon:!0}]),g.value.length||(g.value=[{id:`summer`,title:`تابستانه`,description:`سبک، خنک و مناسب فصل گرم`,ctaLabel:`مشاهده محصولات`,icon:`bolt`,showTitle:!0,showDescription:!0,showCta:!0,showIcon:!0},{id:`winter`,title:`زمستانه`,description:`گرم و مناسب فصل سرد`,ctaLabel:`مشاهده محصولات`,icon:`feather`,showTitle:!0,showDescription:!0,showCta:!0,showIcon:!0},{id:`all_season`,title:`چهارفصل`,description:`مناسب استفاده در بیشتر فصل‌های سال`,ctaLabel:`مشاهده محصولات`,icon:`diamond`,showTitle:!0,showDescription:!0,showCta:!0,showIcon:!0}]),Q()}finally{T.value=!1}}function Se(){let e=Z(K.id||K.title),t=K.title.trim();if(!e||!t){D.error(`شناسه و عنوان دسته کاربرد الزامی است.`);return}if(Y.value.includes(e)||X.value.includes(e)){D.error(`این شناسه از قبل وجود دارد.`);return}p.value.push({id:e,title:t,subtitle:K.subtitle.trim()||`مشاهده محصولات`,icon:K.icon,showTitle:K.showTitle,showSubtitle:K.showSubtitle,showIcon:K.showIcon}),x[e]=null,K.id=``,K.title=``,K.subtitle=`مشاهده محصولات`,K.icon=`grid`,K.showTitle=!0,K.showSubtitle=!0,K.showIcon=!0,O.value=!1}function Ce(){let e=Z(q.id||q.title),t=q.title.trim();if(!e||!t){D.error(`شناسه و عنوان دسته فصل الزامی است.`);return}if(Y.value.includes(e)||X.value.includes(e)){D.error(`این شناسه از قبل وجود دارد.`);return}g.value.push({id:e,title:t,description:q.description.trim(),ctaLabel:q.ctaLabel.trim()||`مشاهده محصولات`,icon:q.icon,showTitle:q.showTitle,showDescription:q.showDescription,showCta:q.showCta,showIcon:q.showIcon}),x[e]=null,q.id=``,q.title=``,q.description=``,q.ctaLabel=`مشاهده محصولات`,q.icon=`diamond`,q.showTitle=!0,q.showDescription=!0,q.showCta=!0,q.showIcon=!0,k.value=!1}function we(e){if(p.value.length<=1){D.error(`حداقل یک دسته کاربرد لازم است.`);return}p.value=p.value.filter(t=>t.id!==e),delete x[e]}function Te(e){if(g.value.length<=1){D.error(`حداقل یک دسته فصل لازم است.`);return}g.value=g.value.filter(t=>t.id!==e),delete x[e]}async function Ee(){E.value=!0;try{let e={};for(let[t,n]of Object.entries(x))n&&(e[t]=n);await b.update({categoryDefsJson:{usage:p.value,seasons:g.value},categoryImagesJson:e}),D.success(`دسته‌بندی‌ها ذخیره شد.`),await $()}catch(e){D.error(e instanceof y?e.message:`ذخیره دسته‌بندی‌ها ناموفق بود.`)}finally{E.value=!1}}return t(()=>{$()}),(t,r)=>(e(),s(`div`,ne,[o(`div`,re,[r[8]||=o(`div`,null,[o(`h1`,{class:`admin-page-header__title`},`دسته‌بندی‌ها`),o(`p`,{class:`admin-page-header__sub`},` دسته‌های کاربرد و فصل را اضافه کنید. با کلید «نمایش / مخفی» مشخص کنید عنوان و توضیح در اپ کاربر دیده شود. `)],-1),o(`button`,{type:`button`,class:`admin-btn admin-btn--primary`,disabled:E.value||T.value,onClick:Ee},d(E.value?`در حال ذخیره...`:`ثبت تغییرات`),9,ie)]),T.value?(e(),f(te,{key:0,variant:`cards`})):(e(),s(`div`,ae,[o(`section`,oe,[o(`div`,se,[o(`div`,null,[r[9]||=o(`h2`,null,`بر اساس کاربرد`,-1),o(`p`,null,d(p.value.length)+` دسته برای فیلتر محصول در اپ کاربر`,1)]),o(`button`,{type:`button`,class:`admin-btn admin-btn--outline`,onClick:r[0]||=e=>O.value=!O.value},d(O.value?`بستن فرم`:`+ افزودن دسته`),1)]),O.value?(e(),s(`div`,ce,[a(o(`input`,{"onUpdate:modelValue":r[1]||=e=>K.title=e,class:`admin-input`,type:`text`,placeholder:`عنوان (مثلاً پارچه‌های مانتویی)`},null,512),[[v,K.title]]),a(o(`input`,{"onUpdate:modelValue":r[2]||=e=>K.id=e,class:`admin-input`,type:`text`,dir:`ltr`,placeholder:`شناسه انگلیسی (اختیاری، مثلاً mantle)`},null,512),[[v,K.id]]),a(o(`input`,{"onUpdate:modelValue":r[3]||=e=>K.subtitle=e,class:`admin-input`,type:`text`,placeholder:`زیرعنوان`},null,512),[[v,K.subtitle]]),o(`button`,{type:`button`,class:`admin-btn admin-btn--primary`,onClick:Se},`ثبت در لیست`)])):_(``,!0),p.value.length?(e(),s(`div`,ue,[(e(!0),s(m,null,n(p.value,t=>(e(),s(`article`,{key:t.id,class:`category-row`},[u(C,{"model-value":x[t.id],"onUpdate:modelValue":e=>x[t.id]=e},null,8,[`model-value`,`onUpdate:modelValue`]),o(`div`,N,[o(`div`,P,[a(o(`input`,{"onUpdate:modelValue":e=>t.title=e,class:`admin-input`,type:`text`,placeholder:`عنوان دسته`},null,8,F),[[v,t.title]]),u(S,{modelValue:t.showTitle,"onUpdate:modelValue":e=>t.showTitle=e,"active-text":`نمایش`,"inactive-text":`مخفی`},null,8,[`modelValue`,`onUpdate:modelValue`])]),o(`div`,I,[a(o(`input`,{"onUpdate:modelValue":e=>t.subtitle=e,class:`admin-input`,type:`text`,placeholder:`زیرعنوان`},null,8,L),[[v,t.subtitle]]),u(S,{modelValue:t.showSubtitle,"onUpdate:modelValue":e=>t.showSubtitle=e,"active-text":`نمایش`,"inactive-text":`مخفی`},null,8,[`modelValue`,`onUpdate:modelValue`])]),o(`div`,R,[u(w,{modelValue:t.icon,"onUpdate:modelValue":e=>t.icon=e,options:A,"aria-label":`آیکون`,block:``},{"option-leading":i(({option:t})=>[t?(e(),f(M,{key:0,name:t.value,size:18},null,8,[`name`])):_(``,!0)]),_:1},8,[`modelValue`,`onUpdate:modelValue`]),u(S,{modelValue:t.showIcon,"onUpdate:modelValue":e=>t.showIcon=e,"active-text":`نمایش`,"inactive-text":`مخفی`},null,8,[`modelValue`,`onUpdate:modelValue`])]),o(`p`,z,d(t.id),1)]),o(`button`,{type:`button`,class:`category-row__remove`,onClick:e=>we(t.id)},`حذف`,8,B)]))),128))])):(e(),s(`p`,le,`هنوز دسته‌ای ثبت نشده. با «افزودن دسته» شروع کنید.`))]),o(`section`,V,[o(`div`,H,[o(`div`,null,[r[10]||=o(`h2`,null,`بر اساس فصل`,-1),o(`p`,null,d(g.value.length)+` دسته فصلی برای فیلتر محصول`,1)]),o(`button`,{type:`button`,class:`admin-btn admin-btn--outline`,onClick:r[4]||=e=>k.value=!k.value},d(k.value?`بستن فرم`:`+ افزودن دسته`),1)]),k.value?(e(),s(`div`,U,[a(o(`input`,{"onUpdate:modelValue":r[5]||=e=>q.title=e,class:`admin-input`,type:`text`,placeholder:`عنوان (مثلاً بهاره)`},null,512),[[v,q.title]]),a(o(`input`,{"onUpdate:modelValue":r[6]||=e=>q.id=e,class:`admin-input`,type:`text`,dir:`ltr`,placeholder:`شناسه انگلیسی (اختیاری، مثلاً spring)`},null,512),[[v,q.id]]),a(o(`input`,{"onUpdate:modelValue":r[7]||=e=>q.description=e,class:`admin-input`,type:`text`,placeholder:`توضیح`},null,512),[[v,q.description]]),o(`button`,{type:`button`,class:`admin-btn admin-btn--primary`,onClick:Ce},`ثبت در لیست`)])):_(``,!0),g.value.length?(e(),s(`div`,de,[(e(!0),s(m,null,n(g.value,t=>(e(),s(`article`,{key:t.id,class:`category-row`},[u(C,{"model-value":x[t.id],"onUpdate:modelValue":e=>x[t.id]=e},null,8,[`model-value`,`onUpdate:modelValue`]),o(`div`,fe,[o(`div`,pe,[a(o(`input`,{"onUpdate:modelValue":e=>t.title=e,class:`admin-input`,type:`text`,placeholder:`عنوان دسته`},null,8,me),[[v,t.title]]),u(S,{modelValue:t.showTitle,"onUpdate:modelValue":e=>t.showTitle=e,"active-text":`نمایش`,"inactive-text":`مخفی`},null,8,[`modelValue`,`onUpdate:modelValue`])]),o(`div`,he,[a(o(`input`,{"onUpdate:modelValue":e=>t.description=e,class:`admin-input`,type:`text`,placeholder:`توضیح`},null,8,ge),[[v,t.description]]),u(S,{modelValue:t.showDescription,"onUpdate:modelValue":e=>t.showDescription=e,"active-text":`نمایش`,"inactive-text":`مخفی`},null,8,[`modelValue`,`onUpdate:modelValue`])]),o(`div`,_e,[a(o(`input`,{"onUpdate:modelValue":e=>t.ctaLabel=e,class:`admin-input`,type:`text`,placeholder:`متن لینک (مشاهده محصولات)`},null,8,ve),[[v,t.ctaLabel]]),u(S,{modelValue:t.showCta,"onUpdate:modelValue":e=>t.showCta=e,"active-text":`نمایش`,"inactive-text":`مخفی`},null,8,[`modelValue`,`onUpdate:modelValue`])]),o(`div`,ye,[u(w,{modelValue:t.icon,"onUpdate:modelValue":e=>t.icon=e,options:A,"aria-label":`آیکون`,block:``},{"option-leading":i(({option:t})=>[t?(e(),f(M,{key:0,name:t.value,size:18},null,8,[`name`])):_(``,!0)]),_:1},8,[`modelValue`,`onUpdate:modelValue`]),u(S,{modelValue:t.showIcon,"onUpdate:modelValue":e=>t.showIcon=e,"active-text":`نمایش`,"inactive-text":`مخفی`},null,8,[`modelValue`,`onUpdate:modelValue`])]),o(`p`,be,d(t.id),1)]),o(`button`,{type:`button`,class:`category-row__remove`,onClick:e=>Te(t.id)},`حذف`,8,xe)]))),128))])):(e(),s(`p`,W,`هنوز دسته‌ای ثبت نشده. با «افزودن دسته» شروع کنید.`))])]))]))}}),[[`__scopeId`,`data-v-c42a22e0`]]);export{G as default};