kn-cli 1.0.133 → 1.0.135

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.
Files changed (108) hide show
  1. package/build/shellUtil.sh +2 -2
  2. package/build/start.sh +3 -2
  3. package/build/vite.config.js +1 -0
  4. package/package.json +1 -1
  5. package/templates/template_admin_antd5/package.json +3 -3
  6. package/templates/template_admin_antd5/public/src/_antd.less +4 -4
  7. package/templates/template_admin_antd5/public/src/_reset.module.less +1 -1
  8. package/templates/template_admin_antd5/public/src/_variable.module.less +5 -5
  9. package/templates/template_admin_antd5/public/src/assets/images/expand-hover.png +0 -0
  10. package/templates/template_admin_antd5/public/src/assets/images/expand.png +0 -0
  11. package/templates/template_admin_antd5/public/src/assets/images/icon-add.png +0 -0
  12. package/templates/template_admin_antd5/public/src/assets/images/icon-full-size.png +0 -0
  13. package/templates/template_admin_antd5/public/src/assets/images/icon-resize.png +0 -0
  14. package/templates/template_admin_antd5/public/src/assets/images/icon-user.png +0 -0
  15. package/templates/template_admin_antd5/public/src/assets/images/login/bg.png +0 -0
  16. package/templates/template_admin_antd5/public/src/assets/images/login/logo.png +0 -0
  17. package/templates/template_admin_antd5/public/src/assets/images/nav/slogan.png +0 -0
  18. package/templates/template_admin_antd5/public/src/assets/images/unexpand-hover.png +0 -0
  19. package/templates/template_admin_antd5/public/src/assets/images/unexpand.png +0 -0
  20. package/templates/template_admin_antd5/public/src/components/antd/antProvider.jsx +16 -4
  21. package/templates/template_admin_antd5/public/src/components/antd/drawer/README.md +336 -0
  22. package/templates/template_admin_antd5/public/src/components/antd/drawer/index.jsx +264 -0
  23. package/templates/template_admin_antd5/public/src/components/antd/index.jsx +19 -7
  24. package/templates/template_admin_antd5/public/src/components/antd/index.module.less +26 -0
  25. package/templates/template_admin_antd5/public/src/components/antd/modal/README.md +324 -0
  26. package/templates/template_admin_antd5/public/src/components/antd/modal/index.jsx +185 -0
  27. package/templates/template_admin_antd5/public/src/components/antd/select/index.jsx +1 -1
  28. package/templates/template_admin_antd5/public/src/components/antd/spin/index.jsx +92 -0
  29. package/templates/template_admin_antd5/public/src/components/antd/spin/index.module.less +58 -0
  30. package/templates/template_admin_antd5/public/src/components/antd/theme.js +19 -8
  31. package/templates/template_admin_antd5/public/src/components/antd/tooltip/detail/index.jsx +19 -56
  32. package/templates/template_admin_antd5/public/src/components/debug/index.jsx +7 -2
  33. package/templates/template_admin_antd5/public/src/components/error/index.jsx +0 -5
  34. package/templates/template_admin_antd5/public/src/components/icon/expand/index.jsx +17 -0
  35. package/templates/template_admin_antd5/public/src/components/icon/expand/index.module.less +22 -0
  36. package/templates/template_admin_antd5/public/src/components/icon/fullSize/index.jsx +13 -0
  37. package/templates/template_admin_antd5/public/src/components/icon/fullSize/index.module.less +28 -0
  38. package/templates/template_admin_antd5/public/src/components/icon/index.jsx +7 -1
  39. package/templates/template_admin_antd5/public/src/components/image/preview.jsx +7 -10
  40. package/templates/template_admin_antd5/public/src/components/layout/basic/index.module.less +1 -1
  41. package/templates/template_admin_antd5/public/src/components/leftMenu/index.jsx +1 -2
  42. package/templates/template_admin_antd5/public/src/components/link/index.module.less +2 -2
  43. package/templates/template_admin_antd5/public/src/components/menuIcon/index.module.less +3 -3
  44. package/templates/template_admin_antd5/public/src/components/popup/index.jsx +91 -50
  45. package/templates/template_admin_antd5/public/src/components/popup/index.module.less +22 -15
  46. package/templates/template_admin_antd5/public/src/components/react/index.jsx +23 -9
  47. package/templates/template_admin_antd5/public/src/components/resizeBox/index.jsx +3 -3
  48. package/templates/template_admin_antd5/public/src/components/select/defaultServicesSelect/index.jsx +151 -40
  49. package/templates/template_admin_antd5/public/src/components/select/dictSelect/index.jsx +19 -3
  50. package/templates/template_admin_antd5/public/src/components/select/useSelectList.jsx +65 -65
  51. package/templates/template_admin_antd5/public/src/components/table/index.jsx +48 -327
  52. package/templates/template_admin_antd5/public/src/components/table/index.module.less +0 -110
  53. package/templates/template_admin_antd5/public/src/components/table/table/index.jsx +242 -0
  54. package/templates/template_admin_antd5/public/src/components/table/table/index.module.less +85 -0
  55. package/templates/template_admin_antd5/public/src/components/table/withPage.jsx +53 -0
  56. package/templates/template_admin_antd5/public/src/components/topMenu/index.jsx +46 -11
  57. package/templates/template_admin_antd5/public/src/components/topMenu/index.module.less +10 -7
  58. package/templates/template_admin_antd5/public/src/components/topMenu/popmenu/index.jsx +89 -0
  59. package/templates/template_admin_antd5/public/src/components/topMenu/popmenu/index.module.less +76 -0
  60. package/templates/template_admin_antd5/public/src/components/topMenu/topBar/index.module.less +4 -3
  61. package/templates/template_admin_antd5/public/src/components/video/index.jsx +1 -1
  62. package/templates/template_admin_antd5/public/src/components/video/preview.jsx +7 -10
  63. package/templates/template_admin_antd5/public/src/config.js +3 -0
  64. package/templates/template_admin_antd5/public/src/hooks/useLoading.jsx +2 -2
  65. package/templates/template_admin_antd5/public/src/index.jsx +2 -4
  66. package/templates/template_admin_antd5/public/src/mock/demo.js +3 -3
  67. package/templates/template_admin_antd5/public/src/pages/antdComponents/button/index.jsx +22 -0
  68. package/templates/template_admin_antd5/public/src/pages/antdComponents/check/index.jsx +12 -0
  69. package/templates/template_admin_antd5/public/src/pages/antdComponents/index.jsx +57 -114
  70. package/templates/template_admin_antd5/public/src/pages/antdComponents/index.module.less +5 -0
  71. package/templates/template_admin_antd5/public/src/pages/antdComponents/input/index.jsx +14 -0
  72. package/templates/template_admin_antd5/public/src/pages/antdComponents/loading/index.jsx +31 -0
  73. package/templates/template_admin_antd5/public/src/pages/antdComponents/message/index.jsx +102 -0
  74. package/templates/template_admin_antd5/public/src/pages/antdComponents/message/index.module.less +17 -0
  75. package/templates/template_admin_antd5/public/src/pages/antdComponents/radio/index.jsx +26 -0
  76. package/templates/template_admin_antd5/public/src/pages/antdComponents/select/index.jsx +13 -0
  77. package/templates/template_admin_antd5/public/src/pages/antdComponents/switch/index.jsx +12 -0
  78. package/templates/template_admin_antd5/public/src/pages/antdComponents/tableWithPage/index.jsx +70 -0
  79. package/templates/template_admin_antd5/public/src/pages/antdComponents/text/index.jsx +21 -0
  80. package/templates/template_admin_antd5/public/src/pages/auth/user/dialog/index.jsx +48 -75
  81. package/templates/template_admin_antd5/public/src/pages/auth/user/index.jsx +17 -23
  82. package/templates/template_admin_antd5/public/src/pages/lazyLoad/index.jsx +11 -0
  83. package/templates/template_admin_antd5/public/src/pages/login/index.jsx +8 -3
  84. package/templates/template_admin_antd5/public/src/pages/login/index.module.less +18 -10
  85. package/templates/template_admin_antd5/public/src/route.jsx +14 -9
  86. package/templates/template_admin_antd5/public/src/services/demo.js +38 -2
  87. package/templates/template_admin_antd5/public/src/services/interceptor/index.js +30 -3
  88. package/templates/template_admin_antd5/public/src/types/global.d.js +306 -0
  89. package/templates/template_admin_antd5/public/src/utils/format.js +1 -1
  90. package/templates/template_admin_antd5/public/src/utils/index.js +3 -3
  91. package/templates/template_admin_antd5/public/src/utils/moment.js +15 -0
  92. package/templates/template_admin_antd5/public/src/components/_table/column.jsx +0 -47
  93. package/templates/template_admin_antd5/public/src/components/_table/column.module.less +0 -12
  94. package/templates/template_admin_antd5/public/src/components/_table/index.jsx +0 -71
  95. package/templates/template_admin_antd5/public/src/components/_table/index.module.less +0 -15
  96. package/templates/template_admin_antd5/public/src/components/badge/index.jsx +0 -47
  97. package/templates/template_admin_antd5/public/src/components/badge/index.module.less +0 -44
  98. package/templates/template_admin_antd5/public/src/components/page/pageLoading/index.jsx +0 -51
  99. package/templates/template_admin_antd5/public/src/components/page/pageLoading/index.module.less +0 -29
  100. package/templates/template_admin_antd5/public/src/components/table/aliTable/index.jsx +0 -250
  101. package/templates/template_admin_antd5/public/src/components/table/aliTable/index.module.less +0 -105
  102. package/templates/template_admin_antd5/public/src/components/toast/index.jsx +0 -79
  103. package/templates/template_admin_antd5/public/src/components/toast/index.module.less +0 -43
  104. package/templates/template_admin_antd5/public/src/type.js +0 -67
  105. package/templates/template_admin_antd5/renamejstojsx.js +0 -45
  106. package/templates/template_admin_antd5/renameless.js +0 -53
  107. /package/templates/template_admin_antd5/public/src/components/{button → antd/button}/index.jsx +0 -0
  108. /package/templates/template_admin_antd5/public/src/components/resizeBox/{index.module.css → index.module.less} +0 -0
