mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-08-10 20:39:48 +08:00
feat: Unify FilterField and FilterColumn component (#931)
This commit is contained in:
parent
46db7de0b2
commit
9b64e66722
@ -15,7 +15,7 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import FieldDefinition from '@/components/ADempiere/Field'
|
import FieldDefinition from '@/components/ADempiere/Field'
|
||||||
import FilterColumns from '@/components/ADempiere/DataTable/filterColumns'
|
import FilterFields from '@/components/ADempiere/FilterFields'
|
||||||
import FixedColumns from '@/components/ADempiere/DataTable/fixedColumns'
|
import FixedColumns from '@/components/ADempiere/DataTable/fixedColumns'
|
||||||
import TableContextMenu from '@/components/ADempiere/DataTable/menu/tableContextMenu'
|
import TableContextMenu from '@/components/ADempiere/DataTable/menu/tableContextMenu'
|
||||||
import TableMainMenu from '@/components/ADempiere/DataTable/menu'
|
import TableMainMenu from '@/components/ADempiere/DataTable/menu'
|
||||||
@ -35,7 +35,7 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
CustomPagination,
|
CustomPagination,
|
||||||
FieldDefinition,
|
FieldDefinition,
|
||||||
FilterColumns,
|
FilterFields,
|
||||||
FixedColumns,
|
FixedColumns,
|
||||||
IconElement,
|
IconElement,
|
||||||
MainPanel,
|
MainPanel,
|
||||||
|
@ -6,13 +6,6 @@
|
|||||||
cursor: pointer !important;
|
cursor: pointer !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.field-optional {
|
|
||||||
margin: 3px 10px;
|
|
||||||
float: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Local search input
|
// Local search input
|
||||||
.local-search-container {
|
.local-search-container {
|
||||||
font-size: 0 !important;
|
font-size: 0 !important;
|
||||||
|
@ -1,93 +0,0 @@
|
|||||||
<!--
|
|
||||||
ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
|
|
||||||
Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A.
|
|
||||||
Contributor(s): Yamel Senih ysenih@erpya.com www.erpya.com
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https:www.gnu.org/licenses/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<el-select
|
|
||||||
v-model="fieldsListShowed"
|
|
||||||
:filterable="!isMobile"
|
|
||||||
:placeholder="$t('components.filterableItems')"
|
|
||||||
multiple
|
|
||||||
size="mini"
|
|
||||||
collapse-tags
|
|
||||||
value-key="key"
|
|
||||||
class="select"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="(item, key) in fieldsListAvailable"
|
|
||||||
:key="key"
|
|
||||||
:label="item.name"
|
|
||||||
:value="item.columnName"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { fieldIsDisplayed } from '@/utils/ADempiere/dictionaryUtils.js'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'FilterColumns',
|
|
||||||
props: {
|
|
||||||
containerUuid: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
isMobile() {
|
|
||||||
return this.$store.state.app.device === 'mobile'
|
|
||||||
},
|
|
||||||
fieldsList() {
|
|
||||||
return this.$store.getters.getFieldsListFromPanel(this.containerUuid)
|
|
||||||
},
|
|
||||||
// available fields
|
|
||||||
fieldsListAvailable() {
|
|
||||||
return this.fieldsList.filter(fieldItem => {
|
|
||||||
return fieldIsDisplayed(fieldItem, true)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
fieldsListShowed: {
|
|
||||||
get() {
|
|
||||||
// columns showed
|
|
||||||
return this.fieldsListAvailable.filter(itemField => {
|
|
||||||
return itemField.isShowedTableFromUser
|
|
||||||
}).map(itemField => {
|
|
||||||
return itemField.columnName
|
|
||||||
})
|
|
||||||
},
|
|
||||||
set(selecteds) {
|
|
||||||
// set columns to show/hidden in vuex store
|
|
||||||
this.addField(selecteds)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
/**
|
|
||||||
* Set columns to hidden/showed in table
|
|
||||||
* @param {array} selectedValues
|
|
||||||
*/
|
|
||||||
addField(selectedValues) {
|
|
||||||
this.$store.dispatch('changeFieldAttributesBoolean', {
|
|
||||||
containerUuid: this.containerUuid,
|
|
||||||
fieldsIncludes: selectedValues,
|
|
||||||
attribute: 'isShowedTableFromUser',
|
|
||||||
valueAttribute: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -71,12 +71,14 @@
|
|||||||
class="header-search-input"
|
class="header-search-input"
|
||||||
/>
|
/>
|
||||||
</icon-element>
|
</icon-element>
|
||||||
<filter-columns
|
|
||||||
|
<filter-fields
|
||||||
v-if="isShowOptionalColumns"
|
v-if="isShowOptionalColumns"
|
||||||
:container-uuid="containerUuid"
|
:container-uuid="containerUuid"
|
||||||
:panel-type="panelType"
|
:panel-type="panelType"
|
||||||
class="field-optional"
|
:in-table="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div :class="{ show: showTableSearch }" class="local-search-container">
|
<div :class="{ show: showTableSearch }" class="local-search-container">
|
||||||
<svg-icon class-name="search-icon" icon-class="search" @click.stop="click()" />
|
<svg-icon class-name="search-icon" icon-class="search" @click.stop="click()" />
|
||||||
<el-input
|
<el-input
|
||||||
|
@ -17,21 +17,24 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-form class="form-filter-fields">
|
<el-form :class="cssClass" style="float: right;">
|
||||||
<!-- <el-form-item :label="groupField"> -->
|
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
|
<template v-if="!isEmptyValue(groupField)" slot="label">
|
||||||
|
{{ groupField }}
|
||||||
|
</template>
|
||||||
|
|
||||||
<el-select
|
<el-select
|
||||||
v-model="selectedFields"
|
v-model="fieldsListShowed"
|
||||||
:filterable="!isMobile"
|
:filterable="!isMobile"
|
||||||
:placeholder="$t('components.filterableItems')"
|
:placeholder="$t('components.filterableItems')"
|
||||||
multiple
|
multiple
|
||||||
collapse-tags
|
collapse-tags
|
||||||
value-key="key"
|
value-key="key"
|
||||||
:popper-append-to-body="false"
|
:size="size"
|
||||||
@change="addField"
|
:popper-append-to-body="true"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="(item, key) in fieldsListOptional"
|
v-for="(item, key) in fieldsListAvailable"
|
||||||
:key="key"
|
:key="key"
|
||||||
:label="item.name"
|
:label="item.name"
|
||||||
:value="item.columnName"
|
:value="item.columnName"
|
||||||
@ -42,7 +45,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent, computed, ref } from '@vue/composition-api'
|
import { defineComponent, computed } from '@vue/composition-api'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'FilterFields',
|
name: 'FilterFields',
|
||||||
@ -59,18 +62,37 @@ export default defineComponent({
|
|||||||
panelType: {
|
panelType: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'window'
|
default: 'window'
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* If is used in table, by default false
|
||||||
|
*/
|
||||||
|
inTable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(props, { root }) {
|
setup(props, { root }) {
|
||||||
const isAdvancedQuery = props.panelType === 'table'
|
const isAdvancedQuery = props.panelType === 'table'
|
||||||
|
|
||||||
|
const size = props.inTable
|
||||||
|
? 'mini'
|
||||||
|
: 'small'
|
||||||
|
|
||||||
|
const cssClass = props.inTable
|
||||||
|
? 'form-filter-columns'
|
||||||
|
: 'form-filter-fields'
|
||||||
|
|
||||||
|
const showedAttibute = props.inTable
|
||||||
|
? 'isShowedTableFromUser'
|
||||||
|
: 'isShowedFromUser'
|
||||||
|
|
||||||
const isMobile = computed(() => {
|
const isMobile = computed(() => {
|
||||||
root.$store.state.app.device === 'mobile'
|
root.$store.state.app.device === 'mobile'
|
||||||
})
|
})
|
||||||
|
|
||||||
const fieldsListOptional = computed(() => {
|
const fieldsListAvailable = computed(() => {
|
||||||
if (props.panelType === 'window' && !root.isEmptyValue(props.groupField)) {
|
if (!props.inTable && props.panelType === 'window' && !root.isEmptyValue(props.groupField)) {
|
||||||
// compare group fields to window
|
// compare group fields to window
|
||||||
return root.$store.getters.getFieldsListNotMandatory({
|
return root.$store.getters.getFieldsListNotMandatory({
|
||||||
containerUuid: props.containerUuid
|
containerUuid: props.containerUuid
|
||||||
@ -81,27 +103,40 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
// get fields not mandatory
|
// get fields not mandatory
|
||||||
return root.$store.getters.getFieldsListNotMandatory({
|
return root.$store.getters.getFieldsListNotMandatory({
|
||||||
containerUuid: props.containerUuid
|
containerUuid: props.containerUuid,
|
||||||
|
isTable: props.inTable
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const getFieldSelected = computed(() => {
|
// fields showed
|
||||||
return fieldsListOptional.value
|
const fieldsListShowed = computed({
|
||||||
.filter(fieldItem => {
|
get() {
|
||||||
return fieldItem.isShowedFromUser
|
return fieldsListAvailable.value.filter(itemField => {
|
||||||
})
|
return itemField[showedAttibute]
|
||||||
.map(itemField => {
|
}).map(itemField => {
|
||||||
return itemField.columnName
|
return itemField.columnName
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
set(selecteds) {
|
||||||
|
// set columns to show/hidden in vuex store
|
||||||
|
changeShowed(selecteds)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// fields optional showed
|
const changeShowed = (selectedValues) => {
|
||||||
const selectedFields = ref(getFieldSelected.value)
|
if (props.inTable) {
|
||||||
|
return changeShowedTable(selectedValues)
|
||||||
|
}
|
||||||
|
return changeShowedPanel(selectedValues)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Set fields to hidden/showed in panel
|
||||||
|
* if is advanced query or browser panel with values or null/not null
|
||||||
|
* operator, dispatch search
|
||||||
* @param {array} selectedValues
|
* @param {array} selectedValues
|
||||||
*/
|
*/
|
||||||
const addField = (selectedValues) => {
|
const changeShowedPanel = (selectedValues) => {
|
||||||
root.$store.dispatch('changeFieldShowedFromUser', {
|
root.$store.dispatch('changeFieldShowedFromUser', {
|
||||||
containerUuid: props.containerUuid,
|
containerUuid: props.containerUuid,
|
||||||
fieldsUser: selectedValues,
|
fieldsUser: selectedValues,
|
||||||
@ -109,15 +144,30 @@ export default defineComponent({
|
|||||||
groupField: props.groupField,
|
groupField: props.groupField,
|
||||||
isAdvancedQuery
|
isAdvancedQuery
|
||||||
})
|
})
|
||||||
selectedFields.value = selectedValues
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set columns to hidden/showed in table
|
||||||
|
* @param {array} selectedValues
|
||||||
|
*/
|
||||||
|
const changeShowedTable = (selectedValues) => {
|
||||||
|
root.$store.dispatch('changeFieldAttributesBoolean', {
|
||||||
|
containerUuid: props.containerUuid,
|
||||||
|
fieldsIncludes: selectedValues,
|
||||||
|
attribute: 'isShowedTableFromUser',
|
||||||
|
valueAttribute: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
cssClass,
|
||||||
|
// computeds
|
||||||
isMobile,
|
isMobile,
|
||||||
addField,
|
size,
|
||||||
fieldsListOptional,
|
fieldsListShowed,
|
||||||
getFieldSelected,
|
fieldsListAvailable,
|
||||||
selectedFields
|
// methods
|
||||||
|
changeShowed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -131,12 +181,14 @@ export default defineComponent({
|
|||||||
margin-right: 0px !important;
|
margin-right: 0px !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-filter-columns {
|
||||||
|
margin: 0px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
/*
|
||||||
.form-filter-fields {
|
.form-filter-fields {
|
||||||
// position
|
|
||||||
float: right;
|
|
||||||
|
|
||||||
.el-tag--small {
|
.el-tag--small {
|
||||||
max-width: 132px !important;
|
max-width: 132px !important;
|
||||||
}
|
}
|
||||||
@ -177,4 +229,5 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
</style>
|
</style>
|
||||||
|
@ -143,7 +143,7 @@ const getters = {
|
|||||||
return getters.getFieldsListFromPanel(containerUuid)
|
return getters.getFieldsListFromPanel(containerUuid)
|
||||||
.filter(fieldItem => {
|
.filter(fieldItem => {
|
||||||
const isMandatory = fieldItem.isMandatory || fieldItem.isMandatoryFromLogic
|
const isMandatory = fieldItem.isMandatory || fieldItem.isMandatoryFromLogic
|
||||||
if (isMandatory) {
|
if (isMandatory && !isTable) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user