fix: merge conflict

This commit is contained in:
07akioni 2019-08-28 17:12:22 +08:00
commit 4537a180e9
5 changed files with 172 additions and 42 deletions

View File

@ -1,7 +1,9 @@
<template> <template>
<div class="n-doc-section"> <div class="n-doc-section">
<div class="n-doc-section__header"> <div class="n-doc-section__header">
本地排序,分页,搜索,过滤(多选过滤\单选过滤\异步过滤选项加载),本地删除 本地排序,分页,搜索,过滤(多选过滤\单选过滤\异步过滤选项加载),本地删除,
<br>
多选删除(注意:data数据发生变化后,多选的状态将会被清空)
<br> <br>
行添加className 行添加className
</div> </div>
@ -11,6 +13,7 @@
> >
<!--EXAMPLE_START--> <!--EXAMPLE_START-->
<n-advance-table <n-advance-table
ref="table"
:row-class-name="computeRowcls" :row-class-name="computeRowcls"
:columns="columns" :columns="columns"
:data="data" :data="data"
@ -18,7 +21,23 @@
:search="search" :search="search"
:pagination="{total:data.length,limit:10}" :pagination="{total:data.length,limit:10}"
@on-change="onChange" @on-change="onChange"
/> @on-selected-change="onSelectedChange"
>
<div
slot="table-operation-batch-left"
style="padding-left:27px;"
>
<n-icon
v-show="selectedRow.length"
color="rgba(255,255,255,.7)"
type="md-trash"
size="24"
title="delete all"
style="cursor:pointer;"
@click="batchDelete"
/>
</div>
</n-advance-table>
<!--EXAMPLE_END--> <!--EXAMPLE_END-->
</div> </div>
<n-doc-source-block> <n-doc-source-block>
@ -50,6 +69,9 @@ const sex = [
] ]
const _columns3 = ($this) => { const _columns3 = ($this) => {
return [ return [
{
type: 'selection'
},
{ {
title: 'Name', title: 'Name',
key: 'name', key: 'name',
@ -115,6 +137,7 @@ export default {
const columns = _columns3(this) const columns = _columns3(this)
return { return {
selectedRow: [],
columns, columns,
data: [], data: [],
query: {}, query: {},
@ -140,8 +163,18 @@ export default {
}, },
mounted () { mounted () {
this.data = this.getData() this.data = this.getData()
// dataselectRow
this.$refs.table.selectRow([1, 2, 5])
// this.$refs.table.selectRow('all') //
}, },
methods: { methods: {
batchDelete () {
this.selectedRow.forEach((item) => {
let index = item._index
this.data[index] = null
})
this.data = this.data.filter(item => item !== null)
},
computeRowcls (params) { computeRowcls (params) {
if (params.row.age > 15) { if (params.row.age > 15) {
return 'age-too-old' return 'age-too-old'
@ -151,7 +184,8 @@ export default {
handleDelete (params) { handleDelete (params) {
let index = params._index let index = params._index
this.data.splice(index, 1) this.data.splice(index, 1)
this.$NMessage.success('Delete successfully', { duration: 2000 }) this.$NMessage.success('Delete successfully,', { duration: 2000 })
this.$NMessage.warning('Data change,selected will be clear!', { duration: 4000 })
}, },
getData (args) { getData (args) {
console.log('TCL: getData -> args', args) console.log('TCL: getData -> args', args)
@ -166,6 +200,10 @@ export default {
}) })
return d return d
}, },
onSelectedChange (selectedRow) {
console.log(selectedRow)
this.selectedRow = selectedRow
},
onChange (args) { onChange (args) {
console.log('TCL: onChange -> args', args) console.log('TCL: onChange -> args', args)
/** /**

View File

@ -63,8 +63,22 @@ const data = [
} }
` `
} }
]
]
},
{
name: 'selectRow',
desc: '可以在mounted里selectRow来进行选中某一行,当为字符串all时,选中当前显示所有行,当为数组时,选中行号-1的行(注意data数据要已经存在)',
params: [
{
name: 'rowIndexs Array|String',
desc: `
[0,1,2]
all
`
}
]
} }
] ]
export default { export default {

View File

@ -1,6 +1,10 @@
{ {
"name": "naive-ui", "name": "naive-ui",
<<<<<<< HEAD
"version": "0.2.124", "version": "0.2.124",
=======
"version": "0.2.125",
>>>>>>> c1c36d1a3bcf2b8c20a364d5143cee8efa1e0496
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -51,6 +51,12 @@
:key="column.key" :key="column.key"
:style="computeAlign(column)" :style="computeAlign(column)"
> >
<n-checkbox
v-if="column.type === 'selection'"
v-model="allCheckboxesSelect"
:indeterminate="!isCheckedBoxAllIndeterminate"
@click.native="onAllCheckboxesClick"
/>
{{ column.title }} {{ column.title }}
<SortIcon <SortIcon
v-if="column.sortable" v-if="column.sortable"
@ -120,7 +126,12 @@
:style="computeAlign(column)" :style="computeAlign(column)"
:class="computeTdClass(column, rowData)" :class="computeTdClass(column, rowData)"
> >
<n-checkbox
v-if="column.type === 'selection'"
v-model="checkBoxes[rowData._index]"
/>
<row <row
v-else
:index="i" :index="i"
:row="rowData" :row="rowData"
:key-name="column.key" :key-name="column.key"
@ -169,6 +180,7 @@ import PopFilter from '../popFilter'
import searchInput from '../searchInput' import searchInput from '../searchInput'
import Loading from '../loading' import Loading from '../loading'
import { noopFn } from '../../../utils/index' import { noopFn } from '../../../utils/index'
export default { export default {
name: 'NAdvanceTable', name: 'NAdvanceTable',
components: { components: {
@ -246,22 +258,8 @@ export default {
} }
}, },
data () { data () {
// const sortIndexs = {}
// this.columns.forEach((column, idx) => {
// sortIndexs[column.key || idx] = column.order ? column.order : 0
// })
// const sortIndexs = new Array(this.columns.length).fill(0).map((item, idx) => {
// return this.columns[idx].order ? this.columns[idx].order : 0
// })
// console.log(sortIndexs)
let copyData = this.data.slice(0).map((row, idx) => {
return {
row,
_index: idx
}
})
return { return {
copyData, copyData: [],
sortIndexs: {}, sortIndexs: {},
wrapperWidth: 'unset', wrapperWidth: 'unset',
tbodyWidth: 'auto;', tbodyWidth: 'auto;',
@ -271,7 +269,9 @@ export default {
currentFilterColumn: null, currentFilterColumn: null,
currentSearchColumn: null, currentSearchColumn: null,
currentPage: 1, currentPage: 1,
selectedFilter: {} selectedFilter: {},
checkBoxes: [],
allCheckboxesSelect: false
} }
}, },
computed: { computed: {
@ -355,6 +355,25 @@ export default {
(this.wrapperWidth - this.scrollBarWidth) / (this.wrapperWidth - this.scrollBarWidth) /
this.columns.length this.columns.length
).toFixed(3) ).toFixed(3)
},
selectedRows () {
return this.checkBoxes
.map((isChecked, idx) => {
if (isChecked) {
return this.copyData[idx]
}
})
.filter((item) => item !== void 0)
},
isCheckedBoxAllIndeterminate () {
let selectedLen = 0
this.showingData.forEach((item) => {
let realIdx = item._index
if (this.checkBoxes[realIdx] === true) {
selectedLen++
}
})
return selectedLen === this.showingData.length || selectedLen === 0
} }
}, },
watch: { watch: {
@ -367,14 +386,11 @@ export default {
this.$emit('on-page-change', this.paginationer) this.$emit('on-page-change', this.paginationer)
}, },
data () { data () {
this.copyData = this.data.slice(0).map((row, idx) => { this.initData()
return {
row,
_index: idx
}
})
this.searchData = this.computeShowingData() this.searchData = this.computeShowingData()
this.searchDataNoSort = null this.searchDataNoSort = null
this.checkBoxes = []
this.allCheckboxesSelect = false
}, },
currentSearchColumn () { currentSearchColumn () {
this.searchData = this.computeShowingData() this.searchData = this.computeShowingData()
@ -383,6 +399,15 @@ export default {
this.searchData = this.computeShowingData() this.searchData = this.computeShowingData()
console.log('currentSortColumn') console.log('currentSortColumn')
}, },
checkBoxes () {
if (
this.selectedRows.length === this.showingData.length &&
this.showingData.length !== 0
) {
this.allCheckboxesSelect = true
}
this.$emit('on-selected-change', this.selectedRows)
},
selectedFilter: { selectedFilter: {
deep: true, deep: true,
handler (val) { handler (val) {
@ -396,7 +421,9 @@ export default {
let key = column.key let key = column.key
if (keys.includes(key) && val[key] && val[key].length !== 0) { if (keys.includes(key) && val[key] && val[key].length !== 0) {
// TODO: ! // TODO: !
console.warn('[NAIVE-UI]: n-advance-table filter filterMultiple=false will return not a array in future') console.warn(
'[NAIVE-UI]: n-advance-table filter filterMultiple=false will return not a array in future'
)
this.currentFilterColumn[key] = { this.currentFilterColumn[key] = {
value: [].concat(val[key]), value: [].concat(val[key]),
filterFn: column.onFilter filterFn: column.onFilter
@ -415,6 +442,9 @@ export default {
deep: true deep: true
} }
}, },
created () {
this.initData()
},
mounted () { mounted () {
this.relTable = this.$refs.tbody.$el.querySelector('table') this.relTable = this.$refs.tbody.$el.querySelector('table')
@ -433,6 +463,14 @@ export default {
// window.removeEventListener('resize', this.init) // window.removeEventListener('resize', this.init)
}, },
methods: { methods: {
initData () {
this.copyData = this.data.slice(0).map((row, idx) => {
return {
row,
_index: idx
}
})
},
computeAlign (column) { computeAlign (column) {
if (column.align) { if (column.align) {
return { return {
@ -456,6 +494,26 @@ export default {
// console.log(className) // console.log(className)
return className return className
}, },
selectRow (rowIndexs = []) {
this.$nextTick(() => {
if (rowIndexs === 'all') {
this.showingData.forEach((item) => {
this.checkBoxes[item._index] = true
})
this.checkBoxes = [].concat(this.checkBoxes)
} else {
if (this.showingData.length > 0) {
rowIndexs.forEach((idx) => {
if (this.showingData[idx]) {
const realIdx = this.showingData[idx]._index
this.checkBoxes[realIdx] = true
}
})
this.checkBoxes = [].concat(this.checkBoxes)
}
}
})
},
/** /**
* {key:[value,value1],key1:[v1,v2]} * {key:[value,value1],key1:[v1,v2]}
* {key:value} * {key:value}
@ -471,9 +529,10 @@ export default {
// clear // clear
this.clearSort() this.clearSort()
} }
this.currentFilterColumn && Object.keys(this.currentFilterColumn).forEach(key => { this.currentFilterColumn &&
this.selectedFilter = {} Object.keys(this.currentFilterColumn).forEach((key) => {
}) this.selectedFilter = {}
})
if (filter) { if (filter) {
// ---- TODO: , // ---- TODO: ,
Object.keys(filter).forEach((key) => { Object.keys(filter).forEach((key) => {
@ -489,9 +548,9 @@ export default {
// ---- // ----
this.selectedFilter = filter this.selectedFilter = filter
} }
if (searcher) { if (searcher && this.search) {
this.$refs.search.setSearch(searcher) this.$refs.search.setSearch(searcher)
} else { } else if (!searcher && this.search) {
this.$refs.search.clearSearch() this.$refs.search.clearSearch()
} }
if (page) { if (page) {
@ -518,8 +577,15 @@ export default {
let width = column.width let width = column.width
return { return {
width: width + 'px', width: width + 'px',
'padding-right': this.scrollBarWidth + 'px', 'padding-right': this.scrollBarWidth + 'px'
minWidth: width + 'px' // minWidth: width + 'px'
}
} else if (column.type === 'selection') {
let width = 60
return {
width: width + 'px',
'padding-right': this.scrollBarWidth + 'px'
// minWidth: width + 'px'
} }
} }
return null return null
@ -533,6 +599,17 @@ export default {
// this.scrollBarWidth = 5 // this.scrollBarWidth = 5
}) })
}, },
onAllCheckboxesClick () {
console.log(
'TCL: onAllCheckboxesClick -> this.allCheckboxesSelect',
this.allCheckboxesSelect
)
this.showingData.forEach((item) => {
this.checkBoxes[item._index] = this.allCheckboxesSelect
})
this.checkBoxes = [].concat(this.checkBoxes)
},
handleSearch ({ key, word }) { handleSearch ({ key, word }) {
this.currentSearchColumn = { this.currentSearchColumn = {
key, key,
@ -556,7 +633,7 @@ export default {
let keys = Object.keys(this.currentFilterColumn) let keys = Object.keys(this.currentFilterColumn)
currentFilterColumn = {} currentFilterColumn = {}
keys.forEach(key => { keys.forEach((key) => {
let val = this.currentFilterColumn[key].value let val = this.currentFilterColumn[key].value
let filterFn = this.currentFilterColumn[key].filterFn let filterFn = this.currentFilterColumn[key].filterFn
if (filterFn === 'custom') { if (filterFn === 'custom') {
@ -578,7 +655,7 @@ export default {
let keys = Object.keys(this.currentSortColumn) let keys = Object.keys(this.currentSortColumn)
currentSortColumn = {} currentSortColumn = {}
keys.forEach(key => { keys.forEach((key) => {
let val = this.currentSortColumn[key].value let val = this.currentSortColumn[key].value
let sortable = this.currentSortColumn[key].sortable let sortable = this.currentSortColumn[key].sortable
if (sortable === 'custom') { if (sortable === 'custom') {

View File

@ -202,12 +202,6 @@ export default {
} }
}, },
watch: { watch: {
selectedOptions (n) {
if (this.formItem) {
let vals = n.map(i => i.value)
this.dispatch('NFormItem', 'on-form-change', vals)
}
},
filteredOptions () { filteredOptions () {
this.$nextTick().then(() => { this.$nextTick().then(() => {
this.updatePosition() this.updatePosition()
@ -217,6 +211,9 @@ export default {
}) })
}, },
value () { value () {
if (this.formItem) {
this.dispatch('NFormItem', 'on-form-change', this.value)
}
this.$nextTick().then(() => { this.$nextTick().then(() => {
this.updatePosition() this.updatePosition()
if (this.$refs.scrollbar) { if (this.$refs.scrollbar) {