qdt-admin-layout 1.1.2 → 1.1.5

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": "qdt-admin-layout",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "description": "基于element-ui的后台管理layout的管家婆改版",
5
5
  "main": "src/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  export default {
26
- name: 'ContextMenu',
26
+ name: "ContextMenu",
27
27
 
28
28
  props: {
29
29
  // 是否显示,支持v-modal
@@ -35,85 +35,88 @@ export default {
35
35
  // 菜单距离屏幕顶部的距离,单位px
36
36
  top: Number,
37
37
  // 菜单距离屏幕边缘的最小距离,单位px
38
- minDistance: { type: Number, default: 10 }
38
+ minDistance: { type: Number, default: 10 },
39
39
  },
40
40
 
41
41
  data() {
42
- this.willAutoAdaptLeft = false
43
- this.willAutoAdaptTop = false
42
+ this.willAutoAdaptLeft = false;
43
+ this.willAutoAdaptTop = false;
44
44
  return {
45
- realLeft: '0px',
46
- realTop: '0px'
47
- }
45
+ realLeft: "0px",
46
+ realTop: "0px",
47
+ };
48
48
  },
49
49
 
50
50
  computed: {
51
51
  style() {
52
- return { left: this.realLeft, top: this.realTop }
52
+ return { left: this.realLeft, top: this.realTop };
53
53
  },
54
54
 
55
55
  menuItems() {
56
- return this.items.filter(Boolean)
57
- }
56
+ return this.items.filter(Boolean);
57
+ },
58
58
  },
59
59
 
60
60
  watch: {
61
61
  value: {
62
62
  immediate: true,
63
63
  handler(v) {
64
- document.body[v ? 'addEventListener' : 'removeEventListener']('click', this.close)
64
+ document.body[v ? "addEventListener" : "removeEventListener"](
65
+ "click",
66
+ this.close
67
+ );
65
68
  if (v) {
66
- this.willAutoAdaptLeft = true
67
- this.willAutoAdaptTop = true
68
- this.$nextTick(this.autoAdapt)
69
+ this.willAutoAdaptLeft = true;
70
+ this.willAutoAdaptTop = true;
71
+ this.$nextTick(this.autoAdapt);
69
72
  }
70
- }
73
+ },
71
74
  },
72
75
  left: {
73
76
  immediate: true,
74
- handler: 'autoAdaptLeft'
77
+ handler: "autoAdaptLeft",
75
78
  },
76
79
  top: {
77
80
  immediate: true,
78
- handler: 'autoAdaptTop'
79
- }
81
+ handler: "autoAdaptTop",
82
+ },
80
83
  },
81
84
 
