diff --git a/pages/upload/upload.vue b/pages/upload/upload.vue index 6288ce2..126a0cb 100644 --- a/pages/upload/upload.vue +++ b/pages/upload/upload.vue @@ -1343,6 +1343,23 @@ export default { searchFacet(keyword, { phpsessid, dataType: 1 }) ]).then(([productsData, onSaleFacet, soldFacet]) => { this.isLoading = false + + // 检测孔夫子登录过期 + if (productsData.loginRequired || onSaleFacet.loginRequired || soldFacet.loginRequired) { + uni.showModal({ + title: '系统提示', + content: '孔夫子登录已过期,请重新登录', + confirmText: '去登录', + success: (modalRes) => { + if (modalRes.confirm) { + uni.removeStorageSync('kongfz_phpsessid') + uni.navigateTo({ url: '/pages/login/login' }) + } + } + }) + return + } + if (productsData && productsData.total > 0) { // 在售商品列表(最多12条) const list = (productsData.list || []).slice(0, 12) @@ -2564,6 +2581,23 @@ export default { searchFacet(keyword, { phpsessid, dataType: 1 }) ]).then(([productsData, onSaleFacet, soldFacet]) => { this.noIsbnLoading = false + + // 检测孔夫子登录过期 + if (productsData.loginRequired || onSaleFacet.loginRequired || soldFacet.loginRequired) { + uni.showModal({ + title: '系统提示', + content: '孔夫子登录已过期,请重新登录', + confirmText: '去登录', + success: (modalRes) => { + if (modalRes.confirm) { + uni.removeStorageSync('kongfz_phpsessid') + uni.navigateTo({ url: '/pages/login/login' }) + } + } + }) + return + } + // 收集作者和出版社选项 const authorSet = new Set() const publisherSet = new Set() @@ -2649,6 +2683,23 @@ export default { author: this.noIsbnAuthor }).then((productsData) => { this.noIsbnLoading = false + + // 检测孔夫子登录过期 + if (productsData.loginRequired) { + uni.showModal({ + title: '系统提示', + content: '孔夫子登录已过期,请重新登录', + confirmText: '去登录', + success: (modalRes) => { + if (modalRes.confirm) { + uni.removeStorageSync('kongfz_phpsessid') + uni.navigateTo({ url: '/pages/login/login' }) + } + } + }) + return + } + if (productsData && productsData.total > 0) { const list = (productsData.list || []).slice(0, 12) this.noIsbnProductList = list.map(item => { diff --git a/utils/kongfz.js b/utils/kongfz.js index 679879d..4d6f6c6 100644 --- a/utils/kongfz.js +++ b/utils/kongfz.js @@ -113,9 +113,12 @@ export function searchFacet(keyword, options = {}) { } }) const totalFound = parseInt(res.data.data.totalFoundText || res.data.data.matchInfo?.totalFound || 0, 10) - resolve({ newCount, oldCount, totalFound }) + resolve({ newCount, oldCount, totalFound, loginRequired: false }) + } else if (res.data && res.data.errType === '102') { + console.warn('孔夫子统计需要重新登录(errType=102)') + resolve({ newCount: 0, oldCount: 0, totalFound: 0, loginRequired: true }) } else { - resolve({ newCount: 0, oldCount: 0, totalFound: 0 }) + resolve({ newCount: 0, oldCount: 0, totalFound: 0, loginRequired: false }) } }, fail: (err) => { @@ -186,7 +189,7 @@ export function fetchItems(token, params = {}, onProgress) { * 搜索孔夫子在售商品(需要登录Cookie) * @param {string} keyword ISBN或书名 * @param {object} options {phpsessid, page} - * @returns {Promise<{total: number, list: Array}>} + * @returns {Promise<{total: number, list: Array, loginRequired: boolean}>} * list中每项: {id, title, author, press, priceText, imgBigUrl, shopName, qualityText, pubDateText, postage} */ export function searchProducts(keyword, options = {}) { @@ -231,13 +234,18 @@ export function searchProducts(keyword, options = {}) { if (itemResp) { resolve({ total: itemResp.total || 0, - list: itemResp.list || [] + list: itemResp.list || [], + loginRequired: false }) } else { - resolve({ total: 0, list: [] }) + resolve({ total: 0, list: [], loginRequired: false }) } + } else if (res.data && res.data.errType === '102') { + // errType 102 = 需要登录 + console.warn('孔夫子搜索需要重新登录(errType=102)') + resolve({ total: 0, list: [], loginRequired: true }) } else { - resolve({ total: 0, list: [] }) + resolve({ total: 0, list: [], loginRequired: false }) } }, fail: (err) => {