This commit is contained in:
@zuopngfei 2025-11-25 17:45:38 +08:00
parent 30d3241536
commit 5de7384ddb
3 changed files with 51 additions and 6 deletions

View File

@ -79,7 +79,7 @@
{{ item.name }} {{ item.name }}
</view> </view>
<view class="sku-description"> <view class="sku-description">
{{ item.description }} {{ item.description.details }}
</view> </view>
<view class="sku-rating"> <view class="sku-rating">
<text class="iconfont icon-xingxing"></text> <text class="iconfont icon-xingxing"></text>
@ -213,6 +213,7 @@
</template> </template>
<script> <script>
import request from '/api/request'; import request from '/api/request';
import { parseDescription } from '/tools/format';
export default { export default {
data() { data() {
return { return {
@ -246,7 +247,10 @@ export default {
page: this.page, page: this.page,
page_size: this.page_size page_size: this.page_size
}).then((res) => { }).then((res) => {
this.shopList = res.list this.shopList = res.list.map(item => {
item.description = parseDescription(item.description)
return item
})
}) })
}, },
async userIsLogin() { async userIsLogin() {

View File

@ -30,6 +30,7 @@
<!-- 商品名称 --> <!-- 商品名称 -->
<view class="product-name">{{ productInfo.name || '玫瑰香水盲盒' }}</view> <view class="product-name">{{ productInfo.name || '玫瑰香水盲盒' }}</view>
<view class="product-sub-title">{{ productInfo.description.sub_title || '玫瑰香水盲盒' }}</view>
<!-- 评分和喜欢 --> <!-- 评分和喜欢 -->
<view class="product-rating"> <view class="product-rating">
<text class="iconfont icon-xingxing star-icon"></text> <text class="iconfont icon-xingxing star-icon"></text>
@ -50,8 +51,9 @@
<!-- 商品描述 --> <!-- 商品描述 -->
<view class="product-description"> <view class="product-description">
{{ productInfo.description || <!-- {{ productInfo.description.details ||
'经典玫瑰香调,优雅女神范,持久留香8小时。采用法国进口玫瑰精油,层次丰富,前调清新,中调浓郁,后调温暖。适合日常使用,也是送礼的绝佳选择。' }} '经典玫瑰香调,优雅女神范,持久留香8小时。采用法国进口玫瑰精油,层次丰富,前调清新,中调浓郁,后调温暖。适合日常使用,也是送礼的绝佳选择。' }} -->
<rich-text :nodes="productInfo.description.details"></rich-text>
</view> </view>
</view> </view>
@ -166,7 +168,8 @@
<view class="detail-section"> <view class="detail-section">
<view class="section-title">使用方法</view> <view class="section-title">使用方法</view>
<view class="ingredients"> <view class="ingredients">
{{ productInfo.usage_instruction || '常温保存' }} <!-- {{ productInfo.usage_instruction || '常温保存' }} -->
<rich-text :nodes="productInfo.usage_instruction"></rich-text>
</view> </view>
</view> </view>
<view class="detail-section"> <view class="detail-section">
@ -264,7 +267,7 @@
<script> <script>
import request from '@/api/request.js'; import request from '@/api/request.js';
import { parseDescription } from '/tools/format';
export default { export default {
data() { data() {
return { return {
@ -389,6 +392,7 @@ export default {
} }
this.productInfo.scent_level = JSON.parse(productInfo.scent_level); this.productInfo.scent_level = JSON.parse(productInfo.scent_level);
this.productInfo.attr = JSON.parse(productInfo.attr); this.productInfo.attr = JSON.parse(productInfo.attr);
this.productInfo.description = parseDescription(productInfo.description);
// SKU // SKU
if (productInfo.skus && Array.isArray(productInfo.skus) && productInfo.skus.length > 0) { if (productInfo.skus && Array.isArray(productInfo.skus) && productInfo.skus.length > 0) {
this.skuList = productInfo.skus; this.skuList = productInfo.skus;
@ -718,6 +722,13 @@ export default {
line-height: 1.4; line-height: 1.4;
} }
.product-sub-title {
font-size: 28rpx;
color: #999;
margin-bottom: 20rpx;
line-height: 1.4;
}
.product-rating { .product-rating {
display: flex; display: flex;
align-items: center; align-items: center;

30
tools/format.js Normal file
View File

@ -0,0 +1,30 @@
export function formatJson(text) {
if (!text) {
return text;
}
if (typeof text === 'string') {
try {
return JSON.stringify(JSON.parse(text), null, 2);
} catch (error) {
return text;
}
}
return text;
}
export function parseDescription(value) {
const fallback = { details: '', sub_title: '' }
if (!value) return { ...fallback }
if (typeof value === 'string') {
try {
const parsed = JSON.parse(value)
if (typeof parsed === 'string') {
return { details: parsed, sub_title: '' }
}
return { ...fallback, ...(parsed || {}) }
} catch (error) {
return { details: value, sub_title: '' }
}
}
return { ...fallback, ...value }
}