@cqsjjb/jjb-react-admin-component 3.1.3 → 3.2.0-beta.0

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.
@@ -0,0 +1,57 @@
1
+ // @ts-ignore
2
+ import * as React from 'react';
3
+
4
+ interface EditorProps {
5
+ // 边框 默认-true 如果为false 则不显示边框
6
+ bordered?: boolean;
7
+ // 边框样式 默认-solid
8
+ borderStyle?: string;
9
+ // 边框颜色 默认-#e8e8e8
10
+ borderColor?: string;
11
+ // 边框宽度 默认-1
12
+ borderWidth?: number;
13
+ // 边框圆角 默认-2
14
+ borderRadius?: number;
15
+ // 内容
16
+ value: string;
17
+ // 模式 默认-default
18
+ mode?: 'default' | 'simple';
19
+ // 高度 默认-300px
20
+ height?: number;
21
+ // 是否禁用 默认-false
22
+ disabled?: boolean;
23
+ // 上传地址 默认-${window.process.env.app.API_HOST}/attachment/files/upload-speed-simple
24
+ uploadUrl?: string;
25
+ // 上传文件名 默认-file
26
+ uploadFileName?: string;
27
+ // 图片上传大小 默认-5MB 最大5MB
28
+ uploadImageFileSize?: number;
29
+ // 视频上传大小 默认-50MB 最大50MB
30
+ uploadVideoFileSize?: number;
31
+ // 上传头 默认-{}
32
+ uploadHeaders?: Record<string, string>;
33
+ // 自定义上传 默认-空
34
+ uploadCustomRequest?: (file: File) => Promise<string>;
35
+ // 占位符 默认-“请输入...”
36
+ placeholder?: string;
37
+ // 失去焦点 默认-空
38
+ onBlur?: () => void;
39
+ // 获得焦点 默认-空
40
+ onFocus?: () => void;
41
+ // 内容变化 默认-空
42
+ onChange?: (value: string) => void;
43
+ }
44
+
45
+ interface EditorFC extends React.FC<EditorProps> {
46
+ ref: React.RefObject<{
47
+ // 获取编辑器实例
48
+ getEditorInstance: () => any;
49
+ // 手动获取html
50
+ getHtml: () => string;
51
+ // 手动设置html
52
+ setHtml: (html: string) => void;
53
+ }>;
54
+ }
55
+
56
+ declare const Editor: EditorFC;
57
+ export default Editor;
@@ -1,12 +1,9 @@
1
- // @ts-ignore
2
1
  import * as React from 'react';
3
- import { ComponentProps } from '../types';
4
2
 
5
- interface ErrorBoundaryProps extends ComponentProps {
3
+ interface ErrorBoundaryProps {
4
+ children: React.ReactNode;
6
5
  }
7
6
 
8
- interface ErrorBoundaryFc extends React.FC<ErrorBoundaryProps> {
9
- }
7
+ declare const ErrorBoundary: React.FC<ErrorBoundaryProps>;
10
8
 
11
- declare const ErrorBoundary: ErrorBoundaryFc;
12
9
  export default ErrorBoundary;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Result, Tooltip, Button } from 'antd';
2
+ import { Result } from 'antd';
3
3
  export default class ErrorBoundary extends React.Component {
4
4
  state = {
5
5
  hasError: false,
@@ -17,7 +17,7 @@ export default class ErrorBoundary extends React.Component {
17
17
  if (this.state.hasError) {
18
18
  return /*#__PURE__*/React.createElement(Result, {
19
19
  status: "error",
20
- title: "\u5E94\u7528\u8FD0\u884C\u5F02\u5E38",
20
+ title: "\u62B1\u6B49\uFF0C\u5E94\u7528\u5185\u90E8\u53D1\u751F\u5F02\u5E38\u9519\u8BEF\u3002",
21
21
  subTitle: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", null, this.state.errorInfo), /*#__PURE__*/React.createElement("div", {
22
22
  style: {
23
23
  width: 700,
@@ -27,13 +27,7 @@ export default class ErrorBoundary extends React.Component {
27
27
  textAlign: 'left',
28
28
  whiteSpace: 'pre-line'
29
29
  }
30
- }, this.state.errorStack)),
31
- extra: /*#__PURE__*/React.createElement(Tooltip, {
32
- title: "\u82E5\u5237\u65B0\u4EFB\u7136\u65E0\u6CD5\u89E3\u51B3\uFF0C\u8BF7\u8054\u7CFB\u6280\u672F\u4EBA\u5458\u89E3\u51B3"
33
- }, /*#__PURE__*/React.createElement(Button, {
34
- type: "primary",
35
- onClick: () => window.location.reload()
36
- }, "\u5237\u65B0\u91CD\u8BD5"))
30
+ }, this.state.errorStack))
37
31
  });
