Skip to content

Commit

Permalink
drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed Oct 22, 2020
1 parent 0451c6c commit 0dbee84
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 10 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.7.16",
"version": "0.8.0",
"description": "个人实验项目, 本框架的目标是借鉴并超越django admin的自动化思想, 实现UI前端的极简快速定制开发",
"main": "index.js",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</el-col>
</el-row>
<!--<login-view></login-view>-->
<drawer></drawer>
</template>
</div>
</template>
Expand All @@ -32,6 +33,7 @@
import {mapState} from 'vuex'
import SideBar from './components/layout/SideBar.vue'
import ViewTabs from './components/layout/ViewTabs.vue'
import Drawer from './components/layout/Drawer.vue'
import LoginView from './views/auth/login.vue'
export default {
data () {
Expand All @@ -40,6 +42,7 @@
components: {
SideBar,
ViewTabs,
Drawer,
LoginView,
},
created(){
Expand Down
11 changes: 8 additions & 3 deletions src/components/layout/Actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</template>
</el-dropdown-menu>
</el-dropdown>

</el-button-group>
</template>
<script>
Expand All @@ -38,7 +39,8 @@
},
data () {
return {
_items: []
_items: [],
dialog: undefined
}
},
components: {},
Expand All @@ -47,7 +49,10 @@
},
methods: {
handleCommand (command) {
command(this.context)
if(typeof command === 'function') {
return command(this.context)
}
this.$store.state.bus.$emit('opendrawer', {component: command, context: this.context})
},
normalizeItem(a)
{
Expand All @@ -65,7 +70,7 @@
},
normalizeItems() {
this._items = arrayNormalize(this.items, this.map, this.normalizeItem)
},
}
},
computed: {
// _items (){
Expand Down
45 changes: 45 additions & 0 deletions src/components/layout/Drawer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<el-drawer v-if="drawer" :visible.sync="drawer" @closed="onDialogDone">
<component :is="drawer.component" v-bind="[drawer.context]" @done="onDialogDone"></component>
</el-drawer>
</template>
<script>
export default{
data () {
return {
drawer: undefined
}
},
components: {},
created (){
this.$store.state.bus.$on('opendrawer', this.onOpen)
},
methods: {
onOpen (context) {
this.drawer = undefined
let c = context.component
if(typeof c === 'string') {
import('@/views/'+c+'.vue').then( module => {
this.drawer = {component: module.default, context: this.filterContext(context.context)}
})
} else{
this.drawer = {...context}
}
},
onDialogDone () {
this.drawer = undefined
},
filterContext(ctx) {
let d = {}
Object.keys(ctx).forEach(k => {
if (k.startsWith('$')) {
return
}
d[k] = ctx[k]
})
return d
}
},
computed: {}
}
</script>
17 changes: 11 additions & 6 deletions src/components/model/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</el-drawer>

<remote-table :items="tableItems" :url="model.getListUrl()" ref="table" v-if="optionLoaded"
@loaded="onLoaded" v-bind="rtAttrs" v-on="$listeners" @selection-change="onSelectionChange">
@loaded="onLoaded" v-bind="rtAttrs" v-on="$listeners" @selection-change="onSelectionChange">

<template slot="left" v-if="$slots.left">
<slot name="left"></slot>
Expand Down Expand Up @@ -201,7 +201,7 @@
let orderingFields = get(this.model.options, 'actions.SEARCH.ordering_fields', [])
let rs = arrayNormalize(config.listItems, this.model.fieldConfigs, (a) => {
Object.assign(a, {field: this.model.fieldConfigs[a.name]})
if(!a.formatter) {
if (!a.formatter) {
a.formatter = this.genDefaultFormatter(a)
}
if (!a.useFormWidget) {
Expand All @@ -222,7 +222,10 @@
return ({selection, scope}) => {
let ids = selection.map((a) => a.id)
let qd = {...this._baseQueries, ...this.search}
return this.$http.post(`${this.model.getListUrl()}${action.api || action.name}/?${Qs.stringify(qd, {arrayFormat: 'comma'})}`, {batch_action_ids: ids, ...action.context, scope}).catch(this.onServerResponseError)
return this.$http.post(`${this.model.getListUrl()}${action.api || action.name}/?${Qs.stringify(qd, {arrayFormat: 'comma'})}`, {
batch_action_ids: ids, ...action.context,
scope
}).catch(this.onServerResponseError)
}
},
addToParent ({selection}) {
Expand Down Expand Up @@ -349,8 +352,10 @@
if (mc.itemActions) {
mc.itemActions.forEach(a => {
ractions[a.name] = a
a.do = ({row}) => {
this.$router.push(`${this.model.getDetailUrl(row.id)}${a.name}/`)
if (!a.do) {
a.do = ({row}) => {
this.$router.push(`${this.model.getDetailUrl(row.id)}${a.name}/`)
}
}
})
}
Expand Down Expand Up @@ -381,7 +386,7 @@
searchMap () {
let d = {}
this.tableItems.forEach(a => {
d[a.name]={name: a.name, label: a.label}
d[a.name] = {name: a.name, label: a.label}
})
return d
},
Expand Down

0 comments on commit 0dbee84

Please sign in to comment.