feat:分类接口支持传author/press/pressNum过滤
This commit is contained in:
parent
36845e6657
commit
b5d4a54340
@ -970,6 +970,7 @@ export default {
|
||||
noIsbnCategoryIndex: 0,
|
||||
noIsbnCategoryLoading: false,
|
||||
noIsbnSelectedCategoryValue: '',
|
||||
noIsbnSelectedPublisherValue: '',
|
||||
_noIsbnCategoryTimer: null,
|
||||
_reSearchTimer: null,
|
||||
|
||||
@ -1905,16 +1906,22 @@ export default {
|
||||
this.noIsbnCategoryLoading = true
|
||||
try {
|
||||
// 并行获取分类、出版社、作者
|
||||
var catOpts = { phpsessid: this.kongfzToken || '' }
|
||||
var pressOpts = { phpsessid: this.kongfzToken || '' }
|
||||
var authorOpts = { phpsessid: this.kongfzToken || '' }
|
||||
// 如果当前已填了作者,查询出版社时带上作者过滤
|
||||
if (this.noIsbnAuthor) pressOpts.author = this.noIsbnAuthor
|
||||
// 如果当前已填了出版社,查询作者时带上市出版社过滤
|
||||
if (this.noIsbnPublisher) authorOpts.publisher = this.noIsbnPublisher
|
||||
// 如果当前已填了作者,查询分类和出版社时带上作者过滤
|
||||
if (this.noIsbnAuthor) {
|
||||
catOpts.author = this.noIsbnAuthor
|
||||
pressOpts.author = this.noIsbnAuthor
|
||||
}
|
||||
// 如果当前已填了出版社,查询分类和作者时带上市出版社过滤
|
||||
if (this.noIsbnPublisher) {
|
||||
catOpts.press = this.noIsbnPublisher
|
||||
catOpts.pressNum = this.noIsbnSelectedPublisherValue
|
||||
authorOpts.publisher = this.noIsbnPublisher
|
||||
}
|
||||
var results = await Promise.all([
|
||||
searchCategories(bookName, {
|
||||
phpsessid: this.kongfzToken || ''
|
||||
}),
|
||||
searchCategories(bookName, catOpts),
|
||||
searchPresses(bookName, pressOpts),
|
||||
searchAuthors(bookName, authorOpts)
|
||||
])
|
||||
@ -3499,6 +3506,7 @@ export default {
|
||||
// 无ISBN - 选择出版社
|
||||
selectNoIsbnPublisher(item) {
|
||||
this.noIsbnPublisher = typeof item === 'string' ? item : (item.showName || '')
|
||||
this.noIsbnSelectedPublisherValue = typeof item === 'object' && item.value ? item.value : ''
|
||||
this.noIsbnPublisherDropdownVisible = false
|
||||
// 选择出版社后:一次获取出版社/分类/作者(全部) + 重搜在售商品
|
||||
this.fetchNoIsbnBookData()
|
||||
|
||||
@ -255,32 +255,55 @@ export function searchProducts(keyword, options = {}) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取孔网图书分类(根据书名搜索孔网 facet 接口)
|
||||
* 获取孔网图书分类(根据书名搜索孔网 facet 接口,可选带作者/出版社过滤)
|
||||
* @param {string} keyword 书名
|
||||
* @param {object} options { phpsessid, userArea }
|
||||
* @returns {Promise<Array<{value:string, showName:string}>>} 图书分类列表(normal组)
|
||||
* @param {object} options { phpsessid, userArea, author, press, pressNum }
|
||||
* @returns {Promise<Array<{value:string, showName:string, showValue:string}>>} 图书分类列表(normal组)
|
||||
*/
|
||||
export function searchCategories(keyword, options = {}) {
|
||||
const { phpsessid = '', userArea = '1006000000' } = options
|
||||
const { phpsessid = '', userArea = '1006000000', author = '', press = '', pressNum = '' } = options
|
||||
return new Promise((resolve) => {
|
||||
if (!keyword || !keyword.trim()) {
|
||||
resolve([])
|
||||
return
|
||||
}
|
||||
var reqData = {
|
||||
requestId: Math.random().toString(36).substring(2, 10),
|
||||
platform: 'web',
|
||||
searchType: 'keyword',
|
||||
dataType: 0,
|
||||
keyword: keyword.trim(),
|
||||
hasStock: 'true',
|
||||
isNewBook: 'false',
|
||||
userArea: userArea,
|
||||
abGroup: 'B',
|
||||
notSelectSearchMode: 'true',
|
||||
page: 1
|
||||
}
|
||||
var actionPathParts = []
|
||||
if (author) {
|
||||
reqData.author = author
|
||||
actionPathParts.push('author')
|
||||
}
|
||||
if (press) {
|
||||
reqData.press = press
|
||||
if (pressNum) {
|
||||
reqData.tplParams = JSON.stringify({ pressNum: pressNum })
|
||||
}
|
||||
actionPathParts.push('press')
|
||||
}
|
||||
if (actionPathParts.length > 0) {
|
||||
reqData.actionPath = actionPathParts.join(',')
|
||||
}
|
||||
uni.request({
|
||||
url: 'https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/normal/facet',
|
||||
method: 'GET',
|
||||
data: {
|
||||
dataType: 0,
|
||||
keyword: keyword.trim(),
|
||||
page: 1,
|
||||
userArea: userArea
|
||||
},
|
||||
data: reqData,
|
||||
header: {
|
||||
'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : ''
|
||||
},
|
||||
success: (res) => {
|
||||
console.log('【孔网分类搜索】URL: https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/normal/facet?dataType=0&keyword=' + encodeURIComponent(keyword) + '&page=1&userArea=' + userArea, '| 响应:', JSON.stringify(res.data))
|
||||
console.log('【孔网分类搜索】keyword:', keyword, '| author:', author, '| press:', press, '| 响应:', JSON.stringify(res.data))
|
||||
if (res.statusCode === 200 && res.data && res.data.status === 1 && res.data.data) {
|
||||
var categories = res.data.data.categories || []
|
||||
// 找到 normal 组(图书分类)
|
||||
@ -313,7 +336,7 @@ export function searchCategories(keyword, options = {}) {
|
||||
* 获取孔网出版社列表(根据书名,可选按作者过滤)
|
||||
* @param {string} keyword 书名
|
||||
* @param {object} options { phpsessid, userArea, author }
|
||||
* @returns {Promise<Array<{showName:string, showValue:string}>>} 出版社列表
|
||||
* @returns {Promise<Array<{showName:string, showValue:string, value:string}>>} 出版社列表
|
||||
*/
|
||||
export function searchPresses(keyword, options = {}) {
|
||||
const { phpsessid = '', userArea = '1006000000', author = '' } = options
|
||||
@ -358,7 +381,7 @@ export function searchPresses(keyword, options = {}) {
|
||||
if (res.statusCode === 200 && res.data && res.data.status === 1 && res.data.data) {
|
||||
var labels = res.data.data.labels || []
|
||||
resolve(labels.map(function(item) {
|
||||
return { showName: item.showName, showValue: item.showValue }
|
||||
return { showName: item.showName, showValue: item.showValue, value: item.value }
|
||||
}))
|
||||
} else {
|
||||
resolve([])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user