kn-cli 1.0.107 → 1.0.108
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/cli.config.js +1 -0
- package/templates/template_admin/public/src/_mixin.less +38 -0
- package/templates/template_admin/public/src/_reset.less +0 -7
- package/templates/template_admin/public/src/assets/images/permission/403.png +0 -0
- package/templates/template_admin/public/src/assets/images/permission/404.png +0 -0
- package/templates/template_admin/public/src/assets/images/permission/503.png +0 -0
- package/templates/template_admin/public/src/components/antd/index.jsx +145 -0
- package/templates/template_admin/public/src/components/antd/tooltip/detail/index.jsx +70 -0
- package/templates/template_admin/public/src/components/antd/tooltip/detail/index.less +12 -0
- package/templates/template_admin/public/src/components/antd/tooltip/index.jsx +69 -0
- package/templates/template_admin/public/src/components/antd/tooltip/index.less +28 -0
- package/templates/template_admin/public/src/components/auth/index.jsx +60 -3
- package/templates/template_admin/public/src/components/auth/navCheck.jsx +27 -0
- package/templates/template_admin/public/src/components/button/index.jsx +17 -0
- package/templates/template_admin/public/src/components/debug/index.jsx +1 -1
- package/templates/template_admin/public/src/components/error/index.jsx +39 -0
- package/templates/template_admin/public/src/components/image/index.jsx +1 -1
- package/templates/template_admin/public/src/components/image/preview.jsx +1 -1
- package/templates/template_admin/public/src/components/layout/provider/index.jsx +2 -2
- package/templates/template_admin/public/src/components/leftMenu/index.jsx +31 -6
- package/templates/template_admin/public/src/components/menuIcon/index.jsx +33 -0
- package/templates/template_admin/public/src/components/menuIcon/index.less +49 -0
- package/templates/template_admin/public/src/components/react/index.jsx +7 -0
- package/templates/template_admin/public/src/components/select/defaultServicesSelect/index.jsx +182 -0
- package/templates/template_admin/public/src/components/select/dictSelect/index.jsx +84 -0
- package/templates/template_admin/public/src/components/select/index.jsx +7 -0
- package/templates/template_admin/public/src/components/select/useSelectList.jsx +217 -0
- package/templates/template_admin/public/src/components/table/index.jsx +1 -1
- package/templates/template_admin/public/src/components/text/index.jsx +1 -1
- package/templates/template_admin/public/src/components/topMenu/index.jsx +6 -1
- package/templates/template_admin/public/src/components/topMenu/index.less +10 -1
- package/templates/template_admin/public/src/components/topMenu/topBar/index.jsx +6 -1
- package/templates/template_admin/public/src/components/topMenu/topBar/index.less +9 -0
- package/templates/template_admin/public/src/config.js +28 -0
- package/templates/template_admin/public/src/dictionary/dictionary.js +289 -0
- package/templates/template_admin/public/src/dictionary/index.js +22 -126
- package/templates/template_admin/public/src/hooks/useRouteMenu.jsx +25 -3
- package/templates/template_admin/public/src/hooks/useThrottole.jsx +68 -0
- package/templates/template_admin/public/src/index.jsx +33 -15
- package/templates/template_admin/public/src/menuConfig.jsx +152 -0
- package/templates/template_admin/public/src/pages/auth/user/create/index.jsx +1 -9
- package/templates/template_admin/public/src/pages/auth/user/dialog/index.jsx +1 -1
- package/templates/template_admin/public/src/pages/auth/user/index.jsx +3 -60
- package/templates/template_admin/public/src/pages/components/select/user.jsx +18 -0
- package/templates/template_admin/public/src/pages/demo/page1.jsx +21 -0
- package/templates/template_admin/public/src/pages/demo/page2.jsx +21 -0
- package/templates/template_admin/public/src/pages/demo/page3.jsx +21 -0
- package/templates/template_admin/public/src/pages/error/403.jsx +15 -0
- package/templates/template_admin/public/src/pages/error/404.jsx +15 -0
- package/templates/template_admin/public/src/pages/error/503.jsx +15 -0
- package/templates/template_admin/public/src/pages/error/permission.jsx +40 -0
- package/templates/template_admin/public/src/pages/error/permission.less +16 -0
- package/templates/template_admin/public/src/pages/home.jsx +15 -4
- package/templates/template_admin/public/src/pages/login/index.jsx +3 -2
- package/templates/template_admin/public/src/pages/pageTemplate.jsx +28 -0
- package/templates/template_admin/public/src/provider/app.jsx +86 -55
- package/templates/template_admin/public/src/provider/menu.jsx +75 -108
- package/templates/template_admin/public/src/route.jsx +55 -35
- package/templates/template_admin/public/src/services/index.js +28 -4
- package/templates/template_admin/public/src/services/socket/index.jsx +1 -1
- package/templates/template_admin/public/src/utils/storage.js +30 -0
- package/templates/template_admin/webpack.api.js +24 -0
- package/templates/template_admin/public/src/pages/components/select/account/index.jsx +0 -114
- package/templates/template_admin/public/src/pages/components/select/device/index.jsx +0 -83
- package/templates/template_admin/public/src/pages/components/select/groupUser/index.jsx +0 -172
- package/templates/template_admin/public/src/pages/components/select/user/index.jsx +0 -119
|
@@ -29,6 +29,30 @@ const API_PROXY= {
|
|
|
29
29
|
'^/api': '/', // rewrite path
|
|
30
30
|
},
|
|
31
31
|
},
|
|
32
|
+
'/devapi/**':{
|
|
33
|
+
target:'https://dev-zeus.kingnet.com/',
|
|
34
|
+
changeOrigin: true,
|
|
35
|
+
logLevel: 'debug',
|
|
36
|
+
pathRewrite: {
|
|
37
|
+
'^/devapi': '/', // rewrite path
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
'/preapi/**': {
|
|
41
|
+
target:'https://pre-zeus.kingnet.com/',
|
|
42
|
+
changeOrigin: true,
|
|
43
|
+
logLevel: 'debug',
|
|
44
|
+
pathRewrite: {
|
|
45
|
+
'^/preapi': '/', // rewrite path
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
'/prodapi/**': {
|
|
49
|
+
target:'https://zeus.kingnet.com/',
|
|
50
|
+
changeOrigin: true,
|
|
51
|
+
logLevel: 'debug',
|
|
52
|
+
pathRewrite: {
|
|
53
|
+
'^/prodapi': '/', // rewrite path
|
|
54
|
+
},
|
|
55
|
+
},
|
|
32
56
|
};
|
|
33
57
|
|
|
34
58
|
// @ts-ignore
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import { Select } from 'antd';
|
|
5
|
-
import {GET_LIST} from '@/services/demo';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 账号选择
|
|
10
|
-
* 数据来源:服务设置-账号管理-所有枚举
|
|
11
|
-
* @param {object} props
|
|
12
|
-
* @param {'single'|'multiple'} [props.mode='single'] - 单选/多选模式
|
|
13
|
-
* @param {(value:string|string[],items:object[])=>void} [props.onChange] - 选择发生变化时的回调
|
|
14
|
-
* @param {string|string[]} [props.value] - 选择发生变化时的回调
|
|
15
|
-
* @param {boolean} [props.withData=false] - 返回的数据是否包含原始用户数据
|
|
16
|
-
* @param {object} [props.style={}] - 样式
|
|
17
|
-
* @param {string} [props.placeholder] - 提示
|
|
18
|
-
* @param {boolean} [props.allowClear=falsse] - 一键删除按钮
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @returns {JSX.Element}
|
|
23
|
-
*/
|
|
24
|
-
const SelectAccount=(props)=>{
|
|
25
|
-
const {mode='single',value:_value,onChange,withData=false,style:_style={},placeholder='',allowClear=false} = props;
|
|
26
|
-
const [list,setList]= useState([]);
|
|
27
|
-
|
|
28
|
-
const [value,setValue]=useState(mode=='single'?'':[]);
|
|
29
|
-
|
|
30
|
-
const init = async ()=>{
|
|
31
|
-
const req = await GET_LIST();
|
|
32
|
-
if(req?.code==0){
|
|
33
|
-
let users= req.data.map(user=>{
|
|
34
|
-
const {id,name} = user;
|
|
35
|
-
|
|
36
|
-
// return <Select.Option value={`${id}`} data={user}>{`${name}(${account})`}</Select.Option>
|
|
37
|
-
return {
|
|
38
|
-
label:`${name}`,
|
|
39
|
-
value:`${id}`,
|
|
40
|
-
data:user
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
setList(users);
|
|
44
|
-
}else{setList([])}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const onUserChange=(newValue,options)=>{
|
|
49
|
-
if(onChange)onChange(newValue,options);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const onFilter=(input,option)=>{
|
|
53
|
-
const {label,value}= option;
|
|
54
|
-
if( `${label}`.toLocaleLowerCase().indexOf(input.toLocaleLowerCase()) >=0 ){
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// useEffect(()=>{
|
|
61
|
-
// if(list&&list.length>0){
|
|
62
|
-
// if(mode=='single'){
|
|
63
|
-
// let find = list.filter(user=>user.value == value);
|
|
64
|
-
// if(!find || !find[0]){
|
|
65
|
-
// if(onChange)onChange(undefined);
|
|
66
|
-
// }
|
|
67
|
-
// }else{
|
|
68
|
-
// let newValue=[];
|
|
69
|
-
// value.forEach(id=>{
|
|
70
|
-
// let find = list.filter(user=>user.value == id);
|
|
71
|
-
// if(find && find[0]){
|
|
72
|
-
// newValue.push(id);
|
|
73
|
-
// }
|
|
74
|
-
// })
|
|
75
|
-
// if(onChange)onChange(newValue);
|
|
76
|
-
|
|
77
|
-
// }
|
|
78
|
-
// }
|
|
79
|
-
// },[list])
|
|
80
|
-
|
|
81
|
-
useEffect(()=>{
|
|
82
|
-
init();
|
|
83
|
-
},[])
|
|
84
|
-
useEffect(()=>{
|
|
85
|
-
if(!_value){
|
|
86
|
-
setValue(undefined);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
let req;
|
|
90
|
-
if(mode=='multiple' && Array.isArray(_value)){
|
|
91
|
-
req= _value.map(id=>`${id}`)
|
|
92
|
-
}else{
|
|
93
|
-
req = `${_value}`
|
|
94
|
-
}
|
|
95
|
-
setValue(req)
|
|
96
|
-
},[_value]);
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<Select
|
|
100
|
-
style={{..._style}}
|
|
101
|
-
placeholder={placeholder}
|
|
102
|
-
allowClear={allowClear?true:false}
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
mode={mode}
|
|
105
|
-
showSearch
|
|
106
|
-
value={value}
|
|
107
|
-
options={list}
|
|
108
|
-
onChange={onUserChange}
|
|
109
|
-
filterOption={onFilter}
|
|
110
|
-
/>
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default SelectAccount;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import { Select } from 'antd';
|
|
5
|
-
import {DEVICE_ENUM} from '@/services/device';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 设备选择框
|
|
11
|
-
* 数据来源:手机管理-所有枚举
|
|
12
|
-
* @param {object} props
|
|
13
|
-
* @param {'single'|'multiple'} [props.mode='single'] - 单选/多选模式
|
|
14
|
-
* @param {(value:string|string[])=>void} [props.onChange] - 选择发生变化时的回调
|
|
15
|
-
* @param {string|string[]} [props.value] - 选择发生变化时的回调
|
|
16
|
-
* @param {object} [props.deviceType={}] - 调用枚举接口可用的传参
|
|
17
|
-
*
|
|
18
|
-
* @returns {JSX.Element}
|
|
19
|
-
*/
|
|
20
|
-
const SelectDevice=(props)=>{
|
|
21
|
-
const {mode='single',value:_value,deviceType={},onChange} = props;
|
|
22
|
-
const [list,setList]= useState([]);
|
|
23
|
-
|
|
24
|
-
const [value,setValue]=useState(mode=='single'?'':[]);
|
|
25
|
-
|
|
26
|
-
const init = async ()=>{
|
|
27
|
-
const req = await DEVICE_ENUM(deviceType);
|
|
28
|
-
if(req?.code==0){
|
|
29
|
-
let devices= req.data.map(device=>{
|
|
30
|
-
const {id,title} = device;
|
|
31
|
-
let strId = `${id}`.padStart(2,'0');
|
|
32
|
-
return {
|
|
33
|
-
label:`[${strId}]${title}`,
|
|
34
|
-
value:`${id}`,
|
|
35
|
-
data:device
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
setList(devices);
|
|
39
|
-
}else{setList([])}
|
|
40
|
-
}
|
|
41
|
-
const onDeviceChange=(newValue)=>{
|
|
42
|
-
if(onChange)onChange(newValue);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const onFilter=(input,option)=>{
|
|
46
|
-
const {label,value}= option;
|
|
47
|
-
if( `${label}`.indexOf(input) >=0 ||
|
|
48
|
-
`${value}`.indexOf(input) >=0
|
|
49
|
-
){
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
useEffect(()=>{
|
|
56
|
-
init();
|
|
57
|
-
},[])
|
|
58
|
-
useEffect(()=>{
|
|
59
|
-
if(!_value){
|
|
60
|
-
setValue(mode=='multiple'?[]:'');
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
let req;
|
|
64
|
-
if(mode=='multiple' && Array.isArray(_value) ){
|
|
65
|
-
req= _value.map(id=>`${id}`)
|
|
66
|
-
}else{
|
|
67
|
-
req = `${_value}`
|
|
68
|
-
}
|
|
69
|
-
setValue(req)
|
|
70
|
-
},[_value]);
|
|
71
|
-
return (
|
|
72
|
-
<Select
|
|
73
|
-
mode={mode}
|
|
74
|
-
showSearch
|
|
75
|
-
value={value}
|
|
76
|
-
options={list}
|
|
77
|
-
onChange={onDeviceChange}
|
|
78
|
-
filterOption={onFilter}
|
|
79
|
-
/>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export default SelectDevice;
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import { Select } from 'antd';
|
|
5
|
-
|
|
6
|
-
import {USERGROUP_ENUM} from '@/services/authAdmin/userGroup';
|
|
7
|
-
import {USER_ENUM} from '@/services/authAdmin/user';
|
|
8
|
-
import {formatUserName} from '@/utils/format';
|
|
9
|
-
|
|
10
|
-
const GROUP_PRE_NAME='group-';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 将组ID和用户ID,转义为 SelectGroupUser 能识别的id
|
|
14
|
-
* @param {number[]|number|string|string[]} groupId - 组ID列表
|
|
15
|
-
* @param {number[]|number|string|string[]} groupId - 用户ID列表
|
|
16
|
-
* @returns {string[]}
|
|
17
|
-
*/
|
|
18
|
-
const encodeValue=(groupId=[],userId=[])=>{
|
|
19
|
-
let req=[];
|
|
20
|
-
if(Array.isArray(groupId)){
|
|
21
|
-
req = groupId.map(id=>`${GROUP_PRE_NAME}${id}`);
|
|
22
|
-
}else{
|
|
23
|
-
if(groupId){
|
|
24
|
-
req.push(`${GROUP_PRE_NAME}${groupId}`)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if(Array.isArray(userId)){
|
|
28
|
-
let temp= userId.map(id=>`${id}`);
|
|
29
|
-
req=[...req,...temp]
|
|
30
|
-
}else{
|
|
31
|
-
if(userId){
|
|
32
|
-
req.push(`${userId}`)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return req;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/***
|
|
39
|
-
* 将 SelectGroupUser 组件的值转义回需要提交给接口的 groupId和userId
|
|
40
|
-
* @param {string[]|string} value - 当前选中的值
|
|
41
|
-
*
|
|
42
|
-
* @returns {{groupId:string[],userId:string[]}}
|
|
43
|
-
*/
|
|
44
|
-
const decodeValue=(value)=>{
|
|
45
|
-
let groupId=[];
|
|
46
|
-
let userId=[];
|
|
47
|
-
|
|
48
|
-
if(Array.isArray(value)){
|
|
49
|
-
value.forEach(v=>{
|
|
50
|
-
if(`${v}`.indexOf(GROUP_PRE_NAME)>=0){
|
|
51
|
-
groupId.push(`${v}`.split(GROUP_PRE_NAME)[1]);
|
|
52
|
-
}else{
|
|
53
|
-
userId.push(`${v}`);
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
}else{
|
|
57
|
-
if(`${value}`.indexOf(GROUP_PRE_NAME)>=0){
|
|
58
|
-
groupId.push( `${value}`.split(GROUP_PRE_NAME)[1] );
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return {groupId,userId}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const convert = {setValue:encodeValue,getValue:decodeValue};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 选择用户组和用户的下拉选择框组件
|
|
68
|
-
* @param {object} props
|
|
69
|
-
* @param {string|string[]} [props.value] - 值,值为组ID和用户ID混合的,组ID由group-前缀打头:['group-组id','用户id'],所以需要进行转义
|
|
70
|
-
* @param {(newValue:string[])=>void} [props.onChange] - 值
|
|
71
|
-
*
|
|
72
|
-
* @returns {JSX.Element}
|
|
73
|
-
*/
|
|
74
|
-
const SelectGroupUser=(props)=>{
|
|
75
|
-
const {value:_value,onChange=null}= props;
|
|
76
|
-
|
|
77
|
-
const [groupList,setGroupList] = useState([]);
|
|
78
|
-
|
|
79
|
-
const [value,setValue]=useState(_value||[]);
|
|
80
|
-
|
|
81
|
-
const init=async ()=>{
|
|
82
|
-
let req1 = USERGROUP_ENUM();
|
|
83
|
-
let req2 = USER_ENUM({status:1});
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @type {ServicesResponse}
|
|
87
|
-
*/
|
|
88
|
-
let reqUserGroup = await req1;
|
|
89
|
-
/**
|
|
90
|
-
* @type {ServicesResponse}
|
|
91
|
-
*/
|
|
92
|
-
let reqUsers = await req2;
|
|
93
|
-
let list=[];
|
|
94
|
-
if(reqUserGroup?.code==0){
|
|
95
|
-
const groupList = reqUserGroup.data.map(group=>{
|
|
96
|
-
const {id,name:label}=group;
|
|
97
|
-
let groupId = `${GROUP_PRE_NAME}${id}`;
|
|
98
|
-
const groupInfo = {
|
|
99
|
-
label,
|
|
100
|
-
value:groupId,
|
|
101
|
-
}
|
|
102
|
-
return groupInfo;
|
|
103
|
-
});
|
|
104
|
-
list.push({
|
|
105
|
-
label:'用户组',
|
|
106
|
-
title:'group',
|
|
107
|
-
options:groupList
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if(reqUsers?.code==0){
|
|
111
|
-
const userList = reqUsers.data.map(user=>{
|
|
112
|
-
const {id:value,name:label}=user;
|
|
113
|
-
let userName = formatUserName(user);
|
|
114
|
-
const userInfo = {
|
|
115
|
-
label:userName,
|
|
116
|
-
value:`${value}`,
|
|
117
|
-
data:user
|
|
118
|
-
}
|
|
119
|
-
return userInfo;
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
list.push({
|
|
123
|
-
label:'用户',
|
|
124
|
-
title:'users',
|
|
125
|
-
options:userList
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
setGroupList(list);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const onGroupUserChange = (newValue) => {
|
|
132
|
-
console.log('onChange ', newValue);
|
|
133
|
-
if(onChange)onChange(newValue);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const onFilter=(input,option)=>{
|
|
137
|
-
if(option.options)return false;
|
|
138
|
-
const {label,value,data}= option;
|
|
139
|
-
if( `${label}`.indexOf(input) >=0 ||
|
|
140
|
-
`${value}`.indexOf(input) >=0
|
|
141
|
-
){
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
if(data && data.account.indexOf(input) >=0 ){
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
useEffect(()=>{
|
|
151
|
-
if(!_value){setValue([]);return;}
|
|
152
|
-
setValue(_value)
|
|
153
|
-
},[_value]);
|
|
154
|
-
|
|
155
|
-
useEffect(()=>{
|
|
156
|
-
init();
|
|
157
|
-
},[])
|
|
158
|
-
|
|
159
|
-
return (
|
|
160
|
-
<Select
|
|
161
|
-
mode="multiple"
|
|
162
|
-
showSearch
|
|
163
|
-
value={value}
|
|
164
|
-
options={groupList}
|
|
165
|
-
onChange={onGroupUserChange}
|
|
166
|
-
filterOption={onFilter}
|
|
167
|
-
placeholder='请选择组名或用户名'
|
|
168
|
-
/>
|
|
169
|
-
)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export default SelectGroupUser;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import { Select } from 'antd';
|
|
5
|
-
import {USER_ENUM} from '@/services/authAdmin/user';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef userEnumPrams
|
|
9
|
-
* @property {1|0|''} status - 1启用中的 0禁用中的 空为所有
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 用户选择框
|
|
14
|
-
* 数据来源:用户管理-所有枚举
|
|
15
|
-
* @param {object} props
|
|
16
|
-
* @param {'single'|'multiple'} [props.mode='single'] - 单选/多选模式
|
|
17
|
-
* @param {(value:string|string[],items:object[])=>void} [props.onChange] - 选择发生变化时的回调
|
|
18
|
-
* @param {string|string[]} [props.value] - 选择发生变化时的回调
|
|
19
|
-
* @param {userEnumPrams} [props.userType={status:1}] - 选择发生变化时的回调
|
|
20
|
-
* @param {boolean} [props.withData=false] - 返回的数据是否包含原始用户数据
|
|
21
|
-
* @param {object} [props.style={}] - 样式
|
|
22
|
-
* @param {string} [props.placeholder] - 提示
|
|
23
|
-
* @param {boolean} [props.allowClear=falsse] - 一键删除按钮
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @returns {JSX.Element}
|
|
28
|
-
*/
|
|
29
|
-
const SelectUser=(props)=>{
|
|
30
|
-
const {mode='single',value:_value,userType={status:1},onChange,withData=false,style:_style={},placeholder='',allowClear=false} = props;
|
|
31
|
-
const [list,setList]= useState([]);
|
|
32
|
-
|
|
33
|
-
const [value,setValue]=useState(mode=='single'?'':[]);
|
|
34
|
-
|
|
35
|
-
const init = async ()=>{
|
|
36
|
-
const req = await USER_ENUM(userType);
|
|
37
|
-
if(req?.code==0){
|
|
38
|
-
let users= req.data.map(user=>{
|
|
39
|
-
const {id,name,account,status} = user;
|
|
40
|
-
|
|
41
|
-
// return <Select.Option value={`${id}`} data={user}>{`${name}(${account})`}</Select.Option>
|
|
42
|
-
return {
|
|
43
|
-
label:status==0?`${name}(${account})[已禁用]`:`${name}(${account})`,
|
|
44
|
-
value:`${id}`,
|
|
45
|
-
data:user
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
setList(users);
|
|
49
|
-
}else{setList([])}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const onUserChange=(newValue,options)=>{
|
|
54
|
-
if(onChange)onChange(newValue,options);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const onFilter=(input,option)=>{
|
|
58
|
-
const {label,value}= option;
|
|
59
|
-
if( `${label}`.indexOf(input) >=0 ){
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// useEffect(()=>{
|
|
66
|
-
// if(list&&list.length>0){
|
|
67
|
-
// if(mode=='single'){
|
|
68
|
-
// let find = list.filter(user=>user.value == value);
|
|
69
|
-
// if(!find || !find[0]){
|
|
70
|
-
// if(onChange)onChange(undefined);
|
|
71
|
-
// }
|
|
72
|
-
// }else{
|
|
73
|
-
// let newValue=[];
|
|
74
|
-
// value.forEach(id=>{
|
|
75
|
-
// let find = list.filter(user=>user.value == id);
|
|
76
|
-
// if(find && find[0]){
|
|
77
|
-
// newValue.push(id);
|
|
78
|
-
// }
|
|
79
|
-
// })
|
|
80
|
-
// if(onChange)onChange(newValue);
|
|
81
|
-
|
|
82
|
-
// }
|
|
83
|
-
// }
|
|
84
|
-
// },[list])
|
|
85
|
-
|
|
86
|
-
useEffect(()=>{
|
|
87
|
-
init();
|
|
88
|
-
},[])
|
|
89
|
-
useEffect(()=>{
|
|
90
|
-
if(!_value){
|
|
91
|
-
setValue(undefined);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
let req;
|
|
95
|
-
if(mode=='multiple' && Array.isArray(_value)){
|
|
96
|
-
req= _value.map(id=>`${id}`)
|
|
97
|
-
}else{
|
|
98
|
-
req = `${_value}`
|
|
99
|
-
}
|
|
100
|
-
setValue(req)
|
|
101
|
-
},[_value]);
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<Select
|
|
105
|
-
style={{..._style}}
|
|
106
|
-
placeholder={placeholder}
|
|
107
|
-
allowClear={allowClear?true:false}
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
mode={mode}
|
|
110
|
-
showSearch
|
|
111
|
-
value={value}
|
|
112
|
-
options={list}
|
|
113
|
-
onChange={onUserChange}
|
|
114
|
-
filterOption={onFilter}
|
|
115
|
-
/>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export default SelectUser;
|