Skip to content

Commit

Permalink
add default
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed Aug 10, 2021
1 parent 4ba495e commit 2252b9b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 15 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.9.7",
"version": "0.9.8",
"description": "个人实验项目, 本框架的目标是借鉴并超越django admin的自动化思想, 实现UI前端的极简快速定制开发",
"main": "index.js",
"files": [
Expand Down
33 changes: 24 additions & 9 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<div id="app" v-cloak :class="{mobile_mode:isMobile}">
<router-view v-if="layout === 'main'">
</router-view>
<template v-if="layout === 'main'">
<component :is="view"></component>
</template>
<template v-else>
<el-menu class="el-menu-demo" mode="horizontal" router>
<el-menu-item index="/" class="brand">
Expand Down Expand Up @@ -37,7 +38,9 @@
import LoginView from './views/auth/login.vue'
export default {
data () {
return {}
return {
view: null
}
},
components: {
SideBar,
Expand All @@ -50,6 +53,19 @@
this.$router.replace('/auth/login/')
})
},
methods: {
logout(){
this.$confirm("确定要退出登录吗?").then(() => {
this.$store.dispatch('logout')
}).catch(this.onServerResponseError)
},
changeRoute(to) {
if (to.matched.length > 0) {
this.view = {...to.matched[to.matched.length - 1].components.default}
}
}
},
computed: {
layout (){
return this.$route.meta.layout
Expand All @@ -62,14 +78,13 @@
}
return false
}
},
methods: {
logout(){
this.$confirm("确定要退出登录吗?").then(() => {
this.$store.dispatch('logout')
}).catch(this.onServerResponseError)
},
watch: {
$route (newVal, oldVal) {
this.changeRoute(newVal, oldVal)
}
}
}
</script>
Expand Down
5 changes: 1 addition & 4 deletions src/components/layout/ViewTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@
}
this.curTab = tab.name
},
changeRoute (newVal, oldVal) {
// console.log(newVal)
// console.log(oldVal)
changeRoute (newVal) {
let to = newVal
// let view = to.matched[0]
let view = null
if (to.matched.length > 0) {
view = to.matched[to.matched.length - 1]
Expand Down
2 changes: 1 addition & 1 deletion src/components/model/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<slot name="actions"></slot>
</el-col>
<el-col :span="6" class="flex-right">
<actions :items="topActionItems" :context="{model: model}" style="margin-right: 1rem"></actions>
<actions :items="topActionItems" :context="{model: model, view: this}" style="margin-right: 1rem"></actions>
</el-col>
</el-row>
<x-form :url="url" :items="formItems" v-model="formValue" ref="form" :options="options.form" :disabled="disabled"
Expand Down
32 changes: 32 additions & 0 deletions src/components/stats/SmartMetic.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<span>{{result}}</span>
</template>
<script>
import {template} from 'lodash'
export default{
props: {
appModel: String,
query: String,
measure: String
},
data () {
return {
result: null
}
},
components: {},
created () {
this.load()
},
methods: {
load () {
let s = template(this.query)(this.$attrs)
let url = `/${this.appModel.replace('.', '/')}/smart_stat/?${s}&measures=${this.measure}`
return this.$http.get(url).then(({data}) => {
this.result = Object.values(data.data)[0]
})
}
},
computed: {}
}
</script>
16 changes: 16 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ function import_or_use_template(path, template) {
}
}

export function setDefaultLayout(rs) {
let ps =location.href.split(/app_default_layout=([^#&]*)/g)
if(ps.length<3) {
return
}
let dl = ps[1]
rs.forEach(r => {
if(!r.meta.layout) {
r.meta.layout = dl
}
if(r.children) {
setDefaultLayout(r.children)
}
})
}

export default router

export var genModelRouters = function (apps, importFunc, defaultLayout) {
Expand Down

0 comments on commit 2252b9b

Please sign in to comment.