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,69 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="page-body">
|
|
3
|
+
<button type="default" bind:tap="toHomePage">主页(全屏登录)</button>
|
|
4
|
+
<button type="default" bind:tap="toHalfHomePage">主页(半屏登录)</button>
|
|
5
|
+
<button type="default" bind:tap="toCompTestPage">组件演示</button>
|
|
6
|
+
<button type="default" bind:tap="loginOut">退出</button>
|
|
7
|
+
</view>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
import mpx, { createPage } from '@mpxjs/core'
|
|
12
|
+
import { auth } from '../../utils/auth'
|
|
13
|
+
|
|
14
|
+
createPage({
|
|
15
|
+
onShow() {
|
|
16
|
+
console.log(this.getTabBar);
|
|
17
|
+
if (typeof this.getTabBar === 'function' &&
|
|
18
|
+
this.getTabBar()) {
|
|
19
|
+
console.log(this.getTabBar().$refs.tabBar.activeTab("Home"));
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
methods: {
|
|
23
|
+
toHomePage() {
|
|
24
|
+
mpx.navigateTo({
|
|
25
|
+
url: '/pages/home'
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
toHalfHomePage() {
|
|
29
|
+
mpx.navigateTo({
|
|
30
|
+
url: '/pages/half-home'
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
toCompTestPage() {
|
|
34
|
+
mpx.navigateTo({
|
|
35
|
+
url: '/pages/basic-component'
|
|
36
|
+
})
|
|
37
|
+
},
|
|
38
|
+
loginOut() {
|
|
39
|
+
auth.loginOut();
|
|
40
|
+
mpx.showToast({
|
|
41
|
+
title: '已退出登录',
|
|
42
|
+
icon: 'success'
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<style lang="scss">
|
|
50
|
+
.page-body {
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
align-items: center;
|
|
54
|
+
padding: 40rpx;
|
|
55
|
+
gap: 30rpx;
|
|
56
|
+
|
|
57
|
+
button {
|
|
58
|
+
width: 80%;
|
|
59
|
+
height: 80rpx;
|
|
60
|
+
font-size: 32rpx;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
</style>
|
|
64
|
+
|
|
65
|
+
<script type="application/json">
|
|
66
|
+
{
|
|
67
|
+
"usingComponents": {}
|
|
68
|
+
}
|
|
69
|
+
</script>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="basic-component-page">
|
|
3
|
+
<jmash-user></jmash-user>
|
|
4
|
+
<text>{{ title }}</text>
|
|
5
|
+
</view>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script>
|
|
9
|
+
import { createPage } from '@mpxjs/core'
|
|
10
|
+
|
|
11
|
+
createPage({
|
|
12
|
+
data: {
|
|
13
|
+
title: 'MY',
|
|
14
|
+
},
|
|
15
|
+
onShow() {
|
|
16
|
+
console.log(this.getTabBar);
|
|
17
|
+
if (typeof this.getTabBar === 'function' &&
|
|
18
|
+
this.getTabBar()) {
|
|
19
|
+
console.log(this.getTabBar().$refs.tabBar.activeTab("My"));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<style lang="scss">
|
|
26
|
+
.basic-component-page {
|
|
27
|
+
padding: 40rpx;
|
|
28
|
+
text-align: center;
|
|
29
|
+
font-size: 32rpx;
|
|
30
|
+
color: #333;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
33
|
+
|
|
34
|
+
<script type="application/json">
|
|
35
|
+
{
|
|
36
|
+
"usingComponents": {
|
|
37
|
+
"jmash-user": "../../components/auth-user/jmash-user.mpx"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// setup.js
|
|
2
|
+
import { defineStore } from "@mpxjs/pinia";
|
|
3
|
+
import { ref, computed } from "@mpxjs/core";
|
|
4
|
+
|
|
5
|
+
export const useSetupStore = defineStore("setup", () => {
|
|
6
|
+
const count = ref(0);
|
|
7
|
+
const name = ref("pinia");
|
|
8
|
+
const myName = computed(() => {
|
|
9
|
+
return name.value;
|
|
10
|
+
});
|
|
11
|
+
function increment() {
|
|
12
|
+
count.value++;
|
|
13
|
+
}
|
|
14
|
+
return { count, name, myName, increment };
|
|
15
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// 圆角
|
|
2
|
+
$border-radius: 20rpx;
|
|
3
|
+
$border-mini-radius: 10rpx;
|
|
4
|
+
$border-max-radius: 50rpx;
|
|
5
|
+
// 字体大小
|
|
6
|
+
$font-size: 28rpx;
|
|
7
|
+
$font-size-mini: 24rpx;
|
|
8
|
+
// 颜色
|
|
9
|
+
$white-color: #fff;
|
|
10
|
+
$red-color: #EF4444;
|
|
11
|
+
$green-color: #16A34A;
|
|
12
|
+
$blue-color: #2563EB;
|
|
13
|
+
$black-color: #000;
|
|
14
|
+
// 字体颜色
|
|
15
|
+
$font-color: #333;
|
|
16
|
+
$font-color-grey: #666;
|
|
17
|
+
$font-color-grey-opacity: #999;
|
|
18
|
+
// 宽
|
|
19
|
+
$width: 100%;
|
|
20
|
+
// 层级
|
|
21
|
+
$z-index: 99999;
|
|
22
|
+
// 下拉线颜色
|
|
23
|
+
$border-line: #EBEBEB;
|
|
24
|
+
// 背景色
|
|
25
|
+
$background-color: #f6f6f6;
|
|
26
|
+
// 白色背景
|
|
27
|
+
$background-white-color: #fff;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type ResponseData<
|
|
2
|
+
T extends string | WechatMiniprogram.IAnyObject | ArrayBuffer =
|
|
3
|
+
| string
|
|
4
|
+
| WechatMiniprogram.IAnyObject
|
|
5
|
+
| ArrayBuffer
|
|
6
|
+
> = WechatMiniprogram.RequestSuccessCallbackResult<T>;
|
|
7
|
+
|
|
8
|
+
export interface AppConfig {
|
|
9
|
+
//租户
|
|
10
|
+
tenant: string;
|
|
11
|
+
// 名称
|
|
12
|
+
name: string;
|
|
13
|
+
//请求地址
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
//静态资源地址
|
|
16
|
+
resourceUrl: string;
|
|
17
|
+
// 小程序appid
|
|
18
|
+
appId: string;
|
|
19
|
+
// 三方平台id
|
|
20
|
+
componentAppid: string;
|
|
21
|
+
// 微信公众号APP_ID
|
|
22
|
+
wechatComponentAppId: string;
|
|
23
|
+
// 微信三方授权appId
|
|
24
|
+
wechatAppId: string;
|
|
25
|
+
// 微信公众号Biz
|
|
26
|
+
wechatBiz: string;
|
|
27
|
+
//站点ID.
|
|
28
|
+
siteId: string;
|
|
29
|
+
//是否开发环境.
|
|
30
|
+
dev: boolean;
|
|
31
|
+
//是否测试新用户.
|
|
32
|
+
testNewUser: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 校验
|
|
36
|
+
export interface ValidateData {
|
|
37
|
+
// 是否校验通过
|
|
38
|
+
validate: boolean;
|
|
39
|
+
// 校验失败提示信息.
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { config } from "./config";
|
|
2
|
+
import { db } from "./db";
|
|
3
|
+
import { authApi } from "../api/auth/index";
|
|
4
|
+
import {
|
|
5
|
+
LoginReq,
|
|
6
|
+
LoginRes,
|
|
7
|
+
RolesPerms,
|
|
8
|
+
TokenModel,
|
|
9
|
+
UserInfo,
|
|
10
|
+
} from "../api/auth/types";
|
|
11
|
+
import { ResponseData } from "../types/core";
|
|
12
|
+
import mpx from "@mpxjs/core";
|
|
13
|
+
|
|
14
|
+
// 认证
|
|
15
|
+
class Auth {
|
|
16
|
+
/** 登录检查 */
|
|
17
|
+
loginOnlyAC(): Promise<boolean> {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
// 已登录成功
|
|
20
|
+
if (this.checkLogin()) {
|
|
21
|
+
resolve(true);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (config.dev && config.testNewUser) {
|
|
25
|
+
reject(false);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// 静默登录
|
|
29
|
+
this.silentLogin().then((res) => {
|
|
30
|
+
if (res.status) {
|
|
31
|
+
resolve(true);
|
|
32
|
+
} else {
|
|
33
|
+
reject(false);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 登录检查并跳转登录 */
|
|
40
|
+
loginAC(
|
|
41
|
+
backurl: string,
|
|
42
|
+
tabbar: boolean,
|
|
43
|
+
loginurl: string = "/jmash/pages/auth/login"
|
|
44
|
+
): Promise<boolean> {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
// 已登录成功
|
|
47
|
+
if (this.checkLogin()) {
|
|
48
|
+
resolve(true);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let toUrl = loginurl + "?tabbar=" + (tabbar ? "true" : "false");
|
|
53
|
+
toUrl += "&backurl=" + encodeURIComponent(backurl);
|
|
54
|
+
|
|
55
|
+
if (config.dev && config.testNewUser) {
|
|
56
|
+
reject(false);
|
|
57
|
+
// 去登录
|
|
58
|
+
mpx.navigateTo({ url: toUrl });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// 静默登录
|
|
62
|
+
this.silentLogin().then((res) => {
|
|
63
|
+
if (res.status) {
|
|
64
|
+
resolve(true);
|
|
65
|
+
} else {
|
|
66
|
+
reject(false);
|
|
67
|
+
// 去登录
|
|
68
|
+
mpx.navigateTo({ url: toUrl });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 检查登录是否有效? */
|
|
75
|
+
checkLogin(): boolean {
|
|
76
|
+
if (db.getToken() && !db.isTokenExpires()) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 判断是否存在有效用户.
|
|
83
|
+
async hasUser() {
|
|
84
|
+
// 如果用户未登录,则尝试静默登录
|
|
85
|
+
const isLoggedIn = auth.checkLogin();
|
|
86
|
+
if (!isLoggedIn) {
|
|
87
|
+
// 返回一个Promise,使得调用者可以使用.then或await处理异步结果
|
|
88
|
+
return auth
|
|
89
|
+
.silentLogin()
|
|
90
|
+
.then((res) => {
|
|
91
|
+
console.log("静默登录--------", res);
|
|
92
|
+
// 静默登录失败时返回false
|
|
93
|
+
if (!res.status) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
// 静默登录成功时返回true
|
|
97
|
+
return true;
|
|
98
|
+
})
|
|
99
|
+
.catch((err) => {
|
|
100
|
+
// 捕获并处理任何错误,然后返回false
|
|
101
|
+
console.error("Silent login failed:", err);
|
|
102
|
+
return false;
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
// 用户已经登录,直接返回true
|
|
106
|
+
return Promise.resolve(true);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 检查角色
|
|
111
|
+
checkRole(role: string): boolean {
|
|
112
|
+
// 获取roleCodes
|
|
113
|
+
const roleCodes: Array<string> = db.getRoleCodes();
|
|
114
|
+
return roleCodes.length > 0 && roleCodes.indexOf(role) !== -1;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** 静默登录 */
|
|
118
|
+
silentLogin(): Promise<LoginRes> {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
try {
|
|
121
|
+
mpx.login({
|
|
122
|
+
success: (res) => {
|
|
123
|
+
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
124
|
+
if (res.code) {
|
|
125
|
+
authApi
|
|
126
|
+
.miniappLogin({
|
|
127
|
+
loginCode: res.code,
|
|
128
|
+
appId: config.appId,
|
|
129
|
+
componentAppid: config.componentAppid,
|
|
130
|
+
} as LoginReq)
|
|
131
|
+
.then((response: ResponseData<LoginRes>) => {
|
|
132
|
+
if (
|
|
133
|
+
response.statusCode === 200 &&
|
|
134
|
+
response.data.status === true
|
|
135
|
+
) {
|
|
136
|
+
db.setToken(response.data.token);
|
|
137
|
+
console.log("login success");
|
|
138
|
+
this.getUserInfo(false);
|
|
139
|
+
this.getRolePerm(false).then(() => {
|
|
140
|
+
resolve(response.data);
|
|
141
|
+
});
|
|
142
|
+
} else if (response.statusCode === 200) {
|
|
143
|
+
resolve(response.data);
|
|
144
|
+
} else {
|
|
145
|
+
reject(response.errMsg);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
fail: (fail) => {
|
|
151
|
+
console.log("登录失败2", fail.errMsg);
|
|
152
|
+
reject(fail.errMsg);
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.log("silentLogin静默登录抛出异常");
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 手机号code 注册登录
|
|
162
|
+
phoneCodeLogin(phoneCode: string, nickName: string = ""): Promise<LoginRes> {
|
|
163
|
+
return new Promise<LoginRes>((resolve, reject) => {
|
|
164
|
+
wx.login({
|
|
165
|
+
success: (res) => {
|
|
166
|
+
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
167
|
+
if (res.code) {
|
|
168
|
+
console.log("phoneCodeLogin-res", res);
|
|
169
|
+
authApi
|
|
170
|
+
.miniappPhoneNumber({
|
|
171
|
+
phoneCode: phoneCode,
|
|
172
|
+
loginCode: res.code,
|
|
173
|
+
appId: config.appId,
|
|
174
|
+
nickName: nickName,
|
|
175
|
+
componentAppid: config.componentAppid,
|
|
176
|
+
})
|
|
177
|
+
.then((resp: ResponseData<LoginRes>) => {
|
|
178
|
+
console.log("phoneCodeLogin-res", resp);
|
|
179
|
+
|
|
180
|
+
if (resp.statusCode === 200 && resp.data.status === true) {
|
|
181
|
+
db.setToken(resp.data.token);
|
|
182
|
+
console.log("login success");
|
|
183
|
+
this.getRolePerm().then(() => {
|
|
184
|
+
resolve(resp.data);
|
|
185
|
+
});
|
|
186
|
+
} else {
|
|
187
|
+
reject(resp.errMsg);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
fail: (fail) => {
|
|
193
|
+
console.log("登录失败3", fail.errMsg);
|
|
194
|
+
reject(fail.errMsg);
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 获取角色
|
|
201
|
+
getRolePerm(cache: boolean = true): Promise<RolesPerms> {
|
|
202
|
+
return new Promise<RolesPerms>((resolve, reject) => {
|
|
203
|
+
const rolesPerms = {
|
|
204
|
+
roleCodes: db.getRoleCodes(),
|
|
205
|
+
permCodes: db.getPermCodes(),
|
|
206
|
+
};
|
|
207
|
+
if (
|
|
208
|
+
cache &&
|
|
209
|
+
(Object.keys(rolesPerms.roleCodes).length > 0 ||
|
|
210
|
+
Object.keys(rolesPerms.permCodes).length > 0)
|
|
211
|
+
) {
|
|
212
|
+
resolve(rolesPerms);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
authApi
|
|
216
|
+
.userRolesPerms()
|
|
217
|
+
.then((response: ResponseData<RolesPerms>) => {
|
|
218
|
+
db.setRoleCodes(response.data.roleCodes);
|
|
219
|
+
db.setPermCodes(response.data.permCodes);
|
|
220
|
+
resolve(response.data);
|
|
221
|
+
})
|
|
222
|
+
.catch(() => {
|
|
223
|
+
reject("获取角色权限错误!");
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 获取用户信息
|
|
229
|
+
getUserInfo(cache: boolean = true): Promise<UserInfo> {
|
|
230
|
+
return new Promise<UserInfo>((resolve, reject) => {
|
|
231
|
+
const userInfo = db.getUserInfo();
|
|
232
|
+
if (cache && Object.keys(userInfo).length > 0) {
|
|
233
|
+
resolve(userInfo);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
authApi
|
|
237
|
+
.userInfo()
|
|
238
|
+
.then((resp: ResponseData<UserInfo>) => {
|
|
239
|
+
db.setUserInfo(resp.data);
|
|
240
|
+
resolve(resp.data);
|
|
241
|
+
})
|
|
242
|
+
.catch(() => {
|
|
243
|
+
reject("获取角色权限错误!");
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// 刷新Token.
|
|
249
|
+
refreshToken(): Promise<boolean> {
|
|
250
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
251
|
+
authApi
|
|
252
|
+
.refreshToken()
|
|
253
|
+
.then((response: ResponseData<TokenModel>) => {
|
|
254
|
+
db.setToken(response.data);
|
|
255
|
+
resolve(true);
|
|
256
|
+
})
|
|
257
|
+
.catch((error) => {
|
|
258
|
+
reject(error);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 登出
|
|
264
|
+
loginOut(): void {
|
|
265
|
+
db.clearStorage();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const auth = new Auth();
|
|
269
|
+
|
|
270
|
+
export { auth };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AppConfig } from "../types/core";
|
|
2
|
+
|
|
3
|
+
const config: AppConfig = {
|
|
4
|
+
name: "Jmash Core MPX",
|
|
5
|
+
dev: true,
|
|
6
|
+
testNewUser: true,
|
|
7
|
+
tenant: "xyvcard",
|
|
8
|
+
baseUrl: "https://mm.sooyie.cn",
|
|
9
|
+
resourceUrl: "https://mm.sooyie.cn/v1/file/path/wxapp",
|
|
10
|
+
appId: "",
|
|
11
|
+
componentAppid: "wxe1b784ea80c01f40",
|
|
12
|
+
wechatComponentAppId: "",
|
|
13
|
+
wechatAppId: "",
|
|
14
|
+
wechatBiz: "",
|
|
15
|
+
siteId: "c0a28f0f-023a-420b-b4e8-0ce138ac8269",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (__mpx_mode__ === "wx") {
|
|
19
|
+
// 微信
|
|
20
|
+
config.appId = "wx2a8b3d689b8959eb";
|
|
21
|
+
} else if (__mpx_mode__ === "ali") {
|
|
22
|
+
// 支付宝
|
|
23
|
+
config.appId = "2016102700684542";
|
|
24
|
+
} else if (__mpx_mode__ === "web") {
|
|
25
|
+
// Web
|
|
26
|
+
config.appId = "web";
|
|
27
|
+
} else {
|
|
28
|
+
// 执行其他环境相关逻辑
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { config };
|
package/src/utils/db.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import mpx from "@mpxjs/core";
|
|
2
|
+
import type { TokenModel, UserInfo } from "../api/auth/types";
|
|
3
|
+
|
|
4
|
+
// 本地存储
|
|
5
|
+
class LocalStorage {
|
|
6
|
+
// 获取token
|
|
7
|
+
getToken(): string {
|
|
8
|
+
return mpx.getStorageSync("token");
|
|
9
|
+
}
|
|
10
|
+
// 用户租户
|
|
11
|
+
getUserTenant(): string {
|
|
12
|
+
return this.getUserInfo().storage as string;
|
|
13
|
+
}
|
|
14
|
+
//获取组织租户
|
|
15
|
+
getOrganTenant(tenant: string): string {
|
|
16
|
+
return mpx.getStorageSync("OrganTenant:" + tenant);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//是否Token过期.
|
|
20
|
+
isTokenExpires(): boolean {
|
|
21
|
+
const expiresDate = this.getTokenExpiresDate();
|
|
22
|
+
if (this.getToken() && expiresDate) {
|
|
23
|
+
const now = new Date().getTime();
|
|
24
|
+
//提前30秒过期.
|
|
25
|
+
return now + 30000 > expiresDate;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 获取刷新token
|
|
31
|
+
getRefreshToken(): string {
|
|
32
|
+
return mpx.getStorageSync("refreshToken");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 删除刷新token
|
|
36
|
+
removeRefreshToken() {
|
|
37
|
+
mpx.removeStorageSync("refreshToken");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 获取Token 过期时间
|
|
41
|
+
getTokenExpiresDate(): number {
|
|
42
|
+
return mpx.getStorageSync("expiresDate");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 设置token
|
|
46
|
+
setToken(data: TokenModel) {
|
|
47
|
+
mpx.setStorageSync("token", data.accessToken);
|
|
48
|
+
mpx.setStorageSync("expiresIn", data.expiresIn);
|
|
49
|
+
mpx.setStorageSync("refreshToken", data.refreshToken);
|
|
50
|
+
const expiresDate = new Date().getTime() + data.expiresIn * 1000;
|
|
51
|
+
mpx.setStorageSync("expiresDate", expiresDate);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 清理本地缓存
|
|
55
|
+
clearStorage(): void {
|
|
56
|
+
mpx.clearStorage();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 获取Bearer 格式请求Token
|
|
60
|
+
getBearerToken(): string {
|
|
61
|
+
const token = this.getToken();
|
|
62
|
+
if (token) {
|
|
63
|
+
return "Bearer " + token;
|
|
64
|
+
}
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 获取用户信息
|
|
69
|
+
getUserInfo() {
|
|
70
|
+
return mpx.getStorageSync("userInfo") || {};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 设置用户信息
|
|
74
|
+
setUserInfo(data: UserInfo) {
|
|
75
|
+
mpx.setStorageSync("userInfo", data);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 获取角色列表
|
|
79
|
+
getRoleCodes() {
|
|
80
|
+
return mpx.getStorageSync("roleCodes") || [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 设置角色列表
|
|
84
|
+
setRoleCodes(codes: string[]) {
|
|
85
|
+
mpx.setStorageSync("roleCodes", codes);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 获取权限列表
|
|
89
|
+
getPermCodes() {
|
|
90
|
+
return mpx.getStorageSync("permCodes") || [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 设置权限列表
|
|
94
|
+
setPermCodes(codes: string[]) {
|
|
95
|
+
mpx.setStorageSync("permCodes", codes);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const db = new LocalStorage();
|
|
100
|
+
export { db };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// grpc工具类
|
|
2
|
+
class GrpcUtil {
|
|
3
|
+
//清理空参数.
|
|
4
|
+
clearEmpty(params: any): void {
|
|
5
|
+
for (const key in params) {
|
|
6
|
+
if (params[key] !== null && typeof params[key] === "object") {
|
|
7
|
+
this.clearEmpty(params[key]);
|
|
8
|
+
if (Object.keys(params[key]).length === 0) {
|
|
9
|
+
delete params[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if ([undefined, null, ""].includes(params[key])) {
|
|
14
|
+
delete params[key];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return params;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const grpc = new GrpcUtil();
|
|
21
|
+
export { grpc };
|