1
- import { Text , View } from '@tarojs/components' ;
1
+ import { Text , View , Image } from '@tarojs/components' ;
2
2
import Taro , { useState } from '@tarojs/taro' ;
3
- import { IProps } from '../../../@types/imagePicker' ;
4
-
3
+ import { IProps , imgList } from '../../../@types/imagePicker' ;
4
+ import ClIcon from '../icon' ;
5
5
6
+ import './index.scss'
6
7
7
8
export default function ClImagePicker ( props : IProps ) {
8
9
const chooseImgObj = props . chooseImgObj || { } ;
@@ -16,22 +17,26 @@ export default function ClImagePicker(props: IProps) {
16
17
count : chooseImgObj . count || 9 ,
17
18
sizeType : chooseImgObj . sizeType || [ 'original' , 'compressed' ] ,
18
19
sourceType : chooseImgObj . sourceType || [ 'album' ] ,
19
- success : function ( res ) {
20
+ success : ( res ) => {
20
21
console . log ( res ) ;
21
- const selectArray : string [ ] = res . tempFilePaths ;
22
- selectArray . forEach ( url => {
23
- if ( ! imgList . includes ( url ) ) imgList . push ( url ) ;
22
+ const selectArray : imgList = res . tempFilePaths . map ( ( url => ( { url , status : 'none' } ) ) ) ;
23
+ selectArray . forEach ( item => {
24
+ if ( ! imgList . find ( obj => item . url === obj . url ) ) imgList . push ( item ) ;
24
25
} ) ;
25
26
setImgList ( imgList ) ;
26
- chooseImgObj . success && chooseImgObj . success ( ) ;
27
+ chooseImgObj . success && chooseImgObj . success . call ( this , imgList ) ;
28
+ } ,
29
+ fail ( ) {
30
+ chooseImgObj . fail && chooseImgObj . fail . call ( this , imgList )
27
31
} ,
28
- fail : chooseImgObj . fail || function ( ) { } ,
29
- complete : chooseImgObj . complete || function ( ) { }
32
+ complete ( ) {
33
+ chooseImgObj . complete && chooseImgObj . complete . call ( this , imgList )
34
+ }
30
35
} ) ;
31
36
} ;
32
37
const viewImage = ( url : string ) => {
33
38
Taro . previewImage ( {
34
- urls : imgList ,
39
+ urls : imgList . map ( item => item . url ) ,
35
40
current : url
36
41
} ) ;
37
42
} ;
@@ -48,32 +53,58 @@ export default function ClImagePicker(props: IProps) {
48
53
}
49
54
} ;
50
55
51
- const imgComponet = imgList . map ( ( url , index ) => (
56
+ const errComponentTip = (
57
+ < View className = 'cu-tag' style = { { backgroundColor : 'rgba(355, 355, 355, 0.8)' } } >
58
+ < ClIcon iconName = 'warnfill' size = 'xsmall' color = 'red' />
59
+ </ View >
60
+ )
61
+
62
+ const successComponentTip = (
63
+ < View className = 'cu-tag' style = { { backgroundColor : 'rgba(355, 355, 355, 0.8)' } } >
64
+ < ClIcon iconName = 'roundcheckfill' size = 'xsmall' color = 'olive' />
65
+ </ View >
66
+ )
67
+
68
+ const loadingComponentTip = (
69
+ < View className = 'cu-tag' style = { { backgroundColor : 'rgba(355, 355, 355, 0.8)' } } >
70
+ < View className = 'imagePicker-rotate-360' >
71
+ < ClIcon iconName = 'loading' size = 'xsmall' color = 'blue' />
72
+ </ View >
73
+ </ View >
74
+ )
75
+
76
+ const imgComponet = imgList . map ( ( item , index ) => (
52
77
< View
53
- className = 'padding-xs bg-img'
54
- key = { url }
55
- style = { { backgroundImage : `url( ${ url } )` } }
78
+ className = 'padding-xs bg-img bg-gray '
79
+ key = { item . url }
80
+ style = { { borderRadius : '6px' , position : 'relative' } }
56
81
onClick = { ( ) => {
57
- viewImage ( url ) ;
82
+ viewImage ( item . url ) ;
58
83
} }
59
84
>
60
- < View
61
- className = 'cu-tag bg-red'
62
- onClick = { e => {
63
- delImg ( index , e ) ;
64
- e . stopPropagation ( ) ;
65
- } }
66
- >
67
- < Text className = 'cuIcon-close' />
68
- </ View >
85
+ < Image src = { item . url } mode = 'widthFix' style = { { width : '100%' , position : 'absolute' , left : '0' , top : '0' , right : '0' , bottom : '0' } } />
86
+ { item . status === 'none' ?
87
+ < View
88
+ className = 'cu-tag bg-red'
89
+ onClick = { e => {
90
+ delImg ( index , e ) ;
91
+ e . stopPropagation ( ) ;
92
+ } }
93
+ style = { { backgroundColor : 'rgba(355, 355, 355, 0.8)' } }
94
+ >
95
+ < ClIcon iconName = 'close' color = 'black' size = 'xsmall' />
96
+ </ View > : '' }
97
+ { item . status === 'success' ? successComponentTip : '' }
98
+ { item . status === 'fail' ? errComponentTip : '' }
99
+ { item . status === 'loading' ? loadingComponentTip : '' }
69
100
</ View >
70
101
) ) ;
71
102
72
103
return (
73
104
< View className = 'cu-form-group' >
74
105
< View className = 'grid col-4 grid-square flex-sub' >
75
106
{ imgComponet }
76
- < View className = 'padding-xs solids ' onClick = { ChooseImage } >
107
+ < View className = 'padding-xs bg-gray ' onClick = { ChooseImage } style = { { borderRadius : '6px' } } >
77
108
< Text className = 'cuIcon-cameraadd' />
78
109
</ View >
79
110
</ View >
0 commit comments