@vtj/web 0.9.9 → 0.9.11
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 +7 -6
- package/src/index.ts +1 -0
- package/src/integrations/element-admin.ts +189 -0
- package/src/integrations/index.ts +1 -0
package/package.json
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vtj/web",
|
3
3
|
"private": false,
|
4
|
-
"version": "0.9.
|
4
|
+
"version": "0.9.11",
|
5
5
|
"type": "module",
|
6
6
|
"sideEffects": false,
|
7
7
|
"dependencies": {
|
8
8
|
"core-js": "~3.39.0",
|
9
9
|
"regenerator-runtime": "~0.14.1",
|
10
|
-
"@vtj/charts": "~0.9.
|
11
|
-
"@vtj/
|
12
|
-
"@vtj/
|
13
|
-
"@vtj/utils": "~0.9.
|
14
|
-
"@vtj/ui": "~0.9.
|
10
|
+
"@vtj/charts": "~0.9.11",
|
11
|
+
"@vtj/core": "~0.9.11",
|
12
|
+
"@vtj/icons": "~0.9.11",
|
13
|
+
"@vtj/utils": "~0.9.11",
|
14
|
+
"@vtj/ui": "~0.9.11",
|
15
|
+
"@vtj/renderer": "~0.9.11"
|
15
16
|
},
|
16
17
|
"devDependencies": {
|
17
18
|
"@vtj/cli": "~0.9.6"
|
package/src/index.ts
CHANGED
@@ -0,0 +1,189 @@
|
|
1
|
+
import type { App } from 'vue';
|
2
|
+
import type { Router, RouteRecordRaw } from 'vue-router';
|
3
|
+
import { kebabCase } from '@vtj/utils';
|
4
|
+
import { autoUpdate } from '@vtj/ui';
|
5
|
+
import type { ProjectSchema, PageFile } from '@vtj/core';
|
6
|
+
import {
|
7
|
+
createProvider,
|
8
|
+
LocalService,
|
9
|
+
NodeEnv,
|
10
|
+
ContextMode,
|
11
|
+
notify,
|
12
|
+
loading,
|
13
|
+
createAdapter,
|
14
|
+
createServiceRequest
|
15
|
+
} from '../renderer';
|
16
|
+
import { createModules } from '../modules';
|
17
|
+
|
18
|
+
type VtjModules = ReturnType<typeof createModules>;
|
19
|
+
|
20
|
+
export interface SetupElementAdminOptions {
|
21
|
+
id: string;
|
22
|
+
app: App;
|
23
|
+
ready?: () => void;
|
24
|
+
}
|
25
|
+
|
26
|
+
export interface setupElementAdminRoutesOptions {
|
27
|
+
id: string;
|
28
|
+
router: Router;
|
29
|
+
routes: any[];
|
30
|
+
layout: any;
|
31
|
+
}
|
32
|
+
|
33
|
+
function toElIcon(icon?: string) {
|
34
|
+
return icon ? `vi-ep:${kebabCase(icon)}` : undefined;
|
35
|
+
}
|
36
|
+
|
37
|
+
async function getComponent(path: string, modules: VtjModules) {
|
38
|
+
// const rawPath = `.vtj/vue/${id}.vue`;
|
39
|
+
const rawModule = modules[path];
|
40
|
+
if (rawModule) {
|
41
|
+
return ((await rawModule()) as any)?.default;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
function createPageRoute(page: PageFile, modules: VtjModules) {
|
46
|
+
const { id, title, icon, hidden, cache = false, meta = {} } = page;
|
47
|
+
return {
|
48
|
+
path: `page/${id}`,
|
49
|
+
name: `Page_${id}`,
|
50
|
+
component: () => getComponent(`.vtj/vue/${id}.vue`, modules),
|
51
|
+
meta: {
|
52
|
+
title,
|
53
|
+
hidden,
|
54
|
+
icon: toElIcon(icon),
|
55
|
+
noCache: !cache,
|
56
|
+
...meta
|
57
|
+
}
|
58
|
+
};
|
59
|
+
}
|
60
|
+
|
61
|
+
function createNoMaskRoute(page: PageFile, modules: VtjModules) {
|
62
|
+
const { id, title, icon, cache = false, meta = {} } = page;
|
63
|
+
return {
|
64
|
+
path: `/page/${id}`,
|
65
|
+
component: () => getComponent(`.vtj/vue/${id}.vue`, modules),
|
66
|
+
meta: {
|
67
|
+
title,
|
68
|
+
icon: toElIcon(icon),
|
69
|
+
hidden: true,
|
70
|
+
noCache: !cache,
|
71
|
+
...meta
|
72
|
+
}
|
73
|
+
};
|
74
|
+
}
|
75
|
+
|
76
|
+
function childrenToRoutes(
|
77
|
+
children: PageFile[] = [],
|
78
|
+
noMask: any[],
|
79
|
+
modules: VtjModules
|
80
|
+
): RouteRecordRaw[] {
|
81
|
+
return children.map((child) => {
|
82
|
+
const { id, dir, mask = true, title, icon, hidden } = child;
|
83
|
+
if (dir) {
|
84
|
+
return {
|
85
|
+
path: '',
|
86
|
+
name: `Dir_${id}`,
|
87
|
+
redirect: `/page/${id}`,
|
88
|
+
meta: {
|
89
|
+
hidden,
|
90
|
+
title,
|
91
|
+
alwaysShow: true,
|
92
|
+
icon: toElIcon(icon)
|
93
|
+
},
|
94
|
+
children: childrenToRoutes(child.children, noMask, modules)
|
95
|
+
};
|
96
|
+
}
|
97
|
+
if (!mask) {
|
98
|
+
noMask.push(createNoMaskRoute(child, modules));
|
99
|
+
}
|
100
|
+
return createPageRoute(child, modules);
|
101
|
+
});
|
102
|
+
}
|
103
|
+
|
104
|
+
function pagesToRoutes(pages: PageFile[], layout: any, modules: VtjModules) {
|
105
|
+
const noMask: any[] = [];
|
106
|
+
const items: any[] = [];
|
107
|
+
for (const page of pages) {
|
108
|
+
const { id, dir, mask = true, title, icon, hidden, children = [] } = page;
|
109
|
+
if (!dir && !mask) {
|
110
|
+
noMask.push(createNoMaskRoute(page, modules));
|
111
|
+
}
|
112
|
+
|
113
|
+
if (children.length) {
|
114
|
+
items.push({
|
115
|
+
path: '/',
|
116
|
+
name: `Root_${id}`,
|
117
|
+
component: layout,
|
118
|
+
meta: {
|
119
|
+
hidden,
|
120
|
+
title,
|
121
|
+
alwaysShow: true,
|
122
|
+
icon: toElIcon(icon)
|
123
|
+
},
|
124
|
+
children: childrenToRoutes(children, noMask, modules)
|
125
|
+
});
|
126
|
+
} else {
|
127
|
+
items.push({
|
128
|
+
path: '/',
|
129
|
+
name: `Root_${id}`,
|
130
|
+
component: layout,
|
131
|
+
meta: {
|
132
|
+
hidden,
|
133
|
+
title,
|
134
|
+
alwaysShow: !!dir,
|
135
|
+
icon: toElIcon(icon)
|
136
|
+
},
|
137
|
+
children: dir ? [] : [createPageRoute(page, modules)]
|
138
|
+
});
|
139
|
+
}
|
140
|
+
}
|
141
|
+
return [...noMask, ...items];
|
142
|
+
}
|
143
|
+
|
144
|
+
export function setupElementAdmin(options: SetupElementAdminOptions) {
|
145
|
+
const { id, app, ready } = options;
|
146
|
+
const adapter = createAdapter({ loading, notify });
|
147
|
+
const service = new LocalService(createServiceRequest(notify));
|
148
|
+
const modules = createModules();
|
149
|
+
const { provider, onReady } = createProvider({
|
150
|
+
nodeEnv: process.env.NODE_ENV as NodeEnv,
|
151
|
+
mode: ContextMode.Raw,
|
152
|
+
modules,
|
153
|
+
adapter,
|
154
|
+
service,
|
155
|
+
dependencies: {
|
156
|
+
Vue: () => import('vue'),
|
157
|
+
VueRouter: () => import('vue-router')
|
158
|
+
},
|
159
|
+
project: {
|
160
|
+
id
|
161
|
+
}
|
162
|
+
});
|
163
|
+
|
164
|
+
onReady(async () => {
|
165
|
+
app.use(provider);
|
166
|
+
ready && ready();
|
167
|
+
});
|
168
|
+
|
169
|
+
if (process.env.NODE_ENV === 'production') {
|
170
|
+
autoUpdate();
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
export async function setupElementAdminRoutes(
|
175
|
+
options: setupElementAdminRoutesOptions
|
176
|
+
) {
|
177
|
+
const modules = createModules();
|
178
|
+
const { id, layout, routes, router } = options;
|
179
|
+
const loader = modules[`.vtj/projects/${id}.json`];
|
180
|
+
if (loader) {
|
181
|
+
const project = ((await loader()) as any).default as ProjectSchema;
|
182
|
+
const pages = project.pages || [];
|
183
|
+
const pageRoutes = pagesToRoutes(pages, layout, modules);
|
184
|
+
routes.unshift(...pageRoutes);
|
185
|
+
routes.forEach((item) => {
|
186
|
+
router.addRoute(item);
|
187
|
+
});
|
188
|
+
}
|
189
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './element-admin';
|