t-lj-service 1.0.1

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.
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/t-lj-api.iml" filepath="$PROJECT_DIR$/.idea/t-lj-api.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
package/README.md ADDED
@@ -0,0 +1,299 @@
1
+
2
+ **技术栈**:
3
+ - qiankun
4
+ - axios
5
+ - file-saver
6
+ - jszip
7
+ - Element-Plus
8
+ - vue3
9
+ - ts
10
+ - vite
11
+
12
+
13
+ ### Project Setup
14
+ ```sh
15
+ # 使用 npm 安装
16
+ npm install
17
+
18
+ # 或者使用 pnpm 安装
19
+ pnpm install
20
+
21
+ # 或者使用 yarn 安装
22
+ yarn
23
+ ```
24
+
25
+ ### Use for QianKun
26
+ ```sh
27
+ main.ts
28
+ import { apps } from 'micro-apps'
29
+ import { startApp } from 't-lj-api'
30
+ ...
31
+
32
+ startApp();
33
+ or
34
+ startApp(apps);
35
+
36
+ const app = createApp(App)
37
+ ...
38
+ ```
39
+ ```sh
40
+ micro-apps.ts
41
+ const apps: any[] = [
42
+ {
43
+ name: 'business',
44
+ entry: import.meta.env.VITE_APP_ENV === 'production' ? 'https://your-domain' : '//localhost:9999',
45
+ activeRule: '/business/',
46
+ },
47
+ ];
48
+ export default apps ;
49
+ ```
50
+ ```sh
51
+ qiankun子系统:
52
+ import { createApp } from 'vue';
53
+ import App from './App.vue';
54
+ import { useApp } from 't-lj-api'
55
+ import { router } from './router/router.ts';
56
+ import { i18n } from "./utils/i18n";
57
+ import ElementPlus from 'element-plus';
58
+ import * as ElementPlusIconsVue from '@element-plus/icons-vue'
59
+ import ZhCn from 'element-plus/es/locale/lang/zh-cn';
60
+ import LJ from 't-lj-components'
61
+ import pinia from '@/store/index.ts';
62
+ ...
63
+
64
+ let root: ReturnType<typeof createApp>;
65
+ const use:any[] = [
66
+ { module: router },
67
+ { module: i18n },
68
+ { module: pinia },
69
+ { module: LJ },
70
+ { module: ElementPlus,
71
+ options: {
72
+ locale: ZhCn,
73
+ }
74
+ },
75
+ ...
76
+ ];
77
+ useApp({
78
+ root,
79
+ App,
80
+ use,
81
+ id: '#app',
82
+ icons: ElementPlusIconsVue,
83
+ })
84
+
85
+ ```
86
+
87
+ ### Use for service
88
+ ```sh
89
+ import { POST, GET, PUT, DELETE, type ServiceResponse, CreateParams, CreateQuery, DEFAULT_QUERY } from 't-lj-api';
90
+ // DEFAULT_QUERY:默认参数,集成在CreateParams/CreateQuery方法内
91
+ export const demo = (params: any ): Promise<ServiceResponse> => POST('your-api-path', CreateParams(params));
92
+ export const demo = (params: any ): Promise<ServiceResponse> => POST('your-api-path', CreateQuery({
93
+ ReqDatas: params,
94
+ }));
95
+ export const demo = (params: any, headers: any ): Promise<ServiceResponse> => POST('your-api-path', CreateParams(params), headers);
96
+ ```
97
+
98
+ ### Use for Development
99
+
100
+ ```sh
101
+ import { hooks } from 't-lj-api';
102
+ or
103
+ import {
104
+ permission,
105
+ message,
106
+ confirm,
107
+ getAssetsImage,
108
+ notification,
109
+ setSession,
110
+ getSession,
111
+ delSession,
112
+ clearSession,
113
+ setLocal,
114
+ getLocal,
115
+ delLocal,
116
+ clearLocal,
117
+ verified,
118
+ verifiedTips,
119
+ postMessage,
120
+ emptyStatus,
121
+ loading,
122
+ randomInt,
123
+ decrypt,
124
+ crypto,
125
+ getQuery,
126
+ download,
127
+ zip,
128
+ padStart,
129
+ formatTime,
130
+ formatTimeArray,
131
+ } from 't-lj-api';
132
+
133
+ /**
134
+ * 权限校验
135
+ * @param sign string 密钥
136
+ * @param serviden string 服务
137
+ * @param version string 版本
138
+ * @param checkTokenServiden string token服务
139
+ * @param config any 配置文件
140
+ * @returns status boolean
141
+ */
142
+ import nodes from './../../../public/nodes.json'
143
+ const status: boolean = await permission({
144
+ sign: '',
145
+ serviden: 'DevCenterManager',
146
+ version: '1.0',
147
+ checkTokenServiden: 'DevCenterSecrity',
148
+ config: nodes,
149
+ });
150
+
151
+ /**
152
+ * 全局 loading
153
+ * @param params string 加载文案
154
+ * @param status boolean 开启关闭
155
+ * @param background string 背景颜色
156
+ */
157
+ hooks.loading(status,params,background) = loading(status,params,background);
158
+
159
+ /**
160
+ * 全局 message 方法,用于显示消息提示
161
+ * @param message 消息内容
162
+ * @param type 消息类型,默认为 success
163
+ * @param [options] 消息选项
164
+ */
165
+ hooks.message(message, type, options) = message(message, type, options);
166
+ hooks.message.success(message, options) = message.success(message, options);
167
+ hooks.message.error(message, options) = message.error(message, options);
168
+ hooks.message.info(message, options) = message.info(message, options);
169
+ hooks.message.warning(message, options) = message.warning(message, options);
170
+ /**
171
+ * 确认对话框
172
+ * @param message string 对话框内容
173
+ * @param title string 对话框标题,默认为 '提示'
174
+ * @param [options] any 对话框选项
175
+ * @return Promise<boolean>
176
+ */
177
+ hooks.confirm(message, title, options) = confirm(message, title, options);
178
+
179
+ /**
180
+ * 全局消息通知
181
+ * @param message 通知内容
182
+ * @param title 通知标题,默认为 '提示'
183
+ * @param [options] 通知选项
184
+ */
185
+ hooks.notification(message, title, options) = notification(message, title, options);
186
+
187
+ /**
188
+ * 获取静态资源
189
+ * @param url string 静态资源assets内文件路径
190
+ */
191
+ hooks.getAssetsImage(url) = getAssetsImage(url);
192
+
193
+ /**
194
+ * 设置 | 获取 | 删除 | 清空临时缓存
195
+ * @param key 缓存名称
196
+ * @param value 缓存数据
197
+ */
198
+ hooks.setSession(key, value) = setSession(key, value);
199
+ hooks.getSession(key) = getSession(key);
200
+ hooks.delSession(key) = delSession(key);
201
+ hooks.clearSession() = clearSession();
202
+
203
+ /**
204
+ * 设置 | 获取 | 删除 | 清空缓存
205
+ * @param key 缓存名称
206
+ * @param value 缓存数据
207
+ */
208
+ hooks.setLocal(key, value) = setLocal(key, value);
209
+ hooks.getLocal(key) = getLocal(key);
210
+ hooks.delLocal(key) = delLocal(key);
211
+ hooks.clearLocal() = clearLocal();
212
+
213
+ /**
214
+ * 校验 | 校验提示信息
215
+ * @param info object
216
+ * @param outKeys any[] 不校验字段
217
+ * @param keys any[] 校验key
218
+ * @param info any[] 必填提示信息
219
+ * @param key string 必填字段key
220
+ * @param tips string 提示信息key
221
+ */
222
+ hooks.verified(info, outKeys) = verified(info, outKeys);
223
+ hooks.verifiedTips(keys, info, key, tips) = verifiedTips(keys, info, key, tips);
224
+
225
+ /**
226
+ * 消息传递
227
+ * @param message string 临时缓存消息/发送消息
228
+ * @param target string 目标地址
229
+ * @param sessionName string 临时缓存名称
230
+ */
231
+ hooks.postMessage(message, target, sessionName) = postMessage(message, target, sessionName);
232
+
233
+ /**
234
+ * 数据空状态判断
235
+ * @param params any 参数
236
+ */
237
+ hooks.emptyStatus(params) = emptyStatus(params);
238
+
239
+ /**
240
+ * 获取随机整数
241
+ * @param min number
242
+ * @param max number
243
+ * @param range string, max:包含最大数;min:包含最小数; both:都包含;neither:都不包含
244
+ */
245
+ hooks.randomInt(min, max, range) = randomInt(min, max, range);
246
+
247
+ /**
248
+ * 加密 | 解密
249
+ * @param content string 内容
250
+ * @param key string
251
+ * @param iv string
252
+ */
253
+ hooks.decrypt(content, key, iv) = decrypt(content, key, iv);
254
+ hooks.crypto(content, key, iv) = crypto(content, key, iv);
255
+
256
+ /**
257
+ * 获取query
258
+ * @returns query string
259
+ */
260
+ hooks.getQuery() = getQuery();
261
+
262
+ /**
263
+ * 下载 | 批量下载
264
+ * @param url string
265
+ * @param name string
266
+ * @param format string
267
+ * @param type string
268
+ * @param fileList any[]
269
+ * @param zipName string 文件包名称
270
+ */
271
+ hooks.download({
272
+ url= "",
273
+ name= "",
274
+ format= "",
275
+ type = 'network',
276
+ }) = download({
277
+ url= "",
278
+ name= "",
279
+ format= "",
280
+ type = 'network',
281
+ });
282
+ hooks.zip(fileList, zipName) = zip(fileList, zipName);
283
+
284
+ /**
285
+ * 数字位数补0
286
+ * @param num string | number
287
+ * @param fixed number = 2
288
+ */
289
+ hooks.padStart(num, fixed) = padStart(num, fixed);
290
+
291
+ /**
292
+ * 时间格式拆分(毫秒)
293
+ * @param time string 00:00:00.00
294
+ * @param seconds number 1
295
+ * @param show boolean false 是否显示毫秒
296
+ */
297
+ hooks.formatTime(time) = formatTime(time);
298
+ hooks.formatTimeArray(seconds, show) = formatTimeArray(seconds, show); //
299
+ ```
package/env.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /// <reference types="vite/client" />
2
+
package/index.ts ADDED
@@ -0,0 +1,94 @@
1
+ import {
2
+ POST,
3
+ GET,
4
+ DELETE,
5
+ PUT,
6
+ DEFAULT_QUERY,
7
+ type ServiceResponse,
8
+ CreateParams,
9
+ CreateQuery
10
+ } from './module/service';
11
+ import hooks, {
12
+ message,
13
+ confirm,
14
+ getAssetsImage,
15
+ notification,
16
+ setSession,
17
+ getSession,
18
+ delSession,
19
+ clearSession,
20
+ setLocal,
21
+ getLocal,
22
+ delLocal,
23
+ clearLocal,
24
+ verified,
25
+ verifiedTips,
26
+ postMessage,
27
+ emptyStatus,
28
+ loading,
29
+ goTo,
30
+ randomInt,
31
+ decrypt,
32
+ crypto,
33
+ getQuery,
34
+ download,
35
+ zip,
36
+ padStart,
37
+ formatTime,
38
+ formatTimeArray,
39
+ } from './module/hooks';
40
+ import { permission } from './module/permission';
41
+ import { startApp, autoApp, useApp } from './module/qiankun/qiankun'
42
+
43
+
44
+
45
+
46
+
47
+ export {
48
+ startApp,
49
+ useApp,
50
+ autoApp,
51
+ }
52
+
53
+ export { type ServiceResponse };
54
+ export {
55
+ POST,
56
+ GET,
57
+ DELETE,
58
+ PUT,
59
+ DEFAULT_QUERY,
60
+ CreateParams,
61
+ CreateQuery,
62
+ }
63
+ export {
64
+ permission,
65
+ message,
66
+ confirm,
67
+ getAssetsImage,
68
+ notification,
69
+ setSession,
70
+ getSession,
71
+ delSession,
72
+ clearSession,
73
+ setLocal,
74
+ getLocal,
75
+ delLocal,
76
+ clearLocal,
77
+ verified,
78
+ verifiedTips,
79
+ postMessage,
80
+ emptyStatus,
81
+ loading,
82
+ goTo,
83
+ randomInt,
84
+ decrypt,
85
+ crypto,
86
+ getQuery,
87
+ download,
88
+ zip,
89
+ padStart,
90
+ formatTime,
91
+ formatTimeArray,
92
+ };
93
+
94
+ export { hooks };
package/module/code.ts ADDED
@@ -0,0 +1,23 @@
1
+
2
+ interface HTTP_CODE {
3
+ [prop : number]: string
4
+ }
5
+
6
+ export const HttpCodeMessage: HTTP_CODE = {
7
+ 400: '请求错误!',
8
+ 401: '未授权,缺少令牌!',
9
+ 403: '拒绝访问!',
10
+ 404: '请求不存在!',
11
+ 408: '请求超时!',
12
+ 410: '请求资源被永久删除!',
13
+ 500: '服务器错误!',
14
+ 501: '服务未实现!',
15
+ 502: '网络错误!',
16
+ 503: '服务不可用!',
17
+ 504: '网关超时!',
18
+ 999: '暂无网络!',
19
+ }
20
+
21
+ export const Code: number[] = [
22
+ 400, 401, 403, 404, 408, 410, 500, 501, 502, 503, 504, 999
23
+ ];
@@ -0,0 +1,80 @@
1
+ import hooks from './hooks';
2
+ const BASE_URL = import.meta.env.MODE === 'dev' ? '/api' : hooks.getLocal("sessioncurraddr") || '';
3
+ const TIME_OUT = 50000;
4
+ export enum REQUEST_METHOD {
5
+ POST = 'post',
6
+ GET = 'get',
7
+ PUT = 'put',
8
+ DELETE = 'delete',
9
+ }
10
+
11
+ enum BUSINESS_TYPE {
12
+ NODE_CENTER = 'nodecenter',
13
+ BIZ_NODE = 'biznode',
14
+ TERMINAL = 'terminal',
15
+ }
16
+
17
+ interface Query {
18
+ Async: boolean,
19
+ ReqID: string, // 请求识别, 没有为空
20
+ Refresh?: string, //是否刷新地址,1是 0 否,默认:不刷新 0
21
+ DataUrl: string, // 接口路径,用于前端负载均衡处理
22
+ ReqDataType: string, //数据类型josn xml text,默认:json
23
+ ReqMethod: string, // 请求方法,仅支持post get,默认:post
24
+ ReqIden?: string, //接口识别(描述接口识别码,为后续负载均衡进行识别接口,没有为空)
25
+ ReqDataIden?: string, //数据主体识别,没有为空
26
+ ReqDatas?: any, // 请求业务数据内容
27
+ ReqI18n?: string, //当前语言,默认:zh-CN
28
+ ServIdentifer?: string, //服务识别,没有为空
29
+ ServVersionIden?: string, //服务版本,没有为空
30
+ BizType?: string, //业务类型,参数值为nodecenter(节点中心地址) 、biznode(业务节点地址) 、terminal(终端网页地址),默认:nodecenter
31
+ ClientType?: string
32
+ }
33
+ let DEFAULT_QUERY: Query = {
34
+ Async: true,
35
+ ReqDataType: 'json',
36
+ ReqMethod: REQUEST_METHOD.POST,
37
+ ReqI18n: 'zh-CN',
38
+ ServVersionIden: '1.0',
39
+ BizType: BUSINESS_TYPE.NODE_CENTER,
40
+ ClientType: 'F',
41
+ ReqDatas: {},
42
+ DataUrl: '',
43
+ Refresh: '0',
44
+ ReqID: '',
45
+ ReqIden: '',
46
+ ReqDataIden: '',
47
+ ServIdentifer: 'DataMagicMgtMain',
48
+ };
49
+
50
+ const CreateQuery = (options: Partial<Query>): Query => {
51
+ return {
52
+ ...DEFAULT_QUERY,
53
+ ...options
54
+ };
55
+ }
56
+
57
+ const CreateParams = (options: Partial<any> = {}): Query => {
58
+ return {
59
+ ...DEFAULT_QUERY,
60
+ ...{
61
+ ReqDatas: options
62
+ }
63
+ };
64
+ }
65
+
66
+ const RequestConfig = (config: any): any => {
67
+ if(config.ContentType !== undefined ){
68
+ config.headers['Content-Type'] = config.ContentType;
69
+ }
70
+ if(config.method === 'post'){
71
+ config.data.DataUrl = config.url;
72
+ }
73
+ if(config.Token !== undefined ){
74
+ config.headers['Token'] = config.Token;
75
+ }
76
+ hooks.setLocal('sessiononlineTime', new Date().toString());
77
+ return config;
78
+ }
79
+
80
+ export { BASE_URL, TIME_OUT, DEFAULT_QUERY, CreateQuery, CreateParams, RequestConfig };