yuang-framework-ui-pc 1.1.2 → 1.1.3

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.
@@ -1,255 +0,0 @@
1
- import type { PropType, ExtractPropTypes, InjectionKey } from 'vue';
2
- import type { StyleValue } from '../ele-app/types';
3
- import type { EleMenusProps, EleBreadcrumbProps, EleDropdownProps, EleBacktopProps } from '../ele-app/plus';
4
- import type { ContextMenus } from '../ele-tabs/types';
5
- import type { BreadcrumbSeparator as Separator } from '../ele-breadcrumb/types';
6
- import type { Layout, SidebarLayout, HeaderStyle, SidebarStyle, TabStyle, TabBar, Maximized } from '../ele-admin-layout/types';
7
- import type { MenuItem, TabItem, MenuItemTrigger, MenuI18n, BeforeClick, TabItemEventOption, BodySizeChangeOption, ProLayoutProvide } from './types';
8
- type TextEllipsisTooltip = EleMenusProps['textEllipsisTooltip'];
9
- type ProLayoutKey = InjectionKey<ProLayoutProvide>;
10
-
11
- /**
12
- * 属性
13
- */
14
- export const proLayoutProps = {
15
- /** 高度 */
16
- height: {
17
- type: [String, Number],
18
- default: null
19
- },
20
- /** 菜单数据 */
21
- menus: Array as PropType<MenuItem[] | null>,
22
- /** 页签数据 */
23
- tabs: Array as PropType<TabItem[] | null>,
24
- /** 是否折叠侧栏 */
25
- collapse: Boolean,
26
- /** 双侧栏一级是否紧凑风格 */
27
- compact: Boolean,
28
- /** 内容区是否最大化 */
29
- maximized: [Boolean, String] as PropType<Maximized>,
30
- /** 是否需要页签栏 */
31
- tabBar: {
32
- type: [Boolean, String] as PropType<TabBar>,
33
- default: true
34
- },
35
- /** 是否需要面包屑导航 */
36
- breadcrumb: {
37
- type: [Boolean, Object] as PropType<boolean | EleBreadcrumbProps>,
38
- default: true
39
- },
40
- /** 是否需要返回顶部 */
41
- backTop: {
42
- type: [Boolean, Object] as PropType<boolean | EleBacktopProps>,
43
- default: true
44
- },
45
- /** 布局类型 */
46
- layout: String as PropType<Layout>,
47
- /** 侧栏布局类型 */
48
- sidebarLayout: String as PropType<SidebarLayout>,
49
- /** 顶栏风格 */
50
- headerStyle: String as PropType<HeaderStyle>,
51
- /** 侧栏风格 */
52
- sidebarStyle: {
53
- type: String as PropType<SidebarStyle>,
54
- default: 'dark'
55
- },
56
- /** 页签风格 */
57
- tabStyle: {
58
- type: String as PropType<TabStyle>,
59
- default: 'simple'
60
- },
61
- /** 是否固定顶栏 */
62
- fixedHeader: {
63
- type: Boolean,
64
- default: true
65
- },
66
- /** 是否固定侧栏 */
67
- fixedSidebar: {
68
- type: Boolean,
69
- default: true
70
- },
71
- /** 是否固定内容区 */
72
- fixedBody: {
73
- type: Boolean,
74
- default: true
75
- },
76
- /** 图标是否置于顶栏 */
77
- logoInHeader: Boolean,
78
- /** 是否需要固定的主页页签 */
79
- fixedHome: {
80
- type: Boolean,
81
- default: true
82
- },
83
- /** 主页路由地址 */
84
- homePath: String,
85
- /** 刷新路由地址 */
86
- redirectPath: {
87
- type: String,
88
- default: '/redirect'
89
- },
90
- /** 内容区是否撑满 */
91
- fluid: {
92
- type: Boolean,
93
- default: true
94
- },
95
- /** 返回键退出内容区最大化 */
96
- compressOnEsc: Boolean,
97
- /** 固定主体时切换路由自动滚到顶部 */
98
- autoScrollTop: {
99
- type: Boolean,
100
- default: true
101
- },
102
- /** 顶栏菜单触发模式 */
103
- navTrigger: String as PropType<MenuItemTrigger>,
104
- /** 双侧栏一级菜单触发模式 */
105
- boxTrigger: String as PropType<MenuItemTrigger>,
106
- /** 侧栏菜单触发模式 */
107
- itemTrigger: String as PropType<MenuItemTrigger>,
108
- /** hover模式的菜单切换超时 */
109
- menuHoverTimeout: {
110
- type: Number,
111
- default: 600
112
- },
113
- /** 菜单点击事件前钩子 */
114
- beforeClick: Function as PropType<BeforeClick>,
115
- /** 是否支持内嵌缓存 */
116
- keepAlive: Boolean,
117
- /** 内嵌切换动画 */
118
- transitionName: String,
119
- /** 内嵌进入动画延迟时间 */
120
- transitionDelay: {
121
- type: Number,
122
- default: 250
123
- },
124
- /** 是否开启响应式 */
125
- responsive: {
126
- type: Boolean,
127
- default: true
128
- },
129
- /** 国际化语言 */
130
- locale: String,
131
- /** 菜单标题国际化方法 */
132
- i18n: Function as PropType<MenuI18n>,
133
- /** 是否支持页签右键菜单 */
134
- tabContextMenu: [Boolean, Object] as PropType<boolean | EleDropdownProps>,
135
- /** 右键菜单 */
136
- tabContextMenus: [Array, Function] as PropType<ContextMenus>,
137
- /** 是否支持页签拖动排序 */
138
- tabSortable: Boolean,
139
- /** 顶栏菜单标题插槽名称 */
140
- headerTitleSlot: {
141
- type: String,
142
- default: 'title'
143
- },
144
- /** 顶栏菜单图标插槽名称 */
145
- headerIconSlot: {
146
- type: String,
147
- default: 'icon'
148
- },
149
- /** 侧栏菜单标题插槽名称 */
150
- sidebarTitleSlot: {
151
- type: String,
152
- default: 'title'
153
- },
154
- /** 侧栏菜单图标插槽名称 */
155
- sidebarIconSlot: {
156
- type: String,
157
- default: 'icon'
158
- },
159
- /** 双侧栏一级菜单标题插槽名称 */
160
- sideboxTitleSlot: {
161
- type: String,
162
- default: 'title'
163
- },
164
- /** 双侧栏一级菜单图标插槽名称 */
165
- sideboxIconSlot: {
166
- type: String,
167
- default: 'icon'
168
- },
169
- /** 顶栏样式 */
170
- headerCustomStyle: Object as PropType<StyleValue>,
171
- /** 侧栏样式 */
172
- sidebarCustomStyle: Object as PropType<StyleValue>,
173
- /** 双侧栏一级样式 */
174
- sideboxCustomStyle: Object as PropType<StyleValue>,
175
- /** 页签栏样式 */
176
- tabsCustomStyle: Object as PropType<StyleValue>,
177
- /** 内容区样式 */
178
- contentCustomStyle: Object as PropType<StyleValue>,
179
- /** logo样式 */
180
- logoStyle: Object as PropType<StyleValue>,
181
- /** logo文字样式 */
182
- logoTitleStyle: Object as PropType<StyleValue>,
183
- /** 顶栏菜单样式 */
184
- headerMenusStyle: Object as PropType<StyleValue>,
185
- /** 侧栏菜单样式 */
186
- sidebarMenusStyle: Object as PropType<StyleValue>,
187
- /** 双侧栏一级菜单样式 */
188
- sideboxMenusStyle: Object as PropType<StyleValue>,
189
- /** 顶栏菜单属性 */
190
- headerMenuProps: Object as PropType<EleMenusProps>,
191
- /** 侧栏菜单属性 */
192
- sidebarMenuProps: Object as PropType<EleMenusProps>,
193
- /** 双侧栏一级菜单属性 */
194
- sideboxMenuProps: Object as PropType<EleMenusProps>,
195
- /** 顶栏菜单是否省略多余的子项 */
196
- ellipsis: {
197
- type: Boolean,
198
- default: true
199
- },
200
- /** 顶栏菜单省略项的属性 */
201
- ellipsisProps: Object as PropType<EleMenusProps['ellipsisProps']>,
202
- /** 顶栏子菜单触发方式 */
203
- menuTrigger: String as PropType<EleMenusProps['menuTrigger']>,
204
- /** 侧栏默认展开的菜单 */
205
- sidebarOpeneds: Array as PropType<string[]>,
206
- /** 侧栏是否只保持一个子菜单展开 */
207
- uniqueOpened: {
208
- type: Boolean,
209
- default: true
210
- },
211
- /** 侧栏菜单是否彩色图标 */
212
- colorfulIcon: Boolean,
213
- /** 菜单 tooltip 主题 */
214
- tooltipEffect: String as PropType<EleMenusProps['popperEffect']>,
215
- /** 是否开启菜单文本溢出提示 */
216
- menuTextEllipsisTooltip: [Boolean, Object] as PropType<TextEllipsisTooltip>,
217
- /** 内容区最大时不带页签栏 */
218
- expanded: Boolean,
219
- /** 面包屑导航分隔符 */
220
- breadcrumbSeparator: [String, Object, Function] as PropType<Separator>,
221
- /** 返回顶部可见的滚动高度 */
222
- backTopVisibilityHeight: Number,
223
- /** 返回顶部的右边距 */
224
- backTopRight: Number,
225
- /** 返回顶部的下边距 */
226
- backTopBottom: Number,
227
- /** 返回顶部的目标选择器 */
228
- backTopTarget: String
229
- };
230
-
231
- export type ProLayoutProps = ExtractPropTypes<typeof proLayoutProps>;
232
-
233
- /**
234
- * 事件
235
- */
236
- export const proLayoutEmits = {
237
- 'update:collapse': (_collapse: boolean) => true,
238
- 'update:maximized': (_maximized: boolean) => true,
239
- tabAdd: (_data: TabItem) => true,
240
- tabClick: (_option: TabItemEventOption) => true,
241
- tabRemove: (_option: TabItemEventOption) => true,
242
- tabContextMenu: (_option: TabItemEventOption) => true,
243
- tabSortChange: (_data: TabItem[]) => true,
244
- logoClick: (_isHome: boolean, _e: MouseEvent) => true,
245
- headMenuOpen: (_index: string, _indexPath: string[]) => true,
246
- headMenuClose: (_index: string, _indexPath: string[]) => true,
247
- sideMenuOpen: (_index: string, _indexPath: string[]) => true,
248
- sideMenuClose: (_index: string, _indexPath: string[]) => true,
249
- bodySizeChange: (_option: BodySizeChangeOption) => true
250
- };
251
-
252
- /**
253
- * 共享数据key
254
- */
255
- export const PRO_LAYOUT_KEY = Symbol('proLayout') as ProLayoutKey;
@@ -1,2 +0,0 @@
1
- import '../../ele-admin-layout/style/index';
2
- import './index.scss';
@@ -1,277 +0,0 @@
1
- import { inject, computed } from 'vue';
2
- import type {
3
- RouteLocationNormalizedLoaded,
4
- RouteLocationMatched
5
- } from 'vue-router';
6
- import type { EleMenuItemProps } from '../ele-app/plus';
7
- import { findTree, mapTree, omit } from '../utils/core';
8
- import { LayoutProvide } from '../ele-admin-layout/types';
9
- import { LAYOUT_KEY } from '../ele-admin-layout/props';
10
- import { PRO_LAYOUT_KEY } from './props';
11
- import type {
12
- MenuItem,
13
- TabItem,
14
- LevelItem,
15
- MatchedResult,
16
- ProLayoutProvide,
17
- ResponsiveProps
18
- } from './types';
19
-
20
- /**
21
- * 根据菜单地址获取菜单
22
- * @param path 菜单地址
23
- * @param menus 菜单数据
24
- */
25
- export function findMenuByPath(path?: string, menus?: MenuItem[]) {
26
- return path == null ? void 0 : findTree(menus, (d) => path === d.path);
27
- }
28
-
29
- /**
30
- * 根据路由地址获取页签
31
- * @param path 路由地址
32
- * @param tabs 页签数据
33
- */
34
- export function findTabByPath(path?: string, tabs?: TabItem[] | null) {
35
- if (path != null && tabs != null) {
36
- return tabs.find((d) => path === d.key || path === d.fullPath);
37
- }
38
- }
39
-
40
- /**
41
- * 根据页签标识获取页签
42
- * @param key 页签标识
43
- * @param tabs 页签数据
44
- */
45
- export function findTabByKey(key?: string, tabs?: TabItem[] | null) {
46
- if (key != null && tabs != null) {
47
- return tabs.find((d) => key === d.key);
48
- }
49
- }
50
-
51
- /**
52
- * 根据菜单地址获取菜单及所有父级
53
- * @param path 菜单地址
54
- * @param menus 菜单数据
55
- */
56
- export function getMatchedMenus(
57
- path: string,
58
- menus: MenuItem[],
59
- parents?: MenuItem[]
60
- ): MenuItem[] | undefined {
61
- for (const m of menus) {
62
- const p = parents ? [...parents, m] : [m];
63
- if (m.path === path) {
64
- return p;
65
- } else if (m.children?.length) {
66
- const result = getMatchedMenus(path, m.children, p);
67
- if (result) {
68
- return result;
69
- }
70
- }
71
- }
72
- }
73
-
74
- /**
75
- * 获取路由匹配的菜单数据
76
- * @param route 路由信息
77
- * @param menus 菜单数据
78
- */
79
- export function getRouteMatched(
80
- route: RouteLocationNormalizedLoaded,
81
- menus: MenuItem[]
82
- ): MatchedResult {
83
- const { path, fullPath, meta } = route;
84
- if (meta?.active) {
85
- const m = findMenuByPath(fullPath, menus) ?? findMenuByPath(path, menus);
86
- return {
87
- active: meta.active as string,
88
- activeOther: true,
89
- title: m?.meta?.title ?? (meta.title as string),
90
- matched: getMatchedMenus(meta.active as string, menus)
91
- };
92
- }
93
- const fm = findMenuByPath(fullPath, menus);
94
- if (fm) {
95
- return {
96
- active: fullPath,
97
- title: fm.meta?.title ?? (meta.title as string),
98
- matched: getMatchedMenus(fullPath, menus)
99
- };
100
- }
101
- const m = findMenuByPath(path, menus);
102
- return {
103
- active: path,
104
- title: m?.meta?.title ?? (meta.title as string),
105
- matched: getMatchedMenus(path, menus)
106
- };
107
- }
108
-
109
- /**
110
- * 获取面包屑导航数据
111
- * @param matched 匹配的菜单数据
112
- * @param activeOther 是否选中非本身
113
- * @param route 路由信息
114
- * @param menus 菜单数据
115
- * @param tabs 页签数据
116
- */
117
- export function getMatchedLevels(
118
- matched: MenuItem[] | undefined,
119
- activeOther: boolean | undefined,
120
- route: RouteLocationNormalizedLoaded,
121
- menus: MenuItem[],
122
- tabs: TabItem[]
123
- ): LevelItem[] {
124
- const levels: LevelItem[] = [];
125
- if (matched) {
126
- matched.forEach((m) => {
127
- if (m.meta && m.meta.title && m.meta.breadcrumb !== false) {
128
- const title = findTabByPath(m.path, tabs)?.title || m.meta.title;
129
- levels.push({ path: m.path, title });
130
- }
131
- });
132
- }
133
- if (activeOther) {
134
- const { path, fullPath, meta } = route;
135
- const notIn = !levels.length || fullPath !== levels[levels.length - 1].path;
136
- if (notIn && meta.title) {
137
- const m = findMenuByPath(fullPath, menus) ?? findMenuByPath(path, menus);
138
- const t = findTabByPath(fullPath, tabs) ?? findTabByPath(path, tabs);
139
- const title = t?.title || m?.meta?.title || (meta.title as string);
140
- levels.push({ path: fullPath, title });
141
- }
142
- }
143
- return levels;
144
- }
145
-
146
- /**
147
- * 获取路由对应的组件名称
148
- * @param matched 路由匹配数据
149
- */
150
- export function getMatchedComponents(matched: RouteLocationMatched[]) {
151
- const components: string[] = [];
152
- matched.forEach((m) => {
153
- if (m.components?.default?.name) {
154
- components.push(m.components.default.name);
155
- }
156
- });
157
- return components;
158
- }
159
-
160
- /**
161
- * 返回路由对应的页签数据
162
- * @param route 路由信息
163
- * @param tabs 当前页签数据
164
- * @param homePath 主页地址
165
- * @param routeTitle 路由对应的标题
166
- */
167
- export function getRouteTab(
168
- route: RouteLocationNormalizedLoaded,
169
- tabs: TabItem[],
170
- homePath: string | undefined,
171
- routeTitle?: string
172
- ): TabItem {
173
- const { path, fullPath, meta, matched } = route;
174
- const key = meta.tabUnique === false ? fullPath : path;
175
- const t = findTabByPath(key, tabs);
176
- // 标题
177
- const title = t?.title || routeTitle;
178
- // 是否是主页
179
- const home = path === homePath || fullPath === homePath;
180
- // 是否可关闭
181
- const closable = t?.closable ?? meta.closable !== false;
182
- // 路由对应的组件名
183
- const components = getMatchedComponents(matched);
184
- return { key, path, fullPath, title, closable, home, components, meta };
185
- }
186
-
187
- /**
188
- * 获取选中菜单的子级
189
- * @param menus 菜单数据
190
- * @param active 选中地址
191
- * @param childrenName 子级字段名称
192
- */
193
- export function getActiveChilds(
194
- menus: MenuItem[],
195
- active?: string,
196
- childrenName?: string
197
- ): MenuItem[] {
198
- const field = childrenName || 'children';
199
- if (!menus.length) {
200
- return [];
201
- }
202
- if (!active) {
203
- return menus[0][field] || [];
204
- }
205
- const m = menus.find((m) => m.path === active);
206
- if (m == null) {
207
- return menus[0][field] || [];
208
- }
209
- return m[field] || [];
210
- }
211
-
212
- /**
213
- * 拼接内嵌地址
214
- * @param routePath 路由地址含参数
215
- * @param iframeUrl 内嵌地址
216
- */
217
- export function getIframeSrc(routePath?: string, iframeUrl?: string) {
218
- const [_path1, query1 = ''] = (routePath ?? '').split('?');
219
- const [path2, query2 = ''] = (iframeUrl ?? '').split('?');
220
- const params1 = new URLSearchParams(query1);
221
- const params2 = new URLSearchParams(query2);
222
- // @ts-ignore
223
- for (const [key, value] of params2.entries()) {
224
- params1.append(key, value);
225
- }
226
- const newQuery = params1.toString();
227
- return `${path2}${newQuery ? `?${newQuery}` : ''}`;
228
- }
229
-
230
- /**
231
- * 菜单数据转换
232
- * @param menus 菜单数据
233
- * @param link 是否使用超链接
234
- */
235
- export function getMenuItems(
236
- menus: MenuItem[],
237
- link: boolean
238
- ): EleMenuItemProps[] {
239
- return mapTree<MenuItem, EleMenuItemProps>(menus, (m) => {
240
- const { path, meta } = m;
241
- const { hide, icon, title, props } = meta ?? {};
242
- if (hide) {
243
- return;
244
- }
245
- const item: EleMenuItemProps = {
246
- title,
247
- icon,
248
- path: link ? path : void 0,
249
- index: path,
250
- ...omit(props, ['title', 'icon', 'path', 'index']),
251
- meta
252
- };
253
- return item;
254
- });
255
- }
256
-
257
- /**
258
- * 获取布局共享数据
259
- */
260
- export function useLayoutState(): LayoutProvide {
261
- return inject(LAYOUT_KEY, {});
262
- }
263
-
264
- /**
265
- * 获取高级布局共享数据
266
- */
267
- export function useProLayoutState(): ProLayoutProvide {
268
- return inject(PRO_LAYOUT_KEY, {});
269
- }
270
-
271
- /**
272
- * 获取是否开启布局响应
273
- */
274
- export function useResponsive(props: ResponsiveProps) {
275
- const state = useProLayoutState();
276
- return computed<boolean>(() => props.responsive ?? state.responsive ?? true);
277
- }