Compare commits

..

10 Commits

4 changed files with 264 additions and 22 deletions

28
App.vue
View File

@ -1,7 +1,35 @@
<script>
// #ifdef APP-PLUS
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
// #endif
export default {
onLaunch: function() {
console.log('App Launch')
// API
uni.addInterceptor('request', {
success: function(res) {
if (res.data && typeof res.data === 'string') {
try {
var obj = JSON.parse(res.data)
if (obj && obj.error === '无效的认证令牌') {
uni.removeStorageSync('token')
uni.reLaunch({ url: '/pages/login/login' })
}
} catch (e) {}
} else if (res.data && res.data.error === '无效的认证令牌') {
uni.removeStorageSync('token')
uni.reLaunch({ url: '/pages/login/login' })
}
}
})
// #ifdef APP-PLUS
// onLaunch
console.log('[Upgrade] 开始检测更新...');
checkUpdate();
// #endif
},
onShow: function() {
console.log('App Show')

View File

@ -8,13 +8,13 @@
<!-- Logo区域 -->
<view class="logo-area" v-if="!isCheckingLogin">
<image class="logo" src="/static/logo.png" mode="aspectFit"></image>
<text class="app-name">扫码图</text>
<text class="app-name">海寻源-入库</text>
</view>
<!-- 登录表单 -->
<view class="login-form" v-if="!isCheckingLogin">
<!-- 账号输入 -->
<view class="form-item">
<view class="form-item" style="position:relative;">
<view class="icon-box">
<view class="icon-user-head"></view>
<view class="icon-user-body"></view>
@ -25,7 +25,21 @@
v-model="formData.account"
placeholder="请输入账号"
maxlength="20"
@focus="showAccountList = true"
@blur="onAccountBlur"
/>
<!-- 历史账号下拉 -->
<view class="account-dropdown" v-if="showAccountList && savedAccountList.length > 0">
<view
class="account-item"
v-for="(item, index) in savedAccountList"
:key="index"
@mousedown.prevent="selectSavedAccount(item)"
>
<text class="account-text">{{ item.account }}</text>
<text class="account-delete" @mousedown.stop @click.stop="deleteSavedAccount(index)"></text>
</view>
</view>
</view>
<!-- 密码输入 -->
@ -161,7 +175,9 @@ export default {
agreed: false
},
showPassword: false,
showModal: false
showModal: false,
showAccountList: false,
savedAccountList: []
}
},
@ -184,6 +200,7 @@ export default {
this.isCheckingLogin = false
//
this.loadRememberedCredentials()
this.loadSavedAccounts()
},
methods: {
@ -262,6 +279,9 @@ export default {
icon: 'success'
})
//
this.saveAccountToList(this.formData.account, this.formData.password)
//
setTimeout(() => {
uni.redirectTo({
@ -308,6 +328,63 @@ export default {
this.formData.password = uni.getStorageSync('remembered_password') || ''
this.formData.remember = true
}
},
//
loadSavedAccounts() {
try {
const list = uni.getStorageSync('saved_account_list')
this.savedAccountList = Array.isArray(list) ? list : []
} catch (e) {
this.savedAccountList = []
}
},
// 5
saveAccountToList(account, password) {
var list = [...this.savedAccountList]
//
var exists = false
for (var i = 0; i < list.length; i++) {
if (list[i].account === account) {
list[i].password = password
exists = true
break
}
}
if (!exists) {
list.unshift({ account: account, password: password })
if (list.length > 5) {
list = list.slice(0, 5)
}
}
this.savedAccountList = list
uni.setStorageSync('saved_account_list', list)
},
//
selectSavedAccount(item) {
this.formData.account = item.account
this.formData.password = item.password
this.formData.remember = true
this.showAccountList = false
},
//
deleteSavedAccount(index) {
var list = [...this.savedAccountList]
list.splice(index, 1)
this.savedAccountList = list
uni.setStorageSync('saved_account_list', list)
},
//
onAccountBlur() {
//
var that = this
setTimeout(function() {
that.showAccountList = false
}, 150)
}
}
}
@ -671,4 +748,50 @@ export default {
font-size: 28rpx;
border: none;
}
/* 历史账号下拉 */
.account-dropdown {
position: absolute;
top: 100%;
left: 0;
right: 0;
background: #ffffff;
border: 1rpx solid #e5e6eb;
border-radius: 8rpx;
box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.1);
z-index: 10;
max-height: 300rpx;
overflow-y: auto;
}
.account-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 24rpx;
border-bottom: 1rpx solid #f2f3f5;
}
.account-item:last-child {
border-bottom: none;
}
.account-text {
font-size: 28rpx;
color: #1d2129;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.account-delete {
font-size: 24rpx;
color: #c0c4cc;
padding: 8rpx 4rpx 8rpx 16rpx;
}
.account-delete:active {
color: #f56c6c;
}
</style>

