@cloudbase/weda-ui 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/mp/components/form/uploaderFile/index.js +2 -16
- package/src/mp/components/form/uploaderFile/index.wxss +1 -0
- package/src/web/components/form/input/index.css +39 -4
- package/src/web/components/form/uploaderFile/{uploadFile.h5.jsx → uploadFile.h5.tsx} +58 -42
- package/src/web/components/form/uploaderFile/{uploadFile.pc.jsx → uploadFile.pc.tsx} +57 -37
- package/src/web/components/swiper/index.tsx +12 -10
package/package.json
CHANGED
|
@@ -178,13 +178,10 @@ Component({
|
|
|
178
178
|
this.data.files[index].status = 'fail';
|
|
179
179
|
}
|
|
180
180
|
});
|
|
181
|
-
const uploadFileList = await Promise.all(uploadPromise);
|
|
182
|
-
const cloudUrls = uploadFileList.map((file) => file.fileID);
|
|
183
181
|
this.setData({
|
|
184
182
|
files: this.data.files,
|
|
185
|
-
//urls: [...this.data.urls, ...cloudUrls],
|
|
186
183
|
});
|
|
187
|
-
return { urls: files.tempFiles
|
|
184
|
+
return { urls: files.tempFiles };
|
|
188
185
|
},
|
|
189
186
|
|
|
190
187
|
onDelete: function (e) {
|
|
@@ -194,7 +191,7 @@ Component({
|
|
|
194
191
|
this.setData({
|
|
195
192
|
files: filelist,
|
|
196
193
|
urls: this.data.urls.filter(
|
|
197
|
-
(v, index) => e.target.dataset.item?.cloudPath
|
|
194
|
+
(v, index) => e.target.dataset.item?.cloudPath != v
|
|
198
195
|
),
|
|
199
196
|
});
|
|
200
197
|
},
|
|
@@ -225,17 +222,6 @@ Component({
|
|
|
225
222
|
maxCount,
|
|
226
223
|
});
|
|
227
224
|
},
|
|
228
|
-
defaultValue: function (value) {
|
|
229
|
-
if (!deepEqual(value, this.data.urls)) {
|
|
230
|
-
if (!Array.isArray(value)) {
|
|
231
|
-
value = [value];
|
|
232
|
-
}
|
|
233
|
-
this.setData({
|
|
234
|
-
files: value.map((f) => ({ url: f })),
|
|
235
|
-
urls: value,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
225
|
urls: function (urls) {
|
|
240
226
|
let value = urls;
|
|
241
227
|
if (this.properties.single) {
|
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* ios safari 特别是小屏幕 iphone SE 之流
|
|
2
|
+
weui自带cell的padding会把input压倒很小,
|
|
3
|
+
容易点不到,需要特殊处理
|
|
4
|
+
START
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
把weui-cell 的padding还回到input
|
|
9
|
+
*/
|
|
10
|
+
.weda-ui.weda-input input.weui-input {
|
|
11
|
+
padding: 28px 16px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.weda-ui.weda-input .weui-cell > label {
|
|
15
|
+
padding: 16px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.weda-ui.weda-input .weui-cell {
|
|
19
|
+
padding: 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.weda-ui.weda-input .weui-btn_input-clear {
|
|
23
|
+
padding-right: 16px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* END
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
背景颜色设置问题
|
|
32
|
+
START
|
|
33
|
+
*/
|
|
34
|
+
.weda-ui .wedatea2td-input {
|
|
35
|
+
background: inherit;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* END
|
|
39
|
+
*/
|
|
@@ -3,6 +3,8 @@ import * as PropTypes from 'prop-types';
|
|
|
3
3
|
import { useSyncValue } from '../../../utils/useSyncValue';
|
|
4
4
|
import isObjectEqual from '../../../utils/isObjectEqual';
|
|
5
5
|
import weui from '../../../utils/weui';
|
|
6
|
+
import { CommonFormPropsType } from '../types';
|
|
7
|
+
|
|
6
8
|
import {
|
|
7
9
|
Upload,
|
|
8
10
|
ConfigProvider,
|
|
@@ -67,13 +69,12 @@ export function UploadFileH5({
|
|
|
67
69
|
deleteVisible = true,
|
|
68
70
|
downloadVisible = true,
|
|
69
71
|
value = [], // 需要兼容 cloud:和https: 协议,需要兼容字符串和字符串数组
|
|
70
|
-
events,
|
|
72
|
+
events = { success: null, error: null, change: null },
|
|
71
73
|
defaultValue,
|
|
72
74
|
uploadPath = 'weda-uploader',
|
|
73
75
|
single = true,
|
|
74
76
|
onChange = null,
|
|
75
|
-
}) {
|
|
76
|
-
//const [inputValue, setInputValue] = useSyncValue(defaultValue, isObjectEqual);
|
|
77
|
+
}: IUploadFileH5) {
|
|
77
78
|
const [fileIDList, setfileIDList] = React.useState(
|
|
78
79
|
filterStrList([].concat(defaultValue, value))
|
|
79
80
|
); // 上传成功文件ID列表,fileID[]
|
|
@@ -230,9 +231,6 @@ export function UploadFileH5({
|
|
|
230
231
|
file={item}
|
|
231
232
|
downloadVisible={downloadVisible}
|
|
232
233
|
deleteVisible={deleteVisible}
|
|
233
|
-
uploadPath={uploadPath}
|
|
234
|
-
events={events}
|
|
235
|
-
onChange={handleChange}
|
|
236
234
|
/>
|
|
237
235
|
}
|
|
238
236
|
</List.Item>
|
|
@@ -253,25 +251,23 @@ export function UploadFileH5({
|
|
|
253
251
|
requiredFlag,
|
|
254
252
|
});
|
|
255
253
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
onChange: PropTypes.objectOf(PropTypes.func), // 配合 fomily 受控使用
|
|
274
|
-
};
|
|
254
|
+
export interface IUploadFileH5 extends CommonFormPropsType {
|
|
255
|
+
className?: string; // 传入类
|
|
256
|
+
label?: string; // 官方属性:标题
|
|
257
|
+
tips?: string; // 官方属性:提示
|
|
258
|
+
btnTitle?: string; // 官方属性:上传按钮标题
|
|
259
|
+
maxUploadCount?: number; // 官方属性:上传文件最大数量,作用于 数组,用 single 控制数组还是单个对象
|
|
260
|
+
deleteVisible?: boolean;
|
|
261
|
+
downloadVisible?: boolean;
|
|
262
|
+
acceptTypes?: any[];
|
|
263
|
+
disabled?: boolean;
|
|
264
|
+
defaultValue?: string | string[];
|
|
265
|
+
maxSize?: number; // 官方属性:单个图片大小限制,单位是M
|
|
266
|
+
value?: string | string[]; // 官方属性:值
|
|
267
|
+
uploadPath?: string; // 上传路径
|
|
268
|
+
single?: boolean; // 单张上传还是多张上传,对应 onChange 参数为字符串还是字符串数组,value 在处理过程统一转为字符串数组
|
|
269
|
+
onChange?: (v: any) => void; // 配合 fomily 受控使用
|
|
270
|
+
}
|
|
275
271
|
|
|
276
272
|
/**
|
|
277
273
|
* 基于 FileID 文件回显组件
|
|
@@ -282,7 +278,7 @@ const TcbFileEcho = ({
|
|
|
282
278
|
onChange,
|
|
283
279
|
deleteVisible,
|
|
284
280
|
downloadVisible,
|
|
285
|
-
}) => {
|
|
281
|
+
}: ITcbFileEcho) => {
|
|
286
282
|
const [src, setSrc] = React.useState('');
|
|
287
283
|
const { fileSizeObj } = React.useContext(FileContext) || {};
|
|
288
284
|
const size = '--';
|
|
@@ -322,26 +318,33 @@ const TcbFileEcho = ({
|
|
|
322
318
|
status="UPLOAD_STATUS_SUCCESS"
|
|
323
319
|
fileID={fileID}
|
|
324
320
|
src={src}
|
|
325
|
-
downloadVisible={downloadVisible}
|
|
326
|
-
deleteVisible={deleteVisible}
|
|
327
|
-
onChange={onChange}
|
|
328
321
|
/>
|
|
329
322
|
</div>
|
|
330
323
|
</div>
|
|
331
324
|
);
|
|
332
325
|
};
|
|
333
|
-
|
|
326
|
+
interface ITcbFileEcho {
|
|
327
|
+
fileID?: string;
|
|
328
|
+
fileList?: any;
|
|
329
|
+
file?: any;
|
|
330
|
+
onChange?: Function;
|
|
331
|
+
deleteVisible?: boolean;
|
|
332
|
+
downloadVisible?: boolean;
|
|
333
|
+
}
|
|
334
|
+
interface ITcbFileUpload {
|
|
335
|
+
file?: any;
|
|
336
|
+
downloadVisible?: boolean;
|
|
337
|
+
deleteVisible?: boolean;
|
|
338
|
+
}
|
|
334
339
|
/**
|
|
335
340
|
* 基于 File 上传文件过程组件
|
|
336
341
|
*/
|
|
337
342
|
const TcbFileUpload = ({
|
|
338
343
|
file,
|
|
339
|
-
uploadPath,
|
|
340
|
-
onChange,
|
|
341
344
|
downloadVisible,
|
|
342
345
|
deleteVisible,
|
|
343
|
-
|
|
344
|
-
})
|
|
346
|
+
}: ITcbFileUpload) => {
|
|
347
|
+
const { uploadPath, onChange, events } = React.useContext(FileContext) || {};
|
|
345
348
|
const [percent, setPercent] = React.useState(0); // 上传进度
|
|
346
349
|
const [status, setStatus] = React.useState('UPLOAD_STATUS_PENDING'); // 上传状态
|
|
347
350
|
const cancleRef = React.useRef(''); // 取消的uuid
|
|
@@ -399,9 +402,6 @@ const TcbFileUpload = ({
|
|
|
399
402
|
file={file}
|
|
400
403
|
uuid={file?._uuid}
|
|
401
404
|
status={status}
|
|
402
|
-
downloadVisible={downloadVisible}
|
|
403
|
-
deleteVisible={deleteVisible}
|
|
404
|
-
onChange={onChange}
|
|
405
405
|
onCancel={(uuid) => {
|
|
406
406
|
cancleRef.current = uuid;
|
|
407
407
|
onChange?.({ type: 'delete', uuid });
|
|
@@ -413,6 +413,13 @@ const TcbFileUpload = ({
|
|
|
413
413
|
);
|
|
414
414
|
};
|
|
415
415
|
|
|
416
|
+
interface IUploadFileStatus {
|
|
417
|
+
status?: string;
|
|
418
|
+
percent?: number;
|
|
419
|
+
size?: any;
|
|
420
|
+
title?: string;
|
|
421
|
+
percentSize?: number;
|
|
422
|
+
}
|
|
416
423
|
/**
|
|
417
424
|
* 上传文件状态组件
|
|
418
425
|
*/
|
|
@@ -422,7 +429,7 @@ const UploadFileStatus = ({
|
|
|
422
429
|
size,
|
|
423
430
|
title = null,
|
|
424
431
|
percentSize = 0,
|
|
425
|
-
}) => {
|
|
432
|
+
}: IUploadFileStatus) => {
|
|
426
433
|
//上传中、待上传状态
|
|
427
434
|
if (
|
|
428
435
|
status == 'UPLOAD_STATUS_LOADING' ||
|
|
@@ -484,6 +491,16 @@ const UploadFileStatus = ({
|
|
|
484
491
|
);
|
|
485
492
|
};
|
|
486
493
|
|
|
494
|
+
interface IUploadFileAction {
|
|
495
|
+
status?: string;
|
|
496
|
+
fileID?: string;
|
|
497
|
+
uuid?: string;
|
|
498
|
+
src?: string;
|
|
499
|
+
file?: any;
|
|
500
|
+
onReLoad?: any;
|
|
501
|
+
onCancel?: any;
|
|
502
|
+
}
|
|
503
|
+
|
|
487
504
|
/**
|
|
488
505
|
* 操作列组件, onChange 从最外层 UploadFilePc 传进来
|
|
489
506
|
* props: { status, fileID, uuid, src, onChange }
|
|
@@ -493,13 +510,12 @@ const UploadFileAction = ({
|
|
|
493
510
|
fileID = '',
|
|
494
511
|
uuid = '',
|
|
495
512
|
src = '',
|
|
496
|
-
downloadVisible = true,
|
|
497
|
-
deleteVisible = true,
|
|
498
513
|
file = null,
|
|
499
|
-
onChange = null,
|
|
500
514
|
onReLoad = null,
|
|
501
515
|
onCancel = null,
|
|
502
|
-
}) => {
|
|
516
|
+
}: IUploadFileAction) => {
|
|
517
|
+
const { onChange, downloadVisible, deleteVisible } =
|
|
518
|
+
React.useContext(FileContext) || {};
|
|
503
519
|
// 操作列按钮-删除
|
|
504
520
|
const renderDelete = () => (
|
|
505
521
|
<Icon
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as PropTypes from 'prop-types';
|
|
3
2
|
import {
|
|
4
3
|
Upload,
|
|
5
4
|
ConfigProvider,
|
|
@@ -16,11 +15,12 @@ import {
|
|
|
16
15
|
isHttpFileID,
|
|
17
16
|
transSize,
|
|
18
17
|
downloadFile,
|
|
19
|
-
cutFileTitle
|
|
18
|
+
cutFileTitle,
|
|
20
19
|
} from '../../../utils/platform';
|
|
21
20
|
import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
|
|
22
21
|
import classNames from '../../../utils/classnames';
|
|
23
22
|
import { renderDecorator } from '../renderDecorator';
|
|
23
|
+
import { CommonFormPropsType } from '../types';
|
|
24
24
|
|
|
25
25
|
// 默认组件类前缀
|
|
26
26
|
const CLASS_PREFIX = 'weda-upload-file-pc';
|
|
@@ -41,14 +41,15 @@ const FileContext = React.createContext(null);
|
|
|
41
41
|
*/
|
|
42
42
|
export function UploadFilePc({
|
|
43
43
|
// 系统属性
|
|
44
|
-
layout
|
|
44
|
+
layout,
|
|
45
45
|
id = '',
|
|
46
46
|
style = {},
|
|
47
47
|
labelVisible = true,
|
|
48
|
-
|
|
48
|
+
label = '上传文件',
|
|
49
49
|
requiredFlag = false,
|
|
50
50
|
disabled = false,
|
|
51
51
|
className = '',
|
|
52
|
+
events = { success: null, error: null, change: null },
|
|
52
53
|
// 组件属性
|
|
53
54
|
decorator,
|
|
54
55
|
tips = '',
|
|
@@ -56,16 +57,15 @@ export function UploadFilePc({
|
|
|
56
57
|
maxUploadCount = 9,
|
|
57
58
|
maxSize = 1024,
|
|
58
59
|
single = true,
|
|
59
|
-
defaultValue = [], //
|
|
60
|
+
defaultValue = [], // 组件默认初始化值
|
|
61
|
+
value = [], // 用于模型组件中 formily 的值管理
|
|
60
62
|
acceptTypes = [],
|
|
61
|
-
events = { success: null, error: null, change: null },
|
|
62
63
|
downloadVisible = true,
|
|
63
64
|
deleteVisible = true,
|
|
64
65
|
uploadPath = 'weda-uploader',
|
|
65
|
-
value = [], // 需要兼容 cloud:和https: 协议,需要兼容字符串和字符串数组
|
|
66
66
|
onChange = null,
|
|
67
67
|
isEdit = true,
|
|
68
|
-
}) {
|
|
68
|
+
}: IUploaderFilePc) {
|
|
69
69
|
const [fileIDList, setfileIDList] = React.useState(
|
|
70
70
|
filterStrList([].concat(defaultValue, value))
|
|
71
71
|
); // 上传成功文件ID列表,fileID[]
|
|
@@ -234,40 +234,37 @@ export function UploadFilePc({
|
|
|
234
234
|
id,
|
|
235
235
|
className: cls,
|
|
236
236
|
style,
|
|
237
|
-
label: labelVisible ?
|
|
237
|
+
label: labelVisible ? label : null,
|
|
238
238
|
layout,
|
|
239
239
|
multiCell: false,
|
|
240
240
|
requiredFlag,
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
decorator: PropTypes.any,
|
|
264
|
-
isEdit: PropTypes.bool, // 是否展示上传按钮,用户详情页面展示
|
|
265
|
-
};
|
|
244
|
+
export interface IUploaderFilePc extends CommonFormPropsType {
|
|
245
|
+
btnTitle?: string;
|
|
246
|
+
maxUploadCount?: number;
|
|
247
|
+
downloadVisible?: boolean;
|
|
248
|
+
deleteVisible?: boolean;
|
|
249
|
+
defaultValue?: string | string[];
|
|
250
|
+
maxSize?: number;
|
|
251
|
+
single?: boolean;
|
|
252
|
+
acceptTypes?: any[];
|
|
253
|
+
tips?: string;
|
|
254
|
+
value?: string | string[];
|
|
255
|
+
uploadPath?: string;
|
|
256
|
+
isEdit?: boolean;
|
|
257
|
+
onChange?: Function;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
interface ITcbFileEcho {
|
|
261
|
+
fileID?: string;
|
|
262
|
+
}
|
|
266
263
|
|
|
267
264
|
/**
|
|
268
265
|
* 基于 FileID 回显文件表格行组件
|
|
269
266
|
*/
|
|
270
|
-
const TcbFileEcho = ({ fileID }) => {
|
|
267
|
+
const TcbFileEcho = ({ fileID }: ITcbFileEcho) => {
|
|
271
268
|
const [src, setSrc] = React.useState('');
|
|
272
269
|
const { fileSizeObj } = React.useContext(FileContext) || {};
|
|
273
270
|
React.useEffect(() => {
|
|
@@ -298,7 +295,9 @@ const TcbFileEcho = ({ fileID }) => {
|
|
|
298
295
|
|
|
299
296
|
return (
|
|
300
297
|
<div className={`${CLASS_PREFIX}--item ${CLASS_PREFIX}--item-body`}>
|
|
301
|
-
<div className={`${CLASS_PREFIX}--item-title`} title={title}>
|
|
298
|
+
<div className={`${CLASS_PREFIX}--item-title`} title={title}>
|
|
299
|
+
{cutFileTitle(title)}
|
|
300
|
+
</div>
|
|
302
301
|
<div className={`${CLASS_PREFIX}--item-size`}>
|
|
303
302
|
{fileSizeObj[fileID] || '--'}
|
|
304
303
|
</div>
|
|
@@ -312,10 +311,14 @@ const TcbFileEcho = ({ fileID }) => {
|
|
|
312
311
|
);
|
|
313
312
|
};
|
|
314
313
|
|
|
314
|
+
interface ITcbFileUpload {
|
|
315
|
+
file?: any;
|
|
316
|
+
}
|
|
317
|
+
|
|
315
318
|
/**
|
|
316
319
|
* 基于 File 上传文件过程表格行组件
|
|
317
320
|
*/
|
|
318
|
-
const TcbFileUpload = ({ file }) => {
|
|
321
|
+
const TcbFileUpload = ({ file }: ITcbFileUpload) => {
|
|
319
322
|
const { uploadPath, onChange, events } = React.useContext(FileContext) || {};
|
|
320
323
|
const [percent, setPercent] = React.useState(0); // 上传进度
|
|
321
324
|
const [status, setStatus] = React.useState('0'); // 上传状态
|
|
@@ -360,7 +363,9 @@ const TcbFileUpload = ({ file }) => {
|
|
|
360
363
|
|
|
361
364
|
return (
|
|
362
365
|
<div className={`${CLASS_PREFIX}--item ${CLASS_PREFIX}--item-body`}>
|
|
363
|
-
<div className={`${CLASS_PREFIX}--item-title`} title={title}>
|
|
366
|
+
<div className={`${CLASS_PREFIX}--item-title`} title={title}>
|
|
367
|
+
{cutFileTitle(title)}
|
|
368
|
+
</div>
|
|
364
369
|
<div className={`${CLASS_PREFIX}--item-size`}>{size}</div>
|
|
365
370
|
<div className={`${CLASS_PREFIX}--item-status`}>
|
|
366
371
|
<UploadFileStatus status={status} percent={percent} />
|
|
@@ -381,10 +386,15 @@ const TcbFileUpload = ({ file }) => {
|
|
|
381
386
|
);
|
|
382
387
|
};
|
|
383
388
|
|
|
389
|
+
interface IUploadFileStatus {
|
|
390
|
+
status?: string;
|
|
391
|
+
percent?: number;
|
|
392
|
+
}
|
|
393
|
+
|
|
384
394
|
/**
|
|
385
395
|
* 上传文件状态组件
|
|
386
396
|
*/
|
|
387
|
-
const UploadFileStatus = ({ status = '2', percent = 0 }) => {
|
|
397
|
+
const UploadFileStatus = ({ status = '2', percent = 0 }: IUploadFileStatus) => {
|
|
388
398
|
if (status == '1' && percent) {
|
|
389
399
|
return (
|
|
390
400
|
<>
|
|
@@ -401,6 +411,16 @@ const UploadFileStatus = ({ status = '2', percent = 0 }) => {
|
|
|
401
411
|
);
|
|
402
412
|
};
|
|
403
413
|
|
|
414
|
+
interface IUploadFileAction {
|
|
415
|
+
status?: string;
|
|
416
|
+
fileID?: string;
|
|
417
|
+
uuid?: string;
|
|
418
|
+
src?: string;
|
|
419
|
+
file?: any;
|
|
420
|
+
onReLoad?: any;
|
|
421
|
+
onCancel?: any;
|
|
422
|
+
}
|
|
423
|
+
|
|
404
424
|
/**
|
|
405
425
|
* 操作列组件, onChange 从最外层 UploadFilePc 传进来
|
|
406
426
|
* props: { status, fileID, uuid, src, onChange }
|
|
@@ -413,7 +433,7 @@ const UploadFileAction = ({
|
|
|
413
433
|
file = null,
|
|
414
434
|
onReLoad = null,
|
|
415
435
|
onCancel = null,
|
|
416
|
-
}) => {
|
|
436
|
+
}: IUploadFileAction) => {
|
|
417
437
|
const { onChange, downloadVisible, deleteVisible, isEdit } =
|
|
418
438
|
React.useContext(FileContext) || {};
|
|
419
439
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useState, useEffect, useRef
|
|
2
|
+
import { useState, useEffect, useRef } from 'react';
|
|
3
3
|
import classNames from '../../utils/classnames';
|
|
4
4
|
import Swipe from 'react-easy-swipe';
|
|
5
|
-
import {useDebouncedCallback, useEventListener, useResizeObserver} from '@react-hookz/web'
|
|
5
|
+
import {useDebouncedCallback, useEventListener, useResizeObserver} from '@react-hookz/web';
|
|
6
6
|
|
|
7
7
|
import './index.css';
|
|
8
8
|
import { CommonPropsType } from '../../types';
|
|
@@ -211,18 +211,20 @@ export default function Swiper({
|
|
|
211
211
|
false
|
|
212
212
|
)}
|
|
213
213
|
<a
|
|
214
|
-
href="
|
|
214
|
+
href="#"
|
|
215
215
|
className="g-swiper__turn-pre"
|
|
216
|
-
onClick={() => {
|
|
216
|
+
onClick={(ev) => {
|
|
217
|
+
ev.preventDefault();
|
|
217
218
|
setIndex(currentIndex - 1);
|
|
218
219
|
}}
|
|
219
220
|
>
|
|
220
221
|
上一页
|
|
221
222
|
</a>
|
|
222
223
|
<a
|
|
223
|
-
href="
|
|
224
|
+
href="#"
|
|
224
225
|
className="g-swiper__turn-next"
|
|
225
|
-
onClick={() => {
|
|
226
|
+
onClick={(ev) => {
|
|
227
|
+
ev.preventDefault();
|
|
226
228
|
setIndex(currentIndex + 1);
|
|
227
229
|
}}
|
|
228
230
|
>
|
|
@@ -241,15 +243,15 @@ const SwiperItem: React.FC<{
|
|
|
241
243
|
const firstChildRef = useRef<HTMLDivElement>(null);
|
|
242
244
|
const syncHeight = useDebouncedCallback((e) => {
|
|
243
245
|
setHeight(e.contentRect.height);
|
|
244
|
-
}, [setHeight], 500, 2000) // 必须debounce延迟,让resize完成后再设置高度
|
|
246
|
+
}, [setHeight], 500, 2000); // 必须debounce延迟,让resize完成后再设置高度
|
|
245
247
|
|
|
246
248
|
// 因为有loading 所以得用resizeobserver
|
|
247
249
|
// @ts-ignore
|
|
248
250
|
useResizeObserver(firstChildRef, (e) => {
|
|
249
251
|
if(currentIndex === index) {
|
|
250
|
-
syncHeight(e)
|
|
252
|
+
syncHeight(e);
|
|
251
253
|
}
|
|
252
|
-
})
|
|
254
|
+
});
|
|
253
255
|
const wrapRef = useRef<HTMLDivElement>();
|
|
254
256
|
return (
|
|
255
257
|
<div
|
|
@@ -263,4 +265,4 @@ const SwiperItem: React.FC<{
|
|
|
263
265
|
</div>
|
|
264
266
|
</div>
|
|
265
267
|
);
|
|
266
|
-
}
|
|
268
|
+
};
|