Skip to content

Commit de7c4ca

Browse files
authored
Merge pull request #36 from sendya/dev
feat: sp tablet
2 parents 88d83e5 + abbfb42 commit de7c4ca

File tree

8 files changed

+93
-71
lines changed

8 files changed

+93
-71
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ yarn run lint
8989
其他说明
9090
----
9191

92-
- **关于 Issue 反馈 (重要!重要!重要!) 请在开 *Issue* 时,描述清楚您的使用环境,所使用 Pro 版本或分支,出现的情况等...** 另外,若有疑问也可加入 QQ群 (Ant Design Vue 原作者使用讨论群 217490093),本项目的几位维护者也在该群
92+
- **关于 Issue 反馈 (重要!重要!重要!) 请在开 *Issue* 时,描述清楚您的使用环境,所使用 Pro 版本或分支,出现的情况等...** 另外,若有疑问也可加入 QQ群 (Ant Design Vue 原作者使用讨论群 217490093**非 Pro 群**),本项目的几位维护者也在该群
9393

9494
- 项目使用的 [vue-cli3](https://cli.vuejs.org/guide/), 请更新您的 cli
9595

src/App.vue

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
</div>
66
</a-locale-provider>
77
</template>
8+
89
<script>
910
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
10-
import enquireScreen from '@/utils/device'
11+
import { deviceEnquire, DEVICE_TYPE } from '@/utils/device'
1112
import { version } from 'ant-design-vue'
1213
1314
export default {
@@ -17,25 +18,28 @@
1718
version
1819
}
1920
},
20-
created () {
21-
const that = this
21+
mounted () {
22+
const { $store } = this
2223
console.log('use Ant-Design Of Vue:', version)
23-
enquireScreen(deviceType => {
24-
// tablet
25-
if (deviceType === 0) {
26-
that.$store.commit('TOGGLE_DEVICE', 'mobile')
27-
that.$store.dispatch('setSidebar', false)
28-
}
29-
// mobile
30-
else if (deviceType === 1) {
31-
that.$store.commit('TOGGLE_DEVICE', 'mobile')
32-
that.$store.dispatch('setSidebar', false)
33-
}
34-
else {
35-
that.$store.commit('TOGGLE_DEVICE', 'desktop')
36-
that.$store.dispatch('setSidebar', true)
37-
}
24+
deviceEnquire(deviceType => {
3825
26+
switch (deviceType) {
27+
case DEVICE_TYPE.DESKTOP:
28+
$store.commit('TOGGLE_DEVICE', 'desktop')
29+
$store.dispatch('setSidebar', true)
30+
break
31+
case DEVICE_TYPE.TABLET:
32+
console.log('tablet')
33+
$store.dispatch('ToggleDevice', 'tablet')
34+
$store.dispatch('setSidebar', false)
35+
break
36+
case DEVICE_TYPE.MOBILE:
37+
default:
38+
$store.commit('TOGGLE_DEVICE', 'mobile')
39+
$store.dispatch('setSidebar', false)
40+
break
41+
}
42+
console.log('deviceType', deviceType)
3943
})
4044
}
4145
}

src/components/page/GlobalLayout.vue

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<template>
22
<a-layout class="layout" :class="[device]">
33

4-
<template v-if="layoutMode === 'sidemenu'">
4+
<template v-if="isSideMenu()">
55
<a-drawer
6-
v-if="device === 'mobile'"
6+
v-if="isMobile()"
77
:wrapClassName="'drawer-sider ' + navTheme"
8-
placement="left"
9-
@close="() => this.collapsed = false"
108
:closable="false"
119
:visible="collapsed"
10+
placement="left"
11+
@close="() => this.collapsed = false"
1212
>
1313
<side-menu
14-
mode="inline"
1514
:menus="menus"
16-
@menuSelect="menuSelect"
1715
:theme="navTheme"
1816
:collapsed="false"
19-
:collapsible="true"></side-menu>
17+
:collapsible="true"
18+
mode="inline"
19+
@menuSelect="menuSelect"></side-menu>
2020
</a-drawer>
2121

2222
<side-menu
@@ -30,31 +30,31 @@
3030
<!-- 下次优化这些代码 -->
3131
<template v-else>
3232
<a-drawer
33-
v-if="device === 'mobile'"
33+
v-if="isMobile()"
3434
:wrapClassName="'drawer-sider ' + navTheme"
3535
placement="left"
3636
@close="() => this.collapsed = false"
3737
:closable="false"
3838
:visible="collapsed"
3939
>
4040
<side-menu
41-
mode="inline"
4241
:menus="menus"
43-
@menuSelect="menuSelect"
4442
:theme="navTheme"
4543
:collapsed="false"
46-
:collapsible="true"></side-menu>
44+
:collapsible="true"
45+
mode="inline"
46+
@menuSelect="menuSelect"></side-menu>
4747
</a-drawer>
4848
</template>
4949

5050
<a-layout :class="[layoutMode, `content-width-${contentWidth}`]" :style="{ paddingLeft: fixSiderbar && isDesktop() ? `${sidebarOpened ? 256 : 80}px` : '0' }">
5151
<!-- layout header -->
52-
<global-header
53-
:mode="layoutMode"
54-
:menus="menus"
55-
:theme="navTheme"
56-
:collapsed="collapsed"
57-
:device="device"
52+
<global-header
53+
:mode="layoutMode"
54+
:menus="menus"
55+
:theme="navTheme"
56+
:collapsed="collapsed"
57+
:device="device"
5858
@toggle="toggle"
5959
/>
6060

@@ -104,11 +104,14 @@
104104
},
105105
watch: {
106106
sidebarOpened(val) {
107+
console.log('sidebarOpened', val)
107108
this.collapsed = !val
108109
},
109110
},
110111
created() {
111112
this.menus = this.mainMenu.find((item) => item.path === '/').children
113+
console.log('created/sidebarOpened', this.sidebarOpened)
114+
this.collapsed = !this.sidebarOpened
112115
},
113116
methods: {
114117
...mapActions(['setSidebar']),
@@ -140,7 +143,7 @@
140143
min-height: 100vh;
141144
overflow-x: hidden;
142145
143-
&.mobile {
146+
&.mobile,&.tablet {
144147
145148
.ant-layout-content {
146149
@@ -301,7 +304,7 @@
301304
}
302305
}
303306
304-
&.mobile {
307+
&.mobile,&.tablet {
305308
.top-nav-header-index {
306309
307310
.header-index-wide {

src/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Vue.use(PermissionHelper)
4040
new Vue({
4141
router,
4242
store,
43-
mounted () {
43+
created () {
4444
store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
4545
store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
4646
store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
@@ -52,6 +52,8 @@ new Vue({
5252
store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
5353
store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
5454

55+
console.log('.... created ()')
56+
5557
removeLoadingAnimate('preloadingWrapper')
5658
},
5759
render: h => h(App)

src/store/modules/app.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import {
1313

1414
const app = {
1515
state: {
16-
sidebar: {
17-
opened: true,
18-
withoutAnimation: false
19-
},
16+
sidebar: true,
2017
device: 'desktop',
2118
theme: '',
2219
layout: '',
@@ -29,13 +26,14 @@ const app = {
2926
},
3027
mutations: {
3128
SET_SIDEBAR_TYPE: (state, type) => {
32-
state.sidebar.opened = type
29+
state.sidebar = type
3330
Vue.ls.set(SIDEBAR_TYPE, type)
31+
32+
console.log('SET_SIDEBAR_TYPE', type)
3433
},
35-
CLOSE_SIDEBAR: (state, withoutAnimation) => {
34+
CLOSE_SIDEBAR: (state) => {
3635
Vue.ls.set(SIDEBAR_TYPE, true)
37-
state.sidebar.opened = false
38-
state.sidebar.withoutAnimation = withoutAnimation
36+
state.sidebar = false
3937
},
4038
TOGGLE_DEVICE: (state, device) => {
4139
state.device = device
@@ -75,11 +73,11 @@ const app = {
7573
}
7674
},
7775
actions: {
78-
setSidebar: ({ commit }, type) => {
76+
setSidebar({ commit }, type) {
7977
commit('SET_SIDEBAR_TYPE', type)
8078
},
81-
CloseSidebar({ commit }, { withoutAnimation }) {
82-
commit('CLOSE_SIDEBAR', withoutAnimation)
79+
CloseSidebar({ commit }) {
80+
commit('CLOSE_SIDEBAR')
8381
},
8482
ToggleDevice({ commit }, device) {
8583
commit('TOGGLE_DEVICE', device)

src/utils/device.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
import enquireJs from 'enquire.js'
22

3-
const enquireScreen = function (call) {
4-
// tablet
5-
const handler = {
6-
match: function () {
7-
call && call(0)
8-
},
9-
unmatch: function () {
10-
call && call(-1)
3+
export const DEVICE_TYPE = {
4+
DESKTOP: 'desktop',
5+
TABLET: 'tablet',
6+
MOBILE: 'mobile',
7+
}
8+
9+
export const deviceEnquire = function (callback) {
10+
11+
const matchDesktop = {
12+
match: () => {
13+
callback && callback(DEVICE_TYPE.DESKTOP)
14+
}
15+
}
16+
17+
const matchLablet = {
18+
match: () => {
19+
callback && callback(DEVICE_TYPE.TABLET)
1120
}
1221
}
13-
// mobile
14-
const handler2 = {
22+
23+
const matchMobile = {
1524
match: () => {
16-
call && call(1)
25+
callback && callback(DEVICE_TYPE.MOBILE)
1726
}
1827
}
19-
enquireJs.register('screen and (max-width: 1087.99px)', handler)
20-
enquireJs.register('screen and (max-width: 767.99px)', handler2)
21-
}
2228

23-
export default enquireScreen
29+
// screen and (max-width: 1087.99px)
30+
enquireJs
31+
.register('screen and (max-width: 576px)', matchMobile)
32+
.register('screen and (min-width: 576px) and (max-width: 1199px)', matchLablet)
33+
.register('screen and (min-width: 1200px)', matchDesktop)
34+
}

src/utils/helper/permission.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const PERMISSION_ENUM = {
77
'enable': { key: 'enable', label: '启用' },
88
'disable': { key: 'disable', label: '禁用' },
99
'import': { key: 'import', label: '导入' },
10-
'export': { key: 'import', label: '导入' },
10+
'export': { key: 'export', label: '导出' },
1111
}
1212

1313
function plugin(Vue) {

src/utils/mixin.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// import Vue from 'vue'
2+
import { DEVICE_TYPE } from '@/utils/device'
23
import { mapState } from 'vuex'
34

45
// const mixinsComputed = Vue.config.optionMergeStrategies.computed
@@ -15,15 +16,15 @@ const mixin = {
1516
fixSiderbar: state => state.app.fixSiderbar,
1617
contentWidth: state => state.app.contentWidth,
1718
autoHideHeader: state => state.app.autoHideHeader,
18-
sidebarOpened: state => state.app.sidebar.opened
19+
sidebarOpened: state => state.app.sidebar
1920
})
2021
},
2122
methods: {
22-
isTopmenu () {
23+
isTopMenu () {
2324
return this.layoutMode === 'topmenu'
2425
},
2526
isSideMenu () {
26-
return !this.isTopmenu()
27+
return !this.isTopMenu()
2728
}
2829
}
2930
}
@@ -36,10 +37,13 @@ const mixinDevice = {
3637
},
3738
methods: {
3839
isMobile () {
39-
return this.device === 'mobile'
40+
return this.device === DEVICE_TYPE.MOBILE
4041
},
4142
isDesktop () {
42-
return this.device === 'desktop'
43+
return this.device === DEVICE_TYPE.DESKTOP
44+
},
45+
isTablet () {
46+
return this.device === DEVICE_TYPE.TABLET
4347
}
4448
}
4549
}

0 commit comments

Comments
 (0)