@hlw-uni/mp-vue 2.1.51 → 2.1.54
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/app.d.ts +2 -20
- package/dist/composables/device/index.d.ts +5 -70
- package/dist/composables/index.d.ts +5 -14
- package/dist/composables/navigator/index.d.ts +15 -39
- package/dist/composables/request/client.d.ts +21 -0
- package/dist/composables/request/index.d.ts +6 -0
- package/dist/composables/request/service.d.ts +30 -0
- package/dist/composables/{http → request}/types.d.ts +0 -3
- package/dist/composables/share/index.d.ts +7 -66
- package/dist/composables/theme/appearance.d.ts +3 -2
- package/dist/composables/theme/index.d.ts +5 -7
- package/dist/composables/utils/index.d.ts +25 -32
- package/dist/hlw.d.ts +2 -4
- package/dist/index.d.ts +2 -3
- package/dist/index.js +485 -1269
- package/dist/index.mjs +484 -1268
- package/package.json +2 -1
- package/src/app.ts +3 -143
- package/src/components/hlw-ad/index.vue +2 -2
- package/src/components/hlw-page/index.vue +1 -1
- package/src/composables/device/index.ts +110 -83
- package/src/composables/index.ts +9 -39
- package/src/composables/navigator/index.ts +77 -77
- package/src/composables/request/client.ts +204 -0
- package/src/composables/request/index.ts +15 -0
- package/src/composables/request/service.ts +54 -0
- package/src/composables/{http → request}/types.ts +0 -4
- package/src/composables/share/index.ts +64 -168
- package/src/composables/theme/appearance.ts +3 -2
- package/src/composables/theme/index.ts +11 -28
- package/src/composables/theme/palette.ts +22 -4
- package/src/composables/utils/index.ts +131 -95
- package/src/hlw.ts +6 -14
- package/src/index.ts +2 -3
- package/dist/composables/_internal/unwrap.d.ts +0 -15
- package/dist/composables/ad/index.d.ts +0 -78
- package/dist/composables/algo/index.d.ts +0 -7
- package/dist/composables/algo/uuid.d.ts +0 -17
- package/dist/composables/color/index.d.ts +0 -8
- package/dist/composables/contact/index.d.ts +0 -32
- package/dist/composables/format/index.d.ts +0 -9
- package/dist/composables/http/client.d.ts +0 -66
- package/dist/composables/http/index.d.ts +0 -8
- package/dist/composables/loading/index.d.ts +0 -7
- package/dist/composables/page-meta/index.d.ts +0 -18
- package/dist/composables/storage/index.d.ts +0 -16
- package/dist/composables/validate/index.d.ts +0 -12
- package/dist/error.d.ts +0 -1
- package/src/composables/_internal/unwrap.ts +0 -19
- package/src/composables/ad/index.ts +0 -412
- package/src/composables/algo/index.ts +0 -7
- package/src/composables/algo/uuid.ts +0 -27
- package/src/composables/color/index.ts +0 -44
- package/src/composables/contact/index.ts +0 -92
- package/src/composables/format/index.ts +0 -48
- package/src/composables/http/client.ts +0 -237
- package/src/composables/http/index.ts +0 -8
- package/src/composables/http/useRequest.ts +0 -107
- package/src/composables/loading/index.ts +0 -23
- package/src/composables/page-meta/index.ts +0 -49
- package/src/composables/storage/index.ts +0 -76
- package/src/composables/validate/index.ts +0 -58
- package/src/error.ts +0 -5
- /package/dist/composables/{http → request}/adapters/alist.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/base.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/cos.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/index.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/oss.d.ts +0 -0
- /package/dist/composables/{http → request}/adapters/qiniu.d.ts +0 -0
- /package/src/composables/{http → request}/adapters/alist.ts +0 -0
- /package/src/composables/{http → request}/adapters/base.ts +0 -0
- /package/src/composables/{http → request}/adapters/cos.ts +0 -0
- /package/src/composables/{http → request}/adapters/index.ts +0 -0
- /package/src/composables/{http → request}/adapters/oss.ts +0 -0
- /package/src/composables/{http → request}/adapters/qiniu.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hlw-uni/mp-vue",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.54",
|
|
4
4
|
"description": "hlw-uni 小程序运行时 — Vue 组件 + composables + theme + http + 工具集(合并自原 mp-core)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@dcloudio/types": "^3.4.30",
|
|
35
|
+
"@dcloudio/uni-app": "3.0.0-5000720260410001",
|
|
35
36
|
"@types/md5": "^2.3.6",
|
|
36
37
|
"@types/node": "^20.19.39",
|
|
37
38
|
"@vitejs/plugin-vue": "^5.2.4",
|
package/src/app.ts
CHANGED
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* useApp - 应用根上下文
|
|
3
|
-
* 生命周期、Pinia
|
|
3
|
+
* 生命周期、Pinia、hlw 注入收敛在此。
|
|
4
4
|
*/
|
|
5
5
|
import { createSSRApp, type App, type Component } from 'vue';
|
|
6
6
|
import { hlw } from '@/hlw';
|
|
7
|
-
import {
|
|
8
|
-
import { useDevice } from '@/composables/device';
|
|
9
|
-
import md5 from 'md5';
|
|
10
|
-
import type { ApiResponse, RequestConfig } from '@/composables/http/types';
|
|
7
|
+
import { useRequest } from '@/composables/request';
|
|
11
8
|
|
|
12
9
|
let _installed = false;
|
|
13
|
-
let _interceptorCleanup: Array<() => void> = [];
|
|
14
|
-
|
|
15
|
-
export interface InterceptorOptions {
|
|
16
|
-
/** API 基础地址 */
|
|
17
|
-
baseURL?: string;
|
|
18
|
-
/** 自动注入 Token 的 header 键名 */
|
|
19
|
-
tokenHeader?: string;
|
|
20
|
-
/** Token 来源函数 */
|
|
21
|
-
getToken?: () => string;
|
|
22
|
-
/** 登录失效时的处理函数 */
|
|
23
|
-
onLogout?: () => void;
|
|
24
|
-
/** 接口业务错误码是否自动 toast */
|
|
25
|
-
autoToastError?: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const _defaultOpts: InterceptorOptions = {
|
|
29
|
-
tokenHeader: 'x-token',
|
|
30
|
-
autoToastError: true,
|
|
31
|
-
};
|
|
32
10
|
|
|
33
11
|
/**
|
|
34
12
|
* 创建 uni-app 应用入口工具。
|
|
@@ -66,123 +44,5 @@ export function useApp() {
|
|
|
66
44
|
return createApp;
|
|
67
45
|
}
|
|
68
46
|
|
|
69
|
-
return { install, use, hlw,
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 提取 URL 中的 query 参数,排序后拼接为签名字符串。
|
|
74
|
-
*/
|
|
75
|
-
function buildSignString(url: string): string {
|
|
76
|
-
try {
|
|
77
|
-
const [path, query] = url.split('?');
|
|
78
|
-
if (!query) return path + '&';
|
|
79
|
-
const params = query.split('&').filter(Boolean);
|
|
80
|
-
params.sort();
|
|
81
|
-
return params.join('&') + '&';
|
|
82
|
-
} catch {
|
|
83
|
-
return url;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** sig 签名密钥。 */
|
|
88
|
-
let _sigSecret = '';
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 注册默认请求、响应和错误拦截器。
|
|
92
|
-
*/
|
|
93
|
-
export function setupInterceptors(options: InterceptorOptions & { sigSecret?: string } = {}) {
|
|
94
|
-
const opts = { ..._defaultOpts, ...options };
|
|
95
|
-
if (opts.sigSecret) _sigSecret = opts.sigSecret;
|
|
96
|
-
if (opts.baseURL) http.setBaseURL(opts.baseURL);
|
|
97
|
-
|
|
98
|
-
_interceptorCleanup.forEach((dispose) => dispose());
|
|
99
|
-
_interceptorCleanup = [];
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 请求拦截:注入设备信息、签名和 token。
|
|
103
|
-
*/
|
|
104
|
-
const offRequest = http.onRequest((config: RequestConfig) => {
|
|
105
|
-
// GET 请求:把 cfg.data 合并到 url query,并清空 cfg.data。
|
|
106
|
-
// 否则 uni.request 会在 sig 之后再把 data 自动拼到 URL,导致后端 raw query
|
|
107
|
-
// 多了未参与签名的字段(如 id/cate_id),sig 校验必然失败。
|
|
108
|
-
const method = (config.method ?? 'GET').toUpperCase();
|
|
109
|
-
if (method === 'GET' && config.data && typeof config.data === 'object') {
|
|
110
|
-
const qs = Object.entries(config.data as Record<string, unknown>)
|
|
111
|
-
.filter(([, v]) => v !== undefined && v !== null)
|
|
112
|
-
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
|
|
113
|
-
.join('&');
|
|
114
|
-
if (qs) {
|
|
115
|
-
config.url = config.url + (config.url.includes('?') ? '&' : '?') + qs;
|
|
116
|
-
}
|
|
117
|
-
config.data = undefined;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const device = useDevice();
|
|
121
|
-
if (device.value) {
|
|
122
|
-
const d = device.value;
|
|
123
|
-
const query = [
|
|
124
|
-
['appid', d.appid],
|
|
125
|
-
['device_brand', d.device_brand],
|
|
126
|
-
['device_model', d.device_model],
|
|
127
|
-
['device_id', d.device_id],
|
|
128
|
-
['device_type', d.device_type],
|
|
129
|
-
['device_orientation', d.device_orientation],
|
|
130
|
-
['platform', d.platform],
|
|
131
|
-
['system', d.system],
|
|
132
|
-
['os', d.os],
|
|
133
|
-
['version', d.version],
|
|
134
|
-
['sdk_version', d.sdk_version],
|
|
135
|
-
['host_name', d.host_name],
|
|
136
|
-
['host_version', d.host_version],
|
|
137
|
-
['host_language', d.host_language],
|
|
138
|
-
['language', d.language],
|
|
139
|
-
['app_version', d.app_version],
|
|
140
|
-
['app_version_code', d.app_version_code],
|
|
141
|
-
['screen_width', String(d.screen_width)],
|
|
142
|
-
['screen_height', String(d.screen_height)],
|
|
143
|
-
]
|
|
144
|
-
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v ?? '')}`)
|
|
145
|
-
.join('&');
|
|
146
|
-
config.url = config.url + (config.url.includes('?') ? '&' : '?') + query;
|
|
147
|
-
config.headers = { ...config.headers, 'X-Appid': d.appid };
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (_sigSecret) {
|
|
151
|
-
const signStr = buildSignString(config.url);
|
|
152
|
-
const sig = md5(signStr + _sigSecret);
|
|
153
|
-
config.url = config.url + '&sig=' + sig;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (opts.getToken) {
|
|
157
|
-
const token = opts.getToken();
|
|
158
|
-
if (token) {
|
|
159
|
-
config.headers = {
|
|
160
|
-
...config.headers,
|
|
161
|
-
[opts.tokenHeader!]: token,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return config;
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* 响应拦截:处理业务错误提示。
|
|
170
|
-
*/
|
|
171
|
-
const offResponse = http.onResponse((res: ApiResponse<unknown>) => {
|
|
172
|
-
if (opts.autoToastError && res.code !== 1) {
|
|
173
|
-
uni.showToast({ title: res.info || '请求失败', icon: 'none' });
|
|
174
|
-
}
|
|
175
|
-
return res;
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* 错误拦截:处理未授权场景。
|
|
180
|
-
*/
|
|
181
|
-
const offError = http.onError((err: Error) => {
|
|
182
|
-
if (err.message.includes('401')) {
|
|
183
|
-
opts.onLogout?.();
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
_interceptorCleanup = [offRequest, offResponse, offError];
|
|
47
|
+
return { install, use, hlw, request: useRequest() };
|
|
188
48
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
HlwAd — 小程序展示型广告原子组件
|
|
3
3
|
------------------------------------------------------------------
|
|
4
|
-
|
|
4
|
+
用法(业务方从自己的接口配置取对应 unit_id 传入):
|
|
5
5
|
hlw-ad type="banner" :unit-id="config.banner_unit_id"
|
|
6
6
|
hlw-ad type="grid" :unit-id="config.grid_unit_id"
|
|
7
7
|
hlw-ad type="custom" :unit-id="config.custom_unit_id"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- grid / custom → ad-custom unit-id="..."(原生模板广告)
|
|
12
12
|
|
|
13
13
|
video / reward / popup 不走这个组件:
|
|
14
|
-
- reward / popup →
|
|
14
|
+
- reward / popup → 业务方自行调用小程序广告 API
|
|
15
15
|
- video(贴片)须嵌在 video 标签内,业务侧自己用 <ad type="video">
|
|
16
16
|
-->
|
|
17
17
|
<template>
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
<script setup lang="ts">
|
|
36
36
|
/**
|
|
37
37
|
* hlw-page 不再负责主题 style 注入。
|
|
38
|
-
*
|
|
38
|
+
* 业务项目可通过 @hlw-uni/mp-vite-plugin 的 themePageMeta 自动注入 page-meta。
|
|
39
39
|
* —— 这样才能把 CSS 变量注入到 page 根,scroll-view 等小程序原生组件内部也能继承。
|
|
40
40
|
*
|
|
41
41
|
* provide("hlwPageScroll") —— 给 hlw-back-top 等子组件用:
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useDevice
|
|
3
|
-
* 使用微信 3.7.0+ 推荐的新 API 替代废弃的 getSystemInfoSync
|
|
2
|
+
* useDevice - 设备信息与接口 query
|
|
4
3
|
*/
|
|
5
|
-
import {
|
|
4
|
+
import { useUtils } from "../utils";
|
|
6
5
|
|
|
7
6
|
export interface DeviceInfo {
|
|
8
7
|
/** 小程序 appId */
|
|
@@ -63,106 +62,134 @@ export interface DeviceInfo {
|
|
|
63
62
|
version: string;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
export type DeviceQueryInfo = Pick<DeviceInfo,
|
|
66
|
+
| "appid"
|
|
67
|
+
| "device_brand"
|
|
68
|
+
| "device_model"
|
|
69
|
+
| "device_id"
|
|
70
|
+
| "device_type"
|
|
71
|
+
| "device_orientation"
|
|
72
|
+
| "platform"
|
|
73
|
+
| "system"
|
|
74
|
+
| "os"
|
|
75
|
+
| "version"
|
|
76
|
+
| "sdk_version"
|
|
77
|
+
| "host_name"
|
|
78
|
+
| "host_version"
|
|
79
|
+
| "host_language"
|
|
80
|
+
| "language"
|
|
81
|
+
| "app_version"
|
|
82
|
+
| "app_version_code"
|
|
83
|
+
| "screen_width"
|
|
84
|
+
| "screen_height"
|
|
85
|
+
>;
|
|
67
86
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
87
|
+
let deviceCache: DeviceInfo | null = null;
|
|
88
|
+
|
|
89
|
+
function readSafe(fn: (() => unknown) | undefined): Record<string, unknown> {
|
|
90
|
+
try {
|
|
91
|
+
return (fn?.() ?? {}) as Record<string, unknown>;
|
|
92
|
+
} catch {
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
73
95
|
}
|
|
74
96
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
function collect(): DeviceInfo {
|
|
79
|
-
// @ts-ignore — 新 API 在旧版 @dcloudio/types 中可能未声明
|
|
80
|
-
let deviceInfo = tryCall(uni.getDeviceInfo);
|
|
97
|
+
function collectDevice(): DeviceInfo {
|
|
98
|
+
// @ts-ignore - 新 API 在旧版 @dcloudio/types 中可能未声明。
|
|
99
|
+
let device = readSafe(uni.getDeviceInfo);
|
|
81
100
|
// @ts-ignore
|
|
82
|
-
let
|
|
83
|
-
let
|
|
101
|
+
let window = readSafe(uni.getWindowInfo);
|
|
102
|
+
let app = readSafe(uni.getAppBaseInfo);
|
|
84
103
|
|
|
85
|
-
if (!
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
104
|
+
if (!device.brand && !device.model) {
|
|
105
|
+
const system = readSafe(() => uni.getSystemInfoSync());
|
|
106
|
+
device = { ...system };
|
|
107
|
+
window = { ...system };
|
|
108
|
+
app = { ...system };
|
|
90
109
|
}
|
|
91
110
|
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
const accountInfo = uni.getAccountInfoSync() as { miniProgram?: { appId?: string } };
|
|
95
|
-
appid = accountInfo?.miniProgram?.appId || "";
|
|
96
|
-
} catch {
|
|
97
|
-
appid = (deviceInfo.appId as string) || "";
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const system = (deviceInfo.system as string) || "";
|
|
111
|
+
const system = (device.system as string) || "";
|
|
101
112
|
|
|
102
113
|
return {
|
|
103
|
-
appid,
|
|
104
|
-
app_name: (
|
|
105
|
-
app_version: (
|
|
106
|
-
app_version_code: (
|
|
107
|
-
app_channel: (
|
|
108
|
-
device_brand: (
|
|
109
|
-
device_model: (
|
|
110
|
-
device_id: (
|
|
111
|
-
device_type: (
|
|
112
|
-
device_orientation: (
|
|
113
|
-
brand: (
|
|
114
|
-
model: (
|
|
114
|
+
appid: getAppid(device),
|
|
115
|
+
app_name: (app.appName as string) || "",
|
|
116
|
+
app_version: (app.appVersion as string) || "",
|
|
117
|
+
app_version_code: (app.appVersionCode as string) || "",
|
|
118
|
+
app_channel: (app.appChannel as string) || "",
|
|
119
|
+
device_brand: (device.brand as string) || "",
|
|
120
|
+
device_model: (device.model as string) || "",
|
|
121
|
+
device_id: (device.deviceId as string) || "",
|
|
122
|
+
device_type: (device.deviceType as string) || "",
|
|
123
|
+
device_orientation: (window.deviceOrientation as "portrait" | "landscape") || "portrait",
|
|
124
|
+
brand: (device.brand as string) || "",
|
|
125
|
+
model: (device.model as string) || "",
|
|
115
126
|
system,
|
|
116
127
|
os: system.split(" ")[0] || "",
|
|
117
|
-
pixel_ratio: (
|
|
118
|
-
screen_width: (
|
|
119
|
-
screen_height: (
|
|
120
|
-
window_width: (
|
|
121
|
-
window_height: (
|
|
122
|
-
status_bar_height: (
|
|
123
|
-
sdk_version: (
|
|
124
|
-
host_name: (
|
|
125
|
-
host_version: (
|
|
126
|
-
host_language: (
|
|
127
|
-
host_theme: (
|
|
128
|
-
platform: (
|
|
129
|
-
language: (
|
|
130
|
-
version: (
|
|
128
|
+
pixel_ratio: (window.pixelRatio as number) || 0,
|
|
129
|
+
screen_width: (window.screenWidth as number) || 0,
|
|
130
|
+
screen_height: (window.screenHeight as number) || 0,
|
|
131
|
+
window_width: (window.windowWidth as number) || 0,
|
|
132
|
+
window_height: (window.windowHeight as number) || 0,
|
|
133
|
+
status_bar_height: (window.statusBarHeight as number) || 0,
|
|
134
|
+
sdk_version: (app.SDKVersion as string) || "",
|
|
135
|
+
host_name: (app.hostName as string) || "",
|
|
136
|
+
host_version: (app.hostVersion as string) || "",
|
|
137
|
+
host_language: (app.hostLanguage as string) || "",
|
|
138
|
+
host_theme: (app.hostTheme as string) || "",
|
|
139
|
+
platform: (device.platform as string) || "",
|
|
140
|
+
language: (app.language as string) || "",
|
|
141
|
+
version: (app.version as string) || "",
|
|
131
142
|
};
|
|
132
143
|
}
|
|
133
144
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
function getAppid(device: Record<string, unknown>) {
|
|
146
|
+
try {
|
|
147
|
+
const account = uni.getAccountInfoSync() as { miniProgram?: { appId?: string } };
|
|
148
|
+
return account?.miniProgram?.appId || "";
|
|
149
|
+
} catch {
|
|
150
|
+
return (device.appId as string) || "";
|
|
140
151
|
}
|
|
141
152
|
}
|
|
142
153
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
export function useDevice() {
|
|
147
|
-
ensure();
|
|
148
|
-
return _info;
|
|
154
|
+
function getDevice() {
|
|
155
|
+
deviceCache ??= collectDevice();
|
|
156
|
+
return deviceCache;
|
|
149
157
|
}
|
|
150
158
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
.
|
|
159
|
-
.
|
|
160
|
-
.
|
|
159
|
+
function getQueryInfo(info: DeviceInfo): DeviceQueryInfo {
|
|
160
|
+
return {
|
|
161
|
+
appid: info.appid,
|
|
162
|
+
device_brand: info.device_brand,
|
|
163
|
+
device_model: info.device_model,
|
|
164
|
+
device_id: info.device_id,
|
|
165
|
+
device_type: info.device_type,
|
|
166
|
+
device_orientation: info.device_orientation,
|
|
167
|
+
platform: info.platform,
|
|
168
|
+
system: info.system,
|
|
169
|
+
os: info.os,
|
|
170
|
+
version: info.version,
|
|
171
|
+
sdk_version: info.sdk_version,
|
|
172
|
+
host_name: info.host_name,
|
|
173
|
+
host_version: info.host_version,
|
|
174
|
+
host_language: info.host_language,
|
|
175
|
+
language: info.language,
|
|
176
|
+
app_version: info.app_version,
|
|
177
|
+
app_version_code: info.app_version_code,
|
|
178
|
+
screen_width: info.screen_width,
|
|
179
|
+
screen_height: info.screen_height,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function useDevice() {
|
|
184
|
+
const info = getDevice();
|
|
185
|
+
const { toQuery } = useUtils();
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
info,
|
|
189
|
+
query: toQuery(getQueryInfo(info)),
|
|
190
|
+
};
|
|
161
191
|
}
|
|
162
192
|
|
|
163
|
-
/**
|
|
164
|
-
* 手动清除缓存(切换账号等场景可能需要)
|
|
165
|
-
*/
|
|
166
193
|
export function clearDeviceCache(): void {
|
|
167
|
-
|
|
194
|
+
deviceCache = null;
|
|
168
195
|
}
|
package/src/composables/index.ts
CHANGED
|
@@ -1,51 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Composables 统一导出
|
|
3
3
|
*/
|
|
4
|
-
export * from "./
|
|
5
|
-
export { useLoading } from "./loading";
|
|
4
|
+
export * from "./request";
|
|
6
5
|
export { useMsg, type HlwMsg, type ToastOptions, type ModalOptions, type ToastIcon } from "./msg";
|
|
7
|
-
export { useDevice, deviceToQuery, clearDeviceCache, type DeviceInfo } from "./device";
|
|
8
|
-
export { useRefs } from "./refs";
|
|
9
|
-
export { usePageMeta } from "./page-meta";
|
|
10
|
-
export { useStorage, type StorageInstance } from "./storage";
|
|
11
|
-
export { useValidate } from "./validate";
|
|
12
|
-
export { useFormat } from "./format";
|
|
13
6
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
type AdAdapter,
|
|
21
|
-
type AdCloseResult,
|
|
22
|
-
} from "./ad";
|
|
7
|
+
useDevice,
|
|
8
|
+
clearDeviceCache,
|
|
9
|
+
type DeviceInfo,
|
|
10
|
+
type DeviceQueryInfo,
|
|
11
|
+
} from "./device";
|
|
12
|
+
export { useRefs } from "./refs";
|
|
23
13
|
export {
|
|
24
14
|
useShare,
|
|
25
|
-
useShareConfig,
|
|
26
|
-
setConfigShare,
|
|
27
15
|
type ShareConfig,
|
|
28
|
-
type ShareConfigResolver,
|
|
29
|
-
type ShareFrom,
|
|
30
|
-
type ShareAppMessageContent,
|
|
31
|
-
type ShareTimelineContent,
|
|
32
|
-
type ShareConfigMap,
|
|
33
|
-
type ShareConfigAdapter,
|
|
34
|
-
type PageShareItem,
|
|
35
|
-
type PageShareFallback,
|
|
36
|
-
type SharePayload,
|
|
37
16
|
} from "./share";
|
|
38
|
-
export {
|
|
39
|
-
|
|
40
|
-
setConfigContact,
|
|
41
|
-
type ContactConfig,
|
|
42
|
-
type ContactAdapter,
|
|
43
|
-
type ContactBindProps,
|
|
44
|
-
} from "./contact";
|
|
45
|
-
export { useUtils, type DownloadFileOptions, type DownloadFileResult, type TapEvent } from "./utils";
|
|
46
|
-
export { useColor } from "./color";
|
|
47
|
-
export { useRouter, type NavigateType, type NavigateOptions } from "./navigator";
|
|
48
|
-
export { useUuid } from "./algo";
|
|
17
|
+
export { useUtils, type DownloadOpt, type DownloadRes } from "./utils";
|
|
18
|
+
export { useNavigate, type NavigateType, type NavigateOptions } from "./navigator";
|
|
49
19
|
|
|
50
20
|
// Theme(mp-vue 自带)
|
|
51
21
|
export type { FontScale, FontPreset } from "./theme";
|