修复孔夫子搜索接口: keyword/list + PHPSESSID + 正确字段映射(与zhizhu一致)
This commit is contained in:
parent
bc4f43756c
commit
a5bb2e3b9b
@ -210,10 +210,13 @@
|
|||||||
<!-- 商品列表 -->
|
<!-- 商品列表 -->
|
||||||
<view class="product-grid" v-else>
|
<view class="product-grid" v-else>
|
||||||
<view class="grid-item" v-for="(item, index) in sortedProductList.slice(0, 12)" :key="index">
|
<view class="grid-item" v-for="(item, index) in sortedProductList.slice(0, 12)" :key="index">
|
||||||
|
<image class="grid-image" :src="item.image" mode="aspectFill" @click="previewProductImage(index)" v-if="item.image"></image>
|
||||||
<text class="grid-book-name">{{ item.bookName || '未知书名' }}</text>
|
<text class="grid-book-name">{{ item.bookName || '未知书名' }}</text>
|
||||||
<text class="grid-author">{{ item.author || item.shopName || '' }}</text>
|
<text class="grid-author">{{ item.author || item.shopName || '' }}</text>
|
||||||
<text class="grid-total-price">{{ item.totalPrice }}</text>
|
<text class="grid-total-price">{{ item.totalPrice }}</text>
|
||||||
<text class="grid-condition">{{ item.condition || item.pubDate || '' }}</text>
|
<text class="grid-price-detail" v-if="item.shippingFee && item.shippingFee > 0">运{{ item.shippingFee }}</text>
|
||||||
|
<text class="grid-condition">{{ item.condition || '' }}</text>
|
||||||
|
<text class="grid-shop">{{ item.shopName || '' }}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 无数据提示 -->
|
<!-- 无数据提示 -->
|
||||||
@ -934,7 +937,8 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 2. 搜索孔夫子 - 获取在售商品信息
|
// 2. 搜索孔夫子 - 获取在售商品信息
|
||||||
searchProducts(this.isbn).then(data => {
|
const phpsessid = this.kongfzToken || uni.getStorageSync('kongfz_phpsessid') || ''
|
||||||
|
searchProducts(this.isbn, { phpsessid }).then(data => {
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
if (data && data.total > 0) {
|
if (data && data.total > 0) {
|
||||||
// 市场统计
|
// 市场统计
|
||||||
@ -947,16 +951,16 @@ export default {
|
|||||||
// 在售商品列表(最多12条)
|
// 在售商品列表(最多12条)
|
||||||
const list = (data.list || []).slice(0, 12)
|
const list = (data.list || []).slice(0, 12)
|
||||||
this.productList = list.map(item => ({
|
this.productList = list.map(item => ({
|
||||||
image: '',
|
image: item.imgBigUrl || '',
|
||||||
totalPrice: item.prodNum + '本在售',
|
totalPrice: item.priceText || '',
|
||||||
bookPrice: '',
|
bookPrice: (item.priceText || '0').replace(/[^\d.]/g, ''),
|
||||||
shippingFee: '',
|
shippingFee: item.postage && item.postage.shippingList && item.postage.shippingList.length > 0 ? item.postage.shippingList[0].shippingFee || '0' : '0',
|
||||||
condition: item.binding || '',
|
condition: item.qualityText || '',
|
||||||
shopName: item.press || '',
|
shopName: item.shopName || '',
|
||||||
bookName: item.bookName || '',
|
bookName: item.title || '',
|
||||||
author: item.author || '',
|
author: item.author || '',
|
||||||
pubDate: item.pubDate || '',
|
pubDate: item.pubDateText || '',
|
||||||
bookId: item.bookId || ''
|
bookId: item.id || ''
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
this.marketData = { onSale: 0, old: 0, new: 0, sold: 0 }
|
this.marketData = { onSale: 0, old: 0, new: 0, sold: 0 }
|
||||||
@ -1870,6 +1874,13 @@ export default {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.grid-price-detail {
|
||||||
|
font-size: 18rpx;
|
||||||
|
color: #909399;
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.grid-book-name {
|
.grid-book-name {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #303133;
|
color: #303133;
|
||||||
|
|||||||
@ -146,30 +146,39 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索孔夫子商品(公开搜索API,无需登录)
|
* 搜索孔夫子在售商品(需要登录Cookie)
|
||||||
* @param {string} keyword ISBN或书名
|
* @param {string} keyword ISBN或书名
|
||||||
* @param {number} page 页码
|
* @param {object} options {phpsessid, page}
|
||||||
* @returns {Promise<{total: number, list: Array}>}
|
* @returns {Promise<{total: number, list: Array}>}
|
||||||
|
* list中每项: {id, title, author, press, priceText, imgBigUrl, shopName, qualityText, pubDateText, postage}
|
||||||
*/
|
*/
|
||||||
export function searchProducts(keyword, page = 1) {
|
export function searchProducts(keyword, options = {}) {
|
||||||
|
const { phpsessid = '', page = 1 } = options
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.request({
|
uni.request({
|
||||||
url: `https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/isbnList?dataType=0&keyword=${encodeURIComponent(keyword)}&page=${page}`,
|
url: 'https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/list',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
dataType: 0,
|
||||||
|
keyword: keyword,
|
||||||
|
page: page,
|
||||||
|
userArea: '13003000000'
|
||||||
|
},
|
||||||
header: {
|
header: {
|
||||||
'Accept': 'application/json, text/plain, */*',
|
'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : ''
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36',
|
|
||||||
'Referer': `https://search.kongfz.com/product/?keyword=${encodeURIComponent(keyword)}`,
|
|
||||||
'sec-ch-ua': '"Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"',
|
|
||||||
'sec-ch-ua-mobile': '?0',
|
|
||||||
'sec-ch-ua-platform': '"Windows"'
|
|
||||||
},
|
},
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('孔夫子搜索响应:', res.statusCode, res.data)
|
console.log('孔夫子在售搜索响应:', res.statusCode, res.data)
|
||||||
if (res.statusCode === 200 && res.data && res.data.status === 1 && res.data.data) {
|
if (res.statusCode === 200 && res.data && res.data.status === 1) {
|
||||||
resolve(res.data.data)
|
const itemResp = res.data.data && res.data.data.itemResponse
|
||||||
} else if (res.statusCode === 200 && res.data && res.data.data) {
|
if (itemResp) {
|
||||||
resolve(res.data.data)
|
resolve({
|
||||||
|
total: itemResp.total || 0,
|
||||||
|
list: itemResp.list || []
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
resolve({ total: 0, list: [] })
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve({ total: 0, list: [] })
|
resolve({ total: 0, list: [] })
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user