Commit f83d1a57 by 胡悦

修改

1 parent 34041902
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<template> <template>
<div class="d2-table"> <div class="d2-table">
<el-table <el-table
:ref="tableParams.mutiSelectName + 'MutiTable' || 'mutiTable'" :ref="tableParams.mutiSelectName + 'MutiTable' || 'MutiTable'"
:data="getListApi ? data : tableData" :data="getListApi ? data : tableData"
:row-key="tableParams.mutiSelectUniqueKey || ''" :row-key="tableParams.mutiSelectUniqueKey || ''"
v-loading="loading" v-loading="loading"
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
width="60px" width="60px"
label="序号" label="序号"
type='index' 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>
<el-table-column <el-table-column
v-for="(item, index) in tableParams.tableColumns" v-for="(item, index) in tableParams.tableColumns"
...@@ -93,16 +93,15 @@ ...@@ -93,16 +93,15 @@
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@current-change="handleCurrentChange" @current-change="handleCurrentChange"
:current-page="page.currentPage" :current-page="page[this.pageConf.pageNum]"
:page-sizes="[10,20,30,40]" :page-sizes="[10,20,30,40]"
:page-size="page.pageSize" :page-size="page[this.pageConf.pageSize]"
:total="getListApi ? total : tableTotal" :total="getListApi ? total : tableTotal"
:layout="layout" :layout="layout"
> >
</el-pagination> </el-pagination>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'd2-table', name: 'd2-table',
...@@ -111,10 +110,7 @@ export default { ...@@ -111,10 +110,7 @@ export default {
loading: false, loading: false,
data: [], data: [],
// 页码 // 页码
page: { page: {},
pageSize: 10,
currentPage: 1
},
total: 10, total: 10,
// 排序 // 排序
sortColum: '', sortColum: '',
...@@ -123,7 +119,6 @@ export default { ...@@ -123,7 +119,6 @@ export default {
mutiSelectArr: {} mutiSelectArr: {}
} }
}, },
props: { props: {
// 搜索条件 // 搜索条件
searchForm: { searchForm: {
...@@ -135,7 +130,11 @@ export default { ...@@ -135,7 +130,11 @@ export default {
type: Array, type: Array,
default: () => [] default: () => []
}, },
tableTotal: { // tableTotal: {
// type: Number,
// default: 0
// },
tableScore: {
type: Number, type: Number,
default: 0 default: 0
}, },
...@@ -158,6 +157,14 @@ export default { ...@@ -158,6 +157,14 @@ export default {
type: Boolean, type: Boolean,
default: true default: true
}, },
pageConf: {
type: Object,
default: () => ({
pageSize: 'pageSize',
pageNum: 'pageNum',
totalCount: 'totalCount'
})
},
// 分页组件配置 // 分页组件配置
layout: { layout: {
type: String, type: String,
...@@ -211,14 +218,14 @@ export default { ...@@ -211,14 +218,14 @@ export default {
} }
} }
}, },
mounted() { mounted() {
this.page = {}
this.page[this.pageConf.pageSize] = 10
this.page[this.pageConf.pageNum] = 1
const btn = document.getElementById(this.tableParams.btnId) const btn = document.getElementById(this.tableParams.btnId)
btn && btn.addEventListener('click', this.refreshEmit) btn && btn.addEventListener('click', this.refreshEmit)
console.log(this.getListApi)
this.getListApi && this.refreshTable() this.getListApi && this.refreshTable()
}, },
methods: { methods: {
// 排序 // 排序
sortChange({ column, prop, order }) { sortChange({ column, prop, order }) {
...@@ -226,31 +233,27 @@ export default { ...@@ -226,31 +233,27 @@ export default {
this.sort = order this.sort = order
this.refreshTable() this.refreshTable()
}, },
// 多选 // 多选
handleSelect(val) { handleSelect(val) {
console.log(val)
this.mutiSelectArr[this.tableParams.mutiSelectName] = val this.mutiSelectArr[this.tableParams.mutiSelectName] = val
}, },
// 清空多选 // 清空多选
clearMutiSelect() { clearMutiSelect() {
this.mutiSelectArr[this.tableParams.mutiSelectName] = [] this.mutiSelectArr[this.tableParams.mutiSelectName] = []
this.$refs[this.tableParams.mutiSelectName + 'MutiTable'].clearSelection() this.$refs[this.tableParams.mutiSelectName + 'MutiTable'].clearSelection()
}, },
// 发布事件,以期查询条件改变后,页面图表需要刷新 // 发布事件,以期查询条件改变后,页面图表需要刷新
refreshEmit() { refreshEmit() {
this.$emit('searchChange') this.$emit('searchChange')
this.refreshTable(true, true) this.refreshTable(true, true)
}, },
refreshTable(clearMuti = true, resetPageNum = false) {
refreshTable(clearMuti = true, resetCurrentPage = false) {
this.beforeSearchFn().then(res => { this.beforeSearchFn().then(res => {
// console.log(res)
// 清空多选 // 清空多选
clearMuti && this.clearMutiSelect() clearMuti && this.clearMutiSelect()
this.loading = true this.loading = true
resetCurrentPage && (this.page.currentPage = 1) resetPageNum && (this.page.pageNum = 1)
var params = { var params = {
...this.page, ...this.page,
...this.searchForm ...this.searchForm
...@@ -261,8 +264,9 @@ export default { ...@@ -261,8 +264,9 @@ export default {
} }
this.getListApi(params) this.getListApi(params)
.then(res => { .then(res => {
this.data = res[this.tableParams.listName] this.data = this.findVal(res, this.tableParams.listName)
this.total = res.pagination.totalCount this.total = this.findVal(res, this.pageConf.totalCount)
this.$emit('sendAlldata', res.data)
this.loading = false this.loading = false
}) })
.catch(() => { .catch(() => {
...@@ -270,18 +274,24 @@ export default { ...@@ -270,18 +274,24 @@ export default {
}) })
}) })
}, },
// 找返回值
findVal(res, rankStr, attr) {
var rankList = rankStr.split('.')
if (!rankStr) {
return res
}
return this.findVal(res[rankList[0]], rankList.splice(1).join('.'), attr)
},
// 每页条数 // 每页条数
handleSizeChange(value) { handleSizeChange(value) {
this.page.pageSize = value this.page[this.pageConf.pageSize] = value
this.getListApi this.getListApi
? this.refreshTable(false) ? this.refreshTable(false)
: this.$emit('refreshTable', this.page) : this.$emit('refreshTable', this.page)
}, },
// 页码 // 页码
handleCurrentChange(value) { handleCurrentChange(value) {
this.page.currentPage = value this.page[this.pageConf.pageNum] = value
this.getListApi this.getListApi
? this.refreshTable(false) ? this.refreshTable(false)
: this.$emit('refreshTable', this.page) : this.$emit('refreshTable', this.page)
...@@ -293,6 +303,9 @@ export default { ...@@ -293,6 +303,9 @@ export default {
.a-click { .a-click {
cursor: pointer; cursor: pointer;
} }
.el-table {
margin-bottom: 16px;
}
.el-table .cell { .el-table .cell {
line-height: 14px; line-height: 14px;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!