Commit 82c3186309971517183fc44bfcac159612e48a7b

Authored by Vben
1 parent 3c4de9b0

fix(menu): make sure the menu is displayed properly on the small screen close #336

CHANGELOG.zh_CN.md
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 ### 🐛 Bug Fixes 7 ### 🐛 Bug Fixes
8 8
9 - 确保 CountDownInput 组件重置清空值 9 - 确保 CountDownInput 组件重置清空值
  10 +- 修复分割模式下在小屏幕中显示问题
10 11
11 ## 2.1.0 (2021-03-15) 12 ## 2.1.0 (2021-03-15)
12 13
package.json
@@ -118,7 +118,7 @@ @@ -118,7 +118,7 @@
118 "vite-plugin-style-import": "^0.8.1", 118 "vite-plugin-style-import": "^0.8.1",
119 "vite-plugin-svg-icons": "^0.3.5", 119 "vite-plugin-svg-icons": "^0.3.5",
120 "vite-plugin-theme": "^0.5.0", 120 "vite-plugin-theme": "^0.5.0",
121 - "vite-plugin-windicss": "0.8.3", 121 + "vite-plugin-windicss": "0.8.4",
122 "vue-eslint-parser": "^7.6.0", 122 "vue-eslint-parser": "^7.6.0",
123 "yargs": "^16.2.0" 123 "yargs": "^16.2.0"
124 }, 124 },
src/components/Application/src/AppProvider.vue
1 <script lang="ts"> 1 <script lang="ts">
2 - import { defineComponent, toRefs, ref } from 'vue'; 2 + import { defineComponent, toRefs, ref, unref } from 'vue';
3 3
4 import { createAppProviderContext } from './useAppContext'; 4 import { createAppProviderContext } from './useAppContext';
5 5
6 import designSetting from '/@/settings/designSetting'; 6 import designSetting from '/@/settings/designSetting';
7 import { createBreakpointListen } from '/@/hooks/event/useBreakpoint'; 7 import { createBreakpointListen } from '/@/hooks/event/useBreakpoint';
8 import { propTypes } from '/@/utils/propTypes'; 8 import { propTypes } from '/@/utils/propTypes';
  9 + import { appStore } from '/@/store/modules/app';
  10 + import { MenuModeEnum, MenuTypeEnum } from '/@/enums/menuEnum';
9 11
10 export default defineComponent({ 12 export default defineComponent({
11 name: 'AppProvider', 13 name: 'AppProvider',
@@ -14,18 +16,56 @@ @@ -14,18 +16,56 @@
14 prefixCls: propTypes.string.def(designSetting.prefixCls), 16 prefixCls: propTypes.string.def(designSetting.prefixCls),
15 }, 17 },
16 setup(props, { slots }) { 18 setup(props, { slots }) {
17 - const isMobileRef = ref(false); 19 + const isMobile = ref(false);
  20 + const isSetState = ref(false);
18 21
19 createBreakpointListen(({ screenMap, sizeEnum, width }) => { 22 createBreakpointListen(({ screenMap, sizeEnum, width }) => {
20 const lgWidth = screenMap.get(sizeEnum.LG); 23 const lgWidth = screenMap.get(sizeEnum.LG);
21 if (lgWidth) { 24 if (lgWidth) {
22 - isMobileRef.value = width.value - 1 < lgWidth; 25 + isMobile.value = width.value - 1 < lgWidth;
23 } 26 }
  27 + handleRestoreState();
24 }); 28 });
25 29
26 const { prefixCls } = toRefs(props); 30 const { prefixCls } = toRefs(props);
27 - createAppProviderContext({ prefixCls, isMobile: isMobileRef }); 31 + createAppProviderContext({ prefixCls, isMobile });
28 32
  33 + function handleRestoreState() {
  34 + if (unref(isMobile)) {
  35 + if (!unref(isSetState)) {
  36 + isSetState.value = true;
  37 + const {
  38 + menuSetting: {
  39 + type: menuType,
  40 + mode: menuMode,
  41 + collapsed: menuCollapsed,
  42 + split: menuSplit,
  43 + },
  44 + } = appStore.getProjectConfig;
  45 + appStore.commitProjectConfigState({
  46 + menuSetting: {
  47 + type: MenuTypeEnum.SIDEBAR,
  48 + mode: MenuModeEnum.INLINE,
  49 + split: false,
  50 + },
  51 + });
  52 + appStore.commitBeforeMiniState({ menuMode, menuCollapsed, menuType, menuSplit });
  53 + }
  54 + } else {
  55 + if (unref(isSetState)) {
  56 + isSetState.value = false;
  57 + const { menuMode, menuCollapsed, menuType, menuSplit } = appStore.getBeforeMiniState;
  58 + appStore.commitProjectConfigState({
  59 + menuSetting: {
  60 + type: menuType,
  61 + mode: menuMode,
  62 + collapsed: menuCollapsed,
  63 + split: menuSplit,
  64 + },
  65 + });
  66 + }
  67 + }
  68 + }
29 return () => slots.default?.(); 69 return () => slots.default?.();
30 }, 70 },
31 }); 71 });
src/components/Menu/src/components/MenuItemContent.vue
1 <template> 1 <template>
2 - <span :class="`${prefixCls}-wrapper`"> 2 + <span :class="`${prefixCls}- flex items-center `">
3 <Icon v-if="getIcon" :icon="getIcon" :size="18" :class="`${prefixCls}-wrapper__icon`" /> 3 <Icon v-if="getIcon" :icon="getIcon" :size="18" :class="`${prefixCls}-wrapper__icon`" />
4 {{ getI18nName }} 4 {{ getI18nName }}
5 </span> 5 </span>
src/hooks/event/useBreakpoint.ts
@@ -60,6 +60,7 @@ export function createBreakpointListen(fn?: (opt: CreateCallbackParams) =&gt; void) @@ -60,6 +60,7 @@ export function createBreakpointListen(fn?: (opt: CreateCallbackParams) =&gt; void)
60 getWindowWidth(); 60 getWindowWidth();
61 resizeFn(); 61 resizeFn();
62 }, 62 },
  63 + // wait: 100,
