feat:出版社改为根据书名从孔网press/facet接口自动获取
This commit is contained in:
parent
e68122a587
commit
5067a283a6
@ -891,7 +891,7 @@
|
||||
|
||||
<script>
|
||||
import { getWarehouseList, getLocationList, searchBookByIsbn, calculateSign, buildFormBodyWithImages } from '@/utils/api.js'
|
||||
import { login as kongfzLogin, searchProducts, searchFacet, searchCategories } from '@/utils/kongfz.js'
|
||||
import { login as kongfzLogin, searchProducts, searchFacet, searchCategories, searchPresses } from '@/utils/kongfz.js'
|
||||
import { uploadImages } from '@/utils/minio.js'
|
||||
|
||||
export default {
|
||||
@ -1891,22 +1891,31 @@ export default {
|
||||
onNoIsbnBookNameInput() {
|
||||
if (this._noIsbnCategoryTimer) clearTimeout(this._noIsbnCategoryTimer)
|
||||
this._noIsbnCategoryTimer = setTimeout(() => {
|
||||
this.fetchNoIsbnCategories()
|
||||
this.fetchNoIsbnBookData()
|
||||
}, 600)
|
||||
},
|
||||
|
||||
// 从孔网搜索图书分类
|
||||
async fetchNoIsbnCategories() {
|
||||
// 从孔网搜索图书分类和出版社
|
||||
async fetchNoIsbnBookData() {
|
||||
var bookName = (this.noIsbnBookName || '').trim()
|
||||
if (!bookName) return
|
||||
this.noIsbnCategoryLoading = true
|
||||
try {
|
||||
var list = await searchCategories(bookName, {
|
||||
// 并行获取分类和出版社
|
||||
var results = await Promise.all([
|
||||
searchCategories(bookName, {
|
||||
phpsessid: this.kongfzToken || ''
|
||||
}),
|
||||
searchPresses(bookName, {
|
||||
phpsessid: this.kongfzToken || ''
|
||||
})
|
||||
this.noIsbnCategoryList = list
|
||||
if (list.length > 0) {
|
||||
this.noIsbnCategoryNames = list.map(function(item) { return item.showName + '(' + item.showValue + ')' })
|
||||
])
|
||||
var catList = results[0]
|
||||
var pressList = results[1]
|
||||
// 更新分类
|
||||
this.noIsbnCategoryList = catList
|
||||
if (catList.length > 0) {
|
||||
this.noIsbnCategoryNames = catList.map(function(item) { return item.showName + '(' + item.showValue + ')' })
|
||||
this.noIsbnCategoryIndex = 0
|
||||
this.onNoIsbnCategorySelect(0)
|
||||
} else {
|
||||
@ -1914,6 +1923,15 @@ export default {
|
||||
this.noIsbnCategoryIndex = 0
|
||||
this.noIsbnSelectedCategoryValue = ''
|
||||
}
|
||||
// 更新出版社
|
||||
if (pressList.length > 0) {
|
||||
this.noIsbnPublisherOptions = pressList.map(function(item) { return item.showName })
|
||||
// 弹出下拉
|
||||
this.noIsbnPublisherDropdownVisible = true
|
||||
} else {
|
||||
// 没有API结果时回退到历史
|
||||
this.noIsbnPublisherOptions = []
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取孔网分类失败:', e)
|
||||
this.noIsbnCategoryNames = ['获取分类失败']
|
||||
|
||||
@ -308,10 +308,65 @@ export function searchCategories(keyword, options = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取孔网出版社列表(根据书名)
|
||||
* @param {string} keyword 书名
|
||||
* @param {object} options { phpsessid, userArea }
|
||||
* @returns {Promise<Array<{showName:string}>>} 出版社列表
|
||||
*/
|
||||
export function searchPresses(keyword, options = {}) {
|
||||
const { phpsessid = '', userArea = '1006000000' } = options
|
||||
return new Promise((resolve) => {
|
||||
if (!keyword || !keyword.trim()) {
|
||||
resolve([])
|
||||
return
|
||||
}
|
||||
uni.request({
|
||||
url: 'https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/more/press/facet',
|
||||
method: 'GET',
|
||||
data: {
|
||||
requestId: Math.random().toString(36).substring(2, 10),
|
||||
platform: 'web',
|
||||
searchType: 'keyword',
|
||||
dataType: 0,
|
||||
keyword: keyword.trim(),
|
||||
hasStock: 'true',
|
||||
isNewBook: 'false',
|
||||
searchMode: 0,
|
||||
userArea: userArea,
|
||||
page: 1,
|
||||
size: 50,
|
||||
tplParams: '{}',
|
||||
sortType: 0,
|
||||
abGroup: 'B',
|
||||
notSelectSearchMode: 'true',
|
||||
filterType: 'press'
|
||||
},
|
||||
header: {
|
||||
'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : ''
|
||||
},
|
||||
success: (res) => {
|
||||
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 }
|
||||
}))
|
||||
} else {
|
||||
resolve([])
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
resolve([])
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
login,
|
||||
searchFacet,
|
||||
fetchItems,
|
||||
searchProducts,
|
||||
searchCategories
|
||||
searchCategories,
|
||||
searchPresses
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user