提交 eeb85fde authored 作者: 王鹏飞's avatar 王鹏飞

TableList组件增加分页功能

上级 870a6a22
...@@ -8,11 +8,13 @@ ...@@ -8,11 +8,13 @@
border border
size="small" size="small"
header-cell-class-name="table-list-header-cell" header-cell-class-name="table-list-header-cell"
:data="data" :data="dataList"
v-bind="$attrs" v-bind="$attrs"
ref="table" ref="table"
> >
<el-table-column type="index" align="center" label="序号" width="60"></el-table-column> <!-- 序号 -->
<el-table-column type="index" align="center" label="序号" width="60" v-if="columns.length"></el-table-column>
<!-- 表头 -->
<el-table-column <el-table-column
:align="column.attrs && column.attrs.align ? column.attrs.align : 'center'" :align="column.attrs && column.attrs.align ? column.attrs.align : 'center'"
show-overflow-tooltip show-overflow-tooltip
...@@ -53,12 +55,20 @@ ...@@ -53,12 +55,20 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<div class="table-list-ft"></div> <div class="table-list-ft" v-if="hasPage">
<el-pagination
:current-page.sync="page.currentPage"
:page-size="page.size"
layout="total, prev, pager, next, jumper"
:total="page.total"
@current-change="handleCurrentChange"
></el-pagination>
</div>
</div> </div>
</template> </template>
<script> <script>
import _ from 'lodash' import { get } from 'lodash'
export default { export default {
props: { props: {
...@@ -78,12 +88,28 @@ export default { ...@@ -78,12 +88,28 @@ export default {
}, },
remote: { remote: {
type: Object type: Object
} },
hasPage: { type: Boolean, default: true }
}, },
data() { data() {
return {} return {
// 列表数据
dataList: [],
page: {
total: 0,
currentPage: 1,
size: 20
}
}
}, },
watch: { watch: {
data: {
immediate: true,
deep: true,
handler(data) {
this.dataList = data
}
},
columns() { columns() {
this.table && this.table.doLayout() this.table && this.table.doLayout()
} }
...@@ -94,25 +120,57 @@ export default { ...@@ -94,25 +120,57 @@ export default {
} }
}, },
methods: { methods: {
get: _.get, // lodash get
get,
// 初始化
init() {
this.page.currentPage = 1
// 列表数据
this.fetchData()
},
// 获取列表数据 // 获取列表数据
fetchListData() { fetchData() {
if (!this.remote || !this.remote.fetch) { if (!this.remote || !this.remote.request) {
return return
} }
// 分页偏移
if (this.hasPage) {
this.remote.params.offset = (this.page.currentPage - 1) * this.page.size
this.remote.params.limit = this.page.size
}
// beforeRequest // beforeRequest
this.remote.params = this.remote.params =
(this.remote.beforeRequest && (this.remote.beforeRequest &&
this.remote.beforeRequest(this.remote.params)) || this.remote.beforeRequest(this.remote.params, this)) ||
this.remote.params this.remote.params
this.remote.fetch(this.remote.params).then(response => {
// 请求接口
this.remote.request(this.remote.params).then(response => {
// responseCallback // responseCallback
response = response =
(this.remote.responseCallback && (this.remote.responseCallback &&
this.remote.responseCallback(response)) || this.remote.responseCallback(response, this)) ||
response response
// 分页
if (this.hasPage) {
this.dataList = response.list
this.page.total = parseInt(response.count)
}
}) })
},
// 页码改变
handleCurrentChange() {
this.fetchData()
},
// 刷新
refersh() {
this.fetchData()
} }
},
beforeMount() {
// 初始化调用
this.init()
} }
} }
</script> </script>
...@@ -130,7 +188,9 @@ export default { ...@@ -130,7 +188,9 @@ export default {
text-align: center; text-align: center;
font-weight: 400; font-weight: 400;
} }
.table-list-ft {
.tabl-list-ft { padding: 20px 0;
display: flex;
justify-content: flex-end;
} }
</style> </style>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
@click="golearningAdd('/app/affairs-hall/again-add/-1')" @click="golearningAdd('/app/affairs-hall/again-add/-1')"
>申请重修</el-button> >申请重修</el-button>
<div style="width: 100%; height: 0.2rem;"></div> <div style="width: 100%; height: 0.2rem;"></div>
<table-list :data="tableData" :columns="columns" :key="affairId"></table-list> <table-list :key="affairId" v-bind="tableOption" v-if="affairId"></table-list>
</div> </div>
<el-dialog title="提示" :visible.sync="dialogVisible" width="30%"> <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
<span>确定删除?</span> <span>确定删除?</span>
...@@ -53,6 +53,11 @@ export default { ...@@ -53,6 +53,11 @@ export default {
TableList TableList
}, },
data() { data() {
const remote = {
request: cAction.Affairs.getAffairsData,
params: { offset: 1 },
beforeRequest: this.tableListbeforeRequest
}
return { return {
dialogVisible: false, dialogVisible: false,
loading: false, loading: false,
...@@ -71,6 +76,7 @@ export default { ...@@ -71,6 +76,7 @@ export default {
tableOptions: { tableOptions: {
// 学术活动 // 学术活动
symposium: { symposium: {
remote,
columns: [ columns: [
{ prop: 'form.symposium_name', label: '活动名称' }, { prop: 'form.symposium_name', label: '活动名称' },
{ prop: 'form.symposium_time', label: '活动时间' }, { prop: 'form.symposium_time', label: '活动时间' },
...@@ -146,6 +152,7 @@ export default { ...@@ -146,6 +152,7 @@ export default {
}, },
// 乐分享 // 乐分享
sharing: { sharing: {
remote,
columns: [ columns: [
{ prop: 'form.sharing_theme', label: '分享主题' }, { prop: 'form.sharing_theme', label: '分享主题' },
{ prop: 'form.class_name', label: '班级' }, { prop: 'form.class_name', label: '班级' },
...@@ -179,6 +186,7 @@ export default { ...@@ -179,6 +186,7 @@ export default {
}, },
// 重修 // 重修
retake: { retake: {
remote,
columns: [ columns: [
{ prop: 'form.semester_name', label: '学期' }, { prop: 'form.semester_name', label: '学期' },
{ prop: 'form.class_name', label: '班级' }, { prop: 'form.class_name', label: '班级' },
...@@ -213,24 +221,20 @@ export default { ...@@ -213,24 +221,20 @@ export default {
] ]
} }
}, },
tableData: [],
affairList: [], affairList: [],
affairId: null affairId: null
} }
}, },
computed: { computed: {
columns() { tableOption() {
const found = this.affairList.find(item => item.id === this.affairId) const found = this.affairList.find(item => item.id === this.affairId)
if (found) { if (found) {
return this.tableOptions[found.form_name].columns return this.tableOptions[found.form_name]
} else { } else {
return [] return []
} }
} }
}, },
mounted() {
this.getTapData()
},
methods: { methods: {
confirmDeletion(row) { confirmDeletion(row) {
/* 删除 */ /* 删除 */
...@@ -258,17 +262,9 @@ export default { ...@@ -258,17 +262,9 @@ export default {
tapIndexs(data) { tapIndexs(data) {
this.tapIndex = data.index this.tapIndex = data.index
this.affairId = data.id this.affairId = data.id
this.getData()
},
getData() {
cAction.Affairs.getAffairsData({ affair_id: this.affairId }).then(
response => {
this.tableData = response
}
)
}, },
// 获取事务类型
getTapData() { getTapData() {
// 获取事务类型
cAction.Affairs.getAffairsType() cAction.Affairs.getAffairsType()
.then(data => { .then(data => {
this.tapParam[0].arrItem = data.map(item => { this.tapParam[0].arrItem = data.map(item => {
...@@ -278,19 +274,23 @@ export default { ...@@ -278,19 +274,23 @@ export default {
const datas = data[this.$route.query.index] || first const datas = data[this.$route.query.index] || first
this.affairId = datas.id this.affairId = datas.id
this.affairList = data this.affairList = data
this.getData()
}) })
.catch(e => { .catch(e => {
this.$message.error(e.message) this.$message.error(e.message)
}) })
}, },
// 新增
golearningAdd(url) { golearningAdd(url) {
const affairId = { id: this.tapParam[0].arrItem[this.tapIndex].val } this.$router.push({ path: url, query: { id: this.affairId } })
this.$router.push({ },
path: url, // 列表接口请求之前
query: affairId tableListbeforeRequest(params) {
}) params.affair_id = this.affairId
return params
} }
},
beforeMount() {
this.getTapData()
} }
} }
</script> </script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论