nsgm-cli 1.0.25 → 1.0.27
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/LICENSE +201 -201
- package/README.md +162 -162
- package/generation/.babelrc +9 -9
- package/generation/README.md +18 -18
- package/generation/app.js +2 -2
- package/generation/client/layout/index.tsx +223 -223
- package/generation/client/redux/reducers.ts +5 -5
- package/generation/client/redux/store.ts +44 -44
- package/generation/client/redux/template/manage/actions.ts +190 -190
- package/generation/client/redux/template/manage/reducers.ts +118 -118
- package/generation/client/redux/template/manage/types.ts +24 -24
- package/generation/client/service/template/manage.ts +73 -73
- package/generation/client/styled/common.ts +28 -28
- package/generation/client/styled/layout/index.ts +13 -13
- package/generation/client/styled/template/manage.ts +51 -51
- package/generation/client/utils/common.ts +45 -45
- package/generation/client/utils/fetch.ts +25 -25
- package/generation/client/utils/menu.tsx +26 -26
- package/generation/gitignore +3 -3
- package/generation/mysql.config.js +12 -12
- package/generation/next-env.d.ts +2 -2
- package/generation/next.config.js +6 -6
- package/generation/package.json +20 -20
- package/generation/pages/_app.tsx +44 -44
- package/generation/pages/_document.tsx +53 -53
- package/generation/pages/index.tsx +54 -54
- package/generation/pages/template/manage.tsx +280 -280
- package/generation/project.config.js +12 -12
- package/generation/server/apis/template.js +18 -18
- package/generation/server/modules/template/resolver.js +231 -231
- package/generation/server/modules/template/schema.js +33 -33
- package/generation/server/rest.js +20 -20
- package/generation/server/sql/template.sql +8 -8
- package/generation/tsconfig.json +29 -29
- package/index.js +10 -10
- package/lib/args.d.ts +6 -6
- package/lib/args.js +47 -47
- package/lib/generate.d.ts +3 -3
- package/lib/generate.js +590 -590
- package/lib/index.d.ts +2 -2
- package/lib/index.js +182 -182
- package/lib/server/db.d.ts +5 -5
- package/lib/server/db.js +47 -47
- package/lib/server/graphql.d.ts +7 -7
- package/lib/server/graphql.js +119 -119
- package/lib/server/plugins/date.d.ts +5 -5
- package/lib/server/plugins/date.js +16 -16
- package/mysql.config.js +14 -14
- package/next.config.js +210 -210
- package/package.json +113 -113
- package/project.config.js +14 -14
|
@@ -1,223 +1,223 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react'
|
|
2
|
-
import { Layout, Menu, Breadcrumb, Image } from 'antd'
|
|
3
|
-
import { Container } from '../styled/layout'
|
|
4
|
-
import { useRouter } from 'next/router'
|
|
5
|
-
import _ from 'lodash'
|
|
6
|
-
import menuConfig from '../utils/menu'
|
|
7
|
-
|
|
8
|
-
const { SubMenu } = Menu
|
|
9
|
-
const { Header, Content, Sider } = Layout
|
|
10
|
-
|
|
11
|
-
const getLocationKey = () => {
|
|
12
|
-
const result = {
|
|
13
|
-
topMenu: '1',
|
|
14
|
-
slideMenu: '0'
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (typeof window !== 'undefined') {
|
|
18
|
-
const locationHref = window.location.href
|
|
19
|
-
|
|
20
|
-
let locationHrefArr = locationHref.split('?')
|
|
21
|
-
if (locationHrefArr.length > 0) {
|
|
22
|
-
locationHrefArr = locationHrefArr[0].split('//')
|
|
23
|
-
|
|
24
|
-
if (locationHrefArr.length > 1) {
|
|
25
|
-
let locationStr = locationHrefArr[1]
|
|
26
|
-
const locationIndex = locationStr.indexOf('/')
|
|
27
|
-
locationStr = locationStr.substring(locationIndex)
|
|
28
|
-
|
|
29
|
-
console.log('locationStr', locationStr)
|
|
30
|
-
|
|
31
|
-
_.each(menuConfig, (item:any, index:any) => {
|
|
32
|
-
const { key, url, subMenus } = item
|
|
33
|
-
|
|
34
|
-
if (subMenus) {
|
|
35
|
-
_.each(subMenus, (subItem:any, subIndex:any) => {
|
|
36
|
-
const { key: subKey, url: subUrl } = subItem
|
|
37
|
-
|
|
38
|
-
if (locationStr === subUrl.split('?')[0]) {
|
|
39
|
-
const subKeyArr = subKey.split('_')
|
|
40
|
-
const subKeyArrLen = subKeyArr.length
|
|
41
|
-
|
|
42
|
-
if (subKeyArrLen > 0) result.topMenu = subKeyArr[0]
|
|
43
|
-
if (subKeyArrLen > 1) result.slideMenu = subKeyArr[1]
|
|
44
|
-
|
|
45
|
-
return false
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
} else {
|
|
49
|
-
if (locationStr === url.split('?')[0]) {
|
|
50
|
-
result.topMenu = key
|
|
51
|
-
return false
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
console.log('result', result)
|
|
59
|
-
return result
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const routerPush = (router: any, url: string) => {
|
|
63
|
-
console.log('routerPush', url)
|
|
64
|
-
|
|
65
|
-
if (router && url) {
|
|
66
|
-
router.push(url)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const LayoutComponent = ({ children }) => {
|
|
71
|
-
const router = useRouter()
|
|
72
|
-
const [topMenuKey, setTopMenuKey] = useState('1')
|
|
73
|
-
const [sliderMenuKey, setSliderMenuKey] = useState('1')
|
|
74
|
-
|
|
75
|
-
console.log('topMenuKey: ' + topMenuKey, ', sliderMenuKey: ' + sliderMenuKey)
|
|
76
|
-
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
const { topMenu, slideMenu } = getLocationKey()
|
|
79
|
-
setTopMenuKey(topMenu)
|
|
80
|
-
setSliderMenuKey(slideMenu)
|
|
81
|
-
}, [])
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<Layout>
|
|
85
|
-
<Container>
|
|
86
|
-
<Header className="header">
|
|
87
|
-
<div className="logo">
|
|
88
|
-
<Image width={100} src="../images/zhizuotu_1.png" preview={false} />
|
|
89
|
-
</div>
|
|
90
|
-
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']} selectedKeys={[topMenuKey]}>
|
|
91
|
-
{_.map(menuConfig, (item:any, index:any) => {
|
|
92
|
-
const { key, text, url, subMenus } = item
|
|
93
|
-
if (key) {
|
|
94
|
-
return (
|
|
95
|
-
<Menu.Item
|
|
96
|
-
key={key}
|
|
97
|
-
onClick={() => {
|
|
98
|
-
routerPush(router, url)
|
|
99
|
-
setTopMenuKey(key)
|
|
100
|
-
|
|
101
|
-
if (subMenus) {
|
|
102
|
-
setSliderMenuKey('1')
|
|
103
|
-
} else {
|
|
104
|
-
setSliderMenuKey('0')
|
|
105
|
-
}
|
|
106
|
-
}}
|
|
107
|
-
>
|
|
108
|
-
{text}
|
|
109
|
-
</Menu.Item>
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
})}
|
|
113
|
-
</Menu>
|
|
114
|
-
</Header>
|
|
115
|
-
<Layout>
|
|
116
|
-
<Sider width={200} className="site-layout-background">
|
|
117
|
-
<Menu
|
|
118
|
-
mode="inline"
|
|
119
|
-
defaultSelectedKeys={['slider_1_0']}
|
|
120
|
-
defaultOpenKeys={['slider_1']}
|
|
121
|
-
selectedKeys={['slider_' + topMenuKey + '_' + sliderMenuKey]}
|
|
122
|
-
openKeys={['slider_' + topMenuKey]}
|
|
123
|
-
style={{ height: '100%', borderRight: 0 }}
|
|
124
|
-
>
|
|
125
|
-
{_.map(menuConfig, (item:any, index:any) => {
|
|
126
|
-
const { key, text, url, icon, subMenus } = item
|
|
127
|
-
|
|
128
|
-
if (subMenus) {
|
|
129
|
-
return (
|
|
130
|
-
<SubMenu
|
|
131
|
-
key={'slider_' + key}
|
|
132
|
-
icon={icon}
|
|
133
|
-
title={text}
|
|
134
|
-
onTitleClick={() => {
|
|
135
|
-
setTopMenuKey(key)
|
|
136
|
-
setSliderMenuKey('1')
|
|
137
|
-
}}
|
|
138
|
-
>
|
|
139
|
-
{_.map(subMenus, (subItem:any, subIndex:any) => {
|
|
140
|
-
const { key: subKey, text: subText, url: subUrl } = subItem
|
|
141
|
-
return (
|
|
142
|
-
<Menu.Item
|
|
143
|
-
key={'slider_' + subKey}
|
|
144
|
-
onClick={() => {
|
|
145
|
-
routerPush(router, subUrl)
|
|
146
|
-
|
|
147
|
-
const subKeyArr = subKey.split('_')
|
|
148
|
-
const subKeyArrLen = subKeyArr.length
|
|
149
|
-
|
|
150
|
-
console.log(subKeyArr, subKeyArrLen)
|
|
151
|
-
|
|
152
|
-
if (subKeyArrLen >= 1) setTopMenuKey(subKeyArr[0])
|
|
153
|
-
|
|
154
|
-
if (subKeyArrLen >= 2) setSliderMenuKey(subKeyArr[1])
|
|
155
|
-
}}
|
|
156
|
-
>
|
|
157
|
-
{subText}
|
|
158
|
-
</Menu.Item>
|
|
159
|
-
)
|
|
160
|
-
})}
|
|
161
|
-
</SubMenu>
|
|
162
|
-
)
|
|
163
|
-
} else {
|
|
164
|
-
if (key) {
|
|
165
|
-
return (
|
|
166
|
-
<Menu.Item
|
|
167
|
-
key={'slider_' + key + '_0'}
|
|
168
|
-
icon={icon}
|
|
169
|
-
onClick={() => {
|
|
170
|
-
routerPush(router, url)
|
|
171
|
-
setTopMenuKey(key)
|
|
172
|
-
setSliderMenuKey('0')
|
|
173
|
-
}}
|
|
174
|
-
>
|
|
175
|
-
{text}
|
|
176
|
-
</Menu.Item>
|
|
177
|
-
)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
})}
|
|
181
|
-
</Menu>
|
|
182
|
-
</Sider>
|
|
183
|
-
<Layout style={{ padding: '0 24px 24px' }}>
|
|
184
|
-
<Breadcrumb style={{ margin: '16px 0' }}>
|
|
185
|
-
{_.map(menuConfig, (item:any, index:any) => {
|
|
186
|
-
const { key, text, subMenus } = item
|
|
187
|
-
|
|
188
|
-
if (key && key === topMenuKey) {
|
|
189
|
-
if (subMenus) {
|
|
190
|
-
const subContent = []
|
|
191
|
-
_.each(subMenus, (subItem:any, subIndex:any) => {
|
|
192
|
-
const { key: subKey, text: subText } = subItem
|
|
193
|
-
if (subKey === key + '_' + sliderMenuKey) {
|
|
194
|
-
subContent.push(<Breadcrumb.Item key={'breadcrumb' + subIndex}>{text}</Breadcrumb.Item>)
|
|
195
|
-
subContent.push(<Breadcrumb.Item key={'breadcrumb' + subIndex}>{subText}</Breadcrumb.Item>)
|
|
196
|
-
return false
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
|
-
return subContent
|
|
200
|
-
} else {
|
|
201
|
-
return <Breadcrumb.Item key={'breadcrumb' + index}>{text}</Breadcrumb.Item>
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
})}
|
|
205
|
-
</Breadcrumb>
|
|
206
|
-
<Content
|
|
207
|
-
className="site-layout-background"
|
|
208
|
-
style={{
|
|
209
|
-
padding: 24,
|
|
210
|
-
margin: 0,
|
|
211
|
-
minHeight: 280
|
|
212
|
-
}}
|
|
213
|
-
>
|
|
214
|
-
{children}
|
|
215
|
-
</Content>
|
|
216
|
-
</Layout>
|
|
217
|
-
</Layout>
|
|
218
|
-
</Container>
|
|
219
|
-
</Layout>
|
|
220
|
-
)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export default LayoutComponent
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
import { Layout, Menu, Breadcrumb, Image } from 'antd'
|
|
3
|
+
import { Container } from '../styled/layout'
|
|
4
|
+
import { useRouter } from 'next/router'
|
|
5
|
+
import _ from 'lodash'
|
|
6
|
+
import menuConfig from '../utils/menu'
|
|
7
|
+
|
|
8
|
+
const { SubMenu } = Menu
|
|
9
|
+
const { Header, Content, Sider } = Layout
|
|
10
|
+
|
|
11
|
+
const getLocationKey = () => {
|
|
12
|
+
const result = {
|
|
13
|
+
topMenu: '1',
|
|
14
|
+
slideMenu: '0'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (typeof window !== 'undefined') {
|
|
18
|
+
const locationHref = window.location.href
|
|
19
|
+
|
|
20
|
+
let locationHrefArr = locationHref.split('?')
|
|
21
|
+
if (locationHrefArr.length > 0) {
|
|
22
|
+
locationHrefArr = locationHrefArr[0].split('//')
|
|
23
|
+
|
|
24
|
+
if (locationHrefArr.length > 1) {
|
|
25
|
+
let locationStr = locationHrefArr[1]
|
|
26
|
+
const locationIndex = locationStr.indexOf('/')
|
|
27
|
+
locationStr = locationStr.substring(locationIndex)
|
|
28
|
+
|
|
29
|
+
console.log('locationStr', locationStr)
|
|
30
|
+
|
|
31
|
+
_.each(menuConfig, (item:any, index:any) => {
|
|
32
|
+
const { key, url, subMenus } = item
|
|
33
|
+
|
|
34
|
+
if (subMenus) {
|
|
35
|
+
_.each(subMenus, (subItem:any, subIndex:any) => {
|
|
36
|
+
const { key: subKey, url: subUrl } = subItem
|
|
37
|
+
|
|
38
|
+
if (locationStr === subUrl.split('?')[0]) {
|
|
39
|
+
const subKeyArr = subKey.split('_')
|
|
40
|
+
const subKeyArrLen = subKeyArr.length
|
|
41
|
+
|
|
42
|
+
if (subKeyArrLen > 0) result.topMenu = subKeyArr[0]
|
|
43
|
+
if (subKeyArrLen > 1) result.slideMenu = subKeyArr[1]
|
|
44
|
+
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
} else {
|
|
49
|
+
if (locationStr === url.split('?')[0]) {
|
|
50
|
+
result.topMenu = key
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
console.log('result', result)
|
|
59
|
+
return result
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const routerPush = (router: any, url: string) => {
|
|
63
|
+
console.log('routerPush', url)
|
|
64
|
+
|
|
65
|
+
if (router && url) {
|
|
66
|
+
router.push(url)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const LayoutComponent = ({ children }) => {
|
|
71
|
+
const router = useRouter()
|
|
72
|
+
const [topMenuKey, setTopMenuKey] = useState('1')
|
|
73
|
+
const [sliderMenuKey, setSliderMenuKey] = useState('1')
|
|
74
|
+
|
|
75
|
+
console.log('topMenuKey: ' + topMenuKey, ', sliderMenuKey: ' + sliderMenuKey)
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const { topMenu, slideMenu } = getLocationKey()
|
|
79
|
+
setTopMenuKey(topMenu)
|
|
80
|
+
setSliderMenuKey(slideMenu)
|
|
81
|
+
}, [])
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Layout>
|
|
85
|
+
<Container>
|
|
86
|
+
<Header className="header">
|
|
87
|
+
<div className="logo">
|
|
88
|
+
<Image width={100} src="../images/zhizuotu_1.png" preview={false} />
|
|
89
|
+
</div>
|
|
90
|
+
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['1']} selectedKeys={[topMenuKey]}>
|
|
91
|
+
{_.map(menuConfig, (item:any, index:any) => {
|
|
92
|
+
const { key, text, url, subMenus } = item
|
|
93
|
+
if (key) {
|
|
94
|
+
return (
|
|
95
|
+
<Menu.Item
|
|
96
|
+
key={key}
|
|
97
|
+
onClick={() => {
|
|
98
|
+
routerPush(router, url)
|
|
99
|
+
setTopMenuKey(key)
|
|
100
|
+
|
|
101
|
+
if (subMenus) {
|
|
102
|
+
setSliderMenuKey('1')
|
|
103
|
+
} else {
|
|
104
|
+
setSliderMenuKey('0')
|
|
105
|
+
}
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
{text}
|
|
109
|
+
</Menu.Item>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
})}
|
|
113
|
+
</Menu>
|
|
114
|
+
</Header>
|
|
115
|
+
<Layout>
|
|
116
|
+
<Sider width={200} className="site-layout-background">
|
|
117
|
+
<Menu
|
|
118
|
+
mode="inline"
|
|
119
|
+
defaultSelectedKeys={['slider_1_0']}
|
|
120
|
+
defaultOpenKeys={['slider_1']}
|
|
121
|
+
selectedKeys={['slider_' + topMenuKey + '_' + sliderMenuKey]}
|
|
122
|
+
openKeys={['slider_' + topMenuKey]}
|
|
123
|
+
style={{ height: '100%', borderRight: 0 }}
|
|
124
|
+
>
|
|
125
|
+
{_.map(menuConfig, (item:any, index:any) => {
|
|
126
|
+
const { key, text, url, icon, subMenus } = item
|
|
127
|
+
|
|
128
|
+
if (subMenus) {
|
|
129
|
+
return (
|
|
130
|
+
<SubMenu
|
|
131
|
+
key={'slider_' + key}
|
|
132
|
+
icon={icon}
|
|
133
|
+
title={text}
|
|
134
|
+
onTitleClick={() => {
|
|
135
|
+
setTopMenuKey(key)
|
|
136
|
+
setSliderMenuKey('1')
|
|
137
|
+
}}
|
|
138
|
+
>
|
|
139
|
+
{_.map(subMenus, (subItem:any, subIndex:any) => {
|
|
140
|
+
const { key: subKey, text: subText, url: subUrl } = subItem
|
|
141
|
+
return (
|
|
142
|
+
<Menu.Item
|
|
143
|
+
key={'slider_' + subKey}
|
|
144
|
+
onClick={() => {
|
|
145
|
+
routerPush(router, subUrl)
|
|
146
|
+
|
|
147
|
+
const subKeyArr = subKey.split('_')
|
|
148
|
+
const subKeyArrLen = subKeyArr.length
|
|
149
|
+
|
|
150
|
+
console.log(subKeyArr, subKeyArrLen)
|
|
151
|
+
|
|
152
|
+
if (subKeyArrLen >= 1) setTopMenuKey(subKeyArr[0])
|
|
153
|
+
|
|
154
|
+
if (subKeyArrLen >= 2) setSliderMenuKey(subKeyArr[1])
|
|
155
|
+
}}
|
|
156
|
+
>
|
|
157
|
+
{subText}
|
|
158
|
+
</Menu.Item>
|
|
159
|
+
)
|
|
160
|
+
})}
|
|
161
|
+
</SubMenu>
|
|
162
|
+
)
|
|
163
|
+
} else {
|
|
164
|
+
if (key) {
|
|
165
|
+
return (
|
|
166
|
+
<Menu.Item
|
|
167
|
+
key={'slider_' + key + '_0'}
|
|
168
|
+
icon={icon}
|
|
169
|
+
onClick={() => {
|
|
170
|
+
routerPush(router, url)
|
|
171
|
+
setTopMenuKey(key)
|
|
172
|
+
setSliderMenuKey('0')
|
|
173
|
+
}}
|
|
174
|
+
>
|
|
175
|
+
{text}
|
|
176
|
+
</Menu.Item>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
})}
|
|
181
|
+
</Menu>
|
|
182
|
+
</Sider>
|
|
183
|
+
<Layout style={{ padding: '0 24px 24px' }}>
|
|
184
|
+
<Breadcrumb style={{ margin: '16px 0' }}>
|
|
185
|
+
{_.map(menuConfig, (item:any, index:any) => {
|
|
186
|
+
const { key, text, subMenus } = item
|
|
187
|
+
|
|
188
|
+
if (key && key === topMenuKey) {
|
|
189
|
+
if (subMenus) {
|
|
190
|
+
const subContent = []
|
|
191
|
+
_.each(subMenus, (subItem:any, subIndex:any) => {
|
|
192
|
+
const { key: subKey, text: subText } = subItem
|
|
193
|
+
if (subKey === key + '_' + sliderMenuKey) {
|
|
194
|
+
subContent.push(<Breadcrumb.Item key={'breadcrumb' + subIndex}>{text}</Breadcrumb.Item>)
|
|
195
|
+
subContent.push(<Breadcrumb.Item key={'breadcrumb' + subIndex}>{subText}</Breadcrumb.Item>)
|
|
196
|
+
return false
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
return subContent
|
|
200
|
+
} else {
|
|
201
|
+
return <Breadcrumb.Item key={'breadcrumb' + index}>{text}</Breadcrumb.Item>
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
})}
|
|
205
|
+
</Breadcrumb>
|
|
206
|
+
<Content
|
|
207
|
+
className="site-layout-background"
|
|
208
|
+
style={{
|
|
209
|
+
padding: 24,
|
|
210
|
+
margin: 0,
|
|
211
|
+
minHeight: 280
|
|
212
|
+
}}
|
|
213
|
+
>
|
|
214
|
+
{children}
|
|
215
|
+
</Content>
|
|
216
|
+
</Layout>
|
|
217
|
+
</Layout>
|
|
218
|
+
</Container>
|
|
219
|
+
</Layout>
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export default LayoutComponent
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// import { templateManageReducer } from './template/manage/reducers'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
// templateManage: templateManageReducer,
|
|
5
|
-
}
|
|
1
|
+
// import { templateManageReducer } from './template/manage/reducers'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
// templateManage: templateManageReducer,
|
|
5
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
import { createStore, applyMiddleware, combineReducers } from 'redux'
|
|
3
|
-
import { composeWithDevTools } from 'redux-devtools-extension'
|
|
4
|
-
import thunkMiddleware from 'redux-thunk'
|
|
5
|
-
import reducers from './reducers'
|
|
6
|
-
import _ from 'lodash'
|
|
7
|
-
|
|
8
|
-
let store:any
|
|
9
|
-
|
|
10
|
-
const reducersKeysLen = _.keys(reducers).length
|
|
11
|
-
const combineReducer = combineReducers((reducersKeysLen === 0) ? {} : { ...reducers })
|
|
12
|
-
|
|
13
|
-
export type RootState = ReturnType<typeof combineReducer>
|
|
14
|
-
|
|
15
|
-
function initStore(initialState:any) {
|
|
16
|
-
return createStore(
|
|
17
|
-
combineReducer,
|
|
18
|
-
initialState,
|
|
19
|
-
composeWithDevTools(applyMiddleware(thunkMiddleware))
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const initializeStore = (preloadedState:any) => {
|
|
24
|
-
let _store = store ?? initStore(preloadedState)
|
|
25
|
-
|
|
26
|
-
if (preloadedState && store) {
|
|
27
|
-
_store = initStore({
|
|
28
|
-
...store.getState(),
|
|
29
|
-
...preloadedState
|
|
30
|
-
})
|
|
31
|
-
store = undefined
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (typeof window === 'undefined') return _store
|
|
35
|
-
|
|
36
|
-
if (!store) store = _store
|
|
37
|
-
|
|
38
|
-
return _store
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function useStore(initialState:any) {
|
|
42
|
-
const memoStore = useMemo(() => initializeStore(initialState), [initialState])
|
|
43
|
-
return memoStore
|
|
44
|
-
}
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { createStore, applyMiddleware, combineReducers } from 'redux'
|
|
3
|
+
import { composeWithDevTools } from 'redux-devtools-extension'
|
|
4
|
+
import thunkMiddleware from 'redux-thunk'
|
|
5
|
+
import reducers from './reducers'
|
|
6
|
+
import _ from 'lodash'
|
|
7
|
+
|
|
8
|
+
let store:any
|
|
9
|
+
|
|
10
|
+
const reducersKeysLen = _.keys(reducers).length
|
|
11
|
+
const combineReducer = combineReducers((reducersKeysLen === 0) ? {} : { ...reducers })
|
|
12
|
+
|
|
13
|
+
export type RootState = ReturnType<typeof combineReducer>
|
|
14
|
+
|
|
15
|
+
function initStore(initialState:any) {
|
|
16
|
+
return createStore(
|
|
17
|
+
combineReducer,
|
|
18
|
+
initialState,
|
|
19
|
+
composeWithDevTools(applyMiddleware(thunkMiddleware))
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const initializeStore = (preloadedState:any) => {
|
|
24
|
+
let _store = store ?? initStore(preloadedState)
|
|
25
|
+
|
|
26
|
+
if (preloadedState && store) {
|
|
27
|
+
_store = initStore({
|
|
28
|
+
...store.getState(),
|
|
29
|
+
...preloadedState
|
|
30
|
+
})
|
|
31
|
+
store = undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof window === 'undefined') return _store
|
|
35
|
+
|
|
36
|
+
if (!store) store = _store
|
|
37
|
+
|
|
38
|
+
return _store
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useStore(initialState:any) {
|
|
42
|
+
const memoStore = useMemo(() => initializeStore(initialState), [initialState])
|
|
43
|
+
return memoStore
|
|
44
|
+
}
|