refactor(wms/mes): 统一多场景查询逻辑,移除关键字混搜
1. 移除所有多字段关键字混搜,改为各筛选字段独立查询 2. 调整excel导出相关逻辑,优化文件名处理与导入模板 3. 修复物料导入的类型解析与token获取逻辑 4. 更新依赖与前端页面文案、筛选参数
This commit is contained in:
@@ -6,6 +6,7 @@ import request from '../utils/request'
|
||||
import { fmtTime } from '../utils/format'
|
||||
import { can } from '../utils/perm'
|
||||
import { exportXlsxFetch } from '../utils/export'
|
||||
import { getToken } from '../utils/auth'
|
||||
import PageHelp from '../components/PageHelp.vue'
|
||||
import { helpZone, helpMaterial } from '../help'
|
||||
|
||||
@@ -237,16 +238,18 @@ async function onMaterialFile(e) {
|
||||
try {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
const token = JSON.parse(localStorage.getItem('token') || '""')
|
||||
// 注意:token 是纯文本存储,不能用 JSON.parse(会对 JWT 抛 SyntaxError 误报"导入异常")
|
||||
const res = await fetch('/api/material/import', {
|
||||
method: 'POST',
|
||||
headers: { Authorization: 'Bearer ' + token },
|
||||
headers: { Authorization: 'Bearer ' + getToken() },
|
||||
body: fd
|
||||
})
|
||||
const body = await res.json().catch(() => ({}))
|
||||
const body = await res.json().catch(() => null)
|
||||
const d = body?.data || {}
|
||||
if (!res.ok || body?.code !== 0) {
|
||||
ElMessage.error('导入失败:' + (body?.message || '未知错误'))
|
||||
// 业务/权限错误:优先展示后端中文 message;解析不出 body 时按 HTTP 状态给中文提示
|
||||
const httpText = res.status === 401 ? '登录已过期,请重新登录' : `服务器错误(${res.status})`
|
||||
ElMessage.error('导入失败:' + (body?.message || httpText))
|
||||
return
|
||||
}
|
||||
if (d.errors && d.errors.length) {
|
||||
@@ -258,7 +261,7 @@ async function onMaterialFile(e) {
|
||||
ElMessage.success(`导入成功 ${d.success || 0} 条`)
|
||||
await loadMaterials()
|
||||
} catch (err) {
|
||||
ElMessage.error('导入异常:' + (err?.message || err))
|
||||
ElMessage.error('导入失败:网络异常或登录已过期,请刷新页面重试')
|
||||
} finally {
|
||||
matImporting.value = false
|
||||
}
|
||||
@@ -373,7 +376,7 @@ async function onMaterialFile(e) {
|
||||
<el-button type="success" @click="openMatCreate">新增物料</el-button>
|
||||
<el-button v-if="can('material:import')" type="warning" :loading="matImporting" @click="pickMaterialFile">导入</el-button>
|
||||
<el-button v-if="can('material:export')" :loading="matExporting" @click="exportMaterials">导出</el-button>
|
||||
<el-tooltip v-if="can('material:import')" content="Excel 模板(首行表头):物料编码 | 名称 | 简称 | 规格 | 单位 | 类型(1结构件/2精密件) | 说明">
|
||||
<el-tooltip v-if="can('material:import')" content="Excel 模板(首行表头):物料编码 | 名称 | 简称 | 规格 | 单位 | 类型(结构件/精密件) | 说明">
|
||||
<el-link type="info" :underline="false" style="margin-left:4px">导入说明</el-link>
|
||||
</el-tooltip>
|
||||
<input ref="matFileRef" type="file" accept=".xlsx,.xls" style="display:none" @change="onMaterialFile" />
|
||||
|
||||
Reference in New Issue
Block a user