手持机
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
onLaunch: function() {
|
||||
this.initApp()
|
||||
},
|
||||
onShow: function() {
|
||||
// 检查应用状态,确保从后台恢复时状态一致
|
||||
this.checkAppState()
|
||||
},
|
||||
methods: {
|
||||
// 初始化应用
|
||||
initApp() {
|
||||
@@ -24,7 +28,30 @@
|
||||
if (!getToken()) {
|
||||
this.$tab.reLaunch('/pages/login')
|
||||
}
|
||||
}
|
||||
},
|
||||
checkAppState() {
|
||||
|
||||
|
||||
// 检查Token状态和页面导航栈状态
|
||||
console.log('应用从后台切换到前台,检查应用状态')
|
||||
// 检查Token状态
|
||||
if (!getToken()) {
|
||||
console.log('Token不存在,提示并跳转到登录页')
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '登录已过期,请重新登录'
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: loginPage })
|
||||
}, 1500)
|
||||
} else {
|
||||
console.log('Token存在,不做操作')
|
||||
}
|
||||
|
||||
// 注意:应用从后台切换到前台的逻辑已在permission.js中处理
|
||||
// 这里不需要重复处理,保留此方法以便未来扩展
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -345,6 +345,7 @@
|
||||
"scanShelfCode": "Please scan shelf code",
|
||||
"unknownMaterial": "Unknown Material",
|
||||
"noCode": "No Code",
|
||||
"noQuantity": "No Quantity",
|
||||
"submit": "Submit",
|
||||
"pleaseSelectMaterial": "Please select materials to bind first",
|
||||
"pleaseScanShelfCode": "Please scan shelf code first",
|
||||
|
||||
@@ -346,6 +346,7 @@
|
||||
"scanShelfCode": "请扫描料架条码",
|
||||
"unknownMaterial": "未知物料",
|
||||
"noCode": "无编码",
|
||||
"noQuantity": "无数量",
|
||||
"submit": "提交",
|
||||
"pleaseSelectMaterial": "请先选择需要绑定的物料",
|
||||
"pleaseScanShelfCode": "请先扫描料架条码",
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
<view v-for="(item, index) in shelfInfo" :key="index" class="shelf-item">
|
||||
<text class="shelf-name">{{ item.productName || $t('outbound.bindShelf.unknownMaterial') }}</text>
|
||||
<text class="shelf-code">{{ item.productId || $t('outbound.bindShelf.noCode') }}</text>
|
||||
<text class="shelf-quantity">{{ item.quantity || $t('outbound.bindShelf.noQuantity') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -244,7 +245,7 @@ export default {
|
||||
this.materialList = (response.rows || []).map(item => ({
|
||||
...item,
|
||||
selected: false,
|
||||
bindQuantity: item.quantit
|
||||
bindQuantity: item.quantity
|
||||
}))
|
||||
} else {
|
||||
uni.showToast({
|
||||
@@ -299,6 +300,19 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查绑定数量是否为0或空
|
||||
const invalidQuantityItem = selectedItems.find(item => {
|
||||
return !item.bindQuantity || item.bindQuantity === 0
|
||||
})
|
||||
|
||||
if (invalidQuantityItem) {
|
||||
uni.showToast({
|
||||
title: '绑定数量不能为0或空',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.$refs.bindShelfPopup.open()
|
||||
},
|
||||
// 关闭绑定料架弹窗
|
||||
@@ -375,6 +389,19 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查绑定数量是否为0或空
|
||||
const invalidQuantityItem = selectedItems.find(item => {
|
||||
return !item.bindQuantity || item.bindQuantity === 0
|
||||
})
|
||||
|
||||
if (invalidQuantityItem) {
|
||||
uni.showToast({
|
||||
title: '绑定数量不能为0或空',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 这里可以根据实际需求调用相应的API进行提交
|
||||
// 示例:构建提交数据
|
||||
const submitData = {
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
<text class="value">{{ item.outQuantity }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="label">{{ $t('outbound.exception.pickQuantity') }}:</text>
|
||||
<text class="value">{{ item.pickQuantity }}</text>
|
||||
</view>
|
||||
<text class="label">{{ $t('outbound.exception.pickQuantity') }}:</text>
|
||||
<uni-easyinput v-model="item.pickQuantity" type="number" :placeholder="$t('outbound.exception.enterPickQuantity')" style="flex: 1;" @input="validatePickQuantity(item)"></uni-easyinput>
|
||||
</view>
|
||||
</view>
|
||||
</uni-card>
|
||||
</view>
|
||||
@@ -68,7 +68,13 @@ export default {
|
||||
try {
|
||||
const response = await getTaskDetail({trayCode: value,inOut:'2'})
|
||||
if (response.code === 200) {
|
||||
this.materialList = response.data || []
|
||||
// 设置materialList并初始化pickQuantity为outQuantity的值
|
||||
this.materialList = (response.data || []).map(item => {
|
||||
return {
|
||||
...item,
|
||||
pickQuantity: item.outQuantity
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: response.msg || this.$t('common.noData'),
|
||||
@@ -88,6 +94,37 @@ export default {
|
||||
handleClear() {
|
||||
this.materialList = []
|
||||
},
|
||||
// 验证拣货数量不超过出库数量且不为负数
|
||||
validatePickQuantity(item) {
|
||||
// 转换为数字
|
||||
let pickQty = Number(item.pickQuantity)
|
||||
let outQty = Number(item.outQuantity)
|
||||
|
||||
// 检查是否为有效数字
|
||||
if (isNaN(pickQty) || pickQty === '') {
|
||||
item.pickQuantity = outQty
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否为负数
|
||||
if (pickQty < 0) {
|
||||
uni.showToast({
|
||||
title: this.$t('outbound.exception.pickQuantityNegative'),
|
||||
icon: 'none'
|
||||
})
|
||||
item.pickQuantity = 0
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否超过出库数量
|
||||
if (pickQty > outQty) {
|
||||
uni.showToast({
|
||||
title: this.$t('outbound.exception.pickQuantityExceed'),
|
||||
icon: 'none'
|
||||
})
|
||||
item.pickQuantity = outQty
|
||||
}
|
||||
},
|
||||
// 处理扫码事件
|
||||
handleScan() {
|
||||
uni.scanCode({
|
||||
@@ -106,10 +143,62 @@ export default {
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 提交前再次验证所有物料的pickQuantity
|
||||
let isValid = true
|
||||
this.materialList.forEach(item => {
|
||||
// 转换为数字
|
||||
let pickQty = Number(item.pickQuantity)
|
||||
let outQty = Number(item.outQuantity)
|
||||
|
||||
// 检查是否为有效数字
|
||||
if (isNaN(pickQty) || pickQty === '') {
|
||||
isValid = false
|
||||
uni.showToast({
|
||||
title: this.$t('outbound.exception.invalidPickQuantity'),
|
||||
icon: 'none'
|
||||
})
|
||||
item.pickQuantity = outQty
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否为负数
|
||||
if (pickQty < 0) {
|
||||
isValid = false
|
||||
uni.showToast({
|
||||
title: this.$t('outbound.exception.pickQuantityNegative'),
|
||||
icon: 'none'
|
||||
})
|
||||
item.pickQuantity = 0
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否超过出库数量
|
||||
if (pickQty > outQty) {
|
||||
isValid = false
|
||||
uni.showToast({
|
||||
title: this.$t('outbound.exception.pickQuantityExceed'),
|
||||
icon: 'none'
|
||||
})
|
||||
item.pickQuantity = outQty
|
||||
}
|
||||
})
|
||||
|
||||
if (!isValid) return
|
||||
|
||||
// 准备提交数据,包含所有物料编码和pickQuantity
|
||||
const materialDetails = this.materialList.map(item => {
|
||||
return {
|
||||
jobDetailId: item.jobDetailId,
|
||||
productId: item.productId,
|
||||
pickQuantity: item.pickQuantity
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
const response = await submitError({
|
||||
trayCode: this.trayCode
|
||||
|
||||
trayCode: this.trayCode,
|
||||
materialDetails: materialDetails
|
||||
})
|
||||
if (response.code === 200) {
|
||||
uni.showToast({
|
||||
|
||||
@@ -3,6 +3,9 @@ import { getToken } from '@/utils/auth'
|
||||
// 登录页面
|
||||
const loginPage = "/pages/login"
|
||||
|
||||
// 首页
|
||||
const indexPage = "/pages/index"
|
||||
|
||||
// 标记是否由navigateBack触发的reLaunch
|
||||
let isNavigateBackTriggered = false
|
||||
|
||||
@@ -10,6 +13,8 @@ let isNavigateBackTriggered = false
|
||||
function getCurrentPageUrl() {
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
console.log("当前页面",currentPage.route)
|
||||
console.log("上一层页面", pages[pages.length - 2].route)
|
||||
return currentPage ? currentPage.route : ''
|
||||
}
|
||||
|
||||
@@ -26,6 +31,8 @@ function checkWhite(url) {
|
||||
return whiteList.indexOf(path) !== -1
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 页面跳转验证拦截器
|
||||
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
|
||||
list.forEach(item => {
|
||||
@@ -77,6 +84,45 @@ uni.addInterceptor('navigateBack', {
|
||||
console.log('navigateBack 拦截器被触发', e)
|
||||
console.log('当前 Token 状态:', getToken() ? '存在' : '不存在')
|
||||
|
||||
// 获取当前页面栈
|
||||
const pages = getCurrentPages()
|
||||
|
||||
// 检查页面导航栈是否为空
|
||||
if (pages.length <= 1) {
|
||||
console.log('页面导航栈为空或只有一个页面,无法正常返回')
|
||||
|
||||
// 检查Token状态
|
||||
if (getToken()) {
|
||||
console.log('Token存在,跳转到首页')
|
||||
// 设置标志,表明当前的reLaunch是由navigateBack触发的
|
||||
isNavigateBackTriggered = true
|
||||
uni.reLaunch({ url: indexPage })
|
||||
// 重置标志
|
||||
setTimeout(() => {
|
||||
isNavigateBackTriggered = false
|
||||
}, 100)
|
||||
} else {
|
||||
console.log('Token不存在,跳转到登录页')
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '登录已过期,请重新登录'
|
||||
})
|
||||
|
||||
// 设置标志,表明当前的reLaunch是由navigateBack触发的
|
||||
isNavigateBackTriggered = true
|
||||
setTimeout(() => {
|
||||
console.log('执行跳转到登录页')
|
||||
uni.reLaunch({ url: loginPage })
|
||||
// 重置标志
|
||||
setTimeout(() => {
|
||||
isNavigateBackTriggered = false
|
||||
}, 100)
|
||||
}, 1500)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 页面导航栈不为空,检查Token状态
|
||||
if (!getToken()) {
|
||||
const currentPage = getCurrentPageUrl()
|
||||
console.log('当前页面路径:', currentPage)
|
||||
@@ -87,26 +133,32 @@ uni.addInterceptor('navigateBack', {
|
||||
return true
|
||||
}
|
||||
|
||||
console.log('Token 不存在且页面不在白名单中,准备跳转到登录页')
|
||||
console.log('Token不存在且页面不在白名单中,准备跳转到登录页')
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '登录已过期,请重新登录'
|
||||
})
|
||||
|
||||
// 设置标志,表明当前的reLaunch是由navigateBack触发的
|
||||
isNavigateBackTriggered = true;
|
||||
isNavigateBackTriggered = true
|
||||
setTimeout(() => {
|
||||
console.log('执行跳转到登录页')
|
||||
uni.reLaunch({ url: loginPage })
|
||||
// 重置标志
|
||||
setTimeout(() => {
|
||||
isNavigateBackTriggered = false;
|
||||
}, 100);
|
||||
isNavigateBackTriggered = false
|
||||
}, 100)
|
||||
}, 1500)
|
||||
return false
|
||||
}
|
||||
|
||||
console.log('Token 存在,允许正常返回')
|
||||
// Token存在且页面导航栈不为空,允许正常返回
|
||||
const currentPage = pages[pages.length - 1]
|
||||
console.log("当前页面:", currentPage.route)
|
||||
if (pages.length > 1) {
|
||||
console.log("上一层页面:", pages[pages.length - 2].route)
|
||||
}
|
||||
console.log('Token存在,允许正常返回')
|
||||
return true
|
||||
},
|
||||
fail(err) {
|
||||
|
||||
Reference in New Issue
Block a user