kn-cli 1.0.97 → 1.0.98
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/package.json +1 -1
- package/templates/template_admin/cli.config.js +4 -1
- package/templates/template_admin/package.json +7 -1
- package/templates/template_admin/public/favicon.png +0 -0
- package/templates/template_admin/public/index.html +6 -4
- package/templates/template_admin/public/src/_antd.less +30 -3
- package/templates/template_admin/public/src/_mixin.less +41 -0
- package/templates/template_admin/public/src/_reset.less +28 -20
- package/templates/template_admin/public/src/_variable.less +11 -6
- package/templates/template_admin/public/src/assets/iconfont/iconfont.eot +0 -0
- package/templates/template_admin/public/src/assets/iconfont/iconfont.less +60 -8
- package/templates/template_admin/public/src/assets/iconfont/iconfont.svg +57 -18
- package/templates/template_admin/public/src/assets/iconfont/iconfont.ttf +0 -0
- package/templates/template_admin/public/src/assets/iconfont/iconfont.woff +0 -0
- package/templates/template_admin/public/src/assets/iconfont/iconfont.woff2 +0 -0
- package/templates/template_admin/public/src/assets/images/arrow.png +0 -0
- package/templates/template_admin/public/src/assets/images/icon-notice.png +0 -0
- package/templates/template_admin/public/src/assets/images/icon-user.png +0 -0
- package/templates/template_admin/public/src/assets/images/loadFail.png +0 -0
- package/templates/template_admin/public/src/assets/images/login/bg.png +0 -0
- package/templates/template_admin/public/src/assets/images/login/logo.png +0 -0
- package/templates/template_admin/public/src/assets/images/login/slogan.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-dep-active.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-dep.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-log-active.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-log.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-loginlog-active.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-loginlog.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-role-active.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-role.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-user-active.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/icon-user.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/nav-toggle.png +0 -0
- package/templates/template_admin/public/src/assets/images/nav/slogan.png +0 -0
- package/templates/template_admin/public/src/assets/images/noData.png +0 -0
- package/templates/template_admin/public/src/assets/images/noSelect.png +0 -0
- package/templates/template_admin/public/src/components/auth/index.jsx +7 -3
- package/templates/template_admin/public/src/components/auth/index.less +7 -0
- package/templates/template_admin/public/src/components/badge/index.jsx +47 -0
- package/templates/template_admin/public/src/components/badge/index.less +44 -0
- package/templates/template_admin/public/src/components/debug/index.jsx +27 -0
- package/templates/template_admin/public/src/components/debug/index.less +9 -0
- package/templates/template_admin/public/src/components/empty/index.jsx +28 -0
- package/templates/template_admin/public/src/components/empty/index.less +20 -0
- package/templates/template_admin/public/src/components/image/index.jsx +73 -0
- package/templates/template_admin/public/src/components/image/index.less +117 -0
- package/templates/template_admin/public/src/components/image/preview.jsx +85 -0
- package/templates/template_admin/public/src/components/layout/basic/index.jsx +24 -11
- package/templates/template_admin/public/src/components/layout/basic/index.less +58 -19
- package/templates/template_admin/public/src/components/layout/index.jsx +20 -17
- package/templates/template_admin/public/src/components/layout/index.less +4 -4
- package/templates/template_admin/public/src/components/layout/provider/index.jsx +19 -6
- package/templates/template_admin/public/src/components/{menu → leftMenu}/index.jsx +20 -28
- package/templates/template_admin/public/src/components/leftMenu/index.less +42 -0
- package/templates/template_admin/public/src/components/popup/index.jsx +25 -0
- package/templates/template_admin/public/src/components/table/column.jsx +47 -0
- package/templates/template_admin/public/src/components/table/column.less +12 -0
- package/templates/template_admin/public/src/components/table/index.jsx +22 -13
- package/templates/template_admin/public/src/components/table/index.less +15 -0
- package/templates/template_admin/public/src/components/text/index.jsx +98 -0
- package/templates/template_admin/public/src/components/text/index.less +13 -0
- package/templates/template_admin/public/src/components/topMenu/index.jsx +97 -0
- package/templates/template_admin/public/src/components/topMenu/index.less +80 -0
- package/templates/template_admin/public/src/components/topMenu/topBar/index.jsx +76 -0
- package/templates/template_admin/public/src/components/topMenu/topBar/index.less +88 -0
- package/templates/template_admin/public/src/components/video/index.jsx +96 -0
- package/templates/template_admin/public/src/components/video/index.less +132 -0
- package/templates/template_admin/public/src/components/video/preview.jsx +38 -0
- package/templates/template_admin/public/src/dictionary/index.js +108 -39
- package/templates/template_admin/public/src/enum.js +41 -0
- package/templates/template_admin/public/src/hooks/index.jsx +8 -6
- package/templates/template_admin/public/src/hooks/useDebounceFn.jsx +33 -0
- package/templates/template_admin/public/src/hooks/useInToView.jsx +58 -0
- package/templates/template_admin/public/src/hooks/useRouteMenu.jsx +37 -28
- package/templates/template_admin/public/src/hooks/useTimer.jsx +42 -0
- package/templates/template_admin/public/src/index.jsx +10 -7
- package/templates/template_admin/public/src/mock/auth.js +33 -0
- package/templates/template_admin/public/src/mock/demo.js +12 -74
- package/templates/template_admin/public/src/mock/index.js +1 -0
- package/templates/template_admin/public/src/pages/auth/user/create/index.jsx +55 -0
- package/templates/template_admin/public/src/pages/auth/user/create/index.less +6 -0
- package/templates/template_admin/public/src/pages/auth/user/dialog/index.jsx +96 -0
- package/templates/template_admin/public/src/pages/auth/user/index.jsx +271 -0
- package/templates/template_admin/public/src/pages/components/layout/index.jsx +75 -0
- package/templates/template_admin/public/src/pages/components/layout/index.less +78 -0
- package/templates/template_admin/public/src/pages/components/layout/titleBar/index.jsx +28 -0
- package/templates/template_admin/public/src/pages/components/layout/titleBar/index.less +44 -0
- package/templates/template_admin/public/src/pages/components/select/account/index.jsx +114 -0
- package/templates/template_admin/public/src/pages/components/select/device/index.jsx +83 -0
- package/templates/template_admin/public/src/pages/components/select/groupUser/index.jsx +172 -0
- package/templates/template_admin/public/src/pages/components/select/user/index.jsx +119 -0
- package/templates/template_admin/public/src/pages/home.jsx +79 -0
- package/templates/template_admin/public/src/pages/home.less +6 -0
- package/templates/template_admin/public/src/pages/login/index.jsx +90 -6
- package/templates/template_admin/public/src/pages/login/index.less +133 -24
- package/templates/template_admin/public/src/provider/app.jsx +72 -66
- package/templates/template_admin/public/src/provider/loading.jsx +47 -0
- package/templates/template_admin/public/src/provider/menu.jsx +117 -83
- package/templates/template_admin/public/src/provider/menu.less +35 -0
- package/templates/template_admin/public/src/route.jsx +41 -40
- package/templates/template_admin/public/src/services/auth.js +39 -0
- package/templates/template_admin/public/src/services/demo.js +3 -37
- package/templates/template_admin/public/src/services/index.js +139 -13
- package/templates/template_admin/public/src/services/login.js +37 -0
- package/templates/template_admin/public/src/services/socket/index.jsx +100 -0
- package/templates/template_admin/public/src/type.js +36 -19
- package/templates/template_admin/public/src/utils/event.js +58 -0
- package/templates/template_admin/public/src/utils/format.js +84 -0
- package/templates/template_admin/public/src/utils/index.js +214 -2
- package/templates/template_admin/public/src/utils/rule.js +3 -0
- package/templates/template_admin/public/static/kssoLogin.html +1 -1
- package/templates/template_admin/webpack.api.js +11 -3
- package/templates/template_admin/public/favicon.ico +0 -0
- package/templates/template_admin/public/src/assets/images/avatars/1.png +0 -0
- package/templates/template_admin/public/src/assets/images/avatars/2.png +0 -0
- package/templates/template_admin/public/src/assets/images/avatars/3.png +0 -0
- package/templates/template_admin/public/src/components/layout/centerBody/index.jsx +0 -25
- package/templates/template_admin/public/src/components/layout/centerBody/index.less +0 -30
- package/templates/template_admin/public/src/components/menu/index.less +0 -19
- package/templates/template_admin/public/src/components/menu/topMenu/index.jsx +0 -132
- package/templates/template_admin/public/src/components/menu/topMenu/index.less +0 -105
- package/templates/template_admin/public/src/pages/demo/detail/index.jsx +0 -27
- package/templates/template_admin/public/src/pages/demo/edit/index.jsx +0 -109
- package/templates/template_admin/public/src/pages/demo/index.less +0 -9
- package/templates/template_admin/public/src/pages/demo/page1.jsx +0 -161
- package/templates/template_admin/public/src/pages/superAdminLogin/index.jsx +0 -64
- package/templates/template_admin/public/src/pages/superAdminLogin/index.less +0 -44
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {GET_DEFAULT,API_ROOT,POST_DEFAULT,PUT_DEFAULT} from './index.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 获取当前用户的权限列表
|
|
6
|
+
* @returns {Promise<ServicesResponse>}
|
|
7
|
+
*/
|
|
8
|
+
export function GET_MY_AUTH(params={
|
|
9
|
+
isTree:'',
|
|
10
|
+
isShow:''
|
|
11
|
+
}){
|
|
12
|
+
return GET_DEFAULT(`${API_ROOT}/my/permissions`,params)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 获取我的角色列表
|
|
17
|
+
* @returns {Promise<ServicesResponse>}
|
|
18
|
+
*/
|
|
19
|
+
export function GET_MY_ROLES(params={}){
|
|
20
|
+
return GET_DEFAULT(`${API_ROOT}/my/roles`,params)
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 获取我的账号列表
|
|
26
|
+
* @returns {Promise<ServicesResponse>}
|
|
27
|
+
*/
|
|
28
|
+
export function GET_MY_WORK_USERS(params={}){
|
|
29
|
+
return GET_DEFAULT(`${API_ROOT}/my/weworkUsers`,params)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 切换账号列表
|
|
34
|
+
* @returns {Promise<ServicesResponse>}
|
|
35
|
+
*/
|
|
36
|
+
export function CHANGE_MY_WORK_USERS(params={}) {
|
|
37
|
+
return PUT_DEFAULT(`${API_ROOT}/my/weworkUsers/selected`,params)
|
|
38
|
+
}
|
|
39
|
+
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import {GET_DEFAULT,POST_DEFAULT,API_ROOT
|
|
3
|
+
import {GET_DEFAULT,POST_DEFAULT,API_ROOT} from './index.js';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export function GET_LIST(params) {
|
|
8
|
-
return
|
|
8
|
+
return GET_DEFAULT(`${API_ROOT}/api/demo/list`,params);
|
|
9
9
|
}
|
|
10
10
|
export function GET_DETAIL(params) {
|
|
11
11
|
return GET_DEFAULT(`${API_ROOT}/api/demo/detail`,params);
|
|
@@ -13,42 +13,8 @@ export function GET_DETAIL(params) {
|
|
|
13
13
|
export function CREATE(params) {
|
|
14
14
|
return POST_DEFAULT(`${API_ROOT}/api/demo/create`,params)
|
|
15
15
|
}
|
|
16
|
+
|
|
16
17
|
export function UPDATE(params) {
|
|
17
18
|
return POST_DEFAULT(`${API_ROOT}/api/demo/update`,params)
|
|
18
19
|
}
|
|
19
|
-
export function GET_USER_INFO(){
|
|
20
|
-
return GET_DEFAULT(`${API_ROOT}/api/demo/userInfo`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function GET_ENUM_TYPE(){
|
|
24
|
-
return GET_DEFAULT(`${API_ROOT}/api/demo/enumType`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const FormatTableService = (response)=>{
|
|
28
|
-
let req={
|
|
29
|
-
code:response[RESPONSE_STRUCT.CODE]||0,
|
|
30
|
-
data:response[RESPONSE_STRUCT.DATA]||null,
|
|
31
|
-
msg:response[RESPONSE_STRUCT.MSG]||''
|
|
32
|
-
};
|
|
33
|
-
if(response[RESPONSE_STRUCT.PAGINATION]){
|
|
34
|
-
req.page = response[RESPONSE_STRUCT.PAGINATION]
|
|
35
|
-
}
|
|
36
|
-
return req;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export function Login(params={
|
|
41
|
-
username:'',
|
|
42
|
-
password:'',
|
|
43
|
-
}){
|
|
44
|
-
return POST_DEFAULT(`${API_ROOT}/api/demo/login`,params)
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function KssoLogin(params={
|
|
49
|
-
code:'',
|
|
50
|
-
redirectUri:'',
|
|
51
|
-
}){
|
|
52
|
-
return POST_DEFAULT(`${API_ROOT}/api/demo/ksso/auth`,params)
|
|
53
20
|
|
|
54
|
-
}
|
|
@@ -4,6 +4,7 @@ import Axios from 'axios';
|
|
|
4
4
|
import qs from 'qs';
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
import { message } from 'antd';
|
|
7
|
+
import {WriteLog} from '@/utils';
|
|
7
8
|
|
|
8
9
|
const axios = Axios.create();
|
|
9
10
|
// @ts-ignore
|
|
@@ -13,8 +14,6 @@ export const API_ROOT = API_HOST;
|
|
|
13
14
|
const tokenMode='header';//header,cookie
|
|
14
15
|
const tokenName='Authorization';
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
17
|
export const RESPONSE_STRUCT={
|
|
19
18
|
CODE:'code',
|
|
20
19
|
MSG:'msg',
|
|
@@ -29,7 +28,7 @@ let Modal = {
|
|
|
29
28
|
};
|
|
30
29
|
|
|
31
30
|
let jwt = '';
|
|
32
|
-
let
|
|
31
|
+
let _logout = ()=>{}
|
|
33
32
|
|
|
34
33
|
export const setJwt = (value) => {
|
|
35
34
|
if(value==''){
|
|
@@ -41,10 +40,16 @@ export const setJwt = (value) => {
|
|
|
41
40
|
localStorage.setItem('jwt', value);
|
|
42
41
|
jwt = value;
|
|
43
42
|
};
|
|
43
|
+
export const getJwt=()=>{
|
|
44
|
+
return jwt;
|
|
45
|
+
}
|
|
44
46
|
// @ts-ignore
|
|
45
47
|
window.setJwt=setJwt;
|
|
46
48
|
export const setLogout=(fn)=>{
|
|
47
|
-
|
|
49
|
+
_logout=fn;
|
|
50
|
+
}
|
|
51
|
+
export const logout=()=>{
|
|
52
|
+
_logout();
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
|
|
@@ -65,6 +70,7 @@ axios.interceptors.request.use(function (config) {
|
|
|
65
70
|
return config;
|
|
66
71
|
});
|
|
67
72
|
|
|
73
|
+
let ERROR_401_COUNT=0;
|
|
68
74
|
/**
|
|
69
75
|
* 统一拦截异常消息弹屏报错处理
|
|
70
76
|
* 如果希望某条消息不拦截,可以再发送消息时带上 noInterceptors:true|'all'
|
|
@@ -72,36 +78,56 @@ axios.interceptors.request.use(function (config) {
|
|
|
72
78
|
axios.interceptors.response.use(
|
|
73
79
|
function (response) {
|
|
74
80
|
// setJwt(response?.headers['set-token'] || jwt);
|
|
81
|
+
ERROR_401_COUNT=0;
|
|
82
|
+
// 不需要接口统一处理异常错误
|
|
75
83
|
if (response.config.noInterceptors) {
|
|
76
84
|
return response;
|
|
77
85
|
}
|
|
86
|
+
const {data}= response;
|
|
87
|
+
const CODE = data[RESPONSE_STRUCT.CODE];
|
|
88
|
+
const MSG = data[RESPONSE_STRUCT.MSG];
|
|
78
89
|
|
|
79
|
-
if (Number(
|
|
80
|
-
console.log(`${JSON.stringify(
|
|
81
|
-
Modal.error({ title: `注意`, content: `${
|
|
90
|
+
if (Number(CODE) !== 0) {
|
|
91
|
+
console.log(`${JSON.stringify(data)}`);
|
|
92
|
+
Modal.error({ title: `注意`, content: `${MSG}(${CODE})` });
|
|
82
93
|
}
|
|
83
94
|
return response;
|
|
84
95
|
},
|
|
85
96
|
function (error) {
|
|
97
|
+
if(!error||!error.response){
|
|
98
|
+
Modal.error({
|
|
99
|
+
title: '网络错误',
|
|
100
|
+
content: error.message||'',
|
|
101
|
+
});
|
|
102
|
+
return Promise.resolve(null);
|
|
103
|
+
}
|
|
104
|
+
|
|
86
105
|
if (error.response.config.noInterceptors === 'all') {
|
|
87
|
-
return Promise.
|
|
106
|
+
return Promise.resolve(error.response);
|
|
88
107
|
}
|
|
89
108
|
// jwt失效
|
|
90
109
|
if (error.response.status === 401) {
|
|
91
|
-
if(
|
|
92
|
-
|
|
110
|
+
if(ERROR_401_COUNT>0)return;
|
|
111
|
+
if( !error.config.url.includes('passport/logOut') ){
|
|
112
|
+
Modal.error({title:'注意',content:'您的登录已过期,请尝试重新登录'});
|
|
113
|
+
ERROR_401_COUNT++;
|
|
114
|
+
WriteLog(`=重新登录=接口401(${error.config.url})`)
|
|
115
|
+
if(logout)logout();
|
|
116
|
+
}
|
|
117
|
+
return Promise.resolve(null);
|
|
93
118
|
} else if (error.response.status === 403) {
|
|
94
119
|
Modal.error({
|
|
95
120
|
title: '提示',
|
|
96
|
-
content: `${error.response.data.
|
|
121
|
+
content: `${error.response.data[RESPONSE_STRUCT.MSG]}`,
|
|
97
122
|
});
|
|
98
|
-
|
|
123
|
+
// if(logout)logout();
|
|
124
|
+
return Promise.resolve(null);
|
|
99
125
|
}
|
|
100
126
|
Modal.error({
|
|
101
127
|
title: `网络错误${error.response.status}`,
|
|
102
128
|
content: `${error.response.config.url}`,
|
|
103
129
|
});
|
|
104
|
-
return null;
|
|
130
|
+
return Promise.resolve(null);
|
|
105
131
|
}
|
|
106
132
|
);
|
|
107
133
|
|
|
@@ -222,3 +248,103 @@ export async function POST_DEFAULT_CROSS(url, params) {
|
|
|
222
248
|
|
|
223
249
|
return response && response.data ? response.data : null;
|
|
224
250
|
}
|
|
251
|
+
|
|
252
|
+
export async function PUT_DEFAULT(url,params,options) {
|
|
253
|
+
let data=params;
|
|
254
|
+
|
|
255
|
+
let response=await axios({
|
|
256
|
+
method: 'PUT',
|
|
257
|
+
url: url,
|
|
258
|
+
data,
|
|
259
|
+
...options,
|
|
260
|
+
});
|
|
261
|
+
return response&&response.data? response.data:null;
|
|
262
|
+
}
|
|
263
|
+
export async function DELETE_DEFAULT(url,params,options) {
|
|
264
|
+
let data=params;
|
|
265
|
+
|
|
266
|
+
let response=await axios({
|
|
267
|
+
method: 'DELETE',
|
|
268
|
+
url: url,
|
|
269
|
+
data,
|
|
270
|
+
...options,
|
|
271
|
+
});
|
|
272
|
+
return response&&response.data? response.data:null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
const axiosExport = Axios.create();
|
|
278
|
+
axiosExport.interceptors.request.use(function (config) {
|
|
279
|
+
const header = { 'X-Requested-With': 'XMLHttpRequest' };
|
|
280
|
+
if(tokenMode=='header'){
|
|
281
|
+
if (jwt) {
|
|
282
|
+
header[tokenName] = jwt;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (config.headers) {
|
|
286
|
+
config.headers = { ...config.headers, ...header };
|
|
287
|
+
} else {
|
|
288
|
+
config.headers = header;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 在发送请求之前做些什么
|
|
292
|
+
return config;
|
|
293
|
+
});
|
|
294
|
+
export async function EXPORT_EXCEL(url, param, options) {
|
|
295
|
+
if (param) param = qs.stringify(param, { arrayFormat: 'indices' });
|
|
296
|
+
|
|
297
|
+
let response = await axiosExport({
|
|
298
|
+
method: 'GET',
|
|
299
|
+
url: param ? `${url}?${param}` : url,
|
|
300
|
+
responseType: 'blob',
|
|
301
|
+
getResponse: true,
|
|
302
|
+
...options,
|
|
303
|
+
});
|
|
304
|
+
let fileType = response.headers.get('content-type');
|
|
305
|
+
const disposition = response.headers.get('content-disposition');
|
|
306
|
+
|
|
307
|
+
const blob = new Blob([response.data], { type: `${fileType},charset=UTF-8` });
|
|
308
|
+
const fileName = decodeURI(
|
|
309
|
+
disposition ? disposition.split(';')[1].split('filename=')[1] : 'download.xlsx',
|
|
310
|
+
);
|
|
311
|
+
let blobUrl = window.URL.createObjectURL(blob);
|
|
312
|
+
|
|
313
|
+
const link = document.createElement('a');
|
|
314
|
+
link.href = blobUrl;
|
|
315
|
+
link.download = fileName.replace(/"/g, '');
|
|
316
|
+
document.body.appendChild(link);
|
|
317
|
+
link.style.display='none';
|
|
318
|
+
link.click();
|
|
319
|
+
link.remove();
|
|
320
|
+
setTimeout(() => window.URL.revokeObjectURL(blobUrl), 1000);
|
|
321
|
+
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
export const FormatTableService = (response)=>{
|
|
327
|
+
let req={
|
|
328
|
+
code:response[RESPONSE_STRUCT.CODE]||0,
|
|
329
|
+
data:response[RESPONSE_STRUCT.DATA]||null,
|
|
330
|
+
msg:response[RESPONSE_STRUCT.MSG]||''
|
|
331
|
+
};
|
|
332
|
+
if(response[RESPONSE_STRUCT.PAGINATION]){
|
|
333
|
+
req.page = response[RESPONSE_STRUCT.PAGINATION]
|
|
334
|
+
}
|
|
335
|
+
return req;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 格式化处理GET请求的参数,将传参为空的删除掉,因为后端认为空字符串也是属于一个特定字符查询
|
|
340
|
+
* @param {object} requestParams
|
|
341
|
+
* @returns {object}
|
|
342
|
+
*/
|
|
343
|
+
export const FormatGetRequest=(requestParams)=>{
|
|
344
|
+
for(let key in requestParams){
|
|
345
|
+
if(requestParams[key]==''||requestParams[key]===null){
|
|
346
|
+
delete requestParams[key];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return requestParams;
|
|
350
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {GET_DEFAULT,API_ROOT,POST_DEFAULT,PUT_DEFAULT} from './index.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* KSSO登录
|
|
7
|
+
* @returns {Promise<ServicesResponse>}
|
|
8
|
+
*/
|
|
9
|
+
export function KSSO_LOGIN(params={
|
|
10
|
+
code:'',
|
|
11
|
+
redirect_uri:''
|
|
12
|
+
}){
|
|
13
|
+
return Promise.resolve({
|
|
14
|
+
code:0,
|
|
15
|
+
data:{
|
|
16
|
+
token:'123',
|
|
17
|
+
name:'cx'
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
return GET_DEFAULT(`${API_ROOT}/auth/oauth2_generic/callback`,params)
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 退出登录
|
|
26
|
+
* @returns {Promise<ServicesResponse>}
|
|
27
|
+
*/
|
|
28
|
+
export function Logout(){
|
|
29
|
+
return Promise.resolve({
|
|
30
|
+
code:0,
|
|
31
|
+
data:{
|
|
32
|
+
token:'123',
|
|
33
|
+
name:'cx'
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
return POST_DEFAULT(`${API_ROOT}/passport/logOut`,{},{noInterceptors:'all'})
|
|
37
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
|
|
2
|
+
import {getJwt} from '@/services'
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import {Modal} from 'antd';
|
|
5
|
+
|
|
6
|
+
import { CONSOLE_LOG ,WriteLog} from '@/utils';
|
|
7
|
+
import {logout} from '@/services'
|
|
8
|
+
let _ws;
|
|
9
|
+
let timer=null;
|
|
10
|
+
|
|
11
|
+
const MODULE_NAME='Websocket'
|
|
12
|
+
|
|
13
|
+
const CHECK_PING_PONG=true;
|
|
14
|
+
const TIME_OUT=15000;
|
|
15
|
+
const HEART_TICK=5000;
|
|
16
|
+
|
|
17
|
+
export const GET_SOCKET=()=>{
|
|
18
|
+
if(_ws)return _ws;
|
|
19
|
+
let token = getJwt();
|
|
20
|
+
let alertCount=0;
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
_ws = new WebSocket(WS_HOST+`?bearer_token=${token}`);
|
|
23
|
+
|
|
24
|
+
let lastPongTime;
|
|
25
|
+
const startHeartbeat=()=> {
|
|
26
|
+
if(timer){window.clearInterval(timer);}
|
|
27
|
+
timer = window.setInterval(function() {
|
|
28
|
+
if (_ws && _ws.readyState === WebSocket.OPEN) {
|
|
29
|
+
if(!lastPongTime){
|
|
30
|
+
lastPongTime = Date.now();
|
|
31
|
+
}
|
|
32
|
+
if( CHECK_PING_PONG && Date.now() - lastPongTime >= TIME_OUT){
|
|
33
|
+
clear();
|
|
34
|
+
Modal.error({
|
|
35
|
+
title: '网络连接中断',
|
|
36
|
+
content: '请重新连接',
|
|
37
|
+
okText:'重新连接',
|
|
38
|
+
onOk:()=>{
|
|
39
|
+
GET_SOCKET();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
_ws.send('ping');
|
|
45
|
+
}
|
|
46
|
+
}, HEART_TICK); // 每5秒发送一次ping
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const clear=()=>{
|
|
50
|
+
if(timer){window.clearInterval(timer);}
|
|
51
|
+
_ws=null;
|
|
52
|
+
}
|
|
53
|
+
_ws.onopen=()=>{
|
|
54
|
+
alertCount=0;
|
|
55
|
+
CONSOLE_LOG(MODULE_NAME,'connect success')
|
|
56
|
+
startHeartbeat();
|
|
57
|
+
}
|
|
58
|
+
_ws.onmessage = function(event) {
|
|
59
|
+
if(event.data == 'pong' || event.data=='ping'){
|
|
60
|
+
lastPongTime = Date.now();
|
|
61
|
+
_ws.send('pong');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const {type,data} = JSON.parse(event.data);
|
|
65
|
+
CONSOLE_LOG(MODULE_NAME,'new msg',type,data)
|
|
66
|
+
switch(type){
|
|
67
|
+
case 'Pong':{}break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_ws.onerror=function(e){
|
|
72
|
+
CONSOLE_LOG.error(MODULE_NAME,'error',e,alertCount)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_ws.onclose = function(e) {
|
|
76
|
+
CONSOLE_LOG.error(MODULE_NAME,'close',e,alertCount)
|
|
77
|
+
if(alertCount>0){return;}
|
|
78
|
+
const {code} =e;
|
|
79
|
+
clear();
|
|
80
|
+
alertCount++;
|
|
81
|
+
|
|
82
|
+
Modal.error({
|
|
83
|
+
title: '网络连接中断websocket',
|
|
84
|
+
content: `请重新登录(${code})`,
|
|
85
|
+
okText:'重新登录',
|
|
86
|
+
onOk:()=>{
|
|
87
|
+
WriteLog(`=重新登录=socket断开(${code})`);
|
|
88
|
+
// GET_SOCKET();
|
|
89
|
+
logout();
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return _ws;
|
|
95
|
+
}
|
|
96
|
+
export const WS_SEND=(message)=>{
|
|
97
|
+
const ws = GET_SOCKET();
|
|
98
|
+
ws.send(message);
|
|
99
|
+
}
|
|
100
|
+
|
|
@@ -11,22 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @typedef {object} FormDataInfo
|
|
17
|
-
* @property {string} btnControl
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {[FormDataInfo,Function]} UseStateFormData
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {FormDataInfo & OtherAny} TableContentData
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
14
|
/**
|
|
31
15
|
* 分页
|
|
32
16
|
* @typedef {object} Pagination
|
|
@@ -38,11 +22,44 @@
|
|
|
38
22
|
*/
|
|
39
23
|
|
|
40
24
|
|
|
25
|
+
|
|
41
26
|
/**
|
|
42
27
|
* 接口response数据
|
|
28
|
+
* @template [T=object]
|
|
43
29
|
* @typedef {object} ServicesResponse
|
|
44
30
|
* @property {number} code - 接口处理结果,0为成功
|
|
45
|
-
* @property {
|
|
46
|
-
* @property {Pagination} page - 分页数据
|
|
31
|
+
* @property {T} data - 接口返回的数据
|
|
32
|
+
* @property {Pagination} [page] - 分页数据
|
|
33
|
+
* @property {string} [msg] - 消息内容
|
|
47
34
|
*
|
|
48
|
-
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 设置菜单属性
|
|
42
|
+
* @typedef MenuConfig
|
|
43
|
+
* @property {string} primaryId - 菜单的primaryId值
|
|
44
|
+
* @property {('msgCount'|'icon'|'name')} key - 需要设置的字段名称
|
|
45
|
+
* @property {any} value - 字段值
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 菜单项
|
|
50
|
+
* @typedef RouteMenuItem
|
|
51
|
+
* @property {string} name - 菜单展示的名称
|
|
52
|
+
* @property {string|JSX.Element} [icon] - 菜单图标
|
|
53
|
+
* @property {string} [url] - 菜单的URL地址
|
|
54
|
+
* @property {string} [routeTemplate] - 菜单的路由模版,用于匹配动态路由
|
|
55
|
+
* @property {number} [msgCount] - 菜单的未读消息数量
|
|
56
|
+
* @property {boolean} [hideMenu=false] - 是否为隐藏的菜单,隐藏的菜单不会展示独立菜单,但是会匹配路由
|
|
57
|
+
* @property {string[]|boolean} [auth] - 允许访问该菜单的权限列表
|
|
58
|
+
* @property {RouteMenuItem[]} [children] - 子菜单
|
|
59
|
+
* @property {string} [primaryId] - 菜单的唯一ID,如果存在primaryId,则菜单的key同primaryId
|
|
60
|
+
* @property {string} [key] - 会自动生成的菜单唯一ID,如果菜单配置内存在了primaryId,则会取该id
|
|
61
|
+
* @property {string} [parentKey] - 父级菜单的key,自动生成的
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import {CONSOLE_LOG} from '@/utils';
|
|
4
|
+
const events={}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const MODULE_NAME='EventBus'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 监听消息
|
|
11
|
+
* @param {import('../enum').ENUM_EVENT_BUS_TYPE} type
|
|
12
|
+
* @param {(params:object)=>void} fn
|
|
13
|
+
*/
|
|
14
|
+
export const addEventListener=(type,fn)=>{
|
|
15
|
+
const list = events[type]=events[type]||[];
|
|
16
|
+
list.push(fn);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 移除监听消息
|
|
21
|
+
* @param {import('../enum').ENUM_EVENT_BUS_TYPE} type
|
|
22
|
+
* @param {(params:object)=>void} fn
|
|
23
|
+
*/
|
|
24
|
+
export const removeEventListener=(type,fn)=>{
|
|
25
|
+
const list = events[type]=events[type]||[];
|
|
26
|
+
for(let i=0;i<list.length;i++){
|
|
27
|
+
let _fn = list[i];
|
|
28
|
+
if(fn==_fn){
|
|
29
|
+
list.splice(i,1);
|
|
30
|
+
i--;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 广播消息
|
|
37
|
+
* @param {import('../enum').ENUM_EVENT_BUS_TYPE} type
|
|
38
|
+
* @param {object} params
|
|
39
|
+
*/
|
|
40
|
+
export const broadcast=(type,params)=>{
|
|
41
|
+
CONSOLE_LOG(MODULE_NAME,'广播',type,params)
|
|
42
|
+
const list = events[type]=events[type]||[];
|
|
43
|
+
for(let i=0;i<list.length;i++){
|
|
44
|
+
let _fn = list[i];
|
|
45
|
+
_fn(params);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export default {
|
|
52
|
+
addEventListener,
|
|
53
|
+
removeEventListener,
|
|
54
|
+
broadcast
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import moment from 'moment';
|
|
1
3
|
|
|
2
4
|
/**
|
|
3
5
|
* 格式化为货币格式
|
|
@@ -48,4 +50,86 @@ export const formatPhone=(value,extra={noValue:'-'})=>{
|
|
|
48
50
|
return value.replace(/(\d)(?=(\d{4})+$)/g, '$1-');
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
/**
|
|
54
|
+
* 文件大小展示转化为B、KB、MB
|
|
55
|
+
* @param {number} fileSize - 文件大小,单位bit
|
|
56
|
+
*/
|
|
57
|
+
export const formatFileSize=(fileSize)=>{
|
|
58
|
+
if(fileSize<1024){
|
|
59
|
+
return fileSize+'B';
|
|
60
|
+
}
|
|
61
|
+
if(fileSize<(1024*1024)){
|
|
62
|
+
const size=(fileSize/1024).toFixed(1);
|
|
63
|
+
return size + 'KB';
|
|
64
|
+
}
|
|
65
|
+
if(fileSize < (1024 * 1024 * 1024)){
|
|
66
|
+
const size=(fileSize/(1024 * 1024)).toFixed(1);
|
|
67
|
+
return size+'M';
|
|
68
|
+
}
|
|
69
|
+
const size=(fileSize/(1024*1024*1024)).toFixed(1);
|
|
70
|
+
return size+'G';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 格式化用户名称
|
|
76
|
+
* @param {object} user
|
|
77
|
+
* @returns {string}
|
|
78
|
+
*/
|
|
79
|
+
export const formatUserName=(user)=>{
|
|
80
|
+
if(user.status==0){
|
|
81
|
+
return `${user.name}[已禁用]`;
|
|
82
|
+
}
|
|
83
|
+
return user.name;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* @param {moment|string} momentTime
|
|
89
|
+
* @param {string} type='minute' 'minute':精确到分钟 ,默认:精确到最大单位
|
|
90
|
+
*
|
|
91
|
+
* @returns {string}
|
|
92
|
+
*/
|
|
93
|
+
export const fromNow=(momentTime,type='minute')=>{
|
|
94
|
+
var now = moment();
|
|
95
|
+
if(!moment.isMoment(momentTime)){
|
|
96
|
+
momentTime = moment(momentTime)
|
|
97
|
+
}
|
|
98
|
+
var duration = moment.duration(now.diff(momentTime));
|
|
99
|
+
|
|
100
|
+
// 获取小时和分钟
|
|
101
|
+
var days = Math.floor(duration.asDays());
|
|
102
|
+
var months = Math.floor(duration.asMonths());
|
|
103
|
+
var years = Math.floor(duration.asYears());
|
|
104
|
+
|
|
105
|
+
var hours = Math.floor(duration.asHours());
|
|
106
|
+
var minutes = duration.minutes();
|
|
107
|
+
// var seconds = duration.seconds();
|
|
108
|
+
|
|
109
|
+
if(years>0){
|
|
110
|
+
return momentTime.format('YYYY-MM-DD')
|
|
111
|
+
return `${years}年前`;
|
|
112
|
+
}
|
|
113
|
+
if(months>0){
|
|
114
|
+
return momentTime.format('MM-DD');
|
|
115
|
+
return `${months}个月前`;
|
|
116
|
+
}
|
|
117
|
+
if(days>0){
|
|
118
|
+
return `${days}天前`;
|
|
119
|
+
}
|
|
120
|
+
if(hours>0){
|
|
121
|
+
if(type=='hour'){
|
|
122
|
+
return `${hours}小时前`;
|
|
123
|
+
}
|
|
124
|
+
if(minutes<=0){
|
|
125
|
+
return `${hours}小时前`;
|
|
126
|
+
}else{
|
|
127
|
+
return `${hours}小时${minutes}分钟前`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if(minutes>0){
|
|
131
|
+
return `${minutes}分钟前`;
|
|
132
|
+
}
|
|
133
|
+
return '刚刚';
|
|
134
|
+
}
|
|
51
135
|
|