kn-cli 1.0.92 → 1.0.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/template_admin/public/index.html +5 -2
- package/templates/template_admin/public/src/_antd.less +7 -1
- package/templates/template_admin/public/src/assets/images/avatars/1.png +0 -0
- package/templates/template_admin/public/src/assets/images/avatars/2.png +0 -0
- package/templates/template_admin/public/src/assets/images/avatars/3.png +0 -0
- package/templates/template_admin/public/src/components/layout/basic/index.less +3 -3
- package/templates/template_admin/public/src/components/menu/index.jsx +47 -100
- package/templates/template_admin/public/src/components/menu/topMenu/index.jsx +129 -0
- package/templates/template_admin/public/src/components/table/index.jsx +62 -0
- package/templates/template_admin/public/src/dictionary/index.js +49 -4
- package/templates/template_admin/public/src/hooks/index.jsx +4 -1
- package/templates/template_admin/public/src/hooks/useRouteMenu.jsx +232 -0
- package/templates/template_admin/public/src/mock/demo.js +177 -0
- package/templates/template_admin/public/src/mock/index.js +5 -2
- package/templates/template_admin/public/src/pages/demo/detail/index.jsx +27 -0
- package/templates/template_admin/public/src/pages/demo/edit/index.jsx +109 -0
- package/templates/template_admin/public/src/pages/demo/index.less +9 -0
- package/templates/template_admin/public/src/pages/demo/page1.jsx +161 -0
- package/templates/template_admin/public/src/pages/login/index.jsx +5 -4
- package/templates/template_admin/public/src/pages/superAdminLogin/index.jsx +9 -2
- package/templates/template_admin/public/src/provider/app.jsx +18 -8
- package/templates/template_admin/public/src/provider/menu.jsx +146 -10
- package/templates/template_admin/public/src/route.jsx +21 -18
- package/templates/template_admin/public/src/services/demo.js +54 -0
- package/templates/template_admin/public/src/services/index.js +9 -0
- package/templates/template_admin/public/src/utils/format.js +51 -0
- package/templates/template_admin/public/src/utils/rule.js +274 -0
- package/templates/template_admin/readme.md +4 -0
- package/templates/template_admin/public/src/components/topMenu/index.jsx +0 -267
- package/templates/template_admin/public/src/mock/auth.js +0 -91
- package/templates/template_admin/public/src/mock/user.js +0 -70
- package/templates/template_admin/public/src/pages/material/index.jsx +0 -84
- package/templates/template_admin/public/src/pages/order/index.jsx +0 -12
- package/templates/template_admin/public/src/pages/permission/index.jsx +0 -12
- package/templates/template_admin/public/src/pages/suggest/index.jsx +0 -12
- package/templates/template_admin/public/src/pages/user/index.jsx +0 -18
- package/templates/template_admin/public/src/pages/userData/index.jsx +0 -12
- package/templates/template_admin/public/src/pages/video/index.jsx +0 -65
- package/templates/template_admin/public/src/services/auth.js +0 -28
- package/templates/template_admin/public/src/services/user.js +0 -26
- package/templates/template_admin/public/src/services/video.js +0 -33
- /package/templates/template_admin/public/src/components/{topMenu → menu/topMenu}/index.less +0 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import React,{ useRef, useState} from 'react';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { matchPath } from 'react-router-dom';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 设置菜单属性
|
|
11
|
+
* @typedef MenuConfig
|
|
12
|
+
* @property {string} primaryId - 菜单的primaryId值
|
|
13
|
+
* @property {('msgCount'|'icon'|'name')} key - 需要设置的字段名称
|
|
14
|
+
* @property {any} value - 字段值
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 菜单项
|
|
19
|
+
* @typedef RouteMenuItem
|
|
20
|
+
* @property {string} name - 菜单展示的名称
|
|
21
|
+
* @property {string|JSX.Element} [icon] - 菜单图标
|
|
22
|
+
* @property {string} [url] - 菜单的URL地址
|
|
23
|
+
* @property {string} [routeTemplate] - 菜单的路由模版,用于匹配动态路由
|
|
24
|
+
* @property {number} [msgCount] - 菜单的未读消息数量
|
|
25
|
+
* @property {boolean} [hideMenu=false] - 是否为隐藏的菜单,隐藏的菜单不会展示独立菜单,但是会匹配路由
|
|
26
|
+
* @property {string[]} [auth] - 允许访问该菜单的权限列表
|
|
27
|
+
* @property {RouteMenuItem[]} [children] - 子菜单
|
|
28
|
+
* @property {string} [primaryId] - 菜单的唯一ID,如果存在primaryId,则菜单的key同primaryId
|
|
29
|
+
* @property {string} [key] - 会自动生成的菜单唯一ID,如果菜单配置内存在了primaryId,则会取该id
|
|
30
|
+
* @property {string} [parentKey] - 父级菜单的key,自动生成的
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
// const MenuData=[
|
|
35
|
+
// {
|
|
36
|
+
// name:'用户中心',
|
|
37
|
+
// icon:'AppstoreOutlined',
|
|
38
|
+
// url:'/user',
|
|
39
|
+
// children:[
|
|
40
|
+
// {
|
|
41
|
+
// key:'myAccount',
|
|
42
|
+
// name:'账号管理',
|
|
43
|
+
// url:'/user/accouunt',
|
|
44
|
+
// msgCount:0,
|
|
45
|
+
// },
|
|
46
|
+
// ]
|
|
47
|
+
// },
|
|
48
|
+
// {
|
|
49
|
+
// name:'消息中心',
|
|
50
|
+
// icon:'AppstoreOutlined',
|
|
51
|
+
// url:'/message',
|
|
52
|
+
// children:[
|
|
53
|
+
// {
|
|
54
|
+
// name:'我的消息',
|
|
55
|
+
// url:'/message/my',
|
|
56
|
+
// msgCount:3,
|
|
57
|
+
// children:[
|
|
58
|
+
// {
|
|
59
|
+
// label: '创建消息',
|
|
60
|
+
// url: '/message/edit/create',
|
|
61
|
+
// routeTemplate:'/message/edit/:type',
|
|
62
|
+
// msgCount:0,
|
|
63
|
+
// },
|
|
64
|
+
// {
|
|
65
|
+
// label: '编辑消息',
|
|
66
|
+
// url: '/message/edit/edit',
|
|
67
|
+
// routeTemplate:'/message/edit/:type',
|
|
68
|
+
// msgCount:0,
|
|
69
|
+
// auth:['super'],
|
|
70
|
+
// },
|
|
71
|
+
// {
|
|
72
|
+
// url:'/message/detail',
|
|
73
|
+
// hideMenu:true,//是否是隐藏
|
|
74
|
+
// routeTemplate:'/message/detail/:id',
|
|
75
|
+
// },
|
|
76
|
+
|
|
77
|
+
// ]
|
|
78
|
+
// },
|
|
79
|
+
|
|
80
|
+
// ]
|
|
81
|
+
// }
|
|
82
|
+
// ]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const useRouteMenu=()=>{
|
|
86
|
+
/**
|
|
87
|
+
* @type [RouteMenuItem[], React.Dispatch<React.SetStateAction<RouteMenuItem[]>>]
|
|
88
|
+
*/
|
|
89
|
+
const [source,setSource]= useState([]);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @type React.MutableRefObject<number>
|
|
93
|
+
*/
|
|
94
|
+
const refKey = useRef(1);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @type React.MutableRefObject<Object<string,RouteMenuItem>>
|
|
98
|
+
*/
|
|
99
|
+
const refKeyMap = useRef();
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 遍历菜单,给菜单创建key,并创建map表以便快速查找菜单数据
|
|
103
|
+
* @param {RouteMenuItem[]} data - 菜单列表数据
|
|
104
|
+
* @param {RouteMenuItem} [parent] - 父级菜单数据,如果没有则代表是顶层菜单
|
|
105
|
+
*/
|
|
106
|
+
const setSourceMap=(data,parent=null)=>{
|
|
107
|
+
if(parent==null){
|
|
108
|
+
// 重置
|
|
109
|
+
refKey.current=1;
|
|
110
|
+
refKeyMap.current={};
|
|
111
|
+
}
|
|
112
|
+
data.forEach(menu=>{
|
|
113
|
+
if(menu.primaryId){
|
|
114
|
+
menu.key = menu.primaryId
|
|
115
|
+
}else{
|
|
116
|
+
menu.key=`${refKey.current++}`;
|
|
117
|
+
}
|
|
118
|
+
refKeyMap.current[menu.key] = menu;
|
|
119
|
+
|
|
120
|
+
if(parent){
|
|
121
|
+
menu.parentKey = parent.key;
|
|
122
|
+
}
|
|
123
|
+
if(menu.children && menu.children.length>0){
|
|
124
|
+
setSourceMap(menu.children,menu);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
if(parent==null){
|
|
128
|
+
setSource([...data]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 获取当前菜单数据,用于渲染
|
|
135
|
+
* 会将没权限的菜单、隐藏菜单过滤掉
|
|
136
|
+
* @param {RouteMenuItem[]} menus - 需要被检查的菜单列表
|
|
137
|
+
* @param {string[]} userAuth - 用户当前的权限列表
|
|
138
|
+
* @returns {RouteMenuItem[]}
|
|
139
|
+
*/
|
|
140
|
+
const getMenu=(menus=source, userAuth=[])=>{
|
|
141
|
+
const list = [];
|
|
142
|
+
menus.forEach(menu=>{
|
|
143
|
+
let auth= true;
|
|
144
|
+
// 判断用户有没有权限可以访问这个菜单
|
|
145
|
+
if(menu.auth){
|
|
146
|
+
if(menu.auth.some(menuAuthName=>userAuth.includes(menuAuthName)) == false){
|
|
147
|
+
auth=false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// 隐藏的菜单
|
|
151
|
+
if(menu.hideMenu){
|
|
152
|
+
auth=false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 只有当前菜单有权限的前提下,才可以继续遍历子菜单查询子菜单是否有权限
|
|
156
|
+
if(auth){
|
|
157
|
+
const item= {...menu};
|
|
158
|
+
if(item.children&&item.children.length>0){
|
|
159
|
+
const chidList= getMenu(item.children, userAuth);
|
|
160
|
+
item.children = chidList.length>0?chidList:null;
|
|
161
|
+
}
|
|
162
|
+
list.push(item)
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
if(menus == source){
|
|
166
|
+
console.warn('[useRouteMenu]getMenu:',list)
|
|
167
|
+
}
|
|
168
|
+
return list
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 计算pathname路由路径下的菜单路径
|
|
173
|
+
* @param {string} pathname - 需要匹配的路由路径
|
|
174
|
+
* @returns {RouteMenuItem[]}
|
|
175
|
+
*/
|
|
176
|
+
const getOpenMenus=(pathname='/')=>{
|
|
177
|
+
/** @type RouteMenuItem */
|
|
178
|
+
let matchMenu;
|
|
179
|
+
for(const menuKeyName in refKeyMap.current){
|
|
180
|
+
const menu= refKeyMap.current[menuKeyName];
|
|
181
|
+
if( matchPath(menu.routeTemplate||menu.url, pathname) ){
|
|
182
|
+
matchMenu = menu;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const getParentMenus = (menu,menus=[])=>{
|
|
188
|
+
menus.push(menu);
|
|
189
|
+
if(menu.parentKey){
|
|
190
|
+
return getParentMenus( refKeyMap.current[menu.parentKey],menus );
|
|
191
|
+
}
|
|
192
|
+
return menus;
|
|
193
|
+
}
|
|
194
|
+
if(matchMenu){
|
|
195
|
+
const menus= getParentMenus(matchMenu);
|
|
196
|
+
console.warn(`[useRouteMenu]openMenus:`,menus)
|
|
197
|
+
return menus;
|
|
198
|
+
}
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 根据menu的key来查找menu数据
|
|
204
|
+
* @param {string} menuKey - 菜单的key
|
|
205
|
+
* @returns {RouteMenuItem}
|
|
206
|
+
*/
|
|
207
|
+
const findMenuData= (menuKey)=>{
|
|
208
|
+
return refKeyMap.current[menuKey]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 设置菜单的属性
|
|
213
|
+
* @param {MenuConfig[]} params
|
|
214
|
+
*/
|
|
215
|
+
const setMenuConfig=(params)=>{
|
|
216
|
+
|
|
217
|
+
params.forEach(param=>{
|
|
218
|
+
const {primaryId,key,value}= param;
|
|
219
|
+
const menu = refKeyMap.current[primaryId];
|
|
220
|
+
if(menu){
|
|
221
|
+
// @ts-ignore
|
|
222
|
+
menu[`${key}`] = value;
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
setSource([...source])
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return {setSourceMap,getOpenMenus,getMenu,source,findMenuData,setMenuConfig}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export default useRouteMenu;
|
|
232
|
+
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {GET_REQUEST,waitTime} from './utils';
|
|
2
|
+
import {RESPONSE_STRUCT} from '@/services';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import avatar1 from '@/assets/images/avatars/1.png';
|
|
8
|
+
|
|
9
|
+
const MAX_TOTAL=98;
|
|
10
|
+
let UPDATE_COUNT=0;
|
|
11
|
+
let CREATE_COUNT=0;
|
|
12
|
+
let LIST=null;
|
|
13
|
+
|
|
14
|
+
function updateListData(){
|
|
15
|
+
let list=[];
|
|
16
|
+
const selectValue=['1','2','3','4','5','6']
|
|
17
|
+
|
|
18
|
+
const createData=(id)=>{
|
|
19
|
+
return {
|
|
20
|
+
id:`${id}`,
|
|
21
|
+
updateCount:UPDATE_COUNT,
|
|
22
|
+
name: `名称`+ `${id}`.padStart(2,'0'),
|
|
23
|
+
phone: `1370000`+ `${id}`.padStart(4,'0'),
|
|
24
|
+
date: moment().add(id,'minute').unix()*1000,//format('YYYY-MM-DD HH:mm:ss'),
|
|
25
|
+
select: selectValue[id%selectValue.length],
|
|
26
|
+
longName: `这是一个很长的名称`+ `${id}`.padStart(2,'0'),
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
for(let i=0;i<MAX_TOTAL;i++){
|
|
31
|
+
list.push(createData(i))
|
|
32
|
+
}
|
|
33
|
+
for(let i=0;i<CREATE_COUNT;i++){
|
|
34
|
+
list.push(createData(300+i))
|
|
35
|
+
}
|
|
36
|
+
LIST=list;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async function CREATE(req,res){
|
|
41
|
+
CREATE_COUNT++;
|
|
42
|
+
updateListData();
|
|
43
|
+
const query = JSON.parse(req.body);
|
|
44
|
+
await waitTime();
|
|
45
|
+
return {
|
|
46
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
47
|
+
[RESPONSE_STRUCT.DATA]:query,
|
|
48
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function UPDATE(req,res){
|
|
53
|
+
UPDATE_COUNT++;
|
|
54
|
+
updateListData();
|
|
55
|
+
const query = JSON.parse(req.body);
|
|
56
|
+
await waitTime();
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
60
|
+
[RESPONSE_STRUCT.DATA]:query,
|
|
61
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function GET_LIST(req){
|
|
66
|
+
const params = GET_REQUEST(req);
|
|
67
|
+
const {current,pageSize,...querys}= params;
|
|
68
|
+
if(!LIST)updateListData();
|
|
69
|
+
const strQuerys=JSON.stringify(querys);
|
|
70
|
+
let data=[];
|
|
71
|
+
let idx=(current-1)*pageSize;
|
|
72
|
+
for(let i=0;i<pageSize;i++){
|
|
73
|
+
if(idx>=MAX_TOTAL+CREATE_COUNT)break;
|
|
74
|
+
data.push({...LIST[idx],query:strQuerys});
|
|
75
|
+
idx++;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
79
|
+
[RESPONSE_STRUCT.DATA]:data,
|
|
80
|
+
[RESPONSE_STRUCT.PAGINATION]:{
|
|
81
|
+
current:current,
|
|
82
|
+
pageSize:pageSize,
|
|
83
|
+
total:MAX_TOTAL
|
|
84
|
+
},
|
|
85
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function GET_DETAIL(req){
|
|
90
|
+
const params = GET_REQUEST(req);
|
|
91
|
+
const {id}= params;
|
|
92
|
+
if(!LIST)updateListData();
|
|
93
|
+
for(let item of LIST){
|
|
94
|
+
if(item.id == id){
|
|
95
|
+
return {
|
|
96
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
97
|
+
[RESPONSE_STRUCT.DATA]:item,
|
|
98
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
104
|
+
[RESPONSE_STRUCT.DATA]:null,
|
|
105
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
let USER_INFO={
|
|
112
|
+
authorities:['leader','admin'],
|
|
113
|
+
realName:'cx',
|
|
114
|
+
name:'cx',
|
|
115
|
+
avater:avatar1,
|
|
116
|
+
unreadMsg:5,
|
|
117
|
+
token:'token',
|
|
118
|
+
username:'fanta',
|
|
119
|
+
};
|
|
120
|
+
async function GET_USER_INFO(req){
|
|
121
|
+
await waitTime();
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
125
|
+
[RESPONSE_STRUCT.DATA]:USER_INFO,
|
|
126
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
async function Login(req,res){
|
|
132
|
+
const query = JSON.parse(req.body);
|
|
133
|
+
await waitTime();
|
|
134
|
+
return {
|
|
135
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
136
|
+
[RESPONSE_STRUCT.DATA]:USER_INFO,
|
|
137
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function KssoLogin(req,res){
|
|
142
|
+
await waitTime();
|
|
143
|
+
return {
|
|
144
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
145
|
+
[RESPONSE_STRUCT.DATA]:USER_INFO,
|
|
146
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
async function GET_ENUM_TYPE(req){
|
|
152
|
+
await waitTime();
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
[RESPONSE_STRUCT.CODE]:0,
|
|
156
|
+
[RESPONSE_STRUCT.DATA]:[
|
|
157
|
+
{label:'类型1',key:'type1',value:'value1'},
|
|
158
|
+
{label:'类型2',key:'type2',value:'value2'},
|
|
159
|
+
{label:'类型3',key:'type3',value:'value3'},
|
|
160
|
+
],
|
|
161
|
+
[RESPONSE_STRUCT.MSG]:''
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
export default {
|
|
167
|
+
'/demo/list':{get:GET_LIST},
|
|
168
|
+
'/demo/create':{post:CREATE},
|
|
169
|
+
'/demo/update':{post:UPDATE},
|
|
170
|
+
'/demo/detail':{get:GET_DETAIL},
|
|
171
|
+
'/demo/userInfo':{get:GET_USER_INFO},
|
|
172
|
+
'/demo/login':{post:Login},
|
|
173
|
+
'/demo/ksso/auth':{post:KssoLogin},
|
|
174
|
+
'/demo/enumType':{get:GET_ENUM_TYPE},
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import mock from 'mockjs-async';
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
+
import demo from './demo.js';
|
|
5
|
+
|
|
4
6
|
function regMock(list){
|
|
5
7
|
if(list){
|
|
6
8
|
let keys = Object.keys(list)
|
|
@@ -49,9 +51,10 @@ function regMock(list){
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
/* eslint-disable */
|
|
54
|
+
// @ts-ignore
|
|
52
55
|
if(MOCK){
|
|
53
56
|
console.log(`=========MOCK OPEN=======`)
|
|
54
|
-
regMock(
|
|
57
|
+
regMock(demo);
|
|
55
58
|
}else{
|
|
56
59
|
console.log(`=========MOCK CLOSE=======`)
|
|
57
60
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { useParams,useNavigate } from 'react-router-dom';
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import {Button} from 'antd';
|
|
7
|
+
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import styles from '@/pages/demo/index.less';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const Detail=()=>{
|
|
14
|
+
const {id} = useParams();
|
|
15
|
+
const navigate= useNavigate();
|
|
16
|
+
const onBack=()=>{
|
|
17
|
+
window.history.back();
|
|
18
|
+
}
|
|
19
|
+
return (
|
|
20
|
+
<section className={styles.contentWrap}>
|
|
21
|
+
<p>id:{id}</p>
|
|
22
|
+
<Button type='primary' onClick={onBack}>返回</Button>
|
|
23
|
+
</section>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default Detail;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import ReactDom from 'react-dom';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { Modal, Form, Input, Select, message, DatePicker,Spin } from 'antd';
|
|
7
|
+
import Popup from '@/components/popup';
|
|
8
|
+
import { GET_DETAIL,CREATE,UPDATE } from '@/services/demo';
|
|
9
|
+
import rule from '@/utils/rule';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const DialogEdit = (props) => {
|
|
14
|
+
const { destory, id=null } = props;
|
|
15
|
+
const [form] = Form.useForm();
|
|
16
|
+
const [record,setRecord]=useState(null)
|
|
17
|
+
|
|
18
|
+
const init=async ()=>{
|
|
19
|
+
if(id){
|
|
20
|
+
const req= await GET_DETAIL({id})
|
|
21
|
+
if(req?.code==0 && req?.data){
|
|
22
|
+
let item= req.data;
|
|
23
|
+
item.date = moment(item.date);
|
|
24
|
+
setRecord(item);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
setRecord({
|
|
29
|
+
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
const onOk = async () => {
|
|
33
|
+
try {
|
|
34
|
+
const values = await form.validateFields();
|
|
35
|
+
const params = {
|
|
36
|
+
...values,
|
|
37
|
+
};
|
|
38
|
+
let res = null;
|
|
39
|
+
if (id) {
|
|
40
|
+
res = await UPDATE({id,...params});
|
|
41
|
+
} else {
|
|
42
|
+
res = await CREATE(params);
|
|
43
|
+
}
|
|
44
|
+
if (res?.code === 0) {
|
|
45
|
+
message.success('成功');
|
|
46
|
+
destory && destory(true);
|
|
47
|
+
}
|
|
48
|
+
} catch (errorInfo) {
|
|
49
|
+
console.log('Failed:', errorInfo);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const onCancel = () => {
|
|
54
|
+
form.resetFields();
|
|
55
|
+
destory && destory(false);
|
|
56
|
+
};
|
|
57
|
+
useEffect(()=>{
|
|
58
|
+
init();
|
|
59
|
+
},[])
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Modal
|
|
63
|
+
title={id? '编辑用户' : '新增用户'}
|
|
64
|
+
width={600}
|
|
65
|
+
open={true}
|
|
66
|
+
onOk={onOk}
|
|
67
|
+
onCancel={onCancel}
|
|
68
|
+
>
|
|
69
|
+
{
|
|
70
|
+
!record?
|
|
71
|
+
<Spin/>:
|
|
72
|
+
<Form labelCol={{ span: 5 }} wrapperCol={{ span: 19 }} form={form} initialValues={record||{}}>
|
|
73
|
+
<Form.Item label="姓名" name="name">
|
|
74
|
+
<Input placeholder="请输入" />
|
|
75
|
+
</Form.Item>
|
|
76
|
+
<Form.Item label="创建时间" name="date" rules={rule.SELECT} required>
|
|
77
|
+
<DatePicker style={{width:'100%'}}/>
|
|
78
|
+
</Form.Item>
|
|
79
|
+
|
|
80
|
+
<Form.Item
|
|
81
|
+
label="手机号码"
|
|
82
|
+
name="phone"
|
|
83
|
+
>
|
|
84
|
+
<Input />
|
|
85
|
+
</Form.Item>
|
|
86
|
+
|
|
87
|
+
<Form.Item label="绑定号码" name="select" required rules={rule.SELECT}>
|
|
88
|
+
<Select>
|
|
89
|
+
<Select.Option value={1}>1</Select.Option>
|
|
90
|
+
<Select.Option value={2}>2</Select.Option>
|
|
91
|
+
</Select>
|
|
92
|
+
</Form.Item>
|
|
93
|
+
</Form>
|
|
94
|
+
}
|
|
95
|
+
</Modal>
|
|
96
|
+
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const ShowEdit = (props = {}) => {
|
|
101
|
+
return new Promise((resolve) => {
|
|
102
|
+
let popup = Popup(resolve);
|
|
103
|
+
ReactDom.render(
|
|
104
|
+
<DialogEdit destory={popup.destory} {...props} />,
|
|
105
|
+
popup.dom
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
export default ShowEdit;
|