From 69e6deed2128ee6b6933ec1e450553c72f7c102c Mon Sep 17 00:00:00 2001
From: sin <2943460818@qq.com>
Date: Wed, 6 Mar 2019 22:02:59 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20admin=20=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin-web/mock/admin.js | 10 +-
admin-web/mock/geographic/dic-value.json | 32 +++
admin-web/src/models/admin/adminList.js | 91 +++++++
admin-web/src/pages/Admin/AdminList.js | 243 +++++++++++++++++
admin-web/src/pages/Admin/AdminList.jsx | 307 ----------------------
admin-web/src/pages/Admin/AdminList.less | 194 +-------------
admin-web/src/pages/Admin/ResourceList.js | 2 +-
admin-web/src/pages/Admin/RoleList.js | 2 +-
admin-web/src/services/admin.js | 54 +++-
admin-web/src/services/api.js | 2 +-
10 files changed, 424 insertions(+), 513 deletions(-)
create mode 100644 admin-web/mock/geographic/dic-value.json
create mode 100644 admin-web/src/models/admin/adminList.js
create mode 100644 admin-web/src/pages/Admin/AdminList.js
delete mode 100644 admin-web/src/pages/Admin/AdminList.jsx
diff --git a/admin-web/mock/admin.js b/admin-web/mock/admin.js
index f5c359a7c..60c11d9c5 100644
--- a/admin-web/mock/admin.js
+++ b/admin-web/mock/admin.js
@@ -1,10 +1,10 @@
+/* eslint-disable */
import adminMenu from './geographic/admin-menu.json';
import adminMenuAll from './geographic/admin-menu-all.json';
import adminUrls from './geographic/admin-urls';
import resourceTree from './geographic/resource-tree.json';
import roleQuery from './geographic/role-query.json';
-/* eslint-disable */
function getAdminMenu(req, res) {
return res.json(adminMenu);
}
@@ -26,8 +26,8 @@ function getQueryRole(req, res) {
}
export default {
- 'GET /admin-api/admin/resource/admin_menu_tree': getAdminMenuAll,
- 'GET /admin-api/admin/resource/admin_url_list': getAdminUrls,
- 'GET /admin-api/admin/resource/tree': getResourceTree,
- 'GET /admin-api/admin/role/page': getQueryRole,
+ 'GET /admin-api/admins/resource/admin_menu_tree': getAdminMenuAll,
+ 'GET /admin-api/admins/resource/admin_url_list': getAdminUrls,
+ 'GET /admin-api/admins/resource/tree': getResourceTree,
+ 'GET /admin-api/admins/role/page': getQueryRole,
};
diff --git a/admin-web/mock/geographic/dic-value.json b/admin-web/mock/geographic/dic-value.json
new file mode 100644
index 000000000..f7b4f8abe
--- /dev/null
+++ b/admin-web/mock/geographic/dic-value.json
@@ -0,0 +1,32 @@
+{
+ "code": 0,
+ "message": "",
+ "data": [
+ {
+ "enumValue": "gender",
+ "values": [
+ {
+ "value": "1",
+ "displayName": "男"
+ },
+ {
+ "value": "2",
+ "displayName": "女"
+ }
+ ]
+ },
+ {
+ "enumValue": "gender",
+ "values": [
+ {
+ "value": "1",
+ "displayName": "男"
+ },
+ {
+ "value": "2",
+ "displayName": "女"
+ }
+ ]
+ }
+ ]
+}
diff --git a/admin-web/src/models/admin/adminList.js b/admin-web/src/models/admin/adminList.js
new file mode 100644
index 000000000..a21faa0d3
--- /dev/null
+++ b/admin-web/src/models/admin/adminList.js
@@ -0,0 +1,91 @@
+import { message } from 'antd';
+import {
+ addAdmin,
+ updateAdmin,
+ updateAdminStatus,
+ deleteAdmin,
+ queryAdmin,
+} from '../../services/admin';
+
+export default {
+ namespace: 'adminList',
+
+ state: {
+ list: [],
+ count: 0,
+ pageNo: 0,
+ pageSize: 10,
+ },
+
+ effects: {
+ *add({ payload }, { call, put }) {
+ const { callback, body, queryParams } = payload;
+ const response = yield call(addAdmin, body);
+ if (callback) {
+ callback(response);
+ }
+ yield put({
+ type: 'query',
+ payload: {
+ ...queryParams,
+ },
+ });
+ },
+ *update({ payload }, { call, put }) {
+ const { callback, body, queryParams } = payload;
+ const response = yield call(updateAdmin, body);
+ if (callback) {
+ callback(response);
+ }
+ yield put({
+ type: 'query',
+ payload: {
+ ...queryParams,
+ },
+ });
+ },
+ *updateStatus({ payload }, { call, put }) {
+ const { body, queryParams } = payload;
+ yield call(updateAdminStatus, body);
+ message.info('更新成功!');
+ yield put({
+ type: 'query',
+ payload: {
+ ...queryParams,
+ },
+ });
+ },
+ *delete({ payload }, { call, put }) {
+ const { queryParams, body } = payload;
+ yield call(deleteAdmin, body);
+ message.info('删除成功!');
+ yield put({
+ type: 'query',
+ payload: {
+ ...queryParams,
+ },
+ });
+ },
+ *query({ payload }, { call, put }) {
+ const response = yield call(queryAdmin, payload);
+ message.info('查询成功!');
+ const { count, admins } = response.data;
+ yield put({
+ type: 'querySuccess',
+ payload: {
+ list: admins,
+ count,
+ },
+ });
+ },
+ },
+
+ reducers: {
+ querySuccess(state, { payload }) {
+ return {
+ ...state,
+ ...payload,
+ };
+ },
+ },
+};
diff --git a/admin-web/src/pages/Admin/AdminList.js b/admin-web/src/pages/Admin/AdminList.js
new file mode 100644
index 000000000..ab25d77c7
--- /dev/null
+++ b/admin-web/src/pages/Admin/AdminList.js
@@ -0,0 +1,243 @@
+/* eslint-disable */
+
+import React, { PureComponent, Fragment } from 'react';
+import { connect } from 'dva';
+import moment from 'moment';
+import { Card, Form, Input, Select, Button, Modal, message, Table, Divider } from 'antd';
+import PageHeaderWrapper from '@/components/PageHeaderWrapper';
+
+import styles from './AdminList.less';
+
+const FormItem = Form.Item;
+const { Option } = Select;
+const status = ['未知', '正常', '禁用'];
+
+// 添加 form 表单
+const CreateForm = Form.create()(props => {
+ const { modalVisible, form, handleAdd, handleModalVisible, modalType, initValues } = props;
+
+ const okHandle = () => {
+ form.validateFields((err, fieldsValue) => {
+ if (err) return;
+ form.resetFields();
+ handleAdd({
+ fields: fieldsValue,
+ modalType,
+ initValues,
+ });
+ });
+ };
+
+ const selectStyle = {
+ width: 200,
+ };
+
+ const title = modalType === 'add' ? '添加一个 Resource' : '更新一个 Resource';
+ const okText = modalType === 'add' ? '添加' : '更新';
+ return (
+ handleModalVisible()}
+ >
+
+ {form.getFieldDecorator('username', {
+ rules: [{ required: true, message: '请输入名称!', min: 2 }],
+ initialValue: initValues.username,
+ })()}
+
+
+ {form.getFieldDecorator('nickname', {
+ rules: [{ required: true, message: '请输入昵称!', min: 2 }],
+ initialValue: initValues.nickname,
+ })()}
+
+
+ {form.getFieldDecorator('password', {
+ initialValue: initValues.password,
+ })()}
+
+
+ );
+});
+
+@connect(({ adminList, loading }) => ({
+ list: adminList.list,
+ data: adminList,
+ loading: loading.models.resourceList,
+}))
+@Form.create()
+class ResourceList extends PureComponent {
+ state = {
+ modalVisible: false,
+ modalType: 'add', //add update
+ initValues: {},
+ };
+
+ componentDidMount() {
+ const { dispatch } = this.props;
+ dispatch({
+ type: 'adminList/query',
+ payload: {},
+ });
+ }
+
+ handleModalVisible = (flag, modalType, initValues) => {
+ this.setState({
+ modalVisible: !!flag,
+ initValues: initValues || {},
+ modalType: modalType || 'add',
+ });
+ };
+
+ handleAdd = ({ fields, modalType, initValues }) => {
+ const { dispatch, data } = this.props;
+ const queryParams = {
+ pageNo: data.pageNo,
+ pageSize: data.pageSize,
+ };
+ if (modalType === 'add') {
+ dispatch({
+ type: 'adminList/add',
+ payload: {
+ body: {
+ ...fields,
+ },
+ queryParams,
+ callback: () => {
+ message.success('添加成功');
+ this.handleModalVisible();
+ },
+ },
+ });
+ } else {
+ dispatch({
+ type: 'adminList/update',
+ payload: {
+ body: {
+ ...initValues,
+ ...fields,
+ },
+ queryParams,
+ callback: () => {
+ message.success('更新成功');
+ this.handleModalVisible();
+ },
+ },
+ });
+ }
+ };
+
+ handleStatus(row) {
+ const { dispatch, data } = this.props;
+ const queryParams = {
+ pageNo: data.pageNo,
+ pageSize: data.pageSize,
+ };
+
+ const title = row.status === 1 ? '确认禁用' : '取消禁用';
+ const updateStatus = row.status === 1 ? 2 : 1;
+
+ Modal.confirm({
+ title: `${title}?`,
+ content: `${row.username}`,
+ onOk() {
+ dispatch({
+ type: 'adminList/updateStatus',
+ payload: {
+ body: {
+ id: row.id,
+ status: updateStatus,
+ },
+ queryParams,
+ },
+ });
+ },
+ onCancel() {},
+ });
+ }
+
+ render() {
+ const { list } = this.props;
+ const { modalVisible, modalType, initValues, defaultExpandAllRows } = this.state;
+ const parentMethods = {
+ handleAdd: this.handleAdd,
+ handleModalVisible: this.handleModalVisible,
+ modalType,
+ initValues,
+ };
+
+ const columns = [
+ {
+ title: 'id',
+ dataIndex: 'id',
+ render: text => {text},
+ },
+ {
+ title: '用户名',
+ dataIndex: 'username',
+ render: text => {text},
+ },
+ {
+ title: '昵称',
+ dataIndex: 'nickname',
+ },
+ {
+ title: '状态',
+ dataIndex: 'status',
+ render(val) {
+ return {status[val]};
+ },
+ },
+ {
+ title: '操作',
+ render: (text, record) => {
+ const statusText = record.status === 1 ? '确认禁用' : '取消禁用';
+ return (
+
+ this.handleModalVisible(true, 'update', record)}>更新
+
+ this.handleStatus(record)}>
+ {statusText}
+
+
+ this.handleDelete(record)}>
+ 删除
+
+
+ );
+ },
+ },
+ ];
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+ );
+ }
+}
+
+export default ResourceList;
diff --git a/admin-web/src/pages/Admin/AdminList.jsx b/admin-web/src/pages/Admin/AdminList.jsx
deleted file mode 100644
index e984b8361..000000000
--- a/admin-web/src/pages/Admin/AdminList.jsx
+++ /dev/null
@@ -1,307 +0,0 @@
-import React, { PureComponent } from 'react';
-import { findDOMNode } from 'react-dom';
-import moment from 'moment';
-import { connect } from 'dva';
-import {
- List,
- Card,
- Input,
- Progress,
- Button,
- Icon,
- Dropdown,
- Menu,
- Avatar,
- Modal,
- Form,
- DatePicker,
- Select,
-} from 'antd';
-
-import PageHeaderWrapper from '@/components/PageHeaderWrapper';
-import Result from '@/components/Result';
-
-import styles from './AdminList.less';
-
-const FormItem = Form.Item;
-const SelectOption = Select.Option;
-const { Search, TextArea } = Input;
-
-@connect(({ list, loading }) => ({
- list,
- loading: loading.models.list,
-}))
-@Form.create()
-class AdminList extends PureComponent {
- state = { visible: false, done: false };
-
- formLayout = {
- labelCol: { span: 7 },
- wrapperCol: { span: 13 },
- };
-
- componentDidMount() {
- const { dispatch } = this.props;
- dispatch({
- type: 'list/fetch',
- payload: {
- count: 5,
- },
- });
- }
-
- showModal = () => {
- this.setState({
- visible: true,
- current: undefined,
- });
- };
-
- showEditModal = item => {
- this.setState({
- visible: true,
- current: item,
- });
- };
-
- handleDone = () => {
- setTimeout(() => this.addBtn.blur(), 0);
- this.setState({
- done: false,
- visible: false,
- });
- };
-
- handleCancel = () => {
- setTimeout(() => this.addBtn.blur(), 0);
- this.setState({
- visible: false,
- });
- };
-
- handleSubmit = e => {
- e.preventDefault();
- const { dispatch, form } = this.props;
- const { current } = this.state;
- const id = current ? current.id : '';
-
- setTimeout(() => this.addBtn.blur(), 0);
- form.validateFields((err, fieldsValue) => {
- if (err) return;
- this.setState({
- done: true,
- });
- dispatch({
- type: 'list/submit',
- payload: { id, ...fieldsValue },
- });
- });
- };
-
- deleteItem = id => {
- const { dispatch } = this.props;
- dispatch({
- type: 'list/submit',
- payload: { id },
- });
- };
-
- render() {
- const {
- list: { list },
- loading,
- } = this.props;
- const {
- form: { getFieldDecorator },
- } = this.props;
- const { visible, done, current = {} } = this.state;
-
- const editAndDelete = (key, currentItem) => {
- if (key === 'edit') this.showEditModal(currentItem);
- else if (key === 'delete') {
- Modal.confirm({
- title: '删除任务',
- content: '确定删除该任务吗?',
- okText: '确认',
- cancelText: '取消',
- onOk: () => this.deleteItem(currentItem.id),
- });
- }
- };
-
- const modalFooter = done
- ? { footer: null, onCancel: this.handleDone }
- : { okText: '保存', onOk: this.handleSubmit, onCancel: this.handleCancel };
-
- const extraContent = (
-
-
- ({})} />
-
- );
-
- const paginationProps = {
- showSizeChanger: true,
- showQuickJumper: true,
- pageSize: 5,
- total: 50,
- };
-
- const ListContent = ({ data: { owner, createdAt, percent, status } }) => (
-
-
-
-
开始时间
-
{moment(createdAt).format('YYYY-MM-DD HH:mm')}
-
-
-
- );
-
- const MoreBtn = props => (
- editAndDelete(key, props.current)}>
- 编辑
- 删除
-
- }
- >
-
- 更多
-
-
- );
-
- const getModalContent = () => {
- if (done) {
- return (
-
- 知道了
-
- }
- className={styles.formResult}
- />
- );
- }
- return (
-
- );
- };
- return (
-
-
-
- (
- {
- e.preventDefault();
- this.showEditModal(item);
- }}
- >
- 编辑
- ,
- ,
- ]}
- >
- }
- title={{item.title}}
- description={item.subDescription}
- />
-
-
- )}
- />
-
-
-
- {getModalContent()}
-
-
- );
- }
-}
-
-export default AdminList;
diff --git a/admin-web/src/pages/Admin/AdminList.less b/admin-web/src/pages/Admin/AdminList.less
index fd226b0f4..ebb45c292 100644
--- a/admin-web/src/pages/Admin/AdminList.less
+++ b/admin-web/src/pages/Admin/AdminList.less
@@ -1,195 +1,15 @@
@import '~antd/lib/style/themes/default.less';
@import '~@/utils/utils.less';
-.standardList {
- :global {
- .ant-card-head {
- border-bottom: none;
- }
- .ant-card-head-title {
- padding: 24px 0;
- line-height: 32px;
- }
- .ant-card-extra {
- padding: 24px 0;
- }
- .ant-list-pagination {
- margin-top: 24px;
- text-align: right;
- }
- .ant-avatar-lg {
- width: 48px;
- height: 48px;
- line-height: 48px;
- }
- }
- .headerInfo {
- position: relative;
- text-align: center;
- & > span {
- display: inline-block;
- margin-bottom: 4px;
- color: @text-color-secondary;
- font-size: @font-size-base;
- line-height: 22px;
- }
- & > p {
- margin: 0;
- color: @heading-color;
- font-size: 24px;
- line-height: 32px;
- }
- & > em {
- position: absolute;
- top: 0;
- right: 0;
- width: 1px;
- height: 56px;
- background-color: @border-color-split;
- }
- }
- .listContent {
- font-size: 0;
- .listContentItem {
- display: inline-block;
- margin-left: 40px;
- color: @text-color-secondary;
- font-size: @font-size-base;
- vertical-align: middle;
- > span {
- line-height: 20px;
- }
- > p {
- margin-top: 4px;
- margin-bottom: 0;
- line-height: 22px;
- }
- }
- }
- .extraContentSearch {
- width: 272px;
- margin-left: 16px;
- }
-}
-
-@media screen and (max-width: @screen-xs) {
- .standardList {
- :global {
- .ant-list-item-content {
- display: block;
- flex: none;
- width: 100%;
- }
- .ant-list-item-action {
- margin-left: 0;
- }
- }
- .listContent {
- margin-left: 0;
- & > div {
- margin-left: 0;
- }
- }
- .listCard {
- :global {
- .ant-card-head-title {
- overflow: visible;
- }
- }
+.tableList {
+ .tableListOperator {
+ margin-bottom: 16px;
+ button {
+ margin-right: 8px;
}
}
}
-@media screen and (max-width: @screen-sm) {
- .standardList {
- .extraContentSearch {
- width: 100%;
- margin-left: 0;
- }
- .headerInfo {
- margin-bottom: 16px;
- & > em {
- display: none;
- }
- }
- }
-}
-
-@media screen and (max-width: @screen-md) {
- .standardList {
- .listContent {
- & > div {
- display: block;
- }
- & > div:last-child {
- top: 0;
- width: 100%;
- }
- }
- }
- .listCard {
- :global {
- .ant-radio-group {
- display: block;
- margin-bottom: 8px;
- }
- }
- }
-}
-
-@media screen and (max-width: @screen-lg) and (min-width: @screen-md) {
- .standardList {
- .listContent {
- & > div {
- display: block;
- }
- & > div:last-child {
- top: 0;
- width: 100%;
- }
- }
- }
-}
-
-@media screen and (max-width: @screen-xl) {
- .standardList {
- .listContent {
- & > div {
- margin-left: 24px;
- }
- & > div:last-child {
- top: 0;
- }
- }
- }
-}
-
-@media screen and (max-width: 1400px) {
- .standardList {
- .listContent {
- text-align: right;
- & > div:last-child {
- top: 0;
- }
- }
- }
-}
-
-.standardListForm {
- :global {
- .ant-form-item {
- margin-bottom: 12px;
- &:last-child {
- margin-bottom: 32px;
- padding-top: 4px;
- }
- }
- }
-}
-
-.formResult {
- width: 100%;
- [class^='title'] {
- margin-bottom: 8px;
- }
+.tableDelete {
+ color: red;
}
diff --git a/admin-web/src/pages/Admin/ResourceList.js b/admin-web/src/pages/Admin/ResourceList.js
index 433a54b4a..61b00cf1b 100644
--- a/admin-web/src/pages/Admin/ResourceList.js
+++ b/admin-web/src/pages/Admin/ResourceList.js
@@ -104,7 +104,7 @@ class ResourceList extends PureComponent {
componentDidMount() {
const { dispatch } = this.props;
dispatch({
- type: 'roleList/tree',
+ type: 'resourceList/tree',
payload: {},
});
}
diff --git a/admin-web/src/pages/Admin/RoleList.js b/admin-web/src/pages/Admin/RoleList.js
index e070e8173..d1435d01f 100644
--- a/admin-web/src/pages/Admin/RoleList.js
+++ b/admin-web/src/pages/Admin/RoleList.js
@@ -6,7 +6,7 @@ import moment from 'moment';
import { Card, Form, Input, Select, Button, Modal, message, Table, Divider } from 'antd';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
-import styles from './ResourceList.less';
+import styles from './RoleList.less';
const FormItem = Form.Item;
const { Option } = Select;
diff --git a/admin-web/src/services/admin.js b/admin-web/src/services/admin.js
index 94718e1d0..be01dffab 100644
--- a/admin-web/src/services/admin.js
+++ b/admin-web/src/services/admin.js
@@ -1,38 +1,70 @@
-import { stringify } from 'qs';
+import { stringify } from '@/utils/request.qs';
import request from '@/utils/request';
// auth
export async function getAdminMenus() {
- return request('/admin-api/admin/resource/admin_menu_tree');
+ return request('/admin-api/admins/resource/admin_menu_tree');
}
export async function getAdminUrls(params) {
- return request(`/admin-api/admin/resource/admin_url_list?${stringify(params)}`);
+ return request(`/admin-api/admins/resource/admin_url_list?${stringify(params)}`);
+}
+
+// admin
+
+export async function queryAdmin(params) {
+ return request(`/admin-api/admins/admin/page?${stringify(params)}`, {
+ method: 'GET',
+ });
+}
+
+export async function addAdmin(params) {
+ return request(`/admin-api/admins/admin/add?${stringify(params)}`, {
+ method: 'POST',
+ });
+}
+
+export async function updateAdmin(params) {
+ return request(`/admin-api/admins/admin/update?${stringify(params)}`, {
+ method: 'POST',
+ });
+}
+
+export async function updateAdminStatus(params) {
+ return request(`/admin-api/admins/admin/update_status?${stringify(params)}`, {
+ method: 'POST',
+ });
+}
+
+export async function deleteAdmin(params) {
+ return request(`/admin-api/admins/admin/delete?${stringify(params)}`, {
+ method: 'POST',
+ });
}
// resource
export async function addResource(params) {
- return request(`/admin-api/admin/resource/add?${stringify(params)}`, {
+ return request(`/admin-api/admins/resource/add?${stringify(params)}`, {
method: 'POST',
});
}
export async function updateResource(params) {
- return request(`/admin-api/admin/resource/update?${stringify(params)}`, {
+ return request(`/admin-api/admins/resource/update?${stringify(params)}`, {
method: 'POST',
});
}
export async function deleteResource(params) {
- return request(`/admin-api/admin/resource/delete?${stringify(params)}`, {
+ return request(`/admin-api/admins/resource/delete?${stringify(params)}`, {
method: 'POST',
});
}
export async function resourceTree(params) {
- return request(`/admin-api/admin/resource/tree?${stringify(params)}`, {
+ return request(`/admin-api/admins/resource/tree?${stringify(params)}`, {
method: 'GET',
});
}
@@ -40,25 +72,25 @@ export async function resourceTree(params) {
// role
export async function queryRole(params) {
- return request(`/admin-api/admin/role/page?${stringify(params)}`);
+ return request(`/admin-api/admins/role/page?${stringify(params)}`);
}
export async function deleteRole(params) {
- return request(`/admin-api/admin/role/delete?${stringify(params)}`, {
+ return request(`/admin-api/admins/role/delete?${stringify(params)}`, {
method: 'POST',
body: {},
});
}
export async function addRole(params) {
- return request(`/admin-api/admin/role/add?${stringify(params)}`, {
+ return request(`/admin-api/admins/role/add?${stringify(params)}`, {
method: 'POST',
body: {},
});
}
export async function updateRole(params) {
- return request(`/admin-api/admin/role/update?${stringify(params)}`, {
+ return request(`/admin-api/admins/role/update?${stringify(params)}`, {
method: 'POST',
body: {},
});
diff --git a/admin-web/src/services/api.js b/admin-web/src/services/api.js
index e9cde9e1b..9a822c9ad 100644
--- a/admin-web/src/services/api.js
+++ b/admin-web/src/services/api.js
@@ -1,4 +1,4 @@
-import { stringify } from 'qs';
+import { stringify } from '@/utils/request.qs';
import request from '@/utils/request';
export async function queryProjectNotice() {