🎉 增加生成前端代码功能.
This commit is contained in:
parent
bbf3fcd495
commit
26c6edf27f
|
|
@ -205,12 +205,15 @@ public class BladeGenerator {
|
||||||
pc.setXml("mapper");
|
pc.setXml("mapper");
|
||||||
mpg.setPackageInfo(pc);
|
mpg.setPackageInfo(pc);
|
||||||
|
|
||||||
|
String servicePackage = serviceName.split("-").length > 1 ? serviceName.split("-")[1] : serviceName;
|
||||||
|
|
||||||
// 自定义配置
|
// 自定义配置
|
||||||
InjectionConfig cfg = new InjectionConfig() {
|
InjectionConfig cfg = new InjectionConfig() {
|
||||||
@Override
|
@Override
|
||||||
public void initMap() {
|
public void initMap() {
|
||||||
Map<String, Object> map = new HashMap<>(16);
|
Map<String, Object> map = new HashMap<>(16);
|
||||||
map.put("serviceName", serviceName);
|
map.put("serviceName", serviceName);
|
||||||
|
map.put("servicePackage", servicePackage);
|
||||||
this.setMap(map);
|
this.setMap(map);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -251,6 +254,30 @@ public class BladeGenerator {
|
||||||
return getOutputWebDir() + "/services" + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
return getOutputWebDir() + "/services" + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
focList.add(new FileOutConfig("/templates/sword/list.js.vm") {
|
||||||
|
@Override
|
||||||
|
public String outputFile(TableInfo tableInfo) {
|
||||||
|
return getOutputWebDir() + "/pages" + "/" + StringUtil.upperFirst(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + ".js";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
focList.add(new FileOutConfig("/templates/sword/add.js.vm") {
|
||||||
|
@Override
|
||||||
|
public String outputFile(TableInfo tableInfo) {
|
||||||
|
return getOutputWebDir() + "/pages" + "/" + StringUtil.upperFirst(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Add.js";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
focList.add(new FileOutConfig("/templates/sword/edit.js.vm") {
|
||||||
|
@Override
|
||||||
|
public String outputFile(TableInfo tableInfo) {
|
||||||
|
return getOutputWebDir() + "/pages" + "/" + StringUtil.upperFirst(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Edit.js";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
focList.add(new FileOutConfig("/templates/sword/view.js.vm") {
|
||||||
|
@Override
|
||||||
|
public String outputFile(TableInfo tableInfo) {
|
||||||
|
return getOutputWebDir() + "/pages" + "/" + StringUtil.upperFirst(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "View.js";
|
||||||
|
}
|
||||||
|
});
|
||||||
cfg.setFileOutConfigList(focList);
|
cfg.setFileOutConfigList(focList);
|
||||||
mpg.setCfg(cfg);
|
mpg.setCfg(cfg);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,37 @@
|
||||||
#set($moduleName=$table.entityPath.toUpperCase())
|
#set($upperEntityPath=$table.entityPath.toUpperCase())
|
||||||
export const $!{moduleName}_NAMESPACE = '$!{table.entityPath}';
|
export const $!{upperEntityPath}_NAMESPACE = '$!{table.entityPath}';
|
||||||
|
|
||||||
export function $!{moduleName}_LIST(payload) {
|
export function $!{upperEntityPath}_LIST(payload) {
|
||||||
return {
|
return {
|
||||||
type: `${$!{moduleName}_NAMESPACE}/fetchList`,
|
type: `${$!{upperEntityPath}_NAMESPACE}/fetchList`,
|
||||||
payload,
|
payload,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function $!{moduleName}_DETAIL(id) {
|
export function $!{upperEntityPath}_DETAIL(id) {
|
||||||
return {
|
return {
|
||||||
type: `${$!{moduleName}_NAMESPACE}/fetchDetail`,
|
type: `${$!{upperEntityPath}_NAMESPACE}/fetchDetail`,
|
||||||
payload: { id },
|
payload: { id },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function $!{moduleName}_CLEAR_DETAIL() {
|
export function $!{upperEntityPath}_CLEAR_DETAIL() {
|
||||||
return {
|
return {
|
||||||
type: `${$!{moduleName}_NAMESPACE}/clearDetail`,
|
type: `${$!{upperEntityPath}_NAMESPACE}/clearDetail`,
|
||||||
payload: {},
|
payload: {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function $!{moduleName}_SUBMIT(payload) {
|
export function $!{upperEntityPath}_SUBMIT(payload) {
|
||||||
return {
|
return {
|
||||||
type: `${$!{moduleName}_NAMESPACE}/submit`,
|
type: `${$!{upperEntityPath}_NAMESPACE}/submit`,
|
||||||
payload,
|
payload,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function $!{moduleName}_REMOVE(payload) {
|
export function $!{upperEntityPath}_REMOVE(payload) {
|
||||||
return {
|
return {
|
||||||
type: `${$!{moduleName}_NAMESPACE}/remove`,
|
type: `${$!{upperEntityPath}_NAMESPACE}/remove`,
|
||||||
payload,
|
payload,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
#set($upperEntityPath=$table.entityPath.toUpperCase())
|
||||||
|
import React, { PureComponent } from 'react';
|
||||||
|
import { Form, Input, Card, Button } from 'antd';
|
||||||
|
import { connect } from 'dva';
|
||||||
|
import Panel from '../../../components/Panel';
|
||||||
|
import styles from '../../../layouts/Sword.less';
|
||||||
|
import { $!{upperEntityPath}_SUBMIT } from '../../../actions/$!{table.entityPath}';
|
||||||
|
|
||||||
|
const FormItem = Form.Item;
|
||||||
|
|
||||||
|
@connect(({ loading }) => ({
|
||||||
|
submitting: loading.effects['$!{table.entityPath}/submit'],
|
||||||
|
}))
|
||||||
|
@Form.create()
|
||||||
|
class $!{entity}Add extends PureComponent {
|
||||||
|
handleSubmit = e => {
|
||||||
|
e.preventDefault();
|
||||||
|
const { dispatch, form } = this.props;
|
||||||
|
form.validateFieldsAndScroll((err, values) => {
|
||||||
|
if (!err) {
|
||||||
|
dispatch($!{upperEntityPath}_SUBMIT(values));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
form: { getFieldDecorator },
|
||||||
|
submitting,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const formItemLayout = {
|
||||||
|
labelCol: {
|
||||||
|
xs: { span: 24 },
|
||||||
|
sm: { span: 7 },
|
||||||
|
},
|
||||||
|
wrapperCol: {
|
||||||
|
xs: { span: 24 },
|
||||||
|
sm: { span: 12 },
|
||||||
|
md: { span: 10 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const action = (
|
||||||
|
<Button type="primary" onClick={this.handleSubmit} loading={submitting}>
|
||||||
|
提交
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Panel title="新增" back="/$!{cfg.servicePackage}/$!{table.entityPath}" action={action}>
|
||||||
|
<Form hideRequiredMark style={{ marginTop: 8 }}>
|
||||||
|
<Card className={styles.card} bordered={false}>
|
||||||
|
#foreach($field in $!{table.fields})
|
||||||
|
<FormItem {...formItemLayout} label="$!{field.comment}">
|
||||||
|
{getFieldDecorator('$!{field.propertyName}', {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入$!{field.comment}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})(<Input placeholder="请输入$!{field.comment}" />)}
|
||||||
|
</FormItem>
|
||||||
|
#end
|
||||||
|
</Card>
|
||||||
|
</Form>
|
||||||
|
</Panel>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default $!{entity}Add;
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
#set($upperEntityPath=$table.entityPath.toUpperCase())
|
||||||
|
import React, { PureComponent } from 'react';
|
||||||
|
import { Form, Input, Card, Button } from 'antd';
|
||||||
|
import { connect } from 'dva';
|
||||||
|
import Panel from '../../../components/Panel';
|
||||||
|
import styles from '../../../layouts/Sword.less';
|
||||||
|
import { $!{upperEntityPath}_DETAIL, $!{upperEntityPath}_SUBMIT } from '../../../actions/$!{table.entityPath}';
|
||||||
|
|
||||||
|
const FormItem = Form.Item;
|
||||||
|
|
||||||
|
@connect(({ $!{table.entityPath}, loading }) => ({
|
||||||
|
$!{table.entityPath},
|
||||||
|
submitting: loading.effects['code/submit'],
|
||||||
|
}))
|
||||||
|
@Form.create()
|
||||||
|
class $!{entity}Edit extends PureComponent {
|
||||||
|
componentWillMount() {
|
||||||
|
const {
|
||||||
|
dispatch,
|
||||||
|
match: {
|
||||||
|
params: { id },
|
||||||
|
},
|
||||||
|
} = this.props;
|
||||||
|
dispatch($!{upperEntityPath}_DETAIL(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit = e => {
|
||||||
|
e.preventDefault();
|
||||||
|
const {
|
||||||
|
dispatch,
|
||||||
|
match: {
|
||||||
|
params: { id },
|
||||||
|
},
|
||||||
|
form,
|
||||||
|
} = this.props;
|
||||||
|
form.validateFieldsAndScroll((err, values) => {
|
||||||
|
if (!err) {
|
||||||
|
const params = {
|
||||||
|
id,
|
||||||
|
...values,
|
||||||
|
};
|
||||||
|
console.log(params);
|
||||||
|
dispatch($!{upperEntityPath}_SUBMIT(params));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
form: { getFieldDecorator },
|
||||||
|
$!{table.entityPath}: { detail },
|
||||||
|
submitting,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const formItemLayout = {
|
||||||
|
labelCol: {
|
||||||
|
xs: { span: 24 },
|
||||||
|
sm: { span: 7 },
|
||||||
|
},
|
||||||
|
wrapperCol: {
|
||||||
|
xs: { span: 24 },
|
||||||
|
sm: { span: 12 },
|
||||||
|
md: { span: 10 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const action = (
|
||||||
|
<Button type="primary" onClick={this.handleSubmit} loading={submitting}>
|
||||||
|
提交
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Panel title="修改" back="/$!{cfg.servicePackage}/$!{table.entityPath}" action={action}>
|
||||||
|
<Form hideRequiredMark style={{ marginTop: 8 }}>
|
||||||
|
<Card className={styles.card} bordered={false}>
|
||||||
|
#foreach($field in $!{table.fields})
|
||||||
|
<FormItem {...formItemLayout} label="$!{field.comment}">
|
||||||
|
{getFieldDecorator('$!{field.propertyName}', {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入$!{field.comment}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
initialValue: detail.$!{field.propertyName},
|
||||||
|
})(<Input placeholder="请输入$!{field.comment}" />)}
|
||||||
|
</FormItem>
|
||||||
|
#end
|
||||||
|
</Card>
|
||||||
|
</Form>
|
||||||
|
</Panel>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default $!{entity}Edit;
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
#set($upperEntityPath=$table.entityPath.toUpperCase())
|
||||||
|
import React, { PureComponent } from 'react';
|
||||||
|
import { connect } from 'dva';
|
||||||
|
import { Button, Col, Form, Input, Row } from 'antd';
|
||||||
|
import Panel from '../../../components/Panel';
|
||||||
|
import { $!{upperEntityPath}_LIST } from '../../../actions/$!{table.entityPath}';
|
||||||
|
import Grid from '../../../components/Sword/Grid';
|
||||||
|
|
||||||
|
const FormItem = Form.Item;
|
||||||
|
|
||||||
|
@connect(({ $!{table.entityPath}, loading }) => ({
|
||||||
|
$!{table.entityPath},
|
||||||
|
loading: loading.models.param,
|
||||||
|
}))
|
||||||
|
@Form.create()
|
||||||
|
class $!{entity} extends PureComponent {
|
||||||
|
// ============ 查询 ===============
|
||||||
|
handleSearch = params => {
|
||||||
|
const { dispatch } = this.props;
|
||||||
|
dispatch($!{upperEntityPath}_LIST(params));
|
||||||
|
};
|
||||||
|
|
||||||
|
// ============ 查询表单 ===============
|
||||||
|
renderSearchForm = onReset => {
|
||||||
|
const { form } = this.props;
|
||||||
|
const { getFieldDecorator } = form;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Row gutter={{ md: 8, lg: 24, xl: 48 }}>
|
||||||
|
<Col md={6} sm={24}>
|
||||||
|
<FormItem label="查询名称">
|
||||||
|
{getFieldDecorator('name')(<Input placeholder="查询名称" />)}
|
||||||
|
</FormItem>
|
||||||
|
</Col>
|
||||||
|
<Col>
|
||||||
|
<div style={{ float: 'right' }}>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
查询
|
||||||
|
</Button>
|
||||||
|
<Button style={{ marginLeft: 8 }} onClick={onReset}>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const code = '$!{table.entityPath}';
|
||||||
|
|
||||||
|
const {
|
||||||
|
form,
|
||||||
|
loading,
|
||||||
|
param: { data },
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
#foreach($field in $!{table.fields})
|
||||||
|
{
|
||||||
|
title: '$!{field.comment}',
|
||||||
|
dataIndex: '$!{field.propertyName}',
|
||||||
|
},
|
||||||
|
#end
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Panel>
|
||||||
|
<Grid
|
||||||
|
code={code}
|
||||||
|
form={form}
|
||||||
|
onSearch={this.handleSearch}
|
||||||
|
renderSearchForm={this.renderSearchForm}
|
||||||
|
loading={loading}
|
||||||
|
data={data}
|
||||||
|
columns={columns}
|
||||||
|
/>
|
||||||
|
</Panel>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default $!{entity};
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
#set($moduleName=$table.entityPath.toUpperCase())
|
#set($upperEntityPath=$table.entityPath.toUpperCase())
|
||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
import { $!{moduleName}_NAMESPACE } from '../actions/$!{table.entityPath}';
|
import router from 'umi/router';
|
||||||
|
import { $!{upperEntityPath}_NAMESPACE } from '../actions/$!{table.entityPath}';
|
||||||
import { list, submit, detail, remove } from '../services/$!{table.entityPath}';
|
import { list, submit, detail, remove } from '../services/$!{table.entityPath}';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespace: $!{moduleName}_NAMESPACE,
|
namespace: $!{upperEntityPath}_NAMESPACE,
|
||||||
state: {
|
state: {
|
||||||
data: {
|
data: {
|
||||||
list: [],
|
list: [],
|
||||||
|
|
@ -46,6 +47,7 @@ export default {
|
||||||
const response = yield call(submit, payload);
|
const response = yield call(submit, payload);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
message.success('提交成功');
|
message.success('提交成功');
|
||||||
|
router.push('/$!{cfg.servicePackage}/$!{table.entityPath}');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
*remove({ payload }, { call }) {
|
*remove({ payload }, { call }) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
#set($upperEntityPath=$table.entityPath.toUpperCase())
|
||||||
|
import React, { PureComponent } from 'react';
|
||||||
|
import router from 'umi/router';
|
||||||
|
import { Form, Card, Button } from 'antd';
|
||||||
|
import { connect } from 'dva';
|
||||||
|
import Panel from '../../../components/Panel';
|
||||||
|
import styles from '../../../layouts/Sword.less';
|
||||||
|
import { $!{upperEntityPath}_DETAIL } from '../../../actions/$!{table.entityPath}';
|
||||||
|
|
||||||
|
const FormItem = Form.Item;
|
||||||
|
|
||||||
|
@connect(({ code }) => ({
|
||||||
|
code,
|
||||||
|
}))
|
||||||
|
@Form.create()
|
||||||
|
class $!{entity}View extends PureComponent {
|
||||||
|
componentWillMount() {
|
||||||
|
const {
|
||||||
|
dispatch,
|
||||||
|
match: {
|
||||||
|
params: { id },
|
||||||
|
},
|
||||||
|
} = this.props;
|
||||||
|
dispatch($!{upperEntityPath}_DETAIL(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleEdit = () => {
|
||||||
|
const {
|
||||||
|
match: {
|
||||||
|
params: { id },
|
||||||
|
},
|
||||||
|
} = this.props;
|
||||||
|
router.push(`/$!{cfg.servicePackage}/$!{table.entityPath}/edit/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
$!{table.entityPath}: { detail },
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const formItemLayout = {
|
||||||
|
labelCol: {
|
||||||
|
xs: { span: 24 },
|
||||||
|
sm: { span: 7 },
|
||||||
|
},
|
||||||
|
wrapperCol: {
|
||||||
|
xs: { span: 24 },
|
||||||
|
sm: { span: 12 },
|
||||||
|
md: { span: 10 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const action = (
|
||||||
|
<Button type="primary" onClick={this.handleEdit}>
|
||||||
|
修改
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Panel title="查看" back="/$!{cfg.servicePackage}/$!{table.entityPath}" action={action}>
|
||||||
|
<Form hideRequiredMark style={{ marginTop: 8 }}>
|
||||||
|
<Card className={styles.card} bordered={false}>
|
||||||
|
#foreach($field in $!{table.fields})
|
||||||
|
<FormItem {...formItemLayout} label="$!{field.comment}">
|
||||||
|
<span>{detail.$!{field.propertyName}}</span>
|
||||||
|
</FormItem>
|
||||||
|
#end
|
||||||
|
</Card>
|
||||||
|
</Form>
|
||||||
|
</Panel>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default $!{entity}View;
|
||||||
Loading…
Reference in New Issue
Block a user