From b1e10dc50780e939e12fe78fe8b418fb32348d94 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Fri, 15 Mar 2019 13:39:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8=E7=9A=84?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=AD=A6=E4=B9=A0~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-web/config/router.config.js | 5 + .../mock/geographic/dictionary-list.json | 22 ++ admin-web/src/locales/zh-CN/menu.js | 3 +- admin-web/src/models/admin/dictionaryList.js | 65 +++++ admin-web/src/pages/Admin/DictionaryList.js | 247 ++++++++++++++++++ admin-web/src/pages/Admin/DictionaryList.less | 15 ++ admin-web/src/services/admin.js | 8 + 7 files changed, 364 insertions(+), 1 deletion(-) create mode 100644 admin-web/mock/geographic/dictionary-list.json create mode 100644 admin-web/src/models/admin/dictionaryList.js create mode 100644 admin-web/src/pages/Admin/DictionaryList.js create mode 100644 admin-web/src/pages/Admin/DictionaryList.less diff --git a/admin-web/config/router.config.js b/admin-web/config/router.config.js index fc9ef3f55..f3b95b91f 100644 --- a/admin-web/config/router.config.js +++ b/admin-web/config/router.config.js @@ -51,6 +51,11 @@ export default [ name: 'role-list', component: './Admin/RoleList', }, + { + path: '/admin/dictionary-list', + name: 'dictionary-list', + component: './Admin/DictionaryList', + }, ], }, { diff --git a/admin-web/mock/geographic/dictionary-list.json b/admin-web/mock/geographic/dictionary-list.json new file mode 100644 index 000000000..ead438f3d --- /dev/null +++ b/admin-web/mock/geographic/dictionary-list.json @@ -0,0 +1,22 @@ +{ + "code": 0, + "message": "", + "data": [ + { + "id": 1, + "enumValue": "gender", + "value": "1", + "displayName": "男", + "sort": 1, + "memo": "" + }, + { + "id": 2, + "enumValue": "gender", + "value": "2", + "displayName": "女", + "sort": 2, + "memo": "" + } + ] +} \ No newline at end of file diff --git a/admin-web/src/locales/zh-CN/menu.js b/admin-web/src/locales/zh-CN/menu.js index 1b846e53e..be480f4df 100644 --- a/admin-web/src/locales/zh-CN/menu.js +++ b/admin-web/src/locales/zh-CN/menu.js @@ -1,9 +1,10 @@ export default { // admin - 'menu.admin': 'Admin管理', + 'menu.admin': '系统设置', 'menu.admin.admin-list': '管理员列表', 'menu.admin.resource-list': '资源列表', 'menu.admin.role-list': '角色列表', + 'menu.admin.dictionary-list': '数据字典', 'menu.home': '首页', 'menu.login': '登录', 'menu.register': '注册', diff --git a/admin-web/src/models/admin/dictionaryList.js b/admin-web/src/models/admin/dictionaryList.js new file mode 100644 index 000000000..6f5f94c1f --- /dev/null +++ b/admin-web/src/models/admin/dictionaryList.js @@ -0,0 +1,65 @@ +import { message } from 'antd'; +import { addResource, updateResource, deleteResource, dictionaryList } from '../../services/admin'; + +export default { + namespace: 'dictionaryList', + + state: { + list: [], + }, + + effects: { + *add({ payload }, { call, put }) { + const { callback, body } = payload; + const response = yield call(addResource, body); + if (callback) { + callback(response); + } + yield put({ + type: 'tree', + payload: {}, + }); + }, + *update({ payload }, { call, put }) { + const { callback, body } = payload; + const response = yield call(updateResource, body); + if (callback) { + callback(response); + } + yield put({ + type: 'tree', + payload: {}, + }); + }, + *delete({ payload }, { call, put }) { + const response = yield call(deleteResource, payload); + message.info('删除成功!'); + yield put({ + type: 'treeSuccess', + payload: { + list: response.data, + }, + }); + }, + *tree({ payload }, { call, put }) { + const { queryParams } = payload; + const response = yield call(dictionaryList, queryParams); + message.info('查询成功!'); + yield put({ + type: 'treeSuccess', + payload: { + list: response.data, + }, + }); + }, + }, + + reducers: { + treeSuccess(state, { payload }) { + return { + ...state, + ...payload, + }; + }, + }, +}; diff --git a/admin-web/src/pages/Admin/DictionaryList.js b/admin-web/src/pages/Admin/DictionaryList.js new file mode 100644 index 000000000..a47b525be --- /dev/null +++ b/admin-web/src/pages/Admin/DictionaryList.js @@ -0,0 +1,247 @@ +/* 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 './DictionaryList.less'; + +const FormItem = Form.Item; +const { Option } = Select; +const types = ['未知', '菜单', '链接']; + +// 添加 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' ? '添加一个数据字典' : '更新一个数据字典'; + const okText = modalType === 'add' ? '添加' : '更新'; + return ( + handleModalVisible()} + > + + {form.getFieldDecorator('displayName', { + rules: [{ required: true, message: '请输入菜单展示名字!', min: 2 }], + initialValue: initValues.displayName, + })()} + + + {form.getFieldDecorator('handler', { + initialValue: initValues.handler, + })()} + + + {form.getFieldDecorator('name', { + rules: [{ required: true, message: '请输入资源名字!' }], + initialValue: initValues.name, + })()} + + + {form.getFieldDecorator('pid', { + rules: [{ required: true, message: '请输入父级编号!' }], + initialValue: initValues.pid, + })()} + 根节点为 0 + + + {form.getFieldDecorator('sort', { + rules: [{ required: true, message: '请输入菜单排序!' }], + initialValue: initValues.sort, + })()} + + + {form.getFieldDecorator('type', { + rules: [{ required: true, message: '请选择资源类型!' }], + initialValue: 1, + })( + + )} + + + ); +}); + +@connect(({ dictionaryList, loading }) => ({ + dictionaryList, + list: dictionaryList.list, + loading: loading.models.dictionaryList, +})) + +@Form.create() +class DictionaryList extends PureComponent { + state = { + modalVisible: false, + modalType: 'add', //add update + initValues: {}, + }; + + componentDidMount() { + const { dispatch } = this.props; + dispatch({ + type: 'dictionaryList/tree', + payload: {}, + }); + } + + handleModalVisible = (flag, modalType, initValues) => { + this.setState({ + modalVisible: !!flag, + initValues: initValues || {}, + modalType: modalType || 'add', + }); + }; + + handleAdd = ({ fields, modalType, initValues }) => { + const { dispatch } = this.props; + if (modalType === 'add') { + dispatch({ + type: 'dictionaryList/add', + payload: { + body: { + ...fields, + }, + callback: () => { + message.success('添加成功'); + this.handleModalVisible(); + }, + }, + }); + } else { + dispatch({ + type: 'dictionaryList/update', + payload: { + body: { + ...initValues, + ...fields, + }, + callback: () => { + message.success('更新成功'); + this.handleModalVisible(); + }, + }, + }); + } + }; + + handleDelete(row) { + const { dispatch } = this.props; + Modal.confirm({ + title: `确认删除?`, + content: `${row.displayName}`, + onOk() { + dispatch({ + type: 'dictionaryList/delete', + payload: { + id: row.id, + }, + }); + }, + onCancel() {}, + }); + } + + render() { + const { list } = this.props; + const { modalVisible, modalType, initValues } = this.state; + const parentMethods = { + handleAdd: this.handleAdd, + handleModalVisible: this.handleModalVisible, + modalType, + initValues, + }; + + const columns = [ + { + title: '枚举值', + dataIndex: 'enumValue' + }, + { + title: '编号', + dataIndex: 'id', + }, + { + title: '小类数值', + dataIndex: 'value' + }, + { + title: '展示名', + dataIndex: 'displayName' + }, + { + title: '排序值', + dataIndex: 'sort' + }, + { + title: '备注', + dataIndex: 'memo' + }, + { + title: '创建时间', + dataIndex: 'createTime', + sorter: true, + render: val => {moment(val).format('YYYY-MM-DD')}, + }, + { + title: '操作', + render: (text, record) => ( + + this.handleModalVisible(true, 'update', record)}>更新 + + this.handleDelete(record)}> + 删除 + + + ), + }, + ]; + + return ( + + +
+
+ +
+
+ + + + + ); + } +} + +export default DictionaryList; diff --git a/admin-web/src/pages/Admin/DictionaryList.less b/admin-web/src/pages/Admin/DictionaryList.less new file mode 100644 index 000000000..ebb45c292 --- /dev/null +++ b/admin-web/src/pages/Admin/DictionaryList.less @@ -0,0 +1,15 @@ +@import '~antd/lib/style/themes/default.less'; +@import '~@/utils/utils.less'; + +.tableList { + .tableListOperator { + margin-bottom: 16px; + button { + margin-right: 8px; + } + } +} + +.tableDelete { + color: red; +} diff --git a/admin-web/src/services/admin.js b/admin-web/src/services/admin.js index 35efff580..79fa7d644 100644 --- a/admin-web/src/services/admin.js +++ b/admin-web/src/services/admin.js @@ -122,3 +122,11 @@ export async function roleAssignResource(params) { }, }); } + +// dictionary + +export async function dictionaryList(params) { + return request(`/admin-api/admins/data_dict/list?${stringify(params)}`, { + method: 'GET', + }); +} \ No newline at end of file