kn-cli 1.0.96 → 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.
Files changed (135) hide show
  1. package/build/package.json +1 -0
  2. package/package.json +1 -1
  3. package/readme.md +3 -0
  4. package/templates/template_admin/cli.config.js +4 -1
  5. package/templates/template_admin/package.json +7 -1
  6. package/templates/template_admin/public/favicon.png +0 -0
  7. package/templates/template_admin/public/index.html +6 -4
  8. package/templates/template_admin/public/src/_antd.less +30 -3
  9. package/templates/template_admin/public/src/_mixin.less +41 -0
  10. package/templates/template_admin/public/src/_reset.less +28 -20
  11. package/templates/template_admin/public/src/_variable.less +11 -6
  12. package/templates/template_admin/public/src/assets/iconfont/iconfont.eot +0 -0
  13. package/templates/template_admin/public/src/assets/iconfont/iconfont.less +60 -8
  14. package/templates/template_admin/public/src/assets/iconfont/iconfont.svg +57 -18
  15. package/templates/template_admin/public/src/assets/iconfont/iconfont.ttf +0 -0
  16. package/templates/template_admin/public/src/assets/iconfont/iconfont.woff +0 -0
  17. package/templates/template_admin/public/src/assets/iconfont/iconfont.woff2 +0 -0
  18. package/templates/template_admin/public/src/assets/images/arrow.png +0 -0
  19. package/templates/template_admin/public/src/assets/images/icon-notice.png +0 -0
  20. package/templates/template_admin/public/src/assets/images/icon-user.png +0 -0
  21. package/templates/template_admin/public/src/assets/images/loadFail.png +0 -0
  22. package/templates/template_admin/public/src/assets/images/login/bg.png +0 -0
  23. package/templates/template_admin/public/src/assets/images/login/logo.png +0 -0
  24. package/templates/template_admin/public/src/assets/images/login/slogan.png +0 -0
  25. package/templates/template_admin/public/src/assets/images/nav/icon-dep-active.png +0 -0
  26. package/templates/template_admin/public/src/assets/images/nav/icon-dep.png +0 -0
  27. package/templates/template_admin/public/src/assets/images/nav/icon-log-active.png +0 -0
  28. package/templates/template_admin/public/src/assets/images/nav/icon-log.png +0 -0
  29. package/templates/template_admin/public/src/assets/images/nav/icon-loginlog-active.png +0 -0
  30. package/templates/template_admin/public/src/assets/images/nav/icon-loginlog.png +0 -0
  31. package/templates/template_admin/public/src/assets/images/nav/icon-role-active.png +0 -0
  32. package/templates/template_admin/public/src/assets/images/nav/icon-role.png +0 -0
  33. package/templates/template_admin/public/src/assets/images/nav/icon-user-active.png +0 -0
  34. package/templates/template_admin/public/src/assets/images/nav/icon-user.png +0 -0
  35. package/templates/template_admin/public/src/assets/images/nav/nav-toggle.png +0 -0
  36. package/templates/template_admin/public/src/assets/images/nav/slogan.png +0 -0
  37. package/templates/template_admin/public/src/assets/images/noData.png +0 -0
  38. package/templates/template_admin/public/src/assets/images/noSelect.png +0 -0
  39. package/templates/template_admin/public/src/components/auth/index.jsx +7 -3
  40. package/templates/template_admin/public/src/components/auth/index.less +7 -0
  41. package/templates/template_admin/public/src/components/badge/index.jsx +47 -0
  42. package/templates/template_admin/public/src/components/badge/index.less +44 -0
  43. package/templates/template_admin/public/src/components/debug/index.jsx +27 -0
  44. package/templates/template_admin/public/src/components/debug/index.less +9 -0
  45. package/templates/template_admin/public/src/components/empty/index.jsx +28 -0
  46. package/templates/template_admin/public/src/components/empty/index.less +20 -0
  47. package/templates/template_admin/public/src/components/image/index.jsx +73 -0
  48. package/templates/template_admin/public/src/components/image/index.less +117 -0
  49. package/templates/template_admin/public/src/components/image/preview.jsx +85 -0
  50. package/templates/template_admin/public/src/components/layout/basic/index.jsx +24 -11
  51. package/templates/template_admin/public/src/components/layout/basic/index.less +58 -19
  52. package/templates/template_admin/public/src/components/layout/index.jsx +20 -17
  53. package/templates/template_admin/public/src/components/layout/index.less +4 -4
  54. package/templates/template_admin/public/src/components/layout/provider/index.jsx +19 -6
  55. package/templates/template_admin/public/src/components/{menu → leftMenu}/index.jsx +20 -28
  56. package/templates/template_admin/public/src/components/leftMenu/index.less +42 -0
  57. package/templates/template_admin/public/src/components/popup/index.jsx +25 -0
  58. package/templates/template_admin/public/src/components/table/column.jsx +47 -0
  59. package/templates/template_admin/public/src/components/table/column.less +12 -0
  60. package/templates/template_admin/public/src/components/table/index.jsx +22 -13
  61. package/templates/template_admin/public/src/components/table/index.less +15 -0
  62. package/templates/template_admin/public/src/components/text/index.jsx +98 -0
  63. package/templates/template_admin/public/src/components/text/index.less +13 -0
  64. package/templates/template_admin/public/src/components/topMenu/index.jsx +97 -0
  65. package/templates/template_admin/public/src/components/topMenu/index.less +80 -0
  66. package/templates/template_admin/public/src/components/topMenu/topBar/index.jsx +76 -0
  67. package/templates/template_admin/public/src/components/topMenu/topBar/index.less +88 -0
  68. package/templates/template_admin/public/src/components/video/index.jsx +96 -0
  69. package/templates/template_admin/public/src/components/video/index.less +132 -0
  70. package/templates/template_admin/public/src/components/video/preview.jsx +38 -0
  71. package/templates/template_admin/public/src/dictionary/index.js +108 -39
  72. package/templates/template_admin/public/src/enum.js +41 -0
  73. package/templates/template_admin/public/src/hooks/index.jsx +8 -6
  74. package/templates/template_admin/public/src/hooks/useDebounceFn.jsx +33 -0
  75. package/templates/template_admin/public/src/hooks/useInToView.jsx +58 -0
  76. package/templates/template_admin/public/src/hooks/useRouteMenu.jsx +37 -28
  77. package/templates/template_admin/public/src/hooks/useTimer.jsx +42 -0
  78. package/templates/template_admin/public/src/index.jsx +10 -7
  79. package/templates/template_admin/public/src/mock/auth.js +33 -0
  80. package/templates/template_admin/public/src/mock/demo.js +12 -74
  81. package/templates/template_admin/public/src/mock/index.js +1 -0
  82. package/templates/template_admin/public/src/pages/auth/user/create/index.jsx +55 -0
  83. package/templates/template_admin/public/src/pages/auth/user/create/index.less +6 -0
  84. package/templates/template_admin/public/src/pages/auth/user/dialog/index.jsx +96 -0
  85. package/templates/template_admin/public/src/pages/auth/user/index.jsx +271 -0
  86. package/templates/template_admin/public/src/pages/components/layout/index.jsx +75 -0
  87. package/templates/template_admin/public/src/pages/components/layout/index.less +78 -0
  88. package/templates/template_admin/public/src/pages/components/layout/titleBar/index.jsx +28 -0
  89. package/templates/template_admin/public/src/pages/components/layout/titleBar/index.less +44 -0
  90. package/templates/template_admin/public/src/pages/components/select/account/index.jsx +114 -0
  91. package/templates/template_admin/public/src/pages/components/select/device/index.jsx +83 -0
  92. package/templates/template_admin/public/src/pages/components/select/groupUser/index.jsx +172 -0
  93. package/templates/template_admin/public/src/pages/components/select/user/index.jsx +119 -0
  94. package/templates/template_admin/public/src/pages/home.jsx +79 -0
  95. package/templates/template_admin/public/src/pages/home.less +6 -0
  96. package/templates/template_admin/public/src/pages/login/index.jsx +90 -6
  97. package/templates/template_admin/public/src/pages/login/index.less +133 -24
  98. package/templates/template_admin/public/src/provider/app.jsx +72 -66
  99. package/templates/template_admin/public/src/provider/loading.jsx +47 -0
  100. package/templates/template_admin/public/src/provider/menu.jsx +117 -83
  101. package/templates/template_admin/public/src/provider/menu.less +35 -0
  102. package/templates/template_admin/public/src/route.jsx +41 -40
  103. package/templates/template_admin/public/src/services/auth.js +39 -0
  104. package/templates/template_admin/public/src/services/demo.js +3 -37
  105. package/templates/template_admin/public/src/services/index.js +139 -13
  106. package/templates/template_admin/public/src/services/login.js +37 -0
  107. package/templates/template_admin/public/src/services/socket/index.jsx +100 -0
  108. package/templates/template_admin/public/src/type.js +36 -19
  109. package/templates/template_admin/public/src/utils/event.js +58 -0
  110. package/templates/template_admin/public/src/utils/format.js +84 -0
  111. package/templates/template_admin/public/src/utils/index.js +214 -2
  112. package/templates/template_admin/public/src/utils/rule.js +3 -0
  113. package/templates/template_admin/public/static/kssoLogin.html +1 -1
  114. package/templates/template_admin/webpack.api.js +11 -3
  115. package/src/.DS_Store +0 -0
  116. package/templates/template_admin/.gitignore +0 -6
  117. package/templates/template_admin/public/favicon.ico +0 -0
  118. package/templates/template_admin/public/src/assets/images/avatars/1.png +0 -0
  119. package/templates/template_admin/public/src/assets/images/avatars/2.png +0 -0
  120. package/templates/template_admin/public/src/assets/images/avatars/3.png +0 -0
  121. package/templates/template_admin/public/src/components/layout/centerBody/index.jsx +0 -25
  122. package/templates/template_admin/public/src/components/layout/centerBody/index.less +0 -30
  123. package/templates/template_admin/public/src/components/menu/index.less +0 -19
  124. package/templates/template_admin/public/src/components/menu/topMenu/index.jsx +0 -132
  125. package/templates/template_admin/public/src/components/menu/topMenu/index.less +0 -105
  126. package/templates/template_admin/public/src/pages/demo/detail/index.jsx +0 -27
  127. package/templates/template_admin/public/src/pages/demo/edit/index.jsx +0 -109
  128. package/templates/template_admin/public/src/pages/demo/index.less +0 -9
  129. package/templates/template_admin/public/src/pages/demo/page1.jsx +0 -161
  130. package/templates/template_admin/public/src/pages/superAdminLogin/index.jsx +0 -64
  131. package/templates/template_admin/public/src/pages/superAdminLogin/index.less +0 -44
  132. package/templates/template_app/.gitignore +0 -6
  133. package/templates/template_oa/.gitignore +0 -6
  134. package/templates/template_oa_jwt/.gitignore +0 -6
  135. package/templates/template_offcial/.gitignore +0 -6
