From f47e5647722d88c460b6234b49a090f615ee3ba2 Mon Sep 17 00:00:00 2001
From: YunaiV <>
Date: Fri, 15 Mar 2019 18:48:40 +0800
Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF-=E6=95=B0=E6=8D=AE=E5=AD=97?=
=?UTF-8?q?=E5=85=B8=E7=9A=84=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin-web/mock/admin.js | 6 ++
.../mock/geographic/dictionary-list.json | 4 +-
admin-web/src/models/admin/dictionaryList.js | 50 ++++++++--
admin-web/src/pages/Admin/DictionaryList.js | 97 +++++++++----------
admin-web/src/services/admin.js | 20 ++++
5 files changed, 113 insertions(+), 64 deletions(-)
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 (