mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-15 14:49:18 +00:00
feat: 新增自定义 table 的 Dialog 中全选功能
This commit is contained in:
@@ -10,10 +10,15 @@
|
|||||||
@cancel="restoreDefault()"
|
@cancel="restoreDefault()"
|
||||||
@confirm="handleColumnConfirm()"
|
@confirm="handleColumnConfirm()"
|
||||||
>
|
>
|
||||||
<label>{{ this.$t('TableColSetting') }}</label>
|
<el-col style="margin-bottom: 5px">
|
||||||
|
<label>{{ this.$t('TableColSetting') }}</label>
|
||||||
|
<el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" style="float: right" @change="handleCheckAllChange">全选</el-checkbox>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
<el-checkbox-group
|
<el-checkbox-group
|
||||||
v-model="iCurrentColumns"
|
v-model="iCurrentColumns"
|
||||||
class="column-setting"
|
class="column-setting"
|
||||||
|
@change="handleCheckedChange"
|
||||||
>
|
>
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col
|
<el-col
|
||||||
@@ -55,6 +60,10 @@ export default {
|
|||||||
type: Array,
|
type: Array,
|
||||||
default: () => []
|
default: () => []
|
||||||
},
|
},
|
||||||
|
defaultColumns: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
url: {
|
url: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
@@ -62,16 +71,34 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
checkAll: false,
|
||||||
showColumnSettingPopover: false,
|
showColumnSettingPopover: false,
|
||||||
iCurrentColumns: ''
|
iCurrentColumns: '',
|
||||||
|
isIndeterminate: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
currentColumns: {
|
||||||
|
handler(val) {
|
||||||
|
this.iCurrentColumns = val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$eventBus.$on('showColumnSettingPopover', ({ url }) => {
|
this.$eventBus.$on('showColumnSettingPopover', ({ url }) => {
|
||||||
if (url === this.url) {
|
if (url === this.url) {
|
||||||
|
this.checkAll = false
|
||||||
this.showColumnSettingPopover = true
|
this.showColumnSettingPopover = true
|
||||||
this.iCurrentColumns = this.currentColumns
|
this.iCurrentColumns = this.currentColumns
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.iCurrentColumns.length === this.totalColumnsList.length) {
|
||||||
|
this.checkAll = true
|
||||||
|
this.isIndeterminate = false
|
||||||
|
} else {
|
||||||
|
this.checkAll = false
|
||||||
|
this.isIndeterminate = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -82,6 +109,22 @@ export default {
|
|||||||
restoreDefault() {
|
restoreDefault() {
|
||||||
this.showColumnSettingPopover = false
|
this.showColumnSettingPopover = false
|
||||||
this.$emit('columnsUpdate', { columns: null, url: this.url })
|
this.$emit('columnsUpdate', { columns: null, url: this.url })
|
||||||
|
},
|
||||||
|
handleCheckAllChange(value) {
|
||||||
|
if (value) {
|
||||||
|
this.iCurrentColumns = this.totalColumnsList.reduce((prev, item) => {
|
||||||
|
return [...prev, (item.prop)]
|
||||||
|
}, [])
|
||||||
|
this.isIndeterminate = false
|
||||||
|
} else {
|
||||||
|
this.iCurrentColumns = this.defaultColumns
|
||||||
|
this.isIndeterminate = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleCheckedChange(value) {
|
||||||
|
const checkedCount = value.length
|
||||||
|
this.checkAll = checkedCount === this.totalColumnsList.length
|
||||||
|
this.isIndeterminate = checkedCount > 0 && checkedCount < this.totalColumnsList.length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
:current-columns="popoverColumns.currentCols"
|
:current-columns="popoverColumns.currentCols"
|
||||||
:min-columns="popoverColumns.minCols"
|
:min-columns="popoverColumns.minCols"
|
||||||
:total-columns-list="popoverColumns.totalColumnsList"
|
:total-columns-list="popoverColumns.totalColumnsList"
|
||||||
|
:default-columns="popoverColumns.defaultCols"
|
||||||
:url="config.url"
|
:url="config.url"
|
||||||
@columnsUpdate="handlePopoverColumnsChange"
|
@columnsUpdate="handlePopoverColumnsChange"
|
||||||
/>
|
/>
|
||||||
@@ -58,7 +59,8 @@ export default {
|
|||||||
popoverColumns: {
|
popoverColumns: {
|
||||||
totalColumnsList: [],
|
totalColumnsList: [],
|
||||||
minCols: [],
|
minCols: [],
|
||||||
currentCols: []
|
currentCols: [],
|
||||||
|
defaultCols: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -426,6 +428,8 @@ export default {
|
|||||||
})
|
})
|
||||||
this.popoverColumns.currentCols = this.cleanedColumnsShow.show
|
this.popoverColumns.currentCols = this.cleanedColumnsShow.show
|
||||||
this.popoverColumns.minCols = this.cleanedColumnsShow.min
|
this.popoverColumns.minCols = this.cleanedColumnsShow.min
|
||||||
|
this.popoverColumns.defaultCols = this.cleanedColumnsShow.default
|
||||||
|
|
||||||
this.$log.debug('Popover cols: ', this.popoverColumns)
|
this.$log.debug('Popover cols: ', this.popoverColumns)
|
||||||
},
|
},
|
||||||
handlePopoverColumnsChange({ columns, url }) {
|
handlePopoverColumnsChange({ columns, url }) {
|
||||||
@@ -434,6 +438,7 @@ export default {
|
|||||||
columns = this.cleanedColumnsShow.default
|
columns = this.cleanedColumnsShow.default
|
||||||
}
|
}
|
||||||
this.popoverColumns.currentCols = columns
|
this.popoverColumns.currentCols = columns
|
||||||
|
|
||||||
const _tableConfig = localStorage.getItem('tableConfig')
|
const _tableConfig = localStorage.getItem('tableConfig')
|
||||||
? JSON.parse(localStorage.getItem('tableConfig'))
|
? JSON.parse(localStorage.getItem('tableConfig'))
|
||||||
: {}
|
: {}
|
||||||
|
Reference in New Issue
Block a user