@v2coding/ui 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v2coding/ui",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "",
5
5
 
6
6
  "main": "dist/v2coding-ui.ssr.js",
@@ -1,188 +0,0 @@
1
- <template>
2
- <el-menu
3
- class="head-menu"
4
- v-bind="$attrs"
5
- v-on="$listeners"
6
- :mode="mode"
7
- :router="router"
8
- :default-active="active"
9
- >
10
- <menu-item v-for="item in displayMenus" :item="item" :key="item.id"/>
11
- </el-menu>
12
- </template>
13
-
14
- <script>
15
- import {mapState} from 'vuex';
16
- import MenuItem from './menu-item';
17
-
18
- export default {
19
- name: 'ui-head-menu',
20
- components: {MenuItem},
21
- provide() {
22
- return {
23
- headMenu: this,
24
- };
25
- },
26
- props: {
27
- router: {
28
- type: Boolean,
29
- default: true,
30
- },
31
- defaultActive: String,
32
- mode: {
33
- default: 'horizontal',
34
- },
35
- },
36
- data() {
37
- return {
38
- packUpWidth: 0,
39
- };
40
- },
41
- computed: {
42
- ...mapState(['menus']),
43
- headMenu() {
44
- // eslint-disable-next-line
45
- return this.menus.filter(menu => [1, 2].includes(menu.type)).map(({children, ...menu}) => menu);
46
- },
47
- active() {
48
- if (!this.router) {
49
- return this.defaultActive;
50
- }
51
- const currentPath = this.$route.path;
52
- const isHeadRoute = this.headMenu.some(menu => menu.url === currentPath);
53
- if (isHeadRoute) {
54
- return currentPath;
55
- }
56
- const currentHeadMenu = this.getCurrentHeadMenu(currentPath, this.menus);
57
- return currentHeadMenu && (currentHeadMenu.path || currentHeadMenu.url);
58
- },
59
- menuWidth() {
60
- return this.headMenu.reduce((total, item) => {
61
- return total + (item.name || '').split('').length * 16 + 25 * 2; // 16:字体大小值; 25:左右padding/margin值
62
- }, 60); // 100:菜单左边的margin值
63
- },
64
- packUpIndex() {
65
- if (this.packUpWidth <= 0) {
66
- return -1;
67
- }
68
- let index = -1;
69
- let width = this.packUpWidth + 130; // 50:更多下拉菜单所占宽度
70
- for(let i = this.headMenu.length - 1; i >= 0; i--) {
71
- const item = this.headMenu[i];
72
- const currentWidth = (item.name || '').split('').length * 16 + 25 * 2;
73
- if (currentWidth >= width) {
74
- index = i - 1;
75
- break;
76
- }
77
- width = width - currentWidth;
78
- }
79
- return Math.max(0, index);
80
- },
81
- displayMenus() {
82
- if (this.packUpIndex === -1) {
83
- return this.headMenu;
84
- }
85
- const menus = this.headMenu.slice(0, this.packUpIndex);
86
- const moreMenus = this.headMenu.slice(this.packUpIndex);
87
- menus.push({
88
- id: 'more',
89
- name: '更多菜单',
90
- children: moreMenus,
91
- });
92
- return menus;
93
- },
94
- },
95
- mounted() {
96
- window.addEventListener('resize', this.onResize);
97
- this.onResize();
98
-
99
- const logo = document.querySelector('.page-header > .logo');
100
- logo && logo.addEventListener('load', () => this.onResize());
101
- },
102
- beforeDestroy() {
103
- window.removeEventListener('resize', this.onResize);
104
- },
105
- methods: {
106
- onResize() {
107
- clearTimeout(this.timer);
108
- this.timer = setTimeout(() => {
109
- const headerWidth = document.documentElement.clientWidth;
110
- const logoEl = document.querySelector('.page-header > .logo');
111
- const titleEl = document.querySelector('.page-header > .title');
112
- const messageEl = document.querySelector('.page-header > .screen');
113
- const usernameEl = document.querySelector('.page-header > .username');
114
- const logoWidth = (logoEl && logoEl.offsetWidth || 0) + 20; // 20 margin
115
- const titleWidth = titleEl && titleEl.offsetWidth || 0;
116
- const messageElWidth = messageEl && messageEl.offsetWidth || 0;
117
- const usernameWidth = usernameEl && usernameEl.offsetWidth || 0;
118
- const allowedMenuWidth = headerWidth - 60 - logoWidth - titleWidth - messageElWidth - usernameWidth;
119
- this.packUpWidth = Math.max(0, this.menuWidth - allowedMenuWidth);
120
- }, 50);
121
- },
122
- getCurrentHeadMenu(path, menus) {
123
- if (!Array.isArray(menus) || menus.length <= 0) {
124
- return undefined;
125
- }
126
- return menus.find(menu => {
127
- const isMatched = (menu.children || []).some(childMenu => (childMenu.path || childMenu.url) === path);
128
- if (isMatched) {
129
- return true;
130
- }
131
- return this.getCurrentHeadMenu(path, menu.children);
132
- });
133
- },
134
- },
135
- };
136
- </script>
137
-
138
- <style lang="scss">
139
-
140
- .head-menu.el-menu {
141
- background-color: transparent;
142
- border-bottom: none;
143
-
144
- > .el-menu-item,
145
- > .el-submenu .el-submenu__title {
146
- font-size: 16px;
147
- font-weight: 400;
148
- color: inherit;
149
- height: var(--header-height);
150
- line-height: var(--header-height);
151
- padding: 0 25px;
152
- border: none;
153
- box-sizing: border-box;
154
- transition: all 0.2s ease-in-out;
155
-
156
- span {
157
- vertical-align: unset;
158
- }
159
-
160
- i {
161
- width: 20px;
162
- font-size: 14px;
163
- }
164
- }
165
-
166
- > .el-menu-item:not(.is-disabled):not(.is-active):hover,
167
- > .el-menu-item:not(.is-disabled):not(.is-active):focus,
168
- > .el-submenu:not(.is-disabled):not(.is-active):hover .el-submenu__title,
169
- > .el-submenu:not(.is-disabled):not(.is-active):focus .el-submenu__title {
170
- color: inherit;
171
- background-color: rgba(0, 146, 63, 0.3);
172
- }
173
-
174
- > .el-menu-item.is-active,
175
- > .el-submenu.is-active .el-submenu__title {
176
- color: inherit;
177
- background-color: rgba(0, 146, 63, 0.6);
178
- }
179
-
180
- .el-submenu__title i {
181
- color: inherit;
182
- }
183
-
184
- .el-menu--popup {
185
-
186
- }
187
- }
188
- </style>
@@ -1,80 +0,0 @@
1
- <script type="text/jsx">
2
- export default {
3
- name: 'head-menu-submenu',
4
- inject: ['headMenu'],
5
- props: {
6
- item: Object,
7
- },
8
- computed: {
9
- isLeaf() {
10
- const {children} = this.item;
11
- return !Array.isArray(children) || children.length <= 0;
12
- },
13
- index() {
14
- const {url, id} = this.item;
15
- if (this.isRouter) {
16
- return url || id + '';
17
- }
18
- return id + '';
19
- },
20
- route() {
21
- const {url} = this.item;
22
- return url;
23
- },
24
- isRouter() {
25
- return this.headMenu.router;
26
- },
27
- theme() {
28
- return this.headMenu.theme;
29
- },
30
- popperClass() {
31
- return ['nav-menu-submenu-popup', this.theme].join(' ');
32
- },
33
- },
34
- render(createElement) {
35
- if (this.isLeaf) {
36
- return createElement('el-menu-item', {props: {index: this.index, route: this.route}}, [
37
- createElement('template', {slot: 'title'}, [this.item.name]),
38
- ]);
39
- }
40
- return createElement('el-submenu', {props: {index: this.index, popperClass: this.popperClass, popperAppendToBody: false}}, [
41
- createElement('template', {slot: 'title'}, [this.item.name]),
42
- ...this.item.children.map(child => createElement('head-menu-submenu', {key: child.id, props: {item: child}})),
43
- ]);
44
- },
45
- };
46
- </script>
47
- <style lang="less">
48
- .el-menu--collapse .el-menu-item [class^=el-icon-],
49
- .el-menu--collapse .el-submenu .el-submenu__title [class^=el-icon-] {
50
- margin: 0;
51
- vertical-align: middle;
52
- width: 24px;
53
- text-align: center
54
- }
55
-
56
- .el-menu--collapse .el-menu-item .el-submenu__icon-arrow,
57
- .el-menu--collapse .el-submenu .el-submenu__title .el-submenu__icon-arrow {
58
- display: none
59
- }
60
-
61
- .el-menu--collapse .el-menu-item span,
62
- .el-menu--collapse .el-submenu .el-submenu__title span {
63
- height: 0;
64
- width: 0;
65
- overflow: hidden;
66
- visibility: hidden;
67
- display: inline-block
68
- }
69
-
70
- .nav-menu-submenu-popup {
71
-
72
- .el-menu-item,
73
- .el-submenu__title {
74
- height: 40px;
75
- line-height: 40px;
76
- font-size: 12px;
77
- }
78
- }
79
-
80
- </style>