2 lines
4.7 KiB
JavaScript
2 lines
4.7 KiB
JavaScript
import{c as h}from"./index-eVF4AHSu.js";import{n as v}from"./pagination-BgSlm-mj.js";const g=h();function f(e){return{id:Number(e.id??0),nameZh:String(e.nameZh??e.name??""),nameEn:e.nameEn!==void 0?String(e.nameEn):void 0,code:e.code!==void 0?String(e.code):void 0,icon:e.icon??null,image:e.image??null,children:Array.isArray(e.children)?e.children.map(i=>f(i&&typeof i=="object"?i:{})):void 0}}function y(e){return{id:Number(e.id??0),nameZh:String(e.nameZh??e.name??""),nameEn:e.nameEn!==void 0?String(e.nameEn):void 0,mainImage:typeof e.mainImage=="string"||e.mainImage===null?e.mainImage:typeof e.coverImage=="string"?e.coverImage:null,summaryZh:typeof e.summaryZh=="string"?e.summaryZh:typeof e.summary=="string"?e.summary:void 0,summaryEn:typeof e.summaryEn=="string"?e.summaryEn:void 0,categoryLabelZh:typeof e.categoryLabelZh=="string"?e.categoryLabelZh:void 0,priceMin:typeof e.priceMin=="number"?e.priceMin:e.priceMin!==void 0&&e.priceMin!==null?Number(e.priceMin):void 0,priceMax:typeof e.priceMax=="number"?e.priceMax:e.priceMax!==void 0&&e.priceMax!==null?Number(e.priceMax):void 0,isShowPrice:typeof e.isShowPrice=="boolean"?e.isShowPrice:void 0}}async function S(){try{const e=await g.get("/portal/product/category/tree");return Array.isArray(e)?e.map(i=>f(i&&typeof i=="object"?i:{})):[]}catch(e){return console.warn("[portal/product/category/tree] fallback:",e),[{id:1,nameZh:"全屋定制",nameEn:"Whole-house tailoring",code:"whole-house",children:[{id:11,nameZh:"客厅系统",nameEn:"Living systems"}]},{id:2,nameZh:"卧室与睡眠",nameEn:"Bedroom",children:[{id:21,nameZh:"床 / 床头柜",nameEn:"Beds / nightstands"}]},{id:3,nameZh:"餐厨空间",nameEn:"Dining · kitchen adjoining"},{id:4,nameZh:"工程配套",nameEn:"Project programs"}]}}function Z(e){return Array.from({length:42}).map((i,r)=>({id:500+r,categoryLabelZh:e?`分类 ${e}`:"全屋定制 · 占位",nameZh:`产品占位 ${r+1}`,nameEn:`Placeholder product ${r+1}`,mainImage:null,summaryZh:"占位:稍后由后台配图、参数库与卖点文案回填。",summaryEn:"Placeholder: images, SKU matrix and narratives will arrive from CMS.",isShowPrice:!1,priceMin:void 0,priceMax:void 0}))}async function b(e){var c;const i=e.size??12,r=e.page??1,a={page:String(r),size:String(i)};e.categoryId!==void 0&&(a.categoryId=String(e.categoryId)),e.keyword&&(a.keyword=e.keyword),e.isHot===!0&&(a.isHot="true"),e.isNew===!0&&(a.isNew="true"),e.isRecommend===!0&&(a.isRecommend="true");try{const l=await g.get("/portal/product/list",{params:a});return v(l,y,i)}catch(l){console.warn("[portal/product/list] fallback:",l);const u=Z(e.categoryId);let m=u;const s=(c=e.keyword)==null?void 0:c.trim().toLowerCase();s&&(m=u.filter(p=>`${p.nameZh} ${p.nameEn??""}`.toLowerCase().includes(s)));const d=Math.max(0,(r-1)*i),t=m.slice(d,d+i),n=m.length,o=Math.max(1,Math.ceil(n/i));return{records:t,total:n,current:r,pages:o}}}async function H(e){const{records:i}=await b({categoryId:e,page:1,size:96});return i}function P(e){const i=y(e),r=e.params&&Array.isArray(e.params)?e.params.map(t=>t&&typeof t=="object"?t:null).filter(Boolean).map(t=>({name:String(t.name??t.key??""),value:String(t.value??"")})).filter(t=>t.name&&t.value):void 0,a=e.specs&&Array.isArray(e.specs)?e.specs.map(t=>typeof t=="string"?t:t&&typeof t=="object"?String(t.text??""):"").filter(Boolean):void 0;let c;e.gallery&&Array.isArray(e.gallery)?c=e.gallery.map(t=>{if(!t||typeof t!="object")return null;const n=t,o=n.src??n.url;return typeof o=="string"&&o?o:null}):e.images&&Array.isArray(e.images)&&(c=e.images.map(t=>{if(typeof t=="string")return t;if(!t||typeof t!="object")return null;const n=t,o=n.url??n.src;return typeof o=="string"&&o?o:null}));const l=a!=null&&a.length?a:r!=null&&r.length?r.map(t=>`${t.name}:${t.value}`):void 0,u=typeof e.detailHtmlZh=="string"?e.detailHtmlZh:typeof e.detailHtml=="string"?e.detailHtml:typeof e.html=="string"?e.html:void 0,m=typeof e.sceneHtmlZh=="string"?e.sceneHtmlZh:void 0;let s;const d=e.relatedProducts??e.related;return Array.isArray(d)&&(s=d.map(t=>y(t&&typeof t=="object"?t:{}))),{...i,specs:l,images:c,detailHtmlZh:u,sceneHtmlZh:m,detailHtml:typeof e.detailHtml=="string"?e.detailHtml:void 0,params:r!=null&&r.length?r:void 0,relatedProducts:s}}async function A(e){try{const i=await g.get(`/portal/product/detail/${e}`);return P(i&&typeof i=="object"?i:{})}catch(i){return console.warn("[portal/product/detail] fallback:",i),{id:Number.parseInt(e,10)||0,nameZh:"产品详情占位",nameEn:"Placeholder detail page",mainImage:null,summaryZh:"该区域用于展示高清图库、结构化参数与应用场景。",images:[null,null,null],specs:["材质:(占位)","尺寸:(占位)","交付周期:(占位)"],detailHtmlZh:"<p>占位段落:稍后由 CMS / page_block / 详情富文本回填。</p>"}}}export{S as a,b,A as c,H as f,y as m};
|