diff --git a/admin-web/mock/admin.js b/admin-web/mock/admin.js index 5fac79368..d6d031072 100644 --- a/admin-web/mock/admin.js +++ b/admin-web/mock/admin.js @@ -6,6 +6,7 @@ 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'; +import dictionaryList from './geographic/dictionary-list.json'; function getAdminMenu(req, res) { return res.json(adminMenu); @@ -43,6 +44,10 @@ function getDictionaryText(req, res) { return res.json(resultBody(values)); } +function getDictionaryList(req, res) { + return res.json(dictionaryList); +} + export default { 'GET /admin-api/admins/admin/menu_resource_tree': getAdminMenuAll, 'GET /admin-api/admins/admin/url_resource_list': getAdminUrls, @@ -51,4 +56,5 @@ export default { 'GET /admin-api/admins/admin/page': getQueryRole, 'GET /admin-api/admins/dictionary/getList': getDictionaryKeys, 'GET /admin-api/admins/dictionary/queryText': getDictionaryText, + // 'GET /admin-api/admins/data_dict/list': getDictionaryList, }; diff --git a/admin-web/mock/geographic/dictionary-list.json b/admin-web/mock/geographic/dictionary-list.json index ead438f3d..d60bc1f04 100644 --- a/admin-web/mock/geographic/dictionary-list.json +++ b/admin-web/mock/geographic/dictionary-list.json @@ -8,7 +8,7 @@ "value": "1", "displayName": "男", "sort": 1, - "memo": "" + "memo": "性别 - 男" }, { "id": 2, @@ -16,7 +16,7 @@ "value": "2", "displayName": "女", "sort": 2, - "memo": "" + "memo": "性别 - 女" } ] } \ No newline at end of file diff --git a/admin-web/src/models/admin/dictionaryList.js b/admin-web/src/models/admin/dictionaryList.js index 6f5f94c1f..ea004ad49 100644 --- a/admin-web/src/models/admin/dictionaryList.js +++ b/admin-web/src/models/admin/dictionaryList.js @@ -1,5 +1,5 @@ -import { message } from 'antd'; -import { addResource, updateResource, deleteResource, dictionaryList } from '../../services/admin'; +import {message} from 'antd'; +import {dictionaryAdd, dictionaryDelete, dictionaryList, dictionaryUpdate} from '../../services/admin'; export default { namespace: 'dictionaryList', @@ -11,7 +11,7 @@ export default { effects: { *add({ payload }, { call, put }) { const { callback, body } = payload; - const response = yield call(addResource, body); + const response = yield call(dictionaryAdd, body); if (callback) { callback(response); } @@ -22,7 +22,7 @@ export default { }, *update({ payload }, { call, put }) { const { callback, body } = payload; - const response = yield call(updateResource, body); + const response = yield call(dictionaryUpdate, body); if (callback) { callback(response); } @@ -32,23 +32,53 @@ export default { }); }, *delete({ payload }, { call, put }) { - const response = yield call(deleteResource, payload); + const response = yield call(dictionaryDelete, payload); message.info('删除成功!'); + // yield put({ + // type: 'treeSuccess', + // payload: { + // list: response.data, + // }, + // }); yield put({ - type: 'treeSuccess', - payload: { - list: response.data, - }, + type: 'tree', + payload: {}, }); }, *tree({ payload }, { call, put }) { const { queryParams } = payload; const response = yield call(dictionaryList, queryParams); message.info('查询成功!'); + + // 将数据格式化成 tree 格式 + // debugger; + let treeNodeMap = new Map(); // key: enumValue value: Node + for(let i = 0, len = response.data.length; i < len; i++){ + let dataDict = response.data[i]; + let treeNode = treeNodeMap.get(dataDict.enumValue); + if (!treeNode) { + treeNode = { + enumValue: dataDict.enumValue, + children: [dataDict] + }; + treeNodeMap.set(dataDict.enumValue, treeNode); + treeNode.index = dataDict.enumValue; // 因为 Table 必须要有 rowKey ,所以这里需要处理下。主要是数据字典的结构特殊 + } else { + treeNode.children.push(dataDict); + } + dataDict.index = dataDict.id; // 因为 Table 必须要有 rowKey ,所以这里需要处理下。主要是数据字典的结构特殊 + } + // 因为不支持 Map.values() 返回的结果,所以这里进行转换。 + let list = []; + treeNodeMap.forEach(function (value, key, map) { + list.push(value) + }); + // console.log(list); + yield put({ type: 'treeSuccess', payload: { - list: response.data, + list: list, }, }); }, diff --git a/admin-web/src/pages/Admin/DictionaryList.js b/admin-web/src/pages/Admin/DictionaryList.js index a47b525be..720f6fbe7 100644 --- a/admin-web/src/pages/Admin/DictionaryList.js +++ b/admin-web/src/pages/Admin/DictionaryList.js @@ -3,7 +3,7 @@ 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 { Card, Form, Input, InputNumber, Select, Button, Modal, message, Table, Divider } from 'antd'; import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import styles from './DictionaryList.less'; @@ -32,8 +32,8 @@ const CreateForm = Form.create()(props => { width: 200, }; - const title = modalType === 'add' ? '添加一个数据字典' : '更新一个数据字典'; - const okText = modalType === 'add' ? '添加' : '更新'; + const title = modalType === 'add' ? '新建数据字典' : '编辑数据字典'; + const okText = '保存'; return ( { okText={okText} onCancel={() => handleModalVisible()} > - + + {form.getFieldDecorator('enumValue', { + rules: [{ required: true, message: '请输入大类枚举值!', min: 2 }], + initialValue: initValues.enumValue, + })()} + + + {form.getFieldDecorator('value', { + rules: [{ required: true, message: '请输入小类数值!' }], + initialValue: initValues.value, + })()} + + {form.getFieldDecorator('displayName', { - rules: [{ required: true, message: '请输入菜单展示名字!', min: 2 }], + rules: [{ required: true, message: '请输入展示名!' }], 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: '请输入菜单排序!' }], + rules: [{ required: true, message: '请输入排序值!' }], initialValue: initValues.sort, - })()} + })()} - - {form.getFieldDecorator('type', { - rules: [{ required: true, message: '请选择资源类型!' }], - initialValue: 1, - })( - - )} + + {form.getFieldDecorator('memo', { + rules: [{ required: true, message: '请输入备注!' }], + initialValue: initValues.memo, + })()} ); @@ -176,16 +165,17 @@ class DictionaryList extends PureComponent { modalType, initValues, }; + let that = this; const columns = [ { - title: '枚举值', + title: '大类枚举值', dataIndex: 'enumValue' }, - { - title: '编号', - dataIndex: 'id', - }, + // { + // title: '编号', + // dataIndex: 'id', + // }, { title: '小类数值', dataIndex: 'value' @@ -210,15 +200,18 @@ class DictionaryList extends PureComponent { }, { title: '操作', - render: (text, record) => ( - - this.handleModalVisible(true, 'update', record)}>更新 - - this.handleDelete(record)}> - 删除 - - - ), + render: function(text, record) { + if (!record.id) { + return ''; + } + return + that.handleModalVisible(true, 'update', record)}>编辑 + + that.handleDelete(record)}> + 删除 + + + } }, ]; @@ -232,11 +225,11 @@ class DictionaryList extends PureComponent { type="primary" onClick={() => this.handleModalVisible(true, 'add', {})} > - 新建 + 新建数据字典 - +
diff --git a/admin-web/src/services/admin.js b/admin-web/src/services/admin.js index 79fa7d644..ca2c7a4f0 100644 --- a/admin-web/src/services/admin.js +++ b/admin-web/src/services/admin.js @@ -129,4 +129,24 @@ export async function dictionaryList(params) { return request(`/admin-api/admins/data_dict/list?${stringify(params)}`, { method: 'GET', }); +} + +export async function dictionaryAdd(params) { + return request(`/admin-api/admins/data_dict/add?${stringify(params)}`, { + method: 'POST', + body: {}, + }); +} + +export async function dictionaryUpdate(params) { + return request(`/admin-api/admins/data_dict/update?${stringify(params)}`, { + method: 'POST', + body: {}, + }); +} + +export async function dictionaryDelete(params) { + return request(`/admin-api/admins/data_dict/delete?${stringify(params)}`, { + method: 'POST', + }); } \ No newline at end of file