107 lines
3.2 KiB
JavaScript
107 lines
3.2 KiB
JavaScript
export function dateFormat(fmt, date) {
|
||
let ret;
|
||
const opt = {
|
||
"Y+": date.getFullYear().toString(), // 年
|
||
"m+": (date.getMonth() + 1).toString(), // 月
|
||
"d+": date.getDate().toString(), // 日
|
||
"H+": date.getHours().toString(), // 时
|
||
"M+": date.getMinutes().toString(), // 分
|
||
"S+": date.getSeconds().toString() // 秒
|
||
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
||
};
|
||
for (let k in opt) {
|
||
ret = new RegExp("(" + k + ")").exec(fmt);
|
||
if (ret) {
|
||
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
|
||
};
|
||
};
|
||
return fmt;
|
||
}
|
||
|
||
export function MatchVersion(oldVersion,newVersion){
|
||
var old = oldVersion.split('.');
|
||
var newV = newVersion.split('.');
|
||
|
||
// console.log(old);
|
||
// console.log(newV)
|
||
|
||
if(parseInt(old[0])< parseInt(newV[0])){
|
||
return true;
|
||
}
|
||
|
||
if(parseInt(old[1])< parseInt(newV[1])){
|
||
return true;
|
||
}
|
||
|
||
if(parseInt(old[2])< parseInt(newV[2])){
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
export function GetBoxIdFromQrCode(qrCode){
|
||
if (qrCode.indexOf("|") === -1){
|
||
return qrCode;
|
||
}
|
||
let count = qrCode.split("|").length;
|
||
//标准标签格式中 | 出现次数为5
|
||
//SN|物料号|数量|供应商|制造日期|过期日
|
||
if (count !== 6) {
|
||
this.showToast('标签不符合规范请确认', 'error');
|
||
return;
|
||
}
|
||
let qrCodeArr = qrCode.split("|");
|
||
return qrCodeArr[0];
|
||
}
|
||
|
||
/**
|
||
* 从二维码字符串中提取箱信息。
|
||
* 二维码格式要求为:SN|物料号|数量|供应商|制造日期|过期日
|
||
* BCDA111|12-0501018|12|12|20240809|20270909
|
||
* 如果二维码不符合格式要求,将显示错误提示并返回 undefined。
|
||
*
|
||
* @param {string} qrCode - 二维码字符串
|
||
* @returns {Object|undefined} - 如果二维码符合格式,返回包含二维码信息的对象;否则返回 undefined
|
||
*/
|
||
export function GetBoxInfoFromQrCode(qrCode) {
|
||
// 检查二维码字符串中是否包含分隔符 "|"
|
||
if (qrCode.indexOf("|") === -1) {
|
||
// 如果不包含分隔符,显示错误提示并返回 undefined
|
||
return undefined;
|
||
}
|
||
|
||
// 将二维码字符串按分隔符 "|" 分割成数组
|
||
let qrCodeArr = qrCode.split("|");
|
||
|
||
// 标准标签格式中分隔符 "|" 出现次数应为 5,因此数组长度应为 6
|
||
if (qrCodeArr.length !== 6) {
|
||
// 如果不符合格式要求,显示错误提示并返回 undefined
|
||
return undefined;
|
||
}
|
||
|
||
// 将分割后的数组映射到对象中
|
||
let boxInfo = {
|
||
boxId: qrCodeArr[0],
|
||
materialSpecName: qrCodeArr[1],
|
||
materialQuantity: qrCodeArr[2],
|
||
supplier: qrCodeArr[3],
|
||
makeDate: qrCodeArr[4].substring(0, 4) + '-' + qrCodeArr[4].substring(4, 6) + '-' + qrCodeArr[4].substring(6, 8),
|
||
expDate: qrCodeArr[5].substring(0, 4) + '-' + qrCodeArr[5].substring(4, 6) + '-' + qrCodeArr[5].substring(6, 8)
|
||
};
|
||
|
||
// 返回包含二维码信息的对象
|
||
return boxInfo;
|
||
}
|
||
|
||
// src/utils/queryParamUtil.js
|
||
export function createQueryParam() {
|
||
return {
|
||
queryId: "",
|
||
version: "",
|
||
params: {}
|
||
};
|
||
}
|
||
|
||
|