feat(工单管理): 添加工单成品数显示与计算逻辑
- 在工单列表和详情弹窗中添加成品数字段 - 修改出货、入库逻辑使用成品数进行计算 - 优化请求错误处理和默认操作员设置 - 调整axios配置缩进格式 - 移除冗余的catch块,使用统一错误处理
This commit is contained in:
@@ -12,110 +12,110 @@ let downloadLoadingInstance
|
||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
||||
// 创建axios实例
|
||||
const service = axios.create({
|
||||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||
// 超时
|
||||
timeout: 30000
|
||||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||
// 超时
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
// request拦截器
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
// 是否需要设置 token
|
||||
if (getToken()) {
|
||||
//将token放到请求头发送给服务器,将tokenkey放在请求头中
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken()
|
||||
config.headers['userid'] = useUserStore().userId
|
||||
config.headers['userName'] = encodeURIComponent(useUserStore().userName)
|
||||
}
|
||||
const method = config?.method || 'get'
|
||||
const header = config?.headers['Content-Type'] ?? ''
|
||||
(config) => {
|
||||
// 是否需要设置 token
|
||||
if (getToken()) {
|
||||
//将token放到请求头发送给服务器,将tokenkey放在请求头中
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken()
|
||||
config.headers['userid'] = useUserStore().userId
|
||||
config.headers['userName'] = encodeURIComponent(useUserStore().userName)
|
||||
}
|
||||
const method = config?.method || 'get'
|
||||
const header = config?.headers['Content-Type'] ?? ''
|
||||
|
||||
if ((method.toLowerCase() === 'post' || method.toLowerCase() === 'put') && header != 'multipart/form-data') {
|
||||
config.data = delEmptyQueryNodes(config.data)
|
||||
if ((method.toLowerCase() === 'post' || method.toLowerCase() === 'put') && header != 'multipart/form-data') {
|
||||
config.data = delEmptyQueryNodes(config.data)
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
console.log(error)
|
||||
Promise.reject(error)
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
console.log(error)
|
||||
Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 响应拦截器
|
||||
service.interceptors.response.use(
|
||||
(res) => {
|
||||
if (res.status !== 200) {
|
||||
Promise.reject('network error')
|
||||
return
|
||||
}
|
||||
// 未设置状态码则默认成功状态
|
||||
const { code, msg } = res.data
|
||||
// 二进制数据则直接返回
|
||||
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||
return res
|
||||
}
|
||||
var token = res.headers['x-refresh-token']
|
||||
if (token) {
|
||||
useUserStore().refreshToken(token)
|
||||
}
|
||||
if (code == 401) {
|
||||
ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
|
||||
confirmButtonText: '重新登陆',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
useUserStore()
|
||||
.logOut()
|
||||
.then(() => {
|
||||
location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index'
|
||||
})
|
||||
})
|
||||
(res) => {
|
||||
if (res.status !== 200) {
|
||||
Promise.reject('network error')
|
||||
return
|
||||
}
|
||||
// 未设置状态码则默认成功状态
|
||||
const { code, msg } = res.data
|
||||
// 二进制数据则直接返回
|
||||
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||
return res
|
||||
}
|
||||
var token = res.headers['x-refresh-token']
|
||||
if (token) {
|
||||
useUserStore().refreshToken(token)
|
||||
}
|
||||
if (code == 401) {
|
||||
ElMessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
|
||||
confirmButtonText: '重新登陆',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
useUserStore()
|
||||
.logOut()
|
||||
.then(() => {
|
||||
location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + 'index'
|
||||
})
|
||||
})
|
||||
|
||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
||||
} else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 403 || code == 500 || code == 429) {
|
||||
ElMessage({
|
||||
message: msg,
|
||||
type: 'error'
|
||||
})
|
||||
return Promise.reject(res.data)
|
||||
} else {
|
||||
//返回标准 code/msg/data字段
|
||||
return res.data
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error('axios err', error)
|
||||
var duration = 3000
|
||||
let { message, response } = error
|
||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
||||
} else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 403 || code == 500 || code == 429) {
|
||||
ElMessage({
|
||||
message: msg,
|
||||
type: 'error'
|
||||
})
|
||||
return Promise.reject(res.data)
|
||||
} else {
|
||||
//返回标准 code/msg/data字段
|
||||
return res.data
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error('axios err', error)
|
||||
var duration = 3000
|
||||
let { message, response } = error
|
||||
|
||||
if (response.status == 404) {
|
||||
message = '接口404'
|
||||
} else if (response.status == 403) {
|
||||
window.location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + '401'
|
||||
} else if (message == 'Network Error') {
|
||||
message = '后端接口连接异常'
|
||||
} else if (message.includes('timeout')) {
|
||||
message = '系统接口请求超时'
|
||||
} else if (message.includes('code 429')) {
|
||||
message = '请求过于频繁,请稍后再试'
|
||||
} else if (message.includes('Request failed with status code')) {
|
||||
message = '系统接口' + message.substr(message.length - 3) + '异常,请联系管理员'
|
||||
if (response.status == 404) {
|
||||
message = '接口404'
|
||||
} else if (response.status == 403) {
|
||||
window.location.href = import.meta.env.VITE_APP_ROUTER_PREFIX + '401'
|
||||
} else if (message == 'Network Error') {
|
||||
message = '后端接口连接异常'
|
||||
} else if (message.includes('timeout')) {
|
||||
message = '系统接口请求超时'
|
||||
} else if (message.includes('code 429')) {
|
||||
message = '请求过于频繁,请稍后再试'
|
||||
} else if (message.includes('Request failed with status code')) {
|
||||
message = '系统接口' + message.substr(message.length - 3) + '异常,请联系管理员'
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
message = 'Oops,后端出错了,你不会连错误日志都不会看吧'
|
||||
duration = 0
|
||||
}
|
||||
if (import.meta.env.DEV) {
|
||||
message = '服务器正在重启中'
|
||||
duration = 0
|
||||
}
|
||||
}
|
||||
ElMessage({
|
||||
message: message,
|
||||
type: 'error',
|
||||
duration: duration,
|
||||
showClose: true,
|
||||
grouping: true
|
||||
})
|
||||
return Promise.reject({ code: 500, msg: message })
|
||||
}
|
||||
ElMessage({
|
||||
message: message,
|
||||
type: 'error',
|
||||
duration: duration,
|
||||
showClose: true,
|
||||
grouping: true
|
||||
})
|
||||
return Promise.reject({ code: 500, msg: message })
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -124,33 +124,33 @@ service.interceptors.response.use(
|
||||
* @param {Object} params [请求时携带的参数]
|
||||
*/
|
||||
export function get(url, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
service
|
||||
.get(url, {
|
||||
params: params
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
service
|
||||
.get(url, {
|
||||
params: params
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function post(url, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
service
|
||||
.post(url, {
|
||||
params: params
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
service
|
||||
.post(url, {
|
||||
params: params
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,16 +159,16 @@ export function post(url, params) {
|
||||
* @param {*} data
|
||||
*/
|
||||
export function postForm(url, data, config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
service
|
||||
.post(url, data, config)
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
service
|
||||
.post(url, data, config)
|
||||
.then((res) => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,48 +179,48 @@ export function postForm(url, data, config) {
|
||||
* @returns
|
||||
*/
|
||||
export async function downFile(url, params, config) {
|
||||
downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' })
|
||||
downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' })
|
||||
|
||||
service
|
||||
.get(url, {
|
||||
params,
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
responseType: 'blob',
|
||||
...config
|
||||
})
|
||||
.then(async (resp) => {
|
||||
const { data } = resp
|
||||
|
||||
const isLogin = await blobValidate(data)
|
||||
if (isLogin) {
|
||||
var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
|
||||
var contentDisposition = decodeURI(resp.headers['content-disposition'])
|
||||
var result = patt.exec(contentDisposition)
|
||||
var fileName = result[1]
|
||||
fileName = fileName.replace(/\"/g, '')
|
||||
|
||||
const blob = new Blob([data])
|
||||
saveAs(blob, fileName)
|
||||
} else {
|
||||
const resText = await data.text()
|
||||
const rspObj = JSON.parse(resText)
|
||||
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
||||
|
||||
ElMessage({
|
||||
message: errMsg,
|
||||
type: 'error'
|
||||
service
|
||||
.get(url, {
|
||||
params,
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
responseType: 'blob',
|
||||
...config
|
||||
})
|
||||
.then(async (resp) => {
|
||||
const { data } = resp
|
||||
|
||||
const isLogin = await blobValidate(data)
|
||||
if (isLogin) {
|
||||
var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
|
||||
var contentDisposition = decodeURI(resp.headers['content-disposition'])
|
||||
var result = patt.exec(contentDisposition)
|
||||
var fileName = result[1]
|
||||
fileName = fileName.replace(/\"/g, '')
|
||||
|
||||
const blob = new Blob([data])
|
||||
saveAs(blob, fileName)
|
||||
} else {
|
||||
const resText = await data.text()
|
||||
const rspObj = JSON.parse(resText)
|
||||
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
||||
|
||||
ElMessage({
|
||||
message: errMsg,
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage({
|
||||
message: '下载文件出现错误,请联系管理员!',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
downloadLoadingInstance.close()
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage({
|
||||
message: '下载文件出现错误,请联系管理员!',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
downloadLoadingInstance.close()
|
||||
})
|
||||
}
|
||||
|
||||
export default service
|
||||
|
||||
@@ -50,6 +50,12 @@
|
||||
<el-form-item label="计划数量">
|
||||
<el-input :disabled="!isEditing" v-model="workorderInfo.planNum" />
|
||||
</el-form-item>
|
||||
<el-form-item label="不良数量">
|
||||
<el-input :disabled="!isEditing" v-model="workorderInfo.defectNum" />
|
||||
</el-form-item>
|
||||
<el-form-item label="成品数量">
|
||||
<el-input :disabled="!isEditing" v-model="workorderInfo.productNum" />
|
||||
</el-form-item>
|
||||
<el-form-item label="出货数量">
|
||||
<el-input :disabled="!isEditing" v-model="workorderInfo.shipmentNum" />
|
||||
</el-form-item>
|
||||
|
||||
@@ -485,19 +485,15 @@ function handleCancel(row) {
|
||||
type: 'warning'
|
||||
})
|
||||
.then(() => {
|
||||
cancelMmInventory({ id: row.id, type: 2 })
|
||||
.then((response) => {
|
||||
if (response.code === 200) {
|
||||
proxy.$message.success('撤销成功')
|
||||
loadPickRecords()
|
||||
loadInventoryList()
|
||||
} else {
|
||||
proxy.$message.error('撤销失败: ' + (response.msg || '未知错误'))
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
proxy.$message.error('撤销失败: ' + error.message)
|
||||
})
|
||||
cancelMmInventory({ id: row.id, type: 2 }).then((response) => {
|
||||
if (response.code === 200) {
|
||||
proxy.$message.success('撤销成功')
|
||||
loadPickRecords()
|
||||
loadInventoryList()
|
||||
} else {
|
||||
proxy.$message.error('撤销失败: ' + (response.msg || '未知错误'))
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
// 取消操作
|
||||
@@ -532,13 +528,12 @@ function submitForm() {
|
||||
// 刷新数据
|
||||
loadPickRecords()
|
||||
loadInventoryList()
|
||||
// 触发外部工单列表更新
|
||||
emit('submit', { type: 'materialPick', data: requestData })
|
||||
} else {
|
||||
proxy.$message.error('领料失败: ' + (response.msg || '未知错误'))
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
proxy.$message.error('领料失败: ' + error.message)
|
||||
})
|
||||
.finally(() => {
|
||||
// 关闭加载状态
|
||||
proxy.$modal.closeLoading()
|
||||
|
||||
@@ -313,7 +313,13 @@ function handleStorageMaterial() {
|
||||
if (props.workorderInfo) {
|
||||
formData.productionCode = props.workorderInfo.productionCode || ''
|
||||
formData.productionName = props.workorderInfo.productionName || ''
|
||||
formData.storageQuantity = props.workorderInfo.planNum || 1
|
||||
// 重新计算入库数量,使用最新的工单数据
|
||||
// 计划数量减去已入库数量
|
||||
formData.storageQuantity = (props.workorderInfo.planNum || 0) - (props.workorderInfo.productNum || 0)
|
||||
// 确保入库数量至少为1
|
||||
if (formData.storageQuantity < 1) {
|
||||
formData.storageQuantity = 1
|
||||
}
|
||||
}
|
||||
// 显示入库单据弹窗
|
||||
showStorageForm.value = true
|
||||
@@ -328,19 +334,15 @@ function handleCancel(row) {
|
||||
type: 'warning'
|
||||
})
|
||||
.then(() => {
|
||||
cancelMmInventory({ id: row.id, type: 1 })
|
||||
.then((response) => {
|
||||
if (response.code === 200) {
|
||||
proxy.$message.success('撤销成功')
|
||||
loadStorageRecords()
|
||||
loadInventoryList()
|
||||
} else {
|
||||
proxy.$message.error('撤销失败: ' + (response.msg || '未知错误'))
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
proxy.$message.error('撤销失败: ' + error.message)
|
||||
})
|
||||
cancelMmInventory({ id: row.id, type: 1 }).then((response) => {
|
||||
if (response.code === 200) {
|
||||
proxy.$message.success('撤销成功')
|
||||
loadStorageRecords()
|
||||
loadInventoryList()
|
||||
} else {
|
||||
proxy.$message.error('撤销失败: ' + (response.msg || '未知错误'))
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
// 取消操作
|
||||
@@ -372,13 +374,12 @@ function submitForm() {
|
||||
// 刷新数据
|
||||
loadStorageRecords()
|
||||
loadInventoryList()
|
||||
// 触发外部工单列表更新
|
||||
emit('submit', { type: 'productStorage', data: requestData })
|
||||
} else {
|
||||
proxy.$message.error('入库失败: ' + (response.msg || '未知错误'))
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
proxy.$message.error('入库失败: ' + error.message)
|
||||
})
|
||||
.finally(() => {
|
||||
// 关闭加载状态
|
||||
proxy.$modal.closeLoading()
|
||||
|
||||
@@ -285,8 +285,8 @@ function resetForm() {
|
||||
// 重置表单数据
|
||||
Object.assign(formData, {
|
||||
selectedOrderNo: '',
|
||||
shipmentQuantity: props.workorderInfo?.planNum - props.workorderInfo?.defectNum || 1,
|
||||
operator: '',
|
||||
shipmentQuantity: 1,
|
||||
operator: '解建雄',
|
||||
orderId: ''
|
||||
})
|
||||
// 如果有工单信息,保持工单相关数据
|
||||
@@ -315,7 +315,13 @@ function handleShipmentMaterial(product) {
|
||||
formData.productionName = product.materialName
|
||||
formData.selectedOrderNo = product.orderNoMes
|
||||
formData.orderId = product.id
|
||||
formData.shipmentQuantity = props.workorderInfo?.planNum || 1
|
||||
// 重新计算出货数量,使用最新的工单数据
|
||||
// 已入库数量减去已出货数量
|
||||
formData.shipmentQuantity = (props.workorderInfo.productNum || 0) - (props.workorderInfo.shipmentNum || 0)
|
||||
// 确保出货数量至少为1
|
||||
if (formData.shipmentQuantity < 1) {
|
||||
formData.shipmentQuantity = 1
|
||||
}
|
||||
// 显示出货单据弹窗
|
||||
showShipmentForm.value = true
|
||||
}
|
||||
@@ -374,13 +380,13 @@ function submitForm() {
|
||||
// 刷新数据
|
||||
loadShipmentRecords()
|
||||
loadInventoryList()
|
||||
// 触发外部工单列表更新
|
||||
emit('submit', { type: 'shipment', data: requestData })
|
||||
} else {
|
||||
console.log('response1', response)
|
||||
proxy.$message.error('出货失败: ' + (response.msg || '未知错误'))
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
proxy.$message.error('出货失败: ' + error.message)
|
||||
})
|
||||
.finally(() => {
|
||||
// 关闭加载状态
|
||||
proxy.$modal.closeLoading()
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
<el-table-column prop="stoveCode" label="炉号" width="100" />
|
||||
<el-table-column prop="planNum" align="center" label="计划数" width="60" />
|
||||
<el-table-column prop="defectNum" align="center" label="不良数" width="60" />
|
||||
<el-table-column prop="productNum" align="center" label="成品数" width="60" />
|
||||
<el-table-column prop="shipmentNum" align="center" label="出货数" width="60" />
|
||||
<el-table-column prop="feedOrder" label="原料批次号" width="120" />
|
||||
<el-table-column prop="customerOrder" label="订单号" width="120" />
|
||||
|
||||
Reference in New Issue
Block a user