Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 656a4e8d
authored
Aug 28, 2023
by
xinla
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
公用导出功能封装,下载优化等
1 parent
67fc0149
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
33 deletions
vue3-lw-pc/src/components/RequestChartTable.vue
vue3-lw-pc/src/config.js
vue3-lw-pc/src/utils/common.js
vue3-lw-pc/src/components/RequestChartTable.vue
View file @
656a4e8
...
...
@@ -117,28 +117,6 @@ export default {
this
.
loading
=
false
})
},
exprotTable
()
{
this
.
$confirm
(
'是否确认导出吗?'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
,
})
.
then
(()
=>
{
this
.
loading
=
true
let
query
=
Object
.
assign
({},
this
.
query
,
{
pageNum
:
undefined
,
pageSize
:
undefined
})
return
this
.
requestExport
(
query
)
})
.
then
((
resBlob
)
=>
{
this
.
downloadBlob
(
resBlob
,
this
.
exportFileName
)
})
.
catch
((
error
)
=>
{
console
.
error
(
error
)
})
.
finally
(()
=>
{
this
.
loading
=
false
})
},
},
}
</
script
>
...
...
@@ -150,7 +128,11 @@ export default {
<div
class=
"RequestChartTable-operation"
v-if=
"requestExport || $slots.query"
>
<slot
name=
"operation"
v-bind=
"query"
></slot>
<el-button
v-if=
"requestExport"
style=
"position: absolute; right: 0"
type=
"primary"
@
click=
"exprotTable"
>
<el-button
v-if=
"requestExport"
style=
"position: absolute; right: 0"
type=
"primary"
@
click=
"$exportData(requestExport.bind(null, query), exportFileName)"
>
导出 Excel
</el-button>
</div>
...
...
vue3-lw-pc/src/config.js
View file @
656a4e8
...
...
@@ -100,8 +100,8 @@ if (h) {
// if (process.env.VUE_APP_ENV === 'production') document.documentElement.style.filter = 'grayscale(100%)'
// el-button点击后自动失焦 去除焦点样式
document
.
addEventListener
(
'click'
,
(
targe
t
)
=>
{
target
=
targe
t
.
target
document
.
addEventListener
(
'click'
,
(
even
t
)
=>
{
let
target
=
even
t
.
target
if
(
target
.
className
.
includes
(
'el-button'
))
{
target
.
blur
()
}
else
if
(
target
.
parentNode
.
className
.
includes
(
'el-button'
))
{
...
...
vue3-lw-pc/src/utils/common.js
View file @
656a4e8
...
...
@@ -99,11 +99,12 @@ export function selectDictLabels(datas, value, separator) {
/**
* 下载bolb文件
* @param {*} blob bolo源数据 必需
* @param {*} type 文件类型 必需
* @param {*} downloadName 下载文件名,需含文件后缀名 可选
* @param {*} downloadName 下载文件名,需含文件后缀名 必需
* @param {*} type 文件类型 enum: excel,zip,image
* @param {*} callback 成功回调
*/
export
function
downloadBlob
(
blob
,
downloadName
,
type
)
{
if
(
!
blob
||
!
downloadName
)
return
export
function
downloadBlob
(
blob
,
downloadName
,
type
,
callback
)
{
if
(
!
blob
||
!
downloadName
)
throw
'文件或文件名不存在'
if
(
blob
instanceof
Blob
)
{
const
typeDict
=
{
excel
:
'application/vnd.ms-excel'
,
...
...
@@ -118,6 +119,7 @@ export function downloadBlob(blob, downloadName, type) {
a
.
click
()
a
.
remove
()
URL
.
revokeObjectURL
(
url
)
// 释放内存
callback
&&
callback
()
}
else
if
(
/^http/
.
test
(
blob
)
&&
type
===
'image'
)
{
let
image
=
new
Image
()
image
.
setAttribute
(
'crossOrigin'
,
'anonymous'
)
...
...
@@ -132,6 +134,8 @@ export function downloadBlob(blob, downloadName, type) {
downloadBlob
(
blob
,
downloadName
)
})
}
}
else
{
throw
'blob:文件类型错误'
}
}
...
...
@@ -146,7 +150,7 @@ export function download(fileName) {
},
}).
then
((
res
)
=>
{
const
{
data
,
headers
}
=
res
downloadBlob
(
data
,
headers
[
'content-type'
],
fileName
)
downloadBlob
(
data
,
fileName
,
headers
[
'content-type'
]
)
// const blob = new Blob([data], { type: headers['content-type'] })
// let dom = document.createElement('a')
...
...
@@ -172,7 +176,7 @@ export function downloadNet(url, fileName) {
},
}).
then
((
res
)
=>
{
const
{
data
,
headers
}
=
res
downloadBlob
(
data
,
headers
[
'content-type'
],
fileName
)
downloadBlob
(
data
,
fileName
,
headers
[
'content-type'
]
)
// const blob = new Blob([data], { type: headers['content-type'] })
// let dom = document.createElement('a')
...
...
@@ -346,7 +350,11 @@ export function filType(file) {
}
}
// 通用删除确认弹窗
/**
* 通用删除
* @param {*} remove 删除接口
* @param {*} callback 成功回调
*/
export
function
$delConfirm
(
remove
,
callback
)
{
this
.
$confirm
(
'是否确认删除?'
,
'警告'
,
{
confirmButtonText
:
'确定'
,
...
...
@@ -361,9 +369,12 @@ export function $delConfirm(remove, callback) {
// this.getList && this.getList()
this
.
msgSuccess
()
})
.
catch
(
function
()
{})
.
catch
((
error
)
=>
{
console
.
error
(
error
)
})
}
// 复制文字
export
function
$copyText
(
txt
)
{
let
clipboard
=
new
this
.
ClipboardJS
(
event
.
currentTarget
.
localName
,
{
target
:
function
(
trigger
)
{
...
...
@@ -379,5 +390,44 @@ export function $copyText(txt) {
}
/**
* 通用导出
* @param {*} requestExport 导出接口 必需
* @param {*} exportFileName 导出文件名 需含文件后缀名 必需
* @param {*} type 文件类型 enum: excel,zip,image 必需
* @param {*} callback 成功回调
*/
export
function
$exportData
(
requestExport
,
exportFileName
=
'导出.xlsx'
,
callback
,
type
)
{
this
.
$confirm
(
'是否确认导出吗?'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
,
})
.
then
(()
=>
{
// debugger
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
$alert
(
'正在导出,请稍等...'
,
'提示'
,
{
confirmButtonText
:
'取消导出'
,
confirmButtonClass
:
'exportData'
,
showClose
:
false
,
}).
then
(()
=>
{
reject
()
})
requestExport
().
then
((
resBlob
)
=>
{
resolve
(
resBlob
)
})
})
})
.
then
((
resBlob
)
=>
{
downloadBlob
(
resBlob
,
exportFileName
,
type
,
()
=>
{
document
.
querySelector
(
'.el-message-box__btns .exportData'
).
click
()
this
.
msgSuccess
(
'操作成功'
)
})
})
.
catch
((
error
)
=>
{
console
.
error
(
error
)
})
}
/**
* 通用js方法封装处理,挂载到 Vue.prototype
*/
Write
Preview
Markdown
is supported
Attach a file
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 post a comment