82
85
  methods: {
83
86
  close() {
84
- this.$emit('input', false)
87
+ this.$emit("input", false);
85
88
  },
86
89
  autoAdapt() {
87
- this.autoAdaptTop(this.top)
88
- this.autoAdaptLeft(this.left)
90
+ this.autoAdaptTop(this.top);
91
+ this.autoAdaptLeft(this.left);
89
92
  },
90
93
  autoAdaptTop(v) {
91
94
  if (this.willAutoAdaptTop) {
92
- this.willAutoAdaptTop = false
93
- return
95
+ this.willAutoAdaptTop = false;
96
+ return;
94
97
  }
95
- if (!this.value || v == null) return
98
+ if (!this.value || v == null) return;
96
99
 
97
- const elHeight = this.$el.offsetHeight
98
- const remainHeight = document.body.clientHeight - v - this.minDistance
99
- const over = elHeight - remainHeight
100
- const finalTop = over > 0 ? v - over : v
100
+ const elHeight = this.$el.offsetHeight;
101
+ const remainHeight = document.body.clientHeight - v - this.minDistance;
102
+ const over = elHeight - remainHeight;
103
+ const finalTop = over > 0 ? v - over : v;
101
104
 
102
- this.realTop = `${finalTop}px`
105
+ this.realTop = `${finalTop}px`;
103
106
  },
104
107
  autoAdaptLeft(v) {
105
108
  if (this.willAutoAdaptLeft) {
106
- this.willAutoAdaptLeft = false
107
- return
109
+ this.willAutoAdaptLeft = false;
110
+ return;
108
111
  }
109
- if (!this.value || v == null) return
112
+ if (!this.value || v == null) return;
110
113
 
111
- const elWidth = this.$el.offsetWidth
112
- const remainWidth = document.body.clientWidth - v - this.minDistance
113
- const over = elWidth - remainWidth
114
- const finalLeft = over > 0 ? v - over : v
114
+ const elWidth = this.$el.offsetWidth;
115
+ const remainWidth = document.body.clientWidth - v - this.minDistance;
116
+ const over = elWidth - remainWidth;
117
+ const finalLeft = over > 0 ? v - over : v;
115
118
 
116
- this.realLeft = `${finalLeft}px`
119
+ this.realLeft = `${finalLeft}px`;
117
120
  },
118
121
 
119
122
  /**
@@ -122,19 +125,19 @@ export default {
122
125
  * @param event {Event}
123
126
  */
124
127
  onClick(event) {
125
- if (!event.target.classList.contains('context-menu-item')) {
126
- return
128
+ if (!event.target.classList.contains("context-menu-item")) {
129
+ return;
127
130
  }
128
131
 
129
- const index = Number(event.target.dataset.index)
130
- const menuItem = this.menuItems[index]
132
+ const index = Number(event.target.dataset.index);
133
+ const menuItem = this.menuItems[index];
131
134
 
132
- menuItem && menuItem.click()
133
- }
135
+ menuItem && menuItem.click();
136
+ },
134
137
  },
135
138
 
136
139
  beforeDestroy() {
137
- document.body.removeEventListener('click', this.close)
138
- }
139
- }
140
+ document.body.removeEventListener("click", this.close);
141
+ },
142
+ };
140
143
  </script>
@@ -6,9 +6,9 @@
6
6
  border-radius: 4px;
7
7
  font-size: 12px;
8
8
  max-height: 50vh;
9
- color: $--color-white;
10
- background-color: $menu-background-dark;
11
- box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, .3);
9
+ color: rgb(96, 98, 102);
10
+ background-color: rgb(255, 255, 255);
11
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.4);
12
12
  overflow-y: auto;
13
13
  overflow-x: hidden;
14
14
 
@@ -8,21 +8,29 @@ import {
8
8
  pageGetters,
9
9
  pageMutations,
10
10
  tagsViewGetters,
11
- tagsViewMutations
12
- } from '../../store'
13
- import useContextMenu from '../../component/ContextMenu/functionalUse'
14
- import HorizontalScroller from '../../component/HorizontalScroller'
15
- import { refreshPage } from '../../helper'
16
- import { getRouterKey, getRouterTitle, isRedirectRouter } from '../../config/logic'
17
- import { isAffix, getAffixTagsFromMenuTree, renderDefaultStyleTag } from './util'
11
+ tagsViewMutations,
12
+ } from "../../store";
13
+ import useContextMenu from "../../component/ContextMenu/functionalUse";
14
+ import HorizontalScroller from "../../component/HorizontalScroller";
15
+ import { refreshPage } from "../../helper";
16
+ import {
17
+ getRouterKey,
18
+ getRouterTitle,
19
+ isRedirectRouter,
20
+ } from "../../config/logic";
21
+ import {
22
+ isAffix,
23
+ getAffixTagsFromMenuTree,
24
+ renderDefaultStyleTag,
25
+ } from "./util";
18
26
 
19
27
  export default {
20
- name: 'TagsView',
28
+ name: "TagsView",
21
29
 
22
30
  data() {
23
31
  return {
24
32
  // 当前激活的页签的key,随路由变化
25
- activeKey: '',
33
+ activeKey: "",
26
34
 
27
35
  // 当前选中的页签
28
36
  selectedTag: undefined,
@@ -31,46 +39,47 @@ export default {
31
39
  contextMenu: {
32
40
  show: false,
33
41
  top: 0,
34
- left: 0
35
- }
36
- }
42
+ left: 0,
43
+ },
44
+ };
37
45
  },
38
46
 
