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
b7a76f75
Commit
b7a76f75
authored
Sep 27, 2023
by
高宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
工序印刷,切换tab,切换之前什么样,切换之后就什么样
parent
54d8a52a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
226 additions
and
1 deletion
+226
-1
data.js
src/api/system/dict/data.js
+24
-0
user.js
src/api/user.js
+9
-0
data.vue
src/views/system/dict/data.vue
+193
-1
No files found.
src/api/system/dict/data.js
View file @
b7a76f75
...
...
@@ -81,3 +81,27 @@ export function exportData(query) {
responseType
:
'blob'
})
}
// 下载字典数据导入模板
export
function
importTemplate
(
params
)
{
return
request
({
url
:
'/system/dict/data/importTemplate'
,
method
:
'get'
,
responseType
:
'blob'
,
params
})
}
// 导入字典数据信息
export
function
importExcel
(
data
)
{
return
request
({
url
:
'/system/dict/data/importDictData'
,
method
:
'post'
,
headers
:
{
'Content-Type'
:
'multipart/form-data'
},
transformRequest
:
[(
data
)
=>
{
return
data
}],
data
})
}
// 导入字典数据信息
src/api/user.js
View file @
b7a76f75
...
...
@@ -28,4 +28,13 @@ export function getFullTimeUsers() {
method
:
'get'
})
}
// 下载错误文件
export
function
uploadFalseFile
(
params
)
{
return
request
({
url
:
'/system/user/downFalseFile'
,
method
:
'post'
,
data
:
params
,
responseType
:
'blob'
})
}
src/views/system/dict/data.vue
View file @
b7a76f75
...
...
@@ -46,6 +46,14 @@
@
click=
"handleAdd"
>
新增
</el-button>
<el-col
:span=
"1.5"
>
<el-button
type=
"warning"
icon=
"el-icon-upload"
size=
"small"
@
click=
"handleImport"
>
导入
</el-button>
</el-col>
</el-col>
<right-toolbar
:show-search
.
sync=
"showSearch"
@
queryTable=
"getList"
/>
</el-row>
...
...
@@ -167,12 +175,56 @@
<el-button
@
click=
"cancel"
>
取 消
</el-button>
</div>
</el-dialog>
<!-- 字典数据导入对话框 -->
<el-dialog
:title=
"upload.title"
:visible
.
sync=
"upload.open"
width=
"400px"
append-to-body
:close-on-click-modal=
"false"
>
<el-upload
accept=
".xlsx, .xls"
:headers=
"upload.headers"
:action=
"upload.url + '?updateSupport=' + upload.updateSupport"
:disabled=
"upload.isUploading"
:on-progress=
"handleFileUploadProgress"
:on-success=
"handleFileSuccess"
:auto-upload=
"false"
:on-change=
"employeeUpload"
:on-remove=
"handleRemove"
:before-remove=
"beforeRemove"
:on-preview=
"handlePreview"
:file-list=
"files"
drag
>
<i
class=
"el-icon-upload"
/>
<div
class=
"el-upload__text"
>
将文件拖到此处,或
<em>
点击上传
</em>
</div>
<div
slot=
"tip"
class=
"el-upload__tip"
>
<!-- <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
<el-link
type=
"info"
style=
"font-size:12px"
@
click=
"importTemplate"
>
下载模板
</el-link>
</div>
<div
slot=
"tip"
class=
"el-upload__tip"
style=
"color:red"
>
提示:仅允许导入“xls”或“xlsx”格式文件!
</div>
</el-upload>
<div
slot=
"footer"
class=
"dialog-footer"
>
<el-button
@
click=
"upload.open = false"
>
取 消
</el-button>
<el-button
:loading=
"importLoading"
type=
"primary"
@
click=
"submitFileForm"
>
确 定
</el-button>
</div>
</el-dialog>
</div>
</template>
<
script
>
import
{
addData
,
checkDictLabelUnique
,
delData
,
exportData
,
getData
,
listData
,
updateData
}
from
'@/api/system/dict/data'
import
{
addData
,
checkDictLabelUnique
,
delData
,
exportData
,
getData
,
importExcel
,
importTemplate
,
listData
,
updateData
}
from
'@/api/system/dict/data'
import
{
getType
,
listType
}
from
'@/api/system/dict/type'
import
{
getToken
}
from
'@/utils/auth'
import
{
uploadFalseFile
}
from
'@/api/system/user'
export
default
{
name
:
'Data'
,
...
...
@@ -204,6 +256,23 @@ export default {
}
}
return
{
importLoading
:
false
,
// 导入列表
files
:
[],
upload
:
{
// 是否显示弹出层(字典数据导入)
open
:
false
,
// 弹出层标题(字典数据导入)
title
:
''
,
// 是否禁用上传
isUploading
:
false
,
// 是否更新已经存在的用户数据
updateSupport
:
0
,
// 设置上传的请求头部
headers
:
{
Authorization
:
'Bearer '
+
getToken
()
},
// 上传的地址
url
:
process
.
env
.
VUE_APP_BASE_API
+
'/system/user/importExcel'
},
// 遮罩层
loading
:
false
,
// 选中数组
...
...
@@ -273,6 +342,129 @@ export default {
// })
},
methods
:
{
// 提交上传文件
submitFileForm
()
{
// this.$refs.upload.submit()
this
.
importLoading
=
true
if
(
this
.
files
.
length
===
0
)
{
this
.
$message
.
warning
(
'请上传文件'
)
// 导入成功后关闭弹出框
this
.
importLoading
=
false
this
.
upload
.
open
=
true
}
else
{
// 根据后台需求数据格式
var
formData
=
new
FormData
()
// 当前为空
formData
.
append
(
'file'
,
this
.
files
)
importExcel
(
formData
).
then
(
res
=>
{
if
(
res
.
code
===
200
)
{
if
(
res
.
data
.
filename
===
null
)
{
this
.
$message
.
success
(
'导入成功'
)
this
.
files
=
[]
// 导入成功后关闭弹出框
this
.
importLoading
=
false
this
.
upload
.
open
=
false
// 导入成功后刷新页面
this
.
getList
()
}
else
{
uploadFalseFile
({
fileName
:
res
.
data
.
filename
}).
then
(
res
=>
{
const
blob
=
new
Blob
([
res
])
const
downloadElement
=
document
.
createElement
(
'a'
)
const
href
=
window
.
URL
.
createObjectURL
(
blob
)
// 创建下载的链接
downloadElement
.
href
=
href
downloadElement
.
download
=
'模板错误提示'
+
'.txt'
// 下载后文件名
document
.
body
.
appendChild
(
downloadElement
)
downloadElement
.
click
()
// 点击下载
document
.
body
.
removeChild
(
downloadElement
)
// 下载完成移除元素
window
.
URL
.
revokeObjectURL
(
href
)
// 释放掉blob对象
this
.
importLoading
=
false
})
}
this
.
importLoading
=
false
}
else
if
(
res
.
code
===
41020
)
{
this
.
$message
.
info
(
'上传超时,请重新上传'
)
this
.
importLoading
=
false
}
else
{
this
.
$message
.
error
(
res
.
message
)
this
.
importLoading
=
false
}
}).
catch
(
err
=>
{
this
.
$message
.
success
(
err
.
message
)
this
.
importLoading
=
false
})
this
.
importLoading
=
false
}
},
employeeUpload
(
file
,
fileList
)
{
if
(
fileList
.
length
>
1
)
{
fileList
.
splice
(
0
,
1
)
}
this
.
files
=
fileList
[
0
].
raw
},
handleRemove
(
file
,
fileList
)
{
this
.
files
=
[]
},
beforeRemove
(
file
,
fileList
)
{
this
.
files
=
[]
},
/* 上传文件所需求 */
handlePreview
(
file
)
{
},
/** 导出按钮操作 */
handleExport
()
{
const
queryParams
=
this
.
queryParams
this
.
$confirm
(
'是否确认导出所有数据项?'
,
'警告'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
}).
then
(
function
()
{
return
exportData
(
queryParams
).
then
(
response
=>
{
const
blob
=
new
Blob
([
response
])
const
downloadElement
=
document
.
createElement
(
'a'
)
const
href
=
window
.
URL
.
createObjectURL
(
blob
)
// 创建下载的链接
downloadElement
.
href
=
href
downloadElement
.
download
=
'字典数据信息'
+
'.xls'
// 下载后文件名
document
.
body
.
appendChild
(
downloadElement
)
downloadElement
.
click
()
// 点击下载
document
.
body
.
removeChild
(
downloadElement
)
// 下载完成移除元素
window
.
URL
.
revokeObjectURL
(
href
)
// 释放掉blob对象
// this.download(response.msg);
})
})
},
// 文件上传中处理
handleFileUploadProgress
(
event
,
file
,
fileList
)
{
this
.
upload
.
isUploading
=
true
},
// 文件上传成功处理
handleFileSuccess
(
response
)
{
this
.
upload
.
open
=
false
this
.
upload
.
isUploading
=
false
this
.
$refs
.
upload
.
clearFiles
()
this
.
$alert
(
response
.
msg
,
'导入结果'
,
{
dangerouslyUseHTMLString
:
true
})
this
.
getList
()
},
/** 下载模板操作 */
importTemplate
()
{
var
params
=
{
dictType
:
this
.
queryParams
.
dictType
}
importTemplate
(
params
).
then
(
response
=>
{
const
blob
=
new
Blob
([
response
])
const
downloadElement
=
document
.
createElement
(
'a'
)
const
href
=
window
.
URL
.
createObjectURL
(
blob
)
// 创建下载的链接
downloadElement
.
href
=
href
downloadElement
.
download
=
'字典数据导入模板'
+
'.xls'
// 下载后文件名
document
.
body
.
appendChild
(
downloadElement
)
downloadElement
.
click
()
// 点击下载
document
.
body
.
removeChild
(
downloadElement
)
// 下载完成移除元素
window
.
URL
.
revokeObjectURL
(
href
)
// 释放掉blob对象
// this.download(response.msg);
})
},
// 导入
handleImport
()
{
this
.
upload
.
title
=
'字典数据导入'
this
.
upload
.
open
=
true
},
// 状态
changeStatus
(
row
)
{
const
text
=
row
.
flag
===
'1'
?
'启用'
:
'停用'
...
...
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