feat:无ISBN上传分类改为根据书名从孔网接口获取

This commit is contained in:
ShenQiLun 2026-07-01 13:56:11 +08:00
parent e24d4f81b9
commit 6edc8aeb5b
2 changed files with 104 additions and 145 deletions

View File

@ -265,7 +265,7 @@
<text class="info-inline-label">书名</text> <text class="info-inline-label">书名</text>
<view class="inline-fields" style="flex:1;"> <view class="inline-fields" style="flex:1;">
<view class="inline-field" style="flex:1;"> <view class="inline-field" style="flex:1;">
<input class="form-input" v-model="noIsbnBookName" placeholder="请输入书名" style="flex:1;" /> <input class="form-input" v-model="noIsbnBookName" placeholder="请输入书名" @input="onNoIsbnBookNameInput" style="flex:1;" />
</view> </view>
<view class="inline-field" style="flex:none;"> <view class="inline-field" style="flex:none;">
<view class="search-btn" @click="searchNoIsbn"> <view class="search-btn" @click="searchNoIsbn">
@ -371,19 +371,12 @@
<text class="info-inline-label">图书分类 & 装订</text> <text class="info-inline-label">图书分类 & 装订</text>
<view class="inline-fields" style="flex:1;align-items:stretch;"> <view class="inline-fields" style="flex:1;align-items:stretch;">
<view class="inline-field" style="flex:1;"> <view class="inline-field" style="flex:1;">
<picker v-if="noIsbnCategoryColumns.length > 0" mode="multiSelector" :range="noIsbnCategoryColumns" range-key="name" @columnchange="onNoIsbnCategoryColumnChange" @change="onNoIsbnCategoryChange" :value="noIsbnCategoryIndexes"> <picker @change="onNoIsbnCategoryChange" :value="noIsbnCategoryIndex" :range="noIsbnCategoryNames">
<view class="category-select" style="height:100%;"> <view class="category-select" style="height:100%;">
<text class="category-value">{{ noIsbnCategoryPathText || '请选择分类' }}</text> <text class="category-value">{{ noIsbnCategoryNames[noIsbnCategoryIndex] || '请选择分类' }}</text>
<text class="picker-arrow"></text> <text class="picker-arrow"></text>
</view> </view>
</picker> </picker>
<view v-else-if="noIsbnCategoryLoading" class="category-select" style="height:100%;">
<text class="category-value" style="color:#999;">加载中...</text>
</view>
<view v-else class="category-select" style="height:100%;" @click="loadNoIsbnCategory">
<text class="category-value" style="color:#999;">点击加载分类</text>
<text class="picker-arrow"></text>
</view>
</view> </view>
<view class="inline-field" style="flex:1;"> <view class="inline-field" style="flex:1;">
<view class="dropdown-wrapper" style="flex:1;"> <view class="dropdown-wrapper" style="flex:1;">
@ -898,7 +891,7 @@
<script> <script>
import { getWarehouseList, getLocationList, searchBookByIsbn, calculateSign, buildFormBodyWithImages } from '@/utils/api.js' import { getWarehouseList, getLocationList, searchBookByIsbn, calculateSign, buildFormBodyWithImages } from '@/utils/api.js'
import { login as kongfzLogin, searchProducts, searchFacet } from '@/utils/kongfz.js' import { login as kongfzLogin, searchProducts, searchFacet, searchCategories } from '@/utils/kongfz.js'
import { uploadImages } from '@/utils/minio.js' import { uploadImages } from '@/utils/minio.js'
export default { export default {
@ -969,15 +962,13 @@ export default {
noIsbnBookPopupVisible: false, noIsbnBookPopupVisible: false,
noIsbnBookList: [], noIsbnBookList: [],
// API //
noIsbnCategoryData: [], noIsbnCategoryList: [],
noIsbnCategoryColumns: [], noIsbnCategoryNames: ['请输入书名后自动获取分类'],
noIsbnCategoryIndexes: [], noIsbnCategoryIndex: 0,
noIsbnCategoryLevels: [],
noIsbnMaxCategoryLevel: 3,
noIsbnCategoryPathText: '',
noIsbnCategoryLoading: false, noIsbnCategoryLoading: false,
noIsbnSelectedCategoryId: '', noIsbnSelectedCategoryValue: '',
_noIsbnCategoryTimer: null,
// ISBN - / // ISBN - /
noIsbnProductList: [], noIsbnProductList: [],
@ -1069,8 +1060,6 @@ export default {
this.loadSavedAccounts() this.loadSavedAccounts()
// //
this.loadPriceConfig() this.loadPriceConfig()
//
this.loadNoIsbnCategory()
// //
this.syncNoIsbnPrintTimeIndexes() this.syncNoIsbnPrintTimeIndexes()
// //
@ -1898,137 +1887,52 @@ export default {
// //
// ISBN - // ISBN -
onNoIsbnCategoryColumnChange(e) { //
const { column, value } = e.detail onNoIsbnBookNameInput() {
this.noIsbnCategoryIndexes[column] = value if (this._noIsbnCategoryTimer) clearTimeout(this._noIsbnCategoryTimer)
this.noIsbnCategoryLevels[column] = this.noIsbnCategoryColumns[column][value] this._noIsbnCategoryTimer = setTimeout(() => {
if (column < this.noIsbnMaxCategoryLevel - 1) { this.fetchNoIsbnCategories()
this.updateNoIsbnSubsequentColumns(column + 1) }, 600)
}
this.updateNoIsbnCategoryPathText()
}, },
// ISBN - //
onNoIsbnCategoryChange(e) { async fetchNoIsbnCategories() {
const values = e.detail.value var bookName = (this.noIsbnBookName || '').trim()
this.noIsbnCategoryIndexes = [...values] if (!bookName) return
for (let i = 0; i < values.length; i++) {
if (this.noIsbnCategoryColumns[i] && this.noIsbnCategoryColumns[i][values[i]]) {
this.noIsbnCategoryLevels[i] = this.noIsbnCategoryColumns[i][values[i]]
}
}
this.updateNoIsbnCategoryPathText()
this.updateNoIsbnSelectedCategoryId()
},
updateNoIsbnSubsequentColumns(startColumn) {
const parentCategory = this.noIsbnCategoryLevels[startColumn - 1]
if (!parentCategory || !parentCategory.children || parentCategory.children.length === 0) {
for (let i = startColumn; i < this.noIsbnMaxCategoryLevel; i++) {
this.noIsbnCategoryColumns[i] = [{ name: '暂无数据', id: '' }]
this.noIsbnCategoryIndexes[i] = 0
this.noIsbnCategoryLevels[i] = { name: '暂无数据', id: '' }
}
return
}
this.noIsbnCategoryColumns[startColumn] = parentCategory.children
this.noIsbnCategoryIndexes[startColumn] = 0
this.noIsbnCategoryLevels[startColumn] = parentCategory.children[0]
if (startColumn < this.noIsbnMaxCategoryLevel - 1) {
this.updateNoIsbnSubsequentColumns(startColumn + 1)
}
},
updateNoIsbnCategoryPathText() {
const validLevels = this.noIsbnCategoryLevels.filter(level => level && level.name && level.name !== '暂无数据')
this.noIsbnCategoryPathText = validLevels.map(level => level.name).join(' / ')
},
updateNoIsbnSelectedCategoryId() {
const validLevels = this.noIsbnCategoryLevels.filter(level => level && level.id && level.id !== '')
this.noIsbnSelectedCategoryId = validLevels.length > 0 ? validLevels[validLevels.length - 1].id : ''
},
// API
loadNoIsbnCategory() {
this.noIsbnCategoryLoading = true this.noIsbnCategoryLoading = true
const cookies = uni.getStorageSync('cookies') || this.kongfzToken || '' try {
uni.request({ var list = await searchCategories(bookName, {
url: 'https://api.buzhiyushu.cn/api/kongfz/getCategory', phpsessid: this.kongfzToken || ''
method: 'GET', })
data: { token: cookies }, this.noIsbnCategoryList = list
header: { 'Content-Type': 'application/json' }, if (list.length > 0) {
success: (res) => { this.noIsbnCategoryNames = list.map(function(item) { return item.showName })
const responseData = res.data this.noIsbnCategoryIndex = 0
if (responseData && responseData.successResponse) { this.onNoIsbnCategorySelect(0)
this.noIsbnCategoryData = responseData.successResponse } else {
this.initNoIsbnCategoryPicker() this.noIsbnCategoryNames = ['未获取到分类']
} else { this.noIsbnCategoryIndex = 0
console.error('获取分类数据失败:', responseData) this.noIsbnSelectedCategoryValue = ''
// 使
this.loadDefaultNoIsbnCategory()
}
},
fail: (err) => {
console.error('获取分类数据异常:', err)
this.loadDefaultNoIsbnCategory()
},
complete: () => {
this.noIsbnCategoryLoading = false
} }
}) } catch (e) {
console.error('获取孔网分类失败:', e)
this.noIsbnCategoryNames = ['获取分类失败']
this.noIsbnCategoryIndex = 0
} finally {
this.noIsbnCategoryLoading = false
}
}, },
loadDefaultNoIsbnCategory() { //
const defaultCategories = [ onNoIsbnCategoryChange(e) {
{ name: '文学', id: '1', level: 1, children: [{ name: '中国文学', id: '11', level: 2, children: [] }] }, var index = e.detail.value
{ name: '艺术', id: '2', level: 1, children: [] }, this.onNoIsbnCategorySelect(index)
{ name: '历史', id: '3', level: 1, children: [] },
{ name: '哲学', id: '4', level: 1, children: [] },
{ name: '科学', id: '5', level: 1, children: [] },
{ name: '技术', id: '6', level: 1, children: [] },
{ name: '教育', id: '7', level: 1, children: [] },
{ name: '经济', id: '8', level: 1, children: [] },
{ name: '政治', id: '9', level: 1, children: [] },
{ name: '军事', id: '10', level: 1, children: [] },
{ name: '法律', id: '11', level: 1, children: [] },
{ name: '社会', id: '12', level: 1, children: [] },
{ name: '文化', id: '13', level: 1, children: [] },
{ name: '语言', id: '14', level: 1, children: [] },
{ name: '工具书', id: '15', level: 1, children: [] },
{ name: '其他', id: '16', level: 1, children: [] }
]
this.noIsbnCategoryData = defaultCategories
this.initNoIsbnCategoryPicker()
}, },
initNoIsbnCategoryPicker() { onNoIsbnCategorySelect(index) {
this.noIsbnCategoryColumns = [] this.noIsbnCategoryIndex = index
this.noIsbnCategoryLevels = [] var item = this.noIsbnCategoryList[index]
this.noIsbnCategoryIndexes = [] this.noIsbnSelectedCategoryValue = item ? item.value : ''
const level1Categories = (this.noIsbnCategoryData || []).filter(item => item.level === 1)
if (level1Categories.length === 0) return
this.noIsbnCategoryColumns[0] = level1Categories
this.noIsbnCategoryIndexes[0] = 0
let currentParent = level1Categories[0]
let currentLevel = 1
this.noIsbnCategoryLevels[0] = currentParent
while (currentLevel < this.noIsbnMaxCategoryLevel) {
const children = currentParent.children || []
if (children.length === 0) break
this.noIsbnCategoryColumns[currentLevel] = children
this.noIsbnCategoryIndexes[currentLevel] = 0
this.noIsbnCategoryLevels[currentLevel] = children[0]
currentParent = children[0]
currentLevel++
}
while (this.noIsbnCategoryColumns.length < this.noIsbnMaxCategoryLevel) {
this.noIsbnCategoryColumns.push([{ name: '暂无数据', id: '' }])
this.noIsbnCategoryIndexes.push(0)
this.noIsbnCategoryLevels.push({ name: '暂无数据', id: '' })
}
this.updateNoIsbnCategoryPathText()
this.updateNoIsbnSelectedCategoryId()
}, },
// - // -

View File

@ -254,9 +254,64 @@ export function searchProducts(keyword, options = {}) {
}) })
} }
/**
* 获取孔网图书分类根据书名搜索孔网 facet 接口
* @param {string} keyword 书名
* @param {object} options { phpsessid, userArea }
* @returns {Promise<Array<{value:string, showName:string}>>} 图书分类列表normal组
*/
export function searchCategories(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/normal/facet',
method: 'GET',
data: {
dataType: 0,
keyword: keyword.trim(),
page: 1,
userArea: userArea
},
header: {
'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : ''
},
success: (res) => {
if (res.statusCode === 200 && res.data && res.data.status === 1 && res.data.data) {
var categories = res.data.data.categories || []
// 找到 normal 组(图书分类)
var normalGroup = null
for (var i = 0; i < categories.length; i++) {
if (categories[i].type === 'GROUP' && categories[i].name === 'normal') {
normalGroup = categories[i]
break
}
}
if (normalGroup && normalGroup.subLabels) {
resolve(normalGroup.subLabels.map(function(item) {
return { value: item.value, showName: item.showName }
}))
} else {
resolve([])
}
} else {
resolve([])
}
},
fail: () => {
resolve([])
}
})
})
}
export default { export default {
login, login,
searchFacet, searchFacet,
fetchItems, fetchItems,
searchProducts searchProducts,
searchCategories
} }