39
47
  computed: {
40
48
  contextMenuItems() {
41
- const { visitedViews } = tagsViewGetters
42
- const closeable = visitedViews.length > 1 && !isAffix(this.selectedTag)
49
+ const { visitedViews } = tagsViewGetters;
50
+ const closeable = visitedViews.length > 1 && !isAffix(this.selectedTag);
43
51
 
44
52
  return [
45
- { content: '刷新', click: this.refreshSelectedTag },
46
- { content: closeable && '关闭', click: this.closeSelectedTag },
47
- { content: '关闭其他', click: this.closeOthersTags },
48
- { content: '关闭全部', click: this.closeAllTags }
49
- ].filter(i => i.content)
53
+ { content: "刷新", click: this.refreshSelectedTag },
54
+ { content: closeable && "关闭", click: this.closeSelectedTag },
55
+ { content: "关闭其他", click: this.closeOthersTags },
56
+ { content: "关闭全部", click: this.closeAllTags },
57
+ ].filter((i) => i.content);
50
58
  },
51
59
 
52
- // 避免HorizontalScroller在右键时触发$forceUpdate
53
- // https://segmentfault.com/q/1010000040171066
54
60
  tagsSlot() {
55
- return this._u([{
56
- key: 'default',
57
- fn: this.renderTags,
58
- proxy: true
59
- }])
60
- }
61
+ return this._u([
62
+ {
63
+ key: "default",
64
+ fn: this.renderTags,
65
+ proxy: true,
66
+ },
67
+ ]);
68
+ },
61
69
  },
62
70
 
63
71
  watch: {
64
72
  $route(to, from) {
65
- tagsViewGetters.enableChangeTransition && this.decideRouteTransition(to, from)
73
+ tagsViewGetters.enableChangeTransition &&
74
+ this.decideRouteTransition(to, from);
66
75
 
67
76
  // 如果是刷新的话,不需要进行后续操作
68
- if (isRedirectRouter(to)) return
77
+ if (isRedirectRouter(to)) return;
69
78
 
70
- this.setActiveKey(to)
71
- this.addTag(to)
72
- this.$nextTick(this.moveToCurrentTag)
73
- }
79
+ this.setActiveKey(to);
80
+ this.addTag(to);
81
+ this.$nextTick(this.moveToCurrentTag);
82
+ },
74
83
  },
75
84
 
