Improve hub page: new RouteStepper, HubProductCard with ApexCharts
All checks were successful
Build Docker Image / build (push) Successful in 4m57s
All checks were successful
Build Docker Image / build (push) Successful in 4m57s
- Redesign RouteStepper: nodes connected by lines with distance on line - Add HubProductCard component with sparkline chart background - Auto-select first product when hub page loads - Remove placeholder with package-x icon - Add ApexCharts plugin for charts - Pass startName/endName to RouteStepper for route visualization
This commit is contained in:
112
app/components/catalog/HubProductCard.vue
Normal file
112
app/components/catalog/HubProductCard.vue
Normal file
@@ -0,0 +1,112 @@
|
||||
<template>
|
||||
<Card
|
||||
padding="md"
|
||||
interactive
|
||||
class="cursor-pointer overflow-hidden min-w-36 shrink-0"
|
||||
:class="{ 'ring-2 ring-primary': selected }"
|
||||
@click="$emit('select')"
|
||||
>
|
||||
<div class="relative min-h-14">
|
||||
<!-- Sparkline chart background -->
|
||||
<div v-if="priceHistory.length > 1" class="absolute inset-0 opacity-15">
|
||||
<ClientOnly>
|
||||
<apexchart
|
||||
type="area"
|
||||
height="56"
|
||||
:options="chartOptions"
|
||||
:series="chartSeries"
|
||||
/>
|
||||
</ClientOnly>
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<div class="relative z-10">
|
||||
<Text weight="semibold" size="sm" class="mb-1">{{ name }}</Text>
|
||||
<div class="flex items-center gap-2">
|
||||
<Text v-if="currentPrice" size="sm" class="text-primary font-bold">
|
||||
{{ formattedPrice }}
|
||||
</Text>
|
||||
<span
|
||||
v-if="trend !== 0"
|
||||
class="text-xs font-medium"
|
||||
:class="trend > 0 ? 'text-success' : 'text-error'"
|
||||
>
|
||||
{{ trend > 0 ? '↑' : '↓' }} {{ Math.abs(trend) }}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const props = withDefaults(defineProps<{
|
||||
name: string
|
||||
currentPrice?: number | null
|
||||
currency?: string | null
|
||||
priceHistory?: number[]
|
||||
selected?: boolean
|
||||
}>(), {
|
||||
priceHistory: () => [],
|
||||
selected: false
|
||||
})
|
||||
|
||||
defineEmits<{
|
||||
select: []
|
||||
}>()
|
||||
|
||||
const formattedPrice = computed(() => {
|
||||
if (!props.currentPrice) return ''
|
||||
const symbol = getCurrencySymbol(props.currency)
|
||||
return `${symbol}${props.currentPrice.toLocaleString()}`
|
||||
})
|
||||
|
||||
const getCurrencySymbol = (currency?: string | null) => {
|
||||
switch (currency?.toUpperCase()) {
|
||||
case 'USD': return '$'
|
||||
case 'EUR': return '€'
|
||||
case 'RUB': return '₽'
|
||||
case 'CNY': return '¥'
|
||||
default: return '$'
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate trend from price history
|
||||
const trend = computed(() => {
|
||||
if (props.priceHistory.length < 2) return 0
|
||||
const first = props.priceHistory[0]
|
||||
const last = props.priceHistory[props.priceHistory.length - 1]
|
||||
if (!first || first === 0) return 0
|
||||
return Math.round(((last - first) / first) * 100)
|
||||
})
|
||||
|
||||
// Chart configuration
|
||||
const chartOptions = computed(() => ({
|
||||
chart: {
|
||||
type: 'area',
|
||||
sparkline: { enabled: true },
|
||||
animations: { enabled: false }
|
||||
},
|
||||
stroke: {
|
||||
curve: 'smooth',
|
||||
width: 2
|
||||
},
|
||||
fill: {
|
||||
type: 'gradient',
|
||||
gradient: {
|
||||
shadeIntensity: 1,
|
||||
opacityFrom: 0.4,
|
||||
opacityTo: 0.1
|
||||
}
|
||||
},
|
||||
colors: [trend.value >= 0 ? '#22c55e' : '#ef4444'],
|
||||
tooltip: { enabled: false },
|
||||
xaxis: { labels: { show: false } },
|
||||
yaxis: { labels: { show: false } }
|
||||
}))
|
||||
|
||||
const chartSeries = computed(() => [{
|
||||
name: 'Price',
|
||||
data: props.priceHistory.length > 0 ? props.priceHistory : [0]
|
||||
}])
|
||||
</script>
|
||||
@@ -12,7 +12,12 @@
|
||||
</div>
|
||||
|
||||
<!-- Route stepper -->
|
||||
<RouteStepper v-if="stages.length > 0" :stages="stages" />
|
||||
<RouteStepper
|
||||
v-if="stages.length > 0"
|
||||
:stages="stages"
|
||||
:start-name="startName"
|
||||
:end-name="endName"
|
||||
/>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -26,6 +31,8 @@ const props = withDefaults(defineProps<{
|
||||
currency?: string | null
|
||||
unit?: string | null
|
||||
stages?: RouteStage[]
|
||||
startName?: string
|
||||
endName?: string
|
||||
}>(), {
|
||||
stages: () => []
|
||||
})
|
||||
|
||||
@@ -1,14 +1,41 @@
|
||||
<template>
|
||||
<ul class="steps steps-horizontal text-xs w-full">
|
||||
<li
|
||||
v-for="(stage, index) in stages"
|
||||
:key="index"
|
||||
class="step step-primary"
|
||||
:data-content="getTransportIcon(stage.transportType)"
|
||||
>
|
||||
{{ formatDistance(stage.distanceKm) }} км
|
||||
</li>
|
||||
</ul>
|
||||
<div class="flex items-center w-full py-2">
|
||||
<!-- Start node -->
|
||||
<div class="flex flex-col items-center shrink-0">
|
||||
<div class="w-3 h-3 rounded-full bg-primary border-2 border-primary"></div>
|
||||
<Text v-if="startName" size="xs" tone="muted" class="mt-1 max-w-16 truncate text-center">{{ startName }}</Text>
|
||||
</div>
|
||||
|
||||
<!-- Stages (line + transport icon + distance -> node) -->
|
||||
<template v-for="(stage, i) in stages" :key="i">
|
||||
<!-- Line segment with transport icon and distance -->
|
||||
<div class="flex-1 flex flex-col items-center mx-1 min-w-12">
|
||||
<!-- Line with icon in the middle -->
|
||||
<div class="flex items-center w-full">
|
||||
<div class="h-0.5 bg-primary/60 flex-1"></div>
|
||||
<span class="px-1.5 text-sm" :title="getTransportName(stage.transportType)">
|
||||
{{ getTransportIcon(stage.transportType) }}
|
||||
</span>
|
||||
<div class="h-0.5 bg-primary/60 flex-1"></div>
|
||||
</div>
|
||||
<!-- Distance label -->
|
||||
<Text size="xs" tone="muted" class="mt-0.5 whitespace-nowrap">
|
||||
{{ formatDistance(stage.distanceKm) }} км
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
<!-- Intermediate/End node -->
|
||||
<div class="flex flex-col items-center shrink-0">
|
||||
<div
|
||||
class="rounded-full border-2"
|
||||
:class="i === stages.length - 1 ? 'w-3 h-3 bg-success border-success' : 'w-2.5 h-2.5 bg-base-100 border-primary'"
|
||||
></div>
|
||||
<Text v-if="i === stages.length - 1 && endName" size="xs" tone="muted" class="mt-1 max-w-16 truncate text-center">
|
||||
{{ endName }}
|
||||
</Text>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -19,6 +46,8 @@ export interface RouteStage {
|
||||
|
||||
defineProps<{
|
||||
stages: RouteStage[]
|
||||
startName?: string
|
||||
endName?: string
|
||||
}>()
|
||||
|
||||
const getTransportIcon = (type?: string | null) => {
|
||||
@@ -34,6 +63,19 @@ const getTransportIcon = (type?: string | null) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getTransportName = (type?: string | null) => {
|
||||
switch (type) {
|
||||
case 'rail':
|
||||
return 'Ж/Д'
|
||||
case 'sea':
|
||||
return 'Море'
|
||||
case 'road':
|
||||
case 'auto':
|
||||
default:
|
||||
return 'Авто'
|
||||
}
|
||||
}
|
||||
|
||||
const formatDistance = (km?: number | null) => {
|
||||
if (!km) return '0'
|
||||
return Math.round(km).toLocaleString()
|
||||
|
||||
@@ -44,17 +44,13 @@
|
||||
|
||||
<template #filters>
|
||||
<div class="flex gap-3 overflow-x-auto pb-2">
|
||||
<Card
|
||||
<HubProductCard
|
||||
v-for="product in products"
|
||||
:key="product.uuid"
|
||||
padding="sm"
|
||||
interactive
|
||||
class="min-w-32 cursor-pointer shrink-0"
|
||||
:class="selectedProductUuid === product.uuid ? 'ring-2 ring-primary' : ''"
|
||||
@click="selectedProductUuid = product.uuid"
|
||||
>
|
||||
<Text weight="semibold" size="sm">{{ product.name }}</Text>
|
||||
</Card>
|
||||
:name="product.name"
|
||||
:selected="selectedProductUuid === product.uuid"
|
||||
@select="selectedProductUuid = product.uuid"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -66,16 +62,13 @@
|
||||
:currency="getOfferData(item.uuid)?.currency"
|
||||
:unit="getOfferData(item.uuid)?.unit"
|
||||
:stages="item.stages"
|
||||
:start-name="item.name"
|
||||
:end-name="hub?.name"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #empty>
|
||||
<Stack align="center" gap="2">
|
||||
<Icon name="lucide:package-x" size="32" class="text-base-content/40" />
|
||||
<Text tone="muted">
|
||||
{{ selectedProductUuid ? t('catalogHub.sources.empty') : t('catalogHub.sources.selectProduct') }}
|
||||
</Text>
|
||||
</Stack>
|
||||
<Text tone="muted">{{ t('catalogHub.sources.empty') }}</Text>
|
||||
</template>
|
||||
</CatalogPage>
|
||||
</template>
|
||||
@@ -221,6 +214,11 @@ try {
|
||||
products.value = (productsData.value?.getAvailableProducts || [])
|
||||
.filter((p): p is { uuid: string; name: string } => p !== null && !!p.uuid && !!p.name)
|
||||
.map(p => ({ uuid: p.uuid!, name: p.name! }))
|
||||
|
||||
// Auto-select first product
|
||||
if (products.value.length > 0) {
|
||||
selectedProductUuid.value = products.value[0].uuid
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading hub:', error)
|
||||
} finally {
|
||||
|
||||
5
app/plugins/apexcharts.client.ts
Normal file
5
app/plugins/apexcharts.client.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import VueApexCharts from 'vue3-apexcharts'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.vueApp.use(VueApexCharts)
|
||||
})
|
||||
Reference in New Issue
Block a user