@hlw-uni/mp-vue 2.1.52 → 2.1.55
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/ad/index.d.ts +11 -73
- package/dist/composables/device/index.d.ts +5 -70
- package/dist/composables/index.d.ts +6 -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/utils/index.d.ts +25 -32
- package/dist/hlw.d.ts +2 -4
- package/dist/index.d.ts +2 -3
- package/dist/index.js +614 -1253
- package/dist/index.mjs +613 -1252
- package/package.json +2 -1
- package/src/app.ts +3 -143
- package/src/components/hlw-ad/index.vue +6 -5
- package/src/components/hlw-page/index.vue +1 -1
- package/src/composables/ad/README.md +58 -0
- package/src/composables/ad/index.ts +117 -376
- package/src/composables/device/README.md +50 -0
- package/src/composables/device/index.ts +110 -83
- package/src/composables/index.ts +10 -39
- package/src/composables/msg/README.md +79 -0
- package/src/composables/navigator/README.md +71 -0
- package/src/composables/navigator/index.ts +77 -77
- package/src/composables/refs/README.md +40 -0
- package/src/composables/request/README.md +124 -0
- package/src/composables/{http → request}/adapters/oss.ts +1 -0
- 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/README.md +53 -0
- package/src/composables/share/index.ts +64 -168
- package/src/composables/theme/README.md +131 -0
- package/src/composables/theme/index.ts +4 -2
- package/src/composables/theme/palette.ts +22 -4
- package/src/composables/utils/README.md +81 -0
- 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/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/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/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.55",
|
|
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>
|
|
@@ -81,12 +81,13 @@ function onError(event: any) {
|
|
|
81
81
|
background: var(--surface-card, #ffffff);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/*
|
|
84
|
+
/* 格子广告:默认右侧居中悬浮;微信硬性规则要求 wrapper 透明无圆角,customStyle 可覆盖 */
|
|
85
85
|
.hlw-ad--grid {
|
|
86
86
|
position: fixed;
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
top: 50%;
|
|
88
|
+
right: 0;
|
|
89
89
|
z-index: 99;
|
|
90
|
+
transform: translateY(-50%);
|
|
90
91
|
border-radius: 0;
|
|
91
92
|
overflow: visible;
|
|
92
93
|
background: transparent;
|
|
@@ -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 等子组件用:
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# ad 调用文档
|
|
2
|
+
|
|
3
|
+
`useHlwAd` 封装微信小程序插屏广告和激励视频广告。仅在存在 `wx` 且对应广告 API 可用时生效。
|
|
4
|
+
|
|
5
|
+
## 引入
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { useHlwAd } from "@hlw-uni/mp-vue";
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 插屏广告
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const ad = useHlwAd();
|
|
15
|
+
|
|
16
|
+
ad.setAdPopup("adunit-popup-id", (ok) => {
|
|
17
|
+
console.log("插屏广告关闭", ok);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await ad.showAdPopup(1000);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 激励视频
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
const ad = useHlwAd();
|
|
27
|
+
|
|
28
|
+
ad.setAdReward("adunit-reward-id", (res) => {
|
|
29
|
+
if (res.ok) {
|
|
30
|
+
// 用户完整看完激励视频
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const result = await ad.showAdReward();
|
|
35
|
+
|
|
36
|
+
if (result.ok) {
|
|
37
|
+
// 发放奖励
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
| 方法 | 说明 |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `setAdPopup(adId, done?)` | 创建插屏广告实例 |
|
|
46
|
+
| `showAdPopup(delay?)` | 延迟展示插屏广告,默认 3000ms |
|
|
47
|
+
| `setAdReward(adId, done?)` | 创建激励视频实例 |
|
|
48
|
+
| `showAdReward()` | 展示激励视频,失败时会尝试 load 后再 show |
|
|
49
|
+
|
|
50
|
+
## 类型
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
interface AdRes {
|
|
54
|
+
ok: boolean;
|
|
55
|
+
isEnded?: boolean;
|
|
56
|
+
err?: unknown;
|
|
57
|
+
}
|
|
58
|
+
```
|