diff --git a/spug_web/src/components/LinkButton.js b/spug_web/src/components/LinkButton.js
index 4eb153e..33a2133 100644
--- a/spug_web/src/components/LinkButton.js
+++ b/spug_web/src/components/LinkButton.js
@@ -1,7 +1,14 @@
import React from 'react';
import { Button } from 'antd';
+import { hasPermission } from 'libs';
export default function LinkButton(props) {
- return
+ let disabled = props.disabled;
+ if (props.auth && !hasPermission(props.auth)) {
+ disabled = true;
+ }
+ return
}
\ No newline at end of file
diff --git a/spug_web/src/menus.js b/spug_web/src/menus.js
index 5ef539e..ea06eb0 100644
--- a/spug_web/src/menus.js
+++ b/spug_web/src/menus.js
@@ -32,6 +32,7 @@ export default [
{
icon: 'setting', title: '系统管理', child: [
{title: '账户管理', path: '/system/account'},
+ {title: '角色管理', path: '/system/role'},
{title: '系统设置', path: '/system/setting'},
]
},
diff --git a/spug_web/src/pages/config/setting/TableView.js b/spug_web/src/pages/config/setting/TableView.js
index d8a805c..58dcba9 100644
--- a/spug_web/src/pages/config/setting/TableView.js
+++ b/spug_web/src/pages/config/setting/TableView.js
@@ -1,6 +1,6 @@
import React from 'react';
import { observer } from 'mobx-react';
-import { Table, Divider, Modal, Tooltip, Tag, Icon, message } from 'antd';
+import { Table, Divider, Modal, Tooltip, Icon, message } from 'antd';
import { LinkButton } from 'components';
import ComForm from './Form';
import http from 'libs/http';
diff --git a/spug_web/src/pages/system/role/Form.js b/spug_web/src/pages/system/role/Form.js
new file mode 100644
index 0000000..14b697c
--- /dev/null
+++ b/spug_web/src/pages/system/role/Form.js
@@ -0,0 +1,59 @@
+import React from 'react';
+import { observer } from 'mobx-react';
+import { Modal, Form, Input, message } from 'antd';
+import http from 'libs/http';
+import store from './store';
+
+@observer
+class ComForm extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ loading: false,
+ type: null,
+ body: store.record['body'],
+ }
+ }
+
+ handleSubmit = () => {
+ this.setState({loading: true});
+ const formData = this.props.form.getFieldsValue();
+ formData['id'] = store.record.id;
+ http.post('/api/account/role/', formData)
+ .then(res => {
+ message.success('操作成功');
+ store.formVisible = false;
+ store.fetchRecords()
+ }, () => this.setState({loading: false}))
+ };
+
+ render() {
+ const info = store.record;
+ const {getFieldDecorator} = this.props.form;
+ return (
+ store.formVisible = false}
+ confirmLoading={this.state.loading}
+ onOk={this.handleSubmit}>
+
+ {getFieldDecorator('name', {initialValue: info['name']})(
+
+ )}
+
+
+ {getFieldDecorator('desc', {initialValue: info['desc']})(
+
+ )}
+
+
+
+ )
+ }
+}
+
+export default Form.create()(ComForm)
\ No newline at end of file
diff --git a/spug_web/src/pages/system/role/Table.js b/spug_web/src/pages/system/role/Table.js
new file mode 100644
index 0000000..c8bc611
--- /dev/null
+++ b/spug_web/src/pages/system/role/Table.js
@@ -0,0 +1,69 @@
+import React from 'react';
+import { observer } from 'mobx-react';
+import { Table, Divider, Modal, message } from 'antd';
+import ComForm from './Form';
+import http from 'libs/http';
+import store from './store';
+import { LinkButton } from "components";
+
+@observer
+class ComTable extends React.Component {
+ componentDidMount() {
+ store.fetchRecords()
+ }
+
+ columns = [{
+ title: '序号',
+ key: 'series',
+ render: (_, __, index) => index + 1,
+ width: 80,
+ }, {
+ title: '角色名称',
+ dataIndex: 'name',
+ }, {
+ title: '权限个数',
+ dataIndex: 'type',
+ }, {
+ title: '描述信息',
+ dataIndex: 'desc',
+ ellipsis: true
+ }, {
+ title: '操作',
+ render: info => (
+
+ store.showForm(info)}>编辑
+
+ this.handleDelete(info)}>删除
+
+ )
+ }];
+
+ handleDelete = (text) => {
+ Modal.confirm({
+ title: '删除确认',
+ content: `确定要删除【${text['name']}】?`,
+ onOk: () => {
+ return http.delete('/api/account/role/', {params: {id: text.id}})
+ .then(() => {
+ message.success('删除成功');
+ store.fetchRecords()
+ })
+ }
+ })
+ };
+
+ render() {
+ let data = store.records;
+ if (store.f_name) {
+ data = data.filter(item => item['name'].toLowerCase().includes(store.f_name.toLowerCase()))
+ }
+ return (
+
+
+ {store.formVisible && }
+
+ )
+ }
+}
+
+export default ComTable
\ No newline at end of file
diff --git a/spug_web/src/pages/system/role/index.js b/spug_web/src/pages/system/role/index.js
new file mode 100644
index 0000000..dedf0d4
--- /dev/null
+++ b/spug_web/src/pages/system/role/index.js
@@ -0,0 +1,25 @@
+import React from 'react';
+import { observer } from 'mobx-react';
+import { Card, Input, Button } from 'antd';
+import { SearchForm } from 'components';
+import ComTable from './Table';
+import store from './store';
+
+export default observer(function () {
+ return (
+
+
+
+ store.f_name = e.target.value} placeholder="请输入"/>
+
+
+
+
+
+
+
+
+
+
+ )
+})
\ No newline at end of file
diff --git a/spug_web/src/pages/system/role/store.js b/spug_web/src/pages/system/role/store.js
new file mode 100644
index 0000000..9d2d3ef
--- /dev/null
+++ b/spug_web/src/pages/system/role/store.js
@@ -0,0 +1,25 @@
+import { observable } from "mobx";
+import http from 'libs/http';
+
+class Store {
+ @observable records = [];
+ @observable record = {};
+ @observable isFetching = false;
+ @observable formVisible = false;
+
+ @observable f_name;
+
+ fetchRecords = () => {
+ this.isFetching = true;
+ http.get('/api/account/role/')
+ .then(res => this.records = res)
+ .finally(() => this.isFetching = false)
+ };
+
+ showForm = (info = {}) => {
+ this.formVisible = true;
+ this.record = info
+ }
+}
+
+export default new Store()
\ No newline at end of file
diff --git a/spug_web/src/pages/system/routes.js b/spug_web/src/pages/system/routes.js
index e2f74fd..3bd379e 100644
--- a/spug_web/src/pages/system/routes.js
+++ b/spug_web/src/pages/system/routes.js
@@ -1,8 +1,10 @@
import { makeRoute } from 'libs/router';
import Account from './account';
import Setting from './setting';
+import Role from './role';
export default [
makeRoute('/account', Account),
+ makeRoute('/role', Role),
makeRoute('/setting', Setting),
]
\ No newline at end of file