init: CATL电池线返修工位APP首次入库

This commit is contained in:
XingCheng3
2026-06-08 17:11:43 +08:00
commit 056af96557
71 changed files with 43178 additions and 0 deletions

103
src/utils/mqtt.js Normal file
View File

@@ -0,0 +1,103 @@
import { v4 as uuid } from 'uuid'
import mqtt from 'mqtt'
class Mqtt {
constructor (config) {
this.connection = {
host: config.host,
port: config.port,
endpoint: config.endpoint || '/mqtt',
clean: config.clean || true,
connectTimeout: config.connectTimeout || 4000,
reconnectPeriod: config.reconnectPeriod || 4000,
clientId: config.clientId || uuid(),
username: config.username || '',
password: config.password || ''
}
this.client = {
connected: false
}
}
// 创建连接
createConnection () {
// 连接字符串, 通过协议指定使用的连接方式
// ws 未加密 WebSocket 连接
// wss 加密 WebSocket 连接
// mqtt 未加密 TCP 连接
// mqtts 加密 TCP 连接
// wxs 微信小程序连接
// alis 支付宝小程序连接
const { host, port, endpoint, ...options } = this.connection
const connectUrl = `ws://${host}:${port}${endpoint}`
try {
this.client = mqtt.connect(connectUrl, options)
} catch (error) {
// 连接错位、
this.connectError(error)
}
}
connectError (error) {
console.log('mqtt.connect error', error)
}
// 订阅主题
doSubscribe (subscription) {
const { topic, qos } = subscription
let subscribeSuccess = false
this.client.subscribe(topic, { qos }, (error, res) => {
if (error) {
subscribeSuccess = false
console.log('Subscribe to topics error', error)
} else {
subscribeSuccess = true
console.log('Subscribe to topics res', res)
}
})
return subscribeSuccess
}
// 取消订阅
doUnSubscribe (subscription) {
const { topic } = subscription
let unSubscribeSuccess = false
this.client.unsubscribe(topic, error => {
if (error) {
unSubscribeSuccess = false
console.log('Unsubscribe error', error)
} else {
unSubscribeSuccess = true
}
})
return unSubscribeSuccess
}
// 发送消息
doPublish (publish) {
const { topic, qos, payload } = publish
let doPublishSuccess = false
this.client.publish(topic, payload, qos, error => {
if (error) {
doPublishSuccess = false
console.log('Publish error', error)
} else {
doPublishSuccess = true
}
})
return doPublishSuccess
}
// 断开连接
destroyConnection () {
let destroyConnectionSuccess = false
if (this.client.connected) {
try {
this.client.end()
this.client = {
connected: false
}
destroyConnectionSuccess = true
console.log('Successfully disconnected!')
} catch (error) {
destroyConnectionSuccess = false
console.log('Disconnect failed', error.toString())
}
}
return destroyConnectionSuccess
}
}
export { Mqtt }

90
src/utils/mqttStart.js Normal file
View File

