就记录下,条形码解析写的很糟糕,好多地方可以封装函数的,所以有点乱,直接复制过去还能用的,UCC条码只能解析包装代码,通过包装代码获取型号是调后台接口,然后上面是自己写的各种时间格式转YY-MM-DD的函数,写的low但能用。
import {
getUCCModel } from '@/api/distributionSheet'
// 时间转化函数
// 日期转化格式
export function formateSData (d) {
return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds()
}
// 日期转化格式
export function formateData (d) {
let m = ''
if ((d.getMonth() + 1).toString().length === 1) {
m = '0' + (d.getMonth() + 1)
} else {
m = d.getMonth() + 1
}
let day = ''
if (d.getDate().toString().length === 1) {
day = '0' + d.getDate()
} else {
day = d.getDate()
}
return d.getFullYear() + '-' + m + '-' + day
}
// YYJJJ转y-m-d
export function getYJDate (n) {
const date = new Date(new Date('20' + n.slice(0, 2) + '/1/1').getTime() + 24 * 60 * 60 * 1000 * (parseInt(n.slice(2)) - 1))
return formateData(date)
}
// YYMMDD转y-m-d
export function getYMDDate (n) {
const data = '20' + n.slice(0, 2) + '-' + n.slice(2, 4) + '-' + n.slice(4)
return data
}
// MMYY转y-m-d
export function getMYDate (n) {
const date = new Date(new Date('20' + n.slice(2) + '/' + (parseInt(n.slice(0, 2)) + 1)) - 24 * 60 * 60 * 1000)
return formateData(date)
}
// MMDDYY转y-m-d
export function getMDYDate (n) {
const data = '20' + n.slice(4) + '-' + n.slice(0, 2) + '-' + n.slice(2, 4)
return data
}
//UCC包装代码获取型号
export async function getUccModel (query) {
await getUCCModel(query.ItemModel).then(res => {
query.ItemModel = res.data.rows
}).catch(err => {
this.$message.error(err.response.data)
})
}
// 条形码解析
export function barcodeAnalysis (barcode, scanData) {
console.log(barcode)
const barCode = barcode
console.log(barCode)
if (/\+/ig.test(barCode) === false) {
if (barCode.slice(0, 2) === '01') {
if (barCode.length > 16) {
console.log('这是UCC全码')
console.log(barCode.slice(2, 16), '包装代码')
scanData.ItemModel = ''
scanData.ItemModel = barCode.slice(2, 16)
getUccModel(scanData)
const barCode1 = barCode.slice(16)
if (barCode1.slice(0, 2) === '11') {
scanData.ManufactureDt = ''
scanData.ManufactureDt = getYMDDate(barCode1.slice(2, 8))
console.log(scanData.ManufactureDt, '生产日期')
const barCode2