js时间转化格式及UCC、HIBC条码解析

2023-05-16

就记录下,条形码解析写的很糟糕,好多地方可以封装函数的,所以有点乱,直接复制过去还能用的,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 = barCode1.slice(8)
          if (barCode2.slice(0, 2) === '17') {
            scanData.DisabledDatetime = ''
            scanData.DisabledDatetime = getYMDDate(barCode2.slice(2, 8))
            console.log(scanData.DisabledDatetime, '失效日期')
            const barCode3 = barCode2.slice(8)
            if (barCode3.slice(0, 2) === '10') {
              const index = barCode3.indexOf('21')
              if (index === -1) {
                scanData.LotCode = ''
                scanData.LotCode = barCode3.slice(2, index)
                console.log(scanData.LotCode, '批号')
              } else {
                scanData.Serial = ''
                scanData.Serial = barCode3.slice(index + 2)
                console.log(scanData.Serial, '序列号')
                scanData.LotCode = ''
                scanData.LotCode = barCode3.slice(2, index)
                console.log(scanData.LotCode, '批号')
              }
            } else if (barCode3.slice(0, 2) === '21') {
              scanData.Serial = ''
              scanData.Serial = barCode3.slice(2)
              console.log(scanData.Serial, '序列号')
            }
          } else if (barCode3.slice(0, 2) === '10') {
            const index = barCode3.indexOf('21')
            if (index === -1) {
              scanData.LotCode = ''
              scanData.LotCode = barCode3.slice(2, index)
              console.log(scanData.LotCode, '批号')
            } else {
              scanData.Serial = ''
              scanData.Serial = barCode3.slice(index + 2)
              console.log(scanData.Serial, '序列号')
              scanData.LotCode = ''
              scanData.LotCode = barCode3.slice(2, index)
              console.log(scanData.LotCode, '批号')
            }
          } else if (barCode3.slice(0, 2) === '21') {
            scanData.Serial = ''
            scanData.Serial = barCode3.slice(2)
            console.log(scanData.Serial, '序列号')
          }
        } else if (barCode1.slice(0, 2) === '17') {
          scanData.DisabledDatetime = ''
          scanData.DisabledDatetime = getYMDDate(barCode1.slice(2, 8))
          console.log(scanData.DisabledDatetime, '失效日期')
          const barCode4 = barCode1.slice(8)
          if (barCode4.slice(0, 2) === '10') {
            const index = barCode4.indexOf('21')
            if (index === -1) {
              scanData.LotCode = ''
              scanData.LotCode = barCode4.slice(2, index)
              console.log(scanData.LotCode, '批号')
            } else {
              scanData.Serial = ''
              scanData.Serial = barCode4.slice(index + 2)
              console.log(scanData.Serial, '序列号')
              scanData.LotCode = ''
              scanData.LotCode = barCode4.slice(2, index)
              console.log(scanData.LotCode, '批号')
            }
          } else if (barCode4.slice(0, 2) === '21') {
            scanData.Serial = ''
            scanData.Serial = barCode4.slice(2)
            console.log(scanData.Serial, '序列号')
          }
        } else if (barCode1.slice(0, 2) === '10') {
          scanData.LotCode = ''
          scanData.LotCode = barCode1.slice(-16, -8)
          console.log(scanData.LotCode, '批号')
          scanData.DisabledDatetime = ''
          scanData.DisabledDatetime = getYMDDate(barCode1.slice(-6))
          console.log(scanData.DisabledDatetime, '失效日期')
        } else if (barCode1.slice(0, 2) === '21') {
          scanData.Serial = ''
          scanData.Serial = barCode1.slice(2)
          console.log(scanData.Serial, '序列号')
        }
      } else {
        console.log('这是UCC主码')
        scanData.ItemModel = ''
        scanData.ItemModel = barCode.slice(2, 16)
        getUccModel(scanData)
        console.log(barCode.slice(2, 16), '包装代码')
      }
    } else {
      console.log('这是UCC副码')
      const barCode1 = barCode
      if (barCode1.slice(0, 2) === '11') {
        scanData.ManufactureDt = ''
        scanData.ManufactureDt = getYMDDate(barCode1.slice(2, 8))
        console.log(scanData.ManufactureDt, '生产日期')
        const barCode2 = barCode1.slice(8)
        if (barCode2.slice(0, 2) === '17') {
          scanData.DisabledDatetime = ''
          scanData.DisabledDatetime = getYMDDate(barCode2.slice(2, 8))
          console.log(scanData.DisabledDatetime, '失效日期')
          const barCode3 = barCode2.slice(8)
          if (barCode3.slice(0, 2) === '10') {
            const index = barCode3.indexOf('21')
            if (index === -1) {
              scanData.LotCode = ''
              scanData.LotCode = barCode3.slice(2, index)
              console.log(scanData.LotCode, '批号')
            } else {
              scanData.Serial = ''
              scanData.Serial = barCode3.slice(index)
              console.log(scanData.Serial, '序列号')
              scanData.LotCode = ''
              scanData.LotCode = barCode3.slice(2, index)
              console.log(scanData.LotCode, '批号')
            }
          } else if (barCode3.slice(0, 2) === '21') {
            scanData.Serial = ''
            scanData.Serial = barCode3.slice(2)
            console.log(scanData.Serial, '序列号')
          }
        } else if (barCode3.slice(0, 2) === '10') {
          const index = barCode3.indexOf('21')
          if (index === -1) {
            scanData.LotCode = ''
            scanData.LotCode = barCode3.slice(2, index + 2)
            console.log(scanData.LotCode, '批号')
          } else {
            scanData.Serial = ''
            scanData.Serial = barCode3.slice(index + 2)
            console.log(scanData.Serial, '序列号')
            scanData.LotCode = ''
            scanData.LotCode = barCode3.slice(2, index)
            console.log(scanData.LotCode, '批号')
          }
        } else if (barCode3.slice(0, 2) === '21') {
          scanData.Serial = ''
          scanData.Serial = barCode3.slice(2)
          console.log(scanData.Serial, '序列号')
        }
      } else if (barCode1.slice(0, 2) === '17') {
        scanData.DisabledDatetime = ''
        scanData.DisabledDatetime = getYMDDate(barCode1.slice(2, 8))
        console.log(scanData.DisabledDatetime, '失效日期')
        const barCode4 = barCode1.slice(8)
        if (barCode4.slice(0, 2) === '10') {
          const index = barCode4.indexOf('21')
          if (index === -1) {
            scanData.LotCode = ''
            scanData.LotCode = barCode4.slice(2, index)
            console.log(scanData.LotCode, '批号')
          } else {
            scanData.Serial = ''
            scanData.Serial = barCode4.slice(index + 2)
            console.log(scanData.Serial, '序列号')
            scanData.LotCode = ''
            scanData.LotCode = barCode4.slice(2, index)
            console.log(scanData.LotCode, '批号')
          }
        } else if (barCode4.slice(0, 2) === '21') {
          scanData.Serial = ''
          scanData.Serial = barCode4.slice(2)
          console.log(scanData.Serial, '序列号')
        }
      } else if (barCode1.slice(0, 2) === '10') {
        scanData.LotCode = ''
        scanData.LotCode = barCode1.slice(-16, -8)
        console.log(scanData.LotCode, '批号')
        scanData.DisabledDatetime = ''
        scanData.DisabledDatetime = getYMDDate(barCode1.slice(-6))
        console.log(scanData.DisabledDatetime, '失效日期')
      } else if (barCode1.slice(0, 2) === '21') {
        scanData.Serial = ''
        scanData.Serial = barCode1.slice(2)
        console.log(scanData.Serial, '序列号')
      }
    }
  } else {
    console.log('这是HIBC码')
    if (barCode.slice(1, 2) === '$') {
      console.log('这是HIBC副码')
      if (barCode.slice(2, 3) === '$') {
        if (barCode.slice(3, 4) === '8') {
          if (barCode.slice(5, 6) === '2') {
            console.log(barCode.slice(12, -2), '批号')
          } else if (barCode.slice(5, 6) === '3') {
            console.log(barCode.slice(13, -2), '批号')
          } else if (barCode.slice(5, 6) === '4') {
            console.log(barCode.slice(15, -2), '批号')
          } else if (barCode.slice(5, 6) === '5') {
            console.log(barCode.slice(12, -2), '批号')
          } else if (barCode.slice(6, 7) === '6') {
            console.log(barCode.slice(14, -2), '批号')
          } else if (barCode.slice(6, 7) === '7') {
            console.log(barCode.slice(8, -2), '批号')
          }
        } else if (barCode.slice(3, 4) === '9') {
          if (barCode.slice(9, 10) === '2') {
            console.log(getMDYDate(barCode.slice(10, 16)), '失效日期')
            scanData.DisabledDatetime = ''
            scanData.DisabledDatetime = getMDYDate(barCode.slice(10, 16))
            console.log(barCode.slice(16, -2), '批号')
            scanData.LotCode = ''
            scanData.LotCode = barCode.slice(16, -2)
          } else if (barCode.slice(9, 10) === '3') {
            console.log(getYMDDate(barCode.slice(10, 16)), '失效日期')
            scanData.DisabledDatetime = ''
            scanData.DisabledDatetime = getYMDDate(barCode.slice(10, 16))
            console.log(barCode.slice(16, -2), '批号')
            scanData.LotCode = ''
            scanData.LotCode = barCode.slice(16, -2)
          } else if (barCode.slice(9, 10) === '4') {
            console.log(barCode.slice(18, -2), '批号')
          } else if (barCode.slice(9, 10) === '5') {
            console.log(getYJDate(barCode.slice(10, 15)), '失效日期')
            scanData.DisabledDatetime = ''
            scanData.DisabledDatetime = getYJDate(barCode.slice(10, 15))
            console.log(barCode.slice(15, -2), '批号')
            scanData.LotCode = ''
            scanData.LotCode = barCode.slice(15, -2)
          } else if (barCode.slice(9, 10) === '6') {
            console.log(barCode.slice(17, -2), '批号')
          } else if (barCode.slice(9, 10) === '7') {
            console.log(barCode.slice(11, -2), '批号')
          } else {
            console.log(getMYDate(barCode.slice(9, 13)), '失效日期')
            scanData.DisabledDatetime = ''
            scanData.DisabledDatetime = getMYDate(barCode.slice(9, 13))
            console.log(barCode.slice(13, -2), '批号')
            scanData.LotCode = ''
            scanData.LotCode = barCode.slice(13, -2)
          }
        } else {
          if (barCode.slice(3, 4) === '2') {
            console.log(barCode.slice(10, -2), '批号')
          } else if (barCode.slice(3, 4) === '3') {
            console.log(barCode.slice(10, -2), '批号')
          } else if (barCode.slice(3, 4) === '4') {
            console.log(barCode.slice(12, -2), '批号')
          } else if (barCode.slice(3, 4) === '5') {
            console.log(barCode.slice(9, -2), '批号')
          } else if (barCode.slice(3, 4) === '6') {
            console.log(barCode.slice(11, -2), '批号')
          } else if (barCode.slice(3, 4) === '7') {
            console.log(barCode.slice(4, -2), '批号')
          }
        }
      } else {

      }
    } else {
      console.log('这是HIBC主码')
      console.log(barCode.slice(5, -2), '型号')
      scanData.ItemModel = ''
      scanData.ItemModel = barCode.slice(5, -2)
    }
  }
  console.log(scanData)
  return scanData
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

