@tarojs/taro-h5 3.4.0-beta.2 → 3.4.0-beta.3
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/dist/api/ad/index.js +4 -0
- package/dist/api/ai/facial.js +5 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +3 -0
- package/dist/api/alipay/index.js +3 -0
- package/dist/api/base/crypto.js +3 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +17 -0
- package/dist/api/base/performance.js +4 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +57 -0
- package/dist/api/base/system/network.js +63 -0
- package/dist/api/base/update.js +4 -0
- package/dist/api/base/weapp/app-event.js +18 -0
- package/dist/api/base/weapp/life-cycle.js +4 -0
- package/dist/api/canvas/CanvasContext.js +191 -0
- package/dist/api/canvas/canvasGetImageData.js +25 -0
- package/dist/api/canvas/canvasPutImageData.js +22 -0
- package/dist/api/canvas/canvasToTempFilePath.js +22 -0
- package/dist/api/canvas/createCanvasContext.js +16 -0
- package/dist/api/canvas/index.js +8 -0
- package/dist/api/cloud/index.js +17 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +83 -0
- package/dist/api/device/accessibility.js +3 -0
- package/dist/api/device/battery.js +4 -0
- package/dist/api/device/bluetooth-ble.js +18 -0
- package/dist/api/device/bluetooth-peripheral.js +5 -0
- package/dist/api/device/bluetooth.js +15 -0
- package/dist/api/device/calendar.js +4 -0
- package/dist/api/device/clipboard.js +65 -0
- package/dist/api/device/compass.js +64 -0
- package/dist/api/device/contact.js +4 -0
- package/dist/api/device/crypto.js +3 -0
- package/dist/api/device/gyroscope.js +6 -0
- package/dist/api/device/iBeacon.js +9 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +6 -0
- package/dist/api/device/memory.js +4 -0
- package/dist/api/device/motion.js +81 -0
- package/dist/api/device/nfc.js +9 -0
- package/dist/api/device/phone.js +24 -0
- package/dist/api/device/scan.js +6 -0
- package/dist/api/device/screen.js +8 -0
- package/dist/api/device/vibrate.js +35 -0
- package/dist/api/device/wifi.js +12 -0
- package/dist/api/ext/index.js +4 -0
- package/dist/api/files/index.js +10 -0
- package/dist/api/framework/index.js +7 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +93 -0
- package/dist/api/location/index.js +13 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +88 -0
- package/dist/api/media/background-audio.js +11 -0
- package/dist/api/media/camera.js +3 -0
- package/dist/api/media/editor.js +18 -0
- package/dist/api/media/image/chooseImage.js +74 -0
- package/dist/api/media/image/getImageInfo.js +31 -0
- package/dist/api/media/image/index.js +9 -0
- package/dist/api/media/image/previewImage.js +67 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +4 -0
- package/dist/api/media/map.js +3 -0
- package/dist/api/media/media-recorder.js +3 -0
- package/dist/api/media/recorder.js +5 -0
- package/dist/api/media/video/index.js +74 -0
- package/dist/api/media/video-decoder.js +3 -0
- package/dist/api/media/video-processing.js +3 -0
- package/dist/api/media/voip.js +16 -0
- package/dist/api/navigate/index.js +6 -0
- package/dist/api/network/download.js +124 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +12 -0
- package/dist/api/network/request/index.js +125 -0
- package/dist/api/network/tcp.js +3 -0
- package/dist/api/network/udp.js +3 -0
- package/dist/api/network/upload.js +151 -0
- package/dist/api/network/utils.js +65 -0
- package/dist/api/network/websocket/index.js +70 -0
- package/dist/api/network/websocket/socketTask.js +63 -0
- package/dist/api/open-api/account.js +3 -0
- package/dist/api/open-api/address.js +3 -0
- package/dist/api/open-api/authorize.js +4 -0
- package/dist/api/open-api/card.js +4 -0
- package/dist/api/open-api/channels-live.js +8 -0
- package/dist/api/open-api/customer-service.js +3 -0
- package/dist/api/open-api/facial.js +6 -0
- package/dist/api/open-api/favorites.js +4 -0
- package/dist/api/open-api/group.js +3 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +4 -0
- package/dist/api/open-api/license-plate.js +3 -0
- package/dist/api/open-api/login.js +5 -0
- package/dist/api/open-api/red-package.js +3 -0
- package/dist/api/open-api/settings.js +4 -0
- package/dist/api/open-api/soter.js +5 -0
- package/dist/api/open-api/subscribe-message.js +3 -0
- package/dist/api/open-api/user-info.js +4 -0
- package/dist/api/open-api/werun.js +4 -0
- package/dist/api/payment/index.js +4 -0
- package/dist/api/route/index.js +3 -0
- package/dist/api/share/index.js +12 -0
- package/dist/api/storage/background-fetch.js +6 -0
- package/dist/api/storage/index.js +157 -0
- package/dist/api/swan/index.js +26 -0
- package/dist/api/taro.js +47 -0
- package/dist/api/ui/animation/index.js +284 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +3 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +188 -0
- package/dist/api/ui/interaction/index.js +268 -0
- package/dist/api/ui/interaction/modal.js +207 -0
- package/dist/api/ui/interaction/toast.js +195 -0
- package/dist/api/ui/menu.js +3 -0
- package/dist/api/ui/navigation-bar/index.js +42 -0
- package/dist/api/ui/pull-down-refresh.js +26 -0
- package/dist/api/ui/scroll/index.js +83 -0
- package/dist/api/ui/sticky.js +3 -0
- package/dist/api/ui/tab-bar.js +282 -0
- package/dist/api/ui/window.js +31 -0
- package/dist/api/utils/handler.js +80 -0
- package/dist/api/utils/index.js +148 -0
- package/dist/api/worker/index.js +3 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +42 -0
- package/dist/api/wxml/selectorQuery.js +201 -0
- package/dist/index.cjs.js +4626 -6915
- package/dist/index.js +4 -10767
- package/dist/types/type.js +2 -0
- package/package.json +10 -13
- package/src/api/canvas/CanvasContext.ts +35 -32
- package/src/api/canvas/createCanvasContext.ts +2 -2
- package/src/api/location/chooseLocation.ts +2 -2
- package/src/api/media/audio/index.ts +16 -16
- package/src/api/media/image/previewImage.ts +4 -25
- package/src/api/network/download.ts +5 -5
- package/src/api/network/upload.ts +5 -5
- package/src/api/network/websocket/index.ts +1 -1
- package/src/api/ui/animation/index.ts +1 -6
- package/src/api/ui/interaction/index.ts +6 -4
- package/src/api/ui/navigation-bar/index.ts +1 -1
- package/src/api/wxml/nodesRef.ts +10 -3
- package/src/api/wxml/selectorQuery.ts +68 -23
- package/src/index.ts +2 -2
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
import 'whatwg-fetch';
|
|
3
|
+
import jsonpRetry from 'jsonp-retry';
|
|
4
|
+
import { serializeParams } from '../../utils';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const { Link } = Taro;
|
|
7
|
+
function generateRequestUrlWithParams(url, params) {
|
|
8
|
+
params = typeof params === 'string' ? params : serializeParams(params);
|
|
9
|
+
if (params) {
|
|
10
|
+
url += (~url.indexOf('?') ? '&' : '?') + params;
|
|
11
|
+
}
|
|
12
|
+
url = url.replace('?&', '?');
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
// FIXME 移除 any 标注
|
|
16
|
+
function _request(options) {
|
|
17
|
+
options = options || {};
|
|
18
|
+
if (typeof options === 'string') {
|
|
19
|
+
options = {
|
|
20
|
+
url: options
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const { success, complete, fail } = options;
|
|
24
|
+
let url = options.url;
|
|
25
|
+
const params = {};
|
|
26
|
+
const res = {};
|
|
27
|
+
if (options.jsonp) {
|
|
28
|
+
Object.assign(params, options);
|
|
29
|
+
params.params = options.data;
|
|
30
|
+
params.cache = options.jsonpCache;
|
|
31
|
+
if (typeof options.jsonp === 'string') {
|
|
32
|
+
params.name = options.jsonp;
|
|
33
|
+
}
|
|
34
|
+
delete params.jsonp;
|
|
35
|
+
return jsonpRetry(url, params)
|
|
36
|
+
.then(data => {
|
|
37
|
+
res.statusCode = 200;
|
|
38
|
+
res.data = data;
|
|
39
|
+
typeof success === 'function' && success(res);
|
|
40
|
+
typeof complete === 'function' && complete(res);
|
|
41
|
+
return res;
|
|
42
|
+
})
|
|
43
|
+
.catch(err => {
|
|
44
|
+
typeof fail === 'function' && fail(err);
|
|
45
|
+
typeof complete === 'function' && complete(res);
|
|
46
|
+
return Promise.reject(err);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
params.method = options.method || 'GET';
|
|
50
|
+
const methodUpper = params.method.toUpperCase();
|
|
51
|
+
params.cache = options.cache || 'default';
|
|
52
|
+
if (methodUpper === 'GET' || methodUpper === 'HEAD') {
|
|
53
|
+
url = generateRequestUrlWithParams(url, options.data);
|
|
54
|
+
}
|
|
55
|
+
else if (typeof options.data === 'object') {
|
|
56
|
+
options.header = options.header || {};
|
|
57
|
+
const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type');
|
|
58
|
+
if (!keyOfContentType) {
|
|
59
|
+
options.header['Content-Type'] = 'application/json';
|
|
60
|
+
}
|
|
61
|
+
const contentType = options.header[keyOfContentType || 'Content-Type'];
|
|
62
|
+
if (contentType.indexOf('application/json') >= 0) {
|
|
63
|
+
params.body = JSON.stringify(options.data);
|
|
64
|
+
}
|
|
65
|
+
else if (contentType.indexOf('application/x-www-form-urlencoded') >= 0) {
|
|
66
|
+
params.body = serializeParams(options.data);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
params.body = options.data;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
params.body = options.data;
|
|
74
|
+
}
|
|
75
|
+
if (options.header) {
|
|
76
|
+
params.headers = options.header;
|
|
77
|
+
}
|
|
78
|
+
if (options.mode) {
|
|
79
|
+
params.mode = options.mode;
|
|
80
|
+
}
|
|
81
|
+
if (options.signal) {
|
|
82
|
+
params.signal = options.signal;
|
|
83
|
+
}
|
|
84
|
+
params.credentials = options.credentials;
|
|
85
|
+
return fetch(url, params)
|
|
86
|
+
.then(response => {
|
|
87
|
+
res.statusCode = response.status;
|
|
88
|
+
res.header = {};
|
|
89
|
+
for (const key of response.headers.keys()) {
|
|
90
|
+
res.header[key] = response.headers.get(key);
|
|
91
|
+
}
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
throw response;
|
|
94
|
+
}
|
|
95
|
+
if (options.responseType === 'arraybuffer') {
|
|
96
|
+
return response.arrayBuffer();
|
|
97
|
+
}
|
|
98
|
+
if (res.statusCode !== 204) {
|
|
99
|
+
if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
|
|
100
|
+
return response.json();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (options.responseType === 'text' || options.dataType === 'text') {
|
|
104
|
+
return response.text();
|
|
105
|
+
}
|
|
106
|
+
return Promise.resolve(null);
|
|
107
|
+
})
|
|
108
|
+
.then(data => {
|
|
109
|
+
res.data = data;
|
|
110
|
+
typeof success === 'function' && success(res);
|
|
111
|
+
typeof complete === 'function' && complete(res);
|
|
112
|
+
return res;
|
|
113
|
+
})
|
|
114
|
+
.catch(err => {
|
|
115
|
+
typeof fail === 'function' && fail(err);
|
|
116
|
+
typeof complete === 'function' && complete(res);
|
|
117
|
+
return Promise.reject(err);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function taroInterceptor(chain) {
|
|
121
|
+
return _request(chain.requestParams);
|
|
122
|
+
}
|
|
123
|
+
const link = new Link(taroInterceptor);
|
|
124
|
+
export const request = link.request.bind(link);
|
|
125
|
+
export const addInterceptor = link.addInterceptor.bind(link);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
import { CallbackManager } from '../utils/handler';
|
|
3
|
+
import { convertObjectUrlToBlob, NETWORK_TIMEOUT, setHeader, XHR_STATS } from './utils';
|
|
4
|
+
const createUploadTask = ({ url, filePath, formData, name, header, timeout, fileName, success, error }) => {
|
|
5
|
+
let timeoutInter;
|
|
6
|
+
let formKey;
|
|
7
|
+
const apiName = 'uploadFile';
|
|
8
|
+
const xhr = new XMLHttpRequest();
|
|
9
|
+
const form = new FormData();
|
|
10
|
+
const callbackManager = {
|
|
11
|
+
headersReceived: new CallbackManager(),
|
|
12
|
+
progressUpdate: new CallbackManager()
|
|
13
|
+
};
|
|
14
|
+
xhr.open('POST', url);
|
|
15
|
+
setHeader(xhr, header);
|
|
16
|
+
for (formKey in formData) {
|
|
17
|
+
form.append(formKey, formData[formKey]);
|
|
18
|
+
}
|
|
19
|
+
xhr.upload.onprogress = e => {
|
|
20
|
+
const { loaded, total } = e;
|
|
21
|
+
callbackManager.progressUpdate.trigger({
|
|
22
|
+
progress: Math.round(loaded / total * 100),
|
|
23
|
+
totalBytesSent: loaded,
|
|
24
|
+
totalBytesExpectedToSent: total
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
xhr.onreadystatechange = () => {
|
|
28
|
+
if (xhr.readyState !== XHR_STATS.HEADERS_RECEIVED)
|
|
29
|
+
return;
|
|
30
|
+
callbackManager.headersReceived.trigger({
|
|
31
|
+
header: xhr.getAllResponseHeaders()
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
xhr.onload = () => {
|
|
35
|
+
const status = xhr.status;
|
|
36
|
+
clearTimeout(timeoutInter);
|
|
37
|
+
success({
|
|
38
|
+
errMsg: `${apiName}:ok`,
|
|
39
|
+
statusCode: status,
|
|
40
|
+
data: xhr.responseText || xhr.response
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
xhr.onabort = () => {
|
|
44
|
+
clearTimeout(timeoutInter);
|
|
45
|
+
error({
|
|
46
|
+
errMsg: `${apiName}:fail abort`
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
xhr.onerror = (e) => {
|
|
50
|
+
clearTimeout(timeoutInter);
|
|
51
|
+
error({
|
|
52
|
+
errMsg: `${apiName}:fail ${e.message}`
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* 中断任务
|
|
57
|
+
*/
|
|
58
|
+
const abort = () => {
|
|
59
|
+
clearTimeout(timeoutInter);
|
|
60
|
+
xhr.abort();
|
|
61
|
+
};
|
|
62
|
+
const send = () => {
|
|
63
|
+
xhr.send(form);
|
|
64
|
+
timeoutInter = setTimeout(() => {
|
|
65
|
+
xhr.onabort = null;
|
|
66
|
+
xhr.onload = null;
|
|
67
|
+
xhr.upload.onprogress = null;
|
|
68
|
+
xhr.onreadystatechange = null;
|
|
69
|
+
xhr.onerror = null;
|
|
70
|
+
abort();
|
|
71
|
+
error({
|
|
72
|
+
errMsg: `${apiName}:fail timeout`
|
|
73
|
+
});
|
|
74
|
+
}, timeout || NETWORK_TIMEOUT);
|
|
75
|
+
};
|
|
76
|
+
convertObjectUrlToBlob(filePath)
|
|
77
|
+
.then((fileObj) => {
|
|
78
|
+
if (!fileName) {
|
|
79
|
+
fileName = typeof fileObj !== 'string' && fileObj.name;
|
|
80
|
+
}
|
|
81
|
+
form.append(name, fileObj, fileName || `file-${Date.now()}`);
|
|
82
|
+
send();
|
|
83
|
+
})
|
|
84
|
+
.catch(e => {
|
|
85
|
+
error({
|
|
86
|
+
errMsg: `${apiName}:fail ${e.message}`
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* 监听 HTTP Response Header 事件。会比请求完成事件更早
|
|
91
|
+
* @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
|
|
92
|
+
*/
|
|
93
|
+
const onHeadersReceived = callbackManager.headersReceived.add;
|
|
94
|
+
/**
|
|
95
|
+
* 取消监听 HTTP Response Header 事件
|
|
96
|
+
* @param {HeadersReceivedCallback} callback HTTP Response Header 事件的回调函数
|
|
97
|
+
*/
|
|
98
|
+
const offHeadersReceived = callbackManager.headersReceived.remove;
|
|
99
|
+
/**
|
|
100
|
+
* 监听进度变化事件
|
|
101
|
+
* @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
|
|
102
|
+
*/
|
|
103
|
+
const onProgressUpdate = callbackManager.progressUpdate.add;
|
|
104
|
+
/**
|
|
105
|
+
* 取消监听进度变化事件
|
|
106
|
+
* @param {ProgressUpdateCallback} callback HTTP Response Header 事件的回调函数
|
|
107
|
+
*/
|
|
108
|
+
const offProgressUpdate = callbackManager.progressUpdate.remove;
|
|
109
|
+
const headersReceived = temporarilyNotSupport('UploadTask.headersReceived');
|
|
110
|
+
const progress = temporarilyNotSupport('UploadTask.progress');
|
|
111
|
+
return {
|
|
112
|
+
abort,
|
|
113
|
+
onHeadersReceived,
|
|
114
|
+
offHeadersReceived,
|
|
115
|
+
onProgressUpdate,
|
|
116
|
+
offProgressUpdate,
|
|
117
|
+
headersReceived,
|
|
118
|
+
progress
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。
|
|
123
|
+
*/
|
|
124
|
+
export const uploadFile = ({ url, filePath, name, header, formData, timeout, fileName, success, fail, complete }) => {
|
|
125
|
+
let task;
|
|
126
|
+
const result = new Promise((resolve, reject) => {
|
|
127
|
+
task = createUploadTask({
|
|
128
|
+
url,
|
|
129
|
+
header,
|
|
130
|
+
name,
|
|
131
|
+
filePath,
|
|
132
|
+
formData,
|
|
133
|
+
timeout,
|
|
134
|
+
fileName,
|
|
135
|
+
success: res => {
|
|
136
|
+
success && success(res);
|
|
137
|
+
complete && complete(res);
|
|
138
|
+
resolve(res);
|
|
139
|
+
},
|
|
140
|
+
error: res => {
|
|
141
|
+
fail && fail(res);
|
|
142
|
+
complete && complete(res);
|
|
143
|
+
reject(res);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
result.headersReceive = task.onHeadersReceived;
|
|
148
|
+
result.progress = task.onProgressUpdate;
|
|
149
|
+
result.abort = task.abort;
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Response Header 事件回调函数的参数
|
|
3
|
+
* @typedef {Object} HeadersReceivedParam
|
|
4
|
+
* @property {Object} header 开发者服务器返回的 HTTP Response Header
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* HTTP Response Header 事件的回调函数
|
|
8
|
+
* @callback HeadersReceivedCallback
|
|
9
|
+
* @param {HeadersReceivedParam} res 参数
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* 进度变化回调函数的参数
|
|
13
|
+
* @typedef {Object} ProgressUpdateParam
|
|
14
|
+
* @property {number} progress 进度百分比
|
|
15
|
+
* @property {number} [totalBytesWritten] 已经下载的数据长度,单位 Bytes
|
|
16
|
+
* @property {number} [totalBytesSent] 已经上传的数据长度,单位 Bytes
|
|
17
|
+
* @property {number} [totalBytesExpectedToWrite] 预期需要下载的数据总长度,单位 Bytes
|
|
18
|
+
* @property {number} [totalBytesExpectedToSend] 预期需要上传的数据总长度,单位 Bytes
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* 进度变化事件的回调函数
|
|
22
|
+
* @callback ProgressUpdateCallback
|
|
23
|
+
* @param {ProgressUpdateParam} res 参数
|
|
24
|
+
*/
|
|
25
|
+
export const NETWORK_TIMEOUT = 60000;
|
|
26
|
+
export const XHR_STATS = {
|
|
27
|
+
UNSENT: 0,
|
|
28
|
+
OPENED: 1,
|
|
29
|
+
HEADERS_RECEIVED: 2,
|
|
30
|
+
LOADING: 3,
|
|
31
|
+
DONE: 4 // The operation is complete.
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 设置xhr的header
|
|
35
|
+
* @param {XMLHttpRequest} xhr
|
|
36
|
+
* @param {Object} header
|
|
37
|
+
*/
|
|
38
|
+
export const setHeader = (xhr, header) => {
|
|
39
|
+
let headerKey;
|
|
40
|
+
for (headerKey in header) {
|
|
41
|
+
xhr.setRequestHeader(headerKey, header[headerKey]);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 将 blob url 转化为文件
|
|
46
|
+
* @param {string} url 要转换的 blob url
|
|
47
|
+
* @returns {Promise<File>}
|
|
48
|
+
*/
|
|
49
|
+
export const convertObjectUrlToBlob = url => {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const xhr = new XMLHttpRequest();
|
|
52
|
+
xhr.open('GET', url, true);
|
|
53
|
+
xhr.responseType = 'blob';
|
|
54
|
+
xhr.onload = function () {
|
|
55
|
+
if (this.status === 200) {
|
|
56
|
+
resolve(this.response);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
/* eslint-disable prefer-promise-reject-errors */
|
|
60
|
+
reject({ status: this.status });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
xhr.send();
|
|
64
|
+
});
|
|
65
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { SocketTask } from './socketTask';
|
|
2
|
+
import { shouldBeObject, getParameterError } from '../../utils';
|
|
3
|
+
import { MethodHandler } from '../../utils/handler';
|
|
4
|
+
let socketTasks = [];
|
|
5
|
+
let socketsCounter = 1;
|
|
6
|
+
export function sendSocketMessage() {
|
|
7
|
+
console.warn('Deprecated.Please use socketTask.send instead.');
|
|
8
|
+
}
|
|
9
|
+
export function onSocketOpen() {
|
|
10
|
+
console.warn('Deprecated.Please use socketTask.onOpen instead.');
|
|
11
|
+
}
|
|
12
|
+
export function onSocketMessage() {
|
|
13
|
+
console.warn('Deprecated.Please use socketTask.onMessage instead.');
|
|
14
|
+
}
|
|
15
|
+
export function onSocketError() {
|
|
16
|
+
console.warn('Deprecated.Please use socketTask.onError instead.');
|
|
17
|
+
}
|
|
18
|
+
export function onSocketClose() {
|
|
19
|
+
console.warn('Deprecated.Please use socketTask.onClose instead.');
|
|
20
|
+
}
|
|
21
|
+
export function connectSocket(options) {
|
|
22
|
+
const name = 'connectSocket';
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
// options must be an Object
|
|
25
|
+
const isObject = shouldBeObject(options);
|
|
26
|
+
if (!isObject.flag) {
|
|
27
|
+
const res = { errMsg: `${name}:fail ${isObject.msg}` };
|
|
28
|
+
console.error(res.errMsg);
|
|
29
|
+
return reject(res);
|
|
30
|
+
}
|
|
31
|
+
const { url, protocols, success, fail, complete } = options;
|
|
32
|
+
const handle = new MethodHandler({ name, success, fail, complete });
|
|
33
|
+
// options.url must be String
|
|
34
|
+
if (typeof url !== 'string') {
|
|
35
|
+
return handle.fail({
|
|
36
|
+
errMsg: getParameterError({
|
|
37
|
+
para: 'url',
|
|
38
|
+
correct: 'String',
|
|
39
|
+
wrong: url
|
|
40
|
+
})
|
|
41
|
+
}, reject);
|
|
42
|
+
}
|
|
43
|
+
// options.url must be invalid
|
|
44
|
+
if (!url.startsWith('ws://') && !url.startsWith('wss://')) {
|
|
45
|
+
return handle.fail({
|
|
46
|
+
errMsg: `request:fail invalid url "${url}"`
|
|
47
|
+
}, reject);
|
|
48
|
+
}
|
|
49
|
+
// protocols must be array
|
|
50
|
+
const _protocols = Array.isArray(protocols) ? protocols : null;
|
|
51
|
+
// 2 connection at most
|
|
52
|
+
if (socketTasks.length > 1) {
|
|
53
|
+
return handle.fail({
|
|
54
|
+
errMsg: '同时最多发起 2 个 socket 请求,更多请参考文档。'
|
|
55
|
+
}, reject);
|
|
56
|
+
}
|
|
57
|
+
const task = new SocketTask(url, _protocols);
|
|
58
|
+
task._destroyWhenClose = function () {
|
|
59
|
+
socketTasks = socketTasks.filter(socketTask => socketTask !== this);
|
|
60
|
+
};
|
|
61
|
+
socketTasks.push(task);
|
|
62
|
+
handle.success({
|
|
63
|
+
socketTaskId: socketsCounter++
|
|
64
|
+
});
|
|
65
|
+
return resolve(task);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export function closeSocket() {
|
|
69
|
+
console.warn('Deprecated.Please use socketTask.close instead.');
|
|
70
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class SocketTask {
|
|
2
|
+
constructor(url, protocols) {
|
|
3
|
+
if (protocols && protocols.length) {
|
|
4
|
+
this.ws = new WebSocket(url, protocols);
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
this.ws = new WebSocket(url);
|
|
8
|
+
}
|
|
9
|
+
this.CONNECTING = 0;
|
|
10
|
+
this.OPEN = 1;
|
|
11
|
+
this.CLOSING = 2;
|
|
12
|
+
this.CLOSED = 3;
|
|
13
|
+
}
|
|
14
|
+
get readyState() {
|
|
15
|
+
return this.ws.readyState;
|
|
16
|
+
}
|
|
17
|
+
send(opts = {}) {
|
|
18
|
+
if (typeof opts !== 'object' || !opts)
|
|
19
|
+
opts = {};
|
|
20
|
+
const { data = '', success, fail, complete } = opts;
|
|
21
|
+
if (this.readyState !== 1) {
|
|
22
|
+
const res = { errMsg: 'SocketTask.send:fail SocketTask.readState is not OPEN' };
|
|
23
|
+
console.error(res.errMsg);
|
|
24
|
+
typeof fail === 'function' && fail(res);
|
|
25
|
+
typeof complete === 'function' && complete(res);
|
|
26
|
+
return Promise.reject(res);
|
|
27
|
+
}
|
|
28
|
+
this.ws.send(data);
|
|
29
|
+
const res = { errMsg: 'sendSocketMessage:ok' };
|
|
30
|
+
typeof success === 'function' && success(res);
|
|
31
|
+
typeof complete === 'function' && complete(res);
|
|
32
|
+
return Promise.resolve(res);
|
|
33
|
+
}
|
|
34
|
+
close(opts = {}) {
|
|
35
|
+
if (typeof opts !== 'object' || !opts)
|
|
36
|
+
opts = {};
|
|
37
|
+
const { code = 1000, reason = 'server complete,close', success, complete } = opts;
|
|
38
|
+
this.closeDetail = { code, reason };
|
|
39
|
+
// 主动断开时需要重置链接数
|
|
40
|
+
this._destroyWhenClose && this._destroyWhenClose();
|
|
41
|
+
this.ws.close();
|
|
42
|
+
const res = { errMsg: 'closeSocket:ok' };
|
|
43
|
+
typeof success === 'function' && success(res);
|
|
44
|
+
typeof complete === 'function' && complete(res);
|
|
45
|
+
return Promise.resolve(res);
|
|
46
|
+
}
|
|
47
|
+
onOpen(func) {
|
|
48
|
+
this.ws.onopen = func;
|
|
49
|
+
}
|
|
50
|
+
onMessage(func) {
|
|
51
|
+
this.ws.onmessage = func;
|
|
52
|
+
}
|
|
53
|
+
onClose(func) {
|
|
54
|
+
this.ws.onclose = () => {
|
|
55
|
+
// 若服务器方断掉也需要重置链接数
|
|
56
|
+
this._destroyWhenClose && this._destroyWhenClose();
|
|
57
|
+
func(this.closeDetail || { code: 1006, reason: 'abnormal closure' });
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
onError(func) {
|
|
61
|
+
this.ws.onerror = func;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 视频号
|
|
3
|
+
export const reserveChannelsLive = temporarilyNotSupport('reserveChannelsLive');
|
|
4
|
+
export const openChannelsLive = temporarilyNotSupport('openChannelsLive');
|
|
5
|
+
export const openChannelsEvent = temporarilyNotSupport('openChannelsEvent');
|
|
6
|
+
export const openChannelsActivity = temporarilyNotSupport('openChannelsActivity');
|
|
7
|
+
export const getChannelsLiveNoticeInfo = temporarilyNotSupport('getChannelsLiveNoticeInfo');
|
|
8
|
+
export const getChannelsLiveInfo = temporarilyNotSupport('getChannelsLiveInfo');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 过往接口
|
|
3
|
+
export const checkIsSupportFacialRecognition = temporarilyNotSupport('checkIsSupportFacialRecognition');
|
|
4
|
+
export const startFacialRecognitionVerify = temporarilyNotSupport('startFacialRecognitionVerify');
|
|
5
|
+
export const startFacialRecognitionVerifyAndUploadVideo = temporarilyNotSupport('startFacialRecognitionVerifyAndUploadVideo');
|
|
6
|
+
export const faceVerifyForPay = temporarilyNotSupport('faceVerifyForPay');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './account';
|
|
2
|
+
export * from './address';
|
|
3
|
+
export * from './authorize';
|
|
4
|
+
export * from './card';
|
|
5
|
+
export * from './channels-live';
|
|
6
|
+
export * from './customer-service';
|
|
7
|
+
export * from './facial';
|
|
8
|
+
export * from './favorites';
|
|
9
|
+
export * from './group';
|
|
10
|
+
export * from './invoice';
|
|
11
|
+
export * from './license-plate';
|
|
12
|
+
export * from './login';
|
|
13
|
+
export * from './red-package';
|
|
14
|
+
export * from './settings';
|
|
15
|
+
export * from './soter';
|
|
16
|
+
export * from './subscribe-message';
|
|
17
|
+
export * from './user-info';
|
|
18
|
+
export * from './werun';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 生物认证
|
|
3
|
+
export const startSoterAuthentication = temporarilyNotSupport('startSoterAuthentication');
|
|
4
|
+
export const checkIsSupportSoterAuthentication = temporarilyNotSupport('checkIsSupportSoterAuthentication');
|
|
5
|
+
export const checkIsSoterEnrolledInDevice = temporarilyNotSupport('checkIsSoterEnrolledInDevice');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 转发
|
|
3
|
+
export const updateShareMenu = temporarilyNotSupport('updateShareMenu');
|
|
4
|
+
export const showShareMenu = temporarilyNotSupport('showShareMenu');
|
|
5
|
+
export const showShareImageMenu = temporarilyNotSupport('showShareImageMenu');
|
|
6
|
+
export const shareVideoMessage = temporarilyNotSupport('shareVideoMessage');
|
|
7
|
+
export const shareFileMessage = temporarilyNotSupport('shareFileMessage');
|
|
8
|
+
export const onCopyUrl = temporarilyNotSupport('onCopyUrl');
|
|
9
|
+
export const offCopyUrl = temporarilyNotSupport('offCopyUrl');
|
|
10
|
+
export const hideShareMenu = temporarilyNotSupport('hideShareMenu');
|
|
11
|
+
export const getShareInfo = temporarilyNotSupport('getShareInfo');
|
|
12
|
+
export const authPrivateMessage = temporarilyNotSupport('authPrivateMessage');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 周期性更新
|
|
3
|
+
export const setBackgroundFetchToken = temporarilyNotSupport('setBackgroundFetchToken');
|
|
4
|
+
export const onBackgroundFetchData = temporarilyNotSupport('onBackgroundFetchData');
|
|
5
|
+
export const getBackgroundFetchToken = temporarilyNotSupport('getBackgroundFetchToken');
|
|
6
|
+
export const getBackgroundFetchData = temporarilyNotSupport('getBackgroundFetchData');
|