2026-09-09 06:46:27 +03:30
|
|
|
// Scoped port of legacy henza_pwa/src/store/store.ts.
|
|
|
|
|
//
|
|
|
|
|
// Legacy fetched one curated payload (POST /front + GET /config) that carried
|
|
|
|
|
// the home banner slider, the category grid, promotions, the ignore-list and
|
|
|
|
|
// the gold price ticker. The new API exposes none of that as a single config
|
|
|
|
|
// endpoint, so this store restores the two pieces that drive visible home-page
|
|
|
|
|
// UI and are actually derivable today:
|
|
|
|
|
//
|
|
|
|
|
// - `cats` — REAL data: distinct categories derived from GET /catalog/products
|
|
|
|
|
// (the response already includes each product's category).
|
|
|
|
|
// Legacy's per-category `icon.image` was a remote URL from the old
|
|
|
|
|
// Laravel host and has no equivalent, so a local brand mark stands
|
|
|
|
|
// in until category artwork exists.
|
|
|
|
|
// - `config.main_slider` — legacy's banner slides were remote URLs too. These
|
|
|
|
|
// are placeholder slides built from legacy's own local artwork,
|
|
|
|
|
// using legacy's exact slide shape ({text, type, src, link}) so
|
|
|
|
|
// HomeSlider's popup/link/discount click handling works unchanged.
|
|
|
|
|
//
|
|
|
|
|
// Not ported (no backend): promotionList, ignoreList, priceList, isLoaded.
|
2026-10-12 10:40:22 +03:30
|
|
|
//
|
|
|
|
|
// `isLoaded` — «عمداً تکرار نشد — D3/ب» (owner, 2026-10-12). Legacy used it as a
|
|
|
|
|
// router guard: a signed-in user whose one big bootstrap request had not landed
|
|
|
|
|
// was sent to `home` from any route lacking `meta.skipLoadedCheck`
|
|
|
|
|
// (henza_pwa/src/router/index.ts:263-266). The target has no such bootstrap —
|
|
|
|
|
// every page fetches its own data — so the flag would guard nothing and only
|
|
|
|
|
// add a bounce: opening a shared product link would land on home instead of the
|
|
|
|
|
// product. Replicating it would port the breakage, not the behaviour (D4).
|
2026-09-09 06:46:27 +03:30
|
|
|
import { defineStore } from 'pinia'
|
2026-10-11 14:31:32 +03:30
|
|
|
import { useCatalogStore } from './catalogStore'
|
2026-09-09 06:46:27 +03:30
|
|
|
import shippingArt from '../assets/img/shipping-and-delivery.png'
|
|
|
|
|
import competitionArt from '../assets/img/sports-and-competition.png'
|
2026-09-16 11:59:35 +03:30
|
|
|
import brandArt from '../assets/img/montzar-logo.png'
|
2026-09-09 06:46:27 +03:30
|
|
|
|
|
|
|
|
export interface Slide {
|
|
|
|
|
text: string | undefined
|
|
|
|
|
type: string | undefined
|
|
|
|
|
src: string | undefined
|
|
|
|
|
link: string | undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface HomeCategory {
|
|
|
|
|
id: string
|
|
|
|
|
title: string
|
|
|
|
|
icon?: { image: string }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PLACEHOLDER_SLIDES: Slide[] = [
|
|
|
|
|
{
|
|
|
|
|
type: 'popup',
|
|
|
|
|
src: shippingArt,
|
|
|
|
|
text: 'ارسال سریع و مطمئن سفارشهای شما به سراسر کشور.',
|
|
|
|
|
link: undefined,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popup',
|
|
|
|
|
src: competitionArt,
|
2026-09-16 11:59:35 +03:30
|
|
|
text: 'جدیدترین محصولات منتزر را در بخش محصولات جدید ببینید.',
|
2026-09-09 06:46:27 +03:30
|
|
|
link: undefined,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'popup',
|
|
|
|
|
src: brandArt,
|
2026-09-16 11:59:35 +03:30
|
|
|
text: 'منتزر، همراه شما در خرید و فروش طلا.',
|
2026-09-09 06:46:27 +03:30
|
|
|
link: undefined,
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
export const useConfigStore = defineStore('config', {
|
|
|
|
|
state: () => ({
|
|
|
|
|
config: { main_slider: PLACEHOLDER_SLIDES as Slide[] },
|
|
|
|
|
cats: [] as HomeCategory[],
|
|
|
|
|
loaded: false,
|
|
|
|
|
}),
|
|
|
|
|
actions: {
|
|
|
|
|
setCats(cats: HomeCategory[]) {
|
|
|
|
|
this.cats = cats
|
|
|
|
|
},
|
|
|
|
|
// Legacy's store.init() fanned out to /config, /promotion, /ignore, /price.
|
|
|
|
|
// Here the only live source is the product catalogue, from which the real
|
|
|
|
|
// category list is derived.
|
2026-10-11 14:31:32 +03:30
|
|
|
// The catalogue comes from catalogStore, so calling this next to another
|
|
|
|
|
// catalogue read costs no second request.
|
|
|
|
|
async init(force = false) {
|
2026-09-09 06:46:27 +03:30
|
|
|
try {
|
2026-10-11 14:31:32 +03:30
|
|
|
const catalog = useCatalogStore()
|
|
|
|
|
await catalog.load(force)
|
|
|
|
|
this.cats = catalog.categories.map((c) => ({ ...c, icon: { image: brandArt } }))
|
2026-09-09 06:46:27 +03:30
|
|
|
this.loaded = true
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log(e)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|