kn-cli 1.0.43 → 1.0.45

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 (118) hide show
  1. package/package.json +2 -1
  2. package/readme.md +6 -0
  3. package/src/utils/index.js +1 -1
  4. package/templates/template_admin/.gitignore +6 -0
  5. package/templates/template_admin/build.sh +2 -0
  6. package/templates/template_admin/cli.config.js +21 -0
  7. package/templates/template_admin/dev.sh +89 -0
  8. package/templates/template_admin/frontend_build.sh +83 -0
  9. package/templates/template_admin/init/prepare-commit-msg +5 -0
  10. package/templates/template_admin/init.sh +33 -0
  11. package/templates/template_admin/package.json +23 -0
  12. package/templates/template_admin/public/404.html +26 -0
  13. package/templates/template_admin/public/favicon.ico +0 -0
  14. package/templates/template_admin/public/favicon.png +0 -0
  15. package/templates/template_admin/public/index.html +43 -0
  16. package/templates/template_admin/public/src/_antd.less +4 -0
  17. package/templates/template_admin/public/src/_reset.less +128 -0
  18. package/templates/template_admin/public/src/_variable.less +80 -0
  19. package/templates/template_admin/public/src/assets/iconfont/iconfont.eot +0 -0
  20. package/templates/template_admin/public/src/assets/iconfont/iconfont.less +57 -0
  21. package/templates/template_admin/public/src/assets/iconfont/iconfont.svg +36 -0
  22. package/templates/template_admin/public/src/assets/iconfont/iconfont.ttf +0 -0
  23. package/templates/template_admin/public/src/assets/iconfont/iconfont.woff +0 -0
  24. package/templates/template_admin/public/src/assets/iconfont/iconfont.woff2 +0 -0
  25. package/templates/template_admin/public/src/assets/images/avatar.png +0 -0
  26. package/templates/template_admin/public/src/assets/images/loading.svg +40 -0
  27. package/templates/template_admin/public/src/components/Alert/index.jsx +0 -0
  28. package/templates/template_admin/public/src/components/Alert/index.less +0 -0
  29. package/templates/template_admin/public/src/components/Auth/index.jsx +44 -0
  30. package/templates/template_admin/public/src/components/Header/index.jsx +57 -0
  31. package/templates/template_admin/public/src/components/Header/index.less +57 -0
  32. package/templates/template_admin/public/src/components/IconFont/index.jsx +10 -0
  33. package/templates/template_admin/public/src/components/IconFont/index.less +5 -0
  34. package/templates/template_admin/public/src/components/Layout/Basic/index.jsx +26 -0
  35. package/templates/template_admin/public/src/components/Layout/Basic/index.less +37 -0
  36. package/templates/template_admin/public/src/components/Layout/CenterBody/index.jsx +15 -0
  37. package/templates/template_admin/public/src/components/Layout/CenterBody/index.less +30 -0
  38. package/templates/template_admin/public/src/components/Layout/Provider/index.jsx +12 -0
  39. package/templates/template_admin/public/src/components/Layout/index.jsx +27 -0
  40. package/templates/template_admin/public/src/components/Layout/index.less +63 -0
  41. package/templates/template_admin/public/src/components/Link/index.jsx +24 -0
  42. package/templates/template_admin/public/src/components/Link/index.less +11 -0
  43. package/templates/template_admin/public/src/components/Loading/index.jsx +14 -0
  44. package/templates/template_admin/public/src/components/Loading/index.less +85 -0
  45. package/templates/template_admin/public/src/components/Menu/index.jsx +126 -0
  46. package/templates/template_admin/public/src/components/Menu/index.less +19 -0
  47. package/templates/template_admin/public/src/components/Page/PageLoading/index.jsx +30 -0
  48. package/templates/template_admin/public/src/components/Page/PageLoading/index.less +29 -0
  49. package/templates/template_admin/public/src/components/Popup/index.jsx +22 -0
  50. package/templates/template_admin/public/src/components/Popup/index.less +18 -0
  51. package/templates/template_admin/public/src/components/Toast/index.jsx +60 -0
  52. package/templates/template_admin/public/src/components/Toast/index.less +43 -0
  53. package/templates/template_admin/public/src/components/TopMenu/index.jsx +228 -0
  54. package/templates/template_admin/public/src/components/TopMenu/index.less +105 -0
  55. package/templates/template_admin/public/src/components/mask/index.jsx +47 -0
  56. package/templates/template_admin/public/src/components/mask/index.less +32 -0
  57. package/templates/template_admin/public/src/dictionary/index.js +103 -0
  58. package/templates/template_admin/public/src/hooks/index.jsx +18 -0
  59. package/templates/template_admin/public/src/hooks/useDelay.jsx +29 -0
  60. package/templates/template_admin/public/src/hooks/useImageLoader.jsx +27 -0
  61. package/templates/template_admin/public/src/hooks/useLoading.jsx +42 -0
  62. package/templates/template_admin/public/src/hooks/useLogin.jsx +33 -0
  63. package/templates/template_admin/public/src/hooks/useNextPage.jsx +89 -0
  64. package/templates/template_admin/public/src/hooks/usePreload.jsx +66 -0
  65. package/templates/template_admin/public/src/hooks/useScrollTop.jsx +32 -0
  66. package/templates/template_admin/public/src/hooks/useSearch.jsx +137 -0
  67. package/templates/template_admin/public/src/hooks/useUpdate.jsx +11 -0
  68. package/templates/template_admin/public/src/index.jsx +50 -0
  69. package/templates/template_admin/public/src/mock/auth.js +91 -0
  70. package/templates/template_admin/public/src/mock/index.js +63 -0
  71. package/templates/template_admin/public/src/mock/user.js +70 -0
  72. package/templates/template_admin/public/src/mock/utils.js +33 -0
  73. package/templates/template_admin/public/src/pages/checkLogin/index.jsx +13 -0
  74. package/templates/template_admin/public/src/pages/index.jsx +23 -0
  75. package/templates/template_admin/public/src/pages/index.less +22 -0
  76. package/templates/template_admin/public/src/pages/login/index.jsx +27 -0
  77. package/templates/template_admin/public/src/pages/login/index.less +44 -0
  78. package/templates/template_admin/public/src/pages/material/index.jsx +12 -0
  79. package/templates/template_admin/public/src/pages/order/index.jsx +12 -0
  80. package/templates/template_admin/public/src/pages/permission/index.jsx +12 -0
  81. package/templates/template_admin/public/src/pages/subHome/index.jsx +12 -0
  82. package/templates/template_admin/public/src/pages/subHome2/index.jsx +12 -0
  83. package/templates/template_admin/public/src/pages/subHome3/index.jsx +12 -0
  84. package/templates/template_admin/public/src/pages/suggest/index.jsx +12 -0
  85. package/templates/template_admin/public/src/pages/superAdminLogin/index.jsx +57 -0
  86. package/templates/template_admin/public/src/pages/superAdminLogin/index.less +44 -0
  87. package/templates/template_admin/public/src/pages/user/index.jsx +13 -0
  88. package/templates/template_admin/public/src/pages/userData/index.jsx +12 -0
  89. package/templates/template_admin/public/src/pages/video/index.jsx +12 -0
  90. package/templates/template_admin/public/src/provider/app.jsx +119 -0
  91. package/templates/template_admin/public/src/provider/menu.jsx +20 -0
  92. package/templates/template_admin/public/src/route.jsx +77 -0
  93. package/templates/template_admin/public/src/services/auth.js +28 -0
  94. package/templates/template_admin/public/src/services/index.js +181 -0
  95. package/templates/template_admin/public/src/services/user.js +26 -0
  96. package/templates/template_admin/public/src/utils/index.js +38 -0
  97. package/templates/template_admin/public/static/about.html +1 -0
  98. package/templates/template_admin/public/static/kssoLogin.html +22 -0
  99. package/templates/template_admin/readme.md +55 -0
  100. package/templates/template_admin/report.sh +68 -0
  101. package/templates/template_admin/tools/iconfont/gulpfile.js +70 -0
  102. package/templates/template_admin/tools/iconfont/package.json +20 -0
  103. package/templates/template_admin/tools/iconfont/run.sh +39 -0
  104. package/templates/template_admin/tools/iconfont/svg/arrowBack.svg +1 -0
  105. package/templates/template_admin/tools/iconfont/svg/check.svg +1 -0
  106. package/templates/template_admin/tools/iconfont/svg/close.svg +1 -0
  107. package/templates/template_admin/tools/iconfont/svg/down.svg +1 -0
  108. package/templates/template_admin/tools/iconfont/svg/image.svg +1 -0
  109. package/templates/template_admin/tools/iconfont/svg/play.svg +1 -0
  110. package/templates/template_admin/tools/iconfont/svg/refresh.svg +1 -0
  111. package/templates/template_admin/tools/iconfont/svg/warn.svg +1 -0
  112. package/templates/template_admin/tools/iconfont/templates/_icons.css +26 -0
  113. package/templates/template_admin/tools/iconfont/templates/_icons.less +29 -0
  114. package/templates/template_admin/tools/iconfont/templates/index.html +56 -0
  115. package/templates/template_admin/tools/tinypng/package.json +11 -0
  116. package/templates/template_admin/tools/tinypng/run.sh +15 -0
  117. package/templates/template_admin/webpack.api.js +33 -0
  118. package/templates/template_app/.gitignore +6 -0
