Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
GaoQuYingJiH5-ASD
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
xinzhedeai
GaoQuYingJiH5-ASD
Commits
ebf76af9
Commit
ebf76af9
authored
Jul 13, 2024
by
xinzhedeai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fetch上传图片
parent
c52db27e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
63 deletions
+122
-63
dw-list-detail.html
src/dw-list-detail.html
+3
-2
dw-list-detail.js
src/dw-list-detail.js
+57
-30
emergency-detail.html
src/emergency-detail.html
+5
-2
emergency-detail.js
src/emergency-detail.js
+57
-29
No files found.
src/dw-list-detail.html
View file @
ebf76af9
...
...
@@ -104,8 +104,9 @@
:before-upload=
"beforeUpload"
:after-read=
"afterRead"
:before-read=
"beforeRead"
:max-count=
"1"
:preview-full-image=
"false"
>
<van-button
size=
"mini"
icon=
"plus"
type=
"primary"
>
上传文件
</van-button>
:preview-full-image=
"false"
>
<!-- <van-button size="mini" icon="plus" type="primary">上传文件</van-button> -->
<div
style=
"width: 1.6rem;height: 0.6rem;line-height: 0.6rem; background-color: #1989fa;color:#fff;text-align: center;border-radius: 2px;"
>
上传文件
</div>
</van-uploader>
</div></van-cell>
</van-cell-group>
...
...
src/dw-list-detail.js
View file @
ebf76af9
...
...
@@ -98,38 +98,65 @@ window.addEventListener("load", function() {
}
return
true
;
},
afterRead
(
file
)
{
// 调用爱山东中台系统,将数据流传递过去
// gemhoUtil.setCookie('uploading', 'Y')
vant
.
Toast
.
loading
({
message
:
'
正在处理...
'
,
forbidClick
:
true
,
loadingType
:
'
spinner
'
,
});
http2
.
post
({
serviceId
:
API_KEY_MAP
[
"
upload
"
][
'
id
'
],
interfacePublicKey
:
API_KEY_MAP
[
"
upload
"
][
"
publicKey
"
],
interfacePrivateKey
:
API_KEY_MAP
[
"
upload
"
][
"
privateKey
"
],
reqParams
:
{
modelName
:
'
dangerjob
'
,
},
fileList
:
[{
fileName
:
'
file
'
,
file
:
file
.
file
}]
},
(
res
)
=>
{
// gemhoUtil.setCookie('uploading', 'N')
if
(
res
){
console
.
log
(
'
接口回调数据
'
,
JSON
.
parse
(
res
))
var
result
=
JSON
.
parse
(
res
)
if
(
result
.
body
&&
result
.
body
.
indexOf
(
'
dangerjob
'
)
>
-
1
){
this
.
filePathList
=
[
result
.
body
]
}
else
{
this
.
filePathList
=
[]
}
vant
.
Toast
.
clear
()
afterRead
(
file
)
{
console
.
log
(
'
afterRead
'
,
file
)
// 文件读取完成后的处理逻辑
const
formData
=
new
FormData
();
formData
.
append
(
'
file
'
,
file
.
file
);
// 通过FormData构建要上传的文件数据
formData
.
append
(
'
modelName
'
,
'
dangerjob
'
);
// 发送HTTP POST请求
fetch
(
this
.
previewUrl
+
'
/api/common/upload
'
,
{
method
:
'
POST
'
,
body
:
formData
})
.
then
(
response
=>
{
if
(
response
.
ok
)
{
return
response
.
json
();
}
throw
new
Error
(
'
Network response was not ok.
'
);
})
.
then
(
data
=>
{
console
.
log
(
data
);
// 处理后端返回的数据
// 可根据后端返回的数据做进一步处理,如显示上传成功信息等
this
.
filePathList
=
data
.
body
?
[
data
.
body
]
:
[]
})
.
catch
(
error
=>
{
console
.
error
(
'
There has been a problem with your fetch operation:
'
,
error
);
});
},
// afterRead(file) { // 调用爱山东中台系统,将数据流传递过去
// // gemhoUtil.setCookie('uploading', 'Y')
// vant.Toast.loading({
// message: '正在处理...',
// forbidClick: true,
// loadingType: 'spinner',
// });
// http2.post({
// serviceId: API_KEY_MAP["upload"]['id'],
// interfacePublicKey: API_KEY_MAP["upload"]["publicKey"],
// interfacePrivateKey: API_KEY_MAP["upload"]["privateKey"],
// reqParams: {
// modelName: 'dangerjob',
// },
// fileList: [{
// fileName: 'file',
// file: file.file
// }]
// }, (res) => {
// // gemhoUtil.setCookie('uploading', 'N')
// if(res){
// console.log('接口回调数据', JSON.parse(res))
// var result = JSON.parse(res)
// if(result.body && result.body.indexOf('dangerjob') > -1){
// this.filePathList = [result.body]
// }else{
// this.filePathList = []
// }
// vant.Toast.clear()
// }
// })
// },
resetData
()
{
// 使用 Object.assign 来重写 this.$data,以达到重置 data 的目的
Object
.
assign
(
this
.
$data
,
this
.
$options
.
data
.
call
(
this
));
...
...
src/emergency-detail.html
View file @
ebf76af9
...
...
@@ -75,8 +75,11 @@
:before-upload=
"beforeUpload"
:after-read=
"afterRead"
:before-read=
"beforeRead"
:max-count=
"1"
:preview-full-image=
"false"
>
<van-button
size=
"mini"
icon=
"plus"
type=
"primary"
>
上传文件
</van-button>
:preview-full-image=
"false"
>
<!-- <van-button size="mini" icon="plus" type="primary">上传文件</van-button> -->
<div
style=
"width: 1.6rem;height: 0.6rem;line-height: 0.6rem; background-color: #1989fa;color:#fff;text-align: center;border-radius: 2px;"
>
上传文件
</div>
</van-uploader>
<!-- <van-uploader v-model="fileList" :max-count="1" :deletable="!disabled" :preview-full-image="false"> -->
</van-uploader>
</div></van-cell>
</van-cell-group>
...
...
src/emergency-detail.js
View file @
ebf76af9
...
...
@@ -27,6 +27,7 @@ window.addEventListener("load", function() {
// companyId: localStorage.getItem('companyId'),
// disabled: false,
fileList
:
[],
}
},
mounted
()
{
...
...
@@ -109,39 +110,66 @@ window.addEventListener("load", function() {
}
return
true
;
},
// afterRead(file) {
// // 获取文件流,调用网关中台接口,获取文件全路径url
// console.log('afterRead',file)
// vant.Toast.loading({
// message: '正在处理...',
// forbidClick: true,
// loadingType: 'spinner',
// });
// http2.post({
// serviceId: API_KEY_MAP["upload"]['id'],
// interfacePublicKey: API_KEY_MAP["upload"]["publicKey"],
// interfacePrivateKey: API_KEY_MAP["upload"]["privateKey"],
// reqParams: {
// modelName: 'emergencydrill',
// },
// fileList: [{
// fileName: 'file',
// file: file.file
// }]
// }, (res) => {
// // gemhoUtil.setCookie('uploading', 'N')
// if(res){
// console.log('接口回调数据', JSON.parse(res))
// var result = JSON.parse(res)
// if(result.body && result.body.indexOf('emergencydrill') > -1){
// this.filePathList = [result.body]
// }else{
// this.filePathList = []
// }
// vant.Toast.clear()
// }
// })
// },
afterRead
(
file
)
{
// 获取文件流,调用网关中台接口,获取文件全路径url
console
.
log
(
'
afterRead
'
,
file
)
// 文件读取完成后的处理逻辑
const
formData
=
new
FormData
();
formData
.
append
(
'
file
'
,
file
.
file
);
// 通过FormData构建要上传的文件数据
formData
.
append
(
'
modelName
'
,
'
emergencydrill
'
);
vant
.
Toast
.
loading
({
message
:
'
正在处理...
'
,
forbidClick
:
true
,
loadingType
:
'
spinner
'
,
});
http2
.
post
({
serviceId
:
API_KEY_MAP
[
"
upload
"
][
'
id
'
],
interfacePublicKey
:
API_KEY_MAP
[
"
upload
"
][
"
publicKey
"
],
interfacePrivateKey
:
API_KEY_MAP
[
"
upload
"
][
"
privateKey
"
],
reqParams
:
{
modelName
:
'
emergencydrill
'
,
},
fileList
:
[{
fileName
:
'
file
'
,
file
:
file
.
file
}]
},
(
res
)
=>
{
// gemhoUtil.setCookie('uploading', 'N')
if
(
res
){
console
.
log
(
'
接口回调数据
'
,
JSON
.
parse
(
res
))
var
result
=
JSON
.
parse
(
res
)
if
(
result
.
body
&&
result
.
body
.
indexOf
(
'
emergencydrill
'
)
>
-
1
){
this
.
filePathList
=
[
result
.
body
]
}
else
{
this
.
filePathList
=
[]
}
vant
.
Toast
.
clear
()
// 发送HTTP POST请求
fetch
(
this
.
previewUrl
+
'
/api/common/upload
'
,
{
method
:
'
POST
'
,
body
:
formData
})
.
then
(
response
=>
{
if
(
response
.
ok
)
{
return
response
.
json
();
}
throw
new
Error
(
'
Network response was not ok.
'
);
})
.
then
(
data
=>
{
console
.
log
(
data
);
// 处理后端返回的数据
// 可根据后端返回的数据做进一步处理,如显示上传成功信息等
this
.
filePathList
=
data
.
body
?
[
data
.
body
]
:
[]
})
.
catch
(
error
=>
{
console
.
error
(
'
There has been a problem with your fetch operation:
'
,
error
);
});
},
showPopup
(
popupType
)
{
if
(
!
this
.
disabled
)
{
...
...
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