feat(钢卷管理): 添加钢卷号前缀生成功能并优化样式

添加钢卷号前缀生成工具函数及测试用例
在合并、拆分、分条和录入页面使用自动生成的钢卷号前缀
调整EmployeeSelector组件默认触发器的样式
移除typing.vue中未使用的变更历史代码块
添加钢卷号长度校验规则
This commit is contained in:
砂糖
2026-03-03 14:15:45 +08:00
parent d927aa8647
commit 07e982b736
7 changed files with 162 additions and 46 deletions

View File

@@ -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;
}

View File

@@ -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);
});
});