@@ -0,0 +1,90 @@
import {
Mqtt
} from '@/utils/mqtt.js'
import store from '@/store/index.js'
function init (pdaId, mqttConnection, subscription, publication) {
store.dispatch('savePdaId', pdaId)
store.dispatch('saveMqttConnection', mqttConnection)
store.dispatch('saveSubscription', subscription)
store.dispatch('savePublication', publication)
// store.dispatch('saveMqttClient', );
// pdaId = pdaId
// mqttConnection = mqttConnection
// console.log(mqttConnection);
// subscription = subscription
// publication = publication
connectMqtt()
}
function connectMqtt () {
let mqttClient = store.state.mqttClient
mqttClient = new Mqtt(store.state.mqttConnection)
mqttClient.createConnection()
mqttClient.client.on('connect', () => {
console.log('MQTT Connection succeeded!')
})
mqttClient.doSubscribe(store.state.subscription)
// 使用过程中的报错 断开连接 服务端出问题
mqttClient.client.on('error', error => {
console.log('Connection failed', error)
})
mqttClient.client.on('message', (topic, message) => {
mqttOnMessage(topic, message)
})
}
function disConnectMqtt () {
if (store.state.mqttConnection) {
store.state.mqttConnection.destroyConnection()
store.state.mqttConnection = null
}
}
function mqttOnMessage (topic, message) {
let pdaId = 'PDA_1010'
// console.log(topic, message.toString())
const arraysSignal = message.toString().split('|')
const mSource = arraysSignal[0] // MES
// const m_Command = arraysSignal[1]
const mOpName = arraysSignal[2]
switch (mSource) {
case 'BarCode':
switch (mOpName) {
case pdaId:
// const BarValue = arraysSignal[3]
connectMessage(arraysSignal[3], message)
// uni.$emit("connect-mqttOnMessage", arraysSignal[3], message)
// this.mqttSendMessage(`PDABarCode|Bar|${mOpName}|${BarValue}`)
break
default:
console.log(`消息工位号不匹配:${message.toString()};工位号:${pdaId}`)
break
}
break
default:
console.log(`消息来源不匹配:${message.toString()};工位号:${pdaId}`)
break
}
}
function connectMessage (val, msg) {
// window.dispatchEvent(new CustomEvent('onmessageMqtt', {
// detail: {
// data: val
// }
// }))
// window.addEventListener('onmessageMqtt', this.getMqttMessage)
store.dispatch('saveMqttMsg', val)
}
// function mqttSendMessage (message) {
// publication.payload = message
// mqttClient.doPublish(this.publication)
// }
export {
init,
mqttOnMessage,
disConnectMqtt,
connectMessage
}

35
src/utils/request.js Normal file
View File

@@ -0,0 +1,35 @@
import axios from 'axios'
var requestConfig = window.dt_Config.requestConfig
// `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL。
let baseURL = ''
const instance = axios.create({
baseURL: baseURL,
timeout: 10000,
headers: {}
})
// 另一种配置超时时间
instance.defaults.timeout = 25000
function request ({
url = '',
method = 'get',
data = {},
params = {}
}) {
if (!url) {
url = requestConfig
}
return new Promise((resolve, reject) => {
instance({
method: method,
url: url,
data: data,
params: params
}).then(resolve).catch(err => {
reject(err)
})
})
}
export default request

391
src/utils/tool.js Normal file
View File

