kn-cli 1.0.64 → 1.0.65

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 (129) hide show
  1. package/package.json +2 -1
  2. package/readme.md +3 -0
  3. package/src/create.js +2 -0
  4. package/templates/template_oa/public/src/components/IFrame/index.jsx +3 -0
  5. package/templates/template_oa/webpack.api.js +7 -3
  6. package/templates/template_oa_jwt/.gitignore +6 -0
  7. package/templates/template_oa_jwt/build.sh +7 -0
  8. package/templates/template_oa_jwt/cli.config.js +30 -0
  9. package/templates/template_oa_jwt/dev.sh +89 -0
  10. package/templates/template_oa_jwt/frontend_build.sh +88 -0
  11. package/templates/template_oa_jwt/init/prepare-commit-msg +5 -0
  12. package/templates/template_oa_jwt/init.sh +33 -0
  13. package/templates/template_oa_jwt/jsconfig.json +10 -0
  14. package/templates/template_oa_jwt/package.json +25 -0
  15. package/templates/template_oa_jwt/public/404.html +26 -0
  16. package/templates/template_oa_jwt/public/favicon.ico +0 -0
  17. package/templates/template_oa_jwt/public/index.html +44 -0
  18. package/templates/template_oa_jwt/public/src/_antd.less +216 -0
  19. package/templates/template_oa_jwt/public/src/_reset.less +134 -0
  20. package/templates/template_oa_jwt/public/src/_variable.less +84 -0
  21. package/templates/template_oa_jwt/public/src/assets/iconfont/iconfont.eot +0 -0
  22. package/templates/template_oa_jwt/public/src/assets/iconfont/iconfont.less +57 -0
  23. package/templates/template_oa_jwt/public/src/assets/iconfont/iconfont.svg +36 -0
  24. package/templates/template_oa_jwt/public/src/assets/iconfont/iconfont.ttf +0 -0
  25. package/templates/template_oa_jwt/public/src/assets/iconfont/iconfont.woff +0 -0
  26. package/templates/template_oa_jwt/public/src/assets/iconfont/iconfont.woff2 +0 -0
  27. package/templates/template_oa_jwt/public/src/assets/images/NY-pop-bg.png +0 -0
  28. package/templates/template_oa_jwt/public/src/assets/images/avatar.png +0 -0
  29. package/templates/template_oa_jwt/public/src/assets/images/loading.svg +40 -0
  30. package/templates/template_oa_jwt/public/src/components/Alert/index.jsx +0 -0
  31. package/templates/template_oa_jwt/public/src/components/Alert/index.less +0 -0
  32. package/templates/template_oa_jwt/public/src/components/Auth/index.jsx +44 -0
  33. package/templates/template_oa_jwt/public/src/components/Dialog/index.jsx +150 -0
  34. package/templates/template_oa_jwt/public/src/components/Dialog/index.less +123 -0
  35. package/templates/template_oa_jwt/public/src/components/Empty/index.jsx +23 -0
  36. package/templates/template_oa_jwt/public/src/components/Empty/index.less +6 -0
  37. package/templates/template_oa_jwt/public/src/components/Footer/index.jsx +17 -0
  38. package/templates/template_oa_jwt/public/src/components/Footer/index.less +28 -0
  39. package/templates/template_oa_jwt/public/src/components/FormRow/index.jsx +39 -0
  40. package/templates/template_oa_jwt/public/src/components/FormRow/index.less +67 -0
  41. package/templates/template_oa_jwt/public/src/components/FormTable/index.jsx +137 -0
  42. package/templates/template_oa_jwt/public/src/components/FormTable/index.less +18 -0
  43. package/templates/template_oa_jwt/public/src/components/IFrame/index.jsx +44 -0
  44. package/templates/template_oa_jwt/public/src/components/IFrame/index.less +4 -0
  45. package/templates/template_oa_jwt/public/src/components/IconFont/index.jsx +10 -0
  46. package/templates/template_oa_jwt/public/src/components/IconFont/index.less +5 -0
  47. package/templates/template_oa_jwt/public/src/components/Layout/Basic/index.jsx +52 -0
  48. package/templates/template_oa_jwt/public/src/components/Layout/Basic/index.less +82 -0
  49. package/templates/template_oa_jwt/public/src/components/Layout/CenterBody/index.jsx +15 -0
  50. package/templates/template_oa_jwt/public/src/components/Layout/CenterBody/index.less +36 -0
  51. package/templates/template_oa_jwt/public/src/components/Layout/FormBlock/index.jsx +23 -0
  52. package/templates/template_oa_jwt/public/src/components/Layout/FormBlock/index.less +37 -0
  53. package/templates/template_oa_jwt/public/src/components/Layout/Provider/index.jsx +12 -0
  54. package/templates/template_oa_jwt/public/src/components/Layout/index.jsx +27 -0
  55. package/templates/template_oa_jwt/public/src/components/Layout/index.less +8 -0
  56. package/templates/template_oa_jwt/public/src/components/Link/index.jsx +24 -0
  57. package/templates/template_oa_jwt/public/src/components/Link/index.less +11 -0
  58. package/templates/template_oa_jwt/public/src/components/Loading/index.jsx +16 -0
  59. package/templates/template_oa_jwt/public/src/components/Loading/index.less +96 -0
  60. package/templates/template_oa_jwt/public/src/components/Nav/index.jsx +184 -0
  61. package/templates/template_oa_jwt/public/src/components/Nav/index.less +38 -0
  62. package/templates/template_oa_jwt/public/src/components/Page/PageLoading/index.jsx +30 -0
  63. package/templates/template_oa_jwt/public/src/components/Page/PageLoading/index.less +29 -0
  64. package/templates/template_oa_jwt/public/src/components/Popup/index.jsx +22 -0
  65. package/templates/template_oa_jwt/public/src/components/Popup/index.less +18 -0
  66. package/templates/template_oa_jwt/public/src/components/Select/DepSelect/index.jsx +47 -0
  67. package/templates/template_oa_jwt/public/src/components/Select/StaffSelect/index.jsx +97 -0
  68. package/templates/template_oa_jwt/public/src/components/Select/StaffSelect/index.less +24 -0
  69. package/templates/template_oa_jwt/public/src/components/Toast/index.jsx +60 -0
  70. package/templates/template_oa_jwt/public/src/components/Toast/index.less +43 -0
  71. package/templates/template_oa_jwt/public/src/components/Upload/index.jsx +358 -0
  72. package/templates/template_oa_jwt/public/src/components/title/index.jsx +12 -0
  73. package/templates/template_oa_jwt/public/src/components/title/index.less +21 -0
  74. package/templates/template_oa_jwt/public/src/dictionary/index.js +20 -0
  75. package/templates/template_oa_jwt/public/src/hooks/index.jsx +21 -0
  76. package/templates/template_oa_jwt/public/src/hooks/useDelay.jsx +29 -0
  77. package/templates/template_oa_jwt/public/src/hooks/useImageLoader.jsx +27 -0
  78. package/templates/template_oa_jwt/public/src/hooks/useLoading.jsx +42 -0
  79. package/templates/template_oa_jwt/public/src/hooks/useLogin.jsx +33 -0
  80. package/templates/template_oa_jwt/public/src/hooks/usePreload.jsx +66 -0
  81. package/templates/template_oa_jwt/public/src/hooks/useScrollTop.jsx +32 -0
  82. package/templates/template_oa_jwt/public/src/hooks/useSearch.jsx +137 -0
  83. package/templates/template_oa_jwt/public/src/hooks/useUpdate.jsx +11 -0
  84. package/templates/template_oa_jwt/public/src/index.jsx +50 -0
  85. package/templates/template_oa_jwt/public/src/mock/common.js +484 -0
  86. package/templates/template_oa_jwt/public/src/mock/index.js +63 -0
  87. package/templates/template_oa_jwt/public/src/mock/user.js +70 -0
  88. package/templates/template_oa_jwt/public/src/mock/utils.js +33 -0
  89. package/templates/template_oa_jwt/public/src/pages/components/pageTitle/index.jsx +13 -0
  90. package/templates/template_oa_jwt/public/src/pages/components/pageTitle/index.less +20 -0
  91. package/templates/template_oa_jwt/public/src/pages/components/totalRecord/index.jsx +21 -0
  92. package/templates/template_oa_jwt/public/src/pages/components/totalRecord/index.less +16 -0
  93. package/templates/template_oa_jwt/public/src/pages/demo/detail/index.jsx +14 -0
  94. package/templates/template_oa_jwt/public/src/pages/demo/index.jsx +399 -0
  95. package/templates/template_oa_jwt/public/src/pages/demo/index.less +15 -0
  96. package/templates/template_oa_jwt/public/src/pages/login/index.jsx +29 -0
  97. package/templates/template_oa_jwt/public/src/pages/login/index.less +44 -0
  98. package/templates/template_oa_jwt/public/src/pages/redirect/index.jsx +31 -0
  99. package/templates/template_oa_jwt/public/src/provider/app.jsx +66 -0
  100. package/templates/template_oa_jwt/public/src/route.jsx +45 -0
  101. package/templates/template_oa_jwt/public/src/services/common.js +133 -0
  102. package/templates/template_oa_jwt/public/src/services/demo.js +41 -0
  103. package/templates/template_oa_jwt/public/src/services/index.js +266 -0
  104. package/templates/template_oa_jwt/public/src/services/token.js +132 -0
  105. package/templates/template_oa_jwt/public/src/utils/index.js +115 -0
  106. package/templates/template_oa_jwt/public/static/about.html +1 -0
  107. package/templates/template_oa_jwt/public/static/kssoLogin.html +22 -0
  108. package/templates/template_oa_jwt/public/static/noAuth.html +217 -0
  109. package/templates/template_oa_jwt/public/static/noAuth.png +0 -0
  110. package/templates/template_oa_jwt/readme.md +71 -0
  111. package/templates/template_oa_jwt/report.sh +68 -0
  112. package/templates/template_oa_jwt/tools/iconfont/gulpfile.js +70 -0
  113. package/templates/template_oa_jwt/tools/iconfont/package.json +20 -0
  114. package/templates/template_oa_jwt/tools/iconfont/run.sh +39 -0
  115. package/templates/template_oa_jwt/tools/iconfont/svg/arrowBack.svg +1 -0
  116. package/templates/template_oa_jwt/tools/iconfont/svg/check.svg +1 -0
  117. package/templates/template_oa_jwt/tools/iconfont/svg/close.svg +1 -0
  118. package/templates/template_oa_jwt/tools/iconfont/svg/down.svg +1 -0
  119. package/templates/template_oa_jwt/tools/iconfont/svg/image.svg +1 -0
  120. package/templates/template_oa_jwt/tools/iconfont/svg/play.svg +1 -0
  121. package/templates/template_oa_jwt/tools/iconfont/svg/refresh.svg +1 -0
  122. package/templates/template_oa_jwt/tools/iconfont/svg/warn.svg +1 -0
  123. package/templates/template_oa_jwt/tools/iconfont/templates/_icons.css +26 -0
  124. package/templates/template_oa_jwt/tools/iconfont/templates/_icons.less +29 -0
  125. package/templates/template_oa_jwt/tools/iconfont/templates/index.html +56 -0
  126. package/templates/template_oa_jwt/tools/tinypng/package.json +11 -0
  127. package/templates/template_oa_jwt/tools/tinypng/run.sh +15 -0
  128. package/templates/template_oa_jwt/versionPublish.sh +27 -0
  129. package/templates/template_oa_jwt/webpack.api.js +61 -0
