@hlw-uni-mp/request 1.0.1 → 1.0.2
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/index.js +44 -53
- package/dist/index.mjs +44 -53
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -58,64 +58,57 @@ module.exports = __toCommonJS(index_exports);
|
|
|
58
58
|
// src/device/index.ts
|
|
59
59
|
var deviceCache = null;
|
|
60
60
|
var currentNetworkType = "";
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (deviceCache) {
|
|
67
|
-
deviceCache.networkType = currentNetworkType;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
if (uni.onNetworkStatusChange) {
|
|
72
|
-
uni.onNetworkStatusChange((res) => {
|
|
73
|
-
currentNetworkType = res.networkType || "";
|
|
74
|
-
if (deviceCache) {
|
|
75
|
-
deviceCache.networkType = currentNetworkType;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
61
|
+
uni.getNetworkType({
|
|
62
|
+
success(res) {
|
|
63
|
+
currentNetworkType = res.networkType || "";
|
|
64
|
+
if (deviceCache) {
|
|
65
|
+
deviceCache.networkType = currentNetworkType;
|
|
78
66
|
}
|
|
79
67
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
68
|
+
});
|
|
69
|
+
uni.onNetworkStatusChange((res) => {
|
|
70
|
+
currentNetworkType = res.networkType || "";
|
|
71
|
+
if (deviceCache) {
|
|
72
|
+
deviceCache.networkType = currentNetworkType;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
82
75
|
function getDevice() {
|
|
83
76
|
if (deviceCache) return deviceCache;
|
|
84
|
-
const deviceRaw =
|
|
85
|
-
const windowRaw =
|
|
86
|
-
const appRaw =
|
|
87
|
-
const accountRaw =
|
|
88
|
-
const system = deviceRaw
|
|
77
|
+
const deviceRaw = uni.getDeviceInfo();
|
|
78
|
+
const windowRaw = uni.getWindowInfo();
|
|
79
|
+
const appRaw = uni.getAppBaseInfo();
|
|
80
|
+
const accountRaw = uni.getAccountInfoSync();
|
|
81
|
+
const system = deviceRaw.system || "";
|
|
89
82
|
deviceCache = {
|
|
90
|
-
appid: accountRaw
|
|
91
|
-
appName: appRaw
|
|
92
|
-
version: appRaw
|
|
93
|
-
versionCode: appRaw
|
|
94
|
-
channel: appRaw
|
|
95
|
-
deviceId: deviceRaw
|
|
96
|
-
deviceType: deviceRaw
|
|
97
|
-
deviceOrientation: deviceRaw
|
|
98
|
-
brand: deviceRaw
|
|
99
|
-
model: deviceRaw
|
|
83
|
+
appid: accountRaw.miniProgram?.appId || "",
|
|
84
|
+
appName: appRaw.appName || "",
|
|
85
|
+
version: appRaw.appVersion || "",
|
|
86
|
+
versionCode: appRaw.appVersionCode || "",
|
|
87
|
+
channel: appRaw.appChannel || "",
|
|
88
|
+
deviceId: deviceRaw.deviceId || "",
|
|
89
|
+
deviceType: deviceRaw.deviceType || "",
|
|
90
|
+
deviceOrientation: deviceRaw.deviceOrientation || windowRaw.deviceOrientation || "portrait",
|
|
91
|
+
brand: deviceRaw.brand || "",
|
|
92
|
+
model: deviceRaw.model || "",
|
|
100
93
|
system,
|
|
101
94
|
os: system.split(" ")[0] || "",
|
|
102
|
-
pixelRatio: windowRaw
|
|
103
|
-
screenWidth: windowRaw
|
|
104
|
-
screenHeight: windowRaw
|
|
105
|
-
windowWidth: windowRaw
|
|
106
|
-
windowHeight: windowRaw
|
|
107
|
-
statusBarHeight: windowRaw
|
|
108
|
-
sdkVersion: appRaw
|
|
109
|
-
hostName: appRaw
|
|
110
|
-
hostVersion: appRaw
|
|
111
|
-
hostLanguage: appRaw
|
|
112
|
-
hostTheme: appRaw
|
|
113
|
-
platform: deviceRaw
|
|
114
|
-
language: appRaw
|
|
95
|
+
pixelRatio: windowRaw.pixelRatio || 0,
|
|
96
|
+
screenWidth: windowRaw.screenWidth || 0,
|
|
97
|
+
screenHeight: windowRaw.screenHeight || 0,
|
|
98
|
+
windowWidth: windowRaw.windowWidth || 0,
|
|
99
|
+
windowHeight: windowRaw.windowHeight || 0,
|
|
100
|
+
statusBarHeight: windowRaw.statusBarHeight || 0,
|
|
101
|
+
sdkVersion: appRaw.SDKVersion || "",
|
|
102
|
+
hostName: appRaw.hostName || "",
|
|
103
|
+
hostVersion: appRaw.hostVersion || "",
|
|
104
|
+
hostLanguage: appRaw.hostLanguage || "",
|
|
105
|
+
hostTheme: appRaw.hostTheme || "",
|
|
106
|
+
platform: deviceRaw.platform || "",
|
|
107
|
+
language: appRaw.appLanguage || appRaw.language || "",
|
|
115
108
|
networkType: currentNetworkType,
|
|
116
|
-
benchmarkLevel: deviceRaw
|
|
117
|
-
theme: appRaw
|
|
118
|
-
fontSizeSetting: appRaw
|
|
109
|
+
benchmarkLevel: deviceRaw.benchmarkLevel || 0,
|
|
110
|
+
theme: appRaw.theme || "light",
|
|
111
|
+
fontSizeSetting: appRaw.fontSizeSetting || 16
|
|
119
112
|
};
|
|
120
113
|
return deviceCache;
|
|
121
114
|
}
|
|
@@ -577,9 +570,7 @@ function handleUnauthorized(message, callback) {
|
|
|
577
570
|
const now = Date.now();
|
|
578
571
|
if (now - lastToastTime > 3e3) {
|
|
579
572
|
lastToastTime = now;
|
|
580
|
-
|
|
581
|
-
uni.showToast({ title: message, icon: "none" });
|
|
582
|
-
}
|
|
573
|
+
uni.showToast({ title: message, icon: "none" });
|
|
583
574
|
}
|
|
584
575
|
if (callback) {
|
|
585
576
|
callback(message);
|
package/dist/index.mjs
CHANGED
|
@@ -1,64 +1,57 @@
|
|
|
1
1
|
// src/device/index.ts
|
|
2
2
|
var deviceCache = null;
|
|
3
3
|
var currentNetworkType = "";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (deviceCache) {
|
|
10
|
-
deviceCache.networkType = currentNetworkType;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
if (uni.onNetworkStatusChange) {
|
|
15
|
-
uni.onNetworkStatusChange((res) => {
|
|
16
|
-
currentNetworkType = res.networkType || "";
|
|
17
|
-
if (deviceCache) {
|
|
18
|
-
deviceCache.networkType = currentNetworkType;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
4
|
+
uni.getNetworkType({
|
|
5
|
+
success(res) {
|
|
6
|
+
currentNetworkType = res.networkType || "";
|
|
7
|
+
if (deviceCache) {
|
|
8
|
+
deviceCache.networkType = currentNetworkType;
|
|
21
9
|
}
|
|
22
10
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
11
|
+
});
|
|
12
|
+
uni.onNetworkStatusChange((res) => {
|
|
13
|
+
currentNetworkType = res.networkType || "";
|
|
14
|
+
if (deviceCache) {
|
|
15
|
+
deviceCache.networkType = currentNetworkType;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
25
18
|
function getDevice() {
|
|
26
19
|
if (deviceCache) return deviceCache;
|
|
27
|
-
const deviceRaw =
|
|
28
|
-
const windowRaw =
|
|
29
|
-
const appRaw =
|
|
30
|
-
const accountRaw =
|
|
31
|
-
const system = deviceRaw
|
|
20
|
+
const deviceRaw = uni.getDeviceInfo();
|
|
21
|
+
const windowRaw = uni.getWindowInfo();
|
|
22
|
+
const appRaw = uni.getAppBaseInfo();
|
|
23
|
+
const accountRaw = uni.getAccountInfoSync();
|
|
24
|
+
const system = deviceRaw.system || "";
|
|
32
25
|
deviceCache = {
|
|
33
|
-
appid: accountRaw
|
|
34
|
-
appName: appRaw
|
|
35
|
-
version: appRaw
|
|
36
|
-
versionCode: appRaw
|
|
37
|
-
channel: appRaw
|
|
38
|
-
deviceId: deviceRaw
|
|
39
|
-
deviceType: deviceRaw
|
|
40
|
-
deviceOrientation: deviceRaw
|
|
41
|
-
brand: deviceRaw
|
|
42
|
-
model: deviceRaw
|
|
26
|
+
appid: accountRaw.miniProgram?.appId || "",
|
|
27
|
+
appName: appRaw.appName || "",
|
|
28
|
+
version: appRaw.appVersion || "",
|
|
29
|
+
versionCode: appRaw.appVersionCode || "",
|
|
30
|
+
channel: appRaw.appChannel || "",
|
|
31
|
+
deviceId: deviceRaw.deviceId || "",
|
|
32
|
+
deviceType: deviceRaw.deviceType || "",
|
|
33
|
+
deviceOrientation: deviceRaw.deviceOrientation || windowRaw.deviceOrientation || "portrait",
|
|
34
|
+
brand: deviceRaw.brand || "",
|
|
35
|
+
model: deviceRaw.model || "",
|
|
43
36
|
system,
|
|
44
37
|
os: system.split(" ")[0] || "",
|
|
45
|
-
pixelRatio: windowRaw
|
|
46
|
-
screenWidth: windowRaw
|
|
47
|
-
screenHeight: windowRaw
|
|
48
|
-
windowWidth: windowRaw
|
|
49
|
-
windowHeight: windowRaw
|
|
50
|
-
statusBarHeight: windowRaw
|
|
51
|
-
sdkVersion: appRaw
|
|
52
|
-
hostName: appRaw
|
|
53
|
-
hostVersion: appRaw
|
|
54
|
-
hostLanguage: appRaw
|
|
55
|
-
hostTheme: appRaw
|
|
56
|
-
platform: deviceRaw
|
|
57
|
-
language: appRaw
|
|
38
|
+
pixelRatio: windowRaw.pixelRatio || 0,
|
|
39
|
+
screenWidth: windowRaw.screenWidth || 0,
|
|
40
|
+
screenHeight: windowRaw.screenHeight || 0,
|
|
41
|
+
windowWidth: windowRaw.windowWidth || 0,
|
|
42
|
+
windowHeight: windowRaw.windowHeight || 0,
|
|
43
|
+
statusBarHeight: windowRaw.statusBarHeight || 0,
|
|
44
|
+
sdkVersion: appRaw.SDKVersion || "",
|
|
45
|
+
hostName: appRaw.hostName || "",
|
|
46
|
+
hostVersion: appRaw.hostVersion || "",
|
|
47
|
+
hostLanguage: appRaw.hostLanguage || "",
|
|
48
|
+
hostTheme: appRaw.hostTheme || "",
|
|
49
|
+
platform: deviceRaw.platform || "",
|
|
50
|
+
language: appRaw.appLanguage || appRaw.language || "",
|
|
58
51
|
networkType: currentNetworkType,
|
|
59
|
-
benchmarkLevel: deviceRaw
|
|
60
|
-
theme: appRaw
|
|
61
|
-
fontSizeSetting: appRaw
|
|
52
|
+
benchmarkLevel: deviceRaw.benchmarkLevel || 0,
|
|
53
|
+
theme: appRaw.theme || "light",
|
|
54
|
+
fontSizeSetting: appRaw.fontSizeSetting || 16
|
|
62
55
|
};
|
|
63
56
|
return deviceCache;
|
|
64
57
|
}
|
|
@@ -520,9 +513,7 @@ function handleUnauthorized(message, callback) {
|
|
|
520
513
|
const now = Date.now();
|
|
521
514
|
if (now - lastToastTime > 3e3) {
|
|
522
515
|
lastToastTime = now;
|
|
523
|
-
|
|
524
|
-
uni.showToast({ title: message, icon: "none" });
|
|
525
|
-
}
|
|
516
|
+
uni.showToast({ title: message, icon: "none" });
|
|
526
517
|
}
|
|
527
518
|
if (callback) {
|
|
528
519
|
callback(message);
|
package/package.json
CHANGED