Skip to content

Commit 1d22f7b

Browse files
committed
Merge branch 'develop'
2 parents 27048ad + 9ffa1f2 commit 1d22f7b

File tree

10 files changed

+234
-161
lines changed

10 files changed

+234
-161
lines changed

.idea/workspace.xml

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@types/animation.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentClass } from 'react';
22

33
export interface IProps {
4-
type: 'fade' | 'scale-up' | 'scale-down' | 'slide-top' | 'slide-bottom' | 'slide-left' | 'slide-right' | 'shake';
4+
type: 'fade' | 'scale-up' | 'scale-down' | 'slide-top' | 'slide-bottom' | 'slide-left' | 'slide-right' | 'shake' | 'none';
55
reverse?: boolean;
66
children?: any;
77
delay?: number;

@types/imagePicker.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@ export type TChooseImgObj = {
2626
/**
2727
* 选择成功回调函数
2828
*/
29-
success?: () => void;
29+
success?: (list?: imgList) => void;
3030
/**
3131
* 选择失败回调函数
3232
*/
33-
fail?: () => void;
33+
fail?: (list?: imgList) => void;
3434
/**
3535
* 接口调用结束的回调函数(调用成功、失败都会执行)
3636
*/
37-
complete?: () => void;
37+
complete?: (list?: imgList) => void;
3838
};
3939

40+
export type imgList = {
41+
url: string,
42+
status: 'success' | 'fail' | 'loading' | 'none'
43+
}[]
44+
4045
export type TBeforeDel = (index: number) => boolean;
4146

4247
export interface IProps {
@@ -49,7 +54,7 @@ export interface IProps {
4954
/**
5055
* 图片列表
5156
*/
52-
imgList?: string[];
57+
imgList?: imgList;
5358
/**
5459
* 删除之前确认函数
5560
*/

@types/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ export { default as ClDivider } from './divider';
3737
export { default as ClForm } from './form';
3838
export { default as ClFormItem } from './formItem';
3939
export { default as ClTip } from './tip';
40+
41+
export { default as ClUtils } from './utils';

@types/utils.d.ts

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
export interface IProps {
2+
rule?: {
3+
/**
4+
* 手机号码正则校验
5+
*/
6+
phone?: (value: string) => boolean;
7+
/**
8+
* email 地址校验
9+
*/
10+
email?: (value: string) => boolean;
11+
/**
12+
* 数值范围校验
13+
*/
14+
range?: (min: number, max: number, value: number) => boolean;
15+
/**
16+
* 是否为空
17+
*/
18+
required?: (value: string) => boolean;
19+
/**
20+
* 是否为纯英文
21+
*/
22+
en?: (value: string) => boolean;
23+
/**
24+
* 是否为纯中文
25+
*/
26+
cn?: (value: string) => boolean;
27+
/**
28+
* 是否为金钱数字
29+
*/
30+
money?: (value: number | string) => boolean;
31+
/**
32+
* 是否字母数字组合
33+
*/
34+
code?: (value: string) => boolean;
35+
/**
36+
* 是否为纯数字
37+
*/
38+
number?: (value: number | string) => boolean;
39+
/**
40+
* 是否为 ip 地址
41+
*/
42+
ip?: (value: string) => boolean;
43+
/**
44+
* 是否为合法 url
45+
*/
46+
url?: (value: string) => boolean;
47+
/**
48+
* 是否为合法身份证
49+
*/
50+
idcard?: (value: string) => boolean;
51+
}
52+
}
53+
54+
declare const Utils: IProps;
55+
56+
export default Utils;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mp-colorui",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"description": "MP ColorUI 是一款基于 Taro 框架并且联合 Color-UI CSS 库开发的多端 UI 组件库(支持小程序端和H5端)",
55
"keywords": [
66
"taro",

src/components/imagePicker/index.scss

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.imagePicker-rotate-360 {
2+
animation: loading 2s infinite linear;
3+
}
4+
5+
@keyframes loading {
6+
from {
7+
transform: rotate(0deg)
8+
}
9+
to {
10+
transform: rotate(360deg)
11+
}
12+
}

src/components/imagePicker/index.tsx

+57-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Text, View } from '@tarojs/components';
1+
import { Text, View, Image } from '@tarojs/components';
22
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';
55

6+
import './index.scss'
67

78
export default function ClImagePicker(props: IProps) {
89
const chooseImgObj = props.chooseImgObj || {};
@@ -16,22 +17,26 @@ export default function ClImagePicker(props: IProps) {
1617
count: chooseImgObj.count || 9,
1718
sizeType: chooseImgObj.sizeType || ['original', 'compressed'],
1819
sourceType: chooseImgObj.sourceType || ['album'],
19-
success: function(res) {
20+
success: (res) => {
2021
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);
2425
});
2526
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)
2731
},
28-
fail: chooseImgObj.fail || function() {},
29-
complete: chooseImgObj.complete || function() {}
32+
complete() {
33+
chooseImgObj.complete && chooseImgObj.complete.call(this, imgList)
34+
}
3035
});
3136
};
3237
const viewImage = (url: string) => {
3338
Taro.previewImage({
34-
urls: imgList,
39+
urls: imgList.map(item => item.url),
3540
current: url
3641
});
3742
};
@@ -48,32 +53,58 @@ export default function ClImagePicker(props: IProps) {
4853
}
4954
};
5055

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) => (
5277
<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' }}
5681
onClick={() => {
57-
viewImage(url);
82+
viewImage(item.url);
5883
}}
5984
>
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 : ''}
69100
</View>
70101
));
71102

72103
return (
73104
<View className='cu-form-group'>
74105
<View className='grid col-4 grid-square flex-sub'>
75106
{imgComponet}
76-
<View className='padding-xs solids' onClick={ChooseImage}>
107+
<View className='padding-xs bg-gray' onClick={ChooseImage} style={{ borderRadius: '6px' }}>
77108
<Text className='cuIcon-cameraadd' />
78109
</View>
79110
</View>

0 commit comments

Comments
 (0)