From 5accc5fdf3d4482f5ce949922f44a96a64bd9de5 Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 21 Jan 2019 11:06:19 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E5=A2=9E=E5=8A=A0=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD=20:zap:=20=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEeslint=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 3 +- mock/code.js | 1 + src/pages/Desk/Notice/NoticeEdit.js | 5 ++- src/pages/System/Code/Code.js | 51 ++++++++++++++++++++++++++++- src/pages/System/Role/Role.js | 11 ++++--- src/pages/System/User/User.js | 7 ++-- src/services/code.js | 7 ++++ src/utils/Func.js | 12 +++---- 8 files changed, 76 insertions(+), 21 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 369b6f1..cd6da0a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -31,7 +31,8 @@ module.exports = { 'jsx-a11y/click-events-have-key-events': 0, 'jsx-a11y/no-static-element-interactions': 0, 'jsx-a11y/anchor-is-valid': 0, - 'linebreak-style': ['off'], + 'no-nested-ternary': 0, + 'linebreak-style': 0, }, settings: { polyfills: ['fetch', 'promises', 'url'], diff --git a/mock/code.js b/mock/code.js index 88bf740..5666568 100644 --- a/mock/code.js +++ b/mock/code.js @@ -48,5 +48,6 @@ const proxy = { 'GET /api/blade-system/code/detail': getFakeDetail, 'POST /api/blade-system/code/submit': fakeSuccess, 'POST /api/blade-system/code/remove': fakeSuccess, + 'POST /api/blade-system/code/gen-code': fakeSuccess, }; export default delay(proxy, 500); diff --git a/src/pages/Desk/Notice/NoticeEdit.js b/src/pages/Desk/Notice/NoticeEdit.js index ce99645..5e778f9 100644 --- a/src/pages/Desk/Notice/NoticeEdit.js +++ b/src/pages/Desk/Notice/NoticeEdit.js @@ -47,10 +47,9 @@ class NoticeAdd extends PureComponent { }); }; - disabledDate = current => { + disabledDate = current => // Can not select days before today - return current && current < moment().endOf('day'); - }; + current && current < moment().endOf('day'); render() { const { diff --git a/src/pages/System/Code/Code.js b/src/pages/System/Code/Code.js index 504dcac..469fa8d 100644 --- a/src/pages/System/Code/Code.js +++ b/src/pages/System/Code/Code.js @@ -1,9 +1,10 @@ import React, { PureComponent } from 'react'; 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 Grid from '../../../components/Sword/Grid'; import { CODE_LIST } from '../../../actions/code'; +import { genCodes } from '../../../services/code'; const FormItem = Form.Item; @@ -13,12 +14,52 @@ const FormItem = Form.Item; })) @Form.create() class Code extends PureComponent { + state = { + selectedRows: [], + }; + // ============ 查询 =============== handleSearch = params => { const { dispatch } = this.props; 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 => { const { form } = this.props; @@ -55,6 +96,12 @@ class Code extends PureComponent { ); }; + renderLeftButton = () => ( + + ); + render() { const code = 'code'; @@ -92,8 +139,10 @@ class Code extends PureComponent { { const { selectedRows } = this.state; - return selectedRows.map(row => { - return row.id; - }); + return selectedRows.map(row => row.id); }; // ============ 查询 =============== @@ -79,6 +77,7 @@ class Role extends PureComponent { dispatch(MENU_REFRESH_DATA()); }) ); + return true; }; showModal = () => { @@ -142,7 +141,11 @@ class Role extends PureComponent { ); }; - renderLeftButton = () => ; + renderLeftButton = () => ( + + ); renderTreeNodes = data => data.map(item => { diff --git a/src/pages/System/User/User.js b/src/pages/System/User/User.js index 34a90c5..5b4ff39 100644 --- a/src/pages/System/User/User.js +++ b/src/pages/System/User/User.js @@ -35,9 +35,7 @@ class User extends PureComponent { getSelectKeys = () => { const { selectedRows } = this.state; - return selectedRows.map(row => { - return row.id; - }); + return selectedRows.map(row => row.id); }; // ============ 查询 =============== @@ -55,7 +53,7 @@ class User extends PureComponent { return; } this.showModal(); - return false; + return; } if (btn.code === 'user_reset') { if (keys.length === 0) { @@ -78,7 +76,6 @@ class User extends PureComponent { }, onCancel() {}, }); - return false; } }; diff --git a/src/services/code.js b/src/services/code.js index cb434b2..f5843d6 100644 --- a/src/services/code.js +++ b/src/services/code.js @@ -25,3 +25,10 @@ export async function submit(params) { export async function detail(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, + }); +} diff --git a/src/utils/Func.js b/src/utils/Func.js index b430de0..5d67274 100644 --- a/src/utils/Func.js +++ b/src/utils/Func.js @@ -25,9 +25,8 @@ export default class Func { (typeof val === 'string' && val === '' && val !== 'undefined') ) { return true; - } else { - return false; } + return false; } /** @@ -39,10 +38,9 @@ export default class Func { static toInt(val, defaultValue) { if (this.isEmpty(val)) { 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) { 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]); - } + }); return data; }