Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
refactor: layout setting drawer. (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby authored Mar 22, 2020
1 parent aa49508 commit 3221a49
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
16 changes: 7 additions & 9 deletions src/components/SettingDrawer/SettingDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
width="300"
closable
@close="onClose"
:visible="visible"
:visible="layoutSetting"
>
<div class="setting-drawer-index-content">
<div :style="{ marginBottom: '24px' }">
Expand Down Expand Up @@ -194,6 +194,7 @@ import SettingItem from '@/components/SettingDrawer/SettingItem'
import config from '@/config/defaultSettings'
import { updateTheme, colorList } from './setting'
import { mixin, mixinDevice } from '@/utils/mixin'
import { mapActions, mapGetters } from 'vuex'
export default {
components: {
Expand All @@ -202,7 +203,6 @@ export default {
mixins: [mixin, mixinDevice],
data() {
return {
visible: false,
colorList,
baseConfig: Object.assign({}, config)
}
Expand All @@ -214,15 +214,13 @@ export default {
updateTheme(this.primaryColor)
}
},
computed: {
...mapGetters(['layoutSetting'])
},
methods: {
showDrawer() {
this.visible = true
},
...mapActions(['setSidebar', 'ToggleLayoutSetting']),
onClose() {
this.visible = false
},
toggle() {
this.visible = !this.visible
this.ToggleLayoutSetting(false)
},
handleMenuTheme(theme) {
this.baseConfig.navTheme = theme
Expand Down
22 changes: 5 additions & 17 deletions src/components/Tools/UserMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</a>
<a
href="javascript:void(0)"
@click="showOptionModal"
@click="handleShowLayoutSetting"
>
<a-tooltip
placement="bottom"
Expand Down Expand Up @@ -60,34 +60,23 @@
</a-menu-item>
</a-menu>
</a-dropdown>
<setting-drawer ref="drawer"></setting-drawer>
</div>
</template>

<script>
import HeaderComment from './HeaderComment'
import SettingDrawer from '@/components/SettingDrawer/SettingDrawer'
import { mapActions, mapGetters } from 'vuex'
export default {
name: 'UserMenu',
components: {
HeaderComment,
SettingDrawer
},
data() {
return {
optionVisible: true
}
},
mounted() {
this.optionVisible = this.$refs.drawer.visible
HeaderComment
},
computed: {
...mapGetters(['user', 'options'])
},
methods: {
...mapActions(['logout']),
...mapActions(['logout', 'ToggleLayoutSetting']),
handleLogout() {
const that = this
Expand All @@ -110,9 +99,8 @@ export default {
onCancel() {}
})
},
showOptionModal() {
this.optionVisible = this.$refs.drawer.visible
this.$refs.drawer.toggle()
handleShowLayoutSetting() {
this.ToggleLayoutSetting(true)
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/layouts/BasicLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<global-footer />
</a-layout-footer>
</a-layout>

<setting-drawer ref="drawer"></setting-drawer>
</a-layout>
</template>

Expand All @@ -68,6 +70,7 @@ import RouteView from './RouteView'
import SideMenu from '@/components/Menu/SideMenu'
import GlobalHeader from '@/components/GlobalHeader'
import GlobalFooter from '@/components/GlobalFooter'
import SettingDrawer from '@/components/SettingDrawer/SettingDrawer'
export default {
name: 'BasicLayout',
Expand All @@ -76,7 +79,8 @@ export default {
RouteView,
SideMenu,
GlobalHeader,
GlobalFooter
GlobalFooter,
SettingDrawer
},
data() {
return {
Expand Down
1 change: 1 addition & 0 deletions src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const getters = {
device: state => state.app.device,
theme: state => state.app.theme,
color: state => state.app.color,
layoutSetting: state => state.app.layoutSetting,
token: state => state.user.token,
user: state => state.user.user,
addRouters: state => state.permission.addRouters,
Expand Down
13 changes: 11 additions & 2 deletions src/store/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
DEFAULT_FIXED_SIDEMENU,
DEFAULT_FIXED_HEADER_HIDDEN,
DEFAULT_CONTENT_WIDTH_TYPE,
API_URL
API_URL,
LAYOUT_SETTING
} from '@/store/mutation-types'

const app = {
Expand All @@ -22,7 +23,8 @@ const app = {
fixSiderbar: false,
autoHideHeader: false,
color: null,
apiUrl: null
apiUrl: null,
layoutSetting: false
},
mutations: {
SET_API_URL: (state, apiUrl) => {
Expand Down Expand Up @@ -72,6 +74,10 @@ const app = {
TOGGLE_COLOR: (state, color) => {
Vue.ls.set(DEFAULT_COLOR, color)
state.color = color
},
TOGGLE_LAYOUT_SETTING: (state, show) => {
Vue.ls.set(LAYOUT_SETTING, show)
state.layoutSetting = show
}
},
actions: {
Expand Down Expand Up @@ -107,6 +113,9 @@ const app = {
},
ToggleColor({ commit }, color) {
commit('TOGGLE_COLOR', color)
},
ToggleLayoutSetting({ commit }, show) {
commit('TOGGLE_LAYOUT_SETTING', show)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/store/mutation-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DEFAULT_CONTENT_WIDTH_TYPE = 'DEFAULT_CONTENT_WIDTH_TYPE'
export const USER = 'USER'
export const API_URL = 'API_URL'
export const OPTIONS = 'OPTIONS'
export const LAYOUT_SETTING = 'LAYOUT_SETTING'

export const CONTENT_WIDTH_TYPE = {
Fluid: 'Fluid',
Expand Down

0 comments on commit 3221a49

Please sign in to comment.