63 }); 64 });
64 65
65 getWindowWidth(); 66 getWindowWidth();
src/layouts/default/sider/LayoutSider.vue
@@ -11,10 +11,9 @@ @@ -11,10 +11,9 @@
11 collapsible 11 collapsible
12 :class="getSiderClass" 12 :class="getSiderClass"
13 :width="getMenuWidth" 13 :width="getMenuWidth"
14 - :collapsed="getIsMobile ? false : getCollapsed" 14 + :collapsed="getCollapsed"
15 :collapsedWidth="getCollapsedWidth" 15 :collapsedWidth="getCollapsedWidth"
16 :theme="getMenuTheme" 16 :theme="getMenuTheme"
17 - @collapse="onCollapseChange"  
18 @breakpoint="onBreakpointChange" 17 @breakpoint="onBreakpointChange"
19 v-bind="getTriggerAttr" 18 v-bind="getTriggerAttr"
20 > 19 >
@@ -66,7 +65,7 @@ @@ -66,7 +65,7 @@
66 65
67 useDragLine(sideRef, dragBarRef); 66 useDragLine(sideRef, dragBarRef);
68 67
69 - const { getCollapsedWidth, onBreakpointChange, onCollapseChange } = useSiderEvent(); 68 + const { getCollapsedWidth, onBreakpointChange } = useSiderEvent();
70 69
71 const getMode = computed(() => { 70 const getMode = computed(() => {
72 return unref(getSplit) ? MenuModeEnum.INLINE : null; 71 return unref(getSplit) ? MenuModeEnum.INLINE : null;
@@ -121,7 +120,6 @@ @@ -121,7 +120,6 @@
121 onBreakpointChange, 120 onBreakpointChange,
122 getMode, 121 getMode,
123 getSplitType, 122 getSplitType,
124 - onCollapseChange,  
125 getShowTrigger, 123 getShowTrigger,
126 }; 124 };
127 }, 125 },
src/layouts/default/sider/useLayoutSider.ts
@@ -11,31 +11,19 @@ import { useDebounce } from &#39;/@/hooks/core/useDebounce&#39;; @@ -11,31 +11,19 @@ import { useDebounce } from &#39;/@/hooks/core/useDebounce&#39;;
11 * Handle related operations of menu events 11 * Handle related operations of menu events
12 */ 12 */
13 export function useSiderEvent() { 13 export function useSiderEvent() {
14 - const initRef = ref(false);  
15 const brokenRef = ref(false); 14 const brokenRef = ref(false);
16 - const collapseRef = ref(true);  
17 15
18 - const { setMenuSetting, getCollapsed, getMiniWidthNumber } = useMenuSetting(); 16 + const { getMiniWidthNumber } = useMenuSetting();
19 17
20 const getCollapsedWidth = computed(() => { 18 const getCollapsedWidth = computed(() => {
21 return unref(brokenRef) ? 0 : unref(getMiniWidthNumber); 19 return unref(brokenRef) ? 0 : unref(getMiniWidthNumber);
22 }); 20 });
23 21
24 - function onCollapseChange(val: boolean) {  
25 - if (initRef.value) {  
26 - collapseRef.value = val;  
27 - setMenuSetting({ collapsed: val });  
28 - } else {  
29 - !unref(getCollapsed) && setMenuSetting({ collapsed: val });  
30 - }  
31 - initRef.value = true;  
32 - }  
33 -  
34 function onBreakpointChange(broken: boolean) { 22 function onBreakpointChange(broken: boolean) {
35 brokenRef.value = broken; 23 brokenRef.value = broken;
36 } 24 }
37 25
38 - return { getCollapsedWidth, onCollapseChange, onBreakpointChange }; 26 + return { getCollapsedWidth, onBreakpointChange };
39 } 27 }
40 28
41 /** 29 /**
src/settings/designSetting.ts
@@ -31,8 +31,8 @@ export const HEADER_PRESET_BG_COLOR_LIST: string[] = [ @@ -31,8 +31,8 @@ export const HEADER_PRESET_BG_COLOR_LIST: string[] = [
31 31
32 // sider preset color 32 // sider preset color
33 export const SIDE_BAR_BG_COLOR_LIST: string[] = [ 33 export const SIDE_BAR_BG_COLOR_LIST: string[] = [
34 - '#001529',  
35 '#273352', 34 '#273352',
  35 + '#001529',
36 '#ffffff', 36 '#ffffff',
37 '#191b24', 37 '#191b24',
38 '#191a23', 38 '#191a23',
src/settings/projectSetting.ts
@@ -8,6 +8,7 @@ import { @@ -8,6 +8,7 @@ import {
8 RouterTransitionEnum, 8 RouterTransitionEnum,
9 SettingButtonPositionEnum, 9 SettingButtonPositionEnum,
10 } from '/@/enums/appEnum'; 10 } from '/@/enums/appEnum';
  11 +import { SIDE_BAR_BG_COLOR_LIST, HEADER_PRESET_BG_COLOR_LIST } from './designSetting';
11 import { primaryColor, themeMode } from '../../build/config/themeConfig'; 12 import { primaryColor, themeMode } from '../../build/config/themeConfig';
12 13
13 // ! You need to clear the browser cache after the change 14 // ! You need to clear the browser cache after the change
@@ -51,7 +52,7 @@ const setting: ProjectConfig = { @@ -51,7 +52,7 @@ const setting: ProjectConfig = {
51 // Header configuration 52 // Header configuration
52 headerSetting: { 53 headerSetting: {
53 // header bg color 54 // header bg color
54 - bgColor: '#ffffff', 55 + bgColor: HEADER_PRESET_BG_COLOR_LIST[0],
55 // Fixed at the top 56 // Fixed at the top
56 fixed: true, 57 fixed: true,
57 // Whether to show top 58 // Whether to show top
@@ -74,7 +75,7 @@ const setting: ProjectConfig = { @@ -74,7 +75,7 @@ const setting: ProjectConfig = {
74 // Menu configuration 75 // Menu configuration
75 menuSetting: { 76 menuSetting: {
76 // sidebar menu bg color 77 // sidebar menu bg color
77 - bgColor: '#001529', 78 + bgColor: SIDE_BAR_BG_COLOR_LIST[0],
78 // Whether to fix the left menu 79 // Whether to fix the left menu
79 fixed: true, 80 fixed: true,
80 // Menu collapse 81 // Menu collapse
src/store/modules/app.ts
1 import type { ProjectConfig } from '/#/config'; 1 import type { ProjectConfig } from '/#/config';
  2 +import type { BeforeMiniState } from '../types';
2 3
3 import { VuexModule, getModule, Module, Mutation, Action } from 'vuex-module-decorators'; 4 import { VuexModule, getModule, Module, Mutation, Action } from 'vuex-module-decorators';
4 import store from '/@/store'; 5 import store from '/@/store';
@@ -30,10 +31,17 @@ export default class App extends VuexModule { @@ -30,10 +31,17 @@ export default class App extends VuexModule {
30 // set main overflow hidden 31 // set main overflow hidden
31 private lockMainScrollState = false; 32 private lockMainScrollState = false;
32 33
  34 + // When the window shrinks, remember some states, and restore these states when the window is restored
  35 + private beforeMiniState: BeforeMiniState = {};
  36 +
33 get getPageLoading() { 37 get getPageLoading() {
34 return this.pageLoadingState; 38 return this.pageLoadingState;
35 } 39 }
36 40
  41 + get getBeforeMiniState() {
  42 + return this.beforeMiniState;
  43 + }
  44 +
37 get getLockMainScrollState() { 45 get getLockMainScrollState() {
38 return this.lockMainScrollState; 46 return this.lockMainScrollState;
39 } 47 }
@@ -48,6 +56,11 @@ export default class App extends VuexModule { @@ -48,6 +56,11 @@ export default class App extends VuexModule {
48 } 56 }
49 57
50 @Mutation 58 @Mutation
  59 + commitBeforeMiniState(state: BeforeMiniState): void {
  60 + this.beforeMiniState = state;
  61 + }
  62 +
  63 + @Mutation
51 commitLockMainScrollState(lock: boolean): void { 64 commitLockMainScrollState(lock: boolean): void {
52 this.lockMainScrollState = lock; 65 this.lockMainScrollState = lock;
53 } 66 }
src/store/types.ts
  1 +import { MenuModeEnum, MenuTypeEnum } from '../enums/menuEnum';
  2 +
1 export interface LockInfo { 3 export interface LockInfo {
2 pwd: string | undefined; 4 pwd: string | undefined;
3 isLock: boolean; 5 isLock: boolean;
@@ -13,3 +15,10 @@ export interface UserInfo { @@ -13,3 +15,10 @@ export interface UserInfo {
13 // 介绍 15 // 介绍
14 desc?: string; 16 desc?: string;
15 } 17 }
  18 +
  19 +export interface BeforeMiniState {
  20 + menuCollapsed?: boolean;
  21 + menuSplit?: boolean;
  22 + menuMode?: MenuModeEnum;
  23 + menuType?: MenuTypeEnum;
  24 +}
yarn.lock
@@ -2379,10 +2379,10 @@ @@ -2379,10 +2379,10 @@
2379 dependencies: 2379 dependencies:
2380 vue-demi latest 2380 vue-demi latest
2381 2381
2382 -"@windicss/plugin-utils@0.8.3":  
2383 - version "0.8.3"  
2384 - resolved "https://registry.npmjs.org/@windicss/plugin-utils/-/plugin-utils-0.8.3.tgz#b694121cb1b4e022c1ebb97d2507d292ca1ce293"  
2385 - integrity sha512-Tk0/EOwRnfi3KzvYJwfDyrImbHRXd7jMUw0MsAJWee0pzHre5Se7IM8/8SrcafJ29aL3v9KcB/qd/uBD8TBmow== 2382 +"@windicss/plugin-utils@0.8.4":
  2383 + version "0.8.4"
  2384 + resolved "https://registry.npmjs.org/@windicss/plugin-utils/-/plugin-utils-0.8.4.tgz#6613bad52cea86a260a040c37069234baac377ae"
  2385 + integrity sha512-i79nEGkC+1Cj+Trtn5SL/bBn1IYqj/N3T6xYHaRnTKJY3mGdsn7ypxvGditBVkGUw0dTZUiHX0nONHLGqQVW7g==
2386 dependencies: 2386 dependencies:
2387 fast-glob "^3.2.5" 2387 fast-glob "^3.2.5"
2388 micromatch "^4.0.2" 2388 micromatch "^4.0.2"
@@ -11626,12 +11626,12 @@ vite-plugin-theme@^0.5.0: @@ -11626,12 +11626,12 @@ vite-plugin-theme@^0.5.0:
11626 tinycolor2 "^1.4.2" 11626 tinycolor2 "^1.4.2"
11627 ts-jest "^26.5.3" 11627 ts-jest "^26.5.3"
11628 11628
11629 -vite-plugin-windicss@0.8.3:  
11630 - version "0.8.3"  
11631 - resolved "https://registry.npmjs.org/vite-plugin-windicss/-/vite-plugin-windicss-0.8.3.tgz#81944473f642a4d4da81f9f8d77012e73095e4a3"  
11632 - integrity sha512-VhiYUBIexKD1Il1dxV6yB4SN+ufza3HWhKK7IFFGrf4gj2JqSX9MNUdS2jPOEInyJszw+fT7WrHj1hsYd7ROJA== 11629 +vite-plugin-windicss@0.8.4:
  11630 + version "0.8.4"
  11631 + resolved "https://registry.npmjs.org/vite-plugin-windicss/-/vite-plugin-windicss-0.8.4.tgz#d064822f2b9e6e2a5385c3fc0fdcf302e2ee545d"
  11632 + integrity sha512-pgAZ7NDnDKYwNUJTy/j0jerh0JRqehu/dEDjM+AKChPD65o6G0WzbpVuHLSkiBcqUzDNHdRU0CodlL4DoCYE3w==
11633 dependencies: 11633 dependencies:
11634 - "@windicss/plugin-utils" "0.8.3" 11634 + "@windicss/plugin-utils" "0.8.4"
11635 windicss "^2.4.5" 11635 windicss "^2.4.5"
11636 11636
11637 vite@2.1.1: 11637 vite@2.1.1: