feat(扫码功能): 重构扫码页面并新增分卷录入功能

- 重构扫码页面结构,采用标签页形式组织功能模块
- 新增分卷录入功能组件(apart.vue)和基础录入功能组件(typing.vue)
- 新增物料选择组件(klp-product-select)和标签页组件(klp-tabs)
- 新增WMS相关API接口(product.js, warehouse.js等)
- 更新uni-data-select组件支持多选和插槽功能
- 更新uni-icons和uni-load-more组件版本及功能
- 移除冗余样式和代码,优化现有组件结构

refactor(组件): 优化acidity.vue组件使用新的标签页组件
style: 移除冗余CSS样式代码
chore: 更新多个uni_modules组件的package.json版本号
This commit is contained in:
砂糖
2025-10-28 18:11:46 +08:00
parent 57600f66c2
commit 771f4ab006
26 changed files with 1757 additions and 531 deletions

View File

@@ -1,174 +1,117 @@
<template>
<view class="content">
<!-- logo 和标题 -->
<image class="logo" src="/static/logo.jpg"></image>
<view class="text-area">
<text class="title">{{ title }}</text>
</view>
<!-- 扫码按钮 -->
<button class="scan-btn" @click="startScan">点击扫码</button>
<!-- 扫码结果组件仅传递必要props -->
<scan-result-card
v-if="scanResult"
:scan-result="scanResult"
:code-status="codeStatus"
:current-time="currentTime"
/>
<view class="content">
<!-- 标签栏 -->
<view class="tab-container">
<view
v-for="item in tabs"
:key="item.value"
@click="switchTab(item.value)"
class="tab-item"
:class="{ 'tab-active': currentTab === item.value }"
>
{{ item.label }}
</view>
</view>
<!-- 备注和确认按钮仅状态非2已出库时显示 -->
<textarea
v-if="scanResult && codeStatus !== CODE_STATUS.OUT_STOCK"
v-model="remark"
placeholder="请填写备注"
></textarea>
<button
class="confirm-btn"
@click="confirm"
v-if="scanResult && codeStatus !== CODE_STATUS.OUT_STOCK"
>
确认信息并录入系统
</button>
</view>
<!-- 动态组件区域 - 根据当前标签显示对应组件 -->
<view class="component-container">
<component
:is="currentComponent"
></component>
</view>
</view>
</template>
<script>
// 引入组件和API
import {
formatCurrentTime
} from '@/utils/wms';
import {
CODE_STATUS,
IO_TYPE
} from '@/constants/wms';
import {
SCAN_OPERATION_STRATEGIES
} from '@/strategies/wmsScan';
import {
addStockIoDetail
} from '@/api/wms/stockIoDetail.js';
import {
getGenerateRecord,
updateGenerateRecord
} from '@/api/wms/code.js';
import ApartVue from '@/components/panels/code/apart.vue'
import MergeVue from '@/components/panels/code/merge.vue'
import TraceVue from '@/components/panels/code/trace.vue'
import TypingVue from '@/components/panels/code/typing.vue'
export default {
data() {
return {
title: '科伦普扫码器',
scanResult: null, // 扫码结果(传递给组件)
currentTime: '', // 扫码时间(传递给组件)
recordId: undefined,
codeStatus: undefined,
remark: '',
CODE_STATUS,
currentTab: 'typing', // 当前激活的标签
tabs: [
{ label: '录入', value: 'typing' },
{ label: '分卷', value: 'apart' },
// { label: '合卷', value: 'merge' },
{ label: '追溯', value: 'trace' }
]
};
},
onLoad() {
this.currentTime = formatCurrentTime(); // 用工具函数
components: {
ApartVue,
MergeVue,
TraceVue,
TypingVue
},
computed: {
username() {
return this.$store.state.user.name
},
avatar() {
return this.$store.state.user.avatar
},
windowHeight() {
return uni.getSystemInfoSync().windowHeight - 50
},
// 根据当前标签计算要显示的组件
currentComponent() {
// 转换为组件名(如 'typing' -> 'TypingVue'
return this.currentTab.charAt(0).toUpperCase() + this.currentTab.slice(1) + 'Vue'
}
},
onLoad() {
uni.setNavigationBarTitle({
title: '扫码(' + this.username + '',
});
},
methods: {
// 更新当前时间(格式化后传递给组件)
updateCurrentTime() {
const date = new Date();
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hour = date.getHours().toString().padStart(2, '0');
const minute = date.getMinutes().toString().padStart(2, '0');
this.currentTime = `${year}-${month}-${day} ${hour}:${minute}`;
// 切换标签
switchTab(tabValue) {
this.currentTab = tabValue
},
// 开始扫码仅保留调用API和赋值逻辑无业务分支
async startScan() {
uni.scanCode({
success: async (res) => {
const codeId = res.result;
this.recordId = codeId;
uni.showLoading({
title: '正在获取二维码信息'
});
try {
const {
data
} = await getGenerateRecord(codeId);
this.scanResult = JSON.parse(data.content);
this.codeStatus = data.status; // 直接用枚举对应的数值
this.currentTime = formatCurrentTime(); // 工具函数
} catch (error) {
console.error('获取扫码信息失败:', error);
uni.showToast({
title: '获取信息失败',
icon: 'none',
duration: 2000
});
} finally {
uni.hideLoading();
}
},
fail: (err) => {
/* 原有逻辑不变 */ }
});
},
// 确认录入用策略模式替代if-else
async confirm() {
if (!this.scanResult || this.codeStatus === undefined) return;
// 1. 生成策略key状态-IO类型
const strategyKey = `${this.codeStatus}-${this.scanResult.ioType}`;
// 2. 匹配对应的策略(无策略则提示异常)
const strategy = SCAN_OPERATION_STRATEGIES[strategyKey];
if (!strategy) {
// 处理确认录入
handleConfirm() {
if (!this.scanResult && this.currentTab !== 'trace') {
uni.showToast({
title: '未知业务场景,无法处理',
title: '请先扫码获取信息',
icon: 'none'
});
return;
}
try {
// 3. 执行策略组装参数并调用入库API
const addParams = strategy.getAddParams(this.scanResult, this.remark);
await addStockIoDetail(addParams);
// 4. 执行策略:更新二维码状态
const targetStatus = strategy.getUpdateStatus();
await updateGenerateRecord({
recordId: this.recordId,
status: targetStatus
});
// 成功提示 + 清空数据
uni.showToast({
title: '确认成功,信息已录入系统',
icon: 'none',
duration: 2000
});
setTimeout(() => {
this.scanResult = null;
this.recordId = undefined;
this.codeStatus = undefined;
this.remark = '';
}, 2000); // 原0秒无意义改为与提示同步
} catch (error) {
console.error('确认失败:', error);
uni.showToast({
title: '确认失败,请重试',
icon: 'none'
});
})
return
}
// 这里添加确认录入的逻辑
console.log('确认录入信息:', {
tab: this.currentTab,
scanResult: this.scanResult,
currentTime: this.currentTime,
recordId: this.recordId,
codeStatus: this.codeStatus,
remark: this.remark,
operator: this.username
})
uni.showToast({
title: '录入成功',
icon: 'success'
})
}
}
};
}
</script>
<style>
/* 父页面样式:保留原有样式,新增确认按钮样式 */
/* 父页面样式:保留原有样式,新增标签栏样式 */
.content {
display: flex;
flex-direction: column;
@@ -179,49 +122,52 @@
background-color: #f5f5f5;
}
.logo {
height: 200rpx;
margin-top: 100rpx;
margin-bottom: 50rpx;
}
.text-area {
/* 标签栏容器 */
.tab-container {
display: flex;
justify-content: center;
margin-bottom: 80rpx;
width: 100%;
background-color: #fff;
border-radius: 10rpx;
overflow: hidden;
margin-bottom: 30rpx;
}
.title {
font-size: 36rpx;
color: #333;
/* 标签项样式 */
.tab-item {
flex: 1;
text-align: center;
padding: 25rpx 0;
font-size: 32rpx;
color: #666;
position: relative;
transition: all 0.3s;
}
/* 激活标签样式 */
.tab-active {
color: #007aff;
font-weight: 500;
}
/* 扫码按钮样式 */
.scan-btn {
width: 600rpx;
height: 100rpx;
line-height: 100rpx;
font-size: 36rpx;
/* 激活标签下划线 */
.tab-active::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 6rpx;
background-color: #007aff;
color: white;
border-radius: 50rpx;
margin-bottom: 60rpx;
box-shadow: 0 4rpx 10rpx rgba(0, 122, 255, 0.3);
border-radius: 3rpx 3rpx 0 0;
}
/* 确认按钮样式(父页面新增,与组件间距协调) */
.confirm-btn {
width: 680rpx;
/* 与组件宽度一致,视觉对齐 */
height: 90rpx;
line-height: 90rpx;
font-size: 32rpx;
background-color: #00b42a;
color: white;
/* 组件容器样式 */
.component-container {
width: 100%;
min-height: 400rpx;
background-color: #fff;
border-radius: 10rpx;
margin-top: 30rpx;
/* 与组件保持间距 */
box-shadow: 0 2rpx 8rpx rgba(0, 180, 42, 0.2);
padding: 30rpx;
margin-bottom: 40rpx;
}
</style>