@wxshot/api 0.1.4
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/README.md +253 -0
- package/miniprogram_dist/index.d.ts +287 -0
- package/miniprogram_dist/index.js +4 -0
- package/package.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
## 安装/更新
|
|
2
|
+
|
|
3
|
+
1、终端使用命令安装 npm 包
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install --save @jdwx/api@latest
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
> 一般会和[jdwx-components](https://code.miniappapi.com/wx/jdwx-components)一同搭配使用。安装:
|
|
10
|
+
> ```bash
|
|
11
|
+
> npm install --save @jdwx/components@latest
|
|
12
|
+
> ```
|
|
13
|
+
|
|
14
|
+
2、在小程序开发者工具中:菜单选择工具 -> 构建 npm
|
|
15
|
+
|
|
16
|
+
## 使用
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import {
|
|
20
|
+
onLoginReady,
|
|
21
|
+
waitLogin,
|
|
22
|
+
|
|
23
|
+
injectApp,
|
|
24
|
+
injectPage,
|
|
25
|
+
injectComponent,
|
|
26
|
+
hijackApp,
|
|
27
|
+
hijackAllPage,
|
|
28
|
+
|
|
29
|
+
gatewayHttpClient,
|
|
30
|
+
baseHttpClient,
|
|
31
|
+
apiHttpClient,
|
|
32
|
+
HttpClient,
|
|
33
|
+
|
|
34
|
+
adManager,
|
|
35
|
+
} from '@jdwx/api'
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### `waitLogin`/`onLoginReady` - 确保登录完成
|
|
39
|
+
|
|
40
|
+
- 同步的写法
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
async function onLoad() {
|
|
44
|
+
await waitLogin()
|
|
45
|
+
// 此处代码将在已登录或登陆完成后执行。请求将自动携带Token
|
|
46
|
+
await gatewayHttpClient.request('/xxx', 'GET', {})
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- 异步的写法
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
function onLoad() {
|
|
54
|
+
onLoginReady(() => {
|
|
55
|
+
// 此处代码将在已登录或登陆完成后执行。请求将自动携带Token
|
|
56
|
+
gatewayHttpClient.request('/xxx', 'GET', {})
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### `injectApp` - 向App注入基础代码
|
|
62
|
+
|
|
63
|
+
- 注入之后实现自动登录、广告初始化等功能
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
// app.js
|
|
67
|
+
App(injectApp()({
|
|
68
|
+
// 业务代码
|
|
69
|
+
onLaunch() {
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
}))
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### `injectPage` - 向Page注入基础代码
|
|
76
|
+
|
|
77
|
+
- 注入之后实现页面自动统计、自动展示插屏广告以及激励视频广告的调用支持
|
|
78
|
+
- 参数:
|
|
79
|
+
- showInterstitialAd: 是否自动展示插屏广告
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
// pages/xxx/xxx.js
|
|
83
|
+
Page(injectPage({
|
|
84
|
+
showInterstitialAd: true
|
|
85
|
+
})({
|
|
86
|
+
// 业务代码
|
|
87
|
+
onLoad() {
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
}))
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### `injectComponent` - 向Component注入基础代码
|
|
94
|
+
|
|
95
|
+
- 适用于使用Component构造页面的场景
|
|
96
|
+
- 注入之后实现页面自动统计、自动展示插屏广告以及激励视频广告的调用支持
|
|
97
|
+
- 参数:
|
|
98
|
+
- showInterstitialAd: 是否自动展示插屏广告
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
// pages/xxx/xxx.js
|
|
102
|
+
Component(injectComponent({
|
|
103
|
+
showInterstitialAd: true
|
|
104
|
+
})({
|
|
105
|
+
// 业务代码
|
|
106
|
+
methods: {
|
|
107
|
+
onLoad() {
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}))
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `hijackApp` - 劫持全局App方法,注入基础代码
|
|
115
|
+
|
|
116
|
+
- 在不方便使用injectApp时使用(如解包后代码复杂,难以修改App调用)
|
|
117
|
+
- 此方法会修改全局App方法,存在未知风险,使用时请进行完整测试
|
|
118
|
+
- 不可与injectApp同时使用
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
// app.js
|
|
122
|
+
hijackApp()
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### `hijackAllPage` - 劫持全局Page方法,注入基础代码
|
|
126
|
+
|
|
127
|
+
- 在不方便使用injectPage/injectComponent时使用(如解包后代码复杂,难以修改Page/Component调用)
|
|
128
|
+
- 此方法会修改全局Page方法,并影响所有的页面,存在未知风险,使用时请进行完整测试
|
|
129
|
+
- 参数同injectPage/injectComponent方法,不可与这些方法同时使用
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
// app.js
|
|
133
|
+
hijackAllPage({
|
|
134
|
+
showInterstitialAd: true
|
|
135
|
+
})
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `gatewayHttpClient` - 网关API调用封装
|
|
139
|
+
|
|
140
|
+
- 同步的写法
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
async function onLoad() {
|
|
144
|
+
try {
|
|
145
|
+
// 网关请求。参数:路径、方法、数据、其他选项(如headers、responseType)
|
|
146
|
+
const data = await gatewayHttpClient.request(path, method, data,options)
|
|
147
|
+
|
|
148
|
+
// 头像上传。参数:文件路径
|
|
149
|
+
const data = await gatewayHttpClient.uploadAvatar(filePath)
|
|
150
|
+
|
|
151
|
+
// 文件上传。参数:文件路径、数据
|
|
152
|
+
const data = await gatewayHttpClient.uploadFile(filePath, data)
|
|
153
|
+
|
|
154
|
+
// 文件删除。参数:文件ID
|
|
155
|
+
const data = await gatewayHttpClient.deleteFile(fileId)
|
|
156
|
+
} catch(err) {
|
|
157
|
+
// 响应HTTP状态码非200时自动showToast并抛出异常
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- 所有方法均支持异步的写法
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
function onLoad() {
|
|
166
|
+
gatewayHttpClient.request('/xxx')
|
|
167
|
+
.then(data => {
|
|
168
|
+
console.log(data)
|
|
169
|
+
})
|
|
170
|
+
.catch(err => {})
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### `baseHttpClient`/`apiHttpClient` - 为老版本兼容保留,不推荐使用
|
|
175
|
+
|
|
176
|
+
### `HttpClient` - API底层类,用于封装自定义请求
|
|
177
|
+
|
|
178
|
+
- 示例:封装一个百度的请求客户端,并调用百度搜索
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
const baiduHttpClient = new HttpClient({
|
|
182
|
+
baseURL: 'https://www.baidu.com',
|
|
183
|
+
timeout: 5000,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
baiduHttpClient.request('/s', 'GET', { wd: '测试' }, { responseType: 'text' })
|
|
187
|
+
.then(data => console.log(data))
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### `adManager` - 广告管理器
|
|
191
|
+
|
|
192
|
+
- 确保广告数据加载完成,支持同步/异步的写法
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
// 同步的写法
|
|
196
|
+
async function onLoad() {
|
|
197
|
+
await adManager.waitAdData()
|
|
198
|
+
// 此处代码将在广告数据加载完成后执行
|
|
199
|
+
await adManager.createAndShowInterstitialAd()
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 异步的写法
|
|
203
|
+
function onLoad () {
|
|
204
|
+
adManager.onDataReady(() => {
|
|
205
|
+
// 此处代码将在广告数据加载完成后执行
|
|
206
|
+
adManager.createAndShowInterstitialAd()
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
- 广告数据
|
|
212
|
+
|
|
213
|
+
```js
|
|
214
|
+
// 格式化之后的广告数据对象,如{banner: "adunit-f7709f349de05edc", custom: "adunit-34c76b0c3e4a6ed0", ...}
|
|
215
|
+
const ads = adManager.ads
|
|
216
|
+
|
|
217
|
+
// 友情链接顶部广告数据
|
|
218
|
+
const top = adManager.top
|
|
219
|
+
|
|
220
|
+
// 友情链接数据
|
|
221
|
+
const link = adManager.link
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
- 创建并展示插屏广告
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
function onLoad() {
|
|
228
|
+
adManager.createAndShowInterstitialAd()
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- 创建并展示激励视频广告
|
|
233
|
+
- 传入当前页面的上下文this,返回用户是否已看完广告
|
|
234
|
+
- 由于微信的底层限制,需要先在调用的页面上进行injectPage注入,且该方法必须放在用户的点击事件里调用
|
|
235
|
+
- 使用示例可参考[jdwx-demo](https://code.miniappapi.com/wx/jdwx-demo)
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
// 同步的写法
|
|
239
|
+
page({
|
|
240
|
+
async handleClick() {
|
|
241
|
+
const isEnded = await adManager.createAndShowRewardedVideoAd(this)
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
// 异步的写法
|
|
246
|
+
page({
|
|
247
|
+
handleClick() {
|
|
248
|
+
adManager.createAndShowRewardedVideoAd(this).then((isEnded) => {
|
|
249
|
+
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
```
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// Generated by dts-bundle v0.7.3
|
|
2
|
+
|
|
3
|
+
declare module '@wxshot/api' {
|
|
4
|
+
import { onLoginReady, waitLogin } from '@wxshot/api/app';
|
|
5
|
+
import HttpClient, { gatewayHttpClient, baseHttpClient, apiHttpClient } from '@wxshot/api/httpClient';
|
|
6
|
+
import { injectApp, injectPage, injectComponent, hijackApp, hijackAllPage } from '@wxshot/api/injector';
|
|
7
|
+
import adManager from '@wxshot/api/adManager';
|
|
8
|
+
export { onLoginReady, waitLogin, injectApp, injectPage, injectComponent, hijackApp, hijackAllPage, gatewayHttpClient, baseHttpClient, apiHttpClient, HttpClient, adManager, };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module '@wxshot/api/app' {
|
|
12
|
+
export interface AppOptions {
|
|
13
|
+
gatewayUrl?: string;
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
apiUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PageOptions {
|
|
18
|
+
showInterstitialAd?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export function initApp(options?: AppOptions): Promise<void>;
|
|
21
|
+
export function showPage(options: PageOptions | undefined, pageId: string): Promise<void>;
|
|
22
|
+
export const checkTokenValid: () => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 确保登录完成
|
|
25
|
+
* @param {Function} callback - 回调函数
|
|
26
|
+
* @returns {void}
|
|
27
|
+
*/
|
|
28
|
+
export function onLoginReady(callback: (...args: any[]) => void): void;
|
|
29
|
+
/**
|
|
30
|
+
* 等待登录完成
|
|
31
|
+
* @returns {Promise<void>}
|
|
32
|
+
*/
|
|
33
|
+
export function waitLogin(): Promise<void>;
|
|
34
|
+
export function login(): Promise<void>;
|
|
35
|
+
export function fetchEchoData(): Promise<void>;
|
|
36
|
+
export function trackVisit(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '@wxshot/api/httpClient' {
|
|
40
|
+
import { HttpClientOptions, RequestOptions, ApiResponse } from '@wxshot/api/types';
|
|
41
|
+
class HttpClient {
|
|
42
|
+
constructor({ baseURL, timeout }: HttpClientOptions);
|
|
43
|
+
setBaseURL(baseURL: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* 请求
|
|
46
|
+
* @param {string} path 路径
|
|
47
|
+
* @param {string} method 方法, 默认GET
|
|
48
|
+
* @param {Object} data 数据, 默认{}
|
|
49
|
+
* @param {Object} options 传入wx.request的其他配置, 默认{}
|
|
50
|
+
* @returns {Promise<Object>} 返回一个Promise对象
|
|
51
|
+
*/
|
|
52
|
+
request<T = any>(path: string, method?: WechatMiniprogram.RequestOption['method'], data?: Record<string, any>, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
53
|
+
/**
|
|
54
|
+
* 上传文件
|
|
55
|
+
* @param {string} filePath 文件路径
|
|
56
|
+
* @param {Object} data 数据, 默认{}
|
|
57
|
+
* @param {'avatar' | 'file'} type 类型, 默认'file'
|
|
58
|
+
* @returns {Promise<Object>} 返回一个Promise对象
|
|
59
|
+
*/
|
|
60
|
+
uploadFile<T = any>(filePath: string, data?: Record<string, any>, type?: 'avatar' | 'file'): Promise<ApiResponse<T>>;
|
|
61
|
+
/**
|
|
62
|
+
* 删除文件
|
|
63
|
+
* @param {number} fileId 文件id
|
|
64
|
+
* @returns {Promise<Object>} 返回一个Promise对象
|
|
65
|
+
*/
|
|
66
|
+
deleteFile(fileId: number): Promise<ApiResponse<null>>;
|
|
67
|
+
/**
|
|
68
|
+
* 上传头像
|
|
69
|
+
* @param {string} filePath 文件路径
|
|
70
|
+
* @returns {Promise<Object>} 返回一个Promise对象
|
|
71
|
+
*/
|
|
72
|
+
uploadAvatar<T = any>(filePath: string): Promise<ApiResponse<T>>;
|
|
73
|
+
}
|
|
74
|
+
export const gatewayHttpClient: HttpClient;
|
|
75
|
+
export const baseHttpClient: HttpClient;
|
|
76
|
+
export const apiHttpClient: HttpClient;
|
|
77
|
+
export default HttpClient;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
declare module '@wxshot/api/injector' {
|
|
81
|
+
interface AppConfig {
|
|
82
|
+
onLaunch?: (...args: any[]) => void | Promise<void>;
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
}
|
|
85
|
+
interface PageConfig {
|
|
86
|
+
onShow?: (...args: any[]) => void | Promise<void>;
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
}
|
|
89
|
+
interface ComponentConfig {
|
|
90
|
+
methods?: {
|
|
91
|
+
onLoad?: (...args: any[]) => void | Promise<void>;
|
|
92
|
+
onShow?: (...args: any[]) => void | Promise<void>;
|
|
93
|
+
[key: string]: any;
|
|
94
|
+
};
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
}
|
|
97
|
+
interface InjectAppOptions {
|
|
98
|
+
gatewayUrl?: string;
|
|
99
|
+
baseUrl?: string;
|
|
100
|
+
apiUrl?: string;
|
|
101
|
+
}
|
|
102
|
+
interface InjectPageOptions {
|
|
103
|
+
showInterstitialAd?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 注入应用配置
|
|
107
|
+
* @param {Object} options - 配置选项
|
|
108
|
+
* @param {string} [options.gatewayUrl] - 网关地址,默认使用CONFIG.API.GATEWAY_URL
|
|
109
|
+
* @param {string} [options.baseUrl] - 基础地址,默认使用CONFIG.API.BASE_URL
|
|
110
|
+
* @param {string} [options.apiUrl] - api地址,默认使用CONFIG.API.API_URL
|
|
111
|
+
* @returns {Function} 返回一个接收应用配置的函数
|
|
112
|
+
*/
|
|
113
|
+
export function injectApp(options?: InjectAppOptions): (appConfig: AppConfig) => AppConfig;
|
|
114
|
+
/**
|
|
115
|
+
* 注入页面配置
|
|
116
|
+
* @param {InjectPageOptions} options - 配置选项
|
|
117
|
+
* @param {boolean} [options.showInterstitialAd] - 是否在onShow显示插屏广告,默认不显示
|
|
118
|
+
* @returns {Function} 返回一个接收页面配置的函数
|
|
119
|
+
*/
|
|
120
|
+
export function injectPage(options?: InjectPageOptions): (pageConfig?: PageConfig) => PageConfig;
|
|
121
|
+
/**
|
|
122
|
+
* 注入组件配置
|
|
123
|
+
* @param {InjectPageOptions} options - 配置选项
|
|
124
|
+
* @param {boolean} [options.showInterstitialAd] - 是否在onShow显示插屏广告,默认不显示
|
|
125
|
+
* @returns {Function} 返回一个接收组件配置的函数
|
|
126
|
+
*/
|
|
127
|
+
export function injectComponent(options?: InjectPageOptions): (pageConfig?: PageConfig) => ComponentConfig;
|
|
128
|
+
/**
|
|
129
|
+
* 劫持App
|
|
130
|
+
* @param {InjectAppOptions} options - 配置选项
|
|
131
|
+
* @param {string} [options.gatewayUrl] - 网关地址,默认使用CONFIG.API.GATEWAY_URL
|
|
132
|
+
* @param {string} [options.baseUrl] - 基础地址,默认使用CONFIG.API.BASE_URL
|
|
133
|
+
* @param {string} [options.apiUrl] - api地址,默认使用CONFIG.API.API_URL
|
|
134
|
+
* @returns {void}
|
|
135
|
+
*/
|
|
136
|
+
export const hijackApp: (options?: InjectAppOptions) => void;
|
|
137
|
+
/**
|
|
138
|
+
* 劫持所有Page
|
|
139
|
+
* @param {InjectPageOptions} options - 配置选项
|
|
140
|
+
* @param {boolean} [options.showInterstitialAd] - 是否在onShow显示插屏广告,默认不显示
|
|
141
|
+
* @returns {void}
|
|
142
|
+
*/
|
|
143
|
+
export const hijackAllPage: (options?: InjectPageOptions) => void;
|
|
144
|
+
export {};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
declare module '@wxshot/api/adManager' {
|
|
148
|
+
import { AdData, LinkData, TopData } from '@wxshot/api/types';
|
|
149
|
+
type Ads = Partial<Record<AdData['appPage'], AdData['ads'][0]['adUnitId']>>;
|
|
150
|
+
class AdManager {
|
|
151
|
+
/**
|
|
152
|
+
* 广告数据
|
|
153
|
+
*/
|
|
154
|
+
ads: Ads;
|
|
155
|
+
/**
|
|
156
|
+
* 友情链接数据
|
|
157
|
+
*/
|
|
158
|
+
link: LinkData[];
|
|
159
|
+
/**
|
|
160
|
+
* 友情链接顶部广告数据
|
|
161
|
+
*/
|
|
162
|
+
top: TopData | null;
|
|
163
|
+
constructor();
|
|
164
|
+
/**
|
|
165
|
+
* 确保广告数据就绪
|
|
166
|
+
* @param {Function} callback - 回调函数
|
|
167
|
+
* @returns {void}
|
|
168
|
+
*/
|
|
169
|
+
onDataReady: (callback: (...args: any[]) => void) => void;
|
|
170
|
+
/**
|
|
171
|
+
* 等待广告数据加载完成
|
|
172
|
+
* @returns {Promise<void>}
|
|
173
|
+
*/
|
|
174
|
+
waitAdData: () => Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* 初始化广告数据
|
|
177
|
+
* @returns {void}
|
|
178
|
+
*/
|
|
179
|
+
init: () => void;
|
|
180
|
+
/**
|
|
181
|
+
* 创建并展示插屏广告
|
|
182
|
+
* @returns {Promise<void>}
|
|
183
|
+
*/
|
|
184
|
+
createAndShowInterstitialAd: () => Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* 创建并展示激励视频广告
|
|
187
|
+
* @param {any} context - 页面上下文
|
|
188
|
+
* @param {string} [pageId] - 页面ID
|
|
189
|
+
* @returns {Promise<boolean>} 是否完成播放
|
|
190
|
+
*/
|
|
191
|
+
createAndShowRewardedVideoAd: (context: any, pageId?: string) => Promise<boolean>;
|
|
192
|
+
}
|
|
193
|
+
const _default: AdManager;
|
|
194
|
+
export default _default;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
declare module '@wxshot/api/types' {
|
|
198
|
+
export interface Config {
|
|
199
|
+
API: {
|
|
200
|
+
GATEWAY_URL: string;
|
|
201
|
+
BASE_URL: string;
|
|
202
|
+
API_URL: string;
|
|
203
|
+
};
|
|
204
|
+
APP: {
|
|
205
|
+
APP_ID: number;
|
|
206
|
+
LOGIN_MAX_RETRY: number;
|
|
207
|
+
};
|
|
208
|
+
HTTP: {
|
|
209
|
+
TIMEOUT: number;
|
|
210
|
+
};
|
|
211
|
+
DATA: {
|
|
212
|
+
PAGE_ID: string;
|
|
213
|
+
};
|
|
214
|
+
STORAGE_KEYS: {
|
|
215
|
+
TOKEN: string;
|
|
216
|
+
USER_INFO: string;
|
|
217
|
+
SPA_DATA: string;
|
|
218
|
+
LINK_DATA: string;
|
|
219
|
+
TOP_DATA: string;
|
|
220
|
+
};
|
|
221
|
+
EVENT_KEYS: {
|
|
222
|
+
LOGIN_SUCCESS: string;
|
|
223
|
+
AD_DATA_READY: string;
|
|
224
|
+
REWARDED_VIDEO_AD_CLOSE: string;
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
export interface HttpClientOptions {
|
|
228
|
+
baseURL: string;
|
|
229
|
+
timeout?: number;
|
|
230
|
+
}
|
|
231
|
+
export interface RequestOptions {
|
|
232
|
+
headers?: Record<string, string>;
|
|
233
|
+
[key: string]: any;
|
|
234
|
+
}
|
|
235
|
+
export interface LoginData {
|
|
236
|
+
appId: number;
|
|
237
|
+
code: string;
|
|
238
|
+
brand: string;
|
|
239
|
+
model: string;
|
|
240
|
+
platform: string;
|
|
241
|
+
}
|
|
242
|
+
export interface ApiResponse<T = any> {
|
|
243
|
+
code: number;
|
|
244
|
+
message?: string;
|
|
245
|
+
data?: T;
|
|
246
|
+
}
|
|
247
|
+
export interface UserInfo {
|
|
248
|
+
token: string;
|
|
249
|
+
user: {
|
|
250
|
+
id: number;
|
|
251
|
+
name: string;
|
|
252
|
+
avatar: string;
|
|
253
|
+
openId: string;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export interface EchoData {
|
|
257
|
+
isPublished: boolean;
|
|
258
|
+
spads: AdData[];
|
|
259
|
+
links: LinkData[];
|
|
260
|
+
top: TopData;
|
|
261
|
+
version: number;
|
|
262
|
+
}
|
|
263
|
+
export interface AdData {
|
|
264
|
+
id: number;
|
|
265
|
+
status: number;
|
|
266
|
+
appPage: 'banner' | 'custom' | 'video' | 'interstitial' | 'rewarded';
|
|
267
|
+
ads: {
|
|
268
|
+
id: number;
|
|
269
|
+
type: number;
|
|
270
|
+
adId: number;
|
|
271
|
+
adUnitId: string;
|
|
272
|
+
}[];
|
|
273
|
+
}
|
|
274
|
+
export interface LinkData {
|
|
275
|
+
appId: string;
|
|
276
|
+
appLogo: string;
|
|
277
|
+
linkName: string;
|
|
278
|
+
linkPage: string;
|
|
279
|
+
}
|
|
280
|
+
export interface TopData {
|
|
281
|
+
appId: string;
|
|
282
|
+
appLogo: string;
|
|
283
|
+
linkName: string;
|
|
284
|
+
appDsc: string;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @jdwx/api v0.1.4
|
|
3
|
+
*
|
|
4
|
+
*/(()=>{"use strict";var t={616:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,s)}u((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},a=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var i=a(n(28)),s=a(n(144)),u=function(){var t=this;this.ads={},this.link=[],this.top=null,this.adDataReady=!1,this.interstitialAd=null,this.rewardedVideoAds={},this.onDataReady=function(e){t.adDataReady?e():s.default.once(i.default.EVENT_KEYS.AD_DATA_READY,e)},this.waitAdData=function(){return new Promise((function(e){t.onDataReady(e)}))},this.init=function(){t.getData()},this.getData=function(){var e=wx.getStorageSync(i.default.STORAGE_KEYS.SPA_DATA);e&&(t.ads=e.reduce((function(t,e){return t[e.appPage]=e.ads&&e.ads.length>0?e.ads[0].adUnitId:"",t}),{}));var n=wx.getStorageSync(i.default.STORAGE_KEYS.LINK_DATA);n&&(t.link=n);var r=wx.getStorageSync(i.default.STORAGE_KEYS.TOP_DATA);r&&r.appDsc.length>40&&(r.appDsc=r.appDsc.substring(0,40)+"...",t.top=r),t.adDataReady=!0,s.default.emit(i.default.EVENT_KEYS.AD_DATA_READY)},this.createAndShowInterstitialAd=function(){return r(t,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return this.interstitialAd&&this.interstitialAd.destroy(),[4,this.waitAdData()];case 1:e.sent(),e.label=2;case 2:return e.trys.push([2,5,,6]),[4,this.createInterstitialAd()];case 3:return e.sent(),[4,this.showInterstitialAd()];case 4:return e.sent(),[3,6];case 5:return t=e.sent(),console.error("创建插屏广告失败:",t),[3,6];case 6:return[2]}}))}))},this.createInterstitialAd=function(){return r(t,void 0,void 0,(function(){var t=this;return o(this,(function(e){return[2,new Promise((function(e,n){t.ads.interstitial?(t.interstitialAd=wx.createInterstitialAd({adUnitId:t.ads.interstitial}),t.interstitialAd.onLoad((function(){console.log("插屏广告加载成功"),e()})),t.interstitialAd.onError((function(t){console.error(t),n(new Error("插屏广告加载失败"))})),t.interstitialAd.onClose((function(){console.log("插屏广告关闭")}))):n(new Error("插屏广告未配置"))}))]}))}))},this.showInterstitialAd=function(){return r(t,void 0,void 0,(function(){var t,e;return o(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),console.log("开始展示插屏广告"),[4,null===(e=this.interstitialAd)||void 0===e?void 0:e.show()];case 1:return[2,n.sent()];case 2:return t=n.sent(),console.error("插屏广告展示失败:",t),[3,3];case 3:return[2]}}))}))},this.createAndShowRewardedVideoAd=function(e,n){return r(t,void 0,void 0,(function(){var t,r,a;return o(this,(function(o){switch(o.label){case 0:return[4,this.waitAdData()];case 1:o.sent(),t=n||(null===(a=null==e?void 0:e.data)||void 0===a?void 0:a[i.default.DATA.PAGE_ID]),o.label=2;case 2:if(o.trys.push([2,6,,7]),!t)throw new Error("未指定pageId或者context");return this.rewardedVideoAds[t]?[3,4]:[4,this.createRewardedVideoAd(t)];case 3:o.sent(),o.label=4;case 4:return[4,this.showRewardedVideoAd(t)];case 5:return o.sent(),[3,7];case 6:return r=o.sent(),console.error("创建激励视频广告失败:",r),[3,7];case 7:return[2,new Promise((function(e){s.default.on(i.default.EVENT_KEYS.REWARDED_VIDEO_AD_CLOSE,(function(n,r){n===t&&e(r)}))}))]}}))}))},this.createRewardedVideoAd=function(e){return r(t,void 0,void 0,(function(){var t=this;return o(this,(function(n){return[2,new Promise((function(n,r){t.ads.rewarded?(t.rewardedVideoAds[e]=wx.createRewardedVideoAd({adUnitId:t.ads.rewarded}),t.rewardedVideoAds[e].onLoad((function(){console.log("激励视频广告加载成功"),n()})),t.rewardedVideoAds[e].onError((function(t){console.error(t),r(new Error("激励视频广告加载失败"))})),t.rewardedVideoAds[e].onClose((function(t){s.default.emit(i.default.EVENT_KEYS.REWARDED_VIDEO_AD_CLOSE,e,t.isEnded),console.log("激励视频广告关闭")}))):r(new Error("激励视频广告未配置"))}))]}))}))},this.showRewardedVideoAd=function(e){return r(t,void 0,void 0,(function(){var t,n;return o(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),console.log("开始展示激励视频广告"),[4,null===(n=this.rewardedVideoAds[e])||void 0===n?void 0:n.show()];case 1:return[2,r.sent()];case 2:return t=r.sent(),console.error("激励视频广告展示失败:",t),[3,3];case 3:return[2]}}))}))}};e.default=new u},859:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,s)}u((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},a=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.checkTokenValid=void 0,e.initApp=function(){return r(this,arguments,void 0,(function(t){return void 0===t&&(t={}),o(this,(function(e){switch(e.label){case 0:return t.gatewayUrl&&i.gatewayHttpClient.setBaseURL(t.gatewayUrl),t.baseUrl&&i.baseHttpClient.setBaseURL(t.baseUrl),t.apiUrl&&i.apiHttpClient.setBaseURL(t.apiUrl),[4,h()];case 1:return e.sent(),[4,p()];case 2:return e.sent(),c.default.init(),[2]}}))}))},e.showPage=function(){return r(this,arguments,void 0,(function(t,e){return void 0===t&&(t={}),o(this,(function(e){switch(e.label){case 0:return t.showInterstitialAd&&c.default.createAndShowInterstitialAd(),[4,f()];case 1:return e.sent(),[4,w()];case 2:return e.sent(),[2]}}))}))},e.onLoginReady=d,e.waitLogin=f,e.login=h,e.fetchEchoData=p,e.trackVisit=w;var i=n(161),s=a(n(28)),u=a(n(144)),c=a(n(616)),l=0;function d(t){(0,e.checkTokenValid)()?t():u.default.once(s.default.EVENT_KEYS.LOGIN_SUCCESS,t)}function f(){return new Promise((function(t){d(t)}))}function h(){return r(this,void 0,void 0,(function(){var t,e,n,r;return o(this,(function(o){switch(o.label){case 0:if(wx.removeStorageSync(s.default.STORAGE_KEYS.TOKEN),wx.removeStorageSync(s.default.STORAGE_KEYS.USER_INFO),l>s.default.APP.LOGIN_MAX_RETRY)throw wx.showToast({title:"网络异常,无法初始化",icon:"none",duration:2e3}),new Error("网络异常,无法初始化");o.label=1;case 1:return o.trys.push([1,7,,9]),t=wx.getDeviceInfo(),[4,wx.login()];case 2:return e=o.sent().code,n={appId:s.default.APP.APP_ID,code:e,brand:t.brand,model:t.model,platform:t.platform},[4,i.gatewayHttpClient.request("/wxbase/v1/api/login","POST",n)];case 3:return 200===(r=o.sent()).code&&r.data?(wx.setStorageSync(s.default.STORAGE_KEYS.TOKEN,r.data.token),wx.setStorageSync(s.default.STORAGE_KEYS.USER_INFO,r.data.user),l=0,u.default.emit(s.default.EVENT_KEYS.LOGIN_SUCCESS),[3,6]):[3,4];case 4:return l++,[4,h()];case 5:o.sent(),o.label=6;case 6:return[3,9];case 7:return o.sent(),l++,[4,h()];case 8:return o.sent(),[3,9];case 9:return[2]}}))}))}function p(){return r(this,void 0,void 0,(function(){var t;return o(this,(function(n){switch(n.label){case 0:return wx.removeStorageSync(s.default.STORAGE_KEYS.SPA_DATA),wx.removeStorageSync(s.default.STORAGE_KEYS.LINK_DATA),wx.removeStorageSync(s.default.STORAGE_KEYS.TOP_DATA),(0,e.checkTokenValid)()?[4,i.gatewayHttpClient.request("/wxbase/v1/api/echo","GET")]:[2];case 1:return 200===(t=n.sent()).code&&t.data?(t.data.spads&&wx.setStorageSync(s.default.STORAGE_KEYS.SPA_DATA,t.data.spads),t.data.links&&wx.setStorageSync(s.default.STORAGE_KEYS.LINK_DATA,t.data.links),t.data.top&&wx.setStorageSync(s.default.STORAGE_KEYS.TOP_DATA,t.data.top),[3,5]):[3,2];case 2:return 401!==t.code?[3,5]:[4,h()];case 3:return n.sent(),[4,p()];case 4:n.sent(),n.label=5;case 5:return[2]}}))}))}function w(){return r(this,void 0,void 0,(function(){var t;return o(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,i.gatewayHttpClient.request("/wxbase/v1/api/visit","POST")];case 1:return 401!==e.sent().code?[3,4]:[4,h()];case 2:return e.sent(),[4,w()];case 3:e.sent(),e.label=4;case 4:return[3,6];case 5:return t=e.sent(),console.error("访问统计失败:",t),[3,6];case 6:return[2]}}))}))}e.checkTokenValid=function(){var t=wx.getStorageSync(s.default.STORAGE_KEYS.TOKEN);return!(!t||t.length<32)}},28:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n={API:{GATEWAY_URL:"https://ca.wxshot.cn",BASE_URL:"https://app.wxshot.cn/v1/api",API_URL:"https://cp.wxshot.cn"},APP:{APP_ID:wx.getExtConfigSync().appId||14,LOGIN_MAX_RETRY:2},HTTP:{TIMEOUT:5e3},DATA:{PAGE_ID:"jdwx-page-id"},STORAGE_KEYS:{TOKEN:"jdwx-token",USER_INFO:"jdwx-userinfo",SPA_DATA:"jdwx-spadata",LINK_DATA:"jdwx-linkdata",TOP_DATA:"jdwx-topdata"},EVENT_KEYS:{LOGIN_SUCCESS:"jdwx-login-success",AD_DATA_READY:"jdwx-ad-data-ready",REWARDED_VIDEO_AD_CLOSE:"jdwx-rewarded-video-ad-close"}};e.default=n},144:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){this.events={}}return t.prototype.on=function(t,e){if("string"!=typeof t)throw new TypeError("eventName must be a string");if("function"!=typeof e)throw new TypeError("callback must be a function");return this.events[t]||(this.events[t]=[]),this.events[t].push(e),this},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if("string"!=typeof t)throw new TypeError("eventName must be a string");var r=this.events[t];return r&&r.forEach((function(n){try{n.apply(void 0,e)}catch(e){console.error('Error in event "'.concat(t,'" callback:'),e)}})),this},t.prototype.off=function(t,e){if("string"!=typeof t)throw new TypeError("eventName must be a string");return e?(this.events[t]&&(this.events[t]=this.events[t].filter((function(t){return t!==e}))),this):(delete this.events[t],this)},t.prototype.once=function(t,e){var n=this;if("string"!=typeof t)throw new TypeError("eventName must be a string");if("function"!=typeof e)throw new TypeError("callback must be a function");var r=function(){for(var o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];n.off(t,r),e.apply(n,o)};return this.on(t,r)},t}();e.default=new n},161:function(t,e,n){var r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)},o=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,s)}u((r=r.apply(t,e||[])).next())}))},a=this&&this.__generator||function(t,e){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.apiHttpClient=e.baseHttpClient=e.gatewayHttpClient=void 0;var s=i(n(28)),u=function(){function t(t){var e=t.baseURL,n=t.timeout;if(!e)throw new Error("baseURL is required");this.baseURL=e,this.timeout=n||s.default.HTTP.TIMEOUT}return t.prototype.setBaseURL=function(t){this.baseURL=t},t.prototype.wxRequestPromise=function(t){return new Promise((function(e,n){wx.request(r(r({},t),{success:function(t){e(t)},fail:function(t){n(t)}}))}))},t.prototype.joinURL=function(t,e){var n=t.replace(/\/+$/,""),r=e.replace(/^\/+/,"");return"".concat(n,"/").concat(r)},t.prototype.request=function(t){return o(this,arguments,void 0,(function(t,e,n,o){var i,u,c,l,d,f,h=this;return void 0===e&&(e="GET"),void 0===n&&(n={}),void 0===o&&(o={}),a(this,(function(a){switch(a.label){case 0:i=wx.getStorageSync(s.default.STORAGE_KEYS.TOKEN),u={Authorization:i,"Content-Type":"application/json"},c=new Promise((function(t,e){setTimeout((function(){return e(new Error("请求超时"))}),h.timeout)})),a.label=1;case 1:return a.trys.push([1,4,,5]),[4,this.wxRequestPromise(r({url:this.joinURL(this.baseURL,t),method:e,data:n,header:r(r({},u),o.headers)},o))];case 2:return l=a.sent(),[4,Promise.race([l,c])];case 3:if((d=a.sent()).statusCode>=200&&d.statusCode<300)return[2,d.data];if(401===d.statusCode)return[2,{code:401,message:"未授权"}];throw new Error(d.data.message||"请求失败");case 4:throw f=a.sent(),console.error("网络错误:",f),wx.showToast({title:f instanceof Error?f.message:"网络错误",icon:"none",duration:2e3}),f;case 5:return[2]}}))}))},t.prototype.uploadFile=function(t){return o(this,arguments,void 0,(function(t,e,n){var r,o,i,u;return void 0===e&&(e={}),void 0===n&&(n="file"),a(this,(function(a){r=this.baseURL===s.default.API.GATEWAY_URL,o=wx.getStorageSync(s.default.STORAGE_KEYS.TOKEN),i="avatar"===n?"/avatar":"/file/new",u=this.joinURL(this.baseURL,"".concat(r?"/wxbase/v1/api":"").concat(i));try{return[2,new Promise((function(n,r){wx.uploadFile({url:u,name:"file",filePath:t,formData:e,header:{"Content-Type":"application/x-www-form-urlencoded",Authorization:o},success:function(t){if(t.statusCode>=200&&t.statusCode<300)n(JSON.parse(t.data));else{if(401!==t.statusCode)throw new Error(t.data.message||"上传失败");n(JSON.parse(t.data))}},fail:function(){throw new Error("网络错误")}}).onProgressUpdate((function(t){console.log("上传进度",t.progress),console.log("已经上传的数据长度",t.totalBytesSent),console.log("预期需要上传的数据总长度",t.totalBytesExpectedToSend)}))}))]}catch(t){throw console.error("上传失败:",t),wx.showToast({title:t instanceof Error?t.message:"上传失败",icon:"none",duration:2e3}),t}return[2]}))}))},t.prototype.deleteFile=function(t){return o(this,void 0,void 0,(function(){var e;return a(this,(function(n){return e=this.baseURL===s.default.API.GATEWAY_URL,[2,this.request("".concat(e?"/wxbase/v1/api":"","/file/del"),"GET",{id:t})]}))}))},t.prototype.uploadAvatar=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){return[2,this.uploadFile(t,{},"avatar")]}))}))},t}();e.gatewayHttpClient=new u({baseURL:s.default.API.GATEWAY_URL,timeout:s.default.HTTP.TIMEOUT}),e.baseHttpClient=new u({baseURL:s.default.API.BASE_URL,timeout:s.default.HTTP.TIMEOUT}),e.apiHttpClient=new u({baseURL:s.default.API.API_URL,timeout:s.default.HTTP.TIMEOUT}),e.default=u},156:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),a=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return o(e,t),e},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.adManager=e.HttpClient=e.apiHttpClient=e.baseHttpClient=e.gatewayHttpClient=e.hijackAllPage=e.hijackApp=e.injectComponent=e.injectPage=e.injectApp=e.waitLogin=e.onLoginReady=void 0;var s=n(859);Object.defineProperty(e,"onLoginReady",{enumerable:!0,get:function(){return s.onLoginReady}}),Object.defineProperty(e,"waitLogin",{enumerable:!0,get:function(){return s.waitLogin}});var u=a(n(161));e.HttpClient=u.default,Object.defineProperty(e,"gatewayHttpClient",{enumerable:!0,get:function(){return u.gatewayHttpClient}}),Object.defineProperty(e,"baseHttpClient",{enumerable:!0,get:function(){return u.baseHttpClient}}),Object.defineProperty(e,"apiHttpClient",{enumerable:!0,get:function(){return u.apiHttpClient}});var c=n(718);Object.defineProperty(e,"injectApp",{enumerable:!0,get:function(){return c.injectApp}}),Object.defineProperty(e,"injectPage",{enumerable:!0,get:function(){return c.injectPage}}),Object.defineProperty(e,"injectComponent",{enumerable:!0,get:function(){return c.injectComponent}}),Object.defineProperty(e,"hijackApp",{enumerable:!0,get:function(){return c.hijackApp}}),Object.defineProperty(e,"hijackAllPage",{enumerable:!0,get:function(){return c.hijackAllPage}});var l=i(n(616));e.adManager=l.default},718:function(t,e,n){var r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.hijackAllPage=e.hijackApp=void 0,e.injectApp=s,e.injectPage=u,e.injectComponent=c;var a=n(859),i=o(n(28));function s(t){return void 0===t&&(t={}),function(e){void 0===e&&(e={});var n=e.onLaunch;return e.onLaunch=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];a.initApp.call(this,t).catch((function(t){console.error("应用API初始化失败:",t)})),null==n||n.apply(this,e)},e}}function u(t){return void 0===t&&(t={showInterstitialAd:!1}),function(e){var n;void 0===e&&(e={}),e.data=r(r({},e.data||{}),((n={})[i.default.DATA.PAGE_ID]=Math.random().toString(36).substring(2,7),n));var o=e.onShow;return e.onShow=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];a.showPage.call(this,t,this.data[i.default.DATA.PAGE_ID]).catch((function(t){console.error("页面API初始化失败:",t)})),null==o||o.apply(this,e)},e}}function c(t){return void 0===t&&(t={showInterstitialAd:!1}),function(e){void 0===e&&(e={}),e.methods=e.methods||{};var n=!1,r=e.methods.onLoad;e.methods.onLoad=function(){for(var t,e,o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];(n=!!this.route)&&!(null===(e=this.data)||void 0===e?void 0:e[i.default.DATA.PAGE_ID])&&this.setData(((t={})[i.default.DATA.PAGE_ID]=Math.random().toString(36).substring(2,7),t)),null==r||r.apply(this,o)};var o=e.methods.onShow;return e.methods.onShow=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];n&&a.showPage.call(this,t,this.data[i.default.DATA.PAGE_ID]).catch((function(t){console.error("页面API初始化失败:",t)})),null==o||o.apply(this,e)},e}}e.hijackApp=function(t){void 0===t&&(t={});var e=App;App=function(n){return e(s(t)(n))}};e.hijackAllPage=function(t){void 0===t&&(t={showInterstitialAd:!1});var e=Page;Page=function(n){return e(u(t)(n))};var n=Component;Component=function(e){return n(c(t)(e))}}}},e={};var n=function n(r){var o=e[r];if(void 0!==o)return o.exports;var a=e[r]={exports:{}};return t[r].call(a.exports,a,a.exports,n),a.exports}(156);module.exports=n})();
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wxshot/api",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"main": "miniprogram_dist/index.js",
|
|
5
|
+
"files": [
|
|
6
|
+
"miniprogram_dist"
|
|
7
|
+
],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "webpack",
|
|
10
|
+
"pub": "npm run build && npm publish --access public",
|
|
11
|
+
"build:js": "tsc --project tsconfig_tsc.json"
|
|
12
|
+
},
|
|
13
|
+
"miniprogram": "miniprogram_dist",
|
|
14
|
+
"author": "",
|
|
15
|
+
"description": "",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/wechat-miniprogram": "^3.4.8",
|
|
18
|
+
"dts-bundle": "^0.7.3",
|
|
19
|
+
"ts-loader": "^9.5.1",
|
|
20
|
+
"typescript": "^5.6.3",
|
|
21
|
+
"webpack": "^5.96.1",
|
|
22
|
+
"webpack-cli": "^5.1.4"
|
|
23
|
+
}
|
|
24
|
+
}
|