From 36265935d3acce0bc6e8ce478f0e525a7ba63214 Mon Sep 17 00:00:00 2001 From: wanhello Date: Fri, 23 Apr 2021 17:19:41 +0800 Subject: [PATCH 01/15] update axios to 0.21.1 for Vulnerabilities --- package.json | 2 +- src/utils/request.js | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 18cda83..4cf28ff 100755 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "@ant-design/compatible": "^1.0.2", "@ant-design/icons": "^4.0.6", "antd": "^4.1.2", - "axios": "^0.18.0", + "axios": "^0.21.1", "classnames": "^2.2.5", "history": "^4.7.2", "lodash": "^4.17.10", diff --git a/src/utils/request.js b/src/utils/request.js index 34b822f..0095e95 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -75,8 +75,14 @@ function requestInterceptors(c) { return config; } +const instance = axios.create({ + baseURL, + timeout: 10000, +}); +instance.interceptors.request.use(requestInterceptors); + // ajax请求 -export default function request(url, options = {}) { +export default function request(url, options = { method: methods.GET }) { const oldToken = store.get(storeKeys.AccessToken); if (oldToken && oldToken.expires_at - lastAccessTime <= 0) { if (refreshTimeout) { @@ -96,23 +102,11 @@ export default function request(url, options = {}) { } const config = { - method: methods.GET, - baseURL, + method: opts.method, headers: {}, - transformRequest: (data, headers) => { - switch (headers[headerKeys.ContentType]) { - case contentType.json: - return JSON.stringify(data); - case contentType.form: - return stringify(data); - default: - return data; - } - }, paramsSerializer: params => { return stringify(params); }, - timeout: 60000, ...opts, }; @@ -123,11 +117,8 @@ export default function request(url, options = {}) { config.headers[headerKeys.ContentType] = contentType.json; } - const instance = axios.create(config); - instance.interceptors.request.use(requestInterceptors); - return instance - .request({ url }) + .request({ url, ...config }) .then(res => { const { data } = res; return data; From 8858ac6e1998bbfab2458f805403065d8ea4616d Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 21:43:35 +0800 Subject: [PATCH 02/15] demo form v3 to v4 --- src/models/demo.js | 25 +++++++++- src/pages/Demo/DemoCard.js | 98 ++++++++++++++++++++------------------ src/pages/Demo/DemoList.js | 2 +- 3 files changed, 76 insertions(+), 49 deletions(-) diff --git a/src/models/demo.js b/src/models/demo.js index cd65034..4da3d98 100644 --- a/src/models/demo.js +++ b/src/models/demo.js @@ -13,6 +13,7 @@ export default { submitting: false, formTitle: '', formID: '', + formModalVisible: false, formVisible: false, formData: {}, }, @@ -54,7 +55,7 @@ export default { }, *loadForm({ payload }, { put }) { yield put({ - type: 'changeFormVisible', + type: 'changeModalFormVisible', payload: true, }); @@ -92,6 +93,13 @@ export default { payload: { id: payload.id }, }), ]; + } else { + yield [ + put({ + type: 'changeFormVisible', + payload: true, + }), + ]; } }, *fetchForm({ payload }, { call, put }) { @@ -101,6 +109,10 @@ export default { type: 'saveFormData', payload: response, }), + put({ + type: 'changeFormVisible', + payload: true, + }), ]; }, *submit({ payload }, { call, put, select }) { @@ -133,7 +145,7 @@ export default { if (success) { message.success('保存成功'); yield put({ - type: 'changeFormVisible', + type: 'changeModalFormVisible', payload: false, }); yield put({ @@ -191,8 +203,17 @@ export default { return { ...state, pagination: payload }; }, changeFormVisible(state, { payload }) { + if (payload) { + return { ...state, formModalVisible: payload, formVisible: payload }; + } return { ...state, formVisible: payload }; }, + changeModalFormVisible(state, { payload }) { + if (!payload) { + return { ...state, formModalVisible: payload, formVisible: payload }; + } + return { ...state, formModalVisible: payload }; + }, saveFormTitle(state, { payload }) { return { ...state, formTitle: payload }; }, diff --git a/src/pages/Demo/DemoCard.js b/src/pages/Demo/DemoCard.js index 6afa12d..9a8fb5c 100644 --- a/src/pages/Demo/DemoCard.js +++ b/src/pages/Demo/DemoCard.js @@ -1,24 +1,32 @@ import React, { PureComponent } from 'react'; import { connect } from 'dva'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Input, Modal, Radio } from 'antd'; +import { Form, Input, Modal, Radio } from 'antd'; @connect(state => ({ demo: state.demo, })) -@Form.create() class DemoCard extends PureComponent { + formRef = React.createRef(); + + onFinishFailed(err) { + const { errorFields } = err; + this.formRef.current.scrollToField(errorFields[0].name); + } + onOKClick = () => { - const { form, onSubmit } = this.props; + const { onSubmit } = this.props; - form.validateFieldsAndScroll((err, values) => { - if (!err) { + this.formRef.current + .validateFields() + .then(values => { const formData = { ...values }; formData.status = parseInt(formData.status, 10); onSubmit(formData); - } - }); + }) + .catch(err => { + console.log(' ----- === err :', err); + }); }; dispatch = action => { @@ -29,8 +37,7 @@ class DemoCard extends PureComponent { render() { const { onCancel, - demo: { formTitle, formVisible, formData, submitting }, - form: { getFieldDecorator }, + demo: { formTitle, formVisible, formModalVisible, formData, submitting }, } = this.props; const formItemLayout = { @@ -48,7 +55,7 @@ class DemoCard extends PureComponent { -
- - {getFieldDecorator('code', { - initialValue: formData.code, - rules: [ - { - required: true, - message: '请输入编号', - }, - ], - })()} - - - {getFieldDecorator('name', { - initialValue: formData.name, - rules: [ - { - required: true, - message: '请输入名称', - }, - ], - })()} - - - {getFieldDecorator('memo', { - initialValue: formData.memo, - })()} - - - {getFieldDecorator('status', { - initialValue: formData.status ? formData.status.toString() : '1', - })( + {formVisible && ( + + + + + + + + + + + 正常 停用 - )} - - +
+ + )}
); } diff --git a/src/pages/Demo/DemoList.js b/src/pages/Demo/DemoList.js index c8d02a4..4d3b38a 100644 --- a/src/pages/Demo/DemoList.js +++ b/src/pages/Demo/DemoList.js @@ -150,7 +150,7 @@ class DemoList extends PureComponent { onDataFormCancel = () => { this.dispatch({ - type: 'demo/changeFormVisible', + type: 'demo/changeModalFormVisible', payload: false, }); }; From 62f83be1df51d8a9d188c0d1150841a8321c0145 Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 22:13:15 +0800 Subject: [PATCH 03/15] user form v3 to v4 --- src/models/menu.js | 10 +++ src/models/role.js | 10 +++ src/models/user.js | 10 +++ src/pages/Menu/MenuList.js | 2 +- src/pages/Role/RoleList.js | 2 +- src/pages/User/UserCard.js | 144 +++++++++++++++++++------------------ src/pages/User/UserList.js | 2 +- 7 files changed, 107 insertions(+), 73 deletions(-) diff --git a/src/models/menu.js b/src/models/menu.js index 4f97ef8..3efe1c6 100644 --- a/src/models/menu.js +++ b/src/models/menu.js @@ -14,6 +14,7 @@ export default { formType: '', formTitle: '', formID: '', + formModalVisible: false, formVisible: false, formData: {}, treeData: [], @@ -213,8 +214,17 @@ export default { return { ...state, pagination: payload }; }, changeFormVisible(state, { payload }) { + if (payload) { + return { ...state, formModalVisible: payload, formVisible: payload }; + } return { ...state, formVisible: payload }; }, + changeModalFormVisible(state, { payload }) { + if (!payload) { + return { ...state, formModalVisible: payload, formVisible: payload }; + } + return { ...state, formModalVisible: payload }; + }, saveFormType(state, { payload }) { return { ...state, formType: payload }; }, diff --git a/src/models/role.js b/src/models/role.js index 00d91d3..d73ab14 100644 --- a/src/models/role.js +++ b/src/models/role.js @@ -13,6 +13,7 @@ export default { submitting: false, formTitle: '', formID: '', + formModalVisible: false, formVisible: false, formData: {}, selectData: [], @@ -218,8 +219,17 @@ export default { return { ...state, pagination: payload }; }, changeFormVisible(state, { payload }) { + if (payload) { + return { ...state, formModalVisible: payload, formVisible: payload }; + } return { ...state, formVisible: payload }; }, + changeModalFormVisible(state, { payload }) { + if (!payload) { + return { ...state, formModalVisible: payload, formVisible: payload }; + } + return { ...state, formModalVisible: payload }; + }, saveFormTitle(state, { payload }) { return { ...state, formTitle: payload }; }, diff --git a/src/models/user.js b/src/models/user.js index 3acc08c..bb07cbb 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -12,6 +12,7 @@ export default { submitting: false, formTitle: '', formID: '', + formModalVisible: false, formVisible: false, formData: {}, }, @@ -185,8 +186,17 @@ export default { return { ...state, search: payload }; }, changeFormVisible(state, { payload }) { + if (payload) { + return { ...state, formModalVisible: payload, formVisible: payload }; + } return { ...state, formVisible: payload }; }, + changeModalFormVisible(state, { payload }) { + if (!payload) { + return { ...state, formModalVisible: payload, formVisible: payload }; + } + return { ...state, formModalVisible: payload }; + }, saveFormTitle(state, { payload }) { return { ...state, formTitle: payload }; }, diff --git a/src/pages/Menu/MenuList.js b/src/pages/Menu/MenuList.js index e85fd50..1c681c2 100644 --- a/src/pages/Menu/MenuList.js +++ b/src/pages/Menu/MenuList.js @@ -152,7 +152,7 @@ class MenuList extends PureComponent { handleFormCancel = () => { this.dispatch({ - type: 'menu/changeFormVisible', + type: 'menu/changeModalFormVisible', payload: false, }); }; diff --git a/src/pages/Role/RoleList.js b/src/pages/Role/RoleList.js index 8ab1fd8..b77807d 100644 --- a/src/pages/Role/RoleList.js +++ b/src/pages/Role/RoleList.js @@ -149,7 +149,7 @@ class RoleList extends PureComponent { handleDataFormCancel = () => { this.dispatch({ - type: 'role/changeFormVisible', + type: 'role/changeModalFormVisible', payload: false, }); }; diff --git a/src/pages/User/UserCard.js b/src/pages/User/UserCard.js index 48897c5..1e436ee 100644 --- a/src/pages/User/UserCard.js +++ b/src/pages/User/UserCard.js @@ -1,29 +1,37 @@ import React, { PureComponent } from 'react'; import { connect } from 'dva'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Input, Modal, Radio } from 'antd'; +import { Form, Input, Modal, Radio } from 'antd'; import { md5Hash } from '../../utils/utils'; import RoleSelect from './RoleSelect'; @connect(state => ({ user: state.user, })) -@Form.create() class UserCard extends PureComponent { + formRef = React.createRef(); + + onFinishFailed(err) { + const { errorFields } = err; + this.formRef.current.scrollToField(errorFields[0].name); + } + onOKClick = () => { - const { form, onSubmit } = this.props; + const { onSubmit } = this.props; - form.validateFieldsAndScroll((err, values) => { - if (!err) { + this.formRef.current + .validateFields() + .then(values => { const formData = { ...values }; formData.status = parseInt(formData.status, 10); if (formData.password && formData.password !== '') { formData.password = md5Hash(formData.password); } onSubmit(formData); - } - }); + }) + .catch(err => { + console.log(' ----- === err :', err); + }); }; dispatch = action => { @@ -34,8 +42,7 @@ class UserCard extends PureComponent { render() { const { onCancel, - user: { formType, formTitle, formVisible, formData, submitting }, - form: { getFieldDecorator }, + user: { formType, formTitle, formModalVisible, formVisible, formData, submitting }, } = this.props; const formItemLayout = { @@ -53,7 +60,7 @@ class UserCard extends PureComponent { -
- - {getFieldDecorator('user_name', { - initialValue: formData.user_name, - rules: [ - { - required: true, - message: '请输入用户名', - }, - ], - })()} - - - {getFieldDecorator('password', { - initialValue: formData.password, - rules: [ + {formVisible && ( + + + + + - )} - - - {getFieldDecorator('real_name', { - initialValue: formData.real_name, - rules: [ - { - required: true, - message: '请输入真实姓名', - }, - ], - })()} - - - {getFieldDecorator('user_roles', { - initialValue: formData.user_roles, - rules: [ - { - required: true, - message: '请选择所属角色', - }, - ], - })()} - - - {getFieldDecorator('status', { - initialValue: formData.status ? formData.status.toString() : '1', - })( + + + + + + + + 正常 停用 - )} - - - {getFieldDecorator('email', { - initialValue: formData.email, - })()} - - - {getFieldDecorator('phone', { - initialValue: formData.phone, - })()} - - +
+ + + + + + + + )}
); } diff --git a/src/pages/User/UserList.js b/src/pages/User/UserList.js index 443f304..33e0c26 100644 --- a/src/pages/User/UserList.js +++ b/src/pages/User/UserList.js @@ -156,7 +156,7 @@ class UserList extends PureComponent { onDataFormCancel = () => { this.dispatch({ - type: 'user/changeFormVisible', + type: 'user/changeModalFormVisible', payload: false, }); }; From fa5af07b40c98f623458b84cac964bbf706ea743 Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 22:41:42 +0800 Subject: [PATCH 04/15] demo from v3 to v4 --- src/pages/Demo/DemoList.js | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/pages/Demo/DemoList.js b/src/pages/Demo/DemoList.js index 4d3b38a..cd34e0f 100644 --- a/src/pages/Demo/DemoList.js +++ b/src/pages/Demo/DemoList.js @@ -1,8 +1,7 @@ import React, { PureComponent } from 'react'; import { connect } from 'dva'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Row, Col, Card, Input, Button, Table, Modal, Badge } from 'antd'; +import { Form, Row, Col, Card, Input, Button, Table, Modal, Badge } from 'antd'; import PageHeaderLayout from '@/layouts/PageHeaderLayout'; import PButton from '@/components/PermButton'; import { formatDate } from '@/utils/utils'; @@ -14,8 +13,9 @@ import styles from './DemoList.less'; loading: state.loading.models.demo, demo: state.demo, })) -@Form.create() class DemoList extends PureComponent { + formRef = React.createRef(); + state = { selectedRowKeys: [], selectedRows: [], @@ -122,22 +122,16 @@ class DemoList extends PureComponent { }); }; - onSearchFormSubmit = e => { - if (e) { - e.preventDefault(); + onSearchFormSubmit = values => { + if (!values.queryValue) { + return; } - const { form } = this.props; - form.validateFields({ force: true }, (err, values) => { - if (err) { - return; - } - this.dispatch({ - type: 'demo/fetch', - search: values, - pagination: {}, - }); - this.clearSelectRows(); + this.dispatch({ + type: 'demo/fetch', + search: values, + pagination: {}, }); + this.clearSelectRows(); }; onDataFormSubmit = data => { @@ -165,15 +159,12 @@ class DemoList extends PureComponent { } renderSearchForm() { - const { - form: { getFieldDecorator }, - } = this.props; return ( -
+ - - {getFieldDecorator('queryValue')()} + + From 59b1435dca7a7781d992868806fe2e979e2925c7 Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 22:49:20 +0800 Subject: [PATCH 05/15] menu form v3 to v4 --- src/models/menu.js | 24 +++- src/pages/Menu/MenuCard.js | 223 ++++++++++++++++++------------------- 2 files changed, 129 insertions(+), 118 deletions(-) diff --git a/src/models/menu.js b/src/models/menu.js index 3efe1c6..543c8a3 100644 --- a/src/models/menu.js +++ b/src/models/menu.js @@ -60,7 +60,7 @@ export default { }, *loadForm({ payload }, { put, select }) { yield put({ - type: 'changeFormVisible', + type: 'changeModalFormVisible', payload: true, }); @@ -105,14 +105,26 @@ export default { type: 'saveFormData', payload: { parent_id: search.parentID ? search.parentID : '' }, }); + yield [ + put({ + type: 'changeFormVisible', + payload: true, + }), + ]; } }, *fetchForm({ payload }, { call, put }) { const response = yield call(menuService.get, payload.id); - yield put({ - type: 'saveFormData', - payload: response, - }); + yield [ + put({ + type: 'saveFormData', + payload: response, + }), + put({ + type: 'changeFormVisible', + payload: true, + }), + ]; }, *submit({ payload }, { call, put, select }) { yield put({ @@ -144,7 +156,7 @@ export default { if (success) { message.success('保存成功'); yield put({ - type: 'changeFormVisible', + type: 'changeModalFormVisible', payload: false, }); diff --git a/src/pages/Menu/MenuCard.js b/src/pages/Menu/MenuCard.js index 294418d..11022e4 100644 --- a/src/pages/Menu/MenuCard.js +++ b/src/pages/Menu/MenuCard.js @@ -1,27 +1,35 @@ import React, { PureComponent } from 'react'; import { connect } from 'dva'; import { QuestionCircleOutlined } from '@ant-design/icons'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Input, Card, Radio, Modal, TreeSelect, Tooltip, InputNumber, Row, Col } from 'antd'; +import { Form, Input, Card, Radio, Modal, TreeSelect, Tooltip, InputNumber, Row, Col } from 'antd'; import MenuAction from './MenuAction'; @connect(({ menu }) => ({ menu, })) -@Form.create() class MenuCard extends PureComponent { + formRef = React.createRef(); + + onFinishFailed(err) { + const { errorFields } = err; + this.formRef.current.scrollToField(errorFields[0].name); + } + onOKClick = () => { - const { form, onSubmit } = this.props; - form.validateFieldsAndScroll((err, values) => { - if (!err) { + const { onSubmit } = this.props; + this.formRef.current + .validateFields() + .then(values => { const formData = { ...values }; formData.show_status = parseInt(formData.show_status, 10); formData.status = parseInt(formData.status, 10); formData.sequence = parseInt(formData.sequence, 10); onSubmit(formData); - } - }); + }) + .catch(err => { + console.log(' ----- === err :', err); + }); }; dispatch = action => { @@ -46,8 +54,7 @@ class MenuCard extends PureComponent { render() { const { - menu: { formVisible, formTitle, formData, submitting, treeData }, - form: { getFieldDecorator }, + menu: { formVisible, formModalVisible, formTitle, formData, submitting, treeData }, onCancel, } = this.props; @@ -64,7 +71,7 @@ class MenuCard extends PureComponent { - - - - - - {getFieldDecorator('name', { - initialValue: formData.name, - rules: [ - { - required: true, - message: '请输入菜单名称', - }, - ], - })()} - - - - - {getFieldDecorator('parent_id', { - initialValue: formData.parent_id, - })( + {formVisible && ( + + + + + + + + + + - )} - - - - - - - {getFieldDecorator('router', { - initialValue: formData.router, - })()} - - - - - - - {getFieldDecorator('icon', { - initialValue: formData.icon, - })()} - - - - - - - - - - - - - - {getFieldDecorator('show_status', { - initialValue: formData.show_status ? formData.show_status.toString() : '1', - })( + + + + + + + + + + + + + + + + + + + + + + + + + + + 显示 隐藏 - )} - - - - - {getFieldDecorator('status', { - initialValue: formData.status ? formData.status.toString() : '1', - })( + + + + 启用 禁用 - )} - - - - - - - {getFieldDecorator('sequence', { - initialValue: formData.sequence ? formData.sequence.toString() : '1000000', - rules: [ - { - required: true, - message: '请输入排序值', - }, - ], - })()} - - - - - {getFieldDecorator('memo', { - initialValue: formData.memo, - })()} - - - - - - - {getFieldDecorator('actions', { - initialValue: formData.actions, - })()} - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + )} ); } From b3ca5bee2251ffc9ad873965c0f3ebffa89a9680 Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 22:59:36 +0800 Subject: [PATCH 06/15] resource --- src/pages/Menu/MenuAction/FormDialog.js | 81 ++++++++++++++----------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/src/pages/Menu/MenuAction/FormDialog.js b/src/pages/Menu/MenuAction/FormDialog.js index ec99983..f6e5f4f 100644 --- a/src/pages/Menu/MenuAction/FormDialog.js +++ b/src/pages/Menu/MenuAction/FormDialog.js @@ -1,11 +1,16 @@ import React, { PureComponent } from 'react'; -import { Modal, Input, Card } from 'antd'; -import { Form } from '@ant-design/compatible'; +import { Form, Modal, Input, Card } from 'antd'; import '@ant-design/compatible/assets/index.css'; import MenuResource from '../MenuResource'; -@Form.create() class FormDialog extends PureComponent { + formRef = React.createRef(); + + onFinishFailed(err) { + const { errorFields } = err; + this.formRef.current.scrollToField(errorFields[0].name); + } + handleCancel = () => { const { onCancel } = this.props; if (onCancel) { @@ -14,17 +19,21 @@ class FormDialog extends PureComponent { }; handleOKClick = () => { - const { form, onSubmit } = this.props; - form.validateFieldsAndScroll((err, values) => { - if (!err) { - onSubmit({ ...values }); - } - }); + const { onSubmit } = this.props; + this.formRef.current + .validateFields() + .then(values => { + const formData = { ...values }; + // onSubmit({ ...values }); + onSubmit(formData); + }) + .catch(err => { + console.log(' ----- -- ', err); + }); }; render() { - const { visible, formData, form } = this.props; - const { getFieldDecorator } = form; + const { visible, formData } = this.props; const formItemLayout = { labelCol: { @@ -49,34 +58,34 @@ class FormDialog extends PureComponent { style={{ top: 20 }} bodyStyle={{ maxHeight: 'calc( 100vh - 158px )', overflowY: 'auto' }} > -
- - {getFieldDecorator('code', { - initialValue: formData.code, - rules: [ - { - required: true, - message: '请输入动作编号', - }, - ], - })()} + + + - - {getFieldDecorator('name', { - initialValue: formData.name, - rules: [ - { - required: true, - message: '请输入动作名称', - }, - ], - })()} + + - - {getFieldDecorator('resources', { - initialValue: formData.resources, - })()} + + From 08bcce0b1d55fccf5b818c5e5b66222937d42810 Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 23:15:45 +0800 Subject: [PATCH 07/15] role form v3 to v4 --- src/models/role.js | 15 +++- src/pages/Role/RoleCard.js | 155 ++++++++++++++++++++----------------- 2 files changed, 95 insertions(+), 75 deletions(-) diff --git a/src/models/role.js b/src/models/role.js index d73ab14..ddc0e5b 100644 --- a/src/models/role.js +++ b/src/models/role.js @@ -56,7 +56,7 @@ export default { }, *loadForm({ payload }, { put }) { yield put({ - type: 'changeFormVisible', + type: 'changeModalFormVisible', payload: true, }); @@ -94,6 +94,13 @@ export default { payload: { id: payload.id }, }), ]; + } else { + yield [ + put({ + type: 'changeFormVisible', + payload: true, + }), + ]; } }, *fetchForm({ payload }, { call, put }) { @@ -121,6 +128,10 @@ export default { type: 'saveFormData', payload: response, }), + put({ + type: 'changeFormVisible', + payload: true, + }), ]; }, *submit({ payload }, { call, put, select }) { @@ -154,7 +165,7 @@ export default { if (success) { message.success('保存成功'); yield put({ - type: 'changeFormVisible', + type: 'changeModalFormVisible', payload: false, }); yield put({ diff --git a/src/pages/Role/RoleCard.js b/src/pages/Role/RoleCard.js index 1ad8d15..273bc8e 100644 --- a/src/pages/Role/RoleCard.js +++ b/src/pages/Role/RoleCard.js @@ -1,45 +1,52 @@ import React, { PureComponent } from 'react'; import { connect } from 'dva'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Input, Modal, message, Card, Row, Col, InputNumber } from 'antd'; +import { Form, Input, Modal, message, Card, Row, Col, InputNumber } from 'antd'; import RoleMenu from './RoleMenu'; @connect(state => ({ role: state.role, })) -@Form.create() class RoleCard extends PureComponent { - onOKClick = () => { - const { form, onSubmit } = this.props; + formRef = React.createRef(); + + onFinishFailed(err) { + const { errorFields } = err; + this.formRef.current.scrollToField(errorFields[0].name); + } - form.validateFieldsAndScroll((err, values) => { - if (err) { - return; - } - const formData = { ...values }; - formData.sequence = parseInt(formData.sequence, 10); - formData.status = 1; - if (!formData.role_menus || formData.role_menus.length === 0) { - message.warning('请选择菜单权限!'); - return; - } + onOKClick = () => { + const { onSubmit } = this.props; + this.formRef.current + .validateFields() + .then(values => { + const formData = { ...values }; - const roleMenus = []; - formData.role_menus.forEach(item => { - if (item.actions && item.actions.length > 0) { - item.actions.forEach(v => { - roleMenus.push({ menu_id: item.menu_id, action_id: v }); - }); - } else { - roleMenus.push({ menu_id: item.menu_id }); + formData.sequence = parseInt(formData.sequence, 10); + formData.status = 1; + if (!formData.role_menus || formData.role_menus.length === 0) { + message.warning('请选择菜单权限!'); + return; } - }); - formData.role_menus = roleMenus; - onSubmit(formData); - }); + const roleMenus = []; + formData.role_menus.forEach(item => { + if (item.actions && item.actions.length > 0) { + item.actions.forEach(v => { + roleMenus.push({ menu_id: item.menu_id, action_id: v }); + }); + } else { + roleMenus.push({ menu_id: item.menu_id }); + } + }); + formData.role_menus = roleMenus; + + onSubmit(formData); + }) + .catch(err => { + console.log(' ----- === err :', err); + }); }; dispatch = action => { @@ -49,8 +56,7 @@ class RoleCard extends PureComponent { render() { const { - role: { formTitle, formVisible, formData, submitting }, - form: { getFieldDecorator }, + role: { formTitle, formVisible, formModalVisible, formData, submitting }, onCancel, } = this.props; @@ -76,7 +82,7 @@ class RoleCard extends PureComponent { -
- - - - {getFieldDecorator('name', { - initialValue: formData.name, - rules: [ - { - required: true, - message: '请输入角色名称', - }, - ], - })()} - - - - - {getFieldDecorator('sequence', { - initialValue: formData.sequence ? formData.sequence.toString() : '1000000', - rules: [ - { - required: true, - message: '请输入排序值', - }, - ], - })()} - - - - - {getFieldDecorator('memo', { - initialValue: formData.memo, - })()} - - - - {getFieldDecorator('role_menus', { - initialValue: formData.role_menus, - })()} - - -
+ {formVisible && ( +
+ + + + + + + + + + + + + + + + + + + + + + +
+ )}
); } From 92f42f8e9ce9a5a5f6b90f5a27ed15e9c195c9f3 Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 23:21:44 +0800 Subject: [PATCH 08/15] dialog --- src/pages/Menu/MenuAction/TplDialog.js | 55 +++++++++++++++----------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/pages/Menu/MenuAction/TplDialog.js b/src/pages/Menu/MenuAction/TplDialog.js index 66fc87c..4818bbb 100644 --- a/src/pages/Menu/MenuAction/TplDialog.js +++ b/src/pages/Menu/MenuAction/TplDialog.js @@ -1,11 +1,16 @@ import React, { PureComponent } from 'react'; import { QuestionCircleOutlined } from '@ant-design/icons'; -import { Modal, Input, Row, Col, Tooltip } from 'antd'; -import { Form } from '@ant-design/compatible'; +import { Form, Modal, Input, Row, Col, Tooltip } from 'antd'; import '@ant-design/compatible/assets/index.css'; -@Form.create() class TplDialog extends PureComponent { + formRef = React.createRef(); + + onFinishFailed(err) { + const { errorFields } = err; + this.formRef.current.scrollToField(errorFields[0].name); + } + handleCancel = () => { const { onCancel } = this.props; if (onCancel) { @@ -14,17 +19,21 @@ class TplDialog extends PureComponent { }; handleOKClick = () => { - const { form, onSubmit } = this.props; - form.validateFieldsAndScroll((err, values) => { - if (!err) { - onSubmit({ ...values }); - } - }); + const { onSubmit } = this.props; + + this.formRef.current + .validateFields() + .then(values => { + const formData = { ...values }; + onSubmit(formData); + }) + .catch(err => { + console.log(' ----- === err :', err); + }); }; render() { - const { visible, form } = this.props; - const { getFieldDecorator } = form; + const { visible } = this.props; const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -48,19 +57,21 @@ class TplDialog extends PureComponent { style={{ top: 20 }} bodyStyle={{ maxHeight: 'calc( 100vh - 158px )', overflowY: 'auto' }} > -
- + + - {getFieldDecorator('path', { - initialValue: '/api/v1/', - rules: [ - { - required: true, - message: '请输入接口路径', - }, - ], - })()} + From eaa3fccc147c0e8d3f9ac3d30d02d088bb9899ee Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 23:30:26 +0800 Subject: [PATCH 09/15] update form v3 to v4 --- src/components/UpdatePasswordDialog/index.js | 104 +++++++++---------- 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/src/components/UpdatePasswordDialog/index.js b/src/components/UpdatePasswordDialog/index.js index 4d98d00..d85cb39 100644 --- a/src/components/UpdatePasswordDialog/index.js +++ b/src/components/UpdatePasswordDialog/index.js @@ -1,41 +1,42 @@ import React, { PureComponent } from 'react'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Input, Modal, message } from 'antd'; +import { Form, Input, Modal, message } from 'antd'; import { updatePwd } from '@/services/login'; import { md5Hash } from '../../utils/utils'; -@Form.create() class UpdatePasswordDialog extends PureComponent { + formRef = React.createRef(); + state = { submitting: false, }; onOKClick = () => { - const { form } = this.props; - - form.validateFieldsAndScroll((err, values) => { - if (err) { - return; - } - if (values.new_password !== values.confirm_new_password) { - message.warning('新密码与确认新密码不一致!'); - return; - } - - this.setState({ submitting: true }); - const formData = { - old_password: md5Hash(values.old_password), - new_password: md5Hash(values.new_password), - }; - updatePwd(formData).then(res => { - if (res.status === 'OK') { - message.success('密码更新成功!'); - this.handleCancel(); + this.formRef.current + .validateFields() + .then(values => { + if (values.new_password !== values.confirm_new_password) { + message.warning('新密码与确认新密码不一致!'); + return; } + + this.setState({ submitting: true }); + const formData = { + old_password: md5Hash(values.old_password), + new_password: md5Hash(values.new_password), + }; + updatePwd(formData).then(res => { + if (res.status === 'OK') { + message.success('密码更新成功!'); + this.handleCancel(); + } + this.setState({ submitting: false }); + }); + }) + .catch(err => { + console.log(' ----- === err :', err); this.setState({ submitting: false }); }); - }); }; handleCancel = () => { @@ -51,10 +52,7 @@ class UpdatePasswordDialog extends PureComponent { }; render() { - const { - visible, - form: { getFieldDecorator }, - } = this.props; + const { visible } = this.props; const { submitting } = this.state; @@ -80,36 +78,30 @@ class UpdatePasswordDialog extends PureComponent { style={{ top: 20 }} bodyStyle={{ maxHeight: 'calc( 100vh - 158px )', overflowY: 'auto' }} > - - - {getFieldDecorator('old_password', { - rules: [ - { - required: true, - message: '请输入旧密码', - }, - ], - })()} + + + - - {getFieldDecorator('new_password', { - rules: [ - { - required: true, - message: '请输入新密码', - }, - ], - })()} + + - - {getFieldDecorator('confirm_new_password', { - rules: [ - { - required: true, - message: '请输入确认新密码', - }, - ], - })()} + + From 62a0c21c2e82434d30c2340d729385148b74d055 Mon Sep 17 00:00:00 2001 From: keye Date: Sat, 12 Jun 2021 23:53:04 +0800 Subject: [PATCH 10/15] menu search form --- src/pages/Menu/MenuList.js | 46 +++++++++++++------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/pages/Menu/MenuList.js b/src/pages/Menu/MenuList.js index 1c681c2..0f0895f 100644 --- a/src/pages/Menu/MenuList.js +++ b/src/pages/Menu/MenuList.js @@ -1,8 +1,7 @@ import React, { PureComponent } from 'react'; import { connect } from 'dva'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Row, Col, Card, Input, Button, Table, Modal, Layout, Tree, Badge } from 'antd'; +import { Form, Row, Col, Card, Input, Button, Table, Modal, Layout, Tree, Badge } from 'antd'; import PageHeaderLayout from '@/layouts/PageHeaderLayout'; import PButton from '@/components/PermButton'; import { formatDate } from '@/utils/utils'; @@ -13,8 +12,9 @@ import styles from './MenuList.less'; menu, loading: loading.models.menu, })) -@Form.create() class MenuList extends PureComponent { + formRef = React.createRef(); + state = { selectedRowKeys: [], selectedRows: [], @@ -111,8 +111,7 @@ class MenuList extends PureComponent { }; onResetFormClick = () => { - const { form } = this.props; - form.resetFields(); + this.formRef.current.resetFields(); this.dispatch({ type: 'menu/fetch', search: { parent_id: this.getParentID() }, @@ -120,26 +119,16 @@ class MenuList extends PureComponent { }); }; - onSearchFormSubmit = e => { - if (e) { - e.preventDefault(); - } - - const { form } = this.props; - form.validateFields((err, values) => { - if (err) { - return; - } - this.dispatch({ - type: 'menu/fetch', - search: { - ...values, - parent_id: this.getParentID(), - }, - pagination: {}, - }); - this.clearSelectRows(); + onSearchFormSubmit = values => { + this.dispatch({ + type: 'menu/fetch', + search: { + ...values, + parent_id: this.getParentID(), + }, + pagination: {}, }); + this.clearSelectRows(); }; handleFormSubmit = data => { @@ -204,15 +193,12 @@ class MenuList extends PureComponent { }); renderSearchForm() { - const { - form: { getFieldDecorator }, - } = this.props; return ( -
+ - - {getFieldDecorator('queryValue')()} + + From 8f90acb2f92fd1c6b7f014814aaca8d80c0e24f6 Mon Sep 17 00:00:00 2001 From: keye Date: Sun, 13 Jun 2021 00:09:53 +0800 Subject: [PATCH 11/15] user form v3 to v4 --- src/models/user.js | 25 +++++++++++++----- src/pages/Role/RoleList.js | 41 ++++++++++-------------------- src/pages/User/UserList.js | 52 ++++++++++++++++---------------------- 3 files changed, 54 insertions(+), 64 deletions(-) diff --git a/src/models/user.js b/src/models/user.js index bb07cbb..76e81e9 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -54,7 +54,7 @@ export default { }, *loadForm({ payload }, { put }) { yield put({ - type: 'changeFormVisible', + type: 'changeModalFormVisible', payload: true, }); @@ -92,14 +92,27 @@ export default { payload: { id: payload.id }, }), ]; + } else { + yield [ + put({ + type: 'changeFormVisible', + payload: true, + }), + ]; } }, *fetchForm({ payload }, { call, put }) { const response = yield call(userService.get, payload.id); - yield put({ - type: 'saveFormData', - payload: response, - }); + yield [ + put({ + type: 'saveFormData', + payload: response, + }), + put({ + type: 'changeFormVisible', + payload: true, + }), + ]; }, *submit({ payload }, { call, put, select }) { yield put({ @@ -131,7 +144,7 @@ export default { if (success) { message.success('保存成功'); yield put({ - type: 'changeFormVisible', + type: 'changeModalFormVisible', payload: false, }); yield put({ diff --git a/src/pages/Role/RoleList.js b/src/pages/Role/RoleList.js index b77807d..68fc3d0 100644 --- a/src/pages/Role/RoleList.js +++ b/src/pages/Role/RoleList.js @@ -1,8 +1,7 @@ import React, { PureComponent } from 'react'; import { connect } from 'dva'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Row, Col, Card, Input, Button, Table, Modal, Badge } from 'antd'; +import { Form, Row, Col, Card, Input, Button, Table, Modal, Badge } from 'antd'; import PageHeaderLayout from '@/layouts/PageHeaderLayout'; import PButton from '@/components/PermButton'; import { formatDate } from '@/utils/utils'; @@ -14,8 +13,9 @@ import styles from './RoleList.less'; role: state.role, loading: state.loading.models.role, })) -@Form.create() class RoleList extends PureComponent { + formRef = React.createRef(); + state = { selectedRowKeys: [], selectedRows: [], @@ -110,8 +110,7 @@ class RoleList extends PureComponent { }; onResetFormClick = () => { - const { form } = this.props; - form.resetFields(); + this.formRef.current.resetFields(); this.dispatch({ type: 'role/fetch', @@ -120,23 +119,13 @@ class RoleList extends PureComponent { }); }; - handleSearchFormSubmit = e => { - if (e) { - e.preventDefault(); - } - - const { form } = this.props; - form.validateFields({ force: true }, (err, values) => { - if (err) { - return; - } - this.dispatch({ - type: 'role/fetch', - search: values, - pagination: {}, - }); - this.clearSelectRows(); + handleSearchFormSubmit = values => { + this.dispatch({ + type: 'role/fetch', + search: values, + pagination: {}, }); + this.clearSelectRows(); }; handleDataFormSubmit = data => { @@ -167,16 +156,12 @@ class RoleList extends PureComponent { } renderSearchForm() { - const { - form: { getFieldDecorator }, - } = this.props; - return ( - + - - {getFieldDecorator('queryValue')()} + + diff --git a/src/pages/User/UserList.js b/src/pages/User/UserList.js index 33e0c26..9d5789c 100644 --- a/src/pages/User/UserList.js +++ b/src/pages/User/UserList.js @@ -1,8 +1,7 @@ import React, { PureComponent } from 'react'; import { connect } from 'dva'; -import { Form } from '@ant-design/compatible'; import '@ant-design/compatible/assets/index.css'; -import { Row, Col, Card, Input, Button, Table, Modal, Badge } from 'antd'; +import { Form, Row, Col, Card, Input, Button, Table, Modal, Badge } from 'antd'; import PButton from '@/components/PermButton'; import PageHeaderLayout from '../../layouts/PageHeaderLayout'; import UserCard from './UserCard'; @@ -15,8 +14,9 @@ import styles from './UserList.less'; loading: state.loading.models.user, user: state.user, })) -@Form.create() class UserList extends PureComponent { + formRef = React.createRef(); + state = { selectedRowKeys: [], selectedRows: [], @@ -114,8 +114,7 @@ class UserList extends PureComponent { }; onResetFormClick = () => { - const { form } = this.props; - form.resetFields(); + this.formRef.current.resetFields(); this.dispatch({ type: 'user/fetch', search: {}, @@ -123,27 +122,21 @@ class UserList extends PureComponent { }); }; - onSearchFormSubmit = e => { - if (e) { - e.preventDefault(); + onSearchFormSubmit = values => { + const formData = { ...values }; + if (!formData.roleIDs && !formData.queryValue) { + return; } - const { form } = this.props; - form.validateFields({ force: true }, (err, values) => { - if (err) { - return; - } - const formData = { ...values }; - if (formData.roleIDs) { - formData.roleIDs = formData.roleIDs.map(v => v.role_id).join(','); - } - this.dispatch({ - type: 'user/fetch', - search: formData, - pagination: {}, - }); - this.clearSelectRows(); + if (formData.roleIDs) { + formData.roleIDs = formData.roleIDs.map(v => v.role_id).join(','); + } + this.dispatch({ + type: 'user/fetch', + search: formData, + pagination: {}, }); + this.clearSelectRows(); }; onDataFormSubmit = data => { @@ -171,19 +164,18 @@ class UserList extends PureComponent { } renderSearchForm() { - const { - form: { getFieldDecorator }, - } = this.props; return ( - + - - {getFieldDecorator('queryValue')()} + + - {getFieldDecorator('roleIDs')()} + + +
From 5e355bafcbd4c9631c068fcfc8aa27f37037be0c Mon Sep 17 00:00:00 2001 From: heromicro <55149369+heromicro@users.noreply.github.com> Date: Tue, 28 Feb 2023 09:22:38 +0800 Subject: [PATCH 12/15] Create uiutil.js --- src/utils/uiutil.js | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/utils/uiutil.js diff --git a/src/utils/uiutil.js b/src/utils/uiutil.js new file mode 100644 index 0000000..bf97ae9 --- /dev/null +++ b/src/utils/uiutil.js @@ -0,0 +1,46 @@ +import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons'; +import PButton from '@/components/PermButton'; + +export const showPButtons = ( + selectedRows, + onAddClick, + onItemEditClick, + onItemDelClick, + onItemEnableClick, + onItemDisableClick +) => [ + } onClick={() => onAddClick()}> + 新建 + , + selectedRows.length === 1 && ( + onItemEditClick(selectedRows[0])}> + 编辑 + + ), + selectedRows.length === 1 && ( + onItemDelClick(selectedRows[0])} + > + 删除 + + ), + selectedRows.length === 1 && !selectedRows[0].is_active && ( + onItemEnableClick(selectedRows[0])}> + 启用 + + ), + selectedRows.length === 1 && selectedRows[0].is_active === true && ( + onItemDisableClick(selectedRows[0])} + > + 禁用 + + ), +]; From a3a69feb79649639b925bb28d8e7162fcc03fc59 Mon Sep 17 00:00:00 2001 From: heromicro <55149369+heromicro@users.noreply.github.com> Date: Tue, 28 Feb 2023 09:27:37 +0800 Subject: [PATCH 13/15] Update DemoList.js --- src/pages/Demo/DemoList.js | 48 +++++++------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/src/pages/Demo/DemoList.js b/src/pages/Demo/DemoList.js index cd34e0f..c197121 100644 --- a/src/pages/Demo/DemoList.js +++ b/src/pages/Demo/DemoList.js @@ -4,6 +4,7 @@ import '@ant-design/compatible/assets/index.css'; import { Form, Row, Col, Card, Input, Button, Table, Modal, Badge } from 'antd'; import PageHeaderLayout from '@/layouts/PageHeaderLayout'; import PButton from '@/components/PermButton'; +import { showPButtons } from '@/utils/uiutil'; import { formatDate } from '@/utils/utils'; import DemoCard from './DemoCard'; @@ -237,45 +238,14 @@ class DemoList extends PureComponent {
{this.renderSearchForm()}
- this.onAddClick()}> - 新建 - - {selectedRows.length === 1 && [ - this.onItemEditClick(selectedRows[0])} - > - 编辑 - , - this.onItemDelClick(selectedRows[0])} - > - 删除 - , - selectedRows[0].status === 2 && ( - this.onItemEnableClick(selectedRows[0])} - > - 启用 - - ), - selectedRows[0].status === 1 && ( - this.onItemDisableClick(selectedRows[0])} - > - 禁用 - - ), - ]} + {showPButtons( + selectedRows, + this.onAddClick, + this.onItemEditClick, + this.onItemDelClick, + this.onItemEnableClick, + this.onItemDisableClick + )}
Date: Tue, 28 Feb 2023 10:26:19 +0800 Subject: [PATCH 14/15] show pbuttons --- src/pages/Demo/DemoList.js | 1 - src/pages/Menu/MenuList.js | 51 +++++++++-------------------------- src/pages/Role/RoleList.js | 55 +++++++++----------------------------- src/pages/User/UserList.js | 54 +++++++++---------------------------- 4 files changed, 36 insertions(+), 125 deletions(-) diff --git a/src/pages/Demo/DemoList.js b/src/pages/Demo/DemoList.js index c197121..e551d4d 100644 --- a/src/pages/Demo/DemoList.js +++ b/src/pages/Demo/DemoList.js @@ -3,7 +3,6 @@ import { connect } from 'dva'; import '@ant-design/compatible/assets/index.css'; import { Form, Row, Col, Card, Input, Button, Table, Modal, Badge } from 'antd'; import PageHeaderLayout from '@/layouts/PageHeaderLayout'; -import PButton from '@/components/PermButton'; import { showPButtons } from '@/utils/uiutil'; import { formatDate } from '@/utils/utils'; import DemoCard from './DemoCard'; diff --git a/src/pages/Menu/MenuList.js b/src/pages/Menu/MenuList.js index e43c090..df72f67 100644 --- a/src/pages/Menu/MenuList.js +++ b/src/pages/Menu/MenuList.js @@ -3,8 +3,8 @@ import { connect } from 'dva'; import '@ant-design/compatible/assets/index.css'; import { Form, Row, Col, Card, Input, Button, Table, Modal, Layout, Tree, Badge } from 'antd'; import PageHeaderLayout from '@/layouts/PageHeaderLayout'; -import PButton from '@/components/PermButton'; import { formatDate } from '@/utils/utils'; +import { showPButtons } from '@/utils/uiutil'; import MenuCard from './MenuCard'; import styles from './MenuList.less'; @@ -47,7 +47,7 @@ class MenuList extends PureComponent { }); }; - handleEditClick = () => { + onItemEditClick = () => { const { selectedRows } = this.state; if (selectedRows.length === 0) { return; @@ -62,7 +62,7 @@ class MenuList extends PureComponent { }); }; - handleAddClick = () => { + onAddClick = () => { this.dispatch({ type: 'menu/loadForm', payload: { @@ -71,7 +71,7 @@ class MenuList extends PureComponent { }); }; - handleDelClick = () => { + onItemDelClick = () => { const { selectedRows } = this.state; if (selectedRows.length === 0) { return; @@ -339,41 +339,14 @@ class MenuList extends PureComponent {
{this.renderSearchForm()}
- this.handleAddClick()}> - 新建 - - {selectedRowKeys.length === 1 && [ - this.handleEditClick()}> - 编辑 - , - this.handleDelClick()} - > - 删除 - , - selectedRows[0].status === 2 && ( - this.onItemEnableClick(selectedRows[0])} - > - 启用 - - ), - selectedRows[0].status === 1 && ( - this.onItemDisableClick(selectedRows[0])} - > - 禁用 - - ), - ]} + {showPButtons( + selectedRows, + this.onAddClick, + this.onItemEditClick, + this.onItemDelClick, + this.onItemEnableClick, + this.onItemDisableClick + )}
{ + onAddClick = () => { this.dispatch({ type: 'role/loadForm', payload: { @@ -65,7 +65,7 @@ class RoleList extends PureComponent { }); }; - handleEditClick = item => { + onItemEditClick = item => { this.dispatch({ type: 'role/loadForm', payload: { @@ -75,7 +75,7 @@ class RoleList extends PureComponent { }); }; - handleDelClick = item => { + onItemDelClick = item => { Modal.confirm({ title: `确定删除【角色数据:${item.name}】?`, okText: '确认', @@ -234,45 +234,14 @@ class RoleList extends PureComponent {
{this.renderSearchForm()}
- this.handleAddClick()}> - 新建 - - {selectedRows.length === 1 && [ - this.handleEditClick(selectedRows[0])} - > - 编辑 - , - this.handleDelClick(selectedRows[0])} - > - 删除 - , - selectedRows[0].status === 2 && ( - this.onItemEnableClick(selectedRows[0])} - > - 启用 - - ), - selectedRows[0].status === 1 && ( - this.onItemDisableClick(selectedRows[0])} - > - 禁用 - - ), - ]} + {showPButtons( + selectedRows, + this.onAddClick, + this.onItemEditClick, + this.onItemDelClick, + this.onItemEnableClick, + this.onItemDisableClick + )}
{this.renderSearchForm()}
- this.onAddClick()}> - 新建 - - {selectedRows.length === 1 && [ - this.onItemEditClick(selectedRows[0])} - > - 编辑 - , - this.onItemDelClick(selectedRows[0])} - > - 删除 - , - selectedRows[0].status === 2 && ( - this.onItemEnableClick(selectedRows[0])} - > - 启用 - - ), - selectedRows[0].status === 1 && ( - this.onItemDisableClick(selectedRows[0])} - > - 禁用 - - ), - ]} + {showPButtons( + selectedRows, + this.onAddClick, + this.onItemEditClick, + this.onItemDelClick, + this.onItemEnableClick, + this.onItemDisableClick + )}
Date: Tue, 28 Feb 2023 10:36:08 +0800 Subject: [PATCH 15/15] ns --- src/utils/uiutil.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/uiutil.js b/src/utils/uiutil.js index bf97ae9..9d5bf70 100644 --- a/src/utils/uiutil.js +++ b/src/utils/uiutil.js @@ -1,6 +1,7 @@ import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons'; import PButton from '@/components/PermButton'; +// export const showPButtons = ( selectedRows, onAddClick,