@@ -0,0 +1,391 @@
import request from '@/utils/request'
// 传通讯服务器参数
export default {
install (Vue) {
// 用于生成传通讯服务器参数。
// 传入参数
// 1type11查询12增删改必须
// 2name存储过程名必须
// 3data存储过程参数名和对应值例如
// param[0] = ['设备类型编码', '3', 'string', '0']
// param[1] = ['output', '3', 'int', '1'],必须
// 数组里四个分别对应存储过程参数名必须存储过程参数值必须参数类型若是output必须参数是否为output0否1是
// 4pageSizepageList分页使用可选
// 旧通讯格式
Vue.prototype.CreateData1 = function (type, name, data, pageSize, pageList) {
var paramStr = ''
var paramarray = []
if (type === '7') {
data.map(v => {
pageSize.map(h => {
const val = h.toString()
if (!v[val]) {
this.$set(v, val, '')
}
})
})
paramStr = data
} else {
if (data !== undefined) {
for (let i = 0; i < data.length; i++) {
paramarray.push({
name: data[i][0],
value: data[i][1],
type: data[i][2],
output: data[i][3]
})
}
paramStr = JSON.stringify(paramarray)
}
}
var obj = []
obj[0] = {}
obj[0].type = type
obj[0].name = name
obj[0].param = paramStr
obj[0].pageSize = pageSize
obj[0].pageList = pageList
var numn = JSON.stringify(obj[0])
return numn
}
// 新通讯格式
Vue.prototype.CreateData = (cmd, tbname, fieldshow, other) => {
const Param = JSON.stringify({
cmd,
tbname,
fieldshow,
...other
})
const data = {
type: 3001,
Param,
Name: '',
Pagination: '',
UserID: '',
HasReturn: false
}
return JSON.stringify(data)
}
// 新通讯11/12---<
Vue.prototype.ExecDatabase = function (num) {
return request({
url: '',
method: 'post',
data: num
})
}
// 设置字段宽度
Vue.prototype.setColumnWidth = function (str) {
let columnWidth = 0
if (str === '日期') {
columnWidth = 100
} else if (str === '工单号' || str === '产品名称') {
columnWidth = 160
} else if (str === '规则型号' || str === '产品编号') {
columnWidth = 150
} else if (str === '大数') {
columnWidth = 110
} else if (str === '状态') {
columnWidth = 100
} else if (str === '序号') {
columnWidth = 60
} else if (str === '单位') {
columnWidth = 60
} else if (str === '数量' || str === '库存') {
columnWidth = 80
} else if (str === '单价') {
columnWidth = 90
} else if (str === '金额') {
columnWidth = 120
} else if (str === '状态' || str === '类型' || str === '选入' || str === '选出') {
columnWidth = 80
} else if (str === '付款方式') {
columnWidth = 100
} else if (str === '买方' || str === '买方名称') {
columnWidth = 150
} else if (str === '外协厂家' || str === '调入仓库' || str === '调出仓库') {
columnWidth = 150
} else if (str === '姓名') {
columnWidth = 80
} else if (str === '日期时间') {
columnWidth = 140
} else if (str === '工序') {
columnWidth = 80
} else if (str === '物料名称' || str === '工件名称' || str === '零件名称') {
columnWidth = 140
} else if (str === '图号或型号' || str === '规格' || str === '零件图号' || str === '图号' || str === '图号/型号') {
columnWidth = 120
} else if (str === '物料编码' || str === '物料编号') {
columnWidth = 120
} else if (str === '材料') {
columnWidth = 80
} else if (str === '仓位' || str === '库位') {
columnWidth = 90
} else if (str === '品名/规格/型号') {
columnWidth = 140
} else if (str === '备注') {
columnWidth = 120
} else if (str === '工序名称') {
columnWidth = 150
} else if (str === '工序说明') {
columnWidth = 300
} else if (str === '加工工时M' || str === '加工时长H' || str === '加工时长M') {
columnWidth = 90
} else if (str === '加工设备') {
columnWidth = 130
} else if (str === '产品详情' || str === '详情') {
columnWidth = 340
} else if (str === '最低库存') {
columnWidth = 110
} else if (str === '本次到货数' || str === '本次入库' || str === '补货数') {
columnWidth = 100
} else {
columnWidth = 110
}
return columnWidth
}
}
}
export function getNowTime2() {
const date = new Date()
const month = zeroFill2(date.getMonth() + 1)
const day = zeroFill(date.getDate())
const time = date.getFullYear() + '-' + month + '-' + day
return time
}
function zeroFill2(i) {
if (i >= 0 && i <= 9) {
if (i === 0) {
return '01'
} else {
return '0' + i
}
} else {
return i
}
}
export function getBeforeOrAfterTime(AddDayCount) {
var dd = new Date()
dd.setDate(dd.getDate() + AddDayCount)// 获取AddDayCount天后的日期
var y = dd.getFullYear()
var m = (dd.getMonth() + 1) < 10 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1)// 获取当前月份的日期不足10补0
var d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate()// 获取当前几号不足10补0
return y + '-' + m + '-' + d
}
// 数组去重s
export function arrayUnique (arr) {
arr.filter((element, index, arr) => {
return arr.indexOf(element) === index
})
}
// 时间转时间戳
export function timeToStamp (time) {
const date = new Date(time)
return date.getTime()
}
// 数组的深度拷贝
export function arrDeepCopy (arr) {
const newArr = []
for (const prop in arr) newArr[prop] = typeof arr[prop] === 'object' ? arrDeepCopy(arr[prop]) : arr[prop]
return newArr
}
// 对象的深度拷贝
export function objDeepCopy (obj) {
const newObj = {}
for (const prop in obj) newObj[prop] = typeof obj[prop] === 'object' ? objDeepCopy(obj[prop]) : obj[prop]
return newObj
}
function zeroFill (i) {
if (i >= 0 && i <= 9) {
return '0' + i
} else {
return i
}
}
// 获取当前日期时间
export function getNowTime () {
const date = new Date()
const month = zeroFill(date.getMonth() + 1)
const day = zeroFill(date.getDate())
const hour = zeroFill(date.getHours())
const minute = zeroFill(date.getMinutes())
const second = zeroFill(date.getSeconds())
const time = date.getFullYear() + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
return time
}
export function formatDate(date) {
const month = zeroFill2(date.getMonth() + 1)
const day = zeroFill(date.getDate())
const time = date.getFullYear() + '-' + month + '-' + day
return time//时间戳转日期格式
}
// 获取当前日期
export function getNowDate () {
const date = new Date()
const month = zeroFill(date.getMonth() + 1)
const day = zeroFill(date.getDate())
const time = date.getFullYear() + '-' + month + '-' + day
return time
}
// 获取当前时间
export function getNowDate1 () {
const date = new Date()
const hour = zeroFill(date.getHours())
const minute = zeroFill(date.getMinutes())
const second = zeroFill(date.getSeconds())
const time = hour + ':' + minute + ':' + second
return time
}
// 每月1号
export function getTime1 () {
const date = new Date()
const month = zeroFill(date.getMonth() + 1)
const time = date.getFullYear() + '-' + month + '-' + '01'
return time
}
// 工时统计上个月26-本月25
export function getTime26 () {
const date = new Date()
const day = date.getDate()
if (day > 25) {
var month = zeroFill(date.getMonth() + 1)
if (month === 0) {
month = 12
const day = 26
const time = date.getFullYear() - 1 + '-' + month + '-' + day
return time
} else {
const day = 26
const time = date.getFullYear() + '-' + month + '-' + day
return time
}
} else {
var month2 = zeroFill(date.getMonth() + 1) - 1
if (month2 === 0) {
month2 = 12
const day = 26
const time = date.getFullYear() - 1 + '-' + month2 + '-' + day
return time
} else {
const day = 26
const time = date.getFullYear() + '-' + month2 + '-' + day
return time
}
}
}
export function getTime25 () {
const date = new Date()
const day = date.getDate()
var time
if (day > 25) {
const month = zeroFill(date.getMonth() + 2)
const day2 = 25
if (month === 13) {
const month = 1
time = (date.getFullYear() + 1) + '-' + month + '-' + day2
} else {
time = date.getFullYear() + '-' + month + '-' + day2
}
return time
} else {
const month = zeroFill(date.getMonth() + 1)
const day2 = 25
if (month === 13) {
const month = 1
time = (date.getFullYear() + 1) + '-' + month + '-' + day2
} else {
time = date.getFullYear() + '-' + month + '-' + day2
}
return time
}
}
// 判断类型
export function type (target) {
const ret = typeof (target)
const template = {
'[object Array]': 'array',
'[object Object]': 'object',
'[object String]': 'string - object',
'[object Number]': 'Number - object',
'[object Boolean]': 'Boolean - object'
}
if (target === null) {
return 'null'
}
if (ret === 'object') {
const str = Object.prototype.toString.call(target)
return template[str]
} else {
return ret
}
}
export function SectionToChinese (section) {
const chnNumChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
const chnUnitChar = ['', '十', '百', '千']
let strIns = ''
let chnStr = ''
let unitPos = 0
let zero = true
while (section > 0) {
const v = section % 10
if (v === 0) {
if (!zero) {
zero = true
chnStr = chnNumChar[v] + chnStr
}
} else {
zero = false
strIns = chnNumChar[v]
strIns += chnUnitChar[unitPos]
chnStr = strIns + chnStr
}
unitPos++
section = Math.floor(section / 10)
}
return chnStr
}
export function sleep (time) {
return new Promise(resolve => {
setTimeout(resolve, time)
})
}
export function groupBy (datas, keys) {
const list = datas || []
const groups = []
const result = []
list.forEach(v => {
const key = {}
keys.forEach(k => {
key[k] = v[k]
})
let group = groups.find(v => {
return v._key === JSON.stringify(key)
})
if (!group) {
group = {
_key: JSON.stringify(key),
key: key
}
groups.push(group)
}
group.data1 = group.data1 || 0
group.key.数量 = group.data1 += v.数量
group.data2 = group.data2 || ''
group.key.机床图号_组号 = group.data2 += (v.机床图号 || '') + '-' + (v.组号 ? v.组号.split('组')[0] : '') + ';'
})
groups.map(v => {
result.push(v.key)
})
return result
}