@@ -4,8 +4,7 @@ import React, { useEffect, useState } from 'react';
4
4
  import {useNavigate,} from 'react-router-dom';
5
5
 
6
6
  // @ts-ignore
7
- import { Menu } from '@/components/antd';
8
- import Badge from '@/components/badge'
7
+ import { Menu,Badge } from '@/components/antd';
9
8
 
10
9
  import {useLoading} from '@/hooks/index';
11
10
  import ProviderMenu from '@/provider/menu';
@@ -2,10 +2,10 @@
2
2
 
3
3
 
4
4
  .linkWrap{
5
- color: var(--color-primary);
5
+ color: var(--theme-color-primary);
6
6
  font-size: 14px;
7
7
  &:hover{
8
- color: var(--color-primary-hover);
8
+ color: var(--theme-color-primary-hover);
9
9
  cursor: pointer;
10
10
  }
11
11
  }
@@ -4,7 +4,7 @@
4
4
  .iconGroup{
5
5
  width: 17px;
6
6
  height: 100%;
7
- margin-right: 12px;
7
+ margin-right: 8px;
8
8
  display: inline-flex;
9
9
  align-items: center;
10
10
  margin-left:-12px;
@@ -37,11 +37,11 @@
37
37
  font-weight: bold;
38
38
  a{
39
39
  font-weight: inherit;
40
- color: #0974F2;
40
+ // color: #0974F2;
41
41
  }
42
42
  }