@@ -0,0 +1,35 @@
1
+
2
+
3
+
4
+ .iconGroup{
5
+ width: 17px;
6
+ height: 100%;
7
+ margin-right: 12px;
8
+ display: inline-flex;
9
+ align-items: center;
10
+
11
+ img{width: 100%;}
12
+ .icon{
13
+ display: inline-block;
14
+ }
15
+ .iconActive{
16
+ display: none;
17
+ }
18
+ }
19
+
20
+ :global(.ant-menu-title-content){
21
+ font-size: 14px;
22
+ }
23
+ :global(.ant-menu-item-selected),
24
+ :global(.ant-menu-item-active){
25
+ .iconGroup .iconActive{
26
+ display: inline-block;
27
+ }
28
+ .iconGroup .icon{
29
+ display: none;
30
+ }
31
+ :global(.ant-menu-title-content){
32
+ font-weight: bold;
33
+ }
34
+
35
+ }
@@ -1,43 +1,39 @@
1
-
2
- // @ts-ignore
3
1
  import React,{Suspense} from 'react';
4
2
  // @ts-ignore
5
3
  import { Routes, Route, Navigate } from 'react-router-dom';
6
-
7
- import { LayoutBasic, Layout } from '@/components/layout';
4
+ // @ts-ignore
5
+ import { LayoutBasic, AbsoluteLayout } from '@/components/layout';
8
6
  import PageLoading from '@/components/page/pageLoading';
