From cd2f2177adbce0ba912b44c23352bf90abf9c8ca Mon Sep 17 00:00:00 2001 From: JiwenBai Date: Wed, 23 Oct 2019 14:10:05 +0800 Subject: [PATCH] feat(advance-table): finished advance-table header components --- .../advancedTable/enUS/seniorUsage.md | 30 ++++---- .../common/AdvanceTable/header/header.vue | 61 +++++++++------ .../common/AdvanceTable/sortIcon/index.vue | 70 +++++++++-------- packages/common/AdvanceTable/src/main.vue | 76 ++++++++++++------- 4 files changed, 141 insertions(+), 96 deletions(-) diff --git a/demo/documentation/components/advancedTable/enUS/seniorUsage.md b/demo/documentation/components/advancedTable/enUS/seniorUsage.md index 93d36af4e..18996e45a 100644 --- a/demo/documentation/components/advancedTable/enUS/seniorUsage.md +++ b/demo/documentation/components/advancedTable/enUS/seniorUsage.md @@ -1,4 +1,5 @@ # Senior Usage + ```html
- + clear all filters
@@ -22,6 +20,7 @@

Network params

{{ query }}
``` + ```js const items = [ { @@ -55,7 +54,7 @@ const sex = [ value: 'female' } ] -const _columns3 = ($this) => { +const _columns3 = $this => { return [ { title: 'Name', @@ -69,11 +68,11 @@ const _columns3 = ($this) => { title: 'Age', key: 'age', sortable: true, - sorter (a, b) { + sorter(a, b) { return a.age - b.age }, // filterMultiple: true, - asyncFilterItems () { + asyncFilterItems() { return new Promise((resolve, reject) => { setTimeout(() => { // 模拟概率发生错误 @@ -95,7 +94,7 @@ const _columns3 = ($this) => { return values.includes(record.sex) }, filterMultiple: true, - asyncFilterItems () { + asyncFilterItems() { return new Promise((resolve, reject) => { setTimeout(() => { Math.random() > 0.6 @@ -123,7 +122,7 @@ const _columns3 = ($this) => { } export default { components: {}, - data () { + data() { const columns = _columns3(this) return { loading: false, @@ -140,15 +139,15 @@ export default { } } }, - mounted () { + mounted() { this.$refs.table.setParams({ filter: { age: [15] }, - sorter: { key: 'age', type: -1 }, + sorter: { key: 'name', type: -1 }, searcher: { key: 'name', value: 'xiaobai' } }) }, methods: { - getData (args) { + getData(args) { this.loading = true setTimeout(() => { let d = new Array(20).fill(0) @@ -163,7 +162,8 @@ export default { this.loading = false }, 3000) }, - onChange (args) { + onChange(args) { + console.log('reomte change') this.query = args /** * "filter": { @@ -199,11 +199,11 @@ export default { */ this.getData(args) }, - clear () { + clear() { // 清除所有的Filter选项,会触发onchange事件 this.$refs.table.setParams({}) this.$NMessage.info('clear all filters', { duration: 5000 }) } } } -``` \ No newline at end of file +``` diff --git a/packages/common/AdvanceTable/header/header.vue b/packages/common/AdvanceTable/header/header.vue index 90601ce45..004660a80 100644 --- a/packages/common/AdvanceTable/header/header.vue +++ b/packages/common/AdvanceTable/header/header.vue @@ -10,9 +10,9 @@ v-for="(column, i) in columns" :key="i" :style="computeCustomWidthStl(column)" - > + /> - + @@ -51,11 +51,10 @@ :ref="'sorter_' + (column.key || i)" :value="sortIndexs[column.key || i]" class="n-advance-table__header-icon" - @input="sortInput" - :current-key="currentKey" :column="column" :index="i" - @onSortTypeChange="onSortTypeChange" + :current-key="currentKey" + @input="sortInput" /> @@ -98,12 +97,30 @@ export default { PopFilter }, props: { - colGroupStl: {}, - columns: {}, - scrollBarWidth: {}, - sortIndexs: {}, - selectedFilter: {}, - showingData: {} + colGroupStl: { + type: Object, + default: () => ({}) + }, + columns: { + type: Array, + default: () => [] + }, + scrollBarWidth: { + type: [Number, String], + default: 0 + }, + sortIndexs: { + type: Object, + default: () => ({}) + }, + selectedFilter: { + type: Object, + default: () => ({}) + }, + showingData: { + type: Array, + default: () => [] + } }, data () { return { @@ -118,12 +135,13 @@ export default { ) }, currentKey () { - let currentKey = null + let currentKey = '' Object.keys(this.sortIndexs).forEach(key => { if (this.sortIndexs[key] !== null) { currentKey = key } }) + // console.log('TCL: currentKey -> currentKey', currentKey) return currentKey } }, @@ -138,8 +156,11 @@ export default { } } }, - sortInput (value, column) { - this.$set(this.sortIndexs, column.key, value) + sortInput (value, column, sorter) { + const sortIndexs = {} + sortIndexs[column.key] = value + // console.log('TCL: sortInput -> value', sortIndexs) + this.$emit('on-sort-change', sortIndexs) }, sortByColumn (column) { if (!column.sortable || column.key === void 0) return @@ -165,20 +186,16 @@ export default { } return null }, - clearSort () { + clearOtherSort (notClearKey) { + const sortIndexs = {} Object.keys(this.sortIndexs).forEach(key => { - this.sortIndexs[key] = null + if (key !== notClearKey) sortIndexs[key] = null }) + return sortIndexs }, onAllCheckboxesClick () { this.$emit('on-checkbox-all', this.currentPageAllSelect) }, - onSortTypeChange (sorter) { - this.clearSort() - this.sortInput(sorter.type, sorter.column) - console.log('TCL: onSortTypeChange -> sorter', sorter) - this.$emit('on-sort-change', sorter) - }, onFilter (value, column) { this.$emit('on-filter', value, column) } diff --git a/packages/common/AdvanceTable/sortIcon/index.vue b/packages/common/AdvanceTable/sortIcon/index.vue index 69fe6cb62..8c9109f5c 100644 --- a/packages/common/AdvanceTable/sortIcon/index.vue +++ b/packages/common/AdvanceTable/sortIcon/index.vue @@ -23,26 +23,22 @@