38
32
  }
39
33
  return this.props.children;
@@ -0,0 +1,56 @@
1
+ // @ts-ignore
2
+ import * as React from 'react';
3
+ // @ts-ignore
4
+ import { ButtonProps } from 'antd';
5
+ // @ts-ignore
6
+ import { AxiosResponse } from 'axios'
7
+
8
+ export interface FileUploaderProps<T> {
9
+ // 上传文件大小 单位KB 默认-5120
10
+ size?: number;
11
+ // 版本 v1-才俊java v2-杨飞java 默认-v2
12
+ version?: 'v1' | 'v2';
13
+ // 组件内部按钮属性-Ant.Button
14
+ buttonProps?: ButtonProps;
15
+ // Http上传携带其他数据
16
+ data?: Record<string, any>;
17
+ // 输入数据
18
+ value?: T;
19
+ // 限制文件上传类型 参考MIME类型
20
+ accept?: string;
21
+ // 请求接口
22
+ action: string;
23
+ // 预览已上传的资源
24
+ preview?: boolean;
25
+ // 配置请求头
26
+ headers?: Record<string, any>;
27
+ // 最多上传数 multiple 为true 有效 默认-99
28
+ maxCount?: number;
29
+ // 启用文件多选 默认-false
30
+ multiple?: boolean;
31
+ // 启用/禁用 默认-false
32
+ disabled?: boolean;
33
+ // 自定义上传文件字段 默认-file
34
+ fieldName?: string;
35
+ // 显示删除图标 默认-true
36
+ showDelete?: boolean;
37
+ // 自定义请求 覆盖默认请求
38
+ customRequest?: (res: AxiosResponse) => void;
39
+ // 上传前验证文件大小 默认-空
40
+ onBeforeUploadVerifySize?: (fileSize: number, maxSize: number) => Promise<void>;
41
+ // 上传前验证文件类型
42
+ onBeforeUploadVerifyAccept?: (fileType: string, accept: string) => Promise<void>;
43
+ // 输出
44
+ onChange?: (e: T) => void;
45
+ }
46
+
47
+ export interface FileUploaderFC extends React.FC<FileUploaderProps<string | { readonly fileId: string; readonly fileUrl: string; }>> {
48
+ ref?: React.Ref<Record<string, any>>;
49
+ children?: React.ReactNode;
50
+ }
51
+
52
+ declare const FileUploader: FileUploaderFC;
53
+ export default FileUploader;
54
+
55
+ export function getValueProps(value: any): { value: { fileUrl: any } | undefined };
56
+ export function getValueFromEvent(event: any): any;
@@ -0,0 +1,385 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import MD5 from 'spark-md5';
3
+ import React from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import { Tooltip, Button, message } from 'antd';
6
+ import { DeleteOutlined, PaperClipOutlined } from '@ant-design/icons';
7
+ import { getAppKey, getToken, isHttpUrl, isVersion1, isVersion2 } from '../tools/index.js';
8
+ import { tools } from '@cqsjjb/jjb-common-lib';
9
+ import './index.less';
10
+ const {
11
+ toObject,
12
+ isPromise,
13
+ isFunction,
14
+ parseObject
15
+ } = tools;
16
+ const prefixCls = window.process?.env?.app?.antd['ant-prefix'] || 'ant';
17
+ class FileUploader extends React.Component {
18
+ state = {
19
+ loading: false
20
+ };
21
+ inputFile = /*#__PURE__*/React.createRef();
22
+
23
+ /**
24
+ * @description http配置
25
+ * @returns {{headers: object, fieldName: string, data: object, action: string, url: string}}
26
+ */
27
+ get httpConfig() {
28
+ const {
29
+ data,
30
+ action,
31
+ headers,
32
+ fieldName
33
+ } = this.props;
34
+ const {
35
+ API_HOST
36
+ } = window.process.env.app;
37
+ return {
38
+ url: isHttpUrl(action) ? action : `${API_HOST}${action}`,
39
+ data,
40
+ action,
41
+ headers: {
42
+ ...headers,
43
+ token: getToken(),
44
+ appKey: getAppKey()
45
+ },
46
+ fieldName
47
+ };
48
+ }
49
+
50
+ /**
51
+ * @description 填充值
52
+ * @returns {string[]}
53
+ */
54
+ get value() {
55
+ const {
56
+ value
57
+ } = this.props;
58
+ return Array.isArray(value) ? value : value ? [value] : [];
59
+ }
60
+
61
+ /**
62
+ * @description 获取禁用状态
63
+ * @return {boolean}
64
+ */
65
+ get disabled() {
66
+ const {
67
+ multiple,
68
+ maxCount,
69
+ disabled
70
+ } = this.props;
71
+ if (disabled) {
72
+ return disabled;
73
+ }
74
+ if (!multiple && this.value.length) {
75
+ return true;
76
+ }
77
+ if (multiple && this.value.length === maxCount) {
78
+ return true;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * @description 验证文件类型
84
+ * @param fileType {string}
85
+ * @param accept {string}
86
+ * @returns {Promise<never>|Promise<void>}
87
+ */
88
+ verifyFileAccept(fileType, accept) {
89
+ const {
90
+ onBeforeUploadVerifyAccept
91
+ } = this.props;
92
+ if (onBeforeUploadVerifyAccept) {
93
+ const fn = onBeforeUploadVerifyAccept(fileType, accept);
94
+ if (fn instanceof Promise) {
95
+ return fn;
96
+ } else {
97
+ return Promise.reject('onBeforeUploadVerifyAccept 应该返回Promise.');
98
+ }
99
+ } else {
100
+ if (accept !== '*') {
101
+ const acceptSplit = accept.split(',').filter(value => !!value);
102
+ if (!acceptSplit.includes(fileType)) {
103
+ message.error(`上传文件格式错误,支持${acceptSplit.join('、')}`);
104
+ return Promise.reject();
105
+ } else {
106
+ return Promise.resolve();
107
+ }
108
+ } else {
109
+ return Promise.resolve();
110
+ }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * @description 验证文件大小
116
+ * @param fileSize {number}
117
+ * @param maxSize {number}
118
+ * @returns {Promise<never>|Promise<void>}
119
+ */
120
+ verifyFileSize(fileSize, maxSize) {
121
+ const {
122
+ onBeforeUploadVerifySize
123
+ } = this.props;
124
+ if (onBeforeUploadVerifySize) {
125
+ const fn = onBeforeUploadVerifySize(fileSize, maxSize);
126
+ if (fn instanceof Promise) {
127
+ return fn;
128
+ } else {
129
+ return Promise.reject('onBeforeUploadVerifySize 应该返回Promise.');
130
+ }
131
+ } else {
132
+ if (fileSize / 1024 > maxSize) {
133
+ message.error(`上传文件大小超过最大值(${maxSize / 1024}MB),请重新选择`);
134
+ return Promise.reject();
135
+ } else {
136
+ return Promise.resolve();
137
+ }
138
+ }
139
+ }
140
+
141
+ /**
142
+ * @description 获取版本
143
+ * @return {string}
144
+ */
145
+ get version() {
146
+ return this.props.version;
147
+ }
148
+
149
+ /**
150
+ * @description 发起上传请求
151
+ * @param file {File}
152
+ * @returns {Promise<{url: string, fileName: string, respDesc: string}>}
153
+ */
154
+ onFormRequest(file) {
155
+ const {
156
+ customRequest
157
+ } = this.props;
158
+ return new Promise((resolve, reject) => {
159
+ const xhr = new XMLHttpRequest();
160
+ const md5 = new MD5();
161
+ const form = new FormData();
162
+ //
163
+ const fn = () => this.setState({
164
+ loading: true
165
+ }, () => {
166
+ xhr.open('POST', this.httpConfig.url);
167
+ Object.keys(this.httpConfig.headers).forEach(key => xhr.setRequestHeader(key, this.httpConfig.headers[key]));
168
+ xhr.onreadystatechange = () => {
169
+ if (xhr.readyState === 4 && xhr.status === 200) {
170
+ this.setState({
171
+ loading: false
172
+ }, () => {
173
+ const res = parseObject(xhr.responseText);
174
+ if (isFunction(customRequest)) {
175
+ const fn = customRequest(res);
176
+ if (isPromise(fn)) {
177
+ fn.then(value => resolve({
178
+ url: value
179
+ }));
180
+ }
181
+ } else {
182
+ if (res.respCode && res.respCode === '0000' || res.success) {
183
+ const result = toObject(res.data);
184
+ message.success('上传成功!');
185
+ resolve(result);
186
+ } else {
187
+ message.error(res.respDesc || res.errMessage || '未知错误,上传失败,请检查!');
188
+ reject(res);
189
+ }
190
+ }
191
+ });
192
+ }
193
+ };
194
+ form.append(this.httpConfig.fieldName, file);
195
+ Object.keys(this.httpConfig.data).forEach(key => form.append(key, this.httpConfig.data[key]));
196
+ xhr.send(form);
197
+ });
198
+ if (isVersion2(this.version)) {
199
+ const read = new FileReader();
200
+ read.onload = e => {
201
+ md5.appendBinary(e.target.result);
202
+ form.append('md5', md5.end());
203
+ fn();
204
+ };
205
+ read.readAsDataURL(file);
206
+ } else {
207
+ fn();
208
+ }
209
+ });
210
+ }
211
+
212
+ /**
213
+ * @description 回调
214
+ * @param value {string}
215
+ */
216
+ onChange(value) {
217
+ const {
218
+ onChange
219
+ } = this.props;
220
+ onChange && onChange(value || undefined);
221
+ }
222
+
223
+ /**
224
+ * @description 删除
225
+ * @param sup {number}
226
+ */
227
+ onDelete(sup) {
228
+ this.onChange(this.props.multiple ? this.value.filter((_, sub) => sub !== sup) : undefined);
229
+ }
230
+
231
+ /**
232
+ * @description 上传
233
+ * @param target {{files: FileList, value: any}}
234
+ */
235
+ onUpload({
236
+ target
237
+ }) {
238
+ const file = target.files[0];
239
+ const {
240
+ size: fileSize,
241
+ type: fileType
242
+ } = file;
243
+ const {
244
+ accept,
245
+ multiple,
246
+ size: maxSize
247
+ } = this.props;
248
+ this.verifyFileAccept(fileType, accept).then(() => this.verifyFileSize(fileSize, maxSize).then(() => this.onFormRequest(file).then(res => {
249
+ const data = isVersion1(this.version) ? res.url : {
250
+ fileId: res.fileId || res.url,
251
+ fileUrl: res.fileUrl || res.fileName
252
+ };
253
+ this.onChange(multiple ? [...this.value, data] : data);
254
+ })));
255
+ target.value = null;
256
+ }
257
+ render() {
258
+ const {
259
+ accept,
260
+ preview,
261
+ showDelete,
262
+ buttonProps,
263
+ // ---------
264
+ children
265
+ } = this.props;
266
+ const {
267
+ loading
268
+ } = this.state;
269
+ return /*#__PURE__*/React.createElement("div", {
270
+ className: `${prefixCls}_file-uploader_`
271
+ }, /*#__PURE__*/React.createElement(Button, _extends({}, buttonProps, {
272
+ loading: loading,
273
+ disabled: this.disabled,
274
+ className: `${prefixCls}_file-uploader-select_`,
275
+ onClick: () => this.inputFile.current.click()
276
+ }), /*#__PURE__*/React.createElement("input", {
277
+ ref: this.inputFile,
278
+ type: "file",
279
+ style: {
280
+ display: 'none'
281
+ },
282
+ accept: accept,
283
+ disabled: this.disabled,
284
+ onChange: e => this.onUpload(e)
285
+ }), /*#__PURE__*/React.createElement("span", null, children)), this.value.map((value, index) => {
286
+ const $value = this.version === 'v1' ? value : value.fileUrl;
287
+ return /*#__PURE__*/React.createElement("div", {
288
+ key: index,
289
+ className: `${prefixCls}-upload-list-text-container`
290
+ }, /*#__PURE__*/React.createElement("div", {
291
+ className: `${prefixCls}-upload-list-item ${prefixCls}-upload-list-item-list-type-text`
292
+ }, /*#__PURE__*/React.createElement("div", {
293
+ className: `${prefixCls}-upload-list-item-info`
294
+ }, /*#__PURE__*/React.createElement("span", {
295
+ className: `${prefixCls}-upload-span`
296
+ }, /*#__PURE__*/React.createElement("div", {
297
+ className: `${prefixCls}-upload-text-icon`
298
+ }, /*#__PURE__*/React.createElement(PaperClipOutlined, null)), /*#__PURE__*/React.createElement("span", {
299
+ style: {
300
+ paddingRight: 22
301
+ },
302
+ className: `${prefixCls}-upload-list-item-name`
303
+ }, preview ? /*#__PURE__*/React.createElement("a", {
304
+ href: $value,
305
+ target: "_blank"
306
+ }, $value) : $value), showDelete && /*#__PURE__*/React.createElement("span", {
307
+ className: `${prefixCls}-upload-list-item-card-actions`
308
+ }, /*#__PURE__*/React.createElement(Tooltip, {
309
+ title: "\u5220\u9664",
310
+ placement: "left"
311
+ }, /*#__PURE__*/React.createElement(DeleteOutlined, {
312
+ onClick: () => this.onDelete(index)
313
+ })))))));
314
+ }));
315
+ }
316
+ }
317
+ FileUploader.defaultProps = {
318
+ size: 5120,
319
+ data: {},
320
+ accept: '*',
321
+ headers: {},
322
+ version: 'v2',
323
+ preview: false,
324
+ maxCount: 99,
325
+ buttonProps: {
326
+ icon: undefined,
327
+ size: 'middle',
328
+ type: 'default',
329
+ block: false,
330
+ shape: 'default',
331
+ ghost: false,
332
+ danger: false
333
+ },
334
+ disabled: false,
335
+ multiple: false,
336
+ fieldName: 'file',
337
+ showDelete: true
338
+ };
339
+ FileUploader.propTypes = {
340
+ // 版本 v1旧版 / v2新版
341
+ version: PropTypes.string,
342
+ // 上传资源文件大小 默认5MB
343
+ size: PropTypes.number,
344
+ // 按钮图标
345
+ buttonProps: PropTypes.object,
346
+ // http上传携带的其他数据 默认{}
347
+ data: PropTypes.object,
348
+ // 填充值 默认undefined
349
+ value: PropTypes.any,
350
+ // 上传资源类型
351
+ accept: PropTypes.string,
352
+ // http上传接口
353
+ action: PropTypes.string.isRequired,
354
+ // 预览 默认false
355
+ preview: PropTypes.bool,
356
+ // http请求头配置 默认{}
357
+ headers: PropTypes.object,
358
+ // 最大上传数 multiple模式下有效 默认最大上传数99
359
+ maxCount: PropTypes.any,
360
+ // 开启多个文件上传 默认false
361
+ multiple: PropTypes.bool,
362
+ // 是否禁用上传 默认false
363
+ disabled: PropTypes.bool,
364
+ // 上传字段 默认ossFile
365
+ fieldName: PropTypes.string,
366
+ // 显示删除按钮 默认true
367
+ showDelete: PropTypes.bool,
368
+ // 数据回调
369
+ onChange: PropTypes.func,
370
+ // 上传之前验证资源大小回调
371
+ onBeforeUploadVerifySize: PropTypes.func,
372
+ // 上传之前验证资源类型回调
373
+ onBeforeUploadVerifyAccept: PropTypes.func,
374
+ // 可以自定义自己的上传实现
375
+ customRequest: PropTypes.func
376
+ };
377
+ export default FileUploader;
378
+ export const getValueProps = value => ({
379
+ value: value ? {
380
+ fileUrl: value
381
+ } : undefined
382
+ });
383
+ export const getValueFromEvent = file => {
384
+ return file?.fileUrl;
385
+ };