7
+ import { AuthLogin } from '@/components/auth';
9
8
 
10
- import Login from '@/pages/login';
11
- import {AuthLogin} from '@/components/auth';
12
- import LeftMenu from '@/components/menu';
13
- import TopMenu from '@/components/menu/topMenu';
14
-
9
+ import LeftMenu from '@/components/leftMenu';
10
+ import TopMenu from '@/components/topMenu';
15
11
  import ProviderMenu from '@/provider/menu';
16
12
 
17
- const delayLoader=(loader)=>{
18
- return new Promise(resolve=>{
19
- loader.then(req=>{
20
- setTimeout(()=>{
21
- resolve(req);
22
- },5000)
23
- })
24
- })
25
- }
13
+ import Login from '@/pages/login';
14
+ import Home from '@/pages/home';
26
15
 
16
+ const AuthUser = React.lazy(() => import('@/pages/auth/user'));
17
+ const AuthUserCreate = React.lazy(() => import('@/pages/auth/user/create'));
27
18
 
28
- const Page1 = React.lazy(()=>import('@/pages/demo/page1'));
29
- const Page1Detail = React.lazy(()=>import('@/pages/demo/detail'));
30
19
 
31
- import SuperAdminLogin from '@/pages/superAdminLogin';
20
+
21
+ import Test from '@/pages/test';
32
22
 