43
43
  :global(.ant-menu-submenu-arrow) {
44
- color: #0974F2
44
+ // color: #0974F2
45
45
  }
46
46
  }
47
47
  :global(.ant-menu-inline.ant-menu-root .ant-menu-item > .ant-menu-title-content){
@@ -1,60 +1,101 @@
1
- // @ts-ignore
2
- import React from 'react';
3
- // @ts-ignore
4
- import ReactDOM from 'react-dom';
5
-
6
- // @ts-ignore
1
+ import React, { useState } from 'react';
2
+ import { ReactRender } from '@/components/react';
7
3
  import styles from './index.module.less';
8
- styles;
9
-
10
- export const popupList={
11
- list:[],
12
- remove:function(fn){
13
- let list = popupList.list;
14
- let idx = list.indexOf(fn);
15
- if(idx>=0)list.splice(idx,1);
16
- },
17
- destroyAll:function(){
18
- let list = popupList.list;
19
4
 
20
- while(list.length>0){
21
- let fn = list.shift();
22
- fn(false);
5
+ /**
6
+ * @typedef {Object} ShowPopupOptions
7
+ * @property {React.ReactNode} content - 居中显示的内容-该组件内接受close方法用于回调用户关闭窗口事件
8
+ * @property {boolean} [showMask=true] - 是否显示背景遮罩(rgba(0,0,0,.5))
9
+ * @property {boolean} [canTouch=false] - 鼠标事件是否穿透浮层
10
+ * @property {boolean} [closeOnClick=false] - 点击浮层区域(非 content)是否关闭
11
+ */
12
+
13
+ const Popup2 = ({ resolve, content, showMask, canTouch, closeOnClick }) => {
14
+ const [overlayEl, setOverlayEl] = useState(null);
15
+
16
+ const close = (result) => {
17
+ resolve(result);
18
+ };
19
+
20
+ const onOverlayClick = (e) => {
21
+ if (!closeOnClick) return;
22
+ if (e.target === e.currentTarget) {
23
+ close(false);
24
+ }
25
+ };
26
+
27
+ return (
28
+ <div
29
+ className={styles.overlay}
30
+ data-mask={showMask || undefined}
31
+ data-can-touch={canTouch || undefined}
32
+ onClick={onOverlayClick}
33
+ >
34
+ <div className={styles.content} ref={setOverlayEl}>
35
+ {overlayEl && React.cloneElement(content, { close, getContainer: () => overlayEl })}
36
+ </div>
37
+ </div>
38
+ );
39
+ };
40
+
41
+ export const popupList = {
42
+ _list: [],
43
+ add(close) {
44
+ this._list.push(close);
45
+ },
46
+ remove(close) {
47
+ const idx = this._list.indexOf(close);
48
+ if (idx >= 0) this._list.splice(idx, 1);
49
+ },
50
+ destroyAll() {
51
+ while (this._list.length > 0) {
52
+ this._list.shift()(false);
23
53
  }
24
54
  },
25
- add:function(fn){
26
- popupList.list.push(fn);
27
- }
55
+ };
56
+
57
+ export const destoryAll=()=>{
58
+ popupList.destroyAll();
28
59
  }
29
60
 
30
61
  /**
31
- * 一个全屏置顶的遮罩层
32
- * @param {(result)=>void} reslove - 遮罩层的关闭回调
33
- * @param {Object} [options] - 参数
34
- * @param {boolean} [options.cantouch=false] - 是否允许被点击穿透
35
- * @param {boolean} [options.transparent=false] - 是否遮罩层完全透明
36
- * @param {string} [options.className=''] - 扩展样式
37
- *
38
- *
39
- * @returns { {dom:HTMLElement,destory:()=>void} }
62
+ * 显示一个全屏浮层
63
+ * @param {ShowPopupOptions} options
64
+ * @returns {Promise<boolean>} true 表示确认关闭,false 表示取消/点击遮罩关闭
40
65
  */
41
- const Popup = (reslove,options) => {
42
- let rootDom = document.createElement('div');
43
- rootDom.className='popup-box';
44
- if(options&&options.className)rootDom.className += ` ${options.className}`
45
- if(options&&options.cantouch)rootDom.setAttribute('data-can-touch','1');
46
- if(options&&options.transparent)rootDom.setAttribute('data-transparent','1');
47
-
48
- let destory = (result) => {
49
- popupList.remove(destory);
50
- ReactDOM.unmountComponentAtNode(rootDom);
51
- rootDom.parentNode.removeChild(rootDom);
52
- if (reslove) reslove(result);
53
- };
54
- popupList.add(destory);
55
- document.body.appendChild(rootDom);
56
- return { dom: rootDom, destory };
57
- };
66
+ export const showPopup = (options = { content: <></> }) => {
67
+ const { content, showMask = true, canTouch = false, closeOnClick = true } = options;
68
+
69
+ return new Promise((resolve) => {
70
+ const container = document.createElement('div');
71
+ document.body.appendChild(container);
72
+
73
+ let root;
58
74
 
75
+ const wrappedResolve = (result) => {
76
+ popupList.remove(wrappedResolve);
77
+ setTimeout(() => {
78
+ root && root.unmount();
79
+ if (container.parentNode) {
80
+ container.parentNode.removeChild(container);
81
+ }
82
+ }, 0);
83
+ resolve(result);
84
+ };
85
+
86
+ popupList.add(wrappedResolve);
87
+
88
+ root = ReactRender(
89
+ <Popup2
90
+ resolve={wrappedResolve}
91
+ content={content}
92
+ showMask={showMask}
93
+ canTouch={canTouch}
94
+ closeOnClick={closeOnClick}
95
+ />,
96
+ container
97
+ );
98
+ });
99
+ };
59
100
 
60
- export default Popup;
101
+ export default showPopup;
@@ -1,18 +1,25 @@
1
+ .overlay {
2
+ position: fixed;
3
+ left: 0;
4
+ top: 0;
5
+ width: 100%;
6
+ height: 100%;
7
+ z-index: 9999;
8
+ display: flex;
9
+ align-items: center;
10
+ justify-content: center;
1
11
 
12
+ &[data-mask] {
13
+ background: rgba(0, 0, 0, 0.5);
14
+ }
2
15
 
3
- :global{
4
- .popup-box{
5
- position: absolute;
6
- left:0;
7
- top:0;
8
- width:100%;
9
- height:100%;
10
- z-index: 99;
11
- &[data-transparent]{
12
- height:auto;
13
- }
14
- &[data-can-touch]{
15
- pointer-events: none;
16
- }
16
+ &[data-can-touch] {
17
+ pointer-events: none;
17
18
  }
18
- }
19
+ }
20
+
21
+ .content {
22
+ position: relative;
23
+ z-index: 1;
24
+ pointer-events: auto;
25
+ }
@@ -1,12 +1,26 @@
1
- import ReactDOM from 'react-dom/client'; // 注意这里增加了 /client
2
-
3
- export const ReactRender = (component, targetDom) => {
4
- // 1. 创建 root
5
- const root = ReactDOM.createRoot(targetDom);
6
- // 2. 渲染组件
7
- root.render(component);
8
-
9
- // 建议:返回这个 root,以便将来可以手动卸载 root.unmount()
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import Antd5Provider from '@/components/antd/antProvider';
4
+
5
+ /**
6
+ * 渲染 React 组件到指定 DOM
7
+ * @param {React.ReactElement} component - 要渲染的组件
8
+ * @param {HTMLElement} targetDom - 目标 DOM 节点
9
+ * @param {ReactDOM.Root} [existingRoot] - 可选的已存在的 root,如果提供则使用它
10
+ * @returns {ReactDOM.Root} React 18 的 root 对象
11
+ */
12
+ export const ReactRender = (component, targetDom, existingRoot = null) => {
13
+ // 如果提供了 existingRoot,使用它;否则创建新的
14
+ const root = existingRoot || ReactDOM.createRoot(targetDom);
15
+
16
+ // 包裹 Antd5Provider,确保继承主题配置
17
+ root.render(
18
+ <Antd5Provider>
19
+ {component}
20
+ </Antd5Provider>
21
+ );
22
+
23
+ // 返回 root,以便将来可以手动卸载 root.unmount()
10
24
  return root;
11
25
  }
12
26
 
@@ -1,10 +1,10 @@
1
1
  import React, { useState, useRef, useEffect, useCallback } from 'react';
2
- import styles from './index.module.css';
2
+ import styles from './index.module.less';
3
3
 
4
4
  const ResizableContainer = (props) => {
5
- const { children, title = '', width: propWidth, height: propHeight, onResize } = props;
5
+ const { children, title = '', width: propWidth, height: propHeight, onResize,autoSize=false } = props;
6
6
  const [refreshKey, setRefreshKey] = useState(0);
7
- const [containerSize, setContainerSize] = useState({ width: propWidth || 400, height: propHeight || 200 });
7
+ const [containerSize, setContainerSize] = useState({ width: propWidth || (autoSize?'auto':400), height: propHeight || (autoSize?'auto':200) });
8
8
  const [displaySize, setDisplaySize] = useState({ width: propWidth || 400, height: propHeight || 200 });
9
9
  const [isEditing, setIsEditing] = useState(false);
10
10
  const [editValue, setEditValue] = useState('');
@@ -3,27 +3,14 @@ import React, { useEffect, useRef, forwardRef, useImperativeHandle, useState } f
3
3
  // @ts-ignore
4
4
  import { Select } from "@/components/antd";
5
5
  import useSelectList from '../useSelectList';
6
+ import {DEBUG_SELECT_ITEMS} from '@/config';
7
+ import { hasValue } from '@/utils';
8
+ import { isArray } from 'lodash';
6
9
 
7
- /**
8
- * @typedef SelectItemOption
9
- * @property {string} label - 显示的名称
10
- * @property {string} value - 唯一值
11
- * @property {object} [data] - 原始数据
12
- *
13
- */
14
-
15
- /**
16
- * @typedef DefaultServicesSelectProps
17
- * @property {string} [name] - 调试用的名称
18
- * @property {object} services - api接口 符合输出的结果为{id:'',name:''}结构
19
- * @property {object} [servicesProps={}] - 接口传参
20
- * @property {(item:object)=>SelectItemOption} [formatOptionItem] - 用户格式化接口返回的数据成标准option数据
21
- * @property {(list:object[]|object)=>SelectItemOption[]} [formatOptionList] - 对整个response处理返回option
22
- */
23
10
 
24
11
  /**
25
12
  * 从字典生成下拉框
26
- * @param {import('../useSelectList').SelectListProps & DefaultServicesSelectProps} props
13
+ * @param {SelectListProps & DefaultServicesSelectProps} props
27
14
  * @returns {JSX.Element}
28
15
  */
29
16
  const DefaultServicesSelect=(props,ref)=>{
@@ -48,9 +35,18 @@ const DefaultServicesSelect=(props,ref)=>{
48
35
  formatOptionList,
49
36
  onDefaultSelect,
50
37
  onListUpdate,
38
+ onBlur,
51
39
  name,
52
- required=false
40
+ required=false,
41
+ maxCount=Infinity,
42
+ debug=false,
43
+ onAfterListUpdate,
44
+ antd5=false
53
45
  } = props;
46
+ /**
47
+ * @type {React.MutableRefObject<object>}
48
+ */
49
+ const refSelf = useRef({});
54
50
 
55
51
  // 单选框默认带一键删除
56
52
  const allowClear = props.allowClear??((required==false)?true:false);
@@ -59,19 +55,38 @@ const DefaultServicesSelect=(props,ref)=>{
59
55
  const selectList = useSelectList(props);
60
56
  const [requestParams,setRequestParams] = useState(servicesProps)
61
57
  const refInitList=useRef([]);
58
+ const [loading,setLoading] = useState(false);
62
59
 
63
60
  // 初始化加载下拉框数据
64
61
  const init = async ()=>{
62
+ setLoading(true);
63
+ if(debug && name ){
64
+ console.log(`[${name}]-init1:`,services,servicesProps)
65
+ }
65
66
  const req = await services(servicesProps);
66
- if(refDestory.current){return;}
67
+ if(debug && name ){
68
+ console.log(`[${name}]-init2:`,req)
69
+ }
70
+ if(refDestory.current){
71
+ if(debug && name ){
72
+ console.log(`[${name}]-init-destory1:`,refInitList.current.length)
73
+ }
74
+ return;
75
+ }
76
+ setLoading(false);
67
77
  let values=[];
68
78
  if(req?.code==0){
69
79
  let data=[];
70
80
  if(formatOptionList){
71
- data = formatOptionList(req.data);
81
+ data = formatOptionList(req?.data||[]);
72
82
  }else{
73
- data= req.data.map(item=>{
83
+ data= req?.data?.map(item=>{
74
84
  return formatOptionItem(item)
85
+ })||[]
86
+ }
87
+ if(DEBUG_SELECT_ITEMS){
88
+ data.forEach(item=>{
89
+ item.label = `${item.label}[${item.value}]`
75
90
  })
76
91
  }
77
92
  values=data;
@@ -80,18 +95,36 @@ const DefaultServicesSelect=(props,ref)=>{
80
95
  onListUpdate(values);
81
96
  }
82
97
  if(onDefaultSelect){
83
- let defaultItem = onDefaultSelect(values);
84
- if(defaultItem){
85
- onValueChange(defaultItem.value,defaultItem,true)
98
+ if(hasValue(_value)==false){
99
+ let defaultItem = onDefaultSelect(values);
100
+ if(defaultItem){
101
+ onValueChange(defaultItem.value,defaultItem,true)
102
+ }
86
103
  }
87
104
  }
105
+ if(debug && name ){
106
+ console.log(`[${name}]-init3:`,values)
107
+ }
88
108
  const t= await selectList.init(values);
89
- if(refDestory.current){return;}
109
+ if(debug && name ){
110
+ console.log(`[${name}]-init4:`,t)
111
+ }
112
+ if(refDestory.current){
113
+ if(debug && name ){
114
+ console.log(`[${name}]-init-destory2:`,refInitList.current.length)
115
+ }
116
+ return;
117
+
118
+ }
119
+ if(onAfterListUpdate){
120
+ onAfterListUpdate(values);
121
+ }
90
122
  refInitList.current.shift();
91
123
  if( refInitList.current.length >0 ){
92
124
  let fn = refInitList.current[0]
93
125
  fn();
94
126
  }
127
+
95
128
  return t;
96
129
  }
97
130
  const onFilter=(input,option)=>{
@@ -105,7 +138,29 @@ const DefaultServicesSelect=(props,ref)=>{
105
138
  const onValueChange= async (newValue,options,force=false)=>{
106
139
  if(!force && canChange){
107
140
  let req = await canChange(newValue,options);
108
- if(!req)return;
141
+ if(!req){
142
+ if(refSelf.current.lastOption){
143
+ if(name){
144
+ // 强行将显示内容切换成上一次选择的内容
145
+ let dom = document.querySelector(`[data-select-name='${name}'] .ant5-select-selection-item`);
146
+ if(dom && refSelf?.current?.lastOption?.label){
147
+ console.log(`antd-select ${name}组件显示label切换为:`,refSelf.current.lastOption.label)
148
+ // @ts-ignore
149
+ dom.innerText = refSelf.current.lastOption.label;
150
+ }
151
+
152
+ }
153
+ }
154
+ return;
155
+ }
156
+ }
157
+ refSelf.current.lastOption=options;
158
+ if(mode == 'multiple' && maxCount && maxCount != Infinity){
159
+ if( newValue.length > maxCount ){
160
+ newValue.pop();
161
+ // message.warn(`最多选择${maxCount}个`);
162
+ return;
163
+ }
109
164
  }
110
165
  if(onChange)onChange(newValue,options);
111
166
  }
@@ -122,13 +177,23 @@ const DefaultServicesSelect=(props,ref)=>{
122
177
 
123
178
  useEffect(()=>{
124
179
  let keys = Object.keys(servicesProps)
125
- if(keys.length<=0)return;
126
- let changes = keys.some(key=>{
127
- if(servicesProps[key] != requestParams[key]){
128
- return true;
129
- }
130
- return false;
131
- })
180
+ let oldKeys = Object.keys(requestParams);
181
+ if(keys.length<=0 && oldKeys.length<=0){
182
+ return;
183
+ }
184
+ let changes=false;
185
+ if( oldKeys.length != keys.length ){
186
+ changes=true;
187
+ }
188
+ if(!changes){
189
+ changes = keys.some(key=>{
190
+ if(servicesProps[key] != requestParams[key]){
191
+ return true;
192
+ }
193
+ return false;
194
+ })
195
+ }
196
+
132
197
  if(changes){
133
198
  setRequestParams(servicesProps)
134
199
  }
@@ -142,15 +207,53 @@ const DefaultServicesSelect=(props,ref)=>{
142
207
 
143
208
 
144
209
  useImperativeHandle(ref, () => ({
210
+ // 检查值是否合法
211
+ validateValue:(value)=>{
212
+ let _value=[];
213
+ if(mode=='single'){
214
+ _value = value==undefined?selectList.value:value;
215
+ _value = hasValue(_value)?[_value]:[];
216
+ }else{
217
+ _value = value==undefined?selectList.value:value;
218
+ if(isArray(_value)){
219
+ _value= [..._value]
220
+ }else{
221
+ _value=[];
222
+ }
223
+ }
224
+ let error=[];
225
+ _value.forEach(id=>{
226
+ let find=false;
227
+ for(let item of selectList.list){
228
+ if(item.value == id){
229
+ find=true;
230
+ if(item.isNoFind){
231
+ error.push(`${id}`);
232
+ }
233
+ break;
234
+ }
235
+ }
236
+ if(!find){
237
+ error.push(`${id}`);
238
+ }
239
+ });
240
+ return error;
241
+ },
145
242
  getSelectList:()=>{
146
243
  return selectList;
147
244
  },
245
+ refresh:()=>{
246
+ if(refInitList.current.length<=0){
247
+ refInitList.current.push(init)
248
+ init();
249
+ }else{
250
+ refInitList.current.push(init);
251
+ }
252
+ },
253
+ loading
148
254
  }));
149
255
 
150
- let className=''
151
- if(selectList.props.className){
152
- className = selectList.props.className;
153
- }
256
+ let className=props?.className||'';
154
257
  if(selectList.props.maxTagCount){
155
258
  if(Array.isArray(className)){
156
259
  className.push('antd-show-tag')
@@ -158,11 +261,15 @@ const DefaultServicesSelect=(props,ref)=>{
158
261
  className+= ' antd-show-tag';
159
262
  }
160
263
  }
264
+ if(name && debug ){
265
+ console.log(`[${name}]:`,loading,selectList.list)
266
+ }
161
267
  return (
162
268
  <Select
269
+ data-select-name={name||undefined}
163
270
  // getPopupContainer={trigger => trigger?.parentElement||document.body}
164
- loading={selectList.list===null}
165
- disabled={selectList.list===null || disabled}
271
+ loading={loading||selectList.list===null}
272
+ disabled={loading||selectList.list===null || disabled}
166
273
  style={{..._style}}
167
274
  placeholder={placeholder}
168
275
  allowClear={allowClear}
@@ -172,9 +279,13 @@ const DefaultServicesSelect=(props,ref)=>{
172
279
  value={selectList.value}
173
280
  options={selectList.list}
174
281
  onChange={onValueChange}
175
- filterOption={onFilter}
282
+ filterOption={props.onFilter??onFilter}
283
+ onBlur={onBlur}
284
+ showAll={props.showAll}
285
+ allValue={props.allValue}
176
286
  {...selectList.props}
177
287
  className={className}
288
+ maxCount={maxCount}
178
289
  />
179
290
  );
180
291
  }
@@ -1,5 +1,5 @@
1
1
 
2
- import React, { useEffect, useRef } from 'react';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
3
  // @ts-ignore
4
4
  import { Select } from "@/components/antd";
5
5
  import useSelectList from '../useSelectList';
@@ -11,7 +11,7 @@ import useSelectList from '../useSelectList';
11
11
 
12
12
  /**
13
13
  * 从字典生成下拉框
14
- * @param {import('../useSelectList').SelectListProps & DictSelectProps} props
14
+ * @param {SelectListProps & DictSelectProps} props
15
15
  * @returns {JSX.Element}
16
16
  */
17
17
  const DictSelect=(props)=>{
@@ -24,6 +24,7 @@ const DictSelect=(props)=>{
24
24
  disabled=false,
25
25
  emDict,
26
26
  required=false,
27
+ onDefaultSelect
27
28
  } = props;
28
29
 
29
30
  const allowClear = props.allowClear??((mode=='single'&&required==false)?true:false);
@@ -31,6 +32,7 @@ const DictSelect=(props)=>{
31
32
  const refDestory = useRef(false);
32
33
  const selectList = useSelectList(props);
33
34
 
35
+
34
36
  // 初始化加载下拉框数据
35
37
  const init = async ()=>{
36
38
  if(refDestory.current)return;
@@ -39,10 +41,19 @@ const DictSelect=(props)=>{
39
41
  return {
40
42
  label:item.label,
41
43
  value:`${item.id}`,
42
- data:item
44
+ data:item,
45
+ disabled:item.disabled
43
46
  }
44
47
  })
45
48
  values=data;
49
+
50
+ if(onDefaultSelect){
51
+ let defaultItem = onDefaultSelect(values);
52
+ if(defaultItem){
53
+ onValueChange(defaultItem.value,defaultItem)
54
+ }
55
+ }
56
+
46
57
  return await selectList.init(values);
47
58
  }
48
59
  const onFilter=(input,option)=>{
@@ -56,12 +67,15 @@ const DictSelect=(props)=>{
56
67
  if(onChange)onChange(newValue,options);
57
68
  }
58
69
 
70
+
59
71
  useEffect(()=>{
60
72
  init();
61
73
  return ()=>{refDestory.current=true}
62
74
  },[])
63
75
 
76
+
64
77
 
78
+
65
79
  return (
66
80
  <Select
67
81
  loading={selectList.list===null}
@@ -76,6 +90,8 @@ const DictSelect=(props)=>{
76
90
  options={selectList.list}
77
91
  onChange={onValueChange}
78
92
  filterOption={onFilter}
93
+ showAll={props.showAll}
94
+ allValue={props.allValue}
79
95
  {...selectList.props}
80
96
  />
81
97
  );