⚡ 增加代码生成功能
⚡ 根据eslint优化代码
This commit is contained in:
parent
a8e2799709
commit
5accc5fdf3
|
|
@ -31,7 +31,8 @@ module.exports = {
|
||||||
'jsx-a11y/click-events-have-key-events': 0,
|
'jsx-a11y/click-events-have-key-events': 0,
|
||||||
'jsx-a11y/no-static-element-interactions': 0,
|
'jsx-a11y/no-static-element-interactions': 0,
|
||||||
'jsx-a11y/anchor-is-valid': 0,
|
'jsx-a11y/anchor-is-valid': 0,
|
||||||
'linebreak-style': ['off'],
|
'no-nested-ternary': 0,
|
||||||
|
'linebreak-style': 0,
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
polyfills: ['fetch', 'promises', 'url'],
|
polyfills: ['fetch', 'promises', 'url'],
|
||||||
|
|
|
||||||
|
|
@ -48,5 +48,6 @@ const proxy = {
|
||||||
'GET /api/blade-system/code/detail': getFakeDetail,
|
'GET /api/blade-system/code/detail': getFakeDetail,
|
||||||
'POST /api/blade-system/code/submit': fakeSuccess,
|
'POST /api/blade-system/code/submit': fakeSuccess,
|
||||||
'POST /api/blade-system/code/remove': fakeSuccess,
|
'POST /api/blade-system/code/remove': fakeSuccess,
|
||||||
|
'POST /api/blade-system/code/gen-code': fakeSuccess,
|
||||||
};
|
};
|
||||||
export default delay(proxy, 500);
|
export default delay(proxy, 500);
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,9 @@ class NoticeAdd extends PureComponent {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
disabledDate = current => {
|
disabledDate = current =>
|
||||||
// Can not select days before today
|
// Can not select days before today
|
||||||
return current && current < moment().endOf('day');
|
current && current < moment().endOf('day');
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import { connect } from 'dva';
|
import { connect } from 'dva';
|
||||||
import { Button, Col, Form, Input, Row } from 'antd';
|
import { Button, Col, Form, Input, message, Modal, Row } from 'antd';
|
||||||
import Panel from '../../../components/Panel';
|
import Panel from '../../../components/Panel';
|
||||||
import Grid from '../../../components/Sword/Grid';
|
import Grid from '../../../components/Sword/Grid';
|
||||||
import { CODE_LIST } from '../../../actions/code';
|
import { CODE_LIST } from '../../../actions/code';
|
||||||
|
import { genCodes } from '../../../services/code';
|
||||||
|
|
||||||
const FormItem = Form.Item;
|
const FormItem = Form.Item;
|
||||||
|
|
||||||
|
|
@ -13,12 +14,52 @@ const FormItem = Form.Item;
|
||||||
}))
|
}))
|
||||||
@Form.create()
|
@Form.create()
|
||||||
class Code extends PureComponent {
|
class Code extends PureComponent {
|
||||||
|
state = {
|
||||||
|
selectedRows: [],
|
||||||
|
};
|
||||||
|
|
||||||
// ============ 查询 ===============
|
// ============ 查询 ===============
|
||||||
handleSearch = params => {
|
handleSearch = params => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
dispatch(CODE_LIST(params));
|
dispatch(CODE_LIST(params));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onSelectRow = rows => {
|
||||||
|
this.setState({
|
||||||
|
selectedRows: rows,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
getSelectKeys = () => {
|
||||||
|
const { selectedRows } = this.state;
|
||||||
|
return selectedRows.map(row => row.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ============ 代码生成 ===============
|
||||||
|
genCode = () => {
|
||||||
|
const keys = this.getSelectKeys();
|
||||||
|
if (keys.length === 0) {
|
||||||
|
message.warn('请先选择一条数据!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Modal.confirm({
|
||||||
|
title: '代码生成确认',
|
||||||
|
content: '是否生成选中模块的代码?',
|
||||||
|
okText: '确定',
|
||||||
|
okType: 'danger',
|
||||||
|
cancelText: '取消',
|
||||||
|
async onOk() {
|
||||||
|
const response = await genCodes({ ids: keys });
|
||||||
|
if (response.success) {
|
||||||
|
message.success(response.msg);
|
||||||
|
} else {
|
||||||
|
message.error(response.msg || '生成失败');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCancel() {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// ============ 查询表单 ===============
|
// ============ 查询表单 ===============
|
||||||
renderSearchForm = onReset => {
|
renderSearchForm = onReset => {
|
||||||
const { form } = this.props;
|
const { form } = this.props;
|
||||||
|
|
@ -55,6 +96,12 @@ class Code extends PureComponent {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
renderLeftButton = () => (
|
||||||
|
<Button icon="tool" onClick={this.genCode}>
|
||||||
|
代码生成
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const code = 'code';
|
const code = 'code';
|
||||||
|
|
||||||
|
|
@ -92,8 +139,10 @@ class Code extends PureComponent {
|
||||||
<Grid
|
<Grid
|
||||||
code={code}
|
code={code}
|
||||||
form={form}
|
form={form}
|
||||||
|
onSelectRow={this.onSelectRow}
|
||||||
onSearch={this.handleSearch}
|
onSearch={this.handleSearch}
|
||||||
renderSearchForm={this.renderSearchForm}
|
renderSearchForm={this.renderSearchForm}
|
||||||
|
renderLeftButton={this.renderLeftButton}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
data={data}
|
data={data}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,7 @@ class Role extends PureComponent {
|
||||||
|
|
||||||
getSelectKeys = () => {
|
getSelectKeys = () => {
|
||||||
const { selectedRows } = this.state;
|
const { selectedRows } = this.state;
|
||||||
return selectedRows.map(row => {
|
return selectedRows.map(row => row.id);
|
||||||
return row.id;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============ 查询 ===============
|
// ============ 查询 ===============
|
||||||
|
|
@ -79,6 +77,7 @@ class Role extends PureComponent {
|
||||||
dispatch(MENU_REFRESH_DATA());
|
dispatch(MENU_REFRESH_DATA());
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
showModal = () => {
|
showModal = () => {
|
||||||
|
|
@ -142,7 +141,11 @@ class Role extends PureComponent {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
renderLeftButton = () => <Button onClick={this.showModal}>权限设置</Button>;
|
renderLeftButton = () => (
|
||||||
|
<Button icon="user-add" onClick={this.showModal}>
|
||||||
|
权限设置
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
|
||||||
renderTreeNodes = data =>
|
renderTreeNodes = data =>
|
||||||
data.map(item => {
|
data.map(item => {
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,7 @@ class User extends PureComponent {
|
||||||
|
|
||||||
getSelectKeys = () => {
|
getSelectKeys = () => {
|
||||||
const { selectedRows } = this.state;
|
const { selectedRows } = this.state;
|
||||||
return selectedRows.map(row => {
|
return selectedRows.map(row => row.id);
|
||||||
return row.id;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============ 查询 ===============
|
// ============ 查询 ===============
|
||||||
|
|
@ -55,7 +53,7 @@ class User extends PureComponent {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.showModal();
|
this.showModal();
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
if (btn.code === 'user_reset') {
|
if (btn.code === 'user_reset') {
|
||||||
if (keys.length === 0) {
|
if (keys.length === 0) {
|
||||||
|
|
@ -78,7 +76,6 @@ class User extends PureComponent {
|
||||||
},
|
},
|
||||||
onCancel() {},
|
onCancel() {},
|
||||||
});
|
});
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,3 +25,10 @@ export async function submit(params) {
|
||||||
export async function detail(params) {
|
export async function detail(params) {
|
||||||
return request(`/api/blade-system/code/detail?${stringify(params)}`);
|
return request(`/api/blade-system/code/detail?${stringify(params)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function genCodes(params) {
|
||||||
|
return request('/api/blade-system/code/gen-code', {
|
||||||
|
method: 'POST',
|
||||||
|
body: params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,8 @@ export default class Func {
|
||||||
(typeof val === 'string' && val === '' && val !== 'undefined')
|
(typeof val === 'string' && val === '' && val !== 'undefined')
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,10 +38,9 @@ export default class Func {
|
||||||
static toInt(val, defaultValue) {
|
static toInt(val, defaultValue) {
|
||||||
if (this.isEmpty(val)) {
|
if (this.isEmpty(val)) {
|
||||||
return defaultValue === undefined ? -1 : defaultValue;
|
return defaultValue === undefined ? -1 : defaultValue;
|
||||||
} else {
|
|
||||||
const num = parseInt(val, 0);
|
|
||||||
return Number.isNaN(num) ? (defaultValue === undefined ? -1 : defaultValue) : num;
|
|
||||||
}
|
}
|
||||||
|
const num = parseInt(val, 0);
|
||||||
|
return Number.isNaN(num) ? (defaultValue === undefined ? -1 : defaultValue) : num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,9 +50,9 @@ export default class Func {
|
||||||
*/
|
*/
|
||||||
static toFormData(obj) {
|
static toFormData(obj) {
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
for (const key of Object.keys(obj)) {
|
Object.keys(obj).forEach(key => {
|
||||||
data.append(key, Array.isArray(obj[key]) ? obj[key].join(',') : obj[key]);
|
data.append(key, Array.isArray(obj[key]) ? obj[key].join(',') : obj[key]);
|
||||||
}
|
});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user