jmash-core-mp 0.1.21 → 0.1.22
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 -9
- package/README.md +60 -60
- package/babel.config.json +34 -34
- package/eslint.config.mjs +7 -7
- package/lib/api/auth/index.d.ts +21 -21
- package/lib/api/auth/index.js +199 -199
- package/lib/api/auth/types.d.ts +86 -86
- package/lib/api/auth/types.js +9 -9
- package/lib/api/cms/index.d.ts +20 -20
- package/lib/api/cms/index.js +161 -161
- package/lib/api/cms/types.d.ts +200 -200
- package/lib/api/cms/types.js +1 -1
- package/lib/api/constant.d.ts +5 -5
- package/lib/api/constant.js +6 -6
- package/lib/api/dict/index.d.ts +18 -18
- package/lib/api/dict/index.js +34 -34
- package/lib/api/dict/types.d.ts +28 -28
- package/lib/api/dict/types.js +1 -1
- package/lib/api/dicts.d.ts +18 -18
- package/lib/api/dicts.js +67 -67
- package/lib/api/files/index.d.ts +25 -25
- package/lib/api/files/index.js +135 -135
- package/lib/api/files/types.d.ts +38 -38
- package/lib/api/files/types.js +1 -1
- package/lib/api/index.d.ts +4 -4
- package/lib/api/index.js +6 -6
- package/lib/api/myorgan/types.d.ts +22 -22
- package/lib/api/myorgan/types.js +1 -1
- package/lib/api/region/index.d.ts +7 -7
- package/lib/api/region/index.js +19 -19
- package/lib/api/region/types.d.ts +19 -19
- package/lib/api/region/types.js +1 -1
- package/lib/api/storage/index.d.ts +10 -10
- package/lib/api/storage/index.js +43 -43
- package/lib/api/storage/types.d.ts +28 -28
- package/lib/api/storage/types.js +1 -1
- package/lib/api/types.d.ts +42 -42
- package/lib/api/types.js +1 -1
- package/lib/app.mpx.d.ts +1 -1
- package/lib/components/auth-user/jmash-update-user.mpx.d.ts +1 -1
- package/lib/components/auth-user/jmash-user.mpx.d.ts +1 -1
- package/lib/components/cms/jmash-cms-acticle-list.mpx.d.ts +1 -1
- package/lib/components/cms/jmash-cms-article-item.mpx.d.ts +1 -1
- package/lib/components/cms/jmash-cms-article-view.mpx.d.ts +1 -0
- package/lib/components/cms/jmash-cms-article.mpx.d.ts +1 -1
- package/lib/components/cms/jmash-cms-like.mpx.d.ts +1 -1
- package/lib/components/common/jmash-upload-picture.mpx.d.ts +1 -0
- package/lib/components/core/jmash-login.mpx.d.ts +1 -0
- package/lib/index.d.ts +21 -21
- package/lib/index.js +14 -14
- package/lib/packages/pages/cms/cms-article-list.mpx.d.ts +1 -1
- package/lib/pages/index.mpx.d.ts +1 -0
- package/lib/store/user.d.ts +31 -31
- package/lib/store/user.js +227 -227
- package/lib/utils/common.d.ts +35 -35
- package/lib/utils/common.js +166 -166
- package/lib/utils/config.d.ts +5 -5
- package/lib/utils/config.js +29 -29
- package/lib/utils/db.d.ts +21 -21
- package/lib/utils/db.js +84 -84
- package/lib/utils/grpc.d.ts +5 -5
- package/lib/utils/grpc.js +20 -20
- package/lib/utils/net.d.ts +7 -7
- package/lib/utils/net.js +15 -15
- package/lib/utils/request.d.ts +2 -2
- package/lib/utils/request.js +123 -123
- package/mpx.config.js +27 -27
- package/package.json +1 -1
- package/postcss.config.js +11 -11
- package/project.config.json +24 -24
- package/project.private.config.json +13 -13
- package/public/index.html +15 -15
- package/src/api/auth/index.ts +227 -227
- package/src/api/auth/types.ts +166 -166
- package/src/api/cms/index.ts +218 -218
- package/src/api/cms/types.ts +379 -379
- package/src/api/constant.ts +6 -6
- package/src/api/dict/index.ts +44 -44
- package/src/api/dict/types.ts +49 -49
- package/src/api/dicts.ts +72 -72
- package/src/api/files/index.ts +163 -163
- package/src/api/files/types.ts +67 -67
- package/src/api/index.ts +11 -11
- package/src/api/myorgan/types.ts +42 -42
- package/src/api/region/index.ts +23 -23
- package/src/api/region/types.ts +36 -36
- package/src/api/storage/index.ts +62 -62
- package/src/api/storage/types.ts +54 -54
- package/src/api/types.ts +72 -72
- package/src/app.mpx +71 -71
- package/src/components/auth-user/jmash-logout.mpx +91 -91
- package/src/components/auth-user/jmash-update-user.mpx +386 -386
- package/src/components/auth-user/jmash-update-user.web.mpx +366 -366
- package/src/components/auth-user/jmash-user.mpx +359 -359
- package/src/components/cms/jmash-cms-acticle-list.mpx +182 -182
- package/src/components/cms/jmash-cms-article-item.mpx +241 -241
- package/src/components/cms/jmash-cms-article-view.mpx +131 -131
- package/src/components/cms/jmash-cms-article.mpx +68 -68
- package/src/components/cms/jmash-cms-like.mpx +151 -151
- package/src/components/common/jmash-avatar-edit.mpx +153 -153
- package/src/components/common/jmash-cascader-region.mpx +112 -112
- package/src/components/common/jmash-menu.mpx +129 -129
- package/src/components/common/jmash-none-data.mpx +82 -82
- package/src/components/common/jmash-pic-swiper.mpx +71 -71
- package/src/components/common/jmash-popup.mpx +137 -137
- package/src/components/common/jmash-search.mpx +126 -126
- package/src/components/common/jmash-single-btn.mpx +53 -53
- package/src/components/common/jmash-stepper.mpx +214 -214
- package/src/components/common/jmash-tab-bar.mpx +50 -50
- package/src/components/common/jmash-textarea.mpx +88 -88
- package/src/components/common/jmash-top-navigation.mpx +203 -203
- package/src/components/common/jmash-upload-picture.mpx +129 -126
- package/src/components/core/jmash-cms-protocol.mpx +66 -66
- package/src/components/core/jmash-login.ali.mpx +284 -284
- package/src/components/core/jmash-login.mpx +348 -348
- package/src/components/core/jmash-login.web.mpx +421 -421
- package/src/components/core/jmash-popup-login.ali.mpx +311 -311
- package/src/components/core/jmash-popup-login.mpx +415 -415
- package/src/components/core/jmash-popup-login.web.mpx +389 -389
- package/src/custom-tab-bar/index.mpx +10 -10
- package/src/global.d.ts +11 -11
- package/src/index.ts +71 -71
- package/src/packages/index.mpx +10 -10
- package/src/packages/pages/auth/cms-protocol.mpx +31 -31
- package/src/packages/pages/auth/login.mpx +59 -59
- package/src/packages/pages/auth/update-user.mpx +17 -17
- package/src/packages/pages/cms/cms-article-list.mpx +164 -164
- package/src/packages/pages/cms/cms-article.mpx +32 -32
- package/src/pages/basic-component.mpx +30 -30
- package/src/pages/half-home.mpx +58 -58
- package/src/pages/home.mpx +52 -52
- package/src/pages/home2.mpx +47 -47
- package/src/pages/index.mpx +13 -3
- package/src/pages/tabbar/home.mpx +77 -77
- package/src/pages/tabbar/my.mpx +80 -80
- package/src/store/user.ts +270 -270
- package/src/styles/index.scss +20 -20
- package/src/styles/vars.scss +27 -27
- package/src/utils/common.ts +179 -179
- package/src/utils/config.ts +35 -35
- package/src/utils/db.ts +100 -100
- package/src/utils/grpc.ts +21 -21
- package/src/utils/net.ts +18 -18
- package/src/utils/request.ts +134 -134
- package/static/ali/mini.project.json +4 -4
- package/static/dd/project.config.json +15 -15
- package/static/swan/project.swan.json +14 -14
- package/static/tt/project.config.json +11 -11
- package/static/wx/project.config.json +40 -40
- package/uno.config.js +9 -9
package/src/api/constant.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
class Constant {
|
|
2
|
-
static readonly MODULE_RBAC = "rbac"; // rbac
|
|
3
|
-
// 性别
|
|
4
|
-
static readonly ENUM_GENDER = "jmash.protobuf.Gender";
|
|
5
|
-
}
|
|
6
|
-
export { Constant };
|
|
1
|
+
class Constant {
|
|
2
|
+
static readonly MODULE_RBAC = "rbac"; // rbac
|
|
3
|
+
// 性别
|
|
4
|
+
static readonly ENUM_GENDER = "jmash.protobuf.Gender";
|
|
5
|
+
}
|
|
6
|
+
export { Constant };
|
package/src/api/dict/index.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { ResponseData, AppConfig } from "../../api/types";
|
|
2
|
-
import { EnumEntryReq, EnumRes, DictEntryReq, DictEntryList } from "./types";
|
|
3
|
-
import mpx from "@mpxjs/core";
|
|
4
|
-
|
|
5
|
-
class DictApiImpl {
|
|
6
|
-
/**
|
|
7
|
-
* 枚举
|
|
8
|
-
* @param data 查询条件
|
|
9
|
-
* @returns 返回Promise<Entry[]>的对象
|
|
10
|
-
*/
|
|
11
|
-
enumApi(
|
|
12
|
-
module: string,
|
|
13
|
-
className: string,
|
|
14
|
-
type?: number
|
|
15
|
-
): Promise<ResponseData<EnumRes>> {
|
|
16
|
-
const data: EnumEntryReq = { className, type };
|
|
17
|
-
return mpx.xfetch.fetch<EnumRes>({
|
|
18
|
-
url: "/v1/" + module + "/enum/entry",
|
|
19
|
-
method: "GET",
|
|
20
|
-
data,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 普通字典
|
|
26
|
-
* @param data 查询条件
|
|
27
|
-
* @returns 返回Promise<Entry[]>的对象
|
|
28
|
-
*/
|
|
29
|
-
dictEntryApi(data: DictEntryReq): Promise<ResponseData<DictEntryList>> {
|
|
30
|
-
if (data) {
|
|
31
|
-
data.hasEnable = data.enable !== undefined;
|
|
32
|
-
}
|
|
33
|
-
const config = getApp().globalData.config;
|
|
34
|
-
return mpx.xfetch.fetch({
|
|
35
|
-
url: "/v1/dict/dict_entry/list/" + config.tenant,
|
|
36
|
-
method: "GET",
|
|
37
|
-
data,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const dictApi = new DictApiImpl();
|
|
43
|
-
|
|
44
|
-
export { dictApi };
|
|
1
|
+
import { ResponseData, AppConfig } from "../../api/types";
|
|
2
|
+
import { EnumEntryReq, EnumRes, DictEntryReq, DictEntryList } from "./types";
|
|
3
|
+
import mpx from "@mpxjs/core";
|
|
4
|
+
|
|
5
|
+
class DictApiImpl {
|
|
6
|
+
/**
|
|
7
|
+
* 枚举
|
|
8
|
+
* @param data 查询条件
|
|
9
|
+
* @returns 返回Promise<Entry[]>的对象
|
|
10
|
+
*/
|
|
11
|
+
enumApi(
|
|
12
|
+
module: string,
|
|
13
|
+
className: string,
|
|
14
|
+
type?: number
|
|
15
|
+
): Promise<ResponseData<EnumRes>> {
|
|
16
|
+
const data: EnumEntryReq = { className, type };
|
|
17
|
+
return mpx.xfetch.fetch<EnumRes>({
|
|
18
|
+
url: "/v1/" + module + "/enum/entry",
|
|
19
|
+
method: "GET",
|
|
20
|
+
data,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 普通字典
|
|
26
|
+
* @param data 查询条件
|
|
27
|
+
* @returns 返回Promise<Entry[]>的对象
|
|
28
|
+
*/
|
|
29
|
+
dictEntryApi(data: DictEntryReq): Promise<ResponseData<DictEntryList>> {
|
|
30
|
+
if (data) {
|
|
31
|
+
data.hasEnable = data.enable !== undefined;
|
|
32
|
+
}
|
|
33
|
+
const config = getApp().globalData.config;
|
|
34
|
+
return mpx.xfetch.fetch({
|
|
35
|
+
url: "/v1/dict/dict_entry/list/" + config.tenant,
|
|
36
|
+
method: "GET",
|
|
37
|
+
data,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const dictApi = new DictApiImpl();
|
|
43
|
+
|
|
44
|
+
export { dictApi };
|
package/src/api/dict/types.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// Entry
|
|
2
|
-
export interface Entry {
|
|
3
|
-
// 键
|
|
4
|
-
key?: string
|
|
5
|
-
// 值
|
|
6
|
-
value?: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// 枚举
|
|
10
|
-
export interface EnumEntryReq {
|
|
11
|
-
className?: string;
|
|
12
|
-
type?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface EnumRes {
|
|
16
|
-
values: Array<Entry>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 数据字典实体
|
|
20
|
-
export interface DictEntryModel {
|
|
21
|
-
// 字典类型编码
|
|
22
|
-
typeCode?: string;
|
|
23
|
-
// 字典编码
|
|
24
|
-
dictCode?: string;
|
|
25
|
-
// 字典名称
|
|
26
|
-
dictName?: string;
|
|
27
|
-
// 排序
|
|
28
|
-
listOrder?: number;
|
|
29
|
-
// 是否启用
|
|
30
|
-
enable?: boolean;
|
|
31
|
-
// 描述
|
|
32
|
-
description?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 数据字典列表
|
|
36
|
-
export interface DictEntryList {
|
|
37
|
-
// 内容
|
|
38
|
-
results: Array<DictEntryModel>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 普通数据字典查询
|
|
42
|
-
export interface DictEntryReq {
|
|
43
|
-
typeCode?: string;
|
|
44
|
-
// 字典编码
|
|
45
|
-
dictCode?: string;
|
|
46
|
-
// 是否包含启用
|
|
47
|
-
hasEnable?: boolean;
|
|
48
|
-
// 是否启用
|
|
49
|
-
enable?: boolean;
|
|
1
|
+
// Entry
|
|
2
|
+
export interface Entry {
|
|
3
|
+
// 键
|
|
4
|
+
key?: string
|
|
5
|
+
// 值
|
|
6
|
+
value?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// 枚举
|
|
10
|
+
export interface EnumEntryReq {
|
|
11
|
+
className?: string;
|
|
12
|
+
type?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface EnumRes {
|
|
16
|
+
values: Array<Entry>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 数据字典实体
|
|
20
|
+
export interface DictEntryModel {
|
|
21
|
+
// 字典类型编码
|
|
22
|
+
typeCode?: string;
|
|
23
|
+
// 字典编码
|
|
24
|
+
dictCode?: string;
|
|
25
|
+
// 字典名称
|
|
26
|
+
dictName?: string;
|
|
27
|
+
// 排序
|
|
28
|
+
listOrder?: number;
|
|
29
|
+
// 是否启用
|
|
30
|
+
enable?: boolean;
|
|
31
|
+
// 描述
|
|
32
|
+
description?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 数据字典列表
|
|
36
|
+
export interface DictEntryList {
|
|
37
|
+
// 内容
|
|
38
|
+
results: Array<DictEntryModel>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 普通数据字典查询
|
|
42
|
+
export interface DictEntryReq {
|
|
43
|
+
typeCode?: string;
|
|
44
|
+
// 字典编码
|
|
45
|
+
dictCode?: string;
|
|
46
|
+
// 是否包含启用
|
|
47
|
+
hasEnable?: boolean;
|
|
48
|
+
// 是否启用
|
|
49
|
+
enable?: boolean;
|
|
50
50
|
}
|
package/src/api/dicts.ts
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { Entry, DictEntryModel, DictEntryReq } from "./dict/types";
|
|
2
|
-
import { dictApi } from "./dict/index";
|
|
3
|
-
//枚举字典类.
|
|
4
|
-
export class EnumDict {
|
|
5
|
-
//模块名
|
|
6
|
-
module: string;
|
|
7
|
-
//枚举类名
|
|
8
|
-
enumClass: string;
|
|
9
|
-
//枚举类型
|
|
10
|
-
type: number;
|
|
11
|
-
//枚举值
|
|
12
|
-
values: Entry[] = [];
|
|
13
|
-
constructor(module: string, enumClass: string, type: number = 0) {
|
|
14
|
-
this.module = module;
|
|
15
|
-
this.enumClass = enumClass;
|
|
16
|
-
this.type = type;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
useEnumValues(): Promise<Entry[]> {
|
|
20
|
-
return new Promise<Entry[]>((resolve) => {
|
|
21
|
-
dictApi
|
|
22
|
-
.enumApi(this.module, this.enumClass, this.type)
|
|
23
|
-
.then(({ data }) => {
|
|
24
|
-
this.values.length = 0;
|
|
25
|
-
this.values.push(...data.values);
|
|
26
|
-
resolve(this.values);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getEnumValue(key: string): string {
|
|
32
|
-
for (const obj of this.values) {
|
|
33
|
-
if (obj.key === key) {
|
|
34
|
-
return obj.value as string;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 普通字典类
|
|
42
|
-
export class EntryDict {
|
|
43
|
-
typeCode: string;
|
|
44
|
-
enable?: boolean;
|
|
45
|
-
values: DictEntryModel[] = [];
|
|
46
|
-
constructor(typeCode: string, enable: boolean = true) {
|
|
47
|
-
// 字典类型编码
|
|
48
|
-
this.typeCode = typeCode;
|
|
49
|
-
// 是否启用
|
|
50
|
-
this.enable = enable;
|
|
51
|
-
}
|
|
52
|
-
// 加载数据字典
|
|
53
|
-
useDictValues(): Promise<DictEntryModel[]> {
|
|
54
|
-
return new Promise((resolve) => {
|
|
55
|
-
const req = {
|
|
56
|
-
typeCode: this.typeCode,
|
|
57
|
-
enable: this.enable,
|
|
58
|
-
} as DictEntryReq;
|
|
59
|
-
dictApi.dictEntryApi(req).then(({ data }) => {
|
|
60
|
-
this.values.length = 0;
|
|
61
|
-
this.values.push(...data.results);
|
|
62
|
-
resolve(this.values);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
//获取字典值
|
|
68
|
-
getDictValue(key: string): string {
|
|
69
|
-
const entry = this.values.find((entrys) => entrys.dictCode === key);
|
|
70
|
-
return entry?.dictName ? entry.dictName : "";
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
import { Entry, DictEntryModel, DictEntryReq } from "./dict/types";
|
|
2
|
+
import { dictApi } from "./dict/index";
|
|
3
|
+
//枚举字典类.
|
|
4
|
+
export class EnumDict {
|
|
5
|
+
//模块名
|
|
6
|
+
module: string;
|
|
7
|
+
//枚举类名
|
|
8
|
+
enumClass: string;
|
|
9
|
+
//枚举类型
|
|
10
|
+
type: number;
|
|
11
|
+
//枚举值
|
|
12
|
+
values: Entry[] = [];
|
|
13
|
+
constructor(module: string, enumClass: string, type: number = 0) {
|
|
14
|
+
this.module = module;
|
|
15
|
+
this.enumClass = enumClass;
|
|
16
|
+
this.type = type;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
useEnumValues(): Promise<Entry[]> {
|
|
20
|
+
return new Promise<Entry[]>((resolve) => {
|
|
21
|
+
dictApi
|
|
22
|
+
.enumApi(this.module, this.enumClass, this.type)
|
|
23
|
+
.then(({ data }) => {
|
|
24
|
+
this.values.length = 0;
|
|
25
|
+
this.values.push(...data.values);
|
|
26
|
+
resolve(this.values);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getEnumValue(key: string): string {
|
|
32
|
+
for (const obj of this.values) {
|
|
33
|
+
if (obj.key === key) {
|
|
34
|
+
return obj.value as string;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 普通字典类
|
|
42
|
+
export class EntryDict {
|
|
43
|
+
typeCode: string;
|
|
44
|
+
enable?: boolean;
|
|
45
|
+
values: DictEntryModel[] = [];
|
|
46
|
+
constructor(typeCode: string, enable: boolean = true) {
|
|
47
|
+
// 字典类型编码
|
|
48
|
+
this.typeCode = typeCode;
|
|
49
|
+
// 是否启用
|
|
50
|
+
this.enable = enable;
|
|
51
|
+
}
|
|
52
|
+
// 加载数据字典
|
|
53
|
+
useDictValues(): Promise<DictEntryModel[]> {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
const req = {
|
|
56
|
+
typeCode: this.typeCode,
|
|
57
|
+
enable: this.enable,
|
|
58
|
+
} as DictEntryReq;
|
|
59
|
+
dictApi.dictEntryApi(req).then(({ data }) => {
|
|
60
|
+
this.values.length = 0;
|
|
61
|
+
this.values.push(...data.results);
|
|
62
|
+
resolve(this.values);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//获取字典值
|
|
68
|
+
getDictValue(key: string): string {
|
|
69
|
+
const entry = this.values.find((entrys) => entrys.dictCode === key);
|
|
70
|
+
return entry?.dictName ? entry.dictName : "";
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/api/files/index.ts
CHANGED
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
import { FileInfo, FileBase64Req, FileDownInfo, FileWebReq } from "./types";
|
|
2
|
-
import { ResponseData, AppConfig } from "../../api/types";
|
|
3
|
-
import { db } from "../../utils/db";
|
|
4
|
-
import { grpc } from "../../utils/grpc";
|
|
5
|
-
import mpx from "@mpxjs/core";
|
|
6
|
-
|
|
7
|
-
class FileApi {
|
|
8
|
-
baseApiUrl(): string {
|
|
9
|
-
const config = getApp().globalData.config;
|
|
10
|
-
let currentBaseURL = config.baseUrl as string;
|
|
11
|
-
// 使用 slice() 方法
|
|
12
|
-
if (currentBaseURL.slice(-1) === "/") {
|
|
13
|
-
currentBaseURL = currentBaseURL.slice(0, -1);
|
|
14
|
-
}
|
|
15
|
-
return currentBaseURL;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 上传Url
|
|
19
|
-
uploadUrl(): string {
|
|
20
|
-
const config = getApp().globalData.config;
|
|
21
|
-
return this.baseApiUrl() + "/v1/file/upload?tenant=" + config.tenant;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* url 获取图片Full路径
|
|
26
|
-
* @param type resize 等比例缩放,white 补白,trans 补透明,clip 裁剪
|
|
27
|
-
*/
|
|
28
|
-
imageUrl(
|
|
29
|
-
imageUrl: string,
|
|
30
|
-
width: number = 0,
|
|
31
|
-
height: number = 0,
|
|
32
|
-
type: string = "clip"
|
|
33
|
-
): string {
|
|
34
|
-
const regular = /^\//;
|
|
35
|
-
if (regular.test(imageUrl)) {
|
|
36
|
-
return (
|
|
37
|
-
this.baseApiUrl() +
|
|
38
|
-
`/v1/file/image/${type}/${width}/${height}` +
|
|
39
|
-
imageUrl
|
|
40
|
-
);
|
|
41
|
-
} else {
|
|
42
|
-
return (
|
|
43
|
-
this.baseApiUrl() +
|
|
44
|
-
`/v1/file/image/${type}/${width}/${height}/` +
|
|
45
|
-
imageUrl
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Id 获取图片Full路径
|
|
52
|
-
* @param type resize 等比例缩放,white 补白,trans 补透明,clip 裁剪
|
|
53
|
-
*/
|
|
54
|
-
imageIdUrl(
|
|
55
|
-
imageId: string,
|
|
56
|
-
width: number = 0,
|
|
57
|
-
height: number = 0,
|
|
58
|
-
type: string = "clip"
|
|
59
|
-
): string {
|
|
60
|
-
const config = getApp().globalData.config;
|
|
61
|
-
return (
|
|
62
|
-
this.baseApiUrl() +
|
|
63
|
-
"/v1/file/image_id/" +
|
|
64
|
-
config.tenant +
|
|
65
|
-
`/${type}/${width}/${height}/` +
|
|
66
|
-
imageId
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// url 获取文件Full路径
|
|
71
|
-
fileUrl(fileUrl?: string): string {
|
|
72
|
-
return this.baseApiUrl() + "/v1/file/path/" + fileUrl;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Id 获取文件Full路径
|
|
76
|
-
fileIdUrl(fileId?: string): string {
|
|
77
|
-
const config = getApp().globalData.config;
|
|
78
|
-
return this.baseApiUrl() + "/v1/file/id/" + config.tenant + fileId;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 上传文件
|
|
82
|
-
uploadBase64File(base64: FileBase64Req): Promise<ResponseData<FileInfo>> {
|
|
83
|
-
const config = getApp().globalData.config;
|
|
84
|
-
base64.tenant = config.tenant;
|
|
85
|
-
grpc.clearEmpty(base64);
|
|
86
|
-
return mpx.xfetch.fetch({
|
|
87
|
-
url: "/v1/file/base64upload",
|
|
88
|
-
method: "POST",
|
|
89
|
-
data: base64,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// 上传文件
|
|
94
|
-
uploadFile(file: string): Promise<FileInfo> {
|
|
95
|
-
const p = mpx.uploadFile({
|
|
96
|
-
url: this.uploadUrl(),
|
|
97
|
-
filePath: file,
|
|
98
|
-
name: "file",
|
|
99
|
-
header: {
|
|
100
|
-
"Content-Type": "multipart/form-data",
|
|
101
|
-
Authorization: db.getBearerToken(),
|
|
102
|
-
},
|
|
103
|
-
} as WechatMiniprogram.UploadFileOption) as any;
|
|
104
|
-
return p.then((res: any) => {
|
|
105
|
-
console.log("uploadFile", res);
|
|
106
|
-
if (res.statusCode === 200) {
|
|
107
|
-
return JSON.parse(res.data) as FileInfo;
|
|
108
|
-
} else if (res.statusCode === 401) {
|
|
109
|
-
// 清理登录信息
|
|
110
|
-
mpx.clearStorage();
|
|
111
|
-
throw new Error("登录过期,请重新登录");
|
|
112
|
-
} else {
|
|
113
|
-
mpx.showToast({
|
|
114
|
-
title: res.errMsg,
|
|
115
|
-
icon: "none",
|
|
116
|
-
duration: 2000,
|
|
117
|
-
});
|
|
118
|
-
return JSON.parse(res.data) as FileInfo;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// 上传文件
|
|
124
|
-
downloadFile(url: string): Promise<FileDownInfo> {
|
|
125
|
-
const p = mpx.downloadFile({
|
|
126
|
-
url: url,
|
|
127
|
-
header: {
|
|
128
|
-
Authorization: db.getBearerToken(),
|
|
129
|
-
},
|
|
130
|
-
}) as any;
|
|
131
|
-
return p.then((res: any) => {
|
|
132
|
-
return {
|
|
133
|
-
statusCode: res.statusCode,
|
|
134
|
-
tempFilePath: res.tempFilePath,
|
|
135
|
-
filePath: res.tempFilePath,
|
|
136
|
-
} as FileDownInfo;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// 上传文件
|
|
141
|
-
uploadWebFile(data: FileWebReq): Promise<ResponseData<FileInfo>> {
|
|
142
|
-
// data.tenant = data.tenant ? config.tenant;
|
|
143
|
-
grpc.clearEmpty(data);
|
|
144
|
-
return mpx.xfetch.fetch({
|
|
145
|
-
url: "/v1/file/webupload",
|
|
146
|
-
method: "POST",
|
|
147
|
-
data: data,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// 删除文件
|
|
152
|
-
deleteFile(filePath?: string): Promise<ResponseData<FileInfo>> {
|
|
153
|
-
return mpx.xfetch.fetch({
|
|
154
|
-
url: "/api/v1/files",
|
|
155
|
-
method: "DELETE",
|
|
156
|
-
data: { filePath: filePath },
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const fileApi = new FileApi();
|
|
162
|
-
|
|
163
|
-
export { fileApi };
|
|
1
|
+
import { FileInfo, FileBase64Req, FileDownInfo, FileWebReq } from "./types";
|
|
2
|
+
import { ResponseData, AppConfig } from "../../api/types";
|
|
3
|
+
import { db } from "../../utils/db";
|
|
4
|
+
import { grpc } from "../../utils/grpc";
|
|
5
|
+
import mpx from "@mpxjs/core";
|
|
6
|
+
|
|
7
|
+
class FileApi {
|
|
8
|
+
baseApiUrl(): string {
|
|
9
|
+
const config = getApp().globalData.config;
|
|
10
|
+
let currentBaseURL = config.baseUrl as string;
|
|
11
|
+
// 使用 slice() 方法
|
|
12
|
+
if (currentBaseURL.slice(-1) === "/") {
|
|
13
|
+
currentBaseURL = currentBaseURL.slice(0, -1);
|
|
14
|
+
}
|
|
15
|
+
return currentBaseURL;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 上传Url
|
|
19
|
+
uploadUrl(): string {
|
|
20
|
+
const config = getApp().globalData.config;
|
|
21
|
+
return this.baseApiUrl() + "/v1/file/upload?tenant=" + config.tenant;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* url 获取图片Full路径
|
|
26
|
+
* @param type resize 等比例缩放,white 补白,trans 补透明,clip 裁剪
|
|
27
|
+
*/
|
|
28
|
+
imageUrl(
|
|
29
|
+
imageUrl: string,
|
|
30
|
+
width: number = 0,
|
|
31
|
+
height: number = 0,
|
|
32
|
+
type: string = "clip"
|
|
33
|
+
): string {
|
|
34
|
+
const regular = /^\//;
|
|
35
|
+
if (regular.test(imageUrl)) {
|
|
36
|
+
return (
|
|
37
|
+
this.baseApiUrl() +
|
|
38
|
+
`/v1/file/image/${type}/${width}/${height}` +
|
|
39
|
+
imageUrl
|
|
40
|
+
);
|
|
41
|
+
} else {
|
|
42
|
+
return (
|
|
43
|
+
this.baseApiUrl() +
|
|
44
|
+
`/v1/file/image/${type}/${width}/${height}/` +
|
|
45
|
+
imageUrl
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Id 获取图片Full路径
|
|
52
|
+
* @param type resize 等比例缩放,white 补白,trans 补透明,clip 裁剪
|
|
53
|
+
*/
|
|
54
|
+
imageIdUrl(
|
|
55
|
+
imageId: string,
|
|
56
|
+
width: number = 0,
|
|
57
|
+
height: number = 0,
|
|
58
|
+
type: string = "clip"
|
|
59
|
+
): string {
|
|
60
|
+
const config = getApp().globalData.config;
|
|
61
|
+
return (
|
|
62
|
+
this.baseApiUrl() +
|
|
63
|
+
"/v1/file/image_id/" +
|
|
64
|
+
config.tenant +
|
|
65
|
+
`/${type}/${width}/${height}/` +
|
|
66
|
+
imageId
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// url 获取文件Full路径
|
|
71
|
+
fileUrl(fileUrl?: string): string {
|
|
72
|
+
return this.baseApiUrl() + "/v1/file/path/" + fileUrl;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Id 获取文件Full路径
|
|
76
|
+
fileIdUrl(fileId?: string): string {
|
|
77
|
+
const config = getApp().globalData.config;
|
|
78
|
+
return this.baseApiUrl() + "/v1/file/id/" + config.tenant + fileId;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 上传文件
|
|
82
|
+
uploadBase64File(base64: FileBase64Req): Promise<ResponseData<FileInfo>> {
|
|
83
|
+
const config = getApp().globalData.config;
|
|
84
|
+
base64.tenant = config.tenant;
|
|
85
|
+
grpc.clearEmpty(base64);
|
|
86
|
+
return mpx.xfetch.fetch({
|
|
87
|
+
url: "/v1/file/base64upload",
|
|
88
|
+
method: "POST",
|
|
89
|
+
data: base64,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 上传文件
|
|
94
|
+
uploadFile(file: string): Promise<FileInfo> {
|
|
95
|
+
const p = mpx.uploadFile({
|
|
96
|
+
url: this.uploadUrl(),
|
|
97
|
+
filePath: file,
|
|
98
|
+
name: "file",
|
|
99
|
+
header: {
|
|
100
|
+
"Content-Type": "multipart/form-data",
|
|
101
|
+
Authorization: db.getBearerToken(),
|
|
102
|
+
},
|
|
103
|
+
} as WechatMiniprogram.UploadFileOption) as any;
|
|
104
|
+
return p.then((res: any) => {
|
|
105
|
+
console.log("uploadFile", res);
|
|
106
|
+
if (res.statusCode === 200) {
|
|
107
|
+
return JSON.parse(res.data) as FileInfo;
|
|
108
|
+
} else if (res.statusCode === 401) {
|
|
109
|
+
// 清理登录信息
|
|
110
|
+
mpx.clearStorage();
|
|
111
|
+
throw new Error("登录过期,请重新登录");
|
|
112
|
+
} else {
|
|
113
|
+
mpx.showToast({
|
|
114
|
+
title: res.errMsg,
|
|
115
|
+
icon: "none",
|
|
116
|
+
duration: 2000,
|
|
117
|
+
});
|
|
118
|
+
return JSON.parse(res.data) as FileInfo;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 上传文件
|
|
124
|
+
downloadFile(url: string): Promise<FileDownInfo> {
|
|
125
|
+
const p = mpx.downloadFile({
|
|
126
|
+
url: url,
|
|
127
|
+
header: {
|
|
128
|
+
Authorization: db.getBearerToken(),
|
|
129
|
+
},
|
|
130
|
+
}) as any;
|
|
131
|
+
return p.then((res: any) => {
|
|
132
|
+
return {
|
|
133
|
+
statusCode: res.statusCode,
|
|
134
|
+
tempFilePath: res.tempFilePath,
|
|
135
|
+
filePath: res.tempFilePath,
|
|
136
|
+
} as FileDownInfo;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 上传文件
|
|
141
|
+
uploadWebFile(data: FileWebReq): Promise<ResponseData<FileInfo>> {
|
|
142
|
+
// data.tenant = data.tenant ? config.tenant;
|
|
143
|
+
grpc.clearEmpty(data);
|
|
144
|
+
return mpx.xfetch.fetch({
|
|
145
|
+
url: "/v1/file/webupload",
|
|
146
|
+
method: "POST",
|
|
147
|
+
data: data,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 删除文件
|
|
152
|
+
deleteFile(filePath?: string): Promise<ResponseData<FileInfo>> {
|
|
153
|
+
return mpx.xfetch.fetch({
|
|
154
|
+
url: "/api/v1/files",
|
|
155
|
+
method: "DELETE",
|
|
156
|
+
data: { filePath: filePath },
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const fileApi = new FileApi();
|
|
162
|
+
|
|
163
|
+
export { fileApi };
|