nsgm-cli 2.0.11 → 2.0.14

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 (65) hide show
  1. package/.babelrc +12 -12
  2. package/LICENSE +201 -201
  3. package/README.md +161 -161
  4. package/client/layout/index.tsx +248 -248
  5. package/client/redux/reducers.ts +4 -4
  6. package/client/redux/store.ts +50 -50
  7. package/client/redux/template/manage/actions.ts +190 -190
  8. package/client/redux/template/manage/reducers.ts +118 -118
  9. package/client/redux/template/manage/types.ts +24 -24
  10. package/client/service/template/manage.ts +96 -96
  11. package/client/styled/common.ts +60 -60
  12. package/client/styled/layout/index.ts +25 -25
  13. package/client/styled/template/manage.ts +51 -51
  14. package/client/utils/common.ts +89 -89
  15. package/client/utils/cookie.ts +51 -51
  16. package/client/utils/fetch.ts +25 -25
  17. package/client/utils/menu.tsx +27 -27
  18. package/client/utils/sso.ts +205 -205
  19. package/generation/.babelrc +10 -10
  20. package/generation/README.md +19 -19
  21. package/generation/app.js +2 -2
  22. package/generation/client/redux/reducers.ts +4 -4
  23. package/generation/client/utils/menu.tsx +27 -27
  24. package/generation/gitignore +4 -4
  25. package/generation/mysql.config.js +12 -12
  26. package/generation/next.config.js +6 -6
  27. package/generation/package.json +24 -24
  28. package/generation/project.config.js +13 -13
  29. package/generation/server/rest.js +23 -23
  30. package/generation/server/utils/common.js +6 -6
  31. package/generation/tsconfig.json +30 -30
  32. package/index.js +10 -10
  33. package/lib/args.d.ts +6 -6
  34. package/lib/args.js +53 -53
  35. package/lib/generate.d.ts +3 -3
  36. package/lib/generate.js +751 -751
  37. package/lib/index.d.ts +2 -2
  38. package/lib/index.js +272 -272
  39. package/lib/server/db.d.ts +5 -5
  40. package/lib/server/db.js +110 -110
  41. package/lib/server/graphql.d.ts +7 -7
  42. package/lib/server/graphql.js +119 -119
  43. package/lib/server/plugins/date.d.ts +5 -5
  44. package/lib/server/plugins/date.js +16 -16
  45. package/lib/tsconfig.build.tsbuildinfo +1 -1
  46. package/mysql.config.js +14 -14
  47. package/next-env.d.ts +5 -5
  48. package/next.config.js +231 -231
  49. package/package.json +127 -126
  50. package/pages/_app.tsx +54 -54
  51. package/pages/_document.tsx +55 -55
  52. package/pages/index.tsx +68 -68
  53. package/pages/login.tsx +78 -78
  54. package/pages/template/manage.tsx +299 -278
  55. package/project.config.js +16 -16
  56. package/public/slbhealthcheck.html +9 -9
  57. package/scripts/shutdown.sh +9 -9
  58. package/scripts/startup.sh +34 -34
  59. package/server/apis/sso.js +43 -43
  60. package/server/apis/template.js +37 -17
  61. package/server/modules/template/resolver.js +225 -225
  62. package/server/modules/template/schema.js +33 -33
  63. package/server/rest.js +24 -24
  64. package/server/sql/template.sql +8 -8
  65. package/server/utils/common.js +6 -6
