From adcaaf50165aef4fea3bc740a698261f030caaa5 Mon Sep 17 00:00:00 2001 From: smallchill Date: Fri, 5 Nov 2021 01:26:59 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=203.2.0.RELEASE=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=81=B5=E6=B4=BB=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E7=89=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/router.config.js | 34 +- package.json | 2 +- src/actions/menu.js | 38 ++ src/actions/role.js | 7 + src/layouts/Footer.js | 2 +- src/layouts/UserLayout.js | 2 +- src/locales/en-US/global.js | 1 + src/locales/en-US/menu.js | 3 + src/locales/zh-CN/global.js | 1 + src/locales/zh-CN/menu.js | 3 + src/locales/zh-TW/global.js | 1 + src/locales/zh-TW/menu.js | 3 + src/models/menu.js | 82 ++++ src/models/role.js | 28 +- src/pages/Authority/DataScope/DataScope.js | 158 ++++++++ .../Authority/DataScope/DataScopeCrud.js | 357 ++++++++++++++++++ src/pages/{System => Authority}/Role/Role.js | 81 ++-- .../{System => Authority}/Role/RoleAdd.js | 4 +- .../{System => Authority}/Role/RoleEdit.js | 8 +- .../{System => Authority}/Role/RoleView.js | 6 +- src/pages/Dashboard/Workplace.js | 23 +- src/services/menu.js | 30 ++ src/services/role.js | 4 + 23 files changed, 822 insertions(+), 56 deletions(-) create mode 100644 src/pages/Authority/DataScope/DataScope.js create mode 100644 src/pages/Authority/DataScope/DataScopeCrud.js rename src/pages/{System => Authority}/Role/Role.js (71%) rename src/pages/{System => Authority}/Role/RoleAdd.js (97%) rename src/pages/{System => Authority}/Role/RoleEdit.js (95%) rename src/pages/{System => Authority}/Role/RoleView.js (93%) diff --git a/config/router.config.js b/config/router.config.js index bc1f472..e80908d 100644 --- a/config/router.config.js +++ b/config/router.config.js @@ -102,6 +102,29 @@ export default [ }, ], }, + { + path: '/authority', + routes: [ + { + path: '/authority/role', + routes: [ + { path: '/authority/role', redirect: '/authority/role/list' }, + { path: '/authority/role/list', component: './Authority/Role/Role' }, + { path: '/authority/role/add', component: './Authority/Role/RoleAdd' }, + { path: '/authority/role/add/:id', component: './Authority/Role/RoleAdd' }, + { path: '/authority/role/edit/:id', component: './Authority/Role/RoleEdit' }, + { path: '/authority/role/view/:id', component: './Authority/Role/RoleView' }, + ], + }, + { + path: '/authority/datascope', + routes: [ + { path: '/authority/datascope', redirect: '/authority/datascope/list' }, + { path: '/authority/datascope/list', component: './Authority/DataScope/DataScope' }, + ], + }, + ], + }, { path: '/system', routes: [ @@ -148,17 +171,6 @@ export default [ { path: '/system/post/view/:id', component: './System/Post/PostView' }, ], }, - { - path: '/system/role', - routes: [ - { path: '/system/role', redirect: '/system/role/list' }, - { path: '/system/role/list', component: './System/Role/Role' }, - { path: '/system/role/add', component: './System/Role/RoleAdd' }, - { path: '/system/role/add/:id', component: './System/Role/RoleAdd' }, - { path: '/system/role/edit/:id', component: './System/Role/RoleEdit' }, - { path: '/system/role/view/:id', component: './System/Role/RoleView' }, - ], - }, { path: '/system/menu', routes: [ diff --git a/package.json b/package.json index bbe68c5..2a6331e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sword", - "version": "3.1.0", + "version": "3.2.0", "description": "An out-of-box UI solution for enterprise applications", "private": true, "scripts": { diff --git a/src/actions/menu.js b/src/actions/menu.js index 4c0bdfb..1cf447c 100644 --- a/src/actions/menu.js +++ b/src/actions/menu.js @@ -2,6 +2,16 @@ import { getAuthority } from '../utils/authority'; export const MENU_NAMESPACE = 'menu'; +export function MENU_REFRESH_ROUTE(topMenuId, callback) { + return { + type: `${MENU_NAMESPACE}/refreshMenuData`, + payload: { + topMenuId, + }, + callback, + }; +} + export function MENU_REFRESH_DATA() { return { type: `${MENU_NAMESPACE}/fetchMenuData`, @@ -16,6 +26,13 @@ export function MENU_LIST(payload) { }; } +export function MENU_PARENT_LIST(payload) { + return { + type: `${MENU_NAMESPACE}/fetchParentList`, + payload, + }; +} + export function MENU_INIT() { return { type: `${MENU_NAMESPACE}/fetchInit`, @@ -59,3 +76,24 @@ export function MENU_SELECT_ICON(icon) { }, }; } + +export function MENU_SHOW_DRAWER(payload) { + return { + type: `${MENU_NAMESPACE}/showDrawer`, + payload, + }; +} + +export function MENU_LOAD_DATA_SCOPE_DRAWER(payload) { + return { + type: `${MENU_NAMESPACE}/loadDataScopeDrawer`, + payload, + }; +} + +export function MENU_LOAD_DATA_SCOPE_DICT() { + return { + type: `${MENU_NAMESPACE}/loadDataScopeDict`, + payload: { code: 'data_scope_type' }, + }; +} diff --git a/src/actions/role.js b/src/actions/role.js index 4f46544..ee4b971 100644 --- a/src/actions/role.js +++ b/src/actions/role.js @@ -14,6 +14,13 @@ export function ROLE_INIT() { }; } +export function ROLE_INIT_BY_ID(roleId) { + return { + type: `${ROLE_NAMESPACE}/fetchInitById`, + payload: { roleId }, + }; +} + export function ROLE_DETAIL(id) { return { type: `${ROLE_NAMESPACE}/fetchDetail`, diff --git a/src/layouts/Footer.js b/src/layouts/Footer.js index b0d49c4..aa59a38 100644 --- a/src/layouts/Footer.js +++ b/src/layouts/Footer.js @@ -8,7 +8,7 @@ const FooterView = () => ( - Copyright 2020 SpringBlade{' '} + Copyright 2021 SpringBlade{' '} - Copyright 2020 SpringBlade{' '} + Copyright 2021 SpringBlade{' '} ({ + menu, + loading: loading.models.menu, +})) +@Form.create() +class DataScope extends PureComponent { + showDrawer = (menuId, menuName, menuCode) => { + const { dispatch } = this.props; + dispatch( + MENU_SHOW_DRAWER({ + visible: true, + menuId, + menuName, + menuCode, + }) + ).then(() => { + dispatch(MENU_LOAD_DATA_SCOPE_DRAWER({ menuId })); + }); + }; + + onClose = () => { + const { dispatch } = this.props; + dispatch( + MENU_SHOW_DRAWER({ + visible: false, + }) + ); + }; + + // ============ 查询 =============== + handleSearch = params => { + const { dispatch } = this.props; + dispatch(MENU_PARENT_LIST(params)); + }; + + // ============ 查询表单 =============== + renderSearchForm = onReset => { + const { form } = this.props; + const { getFieldDecorator } = form; + + return ( + + + + {getFieldDecorator('code')()} + + + + + {getFieldDecorator('name')()} + + + +
+ + +
+ +
+ ); + }; + + // ============ 处理按钮点击回调事件 =============== + handleBtnCallBack = payload => { + const { btn, keys, rows } = payload; + + if (btn.code === 'data_scope_setting') { + this.showDrawer(keys[0], rows[0].name, rows[0].code); + } + }; + + render() { + const code = 'data_scope'; + + const { + form, + loading, + menu: { data, drawer }, + } = this.props; + + const { visible, menuName } = drawer; + + const drawerTitle = func.isEmpty(menuName) ? '' : `[${menuName}]`; + + const columns = [ + { + title: '菜单名称', + dataIndex: 'name', + }, + { + title: '菜单编号', + dataIndex: 'code', + width: 150, + }, + { + title: '菜单别名', + dataIndex: 'alias', + width: 150, + }, + { + title: '路由地址', + dataIndex: 'path', + }, + { + title: '排序', + dataIndex: 'sort', + width: 60, + align: 'right', + }, + ]; + + return ( + + + + + + + ); + } +} +export default DataScope; diff --git a/src/pages/Authority/DataScope/DataScopeCrud.js b/src/pages/Authority/DataScope/DataScopeCrud.js new file mode 100644 index 0000000..05da4e4 --- /dev/null +++ b/src/pages/Authority/DataScope/DataScopeCrud.js @@ -0,0 +1,357 @@ +import React, { Fragment, PureComponent } from 'react'; +import { Button, Card, Col, Divider, Form, Input, message, Modal, Row, Select } from 'antd'; +import { connect } from 'dva'; +import Grid from '../../../components/Sword/Grid'; +import styles from '../../../layouts/Sword.less'; +import { submitDataScope, removeDataScope, scopeDataDetail } from '../../../services/menu'; +import func from '../../../utils/Func'; +import { MENU_LOAD_DATA_SCOPE_DICT, MENU_LOAD_DATA_SCOPE_DRAWER } from '../../../actions/menu'; + +const FormItem = Form.Item; +const { TextArea } = Input; + +@connect(({ menu, loading }) => ({ + menu, + loading: loading.models.menu, +})) +@Form.create() +class DataScopeCrud extends PureComponent { + state = { + stateVisible: false, + viewMode: false, + params: {}, + detail: { + scopeType: 1, + }, + }; + + componentDidMount() { + const { + dispatch + } = this.props; + dispatch(MENU_LOAD_DATA_SCOPE_DICT()); + } + + // ============ 查询 =============== + handleSearch = params => { + const { + dispatch, + menu: { drawer }, + } = this.props; + const { menuId } = drawer; + this.setState({ params }); + const search = { scopeName: params.scopeName, resourceCode: params.resourceCode, menuId}; + dispatch(MENU_LOAD_DATA_SCOPE_DRAWER(search)); + }; + + // ============ 查询表单 =============== + renderSearchForm = onReset => { + const { form } = this.props; + const { getFieldDecorator } = form; + + return ( + + + + {getFieldDecorator('scopeName')()} + + + + + {getFieldDecorator('resourceCode')()} + + + +
+ + +
+ +
+ ); + }; + + handleSubmit = e => { + e.preventDefault(); + const { + form, + menu: { drawer }, + } = this.props; + const { menuId } = drawer; + const { + params, + detail: { id }, + } = this.state; + form.validateFieldsAndScroll((err, values) => { + if (!err) { + let formData = Object.assign(values, { menuId }); + if (!func.isEmpty(id)) { + formData = Object.assign(values, { id }); + } + submitDataScope(formData).then(resp => { + if (resp.success) { + message.success(resp.msg); + } else { + message.error(resp.msg || '提交失败'); + } + this.handleSearch(params); + this.handleStateCancel(); + form.resetFields(); + }); + } + }); + }; + + handleStateCancel = () => { + this.setState({ + stateVisible: false, + viewMode: false, + detail: { id: '' } + }); + }; + + handleClick = (code, record) => { + const { + menu: { drawer }, + } = this.props; + const { menuId, menuCode } = drawer; + if (code === 'data_scope_add') { + this.setState({ + stateVisible: true, + detail: { + id: '', + menuId, + resourceCode: menuCode, + }, + }); + } else if (code === 'data_scope_edit') { + const { id } = record; + scopeDataDetail({ id }).then(resp => { + if (resp.success) { + this.setState({ stateVisible: true, viewMode: false, detail: resp.data }); + } + }); + } else if (code === 'data_scope_view') { + const { id } = record; + scopeDataDetail({ id }).then(resp => { + if (resp.success) { + this.setState({ stateVisible: true, viewMode: true, detail: resp.data }); + } + }); + } else if (code === 'data_scope_delete') { + const { id } = record; + const { params } = this.state; + const refresh = this.handleSearch; + Modal.confirm({ + title: '删除确认', + content: '确定删除该条记录?', + okText: '确定', + okType: 'danger', + cancelText: '取消', + onOk() { + removeDataScope({ ids: id }).then(resp => { + if (resp.success) { + message.success(resp.msg); + refresh(params); + } else { + message.error(resp.msg || '删除失败'); + } + }); + }, + onCancel() {}, + }); + } + }; + + renderLeftButton = () => ( + + ); + + render() { + const { + form, + menu: { drawer, dict }, + loading, + } = this.props; + + const { stateVisible, viewMode, detail } = this.state; + + const { getFieldDecorator } = form; + + const { dataScope } = drawer; + const { dataScopeType } = dict; + + const formItemLayout = { + labelCol: { + span: 8, + }, + wrapperCol: { + span: 16, + }, + }; + + const formAllItemLayout = { + labelCol: { + span: 4, + }, + wrapperCol: { + span: 20, + }, + }; + + const columns = [ + { + title: '权限名称', + dataIndex: 'scopeName', + }, + { + title: '权限编号', + dataIndex: 'resourceCode', + }, + { + title: '权限字段', + dataIndex: 'scopeColumn', + }, + { + title: '规则类型', + dataIndex: 'scopeTypeName', + }, + { + title: '操作', + dataIndex: 'action', + render: (text, record) => ( + +
+ + this.handleClick('data_scope_edit', record)}> + 修改 + + + + + this.handleClick('data_scope_delete', record)}> + 删除 + + + + + this.handleClick('data_scope_view', record)}> + 查看 + + +
+ + ), + }, + ]; + + return ( +
+ + +
+ + + + + {getFieldDecorator('scopeName', { + initialValue: detail.scopeName, + })()} + + + + + {getFieldDecorator('resourceCode', { + initialValue: detail.resourceCode, + })()} + + + + + + + {getFieldDecorator('scopeColumn', { + initialValue: detail.scopeColumn, + })()} + + + + + {getFieldDecorator('scopeType', { + initialValue: detail.scopeType, + })( + + )} + + + + + + + {getFieldDecorator('scopeField', { + initialValue: detail.scopeField, + })()} + + + + + + + {getFieldDecorator('scopeClass', { + initialValue: detail.scopeClass, + })()} + + + + + + + {getFieldDecorator('scopeValue', { + initialValue: detail.scopeValue, + })(