@zamlia/mini-ui 0.0.1
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/es/components/common/BottomPopup/index.d.ts +78 -0
- package/es/components/common/BottomPopup/index.d.ts.map +1 -0
- package/es/components/common/Card/index.d.ts +33 -0
- package/es/components/common/Card/index.d.ts.map +1 -0
- package/es/components/common/CardItem/index.d.ts +60 -0
- package/es/components/common/CardItem/index.d.ts.map +1 -0
- package/es/components/common/DataSelect/index.d.ts +15 -0
- package/es/components/common/DataSelect/index.d.ts.map +1 -0
- package/es/components/common/Modal/index.d.ts +31 -0
- package/es/components/common/Modal/index.d.ts.map +1 -0
- package/es/components/common/NavBar/index.d.ts +38 -0
- package/es/components/common/NavBar/index.d.ts.map +1 -0
- package/es/components/common/Page/index.d.ts +16 -0
- package/es/components/common/Page/index.d.ts.map +1 -0
- package/es/components/common/PullToPushRefresh/index.d.ts +94 -0
- package/es/components/common/PullToPushRefresh/index.d.ts.map +1 -0
- package/es/components/common/Radio/index.d.ts +26 -0
- package/es/components/common/Radio/index.d.ts.map +1 -0
- package/es/components/common/TabPane/index.d.ts +9 -0
- package/es/components/common/TabPane/index.d.ts.map +1 -0
- package/es/components/common/Tabs/index.d.ts +27 -0
- package/es/components/common/Tabs/index.d.ts.map +1 -0
- package/es/components/common/UploadFile/index.d.ts +50 -0
- package/es/components/common/UploadFile/index.d.ts.map +1 -0
- package/es/components/common/UploadFile/upload.d.ts +11 -0
- package/es/components/common/UploadFile/upload.d.ts.map +1 -0
- package/es/components/common/UploadFile/utils.d.ts +20 -0
- package/es/components/common/UploadFile/utils.d.ts.map +1 -0
- package/es/components/common/VideoView/index.d.ts +14 -0
- package/es/components/common/VideoView/index.d.ts.map +1 -0
- package/es/components/common/index.d.ts +23 -0
- package/es/components/common/index.d.ts.map +1 -0
- package/es/components/industry/CitySelectButton/index.d.ts +17 -0
- package/es/components/industry/CitySelectButton/index.d.ts.map +1 -0
- package/es/components/industry/CitySelectModal/index.d.ts +13 -0
- package/es/components/industry/CitySelectModal/index.d.ts.map +1 -0
- package/es/components/industry/PaymentMethodSelect/index.d.ts +59 -0
- package/es/components/industry/PaymentMethodSelect/index.d.ts.map +1 -0
- package/es/components/industry/index.d.ts +5 -0
- package/es/components/industry/index.d.ts.map +1 -0
- package/es/config/classPrefix.d.ts +36 -0
- package/es/config/classPrefix.d.ts.map +1 -0
- package/es/index.d.ts +4 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +5334 -0
- package/es/index.js.map +1 -0
- package/es/styles/_base.scss +4 -0
- package/es/styles/index.scss +19 -0
- package/es/styles/mixins.scss +15 -0
- package/es/styles/variables.scss +2 -0
- package/es/utils/city.d.ts +4005 -0
- package/es/utils/city.d.ts.map +1 -0
- package/es/utils/index.d.ts +50 -0
- package/es/utils/index.d.ts.map +1 -0
- package/lib/components/common/BottomPopup/index.d.ts +78 -0
- package/lib/components/common/BottomPopup/index.d.ts.map +1 -0
- package/lib/components/common/Card/index.d.ts +33 -0
- package/lib/components/common/Card/index.d.ts.map +1 -0
- package/lib/components/common/CardItem/index.d.ts +60 -0
- package/lib/components/common/CardItem/index.d.ts.map +1 -0
- package/lib/components/common/DataSelect/index.d.ts +15 -0
- package/lib/components/common/DataSelect/index.d.ts.map +1 -0
- package/lib/components/common/Modal/index.d.ts +31 -0
- package/lib/components/common/Modal/index.d.ts.map +1 -0
- package/lib/components/common/NavBar/index.d.ts +38 -0
- package/lib/components/common/NavBar/index.d.ts.map +1 -0
- package/lib/components/common/Page/index.d.ts +16 -0
- package/lib/components/common/Page/index.d.ts.map +1 -0
- package/lib/components/common/PullToPushRefresh/index.d.ts +94 -0
- package/lib/components/common/PullToPushRefresh/index.d.ts.map +1 -0
- package/lib/components/common/Radio/index.d.ts +26 -0
- package/lib/components/common/Radio/index.d.ts.map +1 -0
- package/lib/components/common/TabPane/index.d.ts +9 -0
- package/lib/components/common/TabPane/index.d.ts.map +1 -0
- package/lib/components/common/Tabs/index.d.ts +27 -0
- package/lib/components/common/Tabs/index.d.ts.map +1 -0
- package/lib/components/common/UploadFile/index.d.ts +50 -0
- package/lib/components/common/UploadFile/index.d.ts.map +1 -0
- package/lib/components/common/UploadFile/upload.d.ts +11 -0
- package/lib/components/common/UploadFile/upload.d.ts.map +1 -0
- package/lib/components/common/UploadFile/utils.d.ts +20 -0
- package/lib/components/common/UploadFile/utils.d.ts.map +1 -0
- package/lib/components/common/VideoView/index.d.ts +14 -0
- package/lib/components/common/VideoView/index.d.ts.map +1 -0
- package/lib/components/common/index.d.ts +23 -0
- package/lib/components/common/index.d.ts.map +1 -0
- package/lib/components/industry/CitySelectButton/index.d.ts +17 -0
- package/lib/components/industry/CitySelectButton/index.d.ts.map +1 -0
- package/lib/components/industry/CitySelectModal/index.d.ts +13 -0
- package/lib/components/industry/CitySelectModal/index.d.ts.map +1 -0
- package/lib/components/industry/PaymentMethodSelect/index.d.ts +59 -0
- package/lib/components/industry/PaymentMethodSelect/index.d.ts.map +1 -0
- package/lib/components/industry/index.d.ts +5 -0
- package/lib/components/industry/index.d.ts.map +1 -0
- package/lib/config/classPrefix.d.ts +36 -0
- package/lib/config/classPrefix.d.ts.map +1 -0
- package/lib/index.d.ts +585 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5349 -0
- package/lib/index.js.map +1 -0
- package/lib/styles/_base.scss +4 -0
- package/lib/styles/index.scss +19 -0
- package/lib/styles/mixins.scss +15 -0
- package/lib/styles/variables.scss +2 -0
- package/lib/utils/city.d.ts +4005 -0
- package/lib/utils/city.d.ts.map +1 -0
- package/lib/utils/index.d.ts +50 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/package.json +81 -0
- package/src/components/common/BottomPopup/index.scss +34 -0
- package/src/components/common/BottomPopup/index.tsx +129 -0
- package/src/components/common/Card/index.scss +160 -0
- package/src/components/common/Card/index.tsx +72 -0
- package/src/components/common/CardItem/index.tsx +153 -0
- package/src/components/common/DataSelect/index.tsx +86 -0
- package/src/components/common/Modal/index.scss +49 -0
- package/src/components/common/Modal/index.tsx +105 -0
- package/src/components/common/NavBar/index.scss +26 -0
- package/src/components/common/NavBar/index.tsx +81 -0
- package/src/components/common/Page/index.scss +19 -0
- package/src/components/common/Page/index.tsx +56 -0
- package/src/components/common/PullToPushRefresh/index.scss +38 -0
- package/src/components/common/PullToPushRefresh/index.tsx +338 -0
- package/src/components/common/Radio/index.scss +15 -0
- package/src/components/common/Radio/index.tsx +56 -0
- package/src/components/common/TabPane/index.tsx +26 -0
- package/src/components/common/Tabs/index.scss +60 -0
- package/src/components/common/Tabs/index.tsx +107 -0
- package/src/components/common/UploadFile/index.scss +59 -0
- package/src/components/common/UploadFile/index.tsx +321 -0
- package/src/components/common/UploadFile/upload.ts +63 -0
- package/src/components/common/UploadFile/utils.ts +81 -0
- package/src/components/common/VideoView/index.tsx +50 -0
- package/src/components/common/index.ts +23 -0
- package/src/components/industry/CitySelectButton/index.tsx +76 -0
- package/src/components/industry/CitySelectModal/index.scss +122 -0
- package/src/components/industry/CitySelectModal/index.tsx +121 -0
- package/src/components/industry/PaymentMethodSelect/index.scss +146 -0
- package/src/components/industry/PaymentMethodSelect/index.tsx +316 -0
- package/src/components/industry/index.ts +5 -0
- package/src/config/classPrefix.ts +44 -0
- package/src/index.ts +9 -0
- package/src/styles/_base.scss +4 -0
- package/src/styles/index.scss +19 -0
- package/src/styles/mixins.scss +15 -0
- package/src/styles/variables.scss +2 -0
- package/src/utils/city.ts +4072 -0
- package/src/utils/index.ts +155 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { View, Image, ITouchEvent } from '@tarojs/components';
|
|
4
|
+
import {
|
|
5
|
+
beforeUpload,
|
|
6
|
+
convertToDomainFile,
|
|
7
|
+
convertToUploadValue,
|
|
8
|
+
getKeyName,
|
|
9
|
+
uploadImageTypes,
|
|
10
|
+
uploadTypes,
|
|
11
|
+
uploadVideoTypes
|
|
12
|
+
} from './utils';
|
|
13
|
+
import { Utils } from '@utils';
|
|
14
|
+
import { uploadFile, UploadFileOption } from './upload';
|
|
15
|
+
import VideoView from '../VideoView';
|
|
16
|
+
import './index.scss';
|
|
17
|
+
|
|
18
|
+
export type UploadFile = {
|
|
19
|
+
url: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type UploadFileProps = {
|
|
23
|
+
host: string
|
|
24
|
+
/**
|
|
25
|
+
* 可上传文件类型
|
|
26
|
+
*/
|
|
27
|
+
fileTypes?: string[];
|
|
28
|
+
value?: any;
|
|
29
|
+
/**
|
|
30
|
+
* 最大文件大小,单位MB(暂时没有)
|
|
31
|
+
*/
|
|
32
|
+
maxSize?: number;
|
|
33
|
+
/**
|
|
34
|
+
* 最多上传多少个文件
|
|
35
|
+
* 最多是8张图片
|
|
36
|
+
*/
|
|
37
|
+
maxCount?: number;
|
|
38
|
+
/**
|
|
39
|
+
* 是否展示删除按钮
|
|
40
|
+
*/
|
|
41
|
+
showDelete?: boolean;
|
|
42
|
+
chooseType?: 'img' | 'video' | 'media'
|
|
43
|
+
dir?: string
|
|
44
|
+
/**
|
|
45
|
+
* 扩展参数
|
|
46
|
+
*/
|
|
47
|
+
extraData?: Record<string, any>
|
|
48
|
+
onChange?: (v?: any) => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface UploadFileConponent extends React.FC<UploadFileProps> {
|
|
52
|
+
upload?: (options: UploadFileOption) => Promise<string>
|
|
53
|
+
/** 文件类型 */
|
|
54
|
+
UPLOAD_TYPES: string[]
|
|
55
|
+
/** 图片类型 */
|
|
56
|
+
UPLOAD_IMAGE_TYPES: string[]
|
|
57
|
+
/** 视频类型 */
|
|
58
|
+
UPLOAD_VIDEO_TYPES: string[]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param props
|
|
64
|
+
* @returns React.ReactElement
|
|
65
|
+
*/
|
|
66
|
+
export const UploadFile: UploadFileConponent = (props) => {
|
|
67
|
+
let {
|
|
68
|
+
host,
|
|
69
|
+
value = [],
|
|
70
|
+
fileTypes = uploadImageTypes,
|
|
71
|
+
maxCount = 1,
|
|
72
|
+
showDelete = false,
|
|
73
|
+
chooseType = 'img',
|
|
74
|
+
dir,
|
|
75
|
+
extraData = {},
|
|
76
|
+
onChange: handleDomainFileChange
|
|
77
|
+
} = props
|
|
78
|
+
const [files, setFiles] = useState<UploadFile[]>([]);
|
|
79
|
+
const [loading] = useState<boolean>(false);
|
|
80
|
+
|
|
81
|
+
// maxCount = maxCount > 8 ? 8 : maxCount;
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
// 取出上传中的文件
|
|
85
|
+
const uploadValue = convertToUploadValue(value);
|
|
86
|
+
const newFileList = [...uploadValue, ...files] as UploadFile[];
|
|
87
|
+
// 设置文件列表
|
|
88
|
+
setFiles(newFileList);
|
|
89
|
+
}, [])
|
|
90
|
+
|
|
91
|
+
const handleExtraData = async (file: any, dir?: string) => {
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
key: `${dir}/${getKeyName(file)}`,
|
|
95
|
+
...extraData
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 上传图片
|
|
101
|
+
* @param index
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
const handleUploadFile = async (_: ITouchEvent, index?: number) => {
|
|
105
|
+
if (maxCount !== 1 && isNaN(index || NaN) && files.length >= maxCount) {
|
|
106
|
+
Taro.showToast({ title: `最多只能上传${maxCount}文件` })
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let chooseFn = handleChooseImage;
|
|
111
|
+
if (chooseType === 'video') {
|
|
112
|
+
chooseFn = handleChooseVideo
|
|
113
|
+
} else if (chooseType === 'media') {
|
|
114
|
+
chooseFn = handleChooseMedia
|
|
115
|
+
} else {
|
|
116
|
+
chooseFn = handleChooseImage;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
chooseFn().then(async chooseImageList => {
|
|
120
|
+
let firstChooseImageUrl: string = Array.isArray(chooseImageList) ? chooseImageList[0]!! : chooseImageList
|
|
121
|
+
const pass = beforeUpload(firstChooseImageUrl, fileTypes);
|
|
122
|
+
if (!pass) {
|
|
123
|
+
Taro.hideLoading();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (loading) return;
|
|
127
|
+
Taro.showLoading({ title: '上传中...' });
|
|
128
|
+
|
|
129
|
+
const formData = await handleExtraData(firstChooseImageUrl, dir);
|
|
130
|
+
Taro.uploadFile({
|
|
131
|
+
url: host,
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
fileType: 'image',
|
|
134
|
+
filePath: firstChooseImageUrl,
|
|
135
|
+
name: 'file',
|
|
136
|
+
header: {
|
|
137
|
+
'content-type': 'multipart/form-data'
|
|
138
|
+
},
|
|
139
|
+
formData,
|
|
140
|
+
success(res) {
|
|
141
|
+
let { statusCode } = res;
|
|
142
|
+
//do something
|
|
143
|
+
if (!/2\d/.test(statusCode as any)) {
|
|
144
|
+
Taro.hideLoading();
|
|
145
|
+
Taro.showToast({ title: '上传失败' })
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
let newFiles: UploadFile[] = Utils.cloneDeep(files);
|
|
149
|
+
let ossImgUrl = `${host}/${dir}/${getKeyName(firstChooseImageUrl)}`;
|
|
150
|
+
if (maxCount === 1) {
|
|
151
|
+
if (!newFiles[0]) {
|
|
152
|
+
newFiles.push({
|
|
153
|
+
url: ossImgUrl
|
|
154
|
+
})
|
|
155
|
+
} else {
|
|
156
|
+
newFiles[0].url = ossImgUrl
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
if (!isNaN(index || NaN)) {
|
|
160
|
+
newFiles[index || NaN].url = ossImgUrl
|
|
161
|
+
} else {
|
|
162
|
+
newFiles.push({
|
|
163
|
+
url: ossImgUrl
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
handleDomainFileChange?.(convertToDomainFile(maxCount, newFiles));
|
|
168
|
+
setFiles(newFiles);
|
|
169
|
+
Taro.hideLoading();
|
|
170
|
+
},
|
|
171
|
+
fail(res) {
|
|
172
|
+
console.error('上传失败错误信息:', res);
|
|
173
|
+
Taro.hideLoading();
|
|
174
|
+
Taro.showToast({ title: `上传失败${res?.errMsg ? `,${res?.errMsg}` : ''}` })
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 删除图片
|
|
182
|
+
* @param index
|
|
183
|
+
*/
|
|
184
|
+
const handleDeleteImg = async (e: ITouchEvent, index: number) => {
|
|
185
|
+
e.stopPropagation()
|
|
186
|
+
if (files?.length === 0) return
|
|
187
|
+
let newFiles = Utils.cloneDeep(files)
|
|
188
|
+
newFiles.splice(index, 1);
|
|
189
|
+
if (handleDomainFileChange) {
|
|
190
|
+
handleDomainFileChange(convertToDomainFile(maxCount, newFiles));
|
|
191
|
+
}
|
|
192
|
+
setFiles(newFiles)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 选择图片
|
|
197
|
+
*/
|
|
198
|
+
const handleChooseImage = (): Promise<any> => {
|
|
199
|
+
return new Promise((resolve, reject) => {
|
|
200
|
+
Taro.chooseImage({
|
|
201
|
+
count: 1,
|
|
202
|
+
// sizeType: [],
|
|
203
|
+
success(res) {
|
|
204
|
+
const tempFilePaths = res.tempFilePaths
|
|
205
|
+
resolve(tempFilePaths)
|
|
206
|
+
},
|
|
207
|
+
fail(res) {
|
|
208
|
+
reject(res)
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 选择视频
|
|
216
|
+
*/
|
|
217
|
+
const handleChooseVideo = (): Promise<any> => {
|
|
218
|
+
return new Promise((resolve, reject) => {
|
|
219
|
+
Taro.chooseVideo({
|
|
220
|
+
maxDuration: 60,
|
|
221
|
+
sourceType: ['album', 'camera'],
|
|
222
|
+
// sizeType: [],
|
|
223
|
+
success(res) {
|
|
224
|
+
const tempFilePaths = res.tempFilePath
|
|
225
|
+
resolve([tempFilePaths])
|
|
226
|
+
},
|
|
227
|
+
fail(res) {
|
|
228
|
+
reject(res)
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 选择图片视频
|
|
236
|
+
*/
|
|
237
|
+
const handleChooseMedia = (): Promise<any> => {
|
|
238
|
+
return new Promise((resolve, reject) => {
|
|
239
|
+
Taro.chooseMedia({
|
|
240
|
+
count: 1,
|
|
241
|
+
mediaType: ['image', 'video'],
|
|
242
|
+
sourceType: ['album', 'camera'],
|
|
243
|
+
maxDuration: 60,
|
|
244
|
+
camera: 'back',
|
|
245
|
+
success(res) {
|
|
246
|
+
const tempFilePaths = res.tempFiles
|
|
247
|
+
resolve(tempFilePaths)
|
|
248
|
+
},
|
|
249
|
+
fail(res) {
|
|
250
|
+
reject(res)
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let firstFile: any = files[0]
|
|
257
|
+
return (
|
|
258
|
+
<>
|
|
259
|
+
<View className='uploadImg'>
|
|
260
|
+
{
|
|
261
|
+
maxCount !== 1 &&
|
|
262
|
+
<>
|
|
263
|
+
{
|
|
264
|
+
files?.map((item: any, index) => {
|
|
265
|
+
return (
|
|
266
|
+
<View className='uploadImg__item' onClick={(e) => { handleUploadFile(e, index) }}>
|
|
267
|
+
{showDelete && <View className='deleteImg' onClick={(e) => { handleDeleteImg(e, index) }} />}
|
|
268
|
+
{
|
|
269
|
+
Utils.isImg(item?.url) && <Image src={item?.url} mode={'widthFix'} />
|
|
270
|
+
}
|
|
271
|
+
{
|
|
272
|
+
Utils.isVideo(item?.url) && <VideoView url={item?.url} />
|
|
273
|
+
}
|
|
274
|
+
</View>
|
|
275
|
+
)
|
|
276
|
+
})
|
|
277
|
+
}
|
|
278
|
+
{
|
|
279
|
+
files.length < maxCount &&
|
|
280
|
+
<View className='uploadImg__add' onClick={handleUploadFile}>
|
|
281
|
+
<View className='add_icon' />
|
|
282
|
+
</View>
|
|
283
|
+
}
|
|
284
|
+
</>
|
|
285
|
+
}
|
|
286
|
+
{maxCount === 1 &&
|
|
287
|
+
<>
|
|
288
|
+
{
|
|
289
|
+
!firstFile?.url ?
|
|
290
|
+
<View className='uploadImg__add' onClick={(e) => handleUploadFile(e)}>
|
|
291
|
+
<View className='add_icon' />
|
|
292
|
+
</View> :
|
|
293
|
+
<View className='uploadImg__item' onClick={(e) => {
|
|
294
|
+
if (Utils.isImg(firstFile?.url)) {
|
|
295
|
+
handleUploadFile(e)
|
|
296
|
+
}
|
|
297
|
+
}}>
|
|
298
|
+
{showDelete && <View className='deleteImg' onClick={(e) => { handleDeleteImg(e, 0) }} />}
|
|
299
|
+
{
|
|
300
|
+
Utils.isImg(firstFile?.url) &&
|
|
301
|
+
<Image src={firstFile?.url!} mode={'widthFix'} />
|
|
302
|
+
}
|
|
303
|
+
{
|
|
304
|
+
Utils.isVideo(firstFile?.url) && <VideoView url={firstFile?.url} />
|
|
305
|
+
}
|
|
306
|
+
</View>
|
|
307
|
+
}
|
|
308
|
+
</>
|
|
309
|
+
}
|
|
310
|
+
</View>
|
|
311
|
+
</>
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
UploadFile.upload = uploadFile;
|
|
316
|
+
UploadFile.UPLOAD_TYPES = uploadTypes;
|
|
317
|
+
UploadFile.UPLOAD_IMAGE_TYPES = uploadImageTypes;
|
|
318
|
+
UploadFile.UPLOAD_VIDEO_TYPES = uploadVideoTypes;
|
|
319
|
+
|
|
320
|
+
export default UploadFile;
|
|
321
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Taro from "@tarojs/taro"
|
|
2
|
+
import { beforeUpload, getKeyName, uploadImageTypes } from "./utils";
|
|
3
|
+
|
|
4
|
+
export type UploadFileOption = {
|
|
5
|
+
file: string
|
|
6
|
+
dir: string
|
|
7
|
+
/**
|
|
8
|
+
* 扩展参数
|
|
9
|
+
*/
|
|
10
|
+
extraData?: Record<string, any>
|
|
11
|
+
host: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const handleExtraData = async (file: any, dir: string, extraData?: Record<string, any>) => {
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
key: `${dir}/${getKeyName(file)}`,
|
|
18
|
+
...extraData
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 上传头像到服务器
|
|
23
|
+
export const uploadFile = (options: UploadFileOption): Promise<string> => {
|
|
24
|
+
const { file, dir, extraData, host } = options;
|
|
25
|
+
const pass = beforeUpload(file, uploadImageTypes);
|
|
26
|
+
|
|
27
|
+
return new Promise(async (resolve) => {
|
|
28
|
+
if (!pass) {
|
|
29
|
+
Taro.hideLoading();
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const extraFormData = await handleExtraData(file, dir, extraData)
|
|
34
|
+
|
|
35
|
+
Taro.uploadFile({
|
|
36
|
+
url: host,
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
fileType: 'image',
|
|
39
|
+
filePath: file,
|
|
40
|
+
name: 'file',
|
|
41
|
+
header: {
|
|
42
|
+
'content-type': 'multipart/form-data'
|
|
43
|
+
},
|
|
44
|
+
formData: extraFormData,
|
|
45
|
+
success(res) {
|
|
46
|
+
let { statusCode } = res;
|
|
47
|
+
if (!/2\d/.test(statusCode as any)) {
|
|
48
|
+
Taro.hideLoading();
|
|
49
|
+
Taro.showToast({ title: '上传失败' })
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let ossImgUrl = `${host}/${dir}/${getKeyName(file)}`;
|
|
53
|
+
resolve(ossImgUrl)
|
|
54
|
+
Taro.hideLoading();
|
|
55
|
+
},
|
|
56
|
+
fail(res) {
|
|
57
|
+
console.error('上传失败错误信息:', res);
|
|
58
|
+
Taro.hideLoading();
|
|
59
|
+
Taro.showToast({ title: `上传失败${res?.errMsg ? `,${res?.errMsg}` : ''}` })
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import Taro from "@tarojs/taro";
|
|
2
|
+
import UploadFile from ".";
|
|
3
|
+
|
|
4
|
+
export const uploadTypes = ['.rar', '.zip', '.doc', '.docx', '.pdf', '.txt', '.svg', '.png', '.image', '.mp4'];
|
|
5
|
+
export const uploadImageTypes = ['.gif', '.png', '.jpg', '.jpeg', '.image'];
|
|
6
|
+
export const uploadVideoTypes = ['.mp4'];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 将业务文件转换为上传文件
|
|
10
|
+
* @param v
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export const convertToUploadValue = (v: string[] | string): any => {
|
|
14
|
+
if (Array.isArray(v)) {
|
|
15
|
+
if (!v || v === undefined || v === null) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (v as any[]).map((it) => ({
|
|
20
|
+
url: it
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 将上传文件转换为业务文件
|
|
27
|
+
* @param {number} maxCount
|
|
28
|
+
* @param v
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export const convertToDomainFile = (maxCount: number, v?: UploadFile[]): any => {
|
|
32
|
+
if (maxCount > 1) {
|
|
33
|
+
if (!v) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
return v.map((it) => {
|
|
37
|
+
return {
|
|
38
|
+
url: it.url,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (!v) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const it = v[0];
|
|
46
|
+
return {
|
|
47
|
+
url: it.url,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const beforeUpload = (file: string, verifyTypes: string[]): boolean => {
|
|
52
|
+
const isMatchType = verifyTypes.indexOf(file.replace(/.+\./, '.').toLowerCase()) !== -1;
|
|
53
|
+
if (!isMatchType) {
|
|
54
|
+
Taro.showModal({ title: `文件格式只支持:${verifyTypes.join(',')}` })
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// const isLimitSize = file.size / 1024 / 1024 < 8;
|
|
58
|
+
// if (!isLimitSize) {
|
|
59
|
+
// utils.showToastError({ title: `文件必须小于${maxSize}MB` });
|
|
60
|
+
// return false;
|
|
61
|
+
// }
|
|
62
|
+
return true;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const getKeyName = (file: string) => {
|
|
66
|
+
|
|
67
|
+
let key = file;
|
|
68
|
+
if (file?.split("http://tmp/").length === 2) {
|
|
69
|
+
key = file?.split("http://tmp/")[1];
|
|
70
|
+
}
|
|
71
|
+
if (file?.split("https://resource/").length === 2) {
|
|
72
|
+
key = file?.split("https://resource/")[1];
|
|
73
|
+
}
|
|
74
|
+
if (file?.replace(/.+\./, '.').toLowerCase() === '.image') {
|
|
75
|
+
key = key?.replace('.image', '.png')
|
|
76
|
+
}
|
|
77
|
+
if (file?.replace(/.+\./, '.').toLowerCase() === '.video') {
|
|
78
|
+
key = key?.replace('.video', '.mp4')
|
|
79
|
+
}
|
|
80
|
+
return key;
|
|
81
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Video, View } from '@tarojs/components';
|
|
3
|
+
|
|
4
|
+
export type VideoViewProps = {
|
|
5
|
+
url: string
|
|
6
|
+
hasToH5Show?: boolean
|
|
7
|
+
width?: number
|
|
8
|
+
height?: number
|
|
9
|
+
onH5Open?: (url: string) => void
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 视频显示
|
|
14
|
+
*/
|
|
15
|
+
const VideoView: React.FC<VideoViewProps> = (props) => {
|
|
16
|
+
const {
|
|
17
|
+
url,
|
|
18
|
+
hasToH5Show = true,
|
|
19
|
+
width,
|
|
20
|
+
height,
|
|
21
|
+
onH5Open
|
|
22
|
+
} = props;
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<View
|
|
27
|
+
style={{
|
|
28
|
+
width,
|
|
29
|
+
height
|
|
30
|
+
}}
|
|
31
|
+
onClick={() => {
|
|
32
|
+
if (!hasToH5Show) return
|
|
33
|
+
onH5Open?.(url);
|
|
34
|
+
}}>
|
|
35
|
+
<Video
|
|
36
|
+
id='myvideo'
|
|
37
|
+
src={url}
|
|
38
|
+
initialTime={0}
|
|
39
|
+
controls={false}
|
|
40
|
+
autoplay={false}
|
|
41
|
+
loop={false}
|
|
42
|
+
muted={false}
|
|
43
|
+
showPlayBtn={false}
|
|
44
|
+
/>
|
|
45
|
+
</View>
|
|
46
|
+
</>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default VideoView;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { default as BottomPopup} from './BottomPopup'
|
|
2
|
+
export { default as Card} from './Card'
|
|
3
|
+
export { default as Modal} from './Modal'
|
|
4
|
+
export { default as NavBar} from './NavBar'
|
|
5
|
+
export { default as Page} from './Page'
|
|
6
|
+
export { default as PullToPushRefresh} from './PullToPushRefresh'
|
|
7
|
+
export { default as Tabs } from './Tabs';
|
|
8
|
+
export { default as VideoView } from './VideoView';
|
|
9
|
+
export { default as UploadFile } from './UploadFile';
|
|
10
|
+
export { default as Radio } from './Radio';
|
|
11
|
+
export { default as DataSelect } from './DataSelect';
|
|
12
|
+
|
|
13
|
+
export type { BottomPopupProps } from './BottomPopup'
|
|
14
|
+
export type { CardProps} from './Card'
|
|
15
|
+
export type { ModalProps} from './Modal'
|
|
16
|
+
export type { NavBarProps} from './NavBar'
|
|
17
|
+
export type { PageProps} from './Page'
|
|
18
|
+
export type { PullToPushRefreshProps} from './PullToPushRefresh'
|
|
19
|
+
export type { TabsProps } from './Tabs';
|
|
20
|
+
export type { VideoViewProps } from './VideoView';
|
|
21
|
+
export type { UploadFileProps } from './UploadFile';
|
|
22
|
+
export type { RadioProps } from './Radio';
|
|
23
|
+
export type { DataSelectProps } from './DataSelect';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { View } from '@tarojs/components';
|
|
3
|
+
import CitySelectModal, { CityData } from '../CitySelectModal';
|
|
4
|
+
import './index.scss';
|
|
5
|
+
|
|
6
|
+
export type CitySelectButtonProps = {
|
|
7
|
+
className?: string
|
|
8
|
+
onChange?: (value: CityData) => void;
|
|
9
|
+
/**
|
|
10
|
+
* @param {CityData} value
|
|
11
|
+
* @returns {React.ReactElement}
|
|
12
|
+
*/
|
|
13
|
+
buttonRender: (value: CityData) => React.ReactElement
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 顶部选择城市按钮
|
|
18
|
+
*/
|
|
19
|
+
const CitySelectButton: React.FC<CitySelectButtonProps> = (props) => {
|
|
20
|
+
const {
|
|
21
|
+
className,
|
|
22
|
+
onChange,
|
|
23
|
+
buttonRender
|
|
24
|
+
} = props;
|
|
25
|
+
const [visible, setVisible] = useState<boolean>(false);
|
|
26
|
+
const [currentCity, setCurrentCity] = useState<CityData>(null as any);
|
|
27
|
+
|
|
28
|
+
const handleSelectCity = () => {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
if (process.env.TARO_ENV !== 'alipay') {
|
|
31
|
+
setVisible(true)
|
|
32
|
+
return
|
|
33
|
+
} else {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
my.chooseCity({
|
|
36
|
+
showLocatedCity: true,
|
|
37
|
+
showHotCities: true,
|
|
38
|
+
success: async (result: any) => {
|
|
39
|
+
let { adCode, city } = result;
|
|
40
|
+
const cityCode = adCode.slice(3, 4) === '0' ? adCode.replace(/000/, '010') : adCode;
|
|
41
|
+
console.log(cityCode)
|
|
42
|
+
let currentCity = {
|
|
43
|
+
id: cityCode,
|
|
44
|
+
value: city,
|
|
45
|
+
}
|
|
46
|
+
setCurrentCity(currentCity)
|
|
47
|
+
onChange?.(currentCity)
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
<View className={className} onClick={handleSelectCity}>
|
|
56
|
+
{buttonRender(currentCity)}
|
|
57
|
+
</View>
|
|
58
|
+
|
|
59
|
+
{
|
|
60
|
+
visible && (
|
|
61
|
+
<CitySelectModal
|
|
62
|
+
visible={visible}
|
|
63
|
+
onChange={(city) => {
|
|
64
|
+
setCurrentCity(city)
|
|
65
|
+
onChange?.(city)
|
|
66
|
+
setVisible(false)
|
|
67
|
+
}}
|
|
68
|
+
onClose={() => setVisible(false)}
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
</>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default CitySelectButton
|