Skip to content

Commit ebd9a48

Browse files
committed
配置状态机
1 parent 23a6535 commit ebd9a48

File tree

9 files changed

+109
-21
lines changed

9 files changed

+109
-21
lines changed

src/components/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Menus from './menus';
2+
3+
const components = {
4+
Menus,
5+
};
6+
7+
const install = (Vue) => {
8+
Object.keys(components).forEach((component) =>
9+
Vue.component(component, components[component]),
10+
);
11+
};
12+
13+
const API = {
14+
install,
15+
...components,
16+
};
17+
18+
// auto install
19+
if (typeof window !== 'undefined' && window.Vue) {
20+
install(window.Vue);
21+
}
22+
23+
export default API;

src/layout/Layout.vue

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,16 @@
2222
2323
import AppHeader from './header/Index.vue';
2424
import Sidebar from './sidebar/Index.vue';
25-
25+
import { mapActions } from 'vuex';
2626
export default {
2727
components: {
2828
AppHeader,
2929
Sidebar,
30+
},
31+
methods: {
32+
...mapActions(['sidebarOpened'])
3033
}
3134
}
32-
// @Component({
33-
// components: {
34-
// AppHeader,
35-
// Breadcrumb,
36-
// Sidebar,
37-
// },
38-
// })
39-
// export default class Layout extends Vue {
40-
// @Getter('viewStore/sidebarOpened') private sidebarOpened!: IViewState;
41-
// }
4235
</script>
4336

4437
<style lang="scss">

src/layout/header/Index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<!-- 头部切换左侧菜单 -->
77
<div
88
class="menus"
9-
@click="toogleSidebar"
9+
@click="toggleSidebar"
1010
>
1111
<i class="fas fa-bars"></i>
1212
</div>
@@ -50,7 +50,7 @@ export default {
5050
storage.removeItem(currentUser);
5151
this.$router.push({ name: 'login' });
5252
},
53-
...mapActions(['toogleSidebar'])
53+
...mapActions(['toggleSidebar'])
5454
},
5555
mounted () {
5656
this.username = storage.getItem(currentUser);

src/layout/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Layout from './Layout.vue';
2+
export default Layout;

src/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import 'element-ui/lib/theme-chalk/index.css';
1818
Vue.use(ElementUI);
1919
/******************************** 引入elementUi组件库 end ********************************/
2020

21+
// 配置自定义组件
22+
// 使用自己定义的组件
23+
import components from '@/components';
24+
Vue.use(components);
25+
2126
Vue.config.productionTip = false;
2227

2328
new Vue({

src/store/index.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import Vue from 'vue';
22
import Vuex from 'vuex';
3+
const path = require('path');
34

5+
import { viewStore } from './view';
46
Vue.use(Vuex);
57

8+
/********************************自动导包 start********************************/
9+
const file = require.context('./modules', true, /\.ts/);
10+
const modules = {};
11+
file.keys().forEach((key) => {
12+
const name = path.basename(key, '.js');
13+
modules[name] = file(key).default || file(key);
14+
});
15+
/********************************自动导包 end********************************/
16+
17+
const debug = process.env.NODE_ENV !== 'production';
18+
619
export default new Vuex.Store({
7-
state: {
8-
},
9-
mutations: {
10-
},
11-
actions: {
12-
},
20+
strict: debug,
1321
modules: {
14-
}
15-
})
22+
viewStore,
23+
...modules,
24+
},
25+
});

src/store/mutation-types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const OPEN_SIDEBAR = 'OPEN_SIDEBAR'; // 打开侧边栏
2+
export const CLOSE_SIDEBAR = 'CLOSE_SIDEBAR'; // 关闭侧边栏
3+
export const SET_TITLE = 'SET_TITLE';
4+
export const SET_SIDE_MENU = 'SET_SIDE_MENU'; // 设置左侧菜单

src/store/view.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as types from './mutation-types';
2+
const state = {
3+
sidebarOpened: true,
4+
title: '主页',
5+
menuList: [],
6+
};
7+
8+
const getters = {
9+
// tslint:disable-next-line:no-shadowed-variable
10+
sidebarOpened: (state) => state.sidebarOpened,
11+
};
12+
13+
const mutations = {
14+
[types.OPEN_SIDEBAR] (s) {
15+
s.sidebarOpened = true;
16+
},
17+
[types.CLOSE_SIDEBAR] (s) {
18+
s.sidebarOpened = false;
19+
},
20+
[types.SET_TITLE] (s, title) {
21+
s.title = title;
22+
},
23+
[types.SET_SIDE_MENU]: (s, payload) => {
24+
s.menuList = payload;
25+
},
26+
};
27+
28+
const actions = {
29+
toggleSidebar ({ state, commit }) {
30+
state.sidebarOpened
31+
? commit(types.CLOSE_SIDEBAR)
32+
: commit(types.OPEN_SIDEBAR);
33+
},
34+
35+
setTitle ({ commit }, params) {
36+
commit(types.SET_TITLE, params);
37+
},
38+
};
39+
40+
export const viewStore = {
41+
namespaced: true,
42+
state,
43+
getters,
44+
mutations,
45+
actions,
46+
};

src/views/shared/app/Index.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
</div>
55
</template>
66

7+
<script>
8+
export default {
9+
10+
}
11+
</script>
712
<style lang="scss">
813
</style>

0 commit comments

Comments
 (0)