Commit 45dd3c63 by Sendya

fix: table :rowSelection, Tree.jsx

parent 192fe98b
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
}, },
onEnd: { onEnd: {
type: Function, type: Function,
default: () => { default: () => ({})
}
} }
}, },
data() { data() {
......
...@@ -10,14 +10,21 @@ export default { ...@@ -10,14 +10,21 @@ export default {
type: Array, type: Array,
required: true required: true
}, },
openKeys: {
type: Array,
default: () => []
},
search: { search: {
type: Boolean, type: Boolean,
default: false default: false
} }
}, },
created () {
this.localOpenKeys = this.openKeys.slice(0)
},
data () { data () {
return { return {
openKeys: [] localOpenKeys: []
} }
}, },
methods: { methods: {
...@@ -100,6 +107,7 @@ export default { ...@@ -100,6 +107,7 @@ export default {
render () { render () {
const { dataSource, search } = this.$props const { dataSource, search } = this.$props
// this.localOpenKeys = openKeys.slice(0)
const list = dataSource.map(item => { const list = dataSource.map(item => {
return this.renderItem(item) return this.renderItem(item)
}) })
...@@ -107,7 +115,7 @@ export default { ...@@ -107,7 +115,7 @@ export default {
return ( return (
<div class="tree-wrapper"> <div class="tree-wrapper">
{ search ? this.renderSearch() : null } { search ? this.renderSearch() : null }
<Menu mode="inline" class="custom-tree" {...{ on: { click: item => this.$emit('click', item) } }}> <Menu mode="inline" class="custom-tree" {...{ on: { click: item => this.$emit('click', item), 'update:openKeys': val => { this.localOpenKeys = val } }}} openKeys={this.localOpenKeys}>
{ list } { list }
</Menu> </Menu>
</div> </div>
......
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
}, },
tabs: { tabs: {
type: Object, type: Object,
default: () => {} default: () => ({})
} }
}, },
methods: { methods: {
......
...@@ -49,6 +49,10 @@ export default { ...@@ -49,6 +49,10 @@ export default {
type: [Object, Boolean], type: [Object, Boolean],
default: null default: null
}, },
rowSelection: {
type: Object,
default: () => ({})
},
/** @Deprecated */ /** @Deprecated */
showAlertInfo: { showAlertInfo: {
type: Boolean, type: Boolean,
...@@ -172,12 +176,13 @@ export default { ...@@ -172,12 +176,13 @@ export default {
*/ */
updateSelect (selectedRowKeys, selectedRows) { updateSelect (selectedRowKeys, selectedRows) {
this.selectedRows = 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: selectedRows.reduce((sum, val) => {
const total = sum + get(val, item.dataIndex) const total = sum + parseInt(get(val, item.dataIndex))
return isNaN(total) ? 0 : total return isNaN(total) ? 0 : total
}, 0) }, 0)
} }
...@@ -198,6 +203,7 @@ export default { ...@@ -198,6 +203,7 @@ export default {
* @returns {*} * @returns {*}
*/ */
renderClear (callback) { renderClear (callback) {
if (this.selectedRowKeys.length <= 0) return null
return ( return (
<a style="margin-left: 24px" onClick={() => { <a style="margin-left: 24px" onClick={() => {
callback() callback()
...@@ -236,7 +242,7 @@ export default { ...@@ -236,7 +242,7 @@ export default {
render () { render () {
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) || 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)}`
...@@ -246,10 +252,11 @@ export default { ...@@ -246,10 +252,11 @@ export default {
if (showAlert && k === 'rowSelection') { if (showAlert && k === 'rowSelection') {
// 重新绑定 rowSelection 事件 // 重新绑定 rowSelection 事件
return props[k] = { return props[k] = {
selectedRowKeys: this[k].selectedRowKeys, selectedRows: this.selectedRows,
selectedRowKeys: this.selectedRowKeys,
onChange: (selectedRowKeys, selectedRows) => { onChange: (selectedRowKeys, selectedRows) => {
this.updateSelect(selectedRowKeys, selectedRows) this.updateSelect(selectedRowKeys, selectedRows)
this[k].onChange(selectedRowKeys, selectedRows) typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows)
} }
} }
} }
......
import Vue from 'vue' import Vue from 'vue'
import moment from 'moment' import moment from 'moment'
import 'moment/locale/zh-cn'
moment.locale('zh-cn')
Vue.filter('NumberFormat', function (value) { Vue.filter('NumberFormat', function (value) {
if (!value) { if (!value) {
......
...@@ -80,8 +80,7 @@ ...@@ -80,8 +80,7 @@
size="default" size="default"
:columns="columns" :columns="columns"
:data="loadData" :data="loadData"
:showAlertInfo="true" :alert="{ show: true, clear: true }"
@onSelect="onChange"
> >
<template v-for="(col, index) in columns" v-if="col.scopedSlots" :slot="col.dataIndex" slot-scope="text, record, index"> <template v-for="(col, index) in columns" v-if="col.scopedSlots" :slot="col.dataIndex" slot-scope="text, record, index">
<div :key="index"> <div :key="index">
...@@ -89,7 +88,7 @@ ...@@ -89,7 +88,7 @@
v-if="record.editable" v-if="record.editable"
style="margin: -5px 0" style="margin: -5px 0"
:value="text" :value="text"
@change="e => handleChange(e.target.value, record.key, col)" @change="e => handleChange(e.target.value, record.key, col, record)"
/> />
<template v-else>{{ text }}</template> <template v-else>{{ text }}</template>
</div> </div>
...@@ -160,7 +159,7 @@ ...@@ -160,7 +159,7 @@
{ {
title: '更新时间', title: '更新时间',
dataIndex: 'updatedAt', dataIndex: 'updatedAt',
width: '150px', width: '200px',
sorter: true, sorter: true,
scopedSlots: { customRender: 'updatedAt' }, scopedSlots: { customRender: 'updatedAt' },
}, },
...@@ -186,19 +185,19 @@ ...@@ -186,19 +185,19 @@
}, },
methods: { methods: {
handleChange (value, key, column) { handleChange (value, key, column, record) {
console.log(value, key, column) console.log(value, key, column)
record[column.dataIndex] = value
}, },
edit (row) { edit (row) {
row.editable = true row.editable = true
// row = Object.assign({}, row) // row = Object.assign({}, row)
this.$refs.table.updateEdit()
}, },
// eslint-disable-next-line // eslint-disable-next-line
del (row) { del (row) {
this.$confirm({ this.$confirm({
title: '警告', title: '警告',
content: '真的要删除吗?', content: `真的要删除 ${row.no} 吗?`,
okText: '删除', okText: '删除',
okType: 'danger', okType: 'danger',
cancelText: '取消', cancelText: '取消',
...@@ -215,12 +214,10 @@ ...@@ -215,12 +214,10 @@
}) })
}, },
save (row) { save (row) {
delete row.editable row.editable = false
this.$refs.table.updateEdit()
}, },
cancel (row) { cancel (row) {
delete row.editable row.editable = false
this.$refs.table.updateEdit()
}, },
onChange (row) { onChange (row) {
......
...@@ -210,7 +210,7 @@ ...@@ -210,7 +210,7 @@
mdl: {}, mdl: {},
// 高级搜索 展开/关闭 // 高级搜索 展开/关闭
advanced: true, advanced: false,
// 查询参数 // 查询参数
queryParam: {}, queryParam: {},
// 表头 // 表头
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<a-card :bordered="false"> <a-card :bordered="false">
<a-row :gutter="8"> <a-row :gutter="8">
<a-col :span="5"> <a-col :span="5">
<s-tree :dataSource="orgTree" :search="true" @click="handleClick" @add="handleAdd" @titleClick="handleTitleClick"></s-tree> <s-tree :dataSource="orgTree" :openKeys.sync="openKeys" :search="true" @click="handleClick" @add="handleAdd" @titleClick="handleTitleClick"></s-tree>
</a-col> </a-col>
<a-col :span="19"> <a-col :span="19">
<s-table <s-table
...@@ -58,7 +58,7 @@ export default { ...@@ -58,7 +58,7 @@ export default {
}, },
data () { data () {
return { return {
openKeys: ['sub1'], openKeys: ['key-01'],
// 查询参数 // 查询参数
queryParam: {}, queryParam: {},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment