@skyfox2000/microbase 1.0.0
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/README.md +16 -0
- package/lib/assets/modules/index-yUrmSBei.js +11 -0
- package/lib/index.d.ts +459 -0
- package/lib/microbase.es.js +109 -0
- package/package.json +40 -0
- package/src/components/loader/index.ts +70 -0
- package/src/components/loader/index.vue +12 -0
- package/src/index.ts +14 -0
- package/src/router/loader-router.ts +153 -0
- package/src/stores/appInfo.d.ts +95 -0
- package/src/stores/hostInfo.d.ts +56 -0
- package/src/stores/settingInfo.d.ts +36 -0
- package/src/stores/userInfo.d.ts +51 -0
- package/src/utils/data.ts +64 -0
- package/src/utils/micro-app.ts +106 -0
- package/src/vite-env.d.ts +14 -0
- package/tsconfig.json +41 -0
- package/vite.config.ts +71 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "@/stores/appInfo.d";
|
|
2
|
+
export * from "@/stores/hostInfo.d";
|
|
3
|
+
export * from "@/stores/settingInfo.d";
|
|
4
|
+
export * from "@/stores/userInfo.d";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export * from "@/utils/data";
|
|
8
|
+
export * from "@/utils/micro-app";
|
|
9
|
+
|
|
10
|
+
export * from "@/router/loader-router";
|
|
11
|
+
import LoaderRouter from "@/router/loader-router";
|
|
12
|
+
export { LoaderRouter };
|
|
13
|
+
|
|
14
|
+
export * from "@/components/loader/index";
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { mainAppApis } from "@/utils/micro-app";
|
|
2
|
+
import {
|
|
3
|
+
RouteLocationNormalizedGeneric,
|
|
4
|
+
RouteRecordRaw,
|
|
5
|
+
Router,
|
|
6
|
+
createRouter,
|
|
7
|
+
createWebHashHistory
|
|
8
|
+
} from "vue-router";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 菜单链接信息
|
|
12
|
+
*/
|
|
13
|
+
export type MenuLink = {
|
|
14
|
+
/**
|
|
15
|
+
* 名称
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* 图标
|
|
20
|
+
* icon可以是字符串路径或组件
|
|
21
|
+
*/
|
|
22
|
+
icon: string;
|
|
23
|
+
/**
|
|
24
|
+
* 路径
|
|
25
|
+
*/
|
|
26
|
+
path: string;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 路由扩展信息
|
|
32
|
+
*/
|
|
33
|
+
export type RouteMeta = {
|
|
34
|
+
/**
|
|
35
|
+
* 应用码,所属应用
|
|
36
|
+
*/
|
|
37
|
+
code?: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* 应用地址
|
|
40
|
+
*/
|
|
41
|
+
host?: string | null;
|
|
42
|
+
/**
|
|
43
|
+
* 页面地址
|
|
44
|
+
*/
|
|
45
|
+
page?: string | null;
|
|
46
|
+
/**
|
|
47
|
+
* 授权角色
|
|
48
|
+
*/
|
|
49
|
+
roles?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* 功能码
|
|
52
|
+
*/
|
|
53
|
+
permission?: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 路由记录
|
|
58
|
+
*/
|
|
59
|
+
export type RouteRecord = RouteRecordRaw & {
|
|
60
|
+
parent?: RouteRecord | null;
|
|
61
|
+
/**
|
|
62
|
+
* 路由图标
|
|
63
|
+
*/
|
|
64
|
+
icon?: string;
|
|
65
|
+
/**
|
|
66
|
+
* 附加属性
|
|
67
|
+
*/
|
|
68
|
+
meta?: RouteMeta;
|
|
69
|
+
/**
|
|
70
|
+
* 子路由信息
|
|
71
|
+
*/
|
|
72
|
+
children?: RouteRecord[];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 默认路由
|
|
77
|
+
*/
|
|
78
|
+
const routes: RouteRecordRaw[] = [
|
|
79
|
+
{
|
|
80
|
+
path: "/:page(.*)",
|
|
81
|
+
name: "默认页面",
|
|
82
|
+
component: () => import("@/components/loader/index.vue")
|
|
83
|
+
}
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
const router: Router = createRouter({
|
|
87
|
+
history: createWebHashHistory(import.meta.env.VITE_ROUTER_BASE),
|
|
88
|
+
routes: routes
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 路由权限判断
|
|
93
|
+
* @param route 指定路由
|
|
94
|
+
* @param isLogin 是否已登录
|
|
95
|
+
* @param userRoles 用户角色
|
|
96
|
+
* @param userPermits 用户权限
|
|
97
|
+
* @returns 权限判断结果
|
|
98
|
+
*/
|
|
99
|
+
export const hasPermission = (
|
|
100
|
+
route: RouteRecord,
|
|
101
|
+
isLogin: boolean,
|
|
102
|
+
userRoles: string[],
|
|
103
|
+
userPermits: string[]
|
|
104
|
+
): boolean => {
|
|
105
|
+
const roles = route.meta?.roles ?? [];
|
|
106
|
+
const permission = route.meta?.permission;
|
|
107
|
+
|
|
108
|
+
// 如果用户未登录,且路由没有角色和权限要求,则允许访问
|
|
109
|
+
if (!isLogin) {
|
|
110
|
+
return roles.length === 0 && !permission;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 如果用户已登录或有角色和权限信息
|
|
114
|
+
if (isLogin && (userRoles.length > 0 || userPermits.length > 0)) {
|
|
115
|
+
// 没有角色码和权限码,都可以访问
|
|
116
|
+
if (roles.length === 0 && !permission) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 路由有角色码无权限码,符合任何一个角色都可以访问
|
|
121
|
+
if (roles.length && !permission) {
|
|
122
|
+
return roles.some((role) => userRoles.includes(role));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 路由无角色码有权限码,符合权限码即可访问
|
|
126
|
+
if (!roles.length && permission) {
|
|
127
|
+
return userPermits.includes(permission);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 路由同时有角色码和权限码,必须用户角色和权限同时满足才可访问
|
|
131
|
+
if (roles.length && permission) {
|
|
132
|
+
return (
|
|
133
|
+
roles.some((role) => userRoles.includes(role)) &&
|
|
134
|
+
userPermits.includes(permission)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 默认返回 false,即无匹配条件时不允许访问
|
|
140
|
+
return false;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 子应用更新主应用路由
|
|
145
|
+
*/
|
|
146
|
+
router.afterEach((to: RouteLocationNormalizedGeneric) => {
|
|
147
|
+
if (mainAppApis.value) {
|
|
148
|
+
const { mainAppPush } = mainAppApis.value;
|
|
149
|
+
if(mainAppPush) mainAppPush(to.hash);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export default router;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 应用来源: Market | Manual
|
|
3
|
+
*/
|
|
4
|
+
export enum AppSource {
|
|
5
|
+
/**
|
|
6
|
+
* 从市场安装
|
|
7
|
+
*/
|
|
8
|
+
"Market" = "Market",
|
|
9
|
+
/**
|
|
10
|
+
* 手动输入
|
|
11
|
+
*/
|
|
12
|
+
"Manual" = "Manual"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 应用动作: App | Open | Iframe
|
|
16
|
+
*/
|
|
17
|
+
export enum AppAction {
|
|
18
|
+
/**
|
|
19
|
+
* 应用模式加载
|
|
20
|
+
*/
|
|
21
|
+
"App" = "App",
|
|
22
|
+
/**
|
|
23
|
+
* 托管应用模式加载
|
|
24
|
+
* - 菜单托管,平台管理加载菜单
|
|
25
|
+
*/
|
|
26
|
+
"MenuApp" = "MenuApp",
|
|
27
|
+
/**
|
|
28
|
+
* 链接,弹出窗口打开
|
|
29
|
+
*/
|
|
30
|
+
"Link" = "Link",
|
|
31
|
+
/**
|
|
32
|
+
* Iframe内嵌方式打开
|
|
33
|
+
*/
|
|
34
|
+
"Iframe" = "Iframe"
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 应用信息
|
|
38
|
+
*/
|
|
39
|
+
export interface AppInfo {
|
|
40
|
+
/**
|
|
41
|
+
* 主键
|
|
42
|
+
*/
|
|
43
|
+
Id: string;
|
|
44
|
+
/**
|
|
45
|
+
* 名称
|
|
46
|
+
*/
|
|
47
|
+
Name: string;
|
|
48
|
+
/**
|
|
49
|
+
* 唯一编码
|
|
50
|
+
* - 路由前缀地址
|
|
51
|
+
*/
|
|
52
|
+
AppCode: string;
|
|
53
|
+
/**
|
|
54
|
+
* 版本号
|
|
55
|
+
*/
|
|
56
|
+
Version: string;
|
|
57
|
+
/**
|
|
58
|
+
* 图标
|
|
59
|
+
*/
|
|
60
|
+
Icon: string;
|
|
61
|
+
/**
|
|
62
|
+
* 来源: Market | Manual
|
|
63
|
+
*/
|
|
64
|
+
Source: AppSource;
|
|
65
|
+
/**
|
|
66
|
+
* 动作: App | MenuApp | Open | Iframe
|
|
67
|
+
*/
|
|
68
|
+
Action: AppAction;
|
|
69
|
+
/**
|
|
70
|
+
* 应用加载地址
|
|
71
|
+
* - http开头地址
|
|
72
|
+
* - SERVER_HOST配置
|
|
73
|
+
*/
|
|
74
|
+
Host: string;
|
|
75
|
+
/**
|
|
76
|
+
* 默认页面
|
|
77
|
+
*/
|
|
78
|
+
Page?: string;
|
|
79
|
+
/**
|
|
80
|
+
* 默认应用,如没设置,则使用第一个
|
|
81
|
+
*/
|
|
82
|
+
Default?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* 描述
|
|
85
|
+
*/
|
|
86
|
+
Description?: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 启用状态
|
|
90
|
+
* - 启用 true 1
|
|
91
|
+
* - 停用 false 0
|
|
92
|
+
*/
|
|
93
|
+
Enabled: boolean | number;
|
|
94
|
+
[key: string]: any;
|
|
95
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 启动配置信息
|
|
3
|
+
* - 网站配置信息
|
|
4
|
+
* - 前端初始配置
|
|
5
|
+
*/
|
|
6
|
+
export interface HostInfo {
|
|
7
|
+
/**
|
|
8
|
+
* 网站地址,配置码
|
|
9
|
+
*/
|
|
10
|
+
Host: string;
|
|
11
|
+
/**
|
|
12
|
+
* 短名称
|
|
13
|
+
*/
|
|
14
|
+
Title: string;
|
|
15
|
+
/**
|
|
16
|
+
* 网站全名称
|
|
17
|
+
*/
|
|
18
|
+
FullTitle?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Logo图标地址
|
|
21
|
+
*/
|
|
22
|
+
LogoIcon?: string;
|
|
23
|
+
/**
|
|
24
|
+
* 登录页面地址
|
|
25
|
+
*/
|
|
26
|
+
LoginUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 用户信息页面地址
|
|
29
|
+
*/
|
|
30
|
+
UserSettingUrl?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 服务商名称
|
|
33
|
+
*/
|
|
34
|
+
Provider?: string;
|
|
35
|
+
/**
|
|
36
|
+
* 接口域名地址
|
|
37
|
+
*/
|
|
38
|
+
API_HOST?: {
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
} | null;
|
|
41
|
+
/**
|
|
42
|
+
* 网站服务器地址
|
|
43
|
+
*/
|
|
44
|
+
SERVER_HOST?: Record<string, string>;
|
|
45
|
+
/**
|
|
46
|
+
* 扩展属性配置
|
|
47
|
+
*/
|
|
48
|
+
ExtraPropLines?: Record<string, any>[];
|
|
49
|
+
/**
|
|
50
|
+
* 扩展属性
|
|
51
|
+
*/
|
|
52
|
+
ExtraProps?: {
|
|
53
|
+
[key: string]: string;
|
|
54
|
+
};
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表格行操作区位置
|
|
3
|
+
*/
|
|
4
|
+
export enum RowOperate {
|
|
5
|
+
LEFT = 1,
|
|
6
|
+
RIGHT = 2
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 前端个性化配置
|
|
10
|
+
*/
|
|
11
|
+
export interface SettingInfo {
|
|
12
|
+
/**
|
|
13
|
+
* 全屏显示
|
|
14
|
+
*/
|
|
15
|
+
readonly fullscreen: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* 主菜单区折叠
|
|
18
|
+
*/
|
|
19
|
+
readonly menuCollapse: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 表格行操作区位置
|
|
22
|
+
*/
|
|
23
|
+
readonly rowOperate: RowOperate;
|
|
24
|
+
/**
|
|
25
|
+
* 使用语言
|
|
26
|
+
*/
|
|
27
|
+
readonly language?: string;
|
|
28
|
+
/**
|
|
29
|
+
* 主题模式
|
|
30
|
+
*/
|
|
31
|
+
readonly theme?: string;
|
|
32
|
+
/**
|
|
33
|
+
* 主题颜色
|
|
34
|
+
*/
|
|
35
|
+
readonly themeColor?: string;
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用户信息
|
|
3
|
+
*/
|
|
4
|
+
export interface UserInfo {
|
|
5
|
+
/**
|
|
6
|
+
* 主键
|
|
7
|
+
*/
|
|
8
|
+
Id: string;
|
|
9
|
+
/**
|
|
10
|
+
* 名称
|
|
11
|
+
*/
|
|
12
|
+
Name: string;
|
|
13
|
+
/**
|
|
14
|
+
* 用户码
|
|
15
|
+
*/
|
|
16
|
+
Code: string;
|
|
17
|
+
/**
|
|
18
|
+
* 角色
|
|
19
|
+
*/
|
|
20
|
+
Roles: string[];
|
|
21
|
+
/**
|
|
22
|
+
* 权限
|
|
23
|
+
*/
|
|
24
|
+
Permissions: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 登录信息与授权
|
|
29
|
+
*/
|
|
30
|
+
export interface LoginInfo {
|
|
31
|
+
/**
|
|
32
|
+
* 用户名
|
|
33
|
+
*/
|
|
34
|
+
UserName: string;
|
|
35
|
+
/**
|
|
36
|
+
* 密码
|
|
37
|
+
*/
|
|
38
|
+
UserPass: string;
|
|
39
|
+
/**
|
|
40
|
+
* 登录返回的用户信息
|
|
41
|
+
*/
|
|
42
|
+
UserInfo?: UserInfo;
|
|
43
|
+
/**
|
|
44
|
+
* 登录获取的授权token
|
|
45
|
+
*/
|
|
46
|
+
token?: string;
|
|
47
|
+
/**
|
|
48
|
+
* 登录获取的刷新token
|
|
49
|
+
*/
|
|
50
|
+
refreshToken?: string;
|
|
51
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QOD数据处理方法
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ReqParams } from "@skyfox2000/fapi";
|
|
6
|
+
|
|
7
|
+
const mergeDeep = (
|
|
8
|
+
target?: Record<string, any>,
|
|
9
|
+
source?: Record<string, any>
|
|
10
|
+
) => {
|
|
11
|
+
if (!source || !target) return;
|
|
12
|
+
for (const key in source) {
|
|
13
|
+
if (
|
|
14
|
+
key in target &&
|
|
15
|
+
typeof target[key] === "object" &&
|
|
16
|
+
typeof source[key] === "object" &&
|
|
17
|
+
!Array.isArray(source[key])
|
|
18
|
+
) {
|
|
19
|
+
mergeDeep(target[key], source[key]);
|
|
20
|
+
} else {
|
|
21
|
+
target[key] = deepClone(source[key]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// 深拷贝函数,用于创建对象的深拷贝
|
|
27
|
+
const deepClone = (obj: any) => {
|
|
28
|
+
if (obj === null || typeof obj !== "object") {
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
let cloneObj: any = Array.isArray(obj) ? [] : {};
|
|
32
|
+
for (let key in obj) {
|
|
33
|
+
if (obj.hasOwnProperty(key)) {
|
|
34
|
+
cloneObj[key] = deepClone(obj[key]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return cloneObj;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 深度合并QOD参数
|
|
42
|
+
*/
|
|
43
|
+
export const combineParams = (...args: ReqParams[]): ReqParams => {
|
|
44
|
+
const mergedParams: ReqParams = {};
|
|
45
|
+
|
|
46
|
+
// 合并选项对象
|
|
47
|
+
for (const params of args) {
|
|
48
|
+
if (params?.Option && !mergedParams.Option) mergedParams.Option = {};
|
|
49
|
+
mergeDeep(mergedParams.Option, params?.Option);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 合并查询对象
|
|
53
|
+
for (const params of args) {
|
|
54
|
+
if (params?.Query && !mergedParams.Query) mergedParams.Query = {};
|
|
55
|
+
mergeDeep(mergedParams.Query, params?.Query);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 合并数据对象
|
|
59
|
+
for (const params of args) {
|
|
60
|
+
mergedParams.Data = params?.Data ? deepClone(params.Data) : {};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return mergedParams;
|
|
64
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { HostInfo } from "@/stores/hostInfo";
|
|
2
|
+
import { SettingInfo } from "@/stores/settingInfo";
|
|
3
|
+
import { LoginInfo, UserInfo } from "@/stores/userInfo";
|
|
4
|
+
import { ApiResponse } from "@skyfox2000/fapi";
|
|
5
|
+
import { ref } from "vue";
|
|
6
|
+
/**
|
|
7
|
+
* 是否微服务运行环境
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export const isMicroApp = (): boolean => {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
if (window.__MICRO_APP_ENVIRONMENT__) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 是否微服务基座应用
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export const isBaseMicroApp = (): boolean => {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
if (window.__MICRO_APP_BASE_APPLICATION__) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 主应用初始化数据格式
|
|
32
|
+
*/
|
|
33
|
+
export interface MainAppData {
|
|
34
|
+
/**
|
|
35
|
+
* 主应用开放接口
|
|
36
|
+
*/
|
|
37
|
+
MainApis: MainOpenApis;
|
|
38
|
+
/**
|
|
39
|
+
* 主应用开放事件
|
|
40
|
+
*/
|
|
41
|
+
MainEvents: MainOpenEvents;
|
|
42
|
+
/**
|
|
43
|
+
* 加载的页面地址
|
|
44
|
+
*/
|
|
45
|
+
pageUrl: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 主应用开放接口
|
|
50
|
+
*/
|
|
51
|
+
export interface MainOpenApis {
|
|
52
|
+
/**
|
|
53
|
+
* 获取HostInfo
|
|
54
|
+
*/
|
|
55
|
+
getHostInfo: () => HostInfo;
|
|
56
|
+
/**
|
|
57
|
+
* 用户注册接口
|
|
58
|
+
*/
|
|
59
|
+
userRegister?: () => void;
|
|
60
|
+
/**
|
|
61
|
+
* 用户登录接口
|
|
62
|
+
*/
|
|
63
|
+
userLogin?: (loginInfo: LoginInfo) => Promise<ApiResponse<LoginInfo> | void>;
|
|
64
|
+
/**
|
|
65
|
+
* 获取授权码
|
|
66
|
+
* @returns 授权码
|
|
67
|
+
*/
|
|
68
|
+
getToken: () => string;
|
|
69
|
+
/**
|
|
70
|
+
* 获取当前用户信息
|
|
71
|
+
*/
|
|
72
|
+
getUserInfo: () => UserInfo;
|
|
73
|
+
/**
|
|
74
|
+
* 获取前端设置信息
|
|
75
|
+
*/
|
|
76
|
+
getSettingInfo?: () => SettingInfo;
|
|
77
|
+
/**
|
|
78
|
+
* 子应用推送路由变更
|
|
79
|
+
*/
|
|
80
|
+
mainAppPush?: (subPath: string) => void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 主应用开放事件注册
|
|
84
|
+
*/
|
|
85
|
+
export interface MainOpenEvents {
|
|
86
|
+
/**
|
|
87
|
+
* 前端设置信息变更
|
|
88
|
+
*/
|
|
89
|
+
onSettingChanged?: () => void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const mainAppApis = ref<MainOpenApis | undefined>();
|
|
93
|
+
export const mainAppEvents = ref<MainOpenEvents | undefined>();
|
|
94
|
+
export const mainPageUrl = ref<string | undefined>();
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 从页面加载处获取接口
|
|
98
|
+
*/
|
|
99
|
+
export const initMainAppData = () => {
|
|
100
|
+
const mainAppData: MainAppData = window.microApp.getData(
|
|
101
|
+
true
|
|
102
|
+
) as unknown as MainAppData;
|
|
103
|
+
mainAppApis.value = mainAppData.MainApis;
|
|
104
|
+
mainAppEvents.value = mainAppData.MainEvents;
|
|
105
|
+
mainPageUrl.value = mainAppData.pageUrl;
|
|
106
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
//解决ts文件引入vue文件出现红色警告问题
|
|
3
|
+
declare module "*.vue" {
|
|
4
|
+
import { defineComponent } from "vue";
|
|
5
|
+
const Component: ReturnType<typeof defineComponent>;
|
|
6
|
+
export default Component;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
import { EventCenterForMicroApp } from "@micro-zoe/micro-app";
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
microApp: EventCenterForMicroApp;
|
|
13
|
+
}
|
|
14
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"emitDeclarationOnly": false,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"target": "ESNext",
|
|
8
|
+
"useDefineForClassFields": true,
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"removeComments": false,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
|
|
15
|
+
"composite": true,
|
|
16
|
+
"allowSyntheticDefaultImports": true,
|
|
17
|
+
|
|
18
|
+
/* Bundler mode */
|
|
19
|
+
"moduleResolution": "Bundler",
|
|
20
|
+
"resolveJsonModule": true,
|
|
21
|
+
"isolatedModules": true,
|
|
22
|
+
"noEmit": false,
|
|
23
|
+
"jsx": "preserve",
|
|
24
|
+
|
|
25
|
+
/* Linting */
|
|
26
|
+
"strict": true,
|
|
27
|
+
"noUnusedLocals": true,
|
|
28
|
+
"noUnusedParameters": true,
|
|
29
|
+
"noFallthroughCasesInSwitch": true,
|
|
30
|
+
"baseUrl": "./", // 解析非相对模块的基地址,默认是当前目录
|
|
31
|
+
"paths": {
|
|
32
|
+
//路径映射,相对于baseUrl
|
|
33
|
+
"@/*": ["src/*"],
|
|
34
|
+
},
|
|
35
|
+
"typeRoots" : ["./node_modules/@types"],
|
|
36
|
+
"rootDir": "src",
|
|
37
|
+
"outDir": "lib",
|
|
38
|
+
},
|
|
39
|
+
"include": ["src/**/**.ts", "src/**/**.d.ts", "src/**/**.vue"],
|
|
40
|
+
"exclude": ["node_modules"]
|
|
41
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ConfigEnv, defineConfig, loadEnv } from "vite";
|
|
2
|
+
import vue from "@vitejs/plugin-vue";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import dts from "vite-plugin-dts";
|
|
5
|
+
|
|
6
|
+
// https://vitejs.dev/config/
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
export default defineConfig(({ mode }: ConfigEnv) => {
|
|
9
|
+
const root = process.cwd();
|
|
10
|
+
const env = loadEnv(mode, root);
|
|
11
|
+
console.log(env);
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
plugins: [
|
|
15
|
+
vue({
|
|
16
|
+
template: {
|
|
17
|
+
compilerOptions: {
|
|
18
|
+
isCustomElement: (tag) => /^micro-app/.test(tag)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
dts({
|
|
23
|
+
outDir: "lib",
|
|
24
|
+
insertTypesEntry: true,
|
|
25
|
+
rollupTypes: true,
|
|
26
|
+
copyDtsFiles: true
|
|
27
|
+
})
|
|
28
|
+
],
|
|
29
|
+
resolve: {
|
|
30
|
+
alias: {
|
|
31
|
+
"@": path.resolve("./src")
|
|
32
|
+
},
|
|
33
|
+
extensions: [".js", ".ts", ".vue", "json", ".png"]
|
|
34
|
+
},
|
|
35
|
+
build: {
|
|
36
|
+
outDir: "lib",
|
|
37
|
+
assetsDir: "assets",
|
|
38
|
+
lib: {
|
|
39
|
+
entry: "src/index.ts", // 指定入口文件
|
|
40
|
+
fileName: (format) => `microbase.${format}.js` // 输出文件名模板
|
|
41
|
+
},
|
|
42
|
+
rollupOptions: {
|
|
43
|
+
// 外部化处理那些你并不打算打包进库的依赖
|
|
44
|
+
external: [
|
|
45
|
+
"vue",
|
|
46
|
+
"@micro-zoe/micro-app",
|
|
47
|
+
"@skyfox2000/fapi",
|
|
48
|
+
"vue-router"
|
|
49
|
+
],
|
|
50
|
+
// 如果你使用 TypeScript,则需要提供类型声明文件的输出路径
|
|
51
|
+
output: [
|
|
52
|
+
{
|
|
53
|
+
globals: {}, // 这里指定 crypto-js 的全局变量名为 CryptoJS
|
|
54
|
+
extend: false,
|
|
55
|
+
// 提供多个模块格式
|
|
56
|
+
format: "es",
|
|
57
|
+
chunkFileNames: "assets/modules/[name]-[hash].js",
|
|
58
|
+
assetFileNames: (assetInfo) => {
|
|
59
|
+
if (assetInfo.name!.endsWith(".css")) {
|
|
60
|
+
return "assets/css/[name].css";
|
|
61
|
+
}
|
|
62
|
+
return `assets/[ext]/[name]-[hash].[ext]`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
minify: true, // 开启压缩
|
|
68
|
+
sourcemap: false
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
});
|