View File

@ -890,7 +890,7 @@
</template>
<script>
import { getWarehouseList, getLocationList, searchBookByIsbn, calculateSign } 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 { uploadImages } from '@/utils/minio.js'
@ -2066,7 +2066,7 @@ export default {
uni.showLoading({ title: '上传图片中...', mask: true })
try {
const photoList = this.currentTab === 'isbn' ? this.photoList : this.noIsbnPhotoList
const typeDir = this.currentTab === 'isbn' ? (this.isbn || 'UnknownIsbn') : this.noIsbnIsbn || this.noIsbnUnifyIsbn || 'NoIsbn'
const typeDir = this.currentTab === 'isbn' ? (this.isbn || 'UnknownIsbn') : this.getNoIsbnIsbnValue()
const imageUrls = await uploadImages(photoList, typeDir)
console.log('【上传】MinIO图片URL列表:', imageUrls)
@ -2095,7 +2095,9 @@ export default {
var pubTimeStr = this.printTime || ''
var pubTimestamp = '0'
if (pubTimeStr) {
var parts = pubTimeStr.split('-')
// '1980/03' '1980-03'
var normalized = pubTimeStr.replace(/\//g, '-')
var parts = normalized.split('-')
if (parts.length >= 2) {
var d = new Date(parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, 1)
var ts = Math.floor(d.getTime() / 1000)
@ -2120,14 +2122,14 @@ export default {
page_count: '0',
word_count: '',
book_format: '',
'live_image[]': imageUrls.join(','),
'live_image': imageUrls.join(','),
timestamp: timestamp,
sign_method: 'md5'
}
var sign = calculateSign(params)
params.sign = sign
var formBody = buildFormBodyWithImages(params, imageUrls, 'live_image')
const apiUrl = 'https://psi.api.buzhiyushu.cn/api/syncBook'
const token = uni.getStorageSync('token') || ''
console.log('【syncBook】请求地址:', apiUrl)
@ -2141,7 +2143,7 @@ export default {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ' + token
},
data: params,
data: formBody,
success: function (r) { resolve(r) },
fail: function (e) { reject(e) }
})
@ -2168,7 +2170,7 @@ export default {
// syncBook product ID
var syncData = respData.data || {}
var bookInfoId = syncData.id || ''
var barcode = this.currentTab === 'isbn' ? (this.isbn || '') : (this.noIsbnIsbn || this.noIsbnUnifyIsbn || '')
var barcode = this.currentTab === 'isbn' ? (this.isbn || '') : this.getNoIsbnIsbnValue()
var productName = this.currentTab === 'isbn' ? (this.bookName || '') : (this.noIsbnBookName || '')
var appearanceValue = parseInt(this.currentTab === 'isbn' ? this.conditionValue : this.noIsbnConditionValue) || 0
var productPrice = this.currentTab === 'isbn'
@ -2237,7 +2239,9 @@ export default {
var pubTimeStr = this.noIsbnPrintTime || ''
var pubTimestamp = '0'
if (pubTimeStr) {
var parts = pubTimeStr.split('-')
// '1980/03' '1980-03'
var normalized = pubTimeStr.replace(/\//g, '-')
var parts = normalized.split('-')
if (parts.length >= 2) {
var d = new Date(parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, 1)
var ts = Math.floor(d.getTime() / 1000)
@ -2250,7 +2254,7 @@ export default {
client_id: 'psi',
fid: '0',
type: '4',
isbn: this.noIsbnIsbn || this.noIsbnUnifyIsbn || '',
isbn: this.getNoIsbnIsbnValue(),
f_isbn: '0',
book_name: this.noIsbnBookName || '',
f_book_name: '',
@ -2262,7 +2266,7 @@ export default {
page_count: '0',
word_count: this.noIsbnWordCount || '',
book_format: '',
'live_image[]': imageUrls.join(','),
'live_image': imageUrls.join(','),
cat_id: JSON.stringify({
xian_yu_cat_id: '',
kong_fu_zi_cat_id: (this.noIsbnCategoryPathText || '').replace(/ \/ /g, '/'),
@ -2275,6 +2279,7 @@ export default {
//
var sign = calculateSign(params)
params.sign = sign
var formBody = buildFormBodyWithImages(params, imageUrls, 'live_image')
const apiUrl = 'https://psi.api.buzhiyushu.cn/api/syncBook'
console.log('【syncBook】请求地址:', apiUrl)
@ -2288,7 +2293,7 @@ export default {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ' + token
},
data: params,
data: formBody,
success: function (r) { resolve(r) },
fail: function (e) { reject(e) }
})
@ -2315,7 +2320,7 @@ export default {
// syncBook product ID
var syncData = respData.data || {}
var barcode = this.noIsbnIsbn || this.noIsbnUnifyIsbn || ''
var barcode = this.getNoIsbnIsbnValue()
var productName = this.noIsbnBookName || ''
var appearanceValue = parseInt(this.noIsbnConditionValue) || 0
var productPrice = this.noIsbnOriginalPrice ? String(Math.round(parseFloat(this.noIsbnOriginalPrice) * 100)) : '0'
@ -2386,6 +2391,8 @@ export default {
}
var sign = calculateSign(params)
params.sign = sign
// form bodylive_image[] URL product/save live_image[]
var formBody = buildFormBodyWithImages(params, imageUrls, 'live_image[]')
var saveUrl = 'https://psi.api.buzhiyushu.cn/api/product/save'
console.log('【保存商品】请求地址:', saveUrl)
console.log('【保存商品】请求参数:', params)
@ -2399,7 +2406,7 @@ export default {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ' + token
},
data: params,
data: formBody,
success: function (r) { resolve(r) },
fail: function (e) { reject(e) }
})
@ -3119,6 +3126,7 @@ export default {
uni.hideLoading()
try {
const ocrData = JSON.parse(res.data)
console.log('【OCR】原始返回:', JSON.stringify(ocrData))
if (ocrData && ocrData.texts) {
const texts = ocrData.texts
//
@ -3133,12 +3141,16 @@ export default {
const fmt = String(texts.开本).replace('开', '').trim()
this.noIsbnFormat = this.noIsbnFormatOptions.includes(fmt) ? fmt : fmt + '开'
}
if (texts.ISBN && /^\d/.test(texts.ISBN)) {
this.noIsbnIsbn = texts.ISBN
// ISBNOCR
var isbnText = texts.ISBN || texts.isbn || texts.isbn13 || texts.barcode || texts.条码 || ''
if (isbnText && /^\d/.test(isbnText)) {
this.noIsbnIsbn = isbnText
this.noIsbnUnifyIsbn = ''
}
if (texts.书号) {
const bookCode = texts.书号.replace(/\D/g, '')
// OCR
var bookCodeText = texts.书号 || texts.统一书号 || texts.bookcode || texts.unified_code || ''
if (bookCodeText) {
const bookCode = bookCodeText.replace(/\D/g, '')
if (bookCode.length === 13) {
this.noIsbnIsbn = bookCode
} else if (bookCode.length === 10 && /^\d{9}[\dXx]$/i.test(bookCode)) {
@ -3146,7 +3158,11 @@ export default {
} else {
this.noIsbnIsbn = '678' + String(Date.now()).slice(-10)
}
this.noIsbnUnifyIsbn = texts.书号
this.noIsbnUnifyIsbn = bookCodeText
}
// ISBN 678
if (!this.noIsbnIsbn && !this.noIsbnUnifyIsbn) {
this.noIsbnIsbn = this.generateRandomIsbn()
}
if (texts.字数) this.noIsbnWordCount = this.processNoIsbnWordage(texts.字数)
@ -3345,6 +3361,52 @@ export default {
}
},
// ISBN - ISBN
getNoIsbnIsbnValue() {
var raw = (this.noIsbnIsbn || '').replace(/[^0-9]/g, '')
// 1. 13978/979
if (raw.length === 13 && (raw.indexOf('978') === 0 || raw.indexOf('979') === 0)) {
return raw
}
// 2. 10 13
if (raw.length === 10) {
return this.convertIsbn10To13(raw)
}
// 3.
if (this.noIsbnUnifyIsbn) return this.noIsbnUnifyIsbn
// 4. 67813
return this.generateRandomIsbn()
},
// 10ISBN13
convertIsbn10To13(isbn10) {
var prefix = '978'
var first9 = isbn10.substring(0, 9)
var base12 = prefix + first9
// 13
var sum = 0
for (var i = 0; i < 12; i++) {
var weight = (i % 2 === 0) ? 1 : 3
sum += parseInt(base12[i], 10) * weight
}
var remainder = sum % 10
var checkDigit = remainder === 0 ? 0 : 10 - remainder
return base12 + checkDigit
},
// 67813ISBN
generateRandomIsbn() {
var rand = ''
for (var i = 0; i < 10; i++) {
rand += Math.floor(Math.random() * 10)
}
return '678' + rand
},
//
savePriceConfig() {
const cfg = {

View File

@ -303,9 +303,12 @@ export function getLocationList(params = {}) {
* 图书中心 - 根据ISBN查询图书信息
*/
export function searchBookByIsbn(isbn) {
var requestUrl = 'https://book.center.yushutx.com/api/es/searchByISBN?isbn=' + isbn
console.log('【图书中心查询】请求地址:', requestUrl)
console.log('【图书中心查询】参数:', { isbn: isbn })
return new Promise((resolve, reject) => {
uni.request({
url: `https://book.center.yushutx.com/api/es/searchByISBN?isbn=${isbn}`,
url: requestUrl,
method: 'GET',
header: {
'Authorization': 'Basic ZWxhc3RpYzo1bVJESVVnNTJWQzBmcDE0bnctRg==',
@ -313,6 +316,7 @@ export function searchBookByIsbn(isbn) {
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
},
success: (res) => {
console.log('【图书中心查询】返回数据集:', JSON.stringify(res.data))
if (res.statusCode === 200 && res.data && res.data.data) {
resolve(res.data.data)
} else if (res.statusCode === 200 && res.data && res.data.code === 0 && res.data.data) {
@ -332,8 +336,33 @@ export function searchBookByIsbn(isbn) {
// 导出 calculateSign 供组件按名导入
export { calculateSign }
/**
* 构建 form-urlencoded body支持图片以多个单独字段发送
* @param {Object} params - 已包含 sign params 对象live_image[] 为逗号拼接
* @param {string[]} imageUrls - 图片 URL 数组
* @param {string} imageKey - 图片字段名 'live_image' 'live_image[]'
* @returns {string} form-urlencoded 字符串
*/
function buildFormBodyWithImages(params, imageUrls, imageKey) {
var parts = []
for (var key in params) {
if (key === imageKey) {
// 每个 URL 单独发送
for (var j = 0; j < imageUrls.length; j++) {
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(imageUrls[j]))
}
} else {
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(String(params[key])))
}
}
return parts.join('&')
}
export { buildFormBodyWithImages }
export default {
calculateSign,
buildFormBodyWithImages,
getWarehouseList,
getLocationList,
psiLogin,