@cloudbase/weda-ui 0.2.15 → 0.2.16
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 +10 -7
- package/src/configs/components/calendar.json +75 -0
- package/src/configs/components/carousel.json +273 -0
- package/src/configs/components/chart/statisticsCard.json +331 -0
- package/src/configs/components/dataView.json +139 -0
- package/src/configs/components/form/location.json +152 -0
- package/src/configs/components/form/uploaderFile.json +2 -1
- package/src/configs/components/graphicCard.json +399 -0
- package/src/configs/components/link.json +2 -2
- package/src/configs/components/listView.json +230 -0
- package/src/configs/components/navLayout.json +350 -0
- package/src/configs/components/swiper.json +3 -3
- package/src/configs/index.js +16 -0
- package/src/mp/components/button/index.js +12 -13
- package/src/mp/components/button/index.wxml +1 -1
- package/src/mp/components/calendar/arrowright--line.svg +11 -0
- package/src/mp/components/calendar/index.js +238 -0
- package/src/mp/components/calendar/index.json +4 -0
- package/src/mp/components/calendar/index.wxml +37 -0
- package/src/mp/components/calendar/index.wxss +178 -0
- package/src/mp/components/carousel/index.js +88 -0
- package/src/mp/components/carousel/index.json +7 -0
- package/src/mp/components/carousel/index.wxml +6 -0
- package/src/mp/components/chart/statisticsCard/index.js +226 -0
- package/src/mp/components/chart/statisticsCard/index.json +4 -0
- package/src/mp/components/chart/statisticsCard/index.wxml +9 -0
- package/src/mp/components/chart/statisticsCard/index.wxss +45 -0
- package/src/mp/components/dataView/index.js +34 -0
- package/src/mp/components/dataView/index.json +7 -0
- package/src/mp/components/dataView/index.wxml +15 -0
- package/src/mp/components/dataView/index.wxss +0 -0
- package/src/mp/components/form/location/components/mapChoose/index.js +201 -0
- package/src/mp/components/form/location/components/mapChoose/index.json +4 -0
- package/src/mp/components/form/location/components/mapChoose/index.wxml +42 -0
- package/src/mp/components/form/location/components/mapChoose/index.wxss +188 -0
- package/src/mp/components/form/location/index.js +341 -0
- package/src/mp/components/form/location/index.json +6 -0
- package/src/mp/components/form/location/index.wxml +25 -0
- package/src/mp/components/form/location/index.wxss +91 -0
- package/src/mp/components/form/uploader/index.js +39 -35
- package/src/mp/components/form/uploaderFile/index.js +61 -14
- package/src/mp/components/graphicCard/chevron-right.svg +3 -0
- package/src/mp/components/graphicCard/index.js +205 -0
- package/src/mp/components/graphicCard/index.json +4 -0
- package/src/mp/components/graphicCard/index.wxml +29 -0
- package/src/mp/components/graphicCard/index.wxss +157 -0
- package/src/mp/components/image/index.js +0 -1
- package/src/mp/components/listView/arrow-right-line.svg +3 -0
- package/src/mp/components/listView/index.js +286 -0
- package/src/mp/components/listView/index.json +4 -0
- package/src/mp/components/listView/index.wxml +40 -0
- package/src/mp/components/listView/index.wxss +150 -0
- package/src/mp/components/listView/more-line.svg +3 -0
- package/src/mp/components/navLayout/index.js +123 -0
- package/src/mp/components/navLayout/index.json +7 -0
- package/src/mp/components/navLayout/index.wxml +25 -0
- package/src/mp/components/navLayout/index.wxss +1193 -0
- package/src/mp/components/swiper/index.wxml +2 -0
- package/src/mp/index.json +9 -1
- package/src/mp/utils/debounce.js +133 -0
- package/src/mp/utils/dr_square_point.js +25 -0
- package/src/mp/utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js +1336 -0
- package/src/mp/utils/spark-md5.js +776 -0
- package/src/mp/utils/tcb.js +18 -0
- package/src/web/components/calendar/index.css +382 -0
- package/src/web/components/calendar/index.jsx +312 -0
- package/src/web/components/calendar/util.js +90 -0
- package/src/web/components/carousel/index.css +119 -0
- package/src/web/components/carousel/index.tsx +417 -0
- package/src/web/components/chart/statisticsCard/index.css +62 -0
- package/src/web/components/chart/statisticsCard/index.tsx +286 -0
- package/src/web/components/chart/statisticsCard/interface.ts +14 -0
- package/src/web/components/dataView/index.tsx +20 -0
- package/src/web/components/dataView/interface.ts +6 -0
- package/src/web/components/form/location/common/mapChoose.css +178 -0
- package/src/web/components/form/location/common/mapChoose.jsx +343 -0
- package/src/web/components/form/location/common/mapView.jsx +190 -0
- package/src/web/components/form/location/common/propsConfig.js +54 -0
- package/src/web/components/form/location/common/selectModal.css +44 -0
- package/src/web/components/form/location/common/selectModal.jsx +82 -0
- package/src/web/components/form/location/common/useLocationInfo.js +100 -0
- package/src/web/components/form/location/components/LocationH5/index.css +243 -0
- package/src/web/components/form/location/components/LocationH5/location.h5.jsx +403 -0
- package/src/web/components/form/location/components/LocationPC/Header.jsx +109 -0
- package/src/web/components/form/location/components/LocationPC/index.css +44 -0
- package/src/web/components/form/location/components/LocationPC/location.PC.jsx +323 -0
- package/src/web/components/form/location/constants.js +4 -0
- package/src/web/components/form/location/index.css +0 -0
- package/src/web/components/form/location/index.jsx +25 -0
- package/src/web/components/form/uploader/uploader.h5.tsx +16 -10
- package/src/web/components/form/uploader/uploader.pc.tsx +15 -11
- package/src/web/components/form/uploaderFile/uploadFile.h5.tsx +122 -107
- package/src/web/components/form/uploaderFile/uploadFile.pc.tsx +22 -19
- package/src/web/components/graphicCard/index.css +163 -0
- package/src/web/components/graphicCard/index.tsx +309 -0
- package/src/web/components/image/image.tsx +0 -1
- package/src/web/components/index.js +12 -0
- package/src/web/components/listView/arrow-right-line.svg +3 -0
- package/src/web/components/listView/index.css +139 -0
- package/src/web/components/listView/index.tsx +354 -0
- package/src/web/components/listView/interface.ts +98 -0
- package/src/web/components/navLayout/index.css +332 -0
- package/src/web/components/navLayout/index.tsx +247 -0
- package/src/web/components/tabs/index.tsx +2 -2
- package/src/web/components/tabs/tabs.h5.tsx +7 -4
- package/src/web/components/uploaderFileView/index.css +9 -9
- package/src/web/components/uploaderFileView/index.jsx +32 -23
- package/src/web/types.d.ts +15 -14
- package/src/web/utils/debounce.js +98 -0
- package/src/web/utils/platform.js +31 -0
- package/src/web/utils/tcb.js +35 -0
- package/src/web/utils/tmap.js +4 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ConfigProvider } from 'tea-component';
|
|
3
|
+
|
|
4
|
+
import classNames from '../../../../../utils/classnames';
|
|
5
|
+
import weui from '../../../../../utils/weui';
|
|
6
|
+
import { renderDecorator } from '../../../renderDecorator';
|
|
7
|
+
|
|
8
|
+
import MapView from '../../common/mapView';
|
|
9
|
+
import SelectModal from '../../common/selectModal';
|
|
10
|
+
import useLocationInfo from '../../common/useLocationInfo';
|
|
11
|
+
import { propTypes, defaultProps } from '../../common/propsConfig';
|
|
12
|
+
import { callDataSource } from '../../../../../utils/tcb';
|
|
13
|
+
import Header from './Header';
|
|
14
|
+
|
|
15
|
+
import './index.css';
|
|
16
|
+
|
|
17
|
+
const { useState, useEffect, useRef } = React;
|
|
18
|
+
|
|
19
|
+
export default function LocationPC(props) {
|
|
20
|
+
// 属性、变量
|
|
21
|
+
const {
|
|
22
|
+
// 系统属性
|
|
23
|
+
id,
|
|
24
|
+
className,
|
|
25
|
+
style,
|
|
26
|
+
events,
|
|
27
|
+
// 组件属性
|
|
28
|
+
value,
|
|
29
|
+
label,
|
|
30
|
+
labelVisible,
|
|
31
|
+
customLocation,
|
|
32
|
+
locationType,
|
|
33
|
+
showLngLat,
|
|
34
|
+
showMap,
|
|
35
|
+
drag,
|
|
36
|
+
zoom,
|
|
37
|
+
disabled,
|
|
38
|
+
requiredFlag,
|
|
39
|
+
decorator,
|
|
40
|
+
dataSource,
|
|
41
|
+
} = props;
|
|
42
|
+
const cls = classNames({
|
|
43
|
+
'weda-ui': true,
|
|
44
|
+
cloudbase_standard: true,
|
|
45
|
+
[className]: className,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const [isSelectMapVisible, setIsSelectMapVisible] = useState(false);
|
|
49
|
+
const [dataSourceStatus, setDataSourceStatus] = useState({
|
|
50
|
+
status: false,
|
|
51
|
+
message: '连接器初始化中',
|
|
52
|
+
});
|
|
53
|
+
const [userSelectStatus, setUserSelectStatus] = useState('default');
|
|
54
|
+
const [APIKEY, setAPIKEY] = useState('');
|
|
55
|
+
|
|
56
|
+
const eventsChange = (value, noaddr) => {
|
|
57
|
+
const { poiname, latitude, longitude } = value;
|
|
58
|
+
let res = {
|
|
59
|
+
address: poiname,
|
|
60
|
+
geopoint: {
|
|
61
|
+
coordinates: [latitude, longitude],
|
|
62
|
+
type: 'Point',
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
if (noaddr) {
|
|
66
|
+
res = null;
|
|
67
|
+
}
|
|
68
|
+
events.change &&
|
|
69
|
+
events.change({
|
|
70
|
+
value: res,
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const {
|
|
74
|
+
location,
|
|
75
|
+
setLocation,
|
|
76
|
+
apiKeyStatus,
|
|
77
|
+
setApiKeyStatus,
|
|
78
|
+
currentLocStatus,
|
|
79
|
+
currentLocations,
|
|
80
|
+
} = useLocationInfo({
|
|
81
|
+
apiKey: APIKEY,
|
|
82
|
+
locationType,
|
|
83
|
+
dataSourceStatus,
|
|
84
|
+
eventsChange,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (value || !currentLocations.current) return;
|
|
89
|
+
setUserSelectStatus('default');
|
|
90
|
+
// 重置表单时
|
|
91
|
+
const {
|
|
92
|
+
poiname,
|
|
93
|
+
latlng: { lat, lng },
|
|
94
|
+
} = currentLocations.current;
|
|
95
|
+
let location = {
|
|
96
|
+
poiname,
|
|
97
|
+
latlng: { lat, lng },
|
|
98
|
+
};
|
|
99
|
+
if (locationType === 1) {
|
|
100
|
+
location.locationType = 1;
|
|
101
|
+
eventsChange({}, true);
|
|
102
|
+
} else if (locationType === 2) {
|
|
103
|
+
eventsChange({
|
|
104
|
+
latitude: lat,
|
|
105
|
+
longitude: lng,
|
|
106
|
+
poiname: poiname,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
setLocation(location);
|
|
110
|
+
}, [value, locationType]);
|
|
111
|
+
|
|
112
|
+
// 事件
|
|
113
|
+
const handleChooseLocation = () => {
|
|
114
|
+
if (disabled) return;
|
|
115
|
+
if (!dataSourceStatus.status) return weui.alert(dataSourceStatus.message);
|
|
116
|
+
if (!apiKeyStatus.status) return weui.alert(apiKeyStatus.message);
|
|
117
|
+
if (!currentLocStatus) return weui.alert('获取当前位置信息中,请稍等');
|
|
118
|
+
setIsSelectMapVisible(true);
|
|
119
|
+
};
|
|
120
|
+
const onChangeLocation = (value) => {
|
|
121
|
+
const { poiname, latlng } = value;
|
|
122
|
+
events.change &&
|
|
123
|
+
events.change({
|
|
124
|
+
value: {
|
|
125
|
+
address: poiname,
|
|
126
|
+
geopoint: {
|
|
127
|
+
coordinates: [latlng.lat, latlng.lng],
|
|
128
|
+
type: 'Point',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
setUserSelectStatus('selected');
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
// 调用连接器数据源方法
|
|
137
|
+
if (dataSource.name) {
|
|
138
|
+
callDataSource({
|
|
139
|
+
dataSourceName: dataSource.name,
|
|
140
|
+
methodName: 'getApiKey',
|
|
141
|
+
})
|
|
142
|
+
.then((res) => {
|
|
143
|
+
if (res.apiKey) {
|
|
144
|
+
setAPIKEY(res.apiKey);
|
|
145
|
+
setDataSourceStatus({
|
|
146
|
+
status: true,
|
|
147
|
+
message: '',
|
|
148
|
+
});
|
|
149
|
+
setApiKeyStatus({ status: true, message: '' });
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
.catch((error) => {
|
|
153
|
+
console.log('datasources error', error);
|
|
154
|
+
setDataSourceStatus({
|
|
155
|
+
status: false,
|
|
156
|
+
message: error,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
setDataSourceStatus({
|
|
161
|
+
status: false,
|
|
162
|
+
message: '"地图定位组件"需进行地图配置,请检查',
|
|
163
|
+
});
|
|
164
|
+
weui.alert('"地图定位组件"需进行地图配置,请检查');
|
|
165
|
+
}
|
|
166
|
+
}, [dataSource]);
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
let loc = {
|
|
170
|
+
latlng: {
|
|
171
|
+
lat: 39.98410411,
|
|
172
|
+
lng: 116.307503,
|
|
173
|
+
},
|
|
174
|
+
poiname: '',
|
|
175
|
+
locationType,
|
|
176
|
+
};
|
|
177
|
+
switch (locationType) {
|
|
178
|
+
case 2:
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
loc = {
|
|
181
|
+
latlng: {
|
|
182
|
+
lat: location.latlng.lat,
|
|
183
|
+
lng: location.latlng.lng,
|
|
184
|
+
},
|
|
185
|
+
poiname: location.poiname,
|
|
186
|
+
};
|
|
187
|
+
break;
|
|
188
|
+
case 3:
|
|
189
|
+
if (checkCustomLocation(customLocation)) {
|
|
190
|
+
weui.alert('位置输入格式错误 请检查');
|
|
191
|
+
} else {
|
|
192
|
+
// @ts-ignore
|
|
193
|
+
loc = {
|
|
194
|
+
latlng: {
|
|
195
|
+
lat: customLocation.latitude,
|
|
196
|
+
lng: customLocation.longitude,
|
|
197
|
+
},
|
|
198
|
+
poiname: customLocation.poiname,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
setLocation(loc);
|
|
204
|
+
// 暂不支持自定位置,初始化表单值都是null
|
|
205
|
+
eventsChange(
|
|
206
|
+
{
|
|
207
|
+
latitude: loc.latlng.lat,
|
|
208
|
+
longitude: loc.latlng.lng,
|
|
209
|
+
poiname: loc.poiname,
|
|
210
|
+
},
|
|
211
|
+
true
|
|
212
|
+
);
|
|
213
|
+
}, [locationType]);
|
|
214
|
+
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
if (locationType != 3) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (checkCustomLocation(customLocation)) {
|
|
220
|
+
weui.alert('位置输入格式错误 请检查');
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
let { latitude, longitude, poiname } = customLocation;
|
|
224
|
+
let loc = {
|
|
225
|
+
latlng: {
|
|
226
|
+
lat: latitude,
|
|
227
|
+
lng: longitude,
|
|
228
|
+
},
|
|
229
|
+
poiname: poiname,
|
|
230
|
+
};
|
|
231
|
+
setLocation(loc);
|
|
232
|
+
}, [customLocation, locationType]);
|
|
233
|
+
|
|
234
|
+
const checkCustomLocation = (params) => {
|
|
235
|
+
let { latitude, longitude } = params;
|
|
236
|
+
let message = '';
|
|
237
|
+
if (Object.prototype.toString.call(params) !== '[object Object]') {
|
|
238
|
+
return (message = '位置输入格式错误 请检查');
|
|
239
|
+
} else if (!latitude || !Number(latitude)) {
|
|
240
|
+
return (message = '位置输入格式错误 请检查');
|
|
241
|
+
} else if (!longitude || !Number(longitude)) {
|
|
242
|
+
return (message = '位置输入格式错误 请检查');
|
|
243
|
+
} else if (!params) {
|
|
244
|
+
return (message = '位置输入格式错误 请检查');
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const getIsShowMap = () => {
|
|
249
|
+
let status = showMap;
|
|
250
|
+
// @ts-ignore
|
|
251
|
+
if (locationType === 1 && location.locationType === 1) {
|
|
252
|
+
status = false;
|
|
253
|
+
} else if (locationType === 2 && !dataSourceStatus.status) {
|
|
254
|
+
status = false;
|
|
255
|
+
} else if (locationType === 2 && !apiKeyStatus.status) {
|
|
256
|
+
status = false;
|
|
257
|
+
} else if (!currentLocStatus) {
|
|
258
|
+
status = false;
|
|
259
|
+
}
|
|
260
|
+
return status;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const LocationEl = (
|
|
264
|
+
<ConfigProvider classPrefix="wedatea2td">
|
|
265
|
+
<div
|
|
266
|
+
className={classNames(
|
|
267
|
+
'wedatea2td-form__controls wedatea2td-form__controls_wrap',
|
|
268
|
+
className
|
|
269
|
+
)}
|
|
270
|
+
style={style}
|
|
271
|
+
data-testid="_weda-fn-map"
|
|
272
|
+
>
|
|
273
|
+
<div className="_weda-fn-map">
|
|
274
|
+
<Header
|
|
275
|
+
isEdit={userSelectStatus === 'selected'}
|
|
276
|
+
info={location}
|
|
277
|
+
onClick={handleChooseLocation}
|
|
278
|
+
disabled={disabled}
|
|
279
|
+
showLngLat={showLngLat}
|
|
280
|
+
locationType={locationType}
|
|
281
|
+
apiKeyStatus={apiKeyStatus}
|
|
282
|
+
currentLocStatus={currentLocStatus}
|
|
283
|
+
dataSourceStatus={dataSourceStatus.status}
|
|
284
|
+
/>
|
|
285
|
+
{getIsShowMap() ? (
|
|
286
|
+
<div className={classNames('form-location-map-pc')}>
|
|
287
|
+
<MapView
|
|
288
|
+
APIKEY={APIKEY}
|
|
289
|
+
drag={drag}
|
|
290
|
+
zoom={zoom}
|
|
291
|
+
latlng={location.latlng}
|
|
292
|
+
/>
|
|
293
|
+
</div>
|
|
294
|
+
) : null}
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
<SelectModal
|
|
298
|
+
isSelectMapVisible={isSelectMapVisible}
|
|
299
|
+
setIsSelectMapVisible={setIsSelectMapVisible}
|
|
300
|
+
location={location}
|
|
301
|
+
setLocation={setLocation}
|
|
302
|
+
APIKEY={APIKEY}
|
|
303
|
+
chooseLocation={onChangeLocation}
|
|
304
|
+
/>
|
|
305
|
+
</ConfigProvider>
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
return renderDecorator(
|
|
309
|
+
LocationEl,
|
|
310
|
+
decorator
|
|
311
|
+
)({
|
|
312
|
+
id,
|
|
313
|
+
className: cls,
|
|
314
|
+
style,
|
|
315
|
+
label: labelVisible ? label : null,
|
|
316
|
+
multiCell: false,
|
|
317
|
+
requiredFlag,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
LocationPC.propTypes = propTypes;
|
|
322
|
+
|
|
323
|
+
LocationPC.defaultProps = defaultProps;
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ConfigProvider } from 'tea-component';
|
|
3
|
+
import './index.css';
|
|
4
|
+
import { usePlatform } from '../../../utils/platform';
|
|
5
|
+
import LocationH5 from './components/LocationH5/location.h5';
|
|
6
|
+
import LocationPC from './components/LocationPC/location.PC';
|
|
7
|
+
|
|
8
|
+
export default function Location(props) {
|
|
9
|
+
const platform = usePlatform();
|
|
10
|
+
|
|
11
|
+
if (props?.showType === 'pc') {
|
|
12
|
+
return <LocationPC {...props} />;
|
|
13
|
+
}
|
|
14
|
+
if (props?.showType === 'h5') {
|
|
15
|
+
return <LocationH5 {...props} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return platform === 'h5' ? (
|
|
19
|
+
<ConfigProvider classPrefix="wedatea2td">
|
|
20
|
+
<LocationH5 {...props} />
|
|
21
|
+
</ConfigProvider>
|
|
22
|
+
) : (
|
|
23
|
+
<LocationPC {...props} />
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -7,6 +7,7 @@ import { useSyncValue } from '../../../utils/useSyncValue';
|
|
|
7
7
|
import { isCloudFileID } from '../../../utils/platform';
|
|
8
8
|
import { IMAGE_TYPES } from './uploader.pc';
|
|
9
9
|
import { CommonFormPropsType } from '../types';
|
|
10
|
+
import SparkMD5 from 'spark-md5';
|
|
10
11
|
|
|
11
12
|
const uploadPath = 'weda-uploader';
|
|
12
13
|
/**
|
|
@@ -87,16 +88,21 @@ export function ImageUploaderH5({
|
|
|
87
88
|
setUploading(true);
|
|
88
89
|
getCloudInstance().then(async (tcb) => {
|
|
89
90
|
try {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
const fileReader = new FileReader();
|
|
92
|
+
fileReader.readAsBinaryString(file);
|
|
93
|
+
fileReader.onload = async function (e) {
|
|
94
|
+
const md5Path = SparkMD5.hashBinary(e.target.result);
|
|
95
|
+
const fileType = file.type.split('/')?.[1];
|
|
96
|
+
const cloudPath = `${uploadPath}/${md5Path}-${file?.name}`;
|
|
97
|
+
const { fileID } = await tcb.uploadFile({
|
|
98
|
+
cloudPath,
|
|
99
|
+
filePath: file,
|
|
100
|
+
onUploadProgress: onProgress,
|
|
101
|
+
});
|
|
102
|
+
// @ts-expect-error TODO
|
|
103
|
+
fileID && setInputValue((list) => [...list, fileID]);
|
|
104
|
+
fileID && events.success && events.success({ value: fileID, file });
|
|
105
|
+
};
|
|
100
106
|
} catch (err) {
|
|
101
107
|
events.error && events.error(err);
|
|
102
108
|
} finally {
|
|
@@ -8,13 +8,12 @@ import {
|
|
|
8
8
|
ImagePreview,
|
|
9
9
|
ConfigProvider,
|
|
10
10
|
} from 'tea-component';
|
|
11
|
-
import { v4 } from 'uuid';
|
|
12
11
|
import classNames from '../../../utils/classnames';
|
|
13
12
|
import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
|
|
14
13
|
import { isCloudFileID } from '../../../utils/platform';
|
|
15
14
|
import isObjectEqual from '../../../utils/isObjectEqual';
|
|
16
15
|
import { H5UploaderProps } from './uploader.h5';
|
|
17
|
-
|
|
16
|
+
import SparkMD5 from 'spark-md5';
|
|
18
17
|
// 默认组件类前缀
|
|
19
18
|
export const CLASS_PREFIX = 'weda-uploader-pc';
|
|
20
19
|
// 默认图片类型
|
|
@@ -131,15 +130,20 @@ export function UploaderPCInner(props) {
|
|
|
131
130
|
setUploading(true);
|
|
132
131
|
getCloudInstance().then(async (tcb) => {
|
|
133
132
|
try {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
133
|
+
const fileReader = new FileReader();
|
|
134
|
+
fileReader.readAsBinaryString(file);
|
|
135
|
+
fileReader.onload = async function (e) {
|
|
136
|
+
const md5Path = SparkMD5.hashBinary(e.target.result);
|
|
137
|
+
const fileType = file.type.split('/')?.[1];
|
|
138
|
+
const cloudPath = `${uploadPath}/${md5Path}-${file?.name}`;
|
|
139
|
+
const { fileID } = await tcb.uploadFile({
|
|
140
|
+
cloudPath,
|
|
141
|
+
filePath: file,
|
|
142
|
+
onUploadProgress: onProgress,
|
|
143
|
+
});
|
|
144
|
+
fileID && setfileIDList((list) => [...list, fileID]);
|
|
145
|
+
fileID && events.success && events.success({ value: fileID, file });
|
|
146
|
+
};
|
|
143
147
|
} catch (e) {
|
|
144
148
|
events.error && events.error({ value: e, file });
|
|
145
149
|
} finally {
|