Skip to content

Commit e388d31

Browse files
committed
fix: s-table checkbox props #274
- fix showPagination prop setter boolean type err #267
1 parent ba494bc commit e388d31

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

src/components/Table/index.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export default {
109109
current: localPageNum,
110110
pageSize: this.pageSize,
111111
showSizeChanger: this.showSizeChanger
112-
})
112+
}) || false
113+
console.log('this.localPagination', this.localPagination)
113114
this.needTotalList = this.initTotalList(this.columns)
114115
this.loadData()
115116
},
@@ -135,9 +136,9 @@ export default {
135136
this.localLoading = true
136137
const parameter = Object.assign({
137138
pageNo: (pagination && pagination.current) ||
138-
this.localPagination.current || this.pageNum,
139+
this.showPagination && this.localPagination.current || this.pageNum,
139140
pageSize: (pagination && pagination.pageSize) ||
140-
this.localPagination.pageSize || this.pageSize
141+
this.showPagination && this.localPagination.pageSize || this.pageSize
141142
},
142143
(sorter && sorter.field && {
143144
sortField: sorter.field
@@ -148,29 +149,36 @@ export default {
148149
...filters
149150
}
150151
)
152+
console.log('parameter', parameter)
151153
const result = this.data(parameter)
152154
// 对接自己的通用数据接口需要修改下方代码中的 r.pageNo, r.totalCount, r.data
153155
// eslint-disable-next-line
154156
if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
155157
result.then(r => {
156-
this.localPagination = Object.assign({}, this.localPagination, {
158+
this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
157159
current: r.pageNo, // 返回结果中的当前分页数
158160
total: r.totalCount, // 返回结果中的总记录数
159161
showSizeChanger: this.showSizeChanger,
160162
pageSize: (pagination && pagination.pageSize) ||
161163
this.localPagination.pageSize
162-
})
164+
}) || false
163165
// 为防止删除数据后导致页面当前页面数据长度为 0 ,自动翻页到上一页
164-
if (r.data.length === 0 && this.localPagination.current > 1) {
166+
if (r.data.length === 0 && this.showPagination && this.localPagination.current > 1) {
165167
this.localPagination.current--
166168
this.loadData()
167169
return
168170
}
169171

170-
// 这里用于判断接口是否有返回 r.totalCount this.showPagination = false
172+
// 这里用于判断接口是否有返回 r.totalCount this.showPagination = true 且 pageNo 和 pageSize 存在 且 totalCount 小于等于 pageNo * pageSize 的大小
171173
// 当情况满足时,表示数据不满足分页大小,关闭 table 分页功能
172-
173-
(!this.showPagination || !r.totalCount && this.showPagination === 'auto') && (this.localPagination.hideOnSinglePage = true)
174+
try {
175+
if ((['auto', true].includes(this.showPagination) && r.totalCount <= (r.pageNo * pagination.pageSize))) {
176+
this.localPagination.hideOnSinglePage = true
177+
}
178+
} catch (e) {
179+
this.localPagination = false
180+
}
181+
console.log('loadData -> this.localPagination', this.localPagination)
174182
this.localDataSource = r.data // 返回结果中的数组数据
175183
this.localLoading = false
176184
})
@@ -272,7 +280,9 @@ export default {
272280
if (k === 'rowSelection') {
273281
if (showAlert && this.rowSelection) {
274282
// 如果需要使用alert,则重新绑定 rowSelection 事件
283+
console.log('this.rowSelection', this.rowSelection)
275284
props[k] = {
285+
...this.rowSelection,
276286
selectedRows: this.selectedRows,
277287
selectedRowKeys: this.selectedRowKeys,
278288
onChange: (selectedRowKeys, selectedRows) => {

src/views/list/TableList.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@
8484
:data="loadData"
8585
:alert="options.alert"
8686
:rowSelection="options.rowSelection"
87+
:show-pagination="false"
8788
>
8889
<span slot="serial" slot-scope="text, record, index">
8990
{{ index + 1 }}
9091
</span>
9192
<span slot="status" slot-scope="text">
9293
<a-badge :status="text | statusTypeFilter" :text="text | statusFilter" />
9394
</span>
95+
<span slot="description" slot-scope="text">
96+
<ellipsis :length="4" tooltip>{{ text }}</ellipsis>
97+
</span>
9498

9599
<span slot="action" slot-scope="text, record">
96100
<template>
@@ -107,7 +111,7 @@
107111

108112
<script>
109113
import moment from 'moment'
110-
import { STable } from '@/components'
114+
import { STable, Ellipsis } from '@/components'
111115
import StepByStepModal from './modules/StepByStepModal'
112116
import CreateForm from './modules/CreateForm'
113117
import { getRoleList, getServiceList } from '@/api/manage'
@@ -135,6 +139,7 @@ export default {
135139
name: 'TableList',
136140
components: {
137141
STable,
142+
Ellipsis,
138143
CreateForm,
139144
StepByStepModal
140145
},
@@ -157,7 +162,8 @@ export default {
157162
},
158163
{
159164
title: '描述',
160-
dataIndex: 'description'
165+
dataIndex: 'description',
166+
scopedSlots: { customRender: 'description' }
161167
},
162168
{
163169
title: '服务调用次数',
@@ -224,7 +230,13 @@ export default {
224230
alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
225231
rowSelection: {
226232
selectedRowKeys: this.selectedRowKeys,
227-
onChange: this.onSelectChange
233+
onChange: this.onSelectChange,
234+
getCheckboxProps: record => ({
235+
props: {
236+
disabled: record.no === 'No 2', // Column configuration not to be checked
237+
name: record.no
238+
}
239+
})
228240
}
229241
}
230242
this.optionAlertShow = true

0 commit comments

Comments
 (0)