mi
This commit is contained in:
3
miniprogram/src/pages/goods/detail.config.ts
Normal file
3
miniprogram/src/pages/goods/detail.config.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '商品详情'
|
||||
})
|
||||
138
miniprogram/src/pages/goods/detail.scss
Normal file
138
miniprogram/src/pages/goods/detail.scss
Normal file
@@ -0,0 +1,138 @@
|
||||
.page-container {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #000;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.detail-img {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.info-section {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #00f0ff;
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.price {
|
||||
font-size: 28px;
|
||||
color: #00b96b;
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.specs {
|
||||
display: flex;
|
||||
background: rgba(255,255,255,0.05);
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
|
||||
.spec-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
border-right: 1px solid rgba(255,255,255,0.1);
|
||||
|
||||
&:last-child {
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 12px;
|
||||
color: #888;
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 14px;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.desc {
|
||||
margin-bottom: 20px;
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
color: #fff;
|
||||
margin-bottom: 10px;
|
||||
display: block;
|
||||
border-left: 3px solid #00f0ff;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.text {
|
||||
font-size: 14px;
|
||||
color: #ccc;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
|
||||
.feature-item {
|
||||
margin-bottom: 15px;
|
||||
|
||||
.f-title {
|
||||
font-size: 15px;
|
||||
color: #00f0ff;
|
||||
margin-bottom: 5px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.f-desc {
|
||||
font-size: 13px;
|
||||
color: #bbb;
|
||||
}
|
||||
}
|
||||
|
||||
.bottom-bar {
|
||||
background: #111;
|
||||
padding: 10px 20px;
|
||||
border-top: 1px solid rgba(255,255,255,0.1);
|
||||
|
||||
.btn-container {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.btn-cart, .btn-buy {
|
||||
flex: 1;
|
||||
border: none;
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
border-radius: 22px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.btn-cart {
|
||||
background: #333;
|
||||
}
|
||||
|
||||
.btn-buy {
|
||||
background: #00b96b;
|
||||
}
|
||||
}
|
||||
|
||||
.safe-area-bottom {
|
||||
padding-bottom: constant(safe-area-inset-bottom);
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
80
miniprogram/src/pages/goods/detail.tsx
Normal file
80
miniprogram/src/pages/goods/detail.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import { View, Text, Image, ScrollView, Button } from '@tarojs/components'
|
||||
import Taro, { useRouter, useLoad } from '@tarojs/taro'
|
||||
import { useState } from 'react'
|
||||
import { getConfigDetail } from '../../api'
|
||||
import './detail.scss'
|
||||
|
||||
export default function Detail() {
|
||||
const router = useRouter()
|
||||
const { id } = router.params
|
||||
const [product, setProduct] = useState<any>(null)
|
||||
|
||||
useLoad(() => {
|
||||
if (id) fetchDetail(id)
|
||||
})
|
||||
|
||||
const fetchDetail = async (id) => {
|
||||
try {
|
||||
const res = await getConfigDetail(id)
|
||||
setProduct(res)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
const buyNow = () => {
|
||||
if (!product) return
|
||||
Taro.navigateTo({
|
||||
url: `/pages/order/checkout?id=${product.id}&quantity=1`
|
||||
})
|
||||
}
|
||||
|
||||
if (!product) return <View className='loading'>Loading...</View>
|
||||
|
||||
return (
|
||||
<View className='page-container'>
|
||||
<ScrollView scrollY className='content'>
|
||||
<Image src={product.detail_image_url || product.static_image_url || 'https://via.placeholder.com/400x400'} mode='widthFix' className='detail-img' />
|
||||
|
||||
<View className='info-section'>
|
||||
<Text className='title'>{product.name}</Text>
|
||||
<Text className='price'>¥{product.price}</Text>
|
||||
|
||||
<View className='specs'>
|
||||
<View className='spec-item'>
|
||||
<Text className='label'>芯片</Text>
|
||||
<Text className='value'>{product.chip_type}</Text>
|
||||
</View>
|
||||
<View className='spec-item'>
|
||||
<Text className='label'>Flash</Text>
|
||||
<Text className='value'>{product.flash_size}MB</Text>
|
||||
</View>
|
||||
<View className='spec-item'>
|
||||
<Text className='label'>RAM</Text>
|
||||
<Text className='value'>{product.ram_size}MB</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className='desc'>
|
||||
<Text className='section-title'>产品介绍</Text>
|
||||
<Text className='text'>{product.description}</Text>
|
||||
</View>
|
||||
|
||||
{product.features && product.features.map((f, idx) => (
|
||||
<View key={idx} className='feature-item'>
|
||||
<Text className='f-title'>• {f.title}</Text>
|
||||
<Text className='f-desc'>{f.description}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</ScrollView>
|
||||
|
||||
<View className='bottom-bar safe-area-bottom'>
|
||||
<View className='btn-container'>
|
||||
<Button className='btn-cart' onClick={() => Taro.showToast({title: '加入购物车', icon:'none'})}>加入购物车</Button>
|
||||
<Button className='btn-buy' onClick={buyNow}>立即购买</Button>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user