jmash-core-mp 0.1.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/.editorconfig +9 -0
- package/README.md +49 -0
- package/babel.config.json +34 -0
- package/eslint.config.mjs +7 -0
- package/mpx.config.js +27 -0
- package/package.json +69 -0
- package/postcss.config.js +11 -0
- package/project.config.json +25 -0
- package/project.private.config.json +14 -0
- package/public/index.html +15 -0
- package/src/api/auth/index.ts +166 -0
- package/src/api/auth/types.ts +115 -0
- package/src/api/cms/index.ts +58 -0
- package/src/api/cms/types.ts +137 -0
- package/src/api/constant.ts +6 -0
- package/src/api/dict/index.ts +44 -0
- package/src/api/dict/types.ts +50 -0
- package/src/api/dicts.ts +72 -0
- package/src/api/files/index.ts +177 -0
- package/src/api/files/types.ts +68 -0
- package/src/api/index.ts +11 -0
- package/src/api/myorgan/index.ts +0 -0
- package/src/api/myorgan/types.ts +43 -0
- package/src/app.mpx +62 -0
- package/src/components/auth-user/jmash-update-user/index.mpx +31 -0
- package/src/components/auth-user/jmash-user.mpx +119 -0
- package/src/components/common/auth-avatar/avatar-edit/index.mpx +31 -0
- package/src/components/common/auth-search/index.mpx +31 -0
- package/src/components/common/jmash-tab-bar.mpx +50 -0
- package/src/components/core/jmash-cms-protocol.mpx +67 -0
- package/src/components/core/jmash-login.mpx +343 -0
- package/src/components/core/jmash-popup-login.mpx +414 -0
- package/src/custom-tab-bar/index.mpx +11 -0
- package/src/global.d.ts +4 -0
- package/src/index.ts +9 -0
- package/src/packages/index.mpx +8 -0
- package/src/packages/pages/auth/cms-protocol.mpx +31 -0
- package/src/packages/pages/auth/login.mpx +53 -0
- package/src/pages/basic-component.mpx +31 -0
- package/src/pages/half-home.mpx +58 -0
- package/src/pages/home.mpx +38 -0
- package/src/pages/index.mpx +45 -0
- package/src/pages/tabbar/home.mpx +69 -0
- package/src/pages/tabbar/my.mpx +40 -0
- package/src/stores/setup.js +15 -0
- package/src/styles/index.scss +27 -0
- package/src/types/core.ts +41 -0
- package/src/utils/auth.ts +270 -0
- package/src/utils/config.ts +31 -0
- package/src/utils/db.ts +100 -0
- package/src/utils/grpc.ts +21 -0
- package/src/utils/request.ts +123 -0
- package/static/ali/mini.project.json +4 -0
- package/static/dd/project.config.json +15 -0
- package/static/swan/project.swan.json +14 -0
- package/static/tt/project.config.json +11 -0
- package/static/wx/project.config.json +41 -0
- package/uno.config.js +9 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { TokenModel } from "../api/auth/types";
|
|
2
|
+
|
|
3
|
+
import { db } from "../utils/db";
|
|
4
|
+
import { grpc } from "../utils/grpc";
|
|
5
|
+
|
|
6
|
+
import mpx from "@mpxjs/core";
|
|
7
|
+
import mpxFetch from "@mpxjs/fetch";
|
|
8
|
+
mpx.use(mpxFetch);
|
|
9
|
+
|
|
10
|
+
import { config as appconfig } from "../utils/config";
|
|
11
|
+
|
|
12
|
+
let isRefreshing = false;
|
|
13
|
+
type TokenCallBackFunc = (token: string) => void;
|
|
14
|
+
let requests: TokenCallBackFunc[] = [];
|
|
15
|
+
//是否登出.
|
|
16
|
+
let isLogout = false;
|
|
17
|
+
|
|
18
|
+
mpx.xfetch.interceptors.request.use(function (config) {
|
|
19
|
+
if (!config.url.startsWith("http")) {
|
|
20
|
+
config.url = appconfig.baseUrl + config.url;
|
|
21
|
+
}
|
|
22
|
+
console.log(config);
|
|
23
|
+
|
|
24
|
+
// Grpc Gateway 清理默认值,Enum,时间等不能空;
|
|
25
|
+
grpc.clearEmpty(config.params);
|
|
26
|
+
grpc.clearEmpty(config.data);
|
|
27
|
+
if (!config.header) {
|
|
28
|
+
config.header = {};
|
|
29
|
+
}
|
|
30
|
+
//配置其他认证请求头信息
|
|
31
|
+
if (config.header.Authorization && config.header.Authorization === false) {
|
|
32
|
+
delete config.header.Authorization;
|
|
33
|
+
return config;
|
|
34
|
+
}
|
|
35
|
+
const auth = config.header.Authorization
|
|
36
|
+
? (config.header.Authorization as string)
|
|
37
|
+
: "";
|
|
38
|
+
if (auth && auth.length > 0 && !auth.startsWith("Bearer ")) {
|
|
39
|
+
return config;
|
|
40
|
+
}
|
|
41
|
+
// 请求设置token和租户
|
|
42
|
+
const expire = db.isTokenExpires();
|
|
43
|
+
console.log("expire", expire);
|
|
44
|
+
if (!expire) {
|
|
45
|
+
config.header["Authorization"] = "Bearer " + db.getToken();
|
|
46
|
+
const organTenant = db.getOrganTenant(config.tenant);
|
|
47
|
+
if (organTenant && config.header.GrpcMetadataTenant !== false) {
|
|
48
|
+
config.header["Grpc-Metadata-Tenant"] = organTenant;
|
|
49
|
+
} else {
|
|
50
|
+
delete config.header["Grpc-Metadata-Tenant"];
|
|
51
|
+
}
|
|
52
|
+
console.log(config);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const isRefreshToken = config.url.endsWith("/v1/rbac/auth/refresh_token");
|
|
56
|
+
//Token已过期或即将过期.
|
|
57
|
+
if (!isRefreshToken && expire) {
|
|
58
|
+
if (!isRefreshing) {
|
|
59
|
+
isRefreshing = true;
|
|
60
|
+
// 刷新token
|
|
61
|
+
refreshToken(db.getRefreshToken())
|
|
62
|
+
.then((res) => {
|
|
63
|
+
// token 刷新后将数组的方法重新执行
|
|
64
|
+
db.setToken(res.data);
|
|
65
|
+
requests.forEach((cb) => cb(res.data.accessToken));
|
|
66
|
+
requests = []; // 刷新完清空
|
|
67
|
+
})
|
|
68
|
+
.catch(() => {
|
|
69
|
+
db.clearStorage();
|
|
70
|
+
})
|
|
71
|
+
.finally(() => {
|
|
72
|
+
isRefreshing = false;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const retry = new Promise<any>((resolve) => {
|
|
76
|
+
/* (token) => {...}这个函数就是回调函数*/
|
|
77
|
+
requests.push((token) => {
|
|
78
|
+
config.header.Authorization = "Bearer " + token;
|
|
79
|
+
resolve(config);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return retry;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 也可以返回promise
|
|
86
|
+
return config;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
mpx.xfetch.interceptors.response.use(function (res) {
|
|
90
|
+
console.log(res);
|
|
91
|
+
if (res.statusCode === 200) {
|
|
92
|
+
return res;
|
|
93
|
+
} else if (res.statusCode === 401) {
|
|
94
|
+
// token 过期,重新登录
|
|
95
|
+
if (!isLogout) {
|
|
96
|
+
isLogout = true;
|
|
97
|
+
mpx.showToast({
|
|
98
|
+
title: "当前页面已失效,请重新登录",
|
|
99
|
+
icon: "none",
|
|
100
|
+
});
|
|
101
|
+
db.clearStorage();
|
|
102
|
+
isLogout = false;
|
|
103
|
+
}
|
|
104
|
+
return Promise.reject(res);
|
|
105
|
+
}
|
|
106
|
+
// 也可以返回promise
|
|
107
|
+
return res;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
//刷新Token
|
|
111
|
+
function refreshToken(refreshToken: string) {
|
|
112
|
+
return mpx.xfetch.fetch<TokenModel>({
|
|
113
|
+
url: appconfig.baseUrl + "/v1/front/rbac/auth/refresh_token",
|
|
114
|
+
method: "POST",
|
|
115
|
+
data: {
|
|
116
|
+
data: { refreshToken: refreshToken },
|
|
117
|
+
tenant: appconfig.tenant,
|
|
118
|
+
clientId: appconfig.appId,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { mpxFetch };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"setting": {
|
|
3
|
+
"newFeature": true,
|
|
4
|
+
"urlCheck": true,
|
|
5
|
+
"es6": false,
|
|
6
|
+
"postcss": false,
|
|
7
|
+
"minified": false,
|
|
8
|
+
"checkSiteMap": false,
|
|
9
|
+
"autoAudits": false
|
|
10
|
+
},
|
|
11
|
+
"appid": "wx2a8b3d689b8959eb",
|
|
12
|
+
"projectname": "jmash-core-mp",
|
|
13
|
+
"description": "Jmash Core MPX小程序",
|
|
14
|
+
"condition": {}
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"setting": {
|
|
3
|
+
"newFeature": true,
|
|
4
|
+
"urlCheck": true,
|
|
5
|
+
"es6": false,
|
|
6
|
+
"postcss": true,
|
|
7
|
+
"minified": false,
|
|
8
|
+
"checkSiteMap": false,
|
|
9
|
+
"autoAudits": false,
|
|
10
|
+
"compileWorklet": false,
|
|
11
|
+
"uglifyFileName": false,
|
|
12
|
+
"uploadWithSourceMap": true,
|
|
13
|
+
"enhance": false,
|
|
14
|
+
"packNpmManually": false,
|
|
15
|
+
"packNpmRelationList": [],
|
|
16
|
+
"minifyWXSS": true,
|
|
17
|
+
"minifyWXML": true,
|
|
18
|
+
"localPlugins": false,
|
|
19
|
+
"disableUseStrict": false,
|
|
20
|
+
"useCompilerPlugins": false,
|
|
21
|
+
"condition": false,
|
|
22
|
+
"swc": false,
|
|
23
|
+
"disableSWC": true,
|
|
24
|
+
"babelSetting": {
|
|
25
|
+
"ignore": [],
|
|
26
|
+
"disablePlugins": [],
|
|
27
|
+
"outputPath": ""
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"appid": "wx2a8b3d689b8959eb",
|
|
31
|
+
"projectname": "jmash-core-mp",
|
|
32
|
+
"description": "Jmash Core MPX小程序",
|
|
33
|
+
"condition": {},
|
|
34
|
+
"compileType": "miniprogram",
|
|
35
|
+
"simulatorPluginLibVersion": {},
|
|
36
|
+
"packOptions": {
|
|
37
|
+
"ignore": [],
|
|
38
|
+
"include": []
|
|
39
|
+
},
|
|
40
|
+
"editorSetting": {}
|
|
41
|
+
}
|