js时间转化格式及UCC、HIBC条码解析 的相关文章

随机推荐

  • Java单例模式双检锁原理

    一 Java中什么是双检锁模式 xff1f 双检锁又名双重检查锁 xff0c 可以保证我们使用单例模式的时候避免多个线程竞争 xff0c 导致同一个对象被实例化多次 二 单例模式中除了双检锁还有什么模式 xff1f 还有比如饿汉式 xff0
  • 树莓派配置WIFI后连接失败的解决办法

    文章目录 01 问题 02 解决办法 问题的解决办法来源这个网站 xff0c 小白整理后分享 01 问题 新买的raspberry pi 3B 43 型号 xff0c 使用TF卡烧录raspbian stretch img镜像后 xff0c
  • Meta-learning(元学习)

    Meta learning meta learning是learning to learn meta learning是和machine learning并列的 相较于之前的机器学习算法 xff0c meta learning 是让机器学会
  • Scene understanding 场景理解

    depth estimation 深度估计属于场景理解
  • Pytorch之经典神经网络CNN(Extra-1) —— CNN可视化(查看中间层feature_map)

    从ZF Net开始人们就在研究神经网络和filter的可视化 结合了多篇文章整理了好久 xff0c 网上写的真的鱼龙混杂 xff0c 代码具有可操作性的不多 也或者是我的coding水平还没到 xff1f sad CNN可视化各层输出的fe
  • zsh安装及配置

    安装 sudo apt get install zsh centos的话 sudo yum install y zsh 然后就是下载oh my zsh 把 oh my zsh 项目 Clone 下来 xff1a git clone http
  • soft-nms(softnms)(pytorch实现)& softer nms

    softnms和softer nms是nms的两个改进算法 传统nms存在的问题 传统的NMS方法是基于分类分数的 xff0c 只有最高分数的预测框能留下来 xff0c 但是大多数情况下IoU和分类分数不是强相关 xff0c 很多分类标签置
  • 树莓派相关知识

    1 树莓派RS与E14版本的区别 树莓派分RS和E14版本 xff0c 由不同的代工厂生产 xff0c 除了外包装不一样 xff0c 硬件电路和功能一模一样 2 普通的计算机主板都是依靠硬盘来存储数据 xff0c 但是Raspberry P
  • CAS server6.x配置与部署笔记

    由于最近将公司的springboot升级到了springboot2 xff0c 而5 x的cas server使用的是springboot1 xff0c 因此为了更方便的开发cas server xff0c 将cas server升级为6
  • SQLyog复制数据库时,报错 “Unknown collation:’utf8mb4_0900_ai_ci'"

    原因为被复制的数据库的Collation为utf8mb4 0900 ai ci 为8 0版本 xff09 xff0c 而目标数据库为5 7版本 xff0c 不支持utf8mb4 0900 ai ci 解决方法 xff1a 将目标数据库更新为
  • 微信小程序背景图虚化

    微信小程序背景图虚化 filter blur 10rpx
  • 判断两个IP是否属于同一子网

    题目描述 子网掩码是用来判断任意两台计算机的IP地址是否属于同一子网络的根据 子网掩码与IP地址结构相同 xff0c 是32位二进制数 xff0c 其中网络号部分全为 1 和主机号部分全为 0 利用子网掩码可以判断两台主机是否中同一子网中
  • 状态模式

    状态模式允许对象在内部状态改变时改变它的行为 xff0c 对象看起来好像修改了它的类 它将一群行为封装在状态对象中 xff0c context的行为随时可委托到那些状态对象中的一个 随着时间的流逝 xff0c 当前状态在状态对象中游走改变
  • openstack cinder 双ceph后端之间的卷迁移操作

    1 前置条件 已为cinder配置好双ceph后端 xff0c 配置过程见openstack cinder对接两个ceph后端配置 2 卷类型相同的卷迁移 页面上的卷迁移 xff0c 走的是migrate volume接口 入口在cinde
  • KEIL软件的Error: Flash Download failed - Could not load file ‘...axf‘解决思路

    在下载程序的时候出现Error Flash Download failed Could not load file 39 的错误 xff0c 我的原因是之前勾选了下面这里的软件组件 xff0c 全部取消后就可以了
  • C# WinForm系列-创建Windows项目

    本系列实例适合初学者 xff0c 老手请直接Pass吧 Visual Studio从2003版本到现在的2022版本 xff0c 我也一版一版的使用 xff0c 体验了微软这个IDE开发工具的强大 唉 xff0c 我想多说点或上网多找点资料
  • vscode远程无密码登录

    1 安装插件 xff1a remote development 2 免密码登陆 xff1a vscode远程开发及公钥配置 xff08 告别密码登录 xff09 星轨 CSDN博客 vscode 公钥 当你完成全部设置 xff0c 并以密钥
  • Jetson Nano B01 从零入门笔记系列(二)python环境构建-pycharm安装-pytorch安装

    Jetson Nano B01 从零入门笔记系列 xff08 二 xff09 python环境构建 pycharm安装 pytorch安装Bug与报错 1 前言 时隔N年我居然又回来搞这个了 xff0c 真是命运弄人 为了应付万恶甲方的BT
  • 树莓派只能网线连接无法连接WiFi的解决方法

    最近几天树莓派好端端地突然连不上WiFi xff0c 右上角WiFi图标也显示异常 xff0c 无法看到周围可连接WiFi列表 xff0c 但却能连上wpa supplicant conf中配置好的另一个WiFi xff0c 插网线也无效
  • js时间转化格式及UCC、HIBC条码解析

    就记录下 xff0c 条形码解析写的很糟糕 xff0c 好多地方可以封装函数的 xff0c 所以有点乱 xff0c 直接复制过去还能用的 xff0c UCC条码只能解析包装代码 xff0c 通过包装代码获取型号是调后台接口 xff0c 然后