Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mes-ui
Project
Project
Details
Activity
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
ximai
mes-ui
Commits
e1163a18
Commit
e1163a18
authored
Aug 31, 2024
by
沈翠玲
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传图纸增加下载功能
parent
a870ecd2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
3 deletions
+52
-3
process.js
src/api/mes/pro/process.js
+10
-0
uploadTuzhi.vue
...ews/mes/pro/productionSolution/components/uploadTuzhi.vue
+42
-3
No files found.
src/api/mes/pro/process.js
View file @
e1163a18
...
...
@@ -52,3 +52,13 @@ export function delProcess(processId) {
method
:
'delete'
})
}
// 下载图纸文件
export
function
download
(
filepath
)
{
return
request
({
url
:
filepath
,
method
:
'get'
,
responseType
:
'arraybuffer'
})
}
src/views/mes/pro/productionSolution/components/uploadTuzhi.vue
View file @
e1163a18
...
...
@@ -41,6 +41,7 @@
<el-table-column
align=
"center"
label=
"操作"
>
<
template
slot-scope=
"scope"
>
<el-button
size=
"small"
type=
"primary"
@
click=
"delItem(scope.row, scope.$index)"
>
删除
</el-button>
<el-button
size=
"small"
type=
"primary"
@
click=
"download(scope.row, scope.$index)"
>
下载
</el-button>
</
template
>
</el-table-column>
</el-table>
...
...
@@ -50,6 +51,7 @@
</div>
</template>
<
script
>
import
{
download
}
from
"@/api/mes/pro/process"
;
import
{
getToken
}
from
"@/utils/auth"
;
export
default
{
props
:
{
...
...
@@ -82,9 +84,46 @@ export default {
created
(){
},
methods
:
{
openFilename
(
row
)
{
const
url
=
this
.
baseURL
+
row
.
filePath
window
.
open
(
url
,
"_blank"
)
download
(
row
)
{
download
(
row
.
filePath
).
then
(
res
=>
{
if
([
'png'
,
'jpeg'
,
'jpg'
].
indexOf
(
row
.
fileOriginalName
.
substring
(
row
.
fileOriginalName
.
lastIndexOf
(
'.'
)
+
1
))
>
-
1
)
{
const
imgUrl
=
`data: image/jpeg;base64,
${
btoa
(
new
Uint8Array
(
res
).
reduce
((
data
,
byte
)
=>
data
+
String
.
fromCharCode
(
byte
),
''
))}
`
// 将图片的src属性作为URL地址
const
a
=
document
.
createElement
(
'a'
)
const
event
=
new
MouseEvent
(
'click'
)
a
.
download
=
row
.
fileOriginalName
// '下载图片名称'
a
.
href
=
imgUrl
// base图片地址
a
.
dispatchEvent
(
event
)
}
else
{
let
blob
=
new
Blob
([
res
]);
//创建读取文件FileReader
let
reader
=
new
FileReader
();
reader
.
readAsText
(
blob
,
"utf-8"
);
reader
.
onload
=
()
=>
{
try
{
//这里返回的数据是JSON格式
//此处对fileReader读出的结果进行JSON解析
//会出现错误,需要进行捕获
let
res
=
JSON
.
parse
(
reader
.
result
);
//文件不存在或出现错误
console
.
log
(
res
);
//弹出提示
//根据你业务处理
}
catch
(
err
){
//捕获异常 无法解析JSON格式 这里返回的数据是文件流 可供下载
console
.
log
(
"pdf存在"
,
res
)
//以'a'标签的形式自点击下载
let
downloadElement
=
document
.
createElement
(
"a"
);
let
href
=
window
.
URL
.
createObjectURL
(
blob
);
//创建下载的链接
downloadElement
.
href
=
href
;
downloadElement
.
download
=
row
.
fileOriginalName
;
//下载后文件名
document
.
body
.
appendChild
(
downloadElement
);
downloadElement
.
click
();
//点击下载
document
.
body
.
removeChild
(
downloadElement
);
//下载完成移除元素
window
.
URL
.
revokeObjectURL
(
href
);
//释放掉blob对象
}
}
}
})
},
beforeClose
(
done
)
{
// 更新父组件的processItemList
...
...
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