Skip to content

Commit

Permalink
Merge branch 'master' of github.com:szuprefix/vue-django
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed May 1, 2020
2 parents 94e07ef + c8a8eef commit 8878180
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
41 changes: 26 additions & 15 deletions src/components/model/Search.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<el-input
<el-input title="模糊搜索, 多个关键词请用空格隔开"
:placeholder="`搜索${searchFieldNames}`"
v-model="value.search"
suffix-icon="el-icon-search"
Expand All @@ -11,29 +11,28 @@
v-if="searchFields.length>0">
</el-input>
<template v-for="f in filterFields" v-if="! (f.name in exclude)">
<el-select v-model="value[f.name]" clearable :placeholder="`请选择${f.label}`" v-if="f.type=='boolean'"
<el-select v-model="value[f.name]" clearable :placeholder="`请选择${f.label}`" v-if="f.widget =='boolean'"
:title="f.label" :style="`width:${f.label.length+5}rem;min-width:8rem;`" @change="onSearch">
<el-option :label="f.label" :value="true"></el-option>
<el-option :label="getBoolFieldFalseLabel(f.label)" :value="false"></el-option>
</el-select>
<model-select :field="f" v-model="value[f.name]" @input="onSearch"
:showCreate="false" :appModel="f.model"
:title="f.label" :style="`width:${f.label.length+5}rem;min-width:8rem;`"
v-else-if="f.model && f.name !== genericContentTypeField" :pageSize="100"></model-select>
<el-select v-model="value[f.name]" clearable :placeholder="`请选择${f.label}`" v-else-if="f.choices"
v-else-if="f.widget === 'modelselect'" :pageSize="100"></model-select>
<el-select v-model="value[f.name]" clearable :placeholder="`请选择${f.label}`"
v-else-if="f.widget === 'select'"
:title="f.label" @change="onSearch">
<el-option v-for="c in f.choices" :label="c.display_name" :value="c.value" :key="c.value"></el-option>
</el-select>
<date-range :field="f" v-model="value[`${f.name}__range`]" separator=","
:title="f.label" v-else-if="['date', 'datetime'].includes(f.type)" @input="onSearch"></date-range>
</template>
:title="f.label" v-else-if="f.widget === 'daterange'" @input="onSearch"></date-range>

<template v-for="f in filterFields" v-if="! (f.name in exclude)">
<array-input v-if="f.type === 'string' && f.lookups && f.lookups.includes('in')"
<array-input v-if="f.widget === 'array'"
v-model="value[`${f.name}__in`]" :placeholder="`批量查询${f.label}`" style="width: 10rem;"
:title="f.label" :autosize="{minRows:1,maxRows:4}" @change="onSearch"></array-input>
<el-input v-model="value[f.name]" :placeholder="`请输入${f.label}`"
v-else-if="f.type === 'string' && f.lookups && f.lookups.includes('exact') && !f.lookups.includes('in') && !searchFields.includes(f.label)"
v-else-if="f.widget === 'input'"
:title="f.label" style="width: 10rem;" clearable @change="onSearch"></el-input>
</template>
</div>
Expand Down Expand Up @@ -61,6 +60,7 @@
},
components: {ModelSelect, ArrayInput, DateRange},
created () {
this.init()
},
methods: {
onSearch () {
Expand All @@ -75,26 +75,27 @@
return {multiple: false, ...a, label, widget: this.defaultWidget(a)}
})
this.filterFields = this.reorder(ffields)
console.log(search.filter_fields, ffields, this.filterFields)
this.filters = Object.assign({}, this.getFilters())
},
defaultWidget (item) {
let f = item
if (f.type=='boolean') {
if (f.type == 'boolean') {
return 'boolean'
} else if (f.model && f.name !== this.genericContentTypeField) {
} else if (f.model /* && f.name !== this.genericContentTypeField */) {
return 'modelselect'
} else if (f.choices) {
return 'select'
} else if (['date', 'datetime'].includes(f.type)) {
} else if (['date', 'datetime'].includes(f.type) && f.lookups && f.lookups.includes('range')) {
return 'daterange'
} else if (f.type === 'string' && f.lookups && f.lookups.includes('in')) {
return 'array'
} else if (f.type === 'string' && f.lookups && f.lookups.includes('exact') && !f.lookups.includes('in') && !this.searchFields.includes(f.label)) {
} else if (f.type === 'string' && f.lookups && f.lookups.includes('exact') && !f.lookups.includes('in')) {
return 'input'
}
},
reorder (items) {
let os = ['boolean', 'select', 'modelselect','daterange', 'input', 'array']
let os = ['boolean', 'select', 'modelselect', 'input', 'array', 'daterange']
let rs = []
os.forEach(w => {
rs = rs.concat(items.filter(a => a.widget === w))
Expand Down Expand Up @@ -137,7 +138,17 @@
vns.push(c.label)
}
})
return this.searchFields.filter((a) => !(a in vns)).join(',')
let rs = this.searchFields.filter((a) => !(a in vns))
let vm = {}
if(this.map) {
Object.keys(this.map).forEach(a => {
let c = this.model.fieldConfigs[a]
if (c) {
vm[c.label] = this.map[a].label
}
})
}
return rs.map(a => vm[a] || a).join(',')
},
genericContentTypeField () {
let popt = this.model.options
Expand Down
5 changes: 1 addition & 4 deletions src/components/model/Table.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<search v-model="search" :model="model" :items="searchItems" :exclude="_baseQueries" ref="search"
v-if="showSearch" :map="searchMap" @change="onSearch"></search>
v-if="showSearch && optionLoaded" :map="searchMap" @change="onSearch"></search>
<batch-actions :items="batchActionItems" @done="refresh" :context="{selection,count}"
v-if="batchActionItems.length>0"></batch-actions>
<el-drawer :visible.sync="editing" direction="rtl"
Expand Down Expand Up @@ -134,9 +134,6 @@
methods: {
init () {
this.model.loadOptionsAndViewsConfig().then(() => {
if (this.$refs.search) {
this.$refs.search.init()
}
this.parentQueries = Object.assign({}, this.getParentQueries())
return this.normalizeItems()
}).then(() => {
Expand Down

0 comments on commit 8878180

Please sign in to comment.