first commit
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* 产品品类配置文件
|
||||
*
|
||||
* ⚠️ 重要:当实际产品尺寸确定后,请修改本文件中的 mask 参数
|
||||
* 修改后页面会自动生效,无需改动其他代码
|
||||
*/
|
||||
|
||||
import { ProductCategory } from '../types'
|
||||
|
||||
export const PRODUCTS: ProductCategory[] = [
|
||||
{
|
||||
id: 'notebook-small',
|
||||
name: '微雕笔记本(小)',
|
||||
desc: '便携随行,记录点滴',
|
||||
icon: '📓',
|
||||
price: 12,
|
||||
leadTime: '3-5个工作日',
|
||||
description:
|
||||
'精选优质纸张,封面采用高档PU材质,手感细腻。内页可定制横线、方格或空白三种版式。激光微雕工艺将名字或图案精准刻印在封面,永不褪色。小巧轻便,适合随身携带,无论是课堂笔记还是日常备忘,都是你的专属伴侣。',
|
||||
images: ['/img/book_small/The1.png'],
|
||||
mask: {
|
||||
shape: 'rect',
|
||||
width: 300,
|
||||
height: 420,
|
||||
borderRadius: 8
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'notebook-large',
|
||||
name: '微雕笔记本(大)',
|
||||
desc: '大开本,更多创作空间',
|
||||
icon: '📔',
|
||||
price: 45,
|
||||
leadTime: '3-5个工作日',
|
||||
description:
|
||||
'A4尺寸大开本,180°平摊设计,书写更自由。封面可选真皮、仿布纹或磨砂材质,激光微雕区域更大,适合呈现全班名字、团队口号或公司Logo等大篇幅内容。是毕业纪念、企业年会礼品的首选。',
|
||||
images: ['/img/book_big/The1.png', '/img/book_big/The2.png'],
|
||||
mask: {
|
||||
shape: 'rect',
|
||||
width: 340,
|
||||
height: 480,
|
||||
borderRadius: 8
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'coaster',
|
||||
name: '铜质杯垫',
|
||||
desc: '金属质感,桌面艺术',
|
||||
icon: '☕',
|
||||
price: 25,
|
||||
leadTime: '5-7个工作日',
|
||||
description:
|
||||
'采用优质黄铜材质,表面经拉丝工艺处理,呈现哑光金属质感。背面配有防滑软木垫,保护桌面同时防止滑动。激光微雕可在表面刻印名字、日期或祝福语,是乔迁新居、新婚贺礼的精致之选。',
|
||||
images: ['/img/cup/The1.jpg'],
|
||||
mask: {
|
||||
shape: 'circle',
|
||||
width: 280,
|
||||
height: 280
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'penbox',
|
||||
name: '竹制笔盒',
|
||||
desc: '自然竹纹,文房雅器',
|
||||
icon: '✏️',
|
||||
price: 75,
|
||||
leadTime: '7-10个工作日',
|
||||
description:
|
||||
'精选天然楠竹,经多道工序打磨抛光,保留天然竹纹肌理。盒盖采用磁吸开合,内部设有分层隔板。激光微雕在竹面上呈现深浅不一的雕刻效果,融入墨香气质。适合书房案头、书法爱好者的文房伴侣。',
|
||||
images: ['/img/penbox/The1.png', '/img/penbox/The2.png', '/img/penbox/The3.jpg'],
|
||||
mask: {
|
||||
shape: 'rect',
|
||||
width: 320,
|
||||
height: 160,
|
||||
borderRadius: 12
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'booklamp',
|
||||
name: '书本型灯',
|
||||
desc: '温暖光影,点亮心意',
|
||||
icon: '💡',
|
||||
price: 45,
|
||||
leadTime: '5-7个工作日',
|
||||
description:
|
||||
'开合式设计,打开即亮,合拢即灭,如魔法书般充满惊喜。采用LED暖光灯源,光线柔和不刺眼,可持续点亮6-8小时。封面激光微雕可定制文字、图案或照片,让温暖的灯光承载专属记忆。是情侣礼物、毕业礼物的创意之选。',
|
||||
images: ['/img/booklight/The1.jpg', '/img/booklight/The2.jpg'],
|
||||
mask: {
|
||||
shape: 'rect',
|
||||
width: 320,
|
||||
height: 240,
|
||||
borderRadius: 4
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
/** CATEGORIES 为 PRODUCTS 的别名,供页面引用 */
|
||||
export const CATEGORIES = PRODUCTS
|
||||
|
||||
/**
|
||||
* 根据产品ID查找品类配置
|
||||
*/
|
||||
export const getProductById = (id: string): ProductCategory | undefined => {
|
||||
return PRODUCTS.find(p => p.id === id)
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
import type { DesignItem, OrderItem } from '../types'
|
||||
|
||||
const DESIGN_KEY = 'smart_design_list'
|
||||
const ORDER_KEY = 'smart_order_list'
|
||||
const USER_KEY = 'smart_user_info'
|
||||
const THEME_KEY = 'smart_theme'
|
||||
|
||||
/** 获取设计清单 */
|
||||
export const getDesignList = (): DesignItem[] => {
|
||||
try {
|
||||
return Taro.getStorageSync(DESIGN_KEY) || []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
/** 保存设计清单 */
|
||||
export const setDesignList = (list: DesignItem[]) => {
|
||||
Taro.setStorageSync(DESIGN_KEY, list)
|
||||
}
|
||||
|
||||
/** 获取订单列表 */
|
||||
export const getOrderList = (): OrderItem[] => {
|
||||
try {
|
||||
return Taro.getStorageSync(ORDER_KEY) || []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
/** 保存订单列表 */
|
||||
export const setOrderList = (list: OrderItem[]) => {
|
||||
Taro.setStorageSync(ORDER_KEY, list)
|
||||
}
|
||||
|
||||
/** 添加设计清单条目 */
|
||||
export const addDesign = (product: any, count: number): DesignItem => {
|
||||
const list = getDesignList()
|
||||
const item: DesignItem = {
|
||||
id: 'DSG' + Date.now(),
|
||||
productId: product.id,
|
||||
productName: product.name,
|
||||
productIcon: product.icon,
|
||||
unitPrice: product.price,
|
||||
count,
|
||||
status: 'undesigned',
|
||||
createdAt: new Date().toISOString().slice(0, 10)
|
||||
}
|
||||
setDesignList([...list, item])
|
||||
return item
|
||||
}
|
||||
|
||||
/** 更新设计清单条目 */
|
||||
export const updateDesign = (id: string, patch: Partial<DesignItem>) => {
|
||||
const list = getDesignList()
|
||||
const idx = list.findIndex(d => d.id === id)
|
||||
if (idx === -1) return
|
||||
list[idx] = { ...list[idx], ...patch }
|
||||
setDesignList(list)
|
||||
}
|
||||
|
||||
/** 设计转订单 */
|
||||
export const designToOrder = (designId: string): OrderItem | null => {
|
||||
const dList = getDesignList()
|
||||
const oList = getOrderList()
|
||||
const design = dList.find(d => d.id === designId)
|
||||
if (!design) return null
|
||||
|
||||
const order: OrderItem = {
|
||||
id: 'ORD' + Date.now().toString().slice(-9),
|
||||
productName: design.productName,
|
||||
productIcon: design.productIcon,
|
||||
statusCode: 'pending',
|
||||
date: new Date().toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }).replace(/\//g, '-'),
|
||||
price: '¥' + (design.unitPrice * design.count).toFixed(2),
|
||||
count: design.count,
|
||||
sku: `${design.productName} × ${design.count}`
|
||||
}
|
||||
|
||||
// 更新 design 状态
|
||||
const dIdx = dList.findIndex(d => d.id === designId)
|
||||
if (dIdx !== -1) {
|
||||
dList[dIdx].status = 'ordered'
|
||||
dList[dIdx].orderId = order.id
|
||||
}
|
||||
|
||||
setDesignList(dList)
|
||||
setOrderList([order, ...oList])
|
||||
return order
|
||||
}
|
||||
|
||||
/** 用户数据 */
|
||||
export const getUserInfo = () => {
|
||||
try {
|
||||
return Taro.getStorageSync(USER_KEY)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export const setUserInfo = (info: any) => {
|
||||
Taro.setStorageSync(USER_KEY, info)
|
||||
}
|
||||
|
||||
/** 主题 */
|
||||
export type ThemeMode = 'light' | 'dark'
|
||||
|
||||
export const getTheme = (): ThemeMode => {
|
||||
try {
|
||||
return Taro.getStorageSync(THEME_KEY) || 'light'
|
||||
} catch {
|
||||
return 'light'
|
||||
}
|
||||
}
|
||||
|
||||
export const setTheme = (theme: ThemeMode) => {
|
||||
Taro.setStorageSync(THEME_KEY, theme)
|
||||
}
|
||||
Reference in New Issue
Block a user