76
85
  methods: {
@@ -79,7 +88,7 @@ export default {
79
88
  * @param route {import('vue-router').Route}
80
89
  */
81
90
  setActiveKey(route) {
82
- this.activeKey = getRouterKey(route)
91
+ this.activeKey = getRouterKey(route);
83
92
  },
84
93
 
85
94
  /**
@@ -88,33 +97,35 @@ export default {
88
97
  * @param from {import('vue-router').Route}
89
98
  */
90
99
  decideRouteTransition(to, from) {
91
- const { next, prev } = pageGetters.transition
92
- const { visitedViews } = tagsViewGetters
93
- const fromKey = getRouterKey(from)
94
- const toKey = getRouterKey(to)
100
+ const { next, prev } = pageGetters.transition;
101
+ const { visitedViews } = tagsViewGetters;
102
+ const fromKey = getRouterKey(from);
103
+ const toKey = getRouterKey(to);
95
104
 
96
105
  // 这里认为页签数量不会太多,所以为了可读性使用两次循环查找
97
- const fromIndex = visitedViews.findIndex(i => i.key === fromKey)
98
- const toIndex = visitedViews.findIndex(i => i.key === toKey)
106
+ const fromIndex = visitedViews.findIndex((i) => i.key === fromKey);
107
+ const toIndex = visitedViews.findIndex((i) => i.key === toKey);
99
108
 
100
- let transitionName = prev
109
+ let transitionName = prev;
101
110
 
102
111
  // 新开tab也认为顺序高于上一个tab
103
112
  if (toIndex === -1 || fromIndex < toIndex) {
104
- transitionName = next
113
+ transitionName = next;
105
114
  }
106
115
 
107
- pageMutations.transition({ curr: transitionName })
116
+ pageMutations.transition({ curr: transitionName });
108
117
  },
109
118
 
110
119
  // 初始化固定显示的页签
111
120
  initTags() {
112
121
  // TODO 如果页签栏初始化后菜单未加载,则固定页签会出问题
113
122
  // 添加所有固定显示的页签
114
- getAffixTagsFromMenuTree(this.$router, appGetters.menus).forEach(tagsViewMutations.addTagOnly)
123
+ getAffixTagsFromMenuTree(this.$router, appGetters.menus).forEach(
124
+ tagsViewMutations.addTagOnly
125
+ );
115
126
 
116
127
  // 将当前路由对象添加为页签
117
- this.addTag(this.$route)
128
+ this.addTag(this.$route);
118
129
  },
119
130
  /**
120
131
  * 尝试将路由对象添加为tab页
@@ -125,18 +136,17 @@ export default {
125
136
  ...route,
126
137
  meta: {
127
138
  ...route.meta,
128
- title: getRouterTitle(route)
129
- }
130
- })
139
+ title: getRouterTitle(route),
140
+ },
141
+ });
131
142
  },
132
143
  // 横向滚动条移动至当前tab
133
144
  moveToCurrentTag() {
134
- const { scroller } = this.$refs
135
- const cur =
136
- Array
137
- .from(scroller.$el.children)
138
- .find(el => el.classList.contains('active'))
139
- cur && scroller.moveToTarget(cur)
145
+ const { scroller } = this.$refs;
146
+ const cur = Array.from(scroller.$el.children).find((el) =>
147
+ el.classList.contains("active")
148
+ );
149
+ cur && scroller.moveToTarget(cur);
140
150
  },
141
151
  /**
142
152
  * 激活末尾页签
@@ -144,20 +154,20 @@ export default {
144
154
  * @return {Promise<Route>}
145
155
  */
146
156
  gotoLastTag(refresh = false) {
147
- const views = tagsViewGetters.visitedViews
148
- const router = this.$router
157
+ const views = tagsViewGetters.visitedViews;
158
+ const router = this.$router;
149
159
 
150
160
  if (views.length === 0) {
151
- return router.push('/')
161
+ return router.push("/");
152
162
  }
153
163
 
154
- const latest = views[views.length - 1]
164
+ const latest = views[views.length - 1];
155
165
 
156
166
  // 目标路由是当前路由时需要刷新,否则直接跳转
157
167
  this.activeKey === latest.key
158
168
  ? refresh && refreshPage(router)
159
- // 需要套一层$nextTick,否则tagsViewStore.visitedViews可能只会变动一次
160
- : this.$nextTick(() => router.push(latest))
169
+ : // 需要套一层$nextTick,否则tagsViewStore.visitedViews可能只会变动一次
170
+ this.$nextTick(() => router.push(latest));
161
171
  },
162
172
 
163
173
  /**
@@ -165,27 +175,27 @@ export default {
165
175
  * @param view {View}
166
176
  */
167
177
  refreshSelectedTag(view = this.selectedTag) {
168
- refreshPage(this.$router, view)
178
+ refreshPage(this.$router, view);
169
179
  },
170
180
  /**
171
181
  * 关闭所选页签
172
182
  * @param view {VisitedView}
173
183
  */
174
184
  closeSelectedTag(view = this.selectedTag) {
175
- if (tagsViewGetters.visitedViews.length <= 1 || isAffix(view)) return
185
+ if (tagsViewGetters.visitedViews.length <= 1 || isAffix(view)) return;
176
186
 
177
- tagsViewMutations.delTagAndCache(view)
178
- this.activeKey === view.key && this.gotoLastTag()
187
+ tagsViewMutations.delTagAndCache(view);
188
+ this.activeKey === view.key && this.gotoLastTag();
179
189
  },
180
190
  // 关闭除激活、固定页签以外的所有页签
181
191
  closeOthersTags() {
182
- tagsViewMutations.delOtherTagAndCache(this.selectedTag)
183
- this.gotoLastTag()
192
+ tagsViewMutations.delOtherTagAndCache(this.selectedTag);
193
+ this.gotoLastTag();
184
194
  },
185
195
  // 关闭除固定页签以外的所有页签
186
196
  closeAllTags() {
187
- tagsViewMutations.delAllTagAndCache()
188
- this.gotoLastTag(true)
197
+ tagsViewMutations.delAllTagAndCache();
198
+ this.gotoLastTag(true);
189
199
  },
190
200
  /**
191
201
  * 在页签上打开右键菜单
@@ -193,39 +203,39 @@ export default {
193
203
  * @param e {MouseEvent}
194
204
  */
195
205
  openContextMenu(tag, e) {
196
- e.preventDefault()
206
+ e.preventDefault();
197
207
 
198
208
  // 销毁之前的右键菜单实例
199
- this.$contextmenu && this.$contextmenu()
209
+ this.$tagscontextmenu && this.$tagscontextmenu();
200
210
 
201
- this.selectedTag = tag
211
+ this.selectedTag = tag;
202
212
 
203
- this.$contextmenu = useContextMenu(this.contextMenuItems, {
213
+ this.$tagscontextmenu = useContextMenu(this.contextMenuItems, {
204
214
  left: e.clientX + 15,
205
- top: e.clientY + 5
206
- })
215
+ top: e.clientY + 5,
216
+ });
207
217
  },
208
218
 
209
219
  renderTags() {
210
- const { $createElement: h, $router, activeKey } = this
211
- const { itemSlot, visitedViews } = tagsViewGetters
212
- const renderFn = itemSlot || renderDefaultStyleTag
220
+ const { $createElement: h, $router, activeKey } = this;
221
+ const { itemSlot, visitedViews } = tagsViewGetters;
222
+ const renderFn = itemSlot || renderDefaultStyleTag;
213
223
 
214
- return visitedViews.map(view => {
215
- const active = activeKey === view.key
216
- const showClose = !isAffix(view) && visitedViews.length > 1
224
+ return visitedViews.map((view) => {
225
+ const active = activeKey === view.key;
226
+ const showClose = !isAffix(view) && visitedViews.length > 1;
217
227
  const on = {
218
- contextmenu: e => this.openContextMenu(view, e)
219
- }
220
- const onClose = e => {
228
+ contextmenu: (e) => this.openContextMenu(view, e),
229
+ };
230
+ const onClose = (e) => {
221
231
  // 需要阻止事件冒泡,不然会触发tag的click事件
222
- e.stopPropagation()
223
- this.closeSelectedTag(view)
224
- }
232
+ e.stopPropagation();
233
+ this.closeSelectedTag(view);
234
+ };
225
235
 
226
236
  // 非激活页签时,绑定点击事件,点击跳转到页签对应的路由
227
237
  if (!active) {
228
- on.click = () => $router.push(view, () => undefined)
238
+ on.click = () => $router.push(view, () => undefined);
229
239
  }
230
240
 
231
241
  return renderFn(h, {
@@ -233,23 +243,23 @@ export default {
233
243
  active,
234
244
  on,
235
245
  title: view.meta.title,
236
- close: showClose && onClose
237
- })
238
- })
239
- }
246
+ close: showClose && onClose,
247
+ });
248
+ });
249
+ },
240
250
  },
241
251
 
242
252
  mounted() {
243
- this.setActiveKey(this.$route)
244
- this.initTags()
253
+ this.setActiveKey(this.$route);
254
+ this.initTags();
245
255
  },
246
256
 
247
257
  render() {
248
258
  return (
249
259
  <nav class="tags-view">
250
- <HorizontalScroller ref="scroller" scopedSlots={this.tagsSlot}/>
260
+ <HorizontalScroller ref="scroller" scopedSlots={this.tagsSlot} />
251
261
  </nav>
252
- )
253
- }
254
- }
262
+ );
263
+ },
264
+ };
255
265
  </script>
@@ -11,7 +11,7 @@ const state = {
11
11
  // 是否启用
12
12
  enabled: true,
13
13
  // 是否启用缓存功能
14
- enableCache: true,
14
+ enableCache: false,
15
15
  // 是否启用根据页签顺序来确定过渡动画的功能
16
16
  enableChangeTransition: true,
17
17