perf: optimize the experience of collapsing the menu (#493)

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/495/head
Ryan Wang 2022-03-08 16:43:25 +08:00 committed by GitHub
parent 545252f11e
commit 54e5f3829a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 50 deletions

View File

@ -22,11 +22,11 @@ export default {
switch (deviceType) { switch (deviceType) {
case DEVICE_TYPE.DESKTOP: case DEVICE_TYPE.DESKTOP:
$store.commit('TOGGLE_DEVICE', 'desktop') $store.commit('TOGGLE_DEVICE', 'desktop')
$store.dispatch('setSidebar', true) $store.dispatch('setSidebar', this.$store.getters.sidebar)
break break
case DEVICE_TYPE.TABLET: case DEVICE_TYPE.TABLET:
$store.commit('TOGGLE_DEVICE', 'tablet') $store.commit('TOGGLE_DEVICE', 'tablet')
$store.dispatch('setSidebar', false) $store.dispatch('setSidebar', this.$store.getters.sidebar)
break break
case DEVICE_TYPE.MOBILE: case DEVICE_TYPE.MOBILE:
default: default:

View File

@ -1,6 +1,5 @@
<template> <template>
<transition name="showHeader"> <transition name="showHeader">
<div v-if="visible" class="header-animat">
<a-layout-header <a-layout-header
v-if="visible" v-if="visible"
:class="[ :class="[
@ -30,7 +29,6 @@
</div> </div>
</div> </div>
</a-layout-header> </a-layout-header>
</div>
</transition> </transition>
</template> </template>
@ -116,11 +114,6 @@ export default {
</script> </script>
<style lang="less"> <style lang="less">
.header-animat {
position: relative;
z-index: 999;
}
.showHeader-enter-active { .showHeader-enter-active {
transition: all 0.25s ease; transition: all 0.25s ease;
} }

View File

@ -176,6 +176,7 @@ export default {
} else { } else {
this.handleSetFixedHeader(true) this.handleSetFixedHeader(true)
this.handleSetFixedSidebar(false) this.handleSetFixedSidebar(false)
this.$store.dispatch('setSidebar', true)
} }
}, },
handleContentWidthChange(type) { handleContentWidthChange(type) {

View File

@ -1,6 +1,7 @@
<template> <template>
<div class="logo"> <div class="logo">
<img <img
:style="{ width: sidebarOpened ? '64px' : '48px' }"
alt="Halo Logo" alt="Halo Logo"
class="select-none cursor-pointer hover:brightness-125 transition-all" class="select-none cursor-pointer hover:brightness-125 transition-all"
src="/images/logo.svg" src="/images/logo.svg"
@ -13,9 +14,11 @@
import { mapActions, mapGetters } from 'vuex' import { mapActions, mapGetters } from 'vuex'
import apiClient from '@/utils/api-client' import apiClient from '@/utils/api-client'
import throttle from 'lodash.throttle' import throttle from 'lodash.throttle'
import { mixin } from '@/mixins/mixin'
export default { export default {
name: 'Logo', name: 'Logo',
mixins: [mixin],
data() { data() {
return { return {
clickCount: 0 clickCount: 0

View File

@ -131,15 +131,6 @@ export default {
this.setSidebar(!this.collapsed) this.setSidebar(!this.collapsed)
triggerWindowResizeEvent() triggerWindowResizeEvent()
}, },
paddingCalc() {
let left = ''
if (this.sidebarOpened) {
left = this.isDesktop() ? '256px' : '80px'
} else {
left = (this.isMobile() && '0') || (this.fixedSidebar && '80px') || '0'
}
return left
},
menuSelect() { menuSelect() {
if (!this.isDesktop()) { if (!this.isDesktop()) {
this.collapsed = false this.collapsed = false

View File

@ -3,6 +3,7 @@ const getters = {
theme: state => state.app.theme, theme: state => state.app.theme,
color: state => state.app.color, color: state => state.app.color,
layoutSetting: state => state.app.layoutSetting, layoutSetting: state => state.app.layoutSetting,
sidebar: state => state.app.sidebar,
loginModal: state => state.app.loginModal, loginModal: state => state.app.loginModal,
token: state => state.user.token, token: state => state.user.token,
user: state => state.user.user, user: state => state.user.user,

View File

@ -27,12 +27,8 @@ const app = {
}, },
mutations: { mutations: {
SET_SIDEBAR_TYPE: (state, type) => { SET_SIDEBAR_TYPE: (state, type) => {
state.sidebar = type
Vue.ls.set(SIDEBAR_TYPE, type) Vue.ls.set(SIDEBAR_TYPE, type)
}, state.sidebar = type
CLOSE_SIDEBAR: state => {
Vue.ls.set(SIDEBAR_TYPE, true)
state.sidebar = false
}, },
TOGGLE_DEVICE: (state, device) => { TOGGLE_DEVICE: (state, device) => {
state.device = device state.device = device