mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 14:41:29 +00:00
refactor(BaTable):获取通用搜索数据的方法移至 BaTableClass 内部
This commit is contained in:
parent
2b55d1b54a
commit
8524681bcf
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="table-com-search">
|
||||
<el-form @submit.prevent="" @keyup.enter="onComSearch" label-position="top" :model="baTable.comSearch.form">
|
||||
<el-form @submit.prevent="" @keyup.enter="baTable.onTableAction('com-search', {})" label-position="top" :model="baTable.comSearch.form">
|
||||
<el-row>
|
||||
<template v-for="(item, idx) in baTable.table.column" :key="idx">
|
||||
<template v-if="item.operator !== false">
|
||||
@ -38,7 +38,7 @@
|
||||
<div class="com-search-col-label w16" v-if="item.comSearchShowLabel !== false">{{ item.label }}</div>
|
||||
<div class="com-search-col-input-range w83">
|
||||
<el-date-picker
|
||||
class="datetime-picker"
|
||||
class="datetime-picker w100"
|
||||
v-model="baTable.comSearch.form[item.prop!]"
|
||||
:default-value="
|
||||
baTable.comSearch.form[item.prop! + '-default']
|
||||
@ -81,7 +81,7 @@
|
||||
<div v-else-if="item.operator" class="com-search-col-input">
|
||||
<!-- 时间筛选 -->
|
||||
<el-date-picker
|
||||
class="datetime-picker"
|
||||
class="datetime-picker w100"
|
||||
v-if="item.render == 'datetime' || item.comSearchRender == 'date'"
|
||||
v-model="baTable.comSearch.form[item.prop!]"
|
||||
:type="item.comSearchRender == 'date' ? 'date' : 'datetime'"
|
||||
@ -150,7 +150,7 @@
|
||||
</template>
|
||||
<el-col :xs="24" :sm="6">
|
||||
<div class="com-search-col pl-20">
|
||||
<el-button v-blur @click="onComSearch" type="primary">{{ $t('Search') }}</el-button>
|
||||
<el-button v-blur @click="baTable.onTableAction('com-search', {})" type="primary">{{ $t('Search') }}</el-button>
|
||||
<el-button @click="onResetForm()">{{ $t('Reset') }}</el-button>
|
||||
</div>
|
||||
</el-col>
|
||||
@ -167,54 +167,12 @@ import BaInput from '/@/components/baInput/index.vue'
|
||||
|
||||
const baTable = inject('baTable') as baTableClass
|
||||
|
||||
const onComSearch = () => {
|
||||
let comSearchData: comSearchData[] = []
|
||||
for (const key in baTable.comSearch.form) {
|
||||
if (!baTable.comSearch.fieldData.has(key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
let val = ''
|
||||
let fieldDataTemp = baTable.comSearch.fieldData.get(key)
|
||||
if (fieldDataTemp.render == 'datetime' && (fieldDataTemp.operator == 'RANGE' || fieldDataTemp.operator == 'NOT RANGE')) {
|
||||
// 时间范围组件返回的是时间数组
|
||||
if (baTable.comSearch.form[key] && baTable.comSearch.form[key].length >= 2) {
|
||||
// 数组转字符串,以实现通过url参数传递预设搜索值
|
||||
if (fieldDataTemp.comSearchRender == 'date') {
|
||||
val = baTable.comSearch.form[key][0] + ' 00:00:00' + ',' + baTable.comSearch.form[key][1] + ' 23:59:59'
|
||||
} else {
|
||||
val = baTable.comSearch.form[key][0] + ',' + baTable.comSearch.form[key][1]
|
||||
}
|
||||
}
|
||||
} else if (fieldDataTemp.operator == 'RANGE' || fieldDataTemp.operator == 'NOT RANGE') {
|
||||
// 普通的范围筛选,baTable在初始化时已准备好start和end字段
|
||||
if (!baTable.comSearch.form[key + '-start'] && !baTable.comSearch.form[key + '-end']) {
|
||||
continue
|
||||
}
|
||||
val = baTable.comSearch.form[key + '-start'] + ',' + baTable.comSearch.form[key + '-end']
|
||||
} else if (baTable.comSearch.form[key]) {
|
||||
val = baTable.comSearch.form[key]
|
||||
}
|
||||
|
||||
if (val) {
|
||||
comSearchData.push({
|
||||
field: key,
|
||||
val: val,
|
||||
operator: fieldDataTemp.operator,
|
||||
render: fieldDataTemp.render,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
baTable.onTableAction('com-search', comSearchData)
|
||||
}
|
||||
|
||||
const onResetForm = () => {
|
||||
// 封装好的onResetForm在此处不能使用
|
||||
for (const key in baTable.comSearch.form) {
|
||||
baTable.comSearch.form[key] = ''
|
||||
}
|
||||
onComSearch()
|
||||
baTable.onTableAction('com-search', {})
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -256,9 +214,6 @@ const onResetForm = () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
:deep(.datetime-picker) {
|
||||
width: 100%;
|
||||
}
|
||||
.pl-20 {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
@ -295,8 +295,10 @@ export default class baTable {
|
||||
[
|
||||
'com-search',
|
||||
() => {
|
||||
this.table.filter!.search = data as comSearchData[]
|
||||
this.onTableHeaderAction('refresh', { event: 'com-search', data: data })
|
||||
this.table.filter!.search = this.getComSearchData()
|
||||
|
||||
// 刷新表格
|
||||
this.onTableHeaderAction('refresh', { event: 'com-search', data: this.table.filter!.search })
|
||||
},
|
||||
],
|
||||
[
|
||||
@ -553,4 +555,47 @@ export default class baTable {
|
||||
|
||||
this.comSearch.form = Object.assign(this.comSearch.form, form)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通用搜索数据
|
||||
*/
|
||||
getComSearchData = () => {
|
||||
const comSearchData: comSearchData[] = []
|
||||
|
||||
for (const key in this.comSearch.form) {
|
||||
if (!this.comSearch.fieldData.has(key)) continue
|
||||
|
||||
let val = null
|
||||
const fieldDataTemp = this.comSearch.fieldData.get(key)
|
||||
if (fieldDataTemp.render == 'datetime' && (fieldDataTemp.operator == 'RANGE' || fieldDataTemp.operator == 'NOT RANGE')) {
|
||||
// 时间范围
|
||||
if (this.comSearch.form[key] && this.comSearch.form[key].length >= 2) {
|
||||
if (fieldDataTemp.comSearchRender == 'date') {
|
||||
val = this.comSearch.form[key][0] + ' 00:00:00' + ',' + this.comSearch.form[key][1] + ' 23:59:59'
|
||||
} else {
|
||||
val = this.comSearch.form[key][0] + ',' + this.comSearch.form[key][1]
|
||||
}
|
||||
}
|
||||
} else if (fieldDataTemp.operator == 'RANGE' || fieldDataTemp.operator == 'NOT RANGE') {
|
||||
// 普通的范围筛选,公共搜索初始化时已准备好 start 和 end 字段
|
||||
if (!this.comSearch.form[key + '-start'] && !this.comSearch.form[key + '-end']) {
|
||||
continue
|
||||
}
|
||||
val = this.comSearch.form[key + '-start'] + ',' + this.comSearch.form[key + '-end']
|
||||
} else if (this.comSearch.form[key]) {
|
||||
val = this.comSearch.form[key]
|
||||
}
|
||||
|
||||
if (val !== null) {
|
||||
comSearchData.push({
|
||||
field: key,
|
||||
val: val,
|
||||
operator: fieldDataTemp.operator,
|
||||
render: fieldDataTemp.render,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return comSearchData
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user