@@ -0,0 +1,47 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import styles from './index.less';
4
+ import Popup from '@/components/Popup/index.jsx';
5
+
6
+
7
+ const useToast = () => {
8
+
9
+ const ref = useRef();
10
+
11
+ const runNext = (props) => {
12
+ console.log(props.popup.dom);
13
+ ReactDOM.render(
14
+ <Toast {...props} />,
15
+ props.popup.dom
16
+ );
17
+ }
18
+
19
+ const Toast = ({ children }) => {
20
+ return (
21
+ <section className={styles.wrap}>
22
+ <div className={styles.content + ` animate__animated animate__fast`}>
23
+ {children}
24
+ </div>
25
+ </section>
26
+ )
27
+ }
28
+
29
+ const hiddenToast = () => {
30
+ ref.current.destory();
31
+ }
32
+ const showToast = props => {
33
+ props = { children: props }
34
+ return new Promise((resolve) => {
35
+ let popup = Popup(resolve);
36
+ ref.current = popup;
37
+ props.popup = popup;
38
+ runNext(props);
39
+ });
40
+ }
41
+ return {
42
+ showToast, hiddenToast
43
+ }
44
+
45
+ }
46
+
47
+ export default useToast;
@@ -0,0 +1,32 @@
1
+ @import '~@/_variable.less';
2
+
3
+ .wrap{
4
+ position: fixed;
5
+ left:0;
6
+ top:0;
7
+ width:100vw;
8
+ height:100vh;
9
+ display: flex;
10
+ justify-content: center;
11
+ align-items: center;
12
+ flex-direction: column;
13
+ z-index: 1000;
14
+ .content{
15
+ position: fixed;
16
+ left:0;
17
+ top:0;
18
+ width:100vw;
19
+ height:100vh;
20
+
21
+ background: rgba(0,0,0,.8);
22
+ padding:var(--padding-default);
23
+
24
+ display: flex;
25
+ flex-direction: column;
26
+ justify-content: center;
27
+ align-items: center;
28
+
29
+ font-size: 14px;
30
+ color: #FFFFFF;
31
+ }
32
+ }
@@ -0,0 +1,103 @@
1
+
2
+ import React, { useState, useEffect,useMemo} from 'react';
3
+ import {GET_USER_TYPE} from '@/services/user';
4
+
5
+ const bookCreater=options=>{
6
+ const {
7
+ service,
8
+ idKey='value',
9
+ titleKey='label',
10
+ keyName='key',
11
+ defaultTypes=null
12
+ }=options;
13
+
14
+ return (props)=>{
15
+ const [types,setTypes]=useState(defaultTypes||null);
16
+
17
+ const init=async ()=>{
18
+ let ret = await service();
19
+ if(+ret?.code===0){
20
+ setTypes(ret.data||[]);
21
+ }
22
+ }
23
+ useEffect(()=>{
24
+ if(defaultTypes)return;
25
+ init();
26
+ },[]);
27
+
28
+ const getData=({id,title,key}={})=>{
29
+ let name='';
30
+ if(id){
31
+ name=idKey
32
+ }
33
+ else if(title){
34
+ name=titleKey
35
+ }
36
+ else if(key){
37
+ name=keyName;
38
+ }
39
+
40
+ for(let i=0;i<types.length;i++){
41
+ if(''+types[i][name]===''+id){
42
+ return types[i];
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+
48
+ const getTitle=(id)=>{
49
+ if(types){
50
+ for(let i=0;i<types.length;i++){
51
+ if(''+types[i][idKey]===''+id){
52
+ return types[i][titleKey];
53
+ }
54
+ }
55
+ }
56
+ return '';
57
+ }
58
+ const getId=(title)=>{
59
+ if(types){
60
+ for(let i=0;i<types.length;i++){
61
+ if(''+types[i][titleKey]===''+title){
62
+ return types[i][idKey];
63
+ }
64
+ }
65
+ }
66
+ return '';
67
+ }
68
+
69
+ const isReady=()=>{
70
+ return types!==null;
71
+ }
72
+ const reload=()=>{
73
+ if(defaultTypes)return;
74
+ init();
75
+ }
76
+ const getList=()=>{
77
+ let ret=[]
78
+ for(let i=0;i<types.length;i++){
79
+ let item = types[i];
80
+ ret.push({
81
+ label:item[titleKey],
82
+ value:item[idKey],
83
+ key:item[keyName]
84
+ })
85
+ }
86
+ return ret;
87
+ }
88
+
89
+
90
+ return {types,getTitle,getId,isReady,reload,getData,getList}
91
+ }
92
+ }
93
+
94
+ export const useUserType = bookCreater({
95
+ service:GET_USER_TYPE,
96
+ })
97
+ export const useTaskState=bookCreater({
98
+ defaultTypes:[
99
+ {label:'进行中',value:'1',key:'run'},
100
+ {label:'已完成',value:'5',key:'complete'},
101
+ ]
102
+ });
103
+
@@ -0,0 +1,18 @@
1
+
2
+
3
+ import useImageLoader from './useImageLoader';
4
+ import useDelay from './useDelay';
5
+ import usePreload from './usePreload';
6
+ import useSearch from './useSearch';
7
+ import useUpdate from './useUpdate';
8
+ import useNextPage from './useNextPage';
9
+ import useLoading from './useLoading';
10
+ export {
11
+ useImageLoader,
12
+ useDelay,
13
+ usePreload,
14
+ useSearch,
15
+ useUpdate,
16
+ useNextPage,
17
+ useLoading
18
+ }
@@ -0,0 +1,29 @@
1
+ import { useRef,useState,useMemo, useEffect } from 'react';
2
+
3
+ const useDelay=()=>{
4
+ const [loading,setLoading] = useState(false);
5
+ const refSet = useRef();
6
+ refSet.current = setLoading;
7
+ useEffect(()=>{
8
+ refSet.current = setLoading;
9
+ },[setLoading]);
10
+
11
+ const actions=useMemo(()=>{
12
+ const wait=(ms)=>{
13
+ refSet.current(true);
14
+ return new Promise(res=>{
15
+ setTimeout(()=>{
16
+ refSet.current(false);
17
+ res();
18
+ }, ms);
19
+ })
20
+ }
21
+ return {
22
+ wait,
23
+ loading
24
+ };
25
+ },[loading]);
26
+ return actions;
27
+ }
28
+
29
+ export default useDelay;
@@ -0,0 +1,27 @@
1
+ import React, { useEffect,useState,useMemo } from 'react';
2
+
3
+
4
+
5
+ const useImageLoader=(img_src)=>{
6
+ const [src,setSrc] = useState('');
7
+ useEffect(() => {
8
+ if(img_src===src)return;
9
+ if(!img_src)return;
10
+ let img = new Image();
11
+ img.onload = () => {
12
+ setSrc(img_src);
13
+ };
14
+ img.onerror = () => {
15
+ setSrc('');
16
+ console.log(`图片加载失败:${img_src}`)
17
+ };
18
+ img.src = img_src;
19
+ }, [img_src]);
20
+
21
+ const actions=useMemo(()=>{
22
+ return src;
23
+ },[src]);
24
+ return actions;
25
+ }
26
+
27
+ export default useImageLoader;
@@ -0,0 +1,42 @@
1
+ import { useRef,useState, useEffect } from 'react';
2
+ import {ShowPageLoading} from '@/components/Page/PageLoading';
3
+
4
+ const useLoading=(props={})=>{
5
+ const {canTouch=false} = props;
6
+ const [name] = useState(props?.name||'loading')
7
+ const [count,setCount] = useState(props?.loading?1:0);
8
+ const refPageLoading = useRef();
9
+
10
+ const setLoading=(state)=>{
11
+ if(state){
12
+ setCount(v=>v+1);
13
+ }else{
14
+ setCount(v=>v-1);
15
+ }
16
+ }
17
+ const reset=()=>{
18
+ setCount(v=>0);
19
+ }
20
+ useEffect(()=>{
21
+ if(count > 0 ){
22
+ if(!refPageLoading.current){
23
+ refPageLoading.current = ShowPageLoading({canTouch:canTouch});
24
+ }
25
+ }else{
26
+ if(refPageLoading.current){
27
+ refPageLoading.current();//销毁
28
+ refPageLoading.current=null;
29
+ }
30
+ }
31
+ },[count])
32
+
33
+
34
+ return {
35
+ name,
36
+ reset,
37
+ setLoading,
38
+ loading:count
39
+ }
40
+ }
41
+
42
+ export default useLoading;
@@ -0,0 +1,33 @@
1
+
2
+
3
+ import React, { useEffect, useState, useRef } from 'react';
4
+ import {IS_LOGIN,SET_TOKEN,LOGIN} from '@/services/wish';
5
+ import ShowLogin from '@/pages/components/dialog/alert/login';
6
+
7
+
8
+ const useLogin=(props)=>{
9
+ const [isLogin,setLogin] = useState(IS_LOGIN());
10
+
11
+ const login=async ()=>{
12
+ if(IS_LOGIN()){
13
+ setLogin(true);
14
+ return true;
15
+ }else{
16
+ setLogin(false);
17
+ const phone = await ShowLogin();
18
+ if(phone){
19
+ const loginReq = await LOGIN({phone});
20
+ if(loginReq?.code==0){
21
+ SET_TOKEN(loginReq.data.api_token);
22
+ setLogin(IS_LOGIN());
23
+ return true;
24
+ }
25
+ }
26
+ }
27
+ return false;
28
+ }
29
+
30
+ return {login,isLogin}
31
+ }
32
+
33
+ export default useLogin;
@@ -0,0 +1,89 @@
1
+ import { useState,useRef } from 'react';
2
+
3
+
4
+ const DEFAULT_PAGE_SIZE=20;
5
+ const DEFAULT_PAGE_CURRENT=1;
6
+
7
+ const useNextPage=(props)=>{
8
+ const [search,setSearch] = useState(props.initSearch||{});
9
+ const [service] = useState(()=>props.service);
10
+ const [beforeService] = useState(()=>props.beforeService);
11
+ const [pagination,setPagination] = useState(()=>{
12
+ let temp = {
13
+ current:DEFAULT_PAGE_CURRENT,
14
+ pageSize:DEFAULT_PAGE_SIZE,
15
+ total:0,
16
+ startIdx:0,
17
+ more:false,
18
+ ...props.pagination
19
+ };
20
+ temp.startIdx = (temp.current-1)*temp.pageSize;
21
+ return temp;
22
+ });
23
+ const resetCount = useRef(0);
24
+ const [data,setData] = useState([]);
25
+
26
+ const reset= async ()=>{
27
+ resetCount.current++;
28
+ let page = {...pagination};
29
+ page.current =1;
30
+ return refresh({pageValue:page})
31
+ }
32
+ const nextPage= async ()=>{
33
+ if(!pagination.more){
34
+ return false;
35
+ }
36
+ let page = {...pagination};
37
+ page.current= +page.current+1;
38
+ return refresh({pageValue:page})
39
+ }
40
+ const refresh= async ({searchValue,pageValue}={})=>{
41
+ searchValue = searchValue || search;
42
+ pageValue = pageValue || pagination;
43
+ searchValue = {...search,...searchValue};
44
+ pageValue = {...pagination,...pageValue};
45
+
46
+ const {current,pageSize} = pageValue;
47
+ let params = {...searchValue,current:current,pageSize:pageSize};
48
+ if(beforeService)params=beforeService(params);
49
+ if(!params)return;
50
+
51
+ setSearch(searchValue);
52
+
53
+ let ret = await service(params);
54
+ if(ret?.code==0){
55
+ const {page} = ret.data;
56
+ const current= +(page.pageNum||DEFAULT_PAGE_CURRENT);
57
+ const pageSize= +(page.pageSize||DEFAULT_PAGE_SIZE);
58
+ const total= +page.total;
59
+ const startIdx= (current-1)*pageSize;
60
+ const more = current*pageSize<total;
61
+ setPagination({
62
+ current,pageSize,total,startIdx,more
63
+ })
64
+ if(ret.data.list){
65
+ ret.data.list.map(item=>{
66
+ item.resetCount = resetCount.current;
67
+ })
68
+ let newData = current==1?[]:data;
69
+ newData[current-1] = ret.data.list;
70
+ setData([...newData])
71
+ }
72
+ }
73
+ return ret;
74
+ }
75
+
76
+
77
+ return {
78
+ pagination,
79
+ search,
80
+ setSearch,
81
+ refresh,
82
+ reset,
83
+ nextPage,
84
+ data,
85
+ };
86
+
87
+ }
88
+
89
+ export default useNextPage;
@@ -0,0 +1,66 @@
1
+ import React, { useEffect,useState,useMemo,useRef,useCallback } from 'react';
2
+
3
+ const usePreload=(files)=>{
4
+ const [list] = useState(files);
5
+ const [count,setCount] = useState(files.length);
6
+ const [state,setState]=useState('');
7
+
8
+ const load=useCallback((options)=>{
9
+ return new Promise(resolve=>{
10
+ if(count <= 0 ){
11
+ resolve(true);
12
+ return;
13
+ }
14
+ if(state=='loading'){
15
+ resolve(false);
16
+ return;
17
+ }
18
+ setState('loading');
19
+ let per = files.length;
20
+ list.forEach((item, idx) => {
21
+ if (typeof item === 'string') {
22
+ let img = new Image();
23
+ img.onload = () => {
24
+ console.log('加载成功')
25
+ per--;
26
+ if(per<=0){
27
+ setCount(0);
28
+ if(options?.delay){
29
+ setTimeout(resolve, options.delay);
30
+ return;
31
+ }
32
+ resolve(true);
33
+ }
34
+ };
35
+ img.onerror = () => {
36
+ per--;
37
+ if(per<=0){
38
+ setCount(0);
39
+ resolve(true);
40
+ }
41
+ console.log(`图片预加载失败`,item);
42
+ };
43
+ img.src = item;
44
+ } else {
45
+ console.log(`图片预加载失败异常图片`,item);
46
+ per--;
47
+ if(per<=0){
48
+ setCount(0);
49
+ resolve(true);
50
+ }
51
+ }
52
+ });
53
+ })
54
+
55
+ },[state,setState,count]);
56
+
57
+ const actions=useMemo(()=>{
58
+ return {
59
+ count,
60
+ load,
61
+ };
62
+ },[count]);
63
+ return actions;
64
+ }
65
+
66
+ export default usePreload;
@@ -0,0 +1,32 @@
1
+ import { useState, useMemo, useEffect } from 'react'
2
+ import { createContainer } from 'unstated-next'
3
+
4
+ const useActivity = () => {
5
+ const [scrollTop, setScrollTop] = useState(0);
6
+ const [containerNode, setContainerNode] = useState();
7
+ const [clientHeight, setClientHeight] = useState(0);
8
+ const [titleRefs, setTitleRefs] = useState({});
9
+
10
+ useEffect(() => {
11
+ const node = document.getElementById('main-view');
12
+ setContainerNode(node);
13
+ setClientHeight(node.clientHeight)
14
+ node.addEventListener('scroll', (e) => {
15
+ setScrollTop(e.target.scrollTop);
16
+ })
17
+ }, [])
18
+
19
+ const action = useMemo(() => {
20
+ return {
21
+ scrollTop,
22
+ clientHeight,
23
+ titleRefs,
24
+ setTitleRefs,
25
+ containerNode,
26
+ setContainerNode,
27
+ }
28
+ }, [scrollTop, setScrollTop, clientHeight, titleRefs, setTitleRefs, containerNode, setContainerNode])
29
+ return action
30
+ }
31
+ const Activity = createContainer(useActivity);
32
+ export default Activity;
@@ -0,0 +1,137 @@
1
+ import { useRef,useState,useMemo, useEffect } from 'react';
2
+
3
+ /**
4
+ * 管理表格数据的查询搜索及分页
5
+ */
6
+ const useSearch=(props)=>{
7
+ const [search,setSearch] = useState(props.initSearch||{});
8
+ const [service] = useState(()=>props.service);
9
+ const [beforeSearch] = useState(()=>props.beforeSearch);
10
+ const [beforeService] = useState(()=>props.beforeService);
11
+
12
+ const [pagination,setPagination] = useState(()=>{
13
+ let temp = {current:1,pageSize:10,total:0,startIdx:0,...props.pagination};
14
+ temp.startIdx = (temp.current-1)*temp.pageSize;
15
+ return temp;
16
+ });
17
+ const [updateData] = useState(()=>props.updateData);
18
+ const [orderInfo,setOrderInfo]=useState({});
19
+
20
+ const onPaginationChange=async (pageInfo,sorterInfo)=>{
21
+ let {current,pageSize} = pagination;
22
+ let orderValue=orderInfo;
23
+ if(pageInfo){
24
+ current = pageInfo.current;
25
+ pageSize = pageInfo.pageSize;
26
+ }
27
+
28
+ if(sorterInfo){
29
+ const {field,order}= sorterInfo;
30
+ if(field){
31
+ if(order){
32
+ orderInfo[field] = order;
33
+ }else{
34
+ delete orderInfo[field];
35
+ }
36
+ }
37
+ orderValue = orderInfo;
38
+ setOrderInfo({...orderInfo});
39
+ }
40
+
41
+
42
+ let searchValue = await getSearchValue();
43
+ refresh({
44
+ searchValue,
45
+ pageValue:{pageSize,current},
46
+ orderValue});
47
+ }
48
+
49
+ const onSorter=async (sorter)=>{
50
+ const {field,order}= sorter;
51
+ if(field){
52
+ if(order){
53
+ orderInfo[field] = order;
54
+ }else{
55
+ delete orderInfo[field];
56
+ }
57
+ }
58
+ setOrderInfo({...orderInfo});
59
+ console.log(`${JSON.stringify(orderInfo)}`);
60
+ refresh();
61
+
62
+
63
+
64
+ }
65
+
66
+ const getSearchValue=async ()=>{
67
+ let value={};
68
+ value = search;
69
+
70
+ if(beforeSearch){
71
+ value = beforeSearch(value);
72
+ }
73
+ return value;
74
+
75
+ }
76
+ const btnSearch=async ()=>{
77
+ let value = await getSearchValue();
78
+ if(value){
79
+ refresh({searchValue:value});
80
+ }
81
+ }
82
+ const btnReset=()=>{
83
+ formRef.resetFields();
84
+ }
85
+
86
+ const refresh= async ({searchValue,pageValue,orderValue}={})=>{
87
+ searchValue = searchValue || search;
88
+ pageValue = pageValue || pagination;
89
+
90
+ // 排序暂无
91
+ // orderValue = orderValue || orderInfo;
92
+ // let order=[];
93
+ // if(orderValue){
94
+ // Object.keys(orderValue).map(name=>{
95
+ // if(orderValue[name]==='ascend'){
96
+ // order.push(`${name}`);
97
+ // }else if(orderValue[name]==='descend'){
98
+ // order.push(`-${name}`);
99
+ // }
100
+ // })
101
+ // }
102
+
103
+ let {current,pageSize} = pageValue;
104
+ let params = {...searchValue,page:current,pageSize:pageSize};
105
+ if(beforeService)params=beforeService(params);
106
+ if(!params)return;
107
+ let ret = await service(params);
108
+ if(ret?.code==0){
109
+ const {page} = ret.data;
110
+ setPagination({
111
+ current:page.pageNum||1,
112
+ pageSize:page.pageSize||10,
113
+ total:page.total,
114
+ startIdx:(page.page-1)*page.pageSize
115
+ })
116
+ }
117
+
118
+ if(updateData)updateData(ret);
119
+ return ret;
120
+ }
121
+
122
+
123
+ return {
124
+ onPaginationChange,
125
+ pagination,
126
+ btnSearch,
127
+ search,
128
+ setSearch,
129
+ refresh,
130
+ btnReset,
131
+ onSorter
132
+
133
+ };
134
+
135
+ }
136
+
137
+ export default useSearch;
@@ -0,0 +1,11 @@
1
+ import { useState, useMemo } from 'react';
2
+
3
+ const useUpdate=()=>{
4
+ const [count,setCount] = useState(1);
5
+ const action = useMemo(()=>{
6
+ return [count,()=>{setCount(count+1)}]
7
+ },[count,setCount])
8
+ return action;
9
+ }
10
+
11
+ export default useUpdate;