Skip to content

Commit

Permalink
relations normalize items, widget function
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed Sep 26, 2019
1 parent bf34fa6 commit 7afc0f8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-django",
"version": "0.5.1",
"version": "0.5.2",
"description": "个人实验项目, 本框架的目标是借鉴并超越django admin的自动化思想, 实现UI前端的极简快速定制开发",
"main": "index.js",
"files": [
Expand Down
27 changes: 15 additions & 12 deletions src/components/model/Relations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<el-tabs type="border-card" v-if="items.length>0">
<el-tab-pane lazy v-for="m in modelItems" :key="m.name">
<template slot="label"><i :class="`fa fa-${m.icon}`"></i>{{m.label}}</template>
<model-table :appModel="m.name" :baseQueries="m.baseQueries" :items="m.items" :parent="parent"
:defaults="m.defaults"></model-table>
<model-table :appModel="m.name" :baseQueries="m.baseQueries" :items="m.items" :parent="parent"></model-table>
</el-tab-pane>
</el-tabs>
</template>
Expand All @@ -24,17 +23,21 @@
},
components: {ModelTable},
created () {
this.modelItems = array_normalize(this.items, {}, (a) => {
let m = a.model = Model(a.name)
a.icon = m.config.icon
a.label = m.config.verbose_name
return a
})
this.normalizeItems()
},
methods: {},
computed: {
modelItems () {
return
methods: {
normalizeItems () {
this.modelItems = array_normalize(this.items, {}, (a) => {
let m = a.model = Model(a.name)
a.icon = m.config.icon
a.label = m.config.verbose_name
return a
})
}
},
watch: {
items () {
this.normalizeItems()
}
}
}
Expand Down
20 changes: 14 additions & 6 deletions src/components/model/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
this.$emit('loaded', v)
},
onSearch () {
this.$refs.table.updateQueries(this.search)
this.$refs.table.updateQueries({...this.search, page: 1})
},
onModelPosted ({appModel, id}) {
let dps = this.model.options.dependencies
Expand Down Expand Up @@ -248,11 +248,19 @@
})
},
defaultWidget(f){
// console.log(f)
return f.model ? ForeignKey :
(f.type == 'boolean' ? TrueFlag :
( ['datetime', 'date'].includes(f.type) ? Date2Now :
f.choices ? ChoicesDisplay : undefined))
if (f.model) {
return ForeignKey
} else if (f.type == 'boolean') {
return TrueFlag
} else if (['datetime', 'date'].includes(f.type)) {
return Date2Now
} else if (f.choices) {
return ChoicesDisplay
} else if (f.child) {
return function ({value}) {
return value.map(a => Object.values(a).join(',')).join('\n')
}
}
},
excelFormat(data){
let ds = data.map((d) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/table/TableColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@change="onCellValueChange"></form-widget>
<component :is="f.widget" v-model="row[f.name]" :context="context(row, $index)" :field="f"
v-else-if="f.widget && typeof f.widget == 'object'"></component>
<span v-else-if="f.widget && typeof f.widget == 'function'" v-html="f.widget(row)"></span>
<span v-else-if="f.widget && typeof f.widget == 'function'" v-html="f.widget({value:row[f.name],field,row})"></span>
<template v-else>{{row[f.name]}}</template>
<span v-if="!row[f.name]" class="empty">&nbsp;</span>
</div>
Expand All @@ -34,7 +34,7 @@
@change="onCellValueChange"></form-widget>
<component :is="f.widget" v-model="row[f.name]" :context="context(row, $index)" :field="f"
v-else-if="f.widget && typeof f.widget == 'object'"></component>
<span v-else-if="f.widget && typeof f.widget == 'function'" v-html="f.widget(row)"></span>
<span v-else-if="f.widget && typeof f.widget == 'function'" v-html="f.widget({value:row[f.name],field,row})"></span>
<template v-else>{{row[f.name]}}</template>

</template>
Expand Down

0 comments on commit 7afc0f8

Please sign in to comment.