Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smart
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
wangqinghua
smart
Commits
9e8886d0
Commit
9e8886d0
authored
Jun 11, 2019
by
wangqinghua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兼容IE下载
parent
03b2a2f8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
8 deletions
+24
-8
common.service.ts
src/main/webapp/app/shared/common/common.service.ts
+24
-8
No files found.
src/main/webapp/app/shared/common/common.service.ts
View file @
9e8886d0
import
{
Injectable
,
OnInit
}
from
"@angular/core"
;
import
{
NzModalService
}
from
'ng-zorro-antd'
;
import
{
NzM
essageService
,
NzM
odalService
}
from
'ng-zorro-antd'
;
import
{
SERVER_API_URL
,
SERVER_API_URL_COMS
}
from
'../../app.constants'
;
import
{
DatePipe
}
from
'@angular/common'
;
@
Injectable
()
export
class
CommonService
implements
OnInit
{
constructor
(
private
modalSer
:
NzModalService
,
private
datePipe
:
DatePipe
)
{
constructor
(
private
modalSer
:
NzModalService
,
private
datePipe
:
DatePipe
,
private
message
:
NzMessageService
)
{
// 定义发射事件
}
...
...
@@ -98,16 +99,31 @@ export class CommonService implements OnInit {
* 下载文件
* @param url 文件URL
*/
downloadFile
(
title
,
data
:
Response
)
{
const
blob
=
new
Blob
([
data
],
{
type
:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"
});
const
url
=
window
.
URL
.
createObjectURL
(
blob
);
let
link
=
document
.
createElement
(
"a"
);
link
.
setAttribute
(
"href"
,
url
);
link
.
setAttribute
(
"download"
,
title
);
downloadFile
(
title
,
data
:
Response
)
{
const
blob
=
new
Blob
([
data
],
{
type
:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;'
});
const
ie
=
navigator
.
userAgent
.
match
(
/MSIE
\s([\d
.
]
+
)
/
),
ie11
=
navigator
.
userAgent
.
match
(
/Trident
\/
7.0/
)
&&
navigator
.
userAgent
.
match
(
/rv:11/
),
ieEDGE
=
navigator
.
userAgent
.
match
(
/Edge/g
),
ieVer
=
(
ie
?
ie
[
1
]
:
(
ie11
?
11
:
(
ieEDGE
?
12
:
-
1
)));
console
.
log
(
'ie:'
+
ie
);
console
.
log
(
'ieVer:'
+
ieVer
);
if
(
ie
&&
ieVer
<
10
)
{
this
.
message
.
error
(
'No blobs on IE<10'
);
return
;
}
if
(
ieVer
>
-
1
)
{
window
.
navigator
.
msSaveBlob
(
blob
,
title
);
}
else
{
const
url
=
window
.
URL
.
createObjectURL
(
blob
);
let
link
=
document
.
createElement
(
'a'
);
link
.
setAttribute
(
'href'
,
url
);
link
.
setAttribute
(
'download'
,
title
);
document
.
body
.
appendChild
(
link
);
link
.
click
();
document
.
body
.
removeChild
(
link
);
}
}
/**
* 部分区域全屏
...
...
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