jyj-components 1.0.0 → 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/README.md CHANGED
@@ -27,6 +27,22 @@ npm install jyj-components
27
27
 
28
28
  将 `miniprogram_dist` 目录复制到项目中,然后在 `app.json` 中配置相对路径。
29
29
 
30
+ ## 添加合法域名
31
+
32
+ 1. 小程序账号登录[微信公众平台](https://mp.weixin.qq.com/)
33
+ 2. 开发 —> 开发管理 —> 开发设置 —> 服务器域名
34
+ 3. 在 `downloadFile合法域名` 中增加如下配置
35
+
36
+ ```
37
+ https://wxgo.cdn.adwke.com
38
+ ```
39
+
40
+ 4. 在request合法域名中增加
41
+
42
+ ```
43
+ https://wxgo.adwke.com/
44
+ ```
45
+
30
46
  ## 组件使用
31
47
 
32
48
  ### 1. 横幅广告 (ad-banner)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jyj-components",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "miniprogram_dist/index.js",
6
6
  "scripts": {
package/MIGRATION.md DELETED
@@ -1,336 +0,0 @@
1
- # 插件到组件迁移指南
2
-
3
- 本文档说明了从微信小程序插件到自定义组件的重构过程和主要变更。
4
-
5
- ## 重构概览
6
-
7
- ### 原插件结构
8
- ```
9
- plugin/
10
- ├── index.js # 插件入口
11
- ├── plugin.json # 插件配置
12
- ├── request.js # 请求模块
13
- ├── components/
14
- │ └── banner/ # 广告组件(包含所有类型)
15
- └── pages/
16
- └── coupon/ # 优惠券页面(Page)
17
- ```
18
-
19
- ### 新组件结构
20
- ```
21
- src/
22
- ├── ad-banner/ # 横幅广告组件
23
- ├── ad-interstitial/ # 插屏广告组件
24
- ├── ad-rewarded-video/ # 激励视频组件
25
- ├── ad-splash/ # 开屏广告组件
26
- ├── ad-coupon/ # 优惠券组件(Component)
27
- ├── mixins/
28
- │ └── ad-base.js # 公共逻辑
29
- └── request.js # 请求模块
30
- ```
31
-
32
- ## 主要变更
33
-
34
- ### 1. 组件拆分
35
-
36
- **变更前:** 一个 `banner` 组件包含所有广告类型
37
- ```javascript
38
- // plugin/components/banner/banner.js
39
- Component({
40
- properties: {
41
- type: String // "banner" | "interstitial" | "rewardedVideo" | "splash"
42
- }
43
- });
44
- ```
45
-
46
- **变更后:** 拆分为 4 个独立组件
47
- ```javascript
48
- // src/ad-banner/index.js
49
- // src/ad-interstitial/index.js
50
- // src/ad-rewarded-video/index.js
51
- // src/ad-splash/index.js
52
- ```
53
-
54
- **优势:**
55
- - 代码更清晰,每个组件专注单一功能
56
- - 按需加载,减少包体积
57
- - 独立维护,互不影响
58
-
59
- ### 2. Page 转 Component
60
-
61
- **变更前:** coupon 使用 Page() 构造器
62
- ```javascript
63
- // plugin/pages/coupon/coupon.js
64
- Page({
65
- onLoad(options) {
66
- this.setData({ params: options });
67
- }
68
- });
69
- ```
70
-
71
- **变更后:** 使用 Component() 构造器
72
- ```javascript
73
- // src/ad-coupon/index.js
74
- Component({
75
- properties: {
76
- secret: String,
77
- phone: String,
78
- userId: String
79
- },
80
- lifetimes: {
81
- attached() {
82
- // 初始化逻辑
83
- }
84
- }
85
- });
86
- ```
87
-
88
- **使用方式变更:**
89
-
90
- 插件方式(旧):
91
- ```xml
92
- <navigator url="plugin://juyoujia-adv/promotions?secret=xxx">
93
- 领取优惠券
94
- </navigator>
95
- ```
96
-
97
- 组件方式(新):
98
- ```xml
99
- <ad-coupon secret="{{secret}}" phone="{{phone}}" userId="{{userId}}" />
100
- ```
101
-
102
- ### 3. 公共逻辑提取
103
-
104
- **变更前:** 公共逻辑分散在各个组件中
105
-
106
- **变更后:** 提取到 `mixins/ad-base.js`
107
- ```javascript
108
- // src/mixins/ad-base.js
109
- module.exports = {
110
- restoreAdState() { /* ... */ },
111
- saveAdState() { /* ... */ },
112
- loadNextAd() { /* ... */ },
113
- report(actionType) { /* ... */ }
114
- };
115
- ```
116
-
117
- **使用方式:**
118
- ```javascript
119
- const adBase = require('../mixins/ad-base.js');
120
-
121
- Component({
122
- methods: {
123
- ...adBase,
124
- // 组件特有方法
125
- }
126
- });
127
- ```
128
-
129
- ### 4. 路径引用变更
130
-
131
- **变更前:** 插件内部使用相对路径
132
- ```javascript
133
- const { getAds } = require('../../request.js');
134
- ```
135
-
136
- **变更后:** 组件使用相对路径
137
- ```javascript
138
- const { getAds } = require('../request.js');
139
- ```
140
-
141
- ### 5. 配置文件变更
142
-
143
- **变更前:** 需要 `plugin.json`
144
- ```json
145
- {
146
- "publicComponents": {
147
- "juyoujia-ad": "components/banner/banner"
148
- },
149
- "pages": {
150
- "promotions": "pages/coupon/coupon"
151
- },
152
- "main": "index.js"
153
- }
154
- ```
155
-
156
- **变更后:** 不需要特殊配置,直接使用标准组件配置
157
- ```json
158
- {
159
- "component": true,
160
- "usingComponents": {}
161
- }
162
- ```
163
-
164
- ### 6. 宿主小程序引用方式
165
-
166
- **变更前:** 插件引用
167
- ```json
168
- {
169
- "plugins": {
170
- "juyoujia-adv": {
171
- "version": "1.0.0",
172
- "provider": "wxAppId"
173
- }
174
- },
175
- "usingComponents": {
176
- "juyoujia-ad": "plugin://juyoujia-adv/juyoujia-ad"
177
- }
178
- }
179
- ```
180
-
181
- **变更后:** 普通组件引用
182
- ```json
183
- {
184
- "usingComponents": {
185
- "ad-banner": "/components/jyj-components/ad-banner/index",
186
- "ad-interstitial": "/components/jyj-components/ad-interstitial/index",
187
- "ad-rewarded-video": "/components/jyj-components/ad-rewarded-video/index",
188
- "ad-splash": "/components/jyj-components/ad-splash/index",
189
- "ad-coupon": "/components/jyj-components/ad-coupon/index"
190
- }
191
- }
192
- ```
193
-
194
- ## 迁移步骤
195
-
196
- ### 对于组件开发者
197
-
198
- 1. **构建组件库**
199
- ```bash
200
- cd D:\myCode\miniProgram\jyj-components
201
- npm install
202
- npm run build
203
- ```
204
-
205
- 2. **发布到 npm(可选)**
206
- ```bash
207
- npm publish
208
- ```
209
-
210
- ### 对于小程序开发者
211
-
212
- 1. **移除插件配置**
213
-
214
- 从 `app.json` 中删除:
215
- ```json
216
- {
217
- "plugins": {
218
- "juyoujia-adv": { ... }
219
- }
220
- }
221
- ```
222
-
223
- 2. **安装组件库**
224
-
225
- 方式 A:npm 安装
226
- ```bash
227
- npm install jyj-components
228
- ```
229
-
230
- 方式 B:本地复制
231
- ```bash
232
- # 复制 miniprogram_dist 到项目的 components 目录
233
- ```
234
-
235
- 3. **更新组件引用**
236
-
237
- ```json
238
- {
239
- "usingComponents": {
240
- "ad-banner": "jyj-components/ad-banner/index"
241
- }
242
- }
243
- ```
244
-
245
- 4. **更新代码**
246
-
247
- **横幅广告:**
248
- ```xml
249
- <!-- 旧 -->
250
- <juyoujia-ad slotId="xxx" type="banner" />
251
-
252
- <!-- 新 -->
253
- <ad-banner slotId="xxx" />
254
- ```
255
-
256
- **插屏广告:**
257
- ```xml
258
- <!-- 旧 -->
259
- <juyoujia-ad slotId="xxx" type="interstitial" />
260
-
261
- <!-- 新 -->
262
- <ad-interstitial slotId="xxx" isShow="{{show}}" />
263
- ```
264
-
265
- **激励视频:**
266
- ```xml
267
- <!-- 旧 -->
268
- <juyoujia-ad slotId="xxx" type="rewardedVideo" />
269
-
270
- <!-- 新 -->
271
- <ad-rewarded-video slotId="xxx" isShow="{{show}}" />
272
- ```
273
-
274
- **开屏广告:**
275
- ```xml
276
- <!-- 旧 -->
277
- <juyoujia-ad slotId="xxx" type="splash" />
278
-
279
- <!-- 新 -->
280
- <ad-splash slotId="xxx" />
281
- ```
282
-
283
- **优惠券:**
284
- ```xml
285
- <!-- 旧 -->
286
- <navigator url="plugin://juyoujia-adv/promotions?secret=xxx&phone=xxx">
287
- 领取优惠券
288
- </navigator>
289
-
290
- <!-- 新 -->
291
- <ad-coupon secret="{{secret}}" phone="{{phone}}" userId="{{userId}}" />
292
- ```
293
-
294
- ## 兼容性说明
295
-
296
- ### 保持不变的部分
297
-
298
- 1. **广告数据格式**:后端接口返回的数据格式保持不变
299
- 2. **slotId**:广告位 ID 保持不变
300
- 3. **事件名称**:`adLoad`、`adError`、`adClose` 等事件名保持不变
301
- 4. **业务逻辑**:广告轮播、状态管理、数据上报逻辑保持不变
302
-
303
- ### 需要调整的部分
304
-
305
- 1. **组件名称**:从 `juyoujia-ad` 改为 `ad-banner` 等
306
- 2. **type 属性**:不再需要 `type` 属性,直接使用对应的组件
307
- 3. **优惠券参数传递**:从 URL 参数改为组件属性
308
-
309
- ## 性能对比
310
-
311
- | 指标 | 插件方式 | 组件方式 |
312
- |------|---------|---------|
313
- | 包体积 | 所有类型打包在一起 | 按需加载 |
314
- | 代码可读性 | 大量条件判断 | 清晰独立 |
315
- | 维护成本 | 修改影响全部 | 独立维护 |
316
- | 加载速度 | 加载全部代码 | 只加载使用的组件 |
317
-
318
- ## 常见问题
319
-
320
- ### Q: 为什么要拆分组件?
321
- A: 提高代码可读性、可维护性,支持按需加载,减少包体积。
322
-
323
- ### Q: 旧版插件还能用吗?
324
- A: 可以,但建议迁移到新版组件,获得更好的性能和维护体验。
325
-
326
- ### Q: 迁移需要多久?
327
- A: 对于简单项目,约 30 分钟;复杂项目可能需要 1-2 小时。
328
-
329
- ### Q: 数据会丢失吗?
330
- A: 不会,广告展示状态保存在本地存储中,迁移后会自动恢复。
331
-
332
- ## 技术支持
333
-
334
- 如有迁移问题,请联系开发团队或查看:
335
- - [完整文档](./README.md)
336
- - [快速开始](./QUICKSTART.md)
package/QUICKSTART.md DELETED
@@ -1,300 +0,0 @@
1
- # 快速开始
2
-
3
- ## 5 分钟上手指南
4
-
5
- ### 1. 构建组件
6
-
7
- ```bash
8
- cd D:\myCode\miniProgram\jyj-components
9
- npm install
10
- npm run build
11
- ```
12
-
13
- 构建完成后,会在项目根目录生成 `miniprogram_dist` 目录。
14
-
15
- ### 2. 在小程序中引入
16
-
17
- #### 方式 A:本地引入(推荐用于开发测试)
18
-
19
- 将 `miniprogram_dist` 目录复制到你的小程序项目中,例如:
20
-
21
- ```
22
- your-miniprogram/
23
- ├── components/
24
- │ └── jyj-components/ # 复制 miniprogram_dist 到这里并重命名
25
- ├── pages/
26
- └── app.json
27
- ```
28
-
29
- 在 `app.json` 中全局注册:
30
-
31
- ```json
32
- {
33
- "usingComponents": {
34
- "ad-banner": "/components/jyj-components/ad-banner/index",
35
- "ad-interstitial": "/components/jyj-components/ad-interstitial/index",
36
- "ad-rewarded-video": "/components/jyj-components/ad-rewarded-video/index",
37
- "ad-splash": "/components/jyj-components/ad-splash/index",
38
- "ad-coupon": "/components/jyj-components/ad-coupon/index"
39
- }
40
- }
41
- ```
42
-
43
- 或在页面 JSON 中单独注册:
44
-
45
- ```json
46
- {
47
- "usingComponents": {
48
- "ad-banner": "/components/jyj-components/ad-banner/index"
49
- }
50
- }
51
- ```
52
-
53
- ### 3. 使用组件
54
-
55
- #### 示例 1:横幅广告
56
-
57
- **pages/index/index.wxml**
58
- ```xml
59
- <view class="container">
60
- <text>页面内容</text>
61
-
62
- <!-- 横幅广告 -->
63
- <ad-banner
64
- slotId="banner-slot-001"
65
- bind:adLoad="onBannerLoad"
66
- bind:adError="onBannerError"
67
- />
68
- </view>
69
- ```
70
-
71
- **pages/index/index.js**
72
- ```javascript
73
- Page({
74
- onBannerLoad(e) {
75
- console.log('横幅广告加载成功', e.detail);
76
- },
77
-
78
- onBannerError(e) {
79
- console.error('横幅广告加载失败', e.detail);
80
- }
81
- });
82
- ```
83
-
84
- #### 示例 2:插屏广告
85
-
86
- **pages/game/game.wxml**
87
- ```xml
88
- <view class="container">
89
- <button bindtap="showAd">显示插屏广告</button>
90
-
91
- <ad-interstitial
92
- slotId="interstitial-slot-001"
93
- isShow="{{showInterstitial}}"
94
- isDestroy="{{destroyInterstitial}}"
95
- bind:adClose="onAdClose"
96
- />
97
- </view>
98
- ```
99
-
100
- **pages/game/game.js**
101
- ```javascript
102
- Page({
103
- data: {
104
- showInterstitial: false,
105
- destroyInterstitial: false
106
- },
107
-
108
- showAd() {
109
- this.setData({ showInterstitial: true });
110
- },
111
-
112
- onAdClose() {
113
- this.setData({
114
- showInterstitial: false,
115
- destroyInterstitial: true
116
- });
117
- }
118
- });
119
- ```
120
-
121
- #### 示例 3:激励视频
122
-
123
- **pages/reward/reward.wxml**
124
- ```xml
125
- <view class="container">
126
- <button bindtap="watchVideo">观看视频获得奖励</button>
127
-
128
- <ad-rewarded-video
129
- slotId="video-slot-001"
130
- isShow="{{showVideo}}"
131
- bind:adFinished="onVideoFinished"
132
- bind:adClose="onVideoClose"
133
- />
134
- </view>
135
- ```
136
-
137
- **pages/reward/reward.js**
138
- ```javascript
139
- Page({
140
- data: {
141
- showVideo: false,
142
- coins: 100
143
- },
144
-
145
- watchVideo() {
146
- this.setData({ showVideo: true });
147
- },
148
-
149
- onVideoFinished(e) {
150
- if (e.detail.isEnded) {
151
- // 用户看完视频,发放奖励
152
- this.setData({
153
- coins: this.data.coins + 50,
154
- showVideo: false
155
- });
156
- wx.showToast({
157
- title: '获得 50 金币',
158
- icon: 'success'
159
- });
160
- }
161
- },
162
-
163
- onVideoClose() {
164
- this.setData({ showVideo: false });
165
- }
166
- });
167
- ```
168
-
169
- #### 示例 4:开屏广告
170
-
171
- **app.js 或首页**
172
- ```xml
173
- <ad-splash
174
- slotId="splash-slot-001"
175
- bind:adFinished="onSplashFinished"
176
- />
177
-
178
- <view class="main-content" wx:if="{{!showSplash}}">
179
- <!-- 主要内容 -->
180
- </view>
181
- ```
182
-
183
- ```javascript
184
- Page({
185
- data: {
186
- showSplash: true
187
- },
188
-
189
- onSplashFinished() {
190
- this.setData({ showSplash: false });
191
- }
192
- });
193
- ```
194
-
195
- #### 示例 5:优惠券组件
196
-
197
- **pages/coupon/coupon.wxml**
198
- ```xml
199
- <ad-coupon
200
- secret="{{couponSecret}}"
201
- phone="{{userPhone}}"
202
- userId="{{userId}}"
203
- />
204
- ```
205
-
206
- **pages/coupon/coupon.js**
207
- ```javascript
208
- Page({
209
- data: {
210
- couponSecret: 'secret-key-from-server',
211
- userPhone: '13800138000',
212
- userId: 'user123'
213
- }
214
- });
215
- ```
216
-
217
- ### 4. 测试
218
-
219
- 在微信开发者工具中打开你的小程序项目,即可看到广告组件的效果。
220
-
221
- ### 5. 常见配置
222
-
223
- #### 获取 slotId
224
-
225
- 联系后端开发人员或管理员获取有效的广告位 ID(slotId)。
226
-
227
- #### 广告数据格式
228
-
229
- 后端接口应返回以下格式的数据:
230
-
231
- ```json
232
- {
233
- "code": 1,
234
- "data": [
235
- {
236
- "id": "ad001",
237
- "source": "wx",
238
- "showCount": 3,
239
- "banner": {
240
- "unitId": "adunit-xxxxxxxx"
241
- }
242
- },
243
- {
244
- "id": "ad002",
245
- "source": "custom",
246
- "showCount": 2,
247
- "banner": {
248
- "material": "https://example.com/ad.jpg",
249
- "appid": "wxAppId",
250
- "path": "pages/index/index"
251
- }
252
- }
253
- ]
254
- }
255
- ```
256
-
257
- ### 6. 下一步
258
-
259
- - 查看 [README.md](./README.md) 了解完整的 API 文档
260
- - 查看 `tools/demo` 目录中的完整示例
261
- - 运行 `npm run dev` 启动开发模式,实时预览组件效果
262
-
263
- ## 故障排除
264
-
265
- ### 问题:组件不显示
266
-
267
- **解决方案:**
268
- 1. 检查 `slotId` 是否正确
269
- 2. 打开调试器查看网络请求是否成功
270
- 3. 确认后端返回的数据格式正确
271
-
272
- ### 问题:构建失败
273
-
274
- **解决方案:**
275
- ```bash
276
- # 清理并重新安装依赖
277
- npm run clean
278
- rm -rf node_modules
279
- npm install
280
- npm run build
281
- ```
282
-
283
- ### 问题:组件路径找不到
284
-
285
- **解决方案:**
286
- 确保路径正确,使用绝对路径:
287
- ```json
288
- {
289
- "usingComponents": {
290
- "ad-banner": "/components/jyj-components/ad-banner/index"
291
- }
292
- }
293
- ```
294
-
295
- ## 技术支持
296
-
297
- 如有问题,请查看:
298
- - [完整文档](./README.md)
299
- - [GitHub Issues](https://github.com/your-repo/issues)
300
- - 联系开发团队