33
23
 
34
24
 
35
25
 
36
26
  export const RouteList = (
37
27
  <Routes>
38
- <Route path='/' element={<Suspense fallback={<PageLoading />}><Layout /></Suspense>}>
28
+ <Route path='/' element={
29
+ <Suspense fallback={<PageLoading />}>
30
+ <AbsoluteLayout />
31
+ </Suspense>}
32
+ >
39
33
  <Route path='login' element={<Login />} />
40
- <Route path='superAdminLogin' element={<SuperAdminLogin />} />
34
+ <Route path='test' element={
35
+ <Test />
36
+ } />
41
37
 
42
38
  <Route
43
39
  path='/'
@@ -47,23 +43,28 @@ export const RouteList = (
47
43
  </ProviderMenu.Provider>
48
44
  }
49
45
  >
50
- <Route path='/' element={<Navigate to="/demo/page1"></Navigate> } />
51
- <Route path='/demo/page1' element={<Page1 label='内容管理1' />} />
52
- <Route path='/demo/page2' element={<Page1 label='内容管理2' />} />
53
- <Route path='/demo/page1/detail/:id' element={<Page1Detail />} />
54
- <Route path='/demo/page2/detail/:id' element={<Page1Detail />} />
55
-
56
-
57
- <Route path='/demo/data/page1' element={<Page1 label='数据管理1' />} />
58
- <Route path='/demo/data/page2' element={<Page1 label='数据管理2' />} />
59
- <Route path='/demo/data/page1/detail/:id' element={<Page1Detail />} />
60
- <Route path='/demo/data/page2/detail/:id' element={<Page1Detail />} />
61
-
62
- <Route path='/demo/admin' element={<Navigate to="/demo/admin/page1"></Navigate> } />
63
- <Route path='/demo/admin/page1' element={<Page1 label='权限管理1' />} />
64
- <Route path='/demo/admin/page2' element={<Page1 label='权限管理2' />} />
65
- <Route path='/demo/admin/page1/detail/:id' element={<Page1Detail />} />
66
- <Route path='/demo/admin/page2/detail/:id' element={<Page1Detail />} />
46
+ <Route path='/' element={<Navigate to="/auth/user" />} />
47
+ <Route path='/auth' element={<Navigate to="/auth/user" />} />
48
+
49
+ {/* 控制室-用户 */}
50
+ <Route path='/auth/user' element={<AuthUser />} />
51
+ {/* 控制室-用户-新建用户 */}
52
+ <Route path='/auth/user/create' element={<AuthUserCreate />} />
53
+ {/* 控制室-角色 */}
54
+ <Route path='/auth/role' element={<Home />} />
55
+ {/* 控制室-操作记录 */}
56
+ <Route path='/auth/log' element={<Home />} />
57
+ {/* 控制室-登录日志 */}
58
+ <Route path='/auth/loginLog' element={<Home />} />
59
+
60
+
61
+ <Route path='/jet' element={<Home />} />
62
+ <Route path='/store' element={<Home />} />
63
+ <Route path='/parts' element={<Home />} />
64
+ <Route path='/dna' element={<Home />} />
65
+ <Route path='/auth/dep' element={<Home />} />
66
+
67
+
67
68
 
68
69
 
69
70
  </Route>
@@ -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,RESPONSE_STRUCT} from './index.js';
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 GET_DEFAULT(`${API_ROOT}/api/demo/list`,params);
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 logout = ()=>{}
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
- logout=fn;
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(response.data.code) !== 0) {
80
- console.log(`${JSON.stringify(response.data)}`);
81
- Modal.error({ title: `注意`, content: `${response.data.message}(${response.data.code})` });
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.reject(error.response);
106
+ return Promise.resolve(error.response);
88
107
  }
89
108
  // jwt失效
90
109
  if (error.response.status === 401) {
91
- if(logout)logout();
92
- return;
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.message}`,
121
+ content: `${error.response.data[RESPONSE_STRUCT.MSG]}`,
97
122
  });
98
- return;
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 {object} data - 接口返回的数据
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
+