From 07e982b736998955730989297118ef95b21245a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= Date: Tue, 3 Mar 2026 14:15:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=92=A2=E5=8D=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=92=A2=E5=8D=B7=E5=8F=B7=E5=89=8D=E7=BC=80?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加钢卷号前缀生成工具函数及测试用例 在合并、拆分、分条和录入页面使用自动生成的钢卷号前缀 调整EmployeeSelector组件默认触发器的样式 移除typing.vue中未使用的变更历史代码块 添加钢卷号长度校验规则 --- .../src/components/EmployeeSelector/index.vue | 4 +- klp-ui/src/utils/coil/coilNo.js | 37 ++++++++ klp-ui/src/utils/coil/coilNo.test.js | 85 +++++++++++++++++++ klp-ui/src/views/wms/coil/merge.vue | 5 +- .../src/views/wms/coil/panels/stepSplit.vue | 17 +++- klp-ui/src/views/wms/coil/split.vue | 7 +- klp-ui/src/views/wms/coil/typing.vue | 53 +++--------- 7 files changed, 162 insertions(+), 46 deletions(-) create mode 100644 klp-ui/src/utils/coil/coilNo.js create mode 100644 klp-ui/src/utils/coil/coilNo.test.js diff --git a/klp-ui/src/components/EmployeeSelector/index.vue b/klp-ui/src/components/EmployeeSelector/index.vue index 6e80e7a4..78f2c2da 100644 --- a/klp-ui/src/components/EmployeeSelector/index.vue +++ b/klp-ui/src/components/EmployeeSelector/index.vue @@ -313,10 +313,10 @@ export default { } .default-trigger { - padding: 8px 12px; + padding: 2px 4px; border: 1px solid #dcdfe6; - border-radius: 4px; min-width: 120px; + font-size: 13px; display: inline-block; } diff --git a/klp-ui/src/utils/coil/coilNo.js b/klp-ui/src/utils/coil/coilNo.js new file mode 100644 index 00000000..e7e58997 --- /dev/null +++ b/klp-ui/src/utils/coil/coilNo.js @@ -0,0 +1,37 @@ +/** + * 生成钢卷号前五位 + * 格式:年份后两位 + 月份字母 + 日期两位 + * 例如:2026年3月3日生成 26L03 + * @returns {string} 钢卷号前五位 + */ +export function generateCoilNoPrefix() { + const now = new Date(); + // 取年份后两位 + const year = now.getFullYear().toString().slice(-2); + + // 月份字母映射 + const monthLetters = { + 1: 'J', // 1月 + 2: 'K', // 2月 + 3: 'L', // 3月 + 4: 'M', // 4月 + 5: 'N', // 5月 + 6: 'O', // 6月 + 7: 'P', // 7月 + 8: 'Q', // 8月 + 9: 'R', // 9月 + 10: 'S', // 10月 + 11: 'T', // 11月 + 12: 'U' // 12月 + }; + + // 获取月份字母 + const month = monthLetters[now.getMonth() + 1]; + + // 日期补零 + const day = String(now.getDate()).padStart(2, '0'); + + // 组合前五位:年份后两位 + 月份字母 + 日期两位 + return year + month + day; +} + diff --git a/klp-ui/src/utils/coil/coilNo.test.js b/klp-ui/src/utils/coil/coilNo.test.js new file mode 100644 index 00000000..cec1f0e3 --- /dev/null +++ b/klp-ui/src/utils/coil/coilNo.test.js @@ -0,0 +1,85 @@ +import {expect, test} from '@jest/globals'; +import { generateCoilNoPrefix } from './coilNo'; + +describe('generateCoilNoPrefix', () => { + // 保存原始的Date方法 + let originalGetFullYear; + let originalGetMonth; + let originalGetDate; + + beforeEach(() => { + // 保存原始方法 + originalGetFullYear = Date.prototype.getFullYear; + originalGetMonth = Date.prototype.getMonth; + originalGetDate = Date.prototype.getDate; + }); + + afterEach(() => { + // 恢复原始方法 + Date.prototype.getFullYear = originalGetFullYear; + Date.prototype.getMonth = originalGetMonth; + Date.prototype.getDate = originalGetDate; + }); + + test("生成2026年3月3日的钢卷号前五位", () => { + // 模拟日期:2026年3月3日 + Date.prototype.getFullYear = jest.fn(() => 2026); + Date.prototype.getMonth = jest.fn(() => 2); // 3月是索引2 + Date.prototype.getDate = jest.fn(() => 3); + + const result = generateCoilNoPrefix(); + expect(result).toBe('26L03'); + }); + + test('生成2026年1月1日的钢卷号前五位', () => { + // 模拟日期:2026年1月1日 + Date.prototype.getFullYear = jest.fn(() => 2026); + Date.prototype.getMonth = jest.fn(() => 0); // 1月是索引0 + Date.prototype.getDate = jest.fn(() => 1); + + const result = generateCoilNoPrefix(); + expect(result).toBe('26J01'); + }); + + test('生成2026年12月31日的钢卷号前五位', () => { + // 模拟日期:2026年12月31日 + Date.prototype.getFullYear = jest.fn(() => 2026); + Date.prototype.getMonth = jest.fn(() => 11); // 12月是索引11 + Date.prototype.getDate = jest.fn(() => 31); + + const result = generateCoilNoPrefix(); + expect(result).toBe('26U31'); + }); + + test('生成2027年5月15日的钢卷号前五位', () => { + // 模拟日期:2027年5月15日 + Date.prototype.getFullYear = jest.fn(() => 2027); + Date.prototype.getMonth = jest.fn(() => 4); // 5月是索引4 + Date.prototype.getDate = jest.fn(() => 15); + + const result = generateCoilNoPrefix(); + expect(result).toBe('27N15'); + }); + + test('钢卷号前五位长度为5', () => { + // 模拟任意日期 + Date.prototype.getFullYear = jest.fn(() => 2026); + Date.prototype.getMonth = jest.fn(() => 2); + Date.prototype.getDate = jest.fn(() => 3); + + const result = generateCoilNoPrefix(); + expect(result.length).toBe(5); + }); + + test('钢卷号前五位格式正确', () => { + // 模拟任意日期 + Date.prototype.getFullYear = jest.fn(() => 2026); + Date.prototype.getMonth = jest.fn(() => 2); + Date.prototype.getDate = jest.fn(() => 3); + + const result = generateCoilNoPrefix(); + // 格式:年份后两位(2位数字) + 月份字母(1位字母) + 日期两位(2位数字) + const regex = /^\d{2}[JKLMNOPQRSTU]\d{2}$/; + expect(regex.test(result)).toBe(true); + }); +}); diff --git a/klp-ui/src/views/wms/coil/merge.vue b/klp-ui/src/views/wms/coil/merge.vue index 09495427..9b5b23e6 100644 --- a/klp-ui/src/views/wms/coil/merge.vue +++ b/klp-ui/src/views/wms/coil/merge.vue @@ -226,6 +226,7 @@ import ActualWarehouseSelect from "@/components/KLPService/ActualWarehouseSelect import RawMaterialSelector from "@/components/KLPService/RawMaterialSelect"; import ProductSelector from "@/components/KLPService/ProductSelect"; import WarehouseSelect from "@/components/KLPService/WarehouseSelect"; +import { generateCoilNoPrefix } from "@/utils/coil/coilNo"; export default { name: 'MergeCoil', @@ -238,12 +239,14 @@ export default { }, dicts: ['coil_quality_status'], data() { + const currentCoilNoPrefix = generateCoilNoPrefix() return { + currentCoilNoPrefix, // 源卷列表 sourceCoils: [], // 目标卷信息 targetCoil: { - currentCoilNo: '', + currentCoilNo: currentCoilNoPrefix, team: '', materialType: null, itemType: null, diff --git a/klp-ui/src/views/wms/coil/panels/stepSplit.vue b/klp-ui/src/views/wms/coil/panels/stepSplit.vue index 1c3e91e7..42136332 100644 --- a/klp-ui/src/views/wms/coil/panels/stepSplit.vue +++ b/klp-ui/src/views/wms/coil/panels/stepSplit.vue @@ -198,6 +198,7 @@ import ProductSelect from "@/components/KLPService/ProductSelect"; import RawMaterialSelect from "@/components/KLPService/RawMaterialSelect"; import WarehouseSelect from "@/components/KLPService/WarehouseSelect"; import ActualWarehouseSelect from "@/components/KLPService/ActualWarehouseSelect"; +import { generateCoilNoPrefix } from "@/utils/coil/coilNo"; export default { name: 'StepSplit', @@ -223,7 +224,9 @@ export default { }, dicts: ['coil_quality_status'], data() { + const currentCoilNoPrefix = generateCoilNoPrefix() return { + currentCoilNoPrefix, // 待分条钢卷基础信息 coilInfo: {}, loading: false, @@ -231,7 +234,7 @@ export default { splitForm: { coilId: '', // 分条钢卷ID(编辑时赋值) enterCoilNo: '', - currentCoilNo: '', + currentCoilNo: currentCoilNoPrefix, supplierCoilNo: '', warehouseId: '', actualWarehouseId: '', @@ -262,6 +265,16 @@ export default { rules: { currentCoilNo: [ { required: true, message: "当前钢卷号不能为空", trigger: "blur" }, + { + // 当前钢卷号必须大于等于10位 + validator: (rule, value, callback) => { + if (value.length < 10) { + callback(new Error('当前钢卷号必须大于等于10位')); + } else { + callback(); + } + }, trigger: 'blur' + }, // 仅在新增的时候校验 { validator: (rule, value, callback) => { @@ -400,7 +413,7 @@ export default { this.splitForm = { coilId: undefined, enterCoilNo: '', - currentCoilNo: '', + currentCoilNo: this.currentCoilNoPrefix, supplierCoilNo: '', warehouseId: '', actualWarehouseId: '', diff --git a/klp-ui/src/views/wms/coil/split.vue b/klp-ui/src/views/wms/coil/split.vue index 2932e1bd..7b53c460 100644 --- a/klp-ui/src/views/wms/coil/split.vue +++ b/klp-ui/src/views/wms/coil/split.vue @@ -225,6 +225,7 @@ import ActualWarehouseSelect from "@/components/KLPService/ActualWarehouseSelect import RawMaterialSelect from "@/components/KLPService/RawMaterialSelect"; import ProductSelect from "@/components/KLPService/ProductSelect"; import WarehouseSelect from "@/components/KLPService/WarehouseSelect"; +import { generateCoilNoPrefix } from "@/utils/coil/coilNo"; export default { name: 'SplitCoil', @@ -236,7 +237,9 @@ export default { }, dicts: ['coil_quality_status'], data() { + const currentCoilNoPrefix = generateCoilNoPrefix() return { + currentCoilNoPrefix, // 母卷信息 motherCoil: { coilId: null, @@ -259,7 +262,7 @@ export default { // 子卷列表 splitList: [ { - currentCoilNo: '', + currentCoilNo: currentCoilNoPrefix, team: '', materialType: null, itemType: null, @@ -439,7 +442,7 @@ export default { // 添加子卷 addSplitItem() { this.splitList.push({ - currentCoilNo: '', + currentCoilNo: this.currentCoilNoPrefix, team: '', materialType: null, itemType: null, diff --git a/klp-ui/src/views/wms/coil/typing.vue b/klp-ui/src/views/wms/coil/typing.vue index 3ae8dcd2..a4dee93c 100644 --- a/klp-ui/src/views/wms/coil/typing.vue +++ b/klp-ui/src/views/wms/coil/typing.vue @@ -215,45 +215,6 @@ - - - @@ -268,6 +229,7 @@ import ActualWarehouseSelect from "@/components/KLPService/ActualWarehouseSelect import RawMaterialSelect from "@/components/KLPService/RawMaterialSelect"; import ProductSelect from "@/components/KLPService/ProductSelect"; import WarehouseSelect from "@/components/KLPService/WarehouseSelect"; +import { generateCoilNoPrefix } from "@/utils/coil/coilNo"; export default { name: 'TypingCoil', @@ -324,6 +286,16 @@ export default { rules: { currentCoilNo: [ { required: true, message: '请输入当前钢卷号', trigger: 'blur' }, + { + // 当前钢卷号必须大于等于10位 + validator: (rule, value, callback) => { + if (value.length < 10) { + callback(new Error('当前钢卷号必须大于等于10位')); + } else { + callback(); + } + }, trigger: 'blur' + }, // 仅在新增的时候校验 { validator: (rule, value, callback) => { @@ -524,6 +496,9 @@ export default { } } + const currentCoilNoPrefix = generateCoilNoPrefix() + this.$set(this.updateForm, 'currentCoilNo', currentCoilNoPrefix) + if (actionId) { this.actionId = actionId; }