update 28/011

This commit is contained in:
2026-01-28 17:26:02 +07:00
parent 5fc49b68d3
commit bf78d0583d
27 changed files with 2553 additions and 3045 deletions

View File

@@ -1,6 +1,6 @@
// hoanghapc/src/lib/productPage.ts
import { categories } from "@/data/categories";
import { productList } from "@/data/products";
import { productList } from "@/data/productList";
export type ProductResult =
| { type: "product_category"; data: any }
@@ -23,7 +23,10 @@ export function resolveProductPage(slug: string): ProductResult | null {
}
// DETAIL
const product = productList.list?.find(p => p.productUrl === url);
const product = productList
.flatMap((item: any) => item.list)
.find((p: any) => p.productUrl === url);
if (product) {
return { type: "product_detail", data: product };
}

View File

@@ -1,8 +1,8 @@
// Add tất cả sp trong data product vào 1 mảng
import { productList } from '@/data/products';
import { productList } from '@/data/productList';
export function getAllProducts() {
return productList.flatMap((group:any) => group.list);
return productList.flatMap((group: any) => group.list);
}
@@ -38,8 +38,6 @@ export function formatTextList(
.join('');
}
// Format giá
export function formatPrice(amount: number) {
return amount.toLocaleString('vi-VN');
@@ -54,22 +52,30 @@ export function calculateDiscount(
return Math.ceil(((marketPrice - price) / marketPrice) * 100);
}
export function formatArticleTime(article_time:string) {
// format thời gian
export function formatArticleTime(article_time: string) {
let day: string;
let month: string;
let year: string;
if (article_time.toLowerCase().includes('hôm nay')) {
const time = new Date();
day = (time.getDate() <= 9) ? '0' + time.getDate() : String(time.getDate());
month = (time.getMonth()+1 <= 9) ? '0' + (time.getMonth()+1) : String(time.getMonth()+1);
year = String(time.getFullYear());
const time = new Date();
day = (time.getDate() <= 9) ? '0' + time.getDate() : String(time.getDate());
month = (time.getMonth() + 1 <= 9) ? '0' + (time.getMonth() + 1) : String(time.getMonth() + 1);
year = String(time.getFullYear());
} else {
day = article_time.substring(0,2);
month = article_time.substring(3,5);
year = article_time.substring(6,10);
day = article_time.substring(0, 2);
month = article_time.substring(3, 5);
year = article_time.substring(6, 10);
}
return `${day}/${month}/${year}`;
}
//
export function normalizeKey(str: string) {
return str
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.replace(/\s+/g, '-');
}