@@ -0,0 +1,97 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { Select } from 'antd';
3
+ import CSS from './index.less';
4
+ CSS;
5
+ const StaffSelect = (props) => {
6
+ const [userList, setUserList] = useState(props.userList || null);
7
+ const [value, setValue] = useState(props?.defaultValue || []);
8
+
9
+ function checkUserCanFind(value, name) {
10
+ let find = false;
11
+ for (let i = 0; i < userList.length; i++) {
12
+ if (userList[i].USR_UID === value) {
13
+ find = true;
14
+ break;
15
+ }
16
+ }
17
+ if (!find) {
18
+ console.log(`未发现用户${value}${name}`);
19
+ let list = [...userList];
20
+ list.push({
21
+ USR_UID: value,
22
+ USR_CN: name,
23
+ REAL_NAME:name,
24
+ USR_JOB_ID: '',
25
+ });
26
+ setUserList(list);
27
+ }
28
+ }
29
+
30
+ useEffect(() => {
31
+ if (props?.value) {
32
+ setValue(props.value);
33
+
34
+ // 如果某些员工因为离职,数据不在了,那么这里补上一条
35
+ if (props.ifnofound) {
36
+ if (props.value.constructor === Array) {
37
+ for (let i = 0; i < props.value.length; i++) {
38
+ checkUserCanFind(props.value[i], props.ifnofound[i]);
39
+ }
40
+ } else {
41
+ checkUserCanFind(props.value, props.ifnofound);
42
+ }
43
+ }
44
+ }
45
+ }, [value]);
46
+
47
+ function onChange(options, selected) {
48
+ setValue(options);
49
+ let ret = [];
50
+ if (selected?.map) {
51
+ ret = selected.map((item) => {
52
+ return item.data;
53
+ });
54
+ } else {
55
+ if (selected.data) {
56
+ ret.push(selected.data);
57
+ }
58
+ }
59
+ if (props.onChange) props.onChange(options,ret);
60
+ }
61
+
62
+ function filterOption(inputValue, option) {
63
+ if (
64
+ (option.data.REAL_NAME && option.data.REAL_NAME.includes(inputValue)) ||
65
+ (option.data.USR_JOB_ID && option.data.USR_JOB_ID.includes(inputValue)) ||
66
+ (option.data.USR_USERNAME && option.data.USR_USERNAME.includes(inputValue))
67
+ ) {
68
+ return true;
69
+ }
70
+
71
+ return false;
72
+ }
73
+
74
+ return (
75
+ <Select
76
+ loading={!userList}
77
+ // labelInValue
78
+ optionLabelProp='label'
79
+ value={value}
80
+ showSearch
81
+ mode={props.mode}
82
+ style={{ width: '100%' }}
83
+ onChange={onChange}
84
+ filterOption={filterOption}
85
+ >
86
+ {userList &&
87
+ userList.map((user, idx) => {
88
+ return (
89
+ <Select.Option key={user.USR_UID} data={user} value={props.valIsLabel ? `${user.REAL_NAME}(${user.USR_JOB_ID})` : user.USR_UID} label={`${user.REAL_NAME}(${user.USR_JOB_ID})`}>
90
+ {`${user.REAL_NAME}(${user.USR_JOB_ID})`}
91
+ </Select.Option>
92
+ );
93
+ })}
94
+ </Select>
95
+ );
96
+ };
97
+ export default StaffSelect;
@@ -0,0 +1,24 @@
1
+ .content {
2
+ position: fixed;
3
+ bottom: 0;
4
+ left: 0;
5
+ width: 100%;
6
+ height: 120px;
7
+ background: #fafafa;
8
+ z-index: 10;
9
+ box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.2);
10
+
11
+ :global {
12
+ .ant-col {
13
+ button {
14
+ margin-left: 10px;
15
+ border: 1px solid #d8d8d8;
16
+ }
17
+ &:first-child {
18
+ button {
19
+ margin-left: 0;
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,60 @@
1
+ import React,{useEffect} from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import styles from './index.less';
4
+ import Popup from '@/components/Popup/index.jsx';
5
+
6
+ const toastList=[];
7
+ const runNext=()=>{
8
+ let props = toastList[0];
9
+ if(props){
10
+ const {message,delay,resolve,position}=props;
11
+ let popup = Popup(resolve,{cantouch:true});
12
+ ReactDOM.render(
13
+ <Toast destory={popup.destory} message={message} delay={delay} position={position}/>,
14
+ popup.dom
15
+ );
16
+ }
17
+ }
18
+
19
+ const Toast=props=>{
20
+ const {
21
+ message,
22
+ delay=1000*2,
23
+ destory,
24
+ position='top'
25
+ }=props;
26
+ useEffect(()=>{
27
+ setTimeout(()=>{
28
+ destory();
29
+ toastList.shift();
30
+ runNext();
31
+ },delay);
32
+ },[])
33
+ const ANITYPE={
34
+ 'center':'animate__slideInDown',
35
+ 'top':'animate__slideInDown',
36
+ 'bottom':'animate__slideInUp'
37
+ }
38
+ return (
39
+ <section className={styles.wrap} data-position={position}>
40
+ <div className={styles.content+ ` ${ANITYPE[position]} animate__animated animate__fast`} dangerouslySetInnerHTML={{ __html:message }}>
41
+ </div>
42
+ </section>
43
+ )
44
+ }
45
+
46
+
47
+ const ShowToast=props=>{
48
+ if(typeof props === 'string'){
49
+ props = {message:props}
50
+ }
51
+ return new Promise((resolve) => {
52
+ props.resolve = resolve;
53
+ toastList.push(props);
54
+ if(toastList.length===1){
55
+ runNext();
56
+ }
57
+ });
58
+ }
59
+
60
+ export default ShowToast;
@@ -0,0 +1,43 @@
1
+ @import '~@/_variable.less';
2
+
3
+ .wrap{
4
+ position: fixed;
5
+ left:0;
6
+ top:0;
7
+ width:100%;
8
+ height:100%;
9
+ pointer-events: none;
10
+ display: flex;
11
+ justify-content: center;
12
+ align-items: center;
13
+ flex-direction: column;
14
+ z-index:var(--z-toast);
15
+ &[data-position=top]{
16
+ justify-content: flex-start;
17
+ padding-top:80px;
18
+ }
19
+ &[data-position=bottom]{
20
+ justify-content: flex-end;
21
+ padding-bottom:80px;
22
+ }
23
+ .content{
24
+ min-height:30px;
25
+ min-width:60px;
26
+
27
+ background: rgba(0,0,0,.8);
28
+ opacity:.8;
29
+ border-radius: var(--radius-default);
30
+ padding:var(--padding-small) var(--padding-default);
31
+
32
+ display: flex;
33
+ flex-direction: column;
34
+ justify-content: center;
35
+ align-items: center;
36
+
37
+ font-size: 14px;
38
+ color: #FFFFFF;
39
+ text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.24);
40
+
41
+
42
+ }
43
+ }
@@ -0,0 +1,358 @@
1
+ import React, { useState,useEffect } from 'react';
2
+ import { Upload, message,Button } from 'antd';
3
+ import { UPLOAD_FILE,GET_DOWNLOAD_FILE } from "@/services/common.js";
4
+ // import {getUploadToken,setMediaInfo} from '@/services/common.js';
5
+ // import COS from 'cos-js-sdk-v5';
6
+
7
+ import { UploadOutlined } from '@ant-design/icons';
8
+
9
+
10
+ function DELAY(time){
11
+ return new Promise(reslove=>{
12
+ setTimeout(reslove,time);
13
+ })
14
+ }
15
+
16
+ // export async function uploadToCos(files,onProgress,params){
17
+ // if(params&&params.userId){
18
+ // params.type=1;
19
+ // }
20
+ // let token = await getUploadToken(params);
21
+ // let key = token?.data?.fileKey||Date.now();
22
+ // let baseUrl = token?.data?.baseUrl;
23
+ // let credentials={};
24
+ // let data={};
25
+
26
+ // if(+token?.code===0){
27
+ // credentials = token.data.credentials;
28
+ // data=token.data;
29
+ // }
30
+
31
+
32
+ // var cos = new COS({
33
+ // getAuthorization:(options,callback)=>{
34
+ // callback({
35
+ // TmpSecretId: credentials.tmpSecretId,
36
+ // TmpSecretKey: credentials.tmpSecretKey,
37
+ // XCosSecurityToken: credentials.sessionToken,
38
+ // StartTime: data.startTime,
39
+ // ExpiredTime: data.expiredTime,
40
+ // })
41
+ // }
42
+ // });
43
+
44
+
45
+ // return new Promise(reslove=>{
46
+ // cos.putObject({
47
+ // Bucket:data.bucket,
48
+ // Region:data.region,
49
+ // Key:key,
50
+ // StorageClass: 'STANDARD',
51
+ // Body:files,
52
+ // onProgress: function(progressData) {
53
+ // if(onProgress)onProgress({percent:progressData.percent*100})
54
+ // console.log(JSON.stringify(progressData));
55
+ // }
56
+ // },function(err, data) {
57
+ // if(data){
58
+ // reslove({url:`${baseUrl}/${key}`,key:key});
59
+ // return;
60
+ // }
61
+ // reslove()
62
+ // })
63
+ // })
64
+
65
+
66
+
67
+ // }
68
+
69
+ function CHECK_FILE_TYPE(types, filename) {
70
+ let reg = '';
71
+
72
+ if (types.constructor === Array) {
73
+ types = types.join('|');
74
+ }
75
+ reg = `[.](${types})$`;
76
+ reg = new RegExp(reg, 'i');
77
+ return reg.test(filename);
78
+ }
79
+
80
+
81
+ const getImageInfo= async (file)=>{
82
+ return new Promise(resolve=>{
83
+ var reader = new FileReader();
84
+ reader.readAsDataURL(file);
85
+ reader.onload =()=>{
86
+ let img = new Image();
87
+ img.onload=()=>{
88
+ resolve({width:img.width,height:img.height});
89
+ }
90
+ img.src=reader.result;
91
+ }
92
+ })
93
+ }
94
+ const getVideoInfo= async (file)=>{
95
+ return new Promise(resolve=>{
96
+ var reader = new FileReader();
97
+ reader.readAsDataURL(file);
98
+ reader.onload =()=>{
99
+ let video = document.createElement('video');
100
+ video.addEventListener('canplay',(e)=>{
101
+ const {videoWidth,videoHeight} = e.target;
102
+ resolve({width:videoWidth,height:videoHeight});
103
+ })
104
+ video.setAttribute('src',reader.result);
105
+ // document.body.appendChild(img);
106
+ }
107
+ })
108
+ }
109
+ export const uploadFile=async (props,detail)=>{
110
+ // let response = await UPLOAD_FILE(detail.file, {}, detail.onProgress);
111
+ // await DELAY(1000);
112
+ // detail.onProgress({ percent: 20 });
113
+ // await DELAY(1000);
114
+ // detail.onProgress({ percent: 100 });
115
+
116
+ // mock 拦截上传模拟上传完成用
117
+ // let url='';
118
+ // switch(detail.file.type){
119
+ // case 'image/jpeg':
120
+ // case 'image/png':url='https://officialwebsite-static.kingnet.com/20201130132001-%E6%9C%AA%E5%91%BD%E5%90%8D_meitu_1.jpg';break;
121
+ // case 'video/mp4':url="http://yayapt-1254024138.cos.ap-shanghai.myqcloud.com/1607653172352"
122
+ // }
123
+ // let response = { url: url, key: detail.file.uid } ;
124
+
125
+
126
+ let mimeType = detail.file.type;
127
+ let fileName=detail.file.name;
128
+ let type = 1;
129
+ let fileSize = detail.file.size;
130
+ let module=props?.from||'';
131
+ if(/^video/.test(mimeType)){
132
+ type=2;//视频
133
+ }else if(/^image/.test(mimeType)){
134
+ type=1;//图片
135
+ }
136
+
137
+ let info=null;
138
+ // if(props.getWidthHeight){
139
+ if(type===2){
140
+ info =await getVideoInfo(detail.file);
141
+ }else if(type===1){
142
+ info = await getImageInfo(detail.file);
143
+ }
144
+ let uploadServiceType = 'oa';
145
+ // }
146
+ let response;
147
+ if(uploadServiceType==='oa')response = await UPLOAD_FILE(detail.file,null,detail.onProgress);
148
+ // if(uploadServiceType==='cos')response = await uploadToCos(detail.file,detail.onProgress,props.params);
149
+
150
+ if (response) {
151
+ // if(uploadServiceType==='cos'){
152
+ // let infoRet = await setMediaInfo({
153
+ // fileKey:response.key,
154
+ // fileName,
155
+ // mimeType,
156
+ // fileSize,
157
+ // type,
158
+ // module,
159
+ // mediaWidth:info?.width,
160
+ // mediaHeight:info?.height});
161
+ // if(!infoRet){
162
+ // return;
163
+ // }
164
+ // }
165
+ if(detail?.onSuccess){
166
+ detail.onSuccess({
167
+ server_link: response.url,
168
+ client_name:response.key,
169
+ info:info,
170
+ });
171
+ }
172
+ return {
173
+ server_link: response.url,
174
+ client_name:response.key,
175
+ info:info,
176
+ };
177
+
178
+ } else {
179
+ if(detail?.onError){
180
+ detail.onError();
181
+ }
182
+ return;
183
+ }
184
+ }
185
+
186
+
187
+ /**
188
+ *
189
+ * {
190
+ * uid:'',//唯一id,负数为默认文件
191
+ * url:'',//下载链接
192
+ * status:'done',//上传状态
193
+ * name:'1.png',//文件名称
194
+ * formData:{ //存放提交给接口表单用的文件参数
195
+ * server_name:'',
196
+ * cli_name:''
197
+ * }
198
+ * }
199
+ */
200
+ const UploadHelper = (props) => {
201
+ // const [count, setCount] = useState(0);
202
+ // console.log(`upload helper value:${props.value}`)
203
+ const [fileList, setFileList] = useState([]);
204
+ const updateValue=()=>{
205
+
206
+ let defaultFile=[];
207
+ let ret=[];
208
+ if(props.value){
209
+ if(props.value.map){
210
+ defaultFile=[...props.value];
211
+ }else{
212
+ defaultFile.push(props.value);
213
+ }
214
+ }
215
+ else if(props.defaultFile){
216
+ if(props.defaultFile.map){
217
+ defaultFile=[...props.defaultFile];
218
+ }else{
219
+ defaultFile.push(props.defaultFile);
220
+ }
221
+ }
222
+
223
+ if (!defaultFile || defaultFile.length <= 0) {
224
+
225
+ }
226
+ else{
227
+ ret= defaultFile?.map((file, idx) => {
228
+ let client_name,server_link,thumbUrl,info;
229
+ if( typeof file ==='string' ){
230
+ server_link = file;
231
+ client_name = '';
232
+ }else{
233
+ client_name=file.client_name
234
+ server_link=file.server_link;
235
+ thumbUrl=file.thumbUrl;
236
+ info=file.info;
237
+
238
+ }
239
+ return {
240
+ uid: '-' + idx,
241
+ name: client_name,
242
+ url: server_link,
243
+ status: 'done',
244
+ thumbUrl: file.thumbUrl || props.thumbUrl||null,
245
+ formData: {
246
+ server_link: server_link,
247
+ client_name: client_name,
248
+ info:info,
249
+ },
250
+ };
251
+ });
252
+ }
253
+ setFileList(ret);
254
+
255
+ }
256
+
257
+ useEffect(()=>{
258
+ updateValue();
259
+ },[props.value,props.defaultFile])
260
+ function beforeUpload(acceptTypes, file) {
261
+ if (acceptTypes && !CHECK_FILE_TYPE(acceptTypes, file.name)) {
262
+ message.error( `文件类型不正确,仅支持:${acceptTypes.join(';')}` );
263
+ return false;
264
+ }
265
+ if (props.maxSize && file.size / 1024 > props.maxSize) {
266
+ if(props.maxSize>1024){
267
+ message.error( `文件大小不能超过:${props.maxSize/1024}MB` );
268
+ return false;
269
+ }
270
+ message.error( `文件大小不能超过:${props.maxSize}KB` );
271
+ return false;
272
+ }
273
+ return true;
274
+ }
275
+
276
+ function onChangeFile(detail) {
277
+ let fileList = [];
278
+ let changeFlie = [];
279
+ let change = true;
280
+ // console.log(JSON.stringify(detail.fileList));
281
+ detail.fileList.forEach((file) => {
282
+ if (file.status) {
283
+ fileList.push(file);
284
+ if (file.status === 'uploading') {
285
+ change = false;
286
+ }
287
+ if (file.status === 'done' && file.response && !file.formData) {
288
+ file.formData = {
289
+ server_link: file.response.server_link,
290
+ client_name: file.response.client_name,
291
+ info:file.response.info||null,
292
+ };
293
+ file.formData.thumbUrl = GET_DOWNLOAD_FILE(file.formData.server_link)
294
+ }
295
+ if (file.status === 'done' && file.formData) {
296
+ changeFlie.push(file.formData);
297
+ }
298
+ }
299
+ });
300
+ setFileList(fileList);
301
+ if (change) {
302
+ if (props.onChange) props.onChange(changeFlie);
303
+ }
304
+ }
305
+
306
+
307
+ const BtnUpload=()=>{
308
+ let {listType} = props;
309
+
310
+ if(listType==='text' || !listType){
311
+ return (
312
+ <Button icon={<UploadOutlined />}>上传</Button>
313
+ )
314
+ }
315
+ return (
316
+ <div style={{ marginTop: 8 }}>上传图片</div>
317
+ )
318
+ }
319
+ function renderChildren(){
320
+ let {listType,multiple,disabled} = props;
321
+
322
+
323
+ //单图模式,在有文件的情况下不显示上传按钮
324
+ if(!multiple){
325
+ if(fileList.length>0){
326
+ return '';
327
+ }
328
+ }
329
+ if(disabled){
330
+ return '无';
331
+ }
332
+
333
+ return <BtnUpload />;
334
+
335
+ }
336
+ function onPreview(file){
337
+ window.open(GET_DOWNLOAD_FILE(file.formData.server_link));
338
+ }
339
+ return (
340
+ <Upload
341
+ multiple={props.multiple}
342
+ beforeUpload={beforeUpload.bind(this, props.acceptTypes)}
343
+ onChange={onChangeFile}
344
+ customRequest={uploadFile.bind(this,props)}
345
+ disabled={props.disabled}
346
+ fileList={fileList}
347
+ listType={props.listType}
348
+ onPreview={props.onPreview||onPreview}
349
+ showUploadList={props.showUploadList}
350
+ className={props.className}
351
+ // previewFile={onPreview}
352
+ >
353
+ {renderChildren()}
354
+ </Upload>
355
+ );
356
+ };
357
+
358
+ export default UploadHelper;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import CSS from './index.less';
3
+
4
+ const PageTitle = (props) => {
5
+ return (
6
+ <section className={CSS.title}>
7
+ <div className={CSS.rect}></div>
8
+ <h3 className={CSS.text}>{props.children}</h3>
9
+ </section>
10
+ )
11
+ }
12
+ export default PageTitle;
@@ -0,0 +1,21 @@
1
+ @import '~@/_variable.less';
2
+
3
+ .title{
4
+ display: flex;
5
+ align-items: center;
6
+ border-bottom: 1px solid #ddd;
7
+ padding-bottom: var(--margin-small);
8
+ margin-bottom: var(--margin-default);
9
+ }
10
+ .rect {
11
+ background: var(--color-primary);
12
+ margin-right: 7px;
13
+ width: 4px;
14
+ height: 18px;
15
+ display: block;
16
+ }
17
+ .text{
18
+ font-size: 16px;
19
+ color: #555;
20
+ margin: 0;
21
+ }
@@ -0,0 +1,20 @@
1
+ import { useDictionary } from '@/hooks';
2
+ // import { GET_PROJECT } from '@/services/dataset';
3
+ import { Select, Radio } from 'antd';
4
+ useDictionary.SetConfig({ SelectOption: Select.Option, RadioOption: Radio });
5
+
6
+ // export const useProjectList = useDictionary.createDictionary({
7
+ // api: async () => {
8
+ // const req = await GET_PROJECT();
9
+ // if (req?.code == 0) {
10
+ // const list = req.data.map(item => {
11
+ // const { app_id: id, name: label, _id: name } = item;
12
+ // return {
13
+ // id, label, name
14
+ // }
15
+ // });
16
+ // return { code: 0, data: { body: [{ id: '', label: '全部项目', name: 'all' }, ...list] } };
17
+ // }
18
+ // return null;
19
+ // }
20
+ // });
@@ -0,0 +1,21 @@
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 useLoading from './useLoading';
9
+ import {useDictionary, usePagination,usePaginationWithForm} from 'kn-hooks';
10
+
11
+ export {
12
+ useDictionary,
13
+ usePaginationWithForm,
14
+ usePagination,
15
+ useImageLoader,
16
+ useDelay,
17
+ usePreload,
18
+ useSearch,
19
+ useUpdate,
20
+ useLoading
21
+ }
@@ -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;