Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
template_vue
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨硕
template_vue
Commits
0f1dfefb
Commit
0f1dfefb
authored
Mar 26, 2025
by
liwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ocr识别
parent
3bf78e93
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
376 additions
and
693 deletions
+376
-693
chCheckOrder.js
src/api/sample/chCheckOrder.js
+24
-0
data.js
src/api/system/dict/data.js
+8
-0
ACheckOrders.vue
src/views/sample/chCheckOrder/CheckOrders/ACheckOrders.vue
+224
-612
index.vue
src/views/sample/chCheckOrder/index.vue
+120
-81
No files found.
src/api/sample/chCheckOrder.js
View file @
0f1dfefb
...
...
@@ -15,3 +15,27 @@ export function aliOcr(businessId) {
})
}
// 获取ocr扫描数据
export
function
getOcrData
(
params
)
{
return
request
({
url
:
'/chcheckorder/submit'
,
method
:
'post'
,
data
:
params
,
headers
:
{
'Content-Type'
:
'application/json;charset=UTF-8'
}
})
}
// 新增扫描的数据
export
function
addOcrData
(
params
)
{
return
request
({
url
:
'/chcheckorder/add'
,
method
:
'post'
,
data
:
params
,
headers
:
{
'Content-Type'
:
'application/json;charset=UTF-8'
}
})
}
src/api/system/dict/data.js
View file @
0f1dfefb
...
...
@@ -105,3 +105,11 @@ export function importExcel(data) {
})
}
// 8.根据字典类型查询字典数据信息
export
function
getDict
(
dictType
)
{
return
request
({
url
:
'/system/dict/data/type/'
+
dictType
,
method
:
'get'
})
}
src/views/sample/chCheckOrder/CheckOrders/ACheckOrders.vue
View file @
0f1dfefb
...
...
@@ -4,251 +4,32 @@
<el-table
:data=
"tableData"
style=
"width: 100%"
:
cell-style=
"cellStyle
"
:
span-method=
"arraySpanMethod
"
>
<el-table-column
prop=
"NO"
label=
"规格(项目)MM"
v-for=
"(item, index) in tableHeader"
:key=
"index"
:label=
"item.label"
:prop=
"item.prop"
fixed
/>
<el-table-column
prop=
"difference"
label=
"区分"
fixed
/>
<el-table-column
prop=
"measureInstrument"
label=
"测定器"
fixed
/>
<el-table-column
prop=
"one"
label=
"1"
width=
"130"
>
<template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.one"
:class=
"
{ 'error-border': scope.row.error }"
style="background-color: transparent"
@change="(value)=>ocrVerify(value,scope.row,scope.column.property)"
/>
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"two"
label=
"2"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.two"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"three"
label=
"3"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.three"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"four"
label=
"4"
width=
"130"
>
<template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.four"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"five"
label=
"5"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.five"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"six"
label=
"6"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.six"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
<div
v-if=
"index
<
fixedColumnCount
"
>
{{
scope
.
row
[
index
]
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"seven"
label=
"7"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-
model=
"scope.row.seven
"
:class=
"
{ 'error-border': scope.row.error }
"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)
"
v-
if=
"dataVerify(scope.row,scope.row[index],scope.column)
"
v-model=
"scope.row[index]
"
style=
"background-color: transparent;
"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"eight"
label=
"8"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.eight"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
v-else
v-model=
"scope.row[index]"
style=
"background-color: transparent;"
class=
"custom-input"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"nine"
label=
"9"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.nine"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"ten"
label=
"10"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.ten"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"X"
label=
"X"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.X"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"R"
label=
"R"
width=
"130"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.R"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column.property)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
<el-table-column
prop=
"res"
label=
"结果"
width=
"130"
fixed=
"right"
>
<
template
slot-scope=
"scope"
>
<el-input
v-model=
"scope.row.res"
:class=
"
{ 'error-border': scope.row.error }"
@change="(value)=>ocrVerify(value,scope.row,scope.$index,scope.column)"
/>
<!-- 错误提示 -->
<div
v-if=
"scope.row.error"
class=
"error-message"
>
{{
scope
.
row
.
error
}}
</div>
</
template
>
</el-table-column>
</el-table>
</el-form>
...
...
@@ -256,411 +37,235 @@
</template>
<
script
>
import
Schema
from
'async-validator
'
import
{
getDict
}
from
'../../../../api/system/dict/data
'
export
default
{
props
:
{
ocrArray
:
{
default
:
''
,
type
:
String
default
:
()
=>
[]
,
type
:
Array
}
},
data
()
{
return
{
dataTemplate
:
[{
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
}],
// 列表表头长度
tableHeaderLength
:
0
,
// 固定的列数据数
fixedColumnCount
:
0
,
// 列表数据
tableData
:
[
{
NO
:
'A'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
0
},
{
NO
:
'B'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
1
},
{
NO
:
'C'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
2
},
{
NO
:
'F'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
3
},
{
NO
:
'E'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
4
},
{
NO
:
'M'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
5
},
{
NO
:
'M'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
6
},
{
NO
:
'L'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
7
},
{
NO
:
'N'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
8
},
{
NO
:
'W1'
,
difference
:
'天津威晟'
,
measureInstrument
:
'卡尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
9
},
{
NO
:
'重量'
,
difference
:
'天津威晟'
,
measureInstrument
:
'电子称'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
10
},
{
NO
:
'xxx'
,
difference
:
'天津威晟'
,
measureInstrument
:
'目测'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
11
},
{
NO
:
'边缘强度'
,
difference
:
'天津威晟'
,
measureInstrument
:
'目测'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
12
},
{
NO
:
'弯曲变形'
,
difference
:
'天津威晟'
,
measureInstrument
:
'钢板尺'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
13
},
{
NO
:
'破坏强度'
,
difference
:
'天津威晟'
,
measureInstrument
:
'拉力计'
,
one
:
undefined
,
two
:
undefined
,
three
:
undefined
,
four
:
undefined
,
five
:
undefined
,
six
:
undefined
,
seven
:
undefined
,
eight
:
undefined
,
nine
:
undefined
,
ten
:
undefined
,
X
:
undefined
,
R
:
undefined
,
res
:
undefined
,
error
:
{},
col
:
14
}
// {
// 0: 'A',
// 1: '180+0/-0.5',
// 2: '天津威晟',
// 3: '卡尺',
// 4: undefined,
// 5: undefined,
// 6: undefined,
// 7: undefined,
// 8: undefined,
// 9: undefined,
// 10: undefined,
// 11: undefined,
// 12: undefined,
// 13: undefined,
// 14: undefined,
// 15: undefined
// }
],
tableHeader
:
[
// { label: '项目', prop: '0' },
// { label: '规格', prop: '1' },
// { label: '区分', prop: '2' },
// { label: '测定器', prop: '3' },
// { label: '1', prop: '4' },
// { label: '2', prop: '5' },
// { label: '3', prop: '6' },
// { label: '4', prop: '7' },
// { label: '5', prop: '8' },
// { label: '6', prop: '9' },
// { label: '7', prop: '10' },
// { label: '8', prop: '11' },
// { label: '9', prop: '12' },
// { label: '10', prop: '13' },
// { label: 'X', prop: '14' },
// { label: 'R', prop: '15' },
// { label: '结果', prop: '16' }
]
}
},
watch
:
{
ocrArray
:
{
handler
(
newValue
,
oldValue
)
{
const
ocrResArr
=
JSON
.
parse
(
this
.
ocrArray
)
// 去除已识别的行数
ocrResArr
.
splice
(
0
,
1
)
// 识别的数组与对象的映射
const
keys
=
Object
.
keys
(
this
.
dataTemplate
[
0
])
const
res
=
ocrResArr
.
map
(
subArr
=>
{
const
obj
=
{}
keys
.
forEach
((
key
,
index
)
=>
{
// 从索引 3 开始取值(即忽略前三个元素)
const
value
=
subArr
[
index
+
4
]
obj
[
key
]
=
value
!==
undefined
?
value
:
undefined
})
return
obj
})
this
.
ocrRender
(
res
)
// 循环this.tableData i代表第几行
for
(
let
i
=
0
;
i
<
this
.
tableData
.
length
;
i
++
)
{
for
(
let
j
=
0
;
j
<
newValue
[
i
].
length
;
j
++
)
{
// 使用 Vue.set 确保响应式更新(Vue 2)
this
.
$set
(
this
.
tableData
[
i
],
this
.
fixedColumnCount
+
j
,
newValue
[
i
][
j
])
// 或者在 Vue 3 中可以直接赋值
// this.tableData[i][this.fixedColumnCount + j] = newValue[i][j];
}
}
// 计算当前行的数据是否合格
},
deep
:
true
},
tableData
:
{
handler
(
newValue
,
oldValue
)
{
this
.
$emit
(
'afterUpdate'
,
newValue
)
},
deep
:
true
}
},
created
()
{
// 获取OCR模版1配置
this
.
getDictOcrTemplate1
()
},
methods
:
{
ocrRender
(
res
)
{
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
// 合并当前行数据与 OCR 数据,并确保 error 对象存在
const
newRow
=
{
...
this
.
tableData
[
i
],
// 保留原有数据(如 NO/difference 等)
...
res
[
i
],
// 覆盖 OCR 识别的数值字段(one/two...)
error
:
{
...(
this
.
tableData
[
i
].
error
||
{}),
// 保留已有错误状态
...(
res
[
i
].
error
||
{})
// 合并 OCR 可能的错误信息(可选)
}
}
// 使用 Vue.set 触发响应式更新
this
.
$set
(
this
.
tableData
,
i
,
newRow
)
// 合并最后一行的单元格
arraySpanMethod
({
row
,
column
,
rowIndex
,
columnIndex
})
{
// 假设表格数据存储在 this.tableData 中
const
lastRowIndex
=
this
.
tableData
.
length
-
1
// 最后一行的行号
const
lastColumnIndex
=
this
.
tableHeader
.
length
-
1
// 最后一列的列号
// 如果当前单元格是最后一行,并且列索引为第 5 列(索引为 4)
if
(
rowIndex
===
lastRowIndex
&&
columnIndex
===
4
)
{
// 合并从第 5 列(索引为 4)到最后一列
return
[
1
,
lastColumnIndex
-
4
+
1
]
// 跨 1 行,跨 (lastColumnIndex - 4 + 1) 列
}
// 如果当前单元格是最后一行,并且列索引大于第 5 列,则跳过这些单元格
if
(
rowIndex
===
lastRowIndex
&&
columnIndex
>
4
)
{
return
[
0
,
0
]
// 跳过该单元格
}
// 其他情况保持默认
return
[
1
,
1
]
},
ocrVerify
(
value
,
row
,
field
)
{
console
.
log
(
field
)
const
schema
=
new
Schema
({
[
field
]:
{
type
:
'number'
,
required
:
true
,
message
:
'请输入有效数值'
// 数据校验
dataVerify
(
rowData
,
columnData
,
column
)
{
// 判断该列是否需要校验,X、R列不需要校验
if
(
column
.
label
===
'X'
||
column
.
label
===
'R'
)
{
return
true
}
// 数据为空
if
(
columnData
===
''
||
columnData
===
null
||
columnData
===
undefined
)
{
return
true
}
// 判断当前行数据是否需要校验
if
(
!
rowData
[
1
].
includes
(
'+'
)
&&
!
rowData
[
1
].
includes
(
'-'
)
&&
!
rowData
[
1
].
includes
(
'/'
))
{
return
true
}
if
(
column
.
label
===
'结果'
)
{
// 校验整行数据,只要有一个数据不符合条件 就将结果改为NO
// 获取rowData第4个数据及以后得数据
const
keys
=
Object
.
keys
(
rowData
).
map
(
Number
)
// 过滤出第4个及其以后的键(索引从0开始,所以"3"是第4个)
const
startIndex
=
4
const
endIndex
=
keys
.
length
-
3
// 最后 3 个数据之前的结束索引
const
filteredKeys
=
keys
.
slice
(
startIndex
,
endIndex
)
// 根据过滤后的键名数组提取对应的值
// 根据过滤后的键名数组提取对应的值,并生成数组
const
result
=
filteredKeys
.
map
(
key
=>
rowData
[
key
])
// 遍历result
for
(
let
i
=
0
;
i
<
result
.
length
;
i
++
)
{
const
matches
=
rowData
[
1
].
match
(
/-
?\d
+
(\.\d
+
)?
/g
)
if
(
rowData
[
1
]
!==
''
&&
rowData
[
1
]
!==
null
&&
rowData
[
1
]
!==
undefined
)
{
if
(
rowData
[
1
].
includes
(
'+'
)
&&
rowData
[
1
].
includes
(
'-'
)
&&
rowData
[
1
].
includes
(
'/'
))
{
const
baseValue
=
parseFloat
(
matches
[
0
])
// 提取第一个数字
const
offset
=
parseFloat
(
matches
[
1
])
// 提取第二个数字
const
deviation
=
parseFloat
(
matches
[
2
])
// 提取第三个数字(带符号了)
// 计算范围
const
upperBound
=
baseValue
+
offset
// 上限
const
lowerBound
=
baseValue
+
deviation
// 下限
// 判断columnData是否在lowerBound和upperBound之间
if
(
result
[
i
]
>=
lowerBound
&&
result
[
i
]
<=
upperBound
)
{
// 在范围之间
this
.
$set
(
rowData
,
column
.
property
,
'OK'
)
return
true
}
else
{
// 不在范围之间
this
.
$set
(
rowData
,
column
.
property
,
'NO'
)
return
false
}
}
}
}
})
schema
.
validate
({
[
field
]:
value
},
(
errors
)
=>
{
if
(
errors
)
{
this
.
$set
(
row
.
error
,
field
,
errors
[
0
].
message
)
}
else
{
this
.
$delete
(
row
.
error
,
field
)
}
else
{
const
matches
=
rowData
[
1
].
match
(
/-
?\d
+
(\.\d
+
)?
/g
)
if
(
rowData
[
1
]
!==
''
&&
rowData
[
1
]
!==
null
&&
rowData
[
1
]
!==
undefined
)
{
if
(
rowData
[
1
].
includes
(
'+'
)
&&
rowData
[
1
].
includes
(
'-'
)
&&
rowData
[
1
].
includes
(
'/'
)){
if
(
rowData
[
1
]
&&
rowData
[
1
].
length
>=
3
)
{
const
baseValue
=
parseFloat
(
matches
[
0
])
// 提取第一个数字
const
offset
=
parseFloat
(
matches
[
1
])
// 提取第二个数字
const
deviation
=
parseFloat
(
matches
[
2
])
// 提取第三个数字(带符号了)
// 计算范围
const
upperBound
=
baseValue
+
offset
// 上限
const
lowerBound
=
baseValue
+
deviation
// 下限
// 判断columnData是否在lowerBound和upperBound之间
if
(
columnData
>=
lowerBound
&&
columnData
<=
upperBound
)
{
// console.log(columnData + '在范围之间')
return
true
}
else
{
// console.log(columnData + '不在范围之间')
return
false
}
}
}
}
}
)
}
},
cellStyle
({
row
,
column
})
{
const
value
=
row
[
column
.
property
]
const
hasError
=
!!
row
.
error
[
column
.
property
]
// 空值或存在错误时变红
if
(
value
===
''
||
value
===
null
||
value
===
undefined
||
hasError
)
{
return
{
backgroundColor
:
'red'
// 半透明红色
// 获取OCR模版配置
getDictOcrTemplate1
()
{
getDict
(
'ocr_template1'
).
then
(
res
=>
{
const
templateData
=
res
.
data
// 找出templateData里的所有dictLabel,并变成一个数组
// const dictLabels = templateData.map(item => item.dictLabel)
const
dictRemarks
=
templateData
.
map
(
item
=>
item
.
remarks
)
// console.log('dictLabels:', dictLabels)
// console.log('dictRemarks:', dictRemarks)
// 遍历templateData
for
(
let
i
=
0
;
i
<
templateData
.
length
;
i
++
)
{
const
rowData
=
templateData
[
i
]
// 按逗号分割rowData的dictValue
// console.log('rowData:', rowData)
const
values
=
rowData
.
dictValue
.
split
(
','
)
this
.
fixedColumnCount
=
values
.
length
// 往table表格里放值,但排除row1表头
if
(
rowData
.
dictLabel
!==
'row1'
)
{
const
result
=
{}
// 处理第二个位置的数据
for
(
let
j
=
0
;
j
<
values
.
length
;
j
++
)
{
if
(
j
===
1
)
{
// 将备注按逗号分隔,放入第二个位置
const
dictRemarksArr
=
dictRemarks
[
i
].
split
(
','
)
if
(
dictRemarksArr
.
length
===
1
)
{
result
[
j
]
=
dictRemarksArr
[
0
]
}
else
if
(
dictRemarksArr
.
length
===
2
)
{
result
[
j
]
=
dictRemarksArr
[
0
]
+
'+'
+
dictRemarksArr
[
1
]
}
else
if
(
dictRemarksArr
.
length
===
3
)
{
result
[
j
]
=
dictRemarksArr
[
0
]
+
'+'
+
dictRemarksArr
[
1
]
+
'/'
+
'-'
+
dictRemarksArr
[
2
]
}
else
if
(
dictRemarksArr
.
length
===
4
)
{
result
[
j
]
=
dictRemarksArr
[
0
]
+
'+'
+
dictRemarksArr
[
1
]
+
'/'
+
'-'
+
dictRemarksArr
[
2
]
+
dictRemarksArr
[
3
]
}
}
else
{
result
[
j
]
=
values
[
j
]
}
}
this
.
tableData
.
push
(
result
)
}
if
(
rowData
.
dictLabel
===
'row1'
)
{
// 获取表头数据 循环values
for
(
let
i
=
0
;
i
<
values
.
length
;
i
++
)
{
const
params
=
{
label
:
values
[
i
],
prop
:
i
+
''
}
this
.
tableHeader
.
push
(
params
)
}
this
.
tableHeaderLength
=
this
.
tableHeader
.
length
}
// console.log('this.tableHeader:', this.tableHeader)
// console.log('this.tableData:', this.tableData)
}
}
return
{}
})
}
}
}
...
...
@@ -677,4 +282,11 @@ export default {
color
:
#ff0000
;
font-size
:
12px
;
}
::v-deep
.el-input__inner
{
padding-left
:
5px
;
padding-right
:
0px
;
}
.
custom-input
:
:
v-deep
input
{
color
:
red
!
important
;
/* 确保覆盖默认样式 */
}
</
style
>
src/views/sample/chCheckOrder/index.vue
View file @
0f1dfefb
...
...
@@ -117,8 +117,8 @@
<
el
-
col
:
span
=
"6"
>
<!--
每列占
12
格(总
24
格)
-->
<
el
-
form
-
item
label
=
"请选择订单类型"
>
<
el
-
select
v
-
model
=
"subType"
placeholder
=
"小类型"
@
change
=
"selectHandler"
>
<
el
-
option
label
=
"
a1"
value
=
"a
1"
/>
<
el
-
option
label
=
"
a2"
value
=
"a
2"
/>
<
el
-
option
label
=
"
type1"
value
=
"
1"
/>
<
el
-
option
label
=
"
type2"
value
=
"
2"
/>
<
/el-select
>
<
/el-form-item
>
...
...
@@ -129,7 +129,7 @@
<
el
-
upload
action
=
"http://localhost:8089/common2oss/upload?temp=temp"
multiple
:
on
-
success
=
"
saveBusId
"
:
on
-
success
=
"
updateFileSuccess
"
>
<
i
class
=
"el-icon-upload"
/>
<
el
-
button
type
=
"primary"
>
点击上传
<
/el-button
>
...
...
@@ -139,23 +139,23 @@
<
/el-col
>
<
el
-
col
:
span
=
"6"
>
<
el
-
form
-
item
label
=
"识别结果"
>
<
el
-
select
v
-
model
=
"
wrSelected"
placeholder
=
"识别结果"
>
<
el
-
select
v
-
model
=
"
ocrResult"
placeholder
=
"识别结果"
disabled
>
<
el
-
option
v
-
for
=
"val in
wrVal
"
v
-
for
=
"val in
ocrResultSelect
"
:
key
=
"val.value"
:
value
=
"val.value"
:
label
=
"val.label"
/>
<
/el-select>
</
el
-
form
-
item
>
<
/el-select
>
<
/el-form-item
>
<
/el-col
>
<
/el-row
>
<
/el-form
>
<
div
v
-
if
=
"show
SelectedTableA
1"
>
<
ACheckOrders
:
ocr
-
array
=
"ocrArray"
/>
<
div
v
-
if
=
"show
ModelType
1"
>
<
ACheckOrders
:
ocr
-
array
=
"ocrArray"
@
afterUpdate
=
"getAfterUpdateData"
/>
<
/div
>
<
div
v
-
if
=
"show
SelectedTableA
2"
>
<
div
v
-
if
=
"show
ModelType
2"
>
<
BCheckOrders
:
ocr
-
array
=
"ocrArray"
/>
<
/div
>
<
div
...
...
@@ -176,7 +176,7 @@
<
/template
>
<
script
>
import
{
queryList
,
aliOcr
}
from
'@/api/sample/chCheckOrder'
import
{
queryList
,
getOcrData
,
addOcrData
}
from
'@/api/sample/chCheckOrder'
import
{
parseTime
}
from
'@/utils'
import
BCheckOrders
from
'@/views/sample/chCheckOrder/CheckOrders/BCheckOrders.vue'
import
ACheckOrders
from
'@/views/sample/chCheckOrder/CheckOrders/ACheckOrders.vue'
...
...
@@ -189,6 +189,7 @@ export default {
title
:
''
,
open
:
false
,
form
:
{
}
,
// 校验规则
rules
:
{
file
:
[
{
required
:
true
,
message
:
'请输入文件'
,
trigger
:
'blur'
}
,
...
...
@@ -223,25 +224,27 @@ export default {
basicinfoMationList
:
[],
showPdfTable01
:
false
,
showPdfTable02
:
false
,
// 大类型
type
:
''
,
// 小类型
subType
:
''
,
showSelectedTableA1
:
false
,
showSelectedTableA2
:
false
,
wrVal
:
[
{
value
:
1
,
label
:
'正确'
}
,
{
value
:
0
,
label
:
'错误'
}
// table列表数据
tableData
:
[],
// 模版1展示
showModelType1
:
false
,
// 模版2展示
showModelType2
:
false
,
// 总识别结果下拉框
ocrResultSelect
:
[
{
value
:
'1'
,
label
:
'正确'
}
,
{
value
:
'0'
,
label
:
'错误'
}
],
wrSelected
:
''
,
businessId
:
''
,
ocrArray
:
''
,
ocrData
:
[]
// 总识别结果
ocrResult
:
''
,
// 上传的图片id
pictureId
:
''
,
// 扫描得到的数据
ocrArray
:
''
}
}
,
/** 路由离开前存储筛选条件*/
...
...
@@ -264,6 +267,25 @@ export default {
this
.
getList
()
}
,
methods
:
{
// 获取修改后的整个table列表数据
getAfterUpdateData
(
value
)
{
// 遍历value 取最后一个值,如果有一个NO则为错误
// for (let i = 0; i < value.length; i++)
{
// if (value[i][value[i].length - 1] === 'NO')
{
// this.ocrResult = '0'
//
}
else
{
// this.ocrResult = '1'
//
}
//
}
this
.
tableData
=
JSON
.
parse
(
JSON
.
stringify
(
value
))
// 遍历value
for
(
let
i
=
0
;
i
<
this
.
tableData
.
length
;
i
++
)
{
const
keys
=
Object
.
keys
(
this
.
tableData
[
i
])
// 获取对象的所有键
for
(
let
j
=
0
;
j
<
Math
.
min
(
4
,
keys
.
length
);
j
++
)
{
delete
this
.
tableData
[
i
][
keys
[
j
]]
// 删除前四个键值对
}
}
}
,
// 回车跳转下一个输入框
focusNextInput
(
form
)
{
this
.
$nextTick
(()
=>
{
...
...
@@ -308,36 +330,47 @@ export default {
}
,
// 提交
submitForm
()
{
this
.
$refs
.
form
.
validate
((
valid
)
=>
{
if
(
valid
)
{
// 校验通过,提交表单或进行其他操作
if
(
this
.
form
.
businessId
!==
undefined
)
{
updataInfo
(
this
.
form
).
then
(
res
=>
{
if
(
res
.
code
===
200
)
{
this
.
open
=
false
this
.
$message
.
success
(
'操作成功'
)
this
.
getList
()
this
.
reFrom
()
this
.
queryParams
.
page
=
1
}
else
if
(
res
.
code
===
null
)
{
this
.
$message
.
error
(
res
.
message
)
}
}
)
}
else
{
add
(
this
.
form
).
then
(
res
=>
{
if
(
res
.
code
===
200
)
{
this
.
open
=
false
this
.
$message
.
success
(
'操作成功'
)
this
.
getList
()
this
.
reFrom
()
this
.
queryParams
.
page
=
1
}
else
if
(
res
.
code
===
null
)
{
this
.
$message
.
error
(
res
.
message
)
}
}
)
}
}
const
params
=
{
chType
:
'1'
,
chStype
:
'1'
,
chResult
:
'成功'
,
chAlter
:
'1'
,
chFile
:
129
,
chjson
:
JSON
.
stringify
(
this
.
tableData
)
}
addOcrData
(
params
).
then
(
res
=>
{
}
)
// this.$refs.form.validate((valid) =>
{
// if (valid)
{
// // 校验通过,提交表单或进行其他操作
// if (this.form.businessId !== undefined)
{
// updataInfo(this.form).then(res =>
{
// if (res.code === 200)
{
// this.open = false
// this.$message.success('操作成功')
// this.getList()
// this.reFrom()
// this.queryParams.page = 1
//
}
else
if
(
res
.
code
===
null
)
{
// this.$message.error(res.message)
//
}
//
}
)
//
}
else
{
// add(this.form).then(res =>
{
// if (res.code === 200)
{
// this.open = false
// this.$message.success('操作成功')
// this.getList()
// this.reFrom()
// this.queryParams.page = 1
//
}
else
if
(
res
.
code
===
null
)
{
// this.$message.error(res.message)
//
}
//
}
)
//
}
//
}
//
}
)
}
,
// 初始化获取数据
getList
()
{
...
...
@@ -373,8 +406,9 @@ export default {
handleExport
()
{
}
,
// 开始识别
startOcr
()
{
this
.
ocr
(
this
.
business
Id
)
this
.
ocr
(
this
.
picture
Id
)
}
,
cancel
()
{
this
.
open
=
false
...
...
@@ -391,36 +425,41 @@ export default {
}
this
.
$refs
.
form
.
clearValidate
()
}
,
handleChange
(
value
)
{
switch
(
value
[
0
])
{
case
'a'
:
this
.
showPdfTable01
=
true
this
.
showPdfTable02
=
false
break
case
'b'
:
this
.
showPdfTable01
=
false
this
.
showPdfTable02
=
true
break
}
// 上传图片成功后的回调方法
updateFileSuccess
(
res
)
{
this
.
pictureId
=
res
.
data
.
businessId
}
,
saveBusId
(
res
)
{
this
.
businessId
=
res
.
data
.
businessId
}
,
ocr
(
businessId
)
{
aliOcr
(
businessId
).
then
(
res
=>
{
this
.
ocrArray
=
res
.
data
.
chJson
// console.log(ocrArray)
// 获取识别数据
ocr
(
pictureId
)
{
const
params
=
{
businessId
:
129
,
type
:
1
}
getOcrData
(
params
).
then
(
res
=>
{
this
.
ocrArray
=
res
.
data
// 遍历this.ocrArray 将最后一项全部改为OK for循环
for
(
let
i
=
0
;
i
<
this
.
ocrArray
.
length
;
i
++
)
{
if
(
this
.
ocrArray
[
i
].
length
>
0
)
{
if
(
i
!==
this
.
ocrArray
.
length
-
1
)
{
// 不是最后一行数据
this
.
ocrArray
[
i
][
this
.
ocrArray
[
i
].
length
-
1
]
=
'OK'
// 修改最后一个元素
}
else
{
// 最后一行数据
this
.
ocrArray
[
i
][
0
]
=
'OK'
// 修改最后一个元素
}
}
}
}
)
}
,
selectHandler
(
val
)
{
switch
(
val
)
{
case
'
a
1'
:
this
.
show
SelectedTableA
1
=
true
this
.
show
SelectedTableA
2
=
false
case
'1'
:
this
.
show
ModelType
1
=
true
this
.
show
ModelType
2
=
false
break
case
'
a
2'
:
this
.
show
SelectedTableA
2
=
true
this
.
show
SelectedTableA
1
=
false
case
'2'
:
this
.
show
ModelType
2
=
true
this
.
show
ModelType
1
=
false
break
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment