Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx-web
/
d2-table-demo
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 2294006e
authored
Sep 07, 2021
by
cwq0219
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
组件优化
1 parent
77e04395
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
74 deletions
package-lock.json
package.json
src/components/d2-table/index.vue
src/main.js
src/view/autoTable.vue
src/view/manualTable.vue
package-lock.json
View file @
2294006
...
...
@@ -2836,6 +2836,15 @@
}
}
},
"glsx-table"
:
{
"version"
:
"1.0.6"
,
"resolved"
:
"https://registry.npmjs.org/glsx-table/-/glsx-table-1.0.6.tgz"
,
"integrity"
:
"sha512-3EZJTCE6ZzusjkPZ5O1lUcEHeF2x+NPDpUAAGd9jp6jB6tKY1qLp33ILTYgEKuf6nsyAT7elE3B6+5cCd9nY4w=="
,
"requires"
:
{
"element-ui"
:
"^2.13.1"
,
"vue"
:
"^2.6.12"
}
},
"graceful-fs"
:
{
"version"
:
"4.2.6"
,
"resolved"
:
"https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz"
,
...
...
package.json
View file @
2294006
...
...
@@ -12,6 +12,7 @@
"dependencies"
:
{
"axios"
:
"^0.21.1"
,
"element-ui"
:
"^2.15.1"
,
"glsx-table"
:
"^1.0.6"
,
"vue"
:
"^2.5.11"
},
"browserslist"
:
[
...
...
src/components/d2-table/index.vue
View file @
2294006
<!-- 表格+分页 -->
<
template
>
<div
class=
"
d2
-table"
>
<div
class=
"
glsx
-table"
>
<el-table
:ref=
"tableParams.mutiSelectName + 'MutiTable' || '
m
utiTable'"
:ref=
"tableParams.mutiSelectName + 'MutiTable' || '
M
utiTable'"
:data=
"getListApi ? data : tableData"
:row-key=
"tableParams.mutiSelectUniqueKey || ''"
v-loading=
"loading"
border
:highlight-current-row=
"true"
:stripe=
"true"
@
sort-change=
"sortChange"
@
selection-change=
"handleSelect"
:size=
"size"
>
<el-table-column
v-if=
"tableParams.mutiSelect
Name && tableParams.mutiSelectUniqueKey
"
v-if=
"tableParams.mutiSelect
UniqueKey && tableParams.mutiSelectName
"
type=
"selection"
width=
"55"
:reserve-selection=
"true"
...
...
@@ -24,7 +26,7 @@
width=
"60px"
label=
"序号"
type=
'index'
:index=
"index=>index+(page
.currentPage - 1) * page.pageSize
+ 1"
:index=
"index=>index+(page
[this.pageConf.pageNum] - 1) * page[this.pageConf.pageSize]
+ 1"
></el-table-column>
<el-table-column
v-for=
"(item, index) in tableParams.tableColumns"
...
...
@@ -45,14 +47,28 @@
:width=
"item.width"
></slot>
<template
v-else-if=
"item.formatter"
>
<span
v-text=
"item.formatter(scope.row)"
></span>
<span
class=
"line-ellipsis"
:style=
"
{'-webkit-line-clamp': item.line ? item.line : ''}"
:title="item.formatter(scope.row)"
v-text="item.formatter(scope.row)"
>
</span>
</
template
>
<
template
v-else-if=
"getListApi"
>
<span
v-if=
"item.parentProp"
>
{{
scope
.
row
[
item
.
parentProp
][
item
.
prop
]
}}
</span>
<span
v-else
>
{{
scope
.
row
[
item
.
prop
]
}}
</span>
<span
class=
"line-ellipsis"
:style=
"
{'-webkit-line-clamp': item.line ? item.line : ''}"
:title="scope.row[item.prop]"
v-text="scope.row[item.prop]"
>
</span>
</
template
>
<
template
v-else
>
<span
v-text=
"tableData[scope.$index][item.prop]"
></span>
<span
class=
"line-ellipsis"
:style=
"
{'-webkit-line-clamp': item.line ? item.line : ''}"
:title="tableData[scope.$index][item.prop]"
v-text="tableData[scope.$index][item.prop]"
>
</span>
</
template
>
<
template
v-if=
"item.addSymbol"
>
<span
v-text=
"item.addSymbol"
></span>
...
...
@@ -62,9 +78,9 @@
<el-table-column
v-if=
"tableParams.tableOption"
label=
"操作"
fixed=
"right"
:align=
"tableParams.tableOption.align||'center'"
:width=
"tableParams.tableOption.width||'auto'"
:width=
"tableParams.tableOption.width||'200'"
fixed=
"right"
>
<
template
slot-scope=
"scope"
>
<slot
...
...
@@ -79,9 +95,9 @@
background
@
size-change=
"handleSizeChange"
@
current-change=
"handleCurrentChange"
:current-page=
"page
.currentPage
"
:current-page=
"page
[this.pageConf.pageNum]
"
:page-sizes=
"[10,20,30,40]"
:page-size=
"page
.pageSize
"
:page-size=
"page
[this.pageConf.pageSize]
"
:total=
"getListApi ? total : tableTotal"
:layout=
"layout"
>
...
...
@@ -92,25 +108,23 @@
<
script
>
export
default
{
name
:
'd2-table'
,
data
()
{
data
()
{
return
{
loading
:
false
,
data
:
[],
// 页码
page
:
{
pageSize
:
10
,
currentPage
:
1
},
page
:
{},
total
:
10
,
// 排序
sortColum
:
''
,
sort
:
''
,
// 多选数组
mutiSelectArr
:
{}
}
},
props
:
{
size
:
{
type
:
String
,
default
:
'medium'
},
// 搜索条件
searchForm
:
{
type
:
Object
,
...
...
@@ -144,6 +158,10 @@ export default {
type
:
Boolean
,
default
:
true
},
pageConf
:
{
type
:
Object
,
default
:
()
=>
({
pageSize
:
'pageSize'
,
pageNum
:
'pageNum'
,
totalCount
:
'totalCount'
})
},
// 分页组件配置
layout
:
{
type
:
String
,
...
...
@@ -168,11 +186,6 @@ export default {
// type: String,
// default: ''
// },
// 搜索按钮id;new Date().getTime() + parseInt(Math.random() * 1000)
// btnId: {
// type: String,
// default: ''
// },
// 后端返回列表参数名
listName
:
{
type
:
String
,
...
...
@@ -193,56 +206,44 @@ export default {
}
},
mounted
()
{
const
btn
=
document
.
getElementById
(
this
.
tableParams
.
btnId
)
btn
&&
btn
.
addEventListener
(
'click'
,
this
.
refreshEmit
)
mounted
()
{
this
.
page
=
{}
this
.
page
[
this
.
pageConf
.
pageSize
]
=
10
this
.
page
[
this
.
pageConf
.
pageNum
]
=
1
this
.
getListApi
&&
this
.
refreshTable
()
},
methods
:
{
// 排序
sortChange
({
column
,
prop
,
order
})
{
this
.
sortColum
=
order
?
prop
:
''
this
.
sort
=
order
this
.
refreshTable
()
sortChange
({
column
,
prop
,
order
})
{
this
.
$emit
(
'sortChange'
,
{
column
,
prop
,
order
})
},
// 多选
handleSelect
(
val
)
{
handleSelect
(
val
)
{
this
.
mutiSelectArr
[
this
.
tableParams
.
mutiSelectName
]
=
val
},
// 清空多选
clearMutiSelect
()
{
clearMutiSelect
()
{
this
.
mutiSelectArr
[
this
.
tableParams
.
mutiSelectName
]
=
[]
this
.
$refs
[
this
.
tableParams
.
mutiSelectName
+
'MutiTable'
].
clearSelection
()
},
// 发布事件,以期查询条件改变后,页面图表需要刷新
refreshEmit
()
{
this
.
$emit
(
'searchChange'
)
this
.
refreshTable
(
true
,
true
)
},
refreshTable
(
clearMuti
=
true
,
resetCurrentPage
=
false
)
{
refreshTable
(
resetPageNum
=
true
,
clearMuti
=
true
)
{
this
.
beforeSearchFn
().
then
(
res
=>
{
// console.log(res)
// 清空多选
clearMuti
&&
this
.
clearMutiSelect
()
this
.
loading
=
true
reset
CurrentPage
&&
(
this
.
page
.
currentPage
=
1
)
reset
PageNum
&&
(
this
.
page
[
this
.
pageConf
.
pageNum
]
=
1
)
var
params
=
{
...
this
.
page
,
...
this
.
searchForm
}
if
(
this
.
sort
)
{
params
.
sortColum
=
this
.
sortColum
params
.
sort
=
this
.
sort
===
'descending'
?
1
:
0
}
this
.
getListApi
(
params
).
then
(
res
=>
{
this
.
data
=
res
[
this
.
tableParams
.
listName
]
this
.
total
=
res
.
total
this
.
data
=
this
.
findVal
(
res
,
this
.
tableParams
.
listName
)
this
.
total
=
this
.
findVal
(
res
,
this
.
pageConf
.
totalCount
)
this
.
loading
=
false
}).
catch
(()
=>
{
this
.
loading
=
false
...
...
@@ -250,16 +251,25 @@ export default {
})
},
// 找返回值
findVal
(
res
,
rankStr
)
{
var
rankList
=
rankStr
.
split
(
'.'
)
if
(
!
rankStr
)
{
return
res
}
return
this
.
findVal
(
res
[
rankList
[
0
]],
rankList
.
splice
(
1
).
join
(
'.'
))
},
// 每页条数
handleSizeChange
(
value
)
{
this
.
page
.
pageSize
=
value
this
.
getListApi
?
this
.
refreshTable
(
false
)
:
this
.
$emit
(
'refreshTable'
,
this
.
page
)
handleSizeChange
(
value
)
{
this
.
page
[
this
.
pageConf
.
pageSize
]
=
value
this
.
getListApi
?
this
.
refreshTable
(
false
,
false
)
:
this
.
$emit
(
'refreshTable'
,
this
.
page
)
},
// 页码
handleCurrentChange
(
value
)
{
this
.
page
.
currentPage
=
value
this
.
getListApi
?
this
.
refreshTable
(
false
)
:
this
.
$emit
(
'refreshTable'
,
this
.
page
)
handleCurrentChange
(
value
)
{
this
.
page
[
this
.
pageConf
.
pageNum
]
=
value
this
.
getListApi
?
this
.
refreshTable
(
false
,
false
)
:
this
.
$emit
(
'refreshTable'
,
this
.
page
)
}
}
}
...
...
@@ -272,7 +282,15 @@ export default {
.el-table
.cell
{
line-height
:
14px
;
}
.
d2
-table
p
{
.
glsx
-table
p
{
margin
:
10px
0
;
}
.glsx-table
.line-ellipsis
{
display
:
-webkit-box
;
width
:
100%
;
overflow
:
hidden
;
text-overflow
:
ellipsis
;
/* -webkit-line-clamp: 2; */
-webkit-box-orient
:
vertical
;
}
</
style
>
src/main.js
View file @
2294006
import
Vue
from
'vue'
import
App
from
'./App.vue'
import
ElementUI
from
'element-ui'
import
glsxTable
from
'glsx-table'
import
'element-ui/lib/theme-chalk/index.css'
Vue
.
use
(
ElementUI
)
Vue
.
use
(
glsxTable
)
new
Vue
({
el
:
'#app'
,
...
...
src/view/autoTable.vue
View file @
2294006
...
...
@@ -10,21 +10,23 @@
</el-form-item>
<el-form-item>
<el-button
:id=
"tableParams.btnId"
size=
"small"
type=
"primary"
@
click=
"handleSearch"
>
查询
</el-button>
<el-button
@
click=
"handleOption"
>
批量操作
</el-button>
</el-form-item>
</el-form>
<
d2
-table
<
glsx
-table
ref=
"tableRef"
:searchForm=
"searchForm"
:tableParams=
"tableParams"
:getListApi=
"getListApi"
:pageConf=
"pageConf"
:beforeSearchFn=
"beforeSearchFn"
@
sortChange=
"sortChange"
>
<span
slot=
"showImg"
...
...
@@ -45,13 +47,12 @@
@
click=
"handleAdd(scope.scope)"
>
新增
</el-button>
</span>
</
d2
-table>
</
glsx
-table>
</div>
</
template
>
<
script
>
import
{
getListApi
}
from
'../api/test'
import
d2Table
from
'../components/d2-table'
export
default
{
data
()
{
return
{
...
...
@@ -59,9 +60,9 @@ export default {
id
:
''
},
getListApi
:
getListApi
,
pageConf
:
{
pageSize
:
'pageSize'
,
pageNum
:
'pageNum'
,
totalCount
:
'total'
},
// 表格参数
tableParams
:
{
btnId
:
new
Date
().
getTime
()
+
parseInt
(
Math
.
random
()
*
1000
),
listName
:
'list'
,
// 行数据的key
mutiSelectUniqueKey
:
'id'
,
...
...
@@ -75,6 +76,7 @@ export default {
},
{
label
:
'标题'
,
prop
:
'title'
,
line
:
1
,
sortable
:
true
},
{
label
:
'状态'
,
...
...
@@ -95,10 +97,6 @@ export default {
}
},
components
:
{
d2Table
},
methods
:
{
// 刷新表格前的回调函数
beforeSearchFn
()
{
...
...
@@ -107,14 +105,23 @@ export default {
resolve
()
})
},
// 刷新表格
handleSearch
()
{
this
.
$refs
.
tableRef
.
refreshTable
()
},
sortChange
({
column
,
prop
,
order
})
{
// 添加-排序相关参数
this
.
searchForm
.
order
=
order
this
.
searchForm
.
sortAttr
=
order
?
prop
:
null
this
.
handleSearch
()
},
// 新增
handleAdd
(
row
)
{
this
.
$notify
({
title
:
'提示'
,
message
:
'点击了id为'
+
row
.
id
+
'的数据'
})
// 刷新表格
this
.
$refs
.
tableRef
.
refrshTable
()
this
.
handleSearch
()
},
// 获取批量数据
handleOption
()
{
...
...
src/view/manualTable.vue
View file @
2294006
...
...
@@ -16,7 +16,7 @@
>
查询
</el-button>
</el-form-item>
</el-form>
<
d2
-table
<
glsx
-table
ref=
"tableRef2"
:tableData=
"tableData"
:tableTotal=
"tableTotal"
...
...
@@ -33,13 +33,12 @@
@
click=
"handleAdd(scope.scope)"
>
新增
</el-button>
</span>
</
d2
-table>
</
glsx
-table>
</div>
</
template
>
<
script
>
import
{
getListApi2
}
from
'../api/test'
import
d2Table
from
'../components/d2-table'
export
default
{
name
:
'manualTable'
,
data
()
{
...
...
@@ -49,6 +48,7 @@ export default {
},
// 表格参数
tableData
:
[],
tableTotal
:
0
,
tableParams
:
{
listName
:
'list'
,
tableOption
:
true
,
...
...
@@ -64,15 +64,17 @@ export default {
}
},
components
:
{
d2Table
},
mounted
()
{
this
.
handleSearch
()
},
methods
:
{
handleAdd
(
row
)
{
this
.
$notify
({
title
:
'提示'
,
message
:
row
})
},
handleSearch
()
{
var
params
=
{
...
JSON
.
parse
(
JSON
.
stringify
(
this
.
searchForm
)),
...
...
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