Compare commits
10 Commits
251e2ca311
...
ac0217b724
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac0217b724 | ||
|
|
b7481c1f99 | ||
|
|
46450acdd9 | ||
|
|
4c9d0bae02 | ||
|
|
247d582af8 | ||
|
|
26298368ca | ||
|
|
ba0829ba04 | ||
|
|
9a8cc14b7a | ||
|
|
86c326b27f | ||
|
|
3a4a30511d |
28
App.vue
28
App.vue
@ -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')
|
||||
|
||||
@ -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>
|
||||
@ -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 body(live_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
|
||||
// 尝试多种字段名获取 ISBN(OCR 可能返回不同字段名)
|
||||
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. 13位、978/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. 其他情况(为空或无法识别)→ 生成678开头的13位随机数
|
||||
return this.generateRandomIsbn()
|
||||
},
|
||||
|
||||
// 10位ISBN转13位
|
||||
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
|
||||
},
|
||||
|
||||
// 生成678开头的13位随机ISBN
|
||||
generateRandomIsbn() {
|
||||
var rand = ''
|
||||
for (var i = 0; i < 10; i++) {
|
||||
rand += Math.floor(Math.random() * 10)
|
||||
}
|
||||
return '678' + rand
|
||||
},
|
||||
|
||||
// 保存定价策略配置
|
||||
savePriceConfig() {
|
||||
const cfg = {
|
||||
|
||||
31
utils/api.js
31
utils/api.js
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user