@@ -1,52 +1,52 @@
1
- import _ from 'lodash'
2
-
3
- export const setCookie = (name: string, value:string, cookieExpire:any) => {
4
- const currentDate = new Date()
5
- const currentTime = currentDate.getTime()
6
- let expiresTime = currentDate
7
- expiresTime.setTime(currentTime + 60 * 1000 * 60 * 24 * 30)
8
-
9
- if (typeof document !== 'undefined') {
10
- let cookie = name + '=' + window.btoa(encodeURIComponent(value))
11
- // let cookie = name + '=' + encodeURIComponent(value)
12
- if (cookieExpire) {
13
- cookie += ";expires=" + cookieExpire
14
- } else {
15
- cookie += ";expires=" + expiresTime.toUTCString()
16
- }
17
-
18
- cookie += ";path=/"
19
- document.cookie = cookie
20
- }
21
- }
22
-
23
- export const getCookie = (name: string) => {
24
- let result = ''
25
- if (typeof document !== 'undefined') {
26
- const cookie = document.cookie
27
- // console.log('cookie', cookie)
28
-
29
- const cookieArr = cookie.split("; ")
30
-
31
- _.each(cookieArr, (item, index) => {
32
- const itemArr = item.split("=")
33
- if (name === itemArr[0]) {
34
- result = decodeURIComponent(window.atob(itemArr[1]))
35
- // result = decodeURIComponent(itemArr[1])
36
- return false
37
- }
38
- })
39
- }
40
- return result
41
- }
42
-
43
- export const delCookie = (name: string) => {
44
- const currentDate = new Date()
45
- const currentTime = currentDate.getTime()
46
- let expiresTime = currentDate
47
- expiresTime.setTime(currentTime - 1)
48
-
49
- if (typeof document !== 'undefined') {
50
- document.cookie = name + "=;expires=" + expiresTime.toUTCString() + ";path=/"
51
- }
1
+ import _ from 'lodash'
2
+
3
+ export const setCookie = (name: string, value:string, cookieExpire:any) => {
4
+ const currentDate = new Date()
5
+ const currentTime = currentDate.getTime()
6
+ let expiresTime = currentDate
7
+ expiresTime.setTime(currentTime + 60 * 1000 * 60 * 24 * 30)
8
+
9
+ if (typeof document !== 'undefined') {
10
+ let cookie = name + '=' + window.btoa(encodeURIComponent(value))
11
+ // let cookie = name + '=' + encodeURIComponent(value)
12
+ if (cookieExpire) {
13
+ cookie += ";expires=" + cookieExpire
14
+ } else {
15
+ cookie += ";expires=" + expiresTime.toUTCString()
16
+ }
17
+
18
+ cookie += ";path=/"
19
+ document.cookie = cookie
20
+ }
21
+ }
22
+
23
+ export const getCookie = (name: string) => {
24
+ let result = ''
25
+ if (typeof document !== 'undefined') {
26
+ const cookie = document.cookie
27
+ // console.log('cookie', cookie)
28
+
29
+ const cookieArr = cookie.split("; ")
30
+
31
+ _.each(cookieArr, (item, index) => {
32
+ const itemArr = item.split("=")
33
+ if (name === itemArr[0]) {
34
+ result = decodeURIComponent(window.atob(itemArr[1]))
35
+ // result = decodeURIComponent(itemArr[1])
36
+ return false
37
+ }
38
+ })
39
+ }
40
+ return result
41
+ }
42
+
43
+ export const delCookie = (name: string) => {
44
+ const currentDate = new Date()
45
+ const currentTime = currentDate.getTime()
46
+ let expiresTime = currentDate
47
+ expiresTime.setTime(currentTime - 1)
48
+
49
+ if (typeof document !== 'undefined') {
50
+ document.cookie = name + "=;expires=" + expiresTime.toUTCString() + ";path=/"
51
+ }
52
52
  }
@@ -1,25 +1,25 @@
1
- import axios from 'axios'
2
- import { getLocalApiPrefix } from './common'
3
-
4
- export const getLocalGraphql = (query: string, variables: any = {}) => {
5
- return new Promise((resolve, reject) => {
6
- axios
7
- .post(getLocalApiPrefix() + '/graphql', {
8
- query,
9
- variables
10
- })
11
- .then((res) => {
12
- // console.log('axios_res', res)
13
- if (res) {
14
- const { data } = res
15
- resolve(data)
16
- } else {
17
- reject()
18
- }
19
- })
20
- .catch((_e) => {
21
- // console.error('axios_e', _e)
22
- reject(_e)
23
- })
24
- })
25
- }
1
+ import axios from 'axios'
2
+ import { getLocalApiPrefix } from './common'
3
+
4
+ export const getLocalGraphql = (query: string, variables: any = {}) => {
5
+ return new Promise((resolve, reject) => {
6
+ axios
7
+ .post(getLocalApiPrefix() + '/graphql', {
8
+ query,
9
+ variables
10
+ })
11
+ .then((res) => {
12
+ // console.log('axios_res', res)
13
+ if (res) {
14
+ const { data } = res
15
+ resolve(data)
16
+ } else {
17
+ reject()
18
+ }
19
+ })
20
+ .catch((_e) => {
21
+ // console.error('axios_e', _e)
22
+ reject(_e)
23
+ })
24
+ })
25
+ }
@@ -1,27 +1,27 @@
1
- import { BookOutlined, SolutionOutlined } from '@ant-design/icons'
2
- import React from 'react'
3
-
4
- let key = 1
5
-
6
- export default [
7
- {
8
- key: key.toString(),
9
- text: '介绍',
10
- url: '/',
11
- icon: <BookOutlined rev={undefined} />,
12
- subMenus: null
13
- },
14
- {
15
- key: (++key).toString(),
16
- text: '模板',
17
- url: '/template/manage',
18
- icon: <SolutionOutlined rev={undefined} />,
19
- subMenus: [
20
- {
21
- key: key + '_1',
22
- text: '模板1',
23
- url: '/template/manage'
24
- }
25
- ]
26
- }
27
- ]
1
+ import { BookOutlined, SolutionOutlined } from '@ant-design/icons'
2
+ import React from 'react'
3
+
4
+ let key = 1
5
+
6
+ export default [
7
+ {
8
+ key: key.toString(),
9
+ text: '介绍',
10
+ url: '/',
11
+ icon: <BookOutlined rev={undefined} />,
12
+ subMenus: null
13
+ },
14
+ {
15
+ key: (++key).toString(),
16
+ text: '模板',
17
+ url: '/template/manage',
18
+ icon: <SolutionOutlined rev={undefined} />,
19
+ subMenus: [
20
+ {
21
+ key: key + '_1',
22
+ text: '模板1',
23
+ url: '/template/manage'
24
+ }
25
+ ]
26
+ }
27
+ ]
@@ -1,205 +1,205 @@
1
- import axios from 'axios'
2
- import { setCookie, getCookie, delCookie } from './cookie'
3
- import { getUrlParamByKey, getLocalApiPrefix, getLocalEnv } from './common'
4
- import _ from 'lodash'
5
-
6
- const env = getLocalEnv()
7
-
8
- const LOGIN_COOKIE_ID = env + '_cas_nsgm'
9
- const LOGIN_COOKIE_USER = env + '_nsgm_user'
10
-
11
- const getPrincipalUrl = () => {
12
- const url = getLocalApiPrefix() + '/rest/sso/sessionCheck'
13
- return url
14
- }
15
-
16
- const getValidateUrl = () => {
17
- const url = getLocalApiPrefix() + '/rest/sso/ticketCheck'
18
- return url
19
- }
20
-
21
- const handleLocationHref = () => {
22
- let newHref = ''
23
- if (typeof window !== 'undefined') {
24
- const locationHref = window.location.href
25
- if (locationHref.indexOf('?') !== -1) {
26
- const locationHrefArr = locationHref.split('?')
27
- const locationHrefArrLen = locationHrefArr.length
28
-
29
- let newParamStr = ''
30
-
31
- if (locationHrefArrLen > 1) {
32
- const paramStr = locationHrefArr[1]
33
- if (paramStr.indexOf('&') !== -1) {
34
- const paramArr = paramStr.split('&')
35
-
36
- _.each(paramArr, (item, index) => {
37
- if (item.indexOf('=') !== -1) {
38
- const itemArr = item.split('=')
39
- const itemArrLen = itemArr.length
40
-
41
- const key = itemArr[0]
42
- let value = ''
43
- if (itemArrLen > 1)
44
- value = itemArr[1]
45
-
46
- if ('ticket' !== key) {
47
- newParamStr += key + '=' + value + '&'
48
- }
49
- }
50
- })
51
-
52
- newParamStr = newParamStr.substring(0, newParamStr.length - 1)
53
- } else {
54
- if (paramStr.indexOf('ticket') === -1) {
55
- newParamStr = paramStr
56
- }
57
- }
58
- }
59
-
60
- const locationHrefArrFirst = locationHrefArr[0]
61
- if(newParamStr !== '')
62
- newHref = locationHrefArrFirst + '?' + newParamStr
63
- else
64
- newHref = locationHrefArrFirst
65
- } else {
66
- newHref = locationHref
67
- }
68
- }
69
-
70
- // console.log('newHref', newHref)
71
- return encodeURIComponent(newHref)
72
- }
73
-
74
- const jumpToLogin = () => {
75
- delCookie(LOGIN_COOKIE_ID)
76
- delCookie(LOGIN_COOKIE_USER)
77
-
78
- if (typeof window !== 'undefined') {
79
- window.location.href = window.location.origin + '/login'
80
- }
81
- }
82
-
83
- const jumpToLogout = () => {
84
- delCookie(LOGIN_COOKIE_ID)
85
- delCookie(LOGIN_COOKIE_USER)
86
-
87
- if (typeof window !== 'undefined') {
88
- window.location.href = window.location.origin
89
- }
90
- }
91
-
92
- const principalLogin = (cookie:string, callback:any) => {
93
- let url = getPrincipalUrl()
94
-
95
- if (typeof window !== 'undefined') {
96
- url += '?cookieValue=' + cookie + '&redirectUrl=' + handleLocationHref()
97
- }
98
-
99
- console.log('principalLogin_url', url)
100
- axios.get(url, { params: { credentials: 'include' } }).then((res:any) => {
101
- console.log('principalLogin_res', res)
102
- const { data } = res
103
- if (data) {
104
- const { returnCode, userAttr } = data
105
- if (returnCode !== 0) {
106
- jumpToLogin()
107
- } else {
108
- storeLoginUser(userAttr, callback)
109
- }
110
- } else {
111
- jumpToLogin()
112
- }
113
- }).catch((e) => {
114
- console.log('principalLogin_exception', e)
115
- jumpToLogin()
116
- })
117
- }
118
-
119
- const storeLoginUser = (userAttr:any, callback:any) => {
120
- console.log('storeLoginUser', userAttr)
121
-
122
- if (userAttr) {
123
- const user = JSON.stringify(userAttr, ['city', 'company', 'department', 'displayName', 'employee', 'mail', 'name', 'sn'])
124
- setCookie(LOGIN_COOKIE_USER, user, null)
125
- callback && callback(JSON.parse(user))
126
- } else {
127
- callback && callback()
128
- }
129
- }
130
-
131
- const storeLogin = (cookie:any, cookieExpire:any, userAttr:any, callback:any) => {
132
- console.log('storeLogin_cookie', cookie)
133
-
134
- if (cookie) {
135
- setCookie(LOGIN_COOKIE_ID, cookie, cookieExpire)
136
- }
137
-
138
- storeLoginUser(userAttr, callback)
139
- }
140
-
141
- const validateLogin = (ticket:string, name:string = '', callback:any) => {
142
- let url = getValidateUrl()
143
-
144
- if (typeof window !== 'undefined') {
145
- url += '?ticket=' + ticket
146
-
147
- if(name !== ''){
148
- url += '&name=' + name
149
- }
150
- }
151
-
152
- console.log('validateLogin_url', url)
153
- axios.get(url, { params: { credentials: 'include' } }).then((res:any) => {
154
- console.log('validateLogin_res', res)
155
-
156
- if (res) {
157
- const { data } = res
158
- if (data) {
159
- const { cookieValue, cookieExpire, returnCode, userAttr } = data
160
- if (returnCode === 0) {
161
- storeLogin(cookieValue, cookieExpire, userAttr, callback)
162
- } else {
163
- jumpToLogin()
164
- }
165
- } else {
166
- jumpToLogin()
167
- }
168
- } else {
169
- jumpToLogin()
170
- }
171
- }).catch((e) => {
172
- console.log('validateLogin_exception', e)
173
- })
174
- }
175
-
176
- export const login = (callback:any) => {
177
- const cookieLoginValue = getCookie(LOGIN_COOKIE_ID)
178
- console.log('cookieLoginValue', cookieLoginValue)
179
-
180
- if(typeof window !== 'undefined'){
181
- const locationHref = window.location.href
182
-
183
- if(locationHref.indexOf('/login') === -1){
184
-
185
- if (cookieLoginValue !== '') {
186
- principalLogin(cookieLoginValue, callback)
187
- } else {
188
- const urlParamTicket = getUrlParamByKey('ticket')
189
- const urlParamName = getUrlParamByKey('name')
190
- console.log('urlParamTicket', urlParamTicket, urlParamName)
191
-
192
- if (urlParamTicket !== '') {
193
- validateLogin(urlParamTicket, urlParamName, callback)
194
- } else {
195
- jumpToLogin()
196
- }
197
- }
198
- }
199
- }
200
- }
201
-
202
- export const logout = () => {
203
- jumpToLogout()
204
- }
205
-
1
+ import axios from 'axios'
2
+ import { setCookie, getCookie, delCookie } from './cookie'
3
+ import { getUrlParamByKey, getLocalApiPrefix, getLocalEnv } from './common'
4
+ import _ from 'lodash'
5
+
6
+ const env = getLocalEnv()
7
+
8
+ const LOGIN_COOKIE_ID = env + '_cas_nsgm'
9
+ const LOGIN_COOKIE_USER = env + '_nsgm_user'
10
+
11
+ const getPrincipalUrl = () => {
12
+ const url = getLocalApiPrefix() + '/rest/sso/sessionCheck'
13
+ return url
14
+ }
15
+
16
+ const getValidateUrl = () => {
17
+ const url = getLocalApiPrefix() + '/rest/sso/ticketCheck'
18
+ return url
19
+ }
20
+
21
+ const handleLocationHref = () => {
22
+ let newHref = ''
23
+ if (typeof window !== 'undefined') {
24
+ const locationHref = window.location.href
25
+ if (locationHref.indexOf('?') !== -1) {
26
+ const locationHrefArr = locationHref.split('?')
27
+ const locationHrefArrLen = locationHrefArr.length
28
+
29
+ let newParamStr = ''
30
+
31
+ if (locationHrefArrLen > 1) {
32
+ const paramStr = locationHrefArr[1]
33
+ if (paramStr.indexOf('&') !== -1) {
34
+ const paramArr = paramStr.split('&')
35
+
36
+ _.each(paramArr, (item, index) => {
37
+ if (item.indexOf('=') !== -1) {
38
+ const itemArr = item.split('=')
39
+ const itemArrLen = itemArr.length
40
+
41
+ const key = itemArr[0]
42
+ let value = ''
43
+ if (itemArrLen > 1)
44
+ value = itemArr[1]
45
+
46
+ if ('ticket' !== key) {
47
+ newParamStr += key + '=' + value + '&'
48
+ }
49
+ }
50
+ })
51
+
52
+ newParamStr = newParamStr.substring(0, newParamStr.length - 1)
53
+ } else {
54
+ if (paramStr.indexOf('ticket') === -1) {
55
+ newParamStr = paramStr
56
+ }
57
+ }
58
+ }
59
+
60
+ const locationHrefArrFirst = locationHrefArr[0]
61
+ if(newParamStr !== '')
62
+ newHref = locationHrefArrFirst + '?' + newParamStr
63
+ else
64
+ newHref = locationHrefArrFirst
65
+ } else {
66
+ newHref = locationHref
67
+ }
68
+ }
69
+
70
+ // console.log('newHref', newHref)
71
+ return encodeURIComponent(newHref)
72
+ }
73
+
74
+ const jumpToLogin = () => {
75
+ delCookie(LOGIN_COOKIE_ID)
76
+ delCookie(LOGIN_COOKIE_USER)
77
+
78
+ if (typeof window !== 'undefined') {
79
+ window.location.href = window.location.origin + '/login'
80
+ }
81
+ }
82
+
83
+ const jumpToLogout = () => {
84
+ delCookie(LOGIN_COOKIE_ID)
85
+ delCookie(LOGIN_COOKIE_USER)
86
+
87
+ if (typeof window !== 'undefined') {
88
+ window.location.href = window.location.origin
89
+ }
90
+ }
91
+
92
+ const principalLogin = (cookie:string, callback:any) => {
93
+ let url = getPrincipalUrl()
94
+
95
+ if (typeof window !== 'undefined') {
96
+ url += '?cookieValue=' + cookie + '&redirectUrl=' + handleLocationHref()
97
+ }
98
+
99
+ console.log('principalLogin_url', url)
100
+ axios.get(url, { params: { credentials: 'include' } }).then((res:any) => {
101
+ console.log('principalLogin_res', res)
102
+ const { data } = res
103
+ if (data) {
104
+ const { returnCode, userAttr } = data
105
+ if (returnCode !== 0) {
106
+ jumpToLogin()
107
+ } else {
108
+ storeLoginUser(userAttr, callback)
109
+ }
110
+ } else {
111
+ jumpToLogin()
112
+ }
113
+ }).catch((e) => {
114
+ console.log('principalLogin_exception', e)
115
+ jumpToLogin()
116
+ })
117
+ }
118
+
119
+ const storeLoginUser = (userAttr:any, callback:any) => {
120
+ console.log('storeLoginUser', userAttr)
121
+
122
+ if (userAttr) {
123
+ const user = JSON.stringify(userAttr, ['city', 'company', 'department', 'displayName', 'employee', 'mail', 'name', 'sn'])
124
+ setCookie(LOGIN_COOKIE_USER, user, null)
125
+ callback && callback(JSON.parse(user))
126
+ } else {
127
+ callback && callback()
128
+ }
129
+ }
130
+
131
+ const storeLogin = (cookie:any, cookieExpire:any, userAttr:any, callback:any) => {
132
+ console.log('storeLogin_cookie', cookie)
133
+
134
+ if (cookie) {
135
+ setCookie(LOGIN_COOKIE_ID, cookie, cookieExpire)
136
+ }
137
+
138
+ storeLoginUser(userAttr, callback)
139
+ }
140
+
141
+ const validateLogin = (ticket:string, name:string = '', callback:any) => {
142
+ let url = getValidateUrl()
143
+
144
+ if (typeof window !== 'undefined') {
145
+ url += '?ticket=' + ticket
146
+
147
+ if(name !== ''){
148
+ url += '&name=' + name
149
+ }
150
+ }
151
+
152
+ console.log('validateLogin_url', url)
153
+ axios.get(url, { params: { credentials: 'include' } }).then((res:any) => {
154
+ console.log('validateLogin_res', res)
155
+
156
+ if (res) {
157
+ const { data } = res
158
+ if (data) {
159
+ const { cookieValue, cookieExpire, returnCode, userAttr } = data
160
+ if (returnCode === 0) {
161
+ storeLogin(cookieValue, cookieExpire, userAttr, callback)
162
+ } else {
163
+ jumpToLogin()
164
+ }
165
+ } else {
166
+ jumpToLogin()
167
+ }
168
+ } else {
169
+ jumpToLogin()
170
+ }
171
+ }).catch((e) => {
172
+ console.log('validateLogin_exception', e)
173
+ })
174
+ }
175
+
176
+ export const login = (callback:any) => {
177
+ const cookieLoginValue = getCookie(LOGIN_COOKIE_ID)
178
+ console.log('cookieLoginValue', cookieLoginValue)
179
+
180
+ if(typeof window !== 'undefined'){
181
+ const locationHref = window.location.href
182
+
183
+ if(locationHref.indexOf('/login') === -1){
184
+
185
+ if (cookieLoginValue !== '') {
186
+ principalLogin(cookieLoginValue, callback)
187
+ } else {
188
+ const urlParamTicket = getUrlParamByKey('ticket')
189
+ const urlParamName = getUrlParamByKey('name')
190
+ console.log('urlParamTicket', urlParamTicket, urlParamName)
191
+
192
+ if (urlParamTicket !== '') {
193
+ validateLogin(urlParamTicket, urlParamName, callback)
194
+ } else {
195
+ jumpToLogin()
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+
202
+ export const logout = () => {
203
+ jumpToLogout()
204
+ }
205
+
@@ -1,11 +1,11 @@
1
- {
2
- "presets": ["next/babel"],
3
- "plugins": [
4
- ["styled-components", {
5
- "ssr": true,
6
- "displayName": true,
7
- "preprocess": false
8
- }]
9
- ]
10
- }
1
+ {
2
+ "presets": ["next/babel"],
3
+ "plugins": [
4
+ ["styled-components", {
5
+ "ssr": true,
6
+ "displayName": true,
7
+ "preprocess": false
8
+ }]
9
+ ]
10
+ }
11
11