|
@@ -9,7 +9,8 @@ export default {
|
|
selectedRowKeys: [],
|
|
selectedRowKeys: [],
|
|
localLoading: false,
|
|
localLoading: false,
|
|
localDataSource: [],
|
|
localDataSource: [],
|
|
- localPagination: Object.assign({}, this.pagination)
|
|
|
|
|
|
+ localPagination: Object.assign({}, this.pagination),
|
|
|
|
+ isSucceed: true // 是否请求成功
|
|
}
|
|
}
|
|
},
|
|
},
|
|
props: Object.assign({}, T.props, {
|
|
props: Object.assign({}, T.props, {
|
|
@@ -17,6 +18,10 @@ export default {
|
|
type: [String, Function],
|
|
type: [String, Function],
|
|
default: 'key'
|
|
default: 'key'
|
|
},
|
|
},
|
|
|
|
+ rowKeyName: { // 多选时,唯一标识键名
|
|
|
|
+ type: String,
|
|
|
|
+ default: 'id'
|
|
|
|
+ },
|
|
rowClassName: {
|
|
rowClassName: {
|
|
type: [String, Function],
|
|
type: [String, Function],
|
|
default: ''
|
|
default: ''
|
|
@@ -55,11 +60,6 @@ export default {
|
|
type: Object,
|
|
type: Object,
|
|
default: null
|
|
default: null
|
|
},
|
|
},
|
|
- /** @Deprecated */
|
|
|
|
- showAlertInfo: {
|
|
|
|
- type: Boolean,
|
|
|
|
- default: false
|
|
|
|
- },
|
|
|
|
showPagination: {
|
|
showPagination: {
|
|
type: String | Boolean,
|
|
type: String | Boolean,
|
|
default: 'auto'
|
|
default: 'auto'
|
|
@@ -123,7 +123,7 @@ export default {
|
|
this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, {
|
|
this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, {
|
|
current: localPageNum,
|
|
current: localPageNum,
|
|
pageSize: this.pageSize,
|
|
pageSize: this.pageSize,
|
|
- pageSizeOptions:['5','10', '20', '30', '40'],
|
|
|
|
|
|
+ pageSizeOptions: ['5', '10', '20', '30', '40'],
|
|
showTotal: total => `共 ${total} 条记录`,
|
|
showTotal: total => `共 ${total} 条记录`,
|
|
showSizeChanger: this.showSizeChanger
|
|
showSizeChanger: this.showSizeChanger
|
|
}) || false
|
|
}) || false
|
|
@@ -147,7 +147,10 @@ export default {
|
|
},
|
|
},
|
|
// 重置表格为空
|
|
// 重置表格为空
|
|
clearTable () {
|
|
clearTable () {
|
|
|
|
+ this.localLoading = false
|
|
this.localDataSource = []
|
|
this.localDataSource = []
|
|
|
|
+ this.needTotalList = []
|
|
|
|
+ this.clearSelected()
|
|
this.localPagination = Object.assign({}, {
|
|
this.localPagination = Object.assign({}, {
|
|
current: 1, pageSize: this.pageSize, total: 0
|
|
current: 1, pageSize: this.pageSize, total: 0
|
|
})
|
|
})
|
|
@@ -183,8 +186,13 @@ export default {
|
|
// eslint-disable-next-line
|
|
// eslint-disable-next-line
|
|
if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
|
|
if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
|
|
result.then(r => {
|
|
result.then(r => {
|
|
- const list = r.list || r.data || r
|
|
|
|
|
|
+ // const list = r.list || r.data || r
|
|
|
|
+ let list = []
|
|
|
|
+ if (r) {
|
|
|
|
+ list = r.list || r.data || r
|
|
|
|
+ }
|
|
// console.log(r,'rrrrrrrrrr')
|
|
// console.log(r,'rrrrrrrrrr')
|
|
|
|
+ this.isSucceed = !!r
|
|
this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
|
|
this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
|
|
current: r.pageNo, // 返回结果中的当前分页数
|
|
current: r.pageNo, // 返回结果中的当前分页数
|
|
total: Number(r.count), // 返回结果中的总记录数
|
|
total: Number(r.count), // 返回结果中的总记录数
|
|
@@ -210,6 +218,8 @@ export default {
|
|
}
|
|
}
|
|
this.localDataSource = list // 返回结果中的数组数据
|
|
this.localDataSource = list // 返回结果中的数组数据
|
|
this.localLoading = false
|
|
this.localLoading = false
|
|
|
|
+ }).catch(err => {
|
|
|
|
+ this.clearTable()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -231,26 +241,66 @@ export default {
|
|
* @param selectedRows
|
|
* @param selectedRows
|
|
*/
|
|
*/
|
|
updateSelect (selectedRowKeys, selectedRows) {
|
|
updateSelect (selectedRowKeys, selectedRows) {
|
|
- this.selectedRows = selectedRows
|
|
|
|
- this.selectedRowKeys = selectedRowKeys
|
|
|
|
const list = this.needTotalList
|
|
const list = this.needTotalList
|
|
this.needTotalList = list.map(item => {
|
|
this.needTotalList = list.map(item => {
|
|
return {
|
|
return {
|
|
...item,
|
|
...item,
|
|
- total: selectedRows.reduce((sum, val) => {
|
|
|
|
|
|
+ total: this.selectedRows.reduce((sum, val) => {
|
|
const total = sum + parseInt(get(val, item.dataIndex))
|
|
const total = sum + parseInt(get(val, item.dataIndex))
|
|
return isNaN(total) ? 0 : total
|
|
return isNaN(total) ? 0 : total
|
|
}, 0)
|
|
}, 0)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+ const obj = {
|
|
|
|
+ selectedRowKeys: this.selectedRowKeys,
|
|
|
|
+ selectedRows: this.selectedRows
|
|
|
|
+ }
|
|
|
|
+ this.$emit('rowSelection', obj)
|
|
|
|
+ },
|
|
|
|
+ onSelectChange (record, selected, selectedRows, nativeEvent) {
|
|
|
|
+ if (selected) { // 选择
|
|
|
|
+ this.selectedRows.push(record)
|
|
|
|
+ } else { // 取消
|
|
|
|
+ const selectedRowsArr = []
|
|
|
|
+ this.selectedRows.map(item => {
|
|
|
|
+ if (this.selectedRowKeys.indexOf(item[this.rowKeyName]) != -1) {
|
|
|
|
+ selectedRowsArr.push(item)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ this.selectedRows = selectedRowsArr
|
|
|
|
+ }
|
|
|
|
+ this.updateSelect()
|
|
|
|
+ },
|
|
|
|
+ // 本页全选/取消全选
|
|
|
|
+ onSelectAllChange (selected, selectedRows, changeRows) {
|
|
|
|
+ const _this = this
|
|
|
|
+ if (selected) { // 选择
|
|
|
|
+ this.selectedRows = [...this.selectedRows, ...changeRows]
|
|
|
|
+ } else { // 取消
|
|
|
|
+ const selectedRowsArr = []
|
|
|
|
+ this.selectedRows.map((item, index) => {
|
|
|
|
+ if(!changeRows.find(subItem => subItem[this.rowKeyName] == item[this.rowKeyName])){
|
|
|
|
+ selectedRowsArr.push(item)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ this.selectedRows = selectedRowsArr
|
|
|
|
+ }
|
|
|
|
+ this.updateSelect()
|
|
|
|
+ },
|
|
|
|
+ // 设置 table 已选中项
|
|
|
|
+ setTableSelected (selectedRowKeys, selectedRows) {
|
|
|
|
+ this.selectedRows = selectedRows
|
|
|
|
+ this.selectedRowKeys = selectedRowKeys
|
|
|
|
+ this.updateSelect()
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* 清空 table 已选中项
|
|
* 清空 table 已选中项
|
|
*/
|
|
*/
|
|
clearSelected () {
|
|
clearSelected () {
|
|
if (this.rowSelection) {
|
|
if (this.rowSelection) {
|
|
- this.rowSelection.onChange([], [])
|
|
|
|
- this.updateSelect([], [])
|
|
|
|
|
|
+ this.selectedRows = []
|
|
|
|
+ this.selectedRowKeys = []
|
|
|
|
+ this.updateSelect()
|
|
}
|
|
}
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
@@ -299,7 +349,6 @@ export default {
|
|
const props = {}
|
|
const props = {}
|
|
const localKeys = Object.keys(this.$data)
|
|
const localKeys = Object.keys(this.$data)
|
|
const showAlert = (typeof this.alert === 'object' && this.alert !== null && this.alert.show) && typeof this.rowSelection.selectedRowKeys !== 'undefined' || this.alert
|
|
const showAlert = (typeof this.alert === 'object' && this.alert !== null && this.alert.show) && typeof this.rowSelection.selectedRowKeys !== 'undefined' || this.alert
|
|
-
|
|
|
|
Object.keys(T.props).forEach(k => {
|
|
Object.keys(T.props).forEach(k => {
|
|
const localKey = `local${k.substring(0, 1).toUpperCase()}${k.substring(1)}`
|
|
const localKey = `local${k.substring(0, 1).toUpperCase()}${k.substring(1)}`
|
|
if (localKeys.includes(localKey)) {
|
|
if (localKeys.includes(localKey)) {
|
|
@@ -307,16 +356,19 @@ export default {
|
|
return props[k]
|
|
return props[k]
|
|
}
|
|
}
|
|
if (k === 'rowSelection') {
|
|
if (k === 'rowSelection') {
|
|
- if (showAlert && this.rowSelection) {
|
|
|
|
|
|
+ if (this.rowSelection) {
|
|
// 如果需要使用alert,则重新绑定 rowSelection 事件
|
|
// 如果需要使用alert,则重新绑定 rowSelection 事件
|
|
- // console.log('this.rowSelection', this.rowSelection)
|
|
|
|
props[k] = {
|
|
props[k] = {
|
|
...this.rowSelection,
|
|
...this.rowSelection,
|
|
- selectedRows: this.selectedRows,
|
|
|
|
selectedRowKeys: this.selectedRowKeys,
|
|
selectedRowKeys: this.selectedRowKeys,
|
|
onChange: (selectedRowKeys, selectedRows) => {
|
|
onChange: (selectedRowKeys, selectedRows) => {
|
|
- this.updateSelect(selectedRowKeys, selectedRows)
|
|
|
|
- typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows)
|
|
|
|
|
|
+ this.selectedRowKeys = selectedRowKeys
|
|
|
|
+ },
|
|
|
|
+ onSelect: (record, selected, selectedRows, nativeEvent) => {
|
|
|
|
+ this.onSelectChange(record, selected, selectedRows, nativeEvent)
|
|
|
|
+ },
|
|
|
|
+ onSelectAll: (selected, selectedRows, changeRows) => {
|
|
|
|
+ this.onSelectAllChange(selected, selectedRows, changeRows)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return props[k]
|
|
return props[k]
|
|
@@ -329,6 +381,10 @@ export default {
|
|
this[k] && (props[k] = this[k])
|
|
this[k] && (props[k] = this[k])
|
|
return props[k]
|
|
return props[k]
|
|
})
|
|
})
|
|
|
|
+ if (!this.isSucceed) { // 请求失败
|
|
|
|
+ props['locale'] = { emptyText: '网络异常,请点击按钮刷新' }
|
|
|
|
+ }
|
|
|
|
+ // isSucceed
|
|
const table = (
|
|
const table = (
|
|
<a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}>
|
|
<a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}>
|
|
{ Object.keys(this.$slots).map(name => (<template slot={name}>{this.$slots[name]}</template>)) }
|
|
{ Object.keys(this.$slots).map(name => (<template slot={name}>{this.$slots[name]}</template>)) }
|