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

View File

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