Skip to content

Commit

Permalink
🍰 upgrade templates for boot-template-cli code generator
Browse files Browse the repository at this point in the history
  • Loading branch information
weiq committed Jul 30, 2020
1 parent 1bb1d2e commit 3257871
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 21 deletions.
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@
"react-scripts": "^3.4.0",
"webpack-bundle-analyzer": "^3.3.2"
},
"create-template": {
"ignoreScript": [
"gh-pages"
],
"ignoreDevDependencies": [
"gh-pages"
],
"ignore": [
".git",
"CHANGELOG.md",
"LICENSE",
"README.*.md"
],
"route": {
"nameCase": "pascal",
"importStyle": "func"
}
},
"browserslist": [
"> 1%",
"last 2 versions",
Expand Down
2 changes: 1 addition & 1 deletion templates/routes/Blank/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { Content } = Layout;
export default class extends BaseComponent {
render() {
return (
<Layout className="full-layout page <%=namespace %>-page">
<Layout className="full-layout page <%=name %>-page">
<Content>Route created success, happy work!</Content>
</Layout>
);
Expand Down
2 changes: 1 addition & 1 deletion templates/routes/Blank/components/index.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// 页面样式
.<%=namespace %>-page {
.<%=name %>-page {
}
2 changes: 1 addition & 1 deletion templates/routes/Blank/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dynamicWrapper, createRoute } from '@/utils/core';

const routesConfig = app => ({
path: '<%=route %>',
path: '/<%=name %>',
title: '<%=title %>',
component: dynamicWrapper(app, [import('./model')], () => import('./components'))
});
Expand Down
2 changes: 1 addition & 1 deletion templates/routes/Blank/model/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import modelEnhance from '@/utils/modelEnhance';

export default modelEnhance({
namespace: '<%=namespace %>',
namespace: '<%=name %>',

state: {},

Expand Down
20 changes: 10 additions & 10 deletions templates/routes/CRUD/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import './index.less';
const { Content, Header, Footer } = Layout;
const Pagination = DataTable.Pagination;

@connect(({ <%=namespace %>, loading }) => ({
<%=namespace %>,
loading: loading.models.<%=namespace %>
@connect(({ <%=name %>, loading }) => ({
<%=name %>,
loading: loading.models.<%=name %>
}))
export default class extends BaseComponent {
state = {
Expand All @@ -26,7 +26,7 @@ export default class extends BaseComponent {
const { rows } = this.state;

this.props.dispatch({
type: '<%=namespace %>/remove',
type: '<%=name %>/remove',
payload: {
records,
success: () => {
Expand All @@ -42,16 +42,16 @@ export default class extends BaseComponent {
};

render() {
const { <%=namespace %>, loading, dispatch } = this.props;
const { pageData, employees } = <%=namespace %>;
const { <%=name %>, loading, dispatch } = this.props;
const { pageData, employees } = <%=name %>;
const columns = createColumns(this);
const { rows, record, visible } = this.state;

const searchBarProps = {
columns,
onSearch: values => {
dispatch({
type: '<%=namespace %>/getPageInfo',
type: '<%=name %>/getPageInfo',
payload: {
pageData: pageData.filter(values).jumpPage(1, 10)
}
Expand All @@ -70,7 +70,7 @@ export default class extends BaseComponent {
selectedRowKeys: rows.map(item => item.id),
onChange: ({ pageNum, pageSize }) => {
dispatch({
type: '<%=namespace %>/getPageInfo',
type: '<%=name %>/getPageInfo',
payload: {
pageData: pageData.jumpPage(pageNum, pageSize)
}
Expand All @@ -97,7 +97,7 @@ export default class extends BaseComponent {
// 可以使用主键或是否有record来区分状态
onSubmit: values => {
dispatch({
type: '<%=namespace %>/save',
type: '<%=name %>/save',
payload: {
values,
success: () => {
Expand All @@ -112,7 +112,7 @@ export default class extends BaseComponent {
};

return (
<Layout className="full-layout <%=namespace %>-page">
<Layout className="full-layout <%=name %>-page">
<Header>
<Toolbar
appendLeft={
Expand Down
2 changes: 1 addition & 1 deletion templates/routes/CRUD/components/index.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// 页面样式
.<%=namespace %>-page {
.<%=name %>-page {
}
2 changes: 1 addition & 1 deletion templates/routes/CRUD/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dynamicWrapper, createRoute } from '@/utils/core';

const routesConfig = app => ({
path: '<%=route %>',
path: '/<%=name %>',
title: '<%=title %>',
component: dynamicWrapper(app, [import('./model')], () => import('./components'))
});
Expand Down
10 changes: 5 additions & 5 deletions templates/routes/CRUD/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PageHelper from '@/utils/pageHelper';
*/
let LOADED = false;
export default modelEnhance({
namespace: '<%=namespace %>',
namespace: '<%=name %>',

state: {
pageData: PageHelper.create(),
Expand All @@ -17,7 +17,7 @@ export default modelEnhance({
subscriptions: {
setup({ dispatch, history }) {
history.listen(({ pathname }) => {
if (pathname === '/<%=namespace %>' && !LOADED) {
if (pathname === '/<%=name %>' && !LOADED) {
LOADED = true;
dispatch({
type: 'init'
Expand All @@ -30,7 +30,7 @@ export default modelEnhance({
effects: {
// 进入页面加载
*init({ payload }, { call, put, select }) {
const { pageData } = yield select(state => state.<%=namespace %>);
const { pageData } = yield select(state => state.<%=name %>);
yield put({
type: 'getPageInfo',
payload: {
Expand All @@ -53,7 +53,7 @@ export default modelEnhance({
// 保存 之后查询分页
*save({ payload }, { call, put, select }) {
const { values, success } = payload;
const { pageData } = yield select(state => state.<%=namespace %>);
const { pageData } = yield select(state => state.<%=name %>);
yield put({
type: '@request',
payload: {
Expand All @@ -73,7 +73,7 @@ export default modelEnhance({
// 删除 之后查询分页
*remove({ payload }, { call, put, select }) {
const { records, success } = payload;
const { pageData } = yield select(state => state.<%=namespace %>);
const { pageData } = yield select(state => state.<%=name %>);
yield put({
type: '@request',
payload: {
Expand Down
14 changes: 14 additions & 0 deletions templates/routes/CRUD/prompts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "api_0",
"message": "⭐️ 列表查询接口"
},
{
"name": "api_1",
"message": "⭐️ 保存接口"
},
{
"name": "api_2",
"message": "⭐️ 删除接口"
}
]

0 comments on commit 3257871

Please sign in to comment.