vhall-mini-sdk 0.1.2 → 0.2.1
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 +116 -21
- package/lib/components/live-portrait/live-portrait.js +4 -0
- package/lib/components/mall-reward/index.js +1 -0
- package/lib/components/product/product-card/product-card.js +1 -0
- package/lib/components/product/product-card/product-card.wxss +1 -1
- package/lib/components/product/product-list/product-list.js +1 -0
- package/lib/pubComponents/error-page/index.js +2 -20
- package/lib/sdk/config/index.js +1 -1
- package/lib/sdk/main/index.js +2 -2
- package/lib/sdk/player/index.js +1 -1
- package/lib/sdk/plugins/ChatServer.js +1 -1
- package/lib/sdk/plugins/CustomMenuServer.js +1 -1
- package/lib/sdk/plugins/InteractServer.js +1 -1
- package/lib/sdk/plugins/InviteCardServer.js +1 -1
- package/lib/sdk/plugins/LotteryServer.js +1 -1
- package/lib/sdk/plugins/MallRewardServer.js +1 -1
- package/lib/sdk/plugins/ProductServer.js +1 -1
- package/lib/shared/mpUtils.js +1 -1
- package/package.json +16 -6
package/README.md
CHANGED
|
@@ -8,43 +8,138 @@
|
|
|
8
8
|
|
|
9
9
|
## 快速开始
|
|
10
10
|
|
|
11
|
-
1. 安装
|
|
11
|
+
### 1. 安装 SDK 组件
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
# npm安装
|
|
14
|
+
# npm 安装
|
|
15
15
|
npm install vhall-mini-sdk
|
|
16
16
|
|
|
17
|
-
# yarn安装
|
|
17
|
+
# yarn 安装
|
|
18
18
|
yarn add vhall-mini-sdk
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
uni-app
|
|
21
|
+
> **uni-app 开发注意**:安装完成后,会在当前工程目录下自动生成 `wxcomponents/vhall-mini-sdk` 目录。
|
|
22
22
|
|
|
23
|
-
2. 构建npm
|
|
23
|
+
### 2. 构建 npm(仅原生微信小程序需要)
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
在微信开发者工具菜单栏点击 **工具 → 构建 npm**,执行后生成 `miniprogram_npm/vhall-mini-sdk` 目录。
|
|
26
26
|
|
|
27
|
-
3. SDK
|
|
27
|
+
### 3. 引入 SDK
|
|
28
28
|
|
|
29
|
-
(1) 原生微信小程序开发
|
|
29
|
+
#### (1) 原生微信小程序开发
|
|
30
|
+
|
|
31
|
+
支持 `require` 和 `import` 两种方式引入:
|
|
30
32
|
|
|
31
33
|
```js
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
34
|
+
// require方式
|
|
35
|
+
const VhallMiniSdk = require('vhall-mini-sdk/sdk/main/index.js');
|
|
36
|
+
const CustomMenuServer = require('vhall-mini-sdk/sdk/plugins/CustomMenuServer.js');
|
|
37
|
+
const ChatServer = require('vhall-mini-sdk/sdk/plugins/ChatServer.js');
|
|
38
|
+
const ProductServer = require('vhall-mini-sdk/sdk/plugins/ProductServer.js');
|
|
39
|
+
const InteractServer = require('vhall-mini-sdk/sdk/plugins/InteractServer.js');
|
|
40
|
+
const LotteryServer = require('vhall-mini-sdk/sdk/plugins/LotteryServer.js');
|
|
41
|
+
const MallRewardServer = require('vhall-mini-sdk/sdk/plugins/MallRewardServer.js');
|
|
42
|
+
const InviteCardServer = require('vhall-mini-sdk/sdk/plugins/InviteCardServer.js');
|
|
43
|
+
|
|
44
|
+
// import方式
|
|
45
|
+
import VhallMiniSdk from 'vhall-mini-sdk/sdk/main/index.js';
|
|
46
|
+
import ChatServer from 'vhall-mini-sdk/sdk/plugins/ChatServer.js';
|
|
47
|
+
import CustomMenuServer from 'vhall-mini-sdk/sdk/plugins/CustomMenuServer.js';
|
|
48
|
+
import InteractServer from 'vhall-mini-sdk/sdk/plugins/InteractServer.js';
|
|
49
|
+
import InviteCardServer from 'vhall-mini-sdk/sdk/plugins/InviteCardServer.js';
|
|
50
|
+
import LotteryServer from 'vhall-mini-sdk/sdk/plugins/LotteryServer.js';
|
|
51
|
+
import MallRewardServer from 'vhall-mini-sdk/sdk/plugins/MallRewardServer.js';
|
|
52
|
+
import ProductServer from 'vhall-mini-sdk/sdk/plugins/ProductServer.js';
|
|
37
53
|
```
|
|
38
54
|
|
|
39
|
-
(2) uni-app小程序开发
|
|
55
|
+
#### (2) uni-app 小程序开发
|
|
56
|
+
|
|
57
|
+
> **⚠️ 重点:必须用 `require` 引入,不能用 `import`**
|
|
58
|
+
>
|
|
59
|
+
> `wxcomponents` 目录专门存放“原生小程序组件/库”,uni-app 为保证这些原生代码的纯净性与兼容性,会将其排除在编译流程之外。因此**不能用 Web 标准的 `import` 读取**(其 `export default` 未被编译成可执行代码),必须降级使用小程序标准的 `require` 加载。
|
|
40
60
|
|
|
41
61
|
```js
|
|
42
|
-
import { ref, onMounted } from 'vue';
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const
|
|
62
|
+
import { ref, onMounted, onUnmounted } from 'vue';
|
|
63
|
+
// wxcomponents目录是专门用来存放“原生小程序组件/库”的,uni-app为了保证这些原生代码的纯净性和兼容性,特意把它们排除在编译流程之外。
|
|
64
|
+
// 所以,我们不能用 Web 标准的 import 去读取它(因为 export default 没被转换成任何可执行代码),你必须降级使用小程序标准的 require 来加载它。
|
|
65
|
+
const VhallMiniSdk = require('../../wxcomponents/vhall-mini-sdk/sdk/main/index.js');
|
|
66
|
+
// 下面的Server插件可按需加载
|
|
67
|
+
const CustomMenuServer = require('../../wxcomponents/vhall-mini-sdk/sdk/plugins/CustomMenuServer.js');
|
|
68
|
+
const ChatServer = require('../../wxcomponents/vhall-mini-sdk/sdk/plugins/ChatServer.js');
|
|
69
|
+
const ProductServer = require('../../wxcomponents/vhall-mini-sdk/sdk/plugins/ProductServer.js');
|
|
70
|
+
const InteractServer = require('../../wxcomponents/vhall-mini-sdk/sdk/plugins/InteractServer.js');
|
|
71
|
+
const LotteryServer = require('../../wxcomponents/vhall-mini-sdk/sdk/plugins/LotteryServer.js');
|
|
72
|
+
const MallRewardServer = require('../../wxcomponents/vhall-mini-sdk/sdk/plugins/MallRewardServer.js');
|
|
73
|
+
const InviteCardServer = require('../../wxcomponents/vhall-mini-sdk/sdk/plugins/InviteCardServer.js');
|
|
74
|
+
|
|
75
|
+
// 布尔值用ref包裹,.value修改值
|
|
76
|
+
const sdkReady = ref(false);
|
|
77
|
+
// SDK实例不需要响应式,普通变量即可
|
|
78
|
+
let sdkInstance = null;
|
|
79
|
+
let unListener =null;
|
|
80
|
+
async function initSdk() {
|
|
81
|
+
const options = {
|
|
82
|
+
app_key: '',
|
|
83
|
+
email: '',
|
|
84
|
+
sign: '',
|
|
85
|
+
signedat: ,
|
|
86
|
+
username: '',
|
|
87
|
+
webinar_id: '',
|
|
88
|
+
head: 'https://cnstatic01.e.vhall.com/common-static/images/default_avatar.png',
|
|
89
|
+
modules: [
|
|
90
|
+
CustomMenuServer,
|
|
91
|
+
ChatServer,
|
|
92
|
+
ProductServer,
|
|
93
|
+
InteractServer,
|
|
94
|
+
LotteryServer,
|
|
95
|
+
MallRewardServer,
|
|
96
|
+
InviteCardServer,
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
// 创建实例
|
|
102
|
+
sdkInstance = new VhallMiniSdk(options);
|
|
103
|
+
|
|
104
|
+
// 事件监听
|
|
105
|
+
unListener = sdkInstance.on({
|
|
106
|
+
[VhallMiniSdk.EVENT.NET_STATE_CHANGE]: (state) => {
|
|
107
|
+
console.log('网络状态变化', state);
|
|
108
|
+
},
|
|
109
|
+
[VhallMiniSdk.EVENT.SDK_READY]: () => {
|
|
110
|
+
console.log('initLiveRoom is ready');
|
|
111
|
+
},
|
|
112
|
+
[VhallMiniSdk.EVENT.INIT_FAILED]: (error) => {
|
|
113
|
+
console.error('initLiveRoom is failed', error);
|
|
114
|
+
},
|
|
115
|
+
[VhallMiniSdk.EVENT.ERROR]: (err) => {
|
|
116
|
+
console.error('VhallMiniSdk error:', JSON.stringify(err));
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// 初始化直播间
|
|
121
|
+
await sdkInstance.init();
|
|
122
|
+
|
|
123
|
+
if (sdkInstance.isReady()) {
|
|
124
|
+
// 关键:ref变量修改必须加 .value
|
|
125
|
+
sdkReady.value = true;
|
|
126
|
+
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.warn('VhallMiniSdk init failed', error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
onMounted(() => {
|
|
133
|
+
initSdk();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
onUnmounted(() => {
|
|
137
|
+
unListener?.();
|
|
138
|
+
sdkInstance?.destroy();
|
|
139
|
+
sdkInstance = null;
|
|
140
|
+
});
|
|
48
141
|
```
|
|
49
142
|
|
|
50
|
-
4.
|
|
143
|
+
### 4. 更多接入支持
|
|
144
|
+
|
|
145
|
+
参考文档:<https://vhall.apifox.cn/dev/sdk/wmp/quick-start>
|
|
@@ -142,6 +142,7 @@ Component({
|
|
|
142
142
|
this.unlistener = this.sdkInstance.on(obj);
|
|
143
143
|
},
|
|
144
144
|
async checkAndFetchMallRewardInfo(from, extra) {
|
|
145
|
+
this.sdkInstance.BRSAgent?.customLog(`checkAndFetchMallRewardInfo from=${from}`, JSON.stringify(extra));
|
|
145
146
|
log.info('mall-reward checkAndFetchMallRewardInfo start');
|
|
146
147
|
const mallRewardServer = this.sdkInstance.get('mallRewardServer');
|
|
147
148
|
if (!mallRewardServer) return;
|
|
@@ -46,6 +46,7 @@ Component({
|
|
|
46
46
|
const filteredProducts = val.filter(product => product.push_status === 1);
|
|
47
47
|
// 最多显示3个商品卡片
|
|
48
48
|
const products = filteredProducts.slice(0, 3);
|
|
49
|
+
this.properties.sdkInstance.get('logReportServer').report('116999', { stage: 'productCardUpdate', logData: products });
|
|
49
50
|
this.setData({
|
|
50
51
|
products: products
|
|
51
52
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.product-card-container{align-items:flex-end;bottom:180rpx;display:flex;flex-direction:column;gap:16rpx;position:fixed;right:20rpx;z-index:999}.product-card{
|
|
1
|
+
.product-card-container{align-items:flex-end;bottom:180rpx;display:flex;flex-direction:column;gap:16rpx;position:fixed;right:20rpx;z-index:999}.product-card{background-color:#fff;border-radius:12rpx;box-shadow:0 4rpx 12rpx rgba(0,0,0,.15);overflow:hidden;position:relative;width:240rpx}.product-card-badge{background-color:rgba(0,0,0,.6);border-radius:30rpx;color:#fff;font-size:.71rem;left:8rpx;padding:4rpx 20rpx;position:absolute;top:8rpx;z-index:10}.product-card-badge .product-card-badge-icon{height:20rpx}.product-card-close{color:#fff;font-size:1.14rem;padding:0 14rpx;position:absolute;right:0rpx;top:0rpx;z-index:10}.product-card-image{height:240rpx;position:relative;width:100%}.product-card-image .product-card-img{height:100%;object-fit:cover;width:100%}.product-card-info{padding:12rpx}.product-card-title{color:#333;display:block;font-size:.86rem;font-weight:500;margin-bottom:12rpx;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.product-card-price-container{align-items:center;background:#fb2626;border-radius:8rpx;color:#fff;display:flex;height:50rpx;justify-content:space-between;margin-top:12rpx;padding-left:10rpx}.product-card-buy{background-color:#ff4d4f;border-radius:6rpx;color:#fff;cursor:pointer;font-size:.71rem;padding:8rpx 16rpx}.product-card-mask{align-items:center;background-color:rgba(0,0,0,.4);bottom:0;display:flex;justify-content:center;left:0;position:absolute;right:0;top:0}.product-card-mask-text{border-radius:20rpx;color:#fff;font-size:.86rem;padding:8rpx 16rpx}.product-card-disabled{opacity:.7}.product-card-disabled .product-card-price{color:#fff}.product-card-disabled .product-card-price-container{opacity:.6}.buy-icon{display:block;height:100%}.product-card-small{width:180rpx}.product-card-small .product-card-image{height:180rpx}.product-card-small .product-card-price-container{height:40rpx}.product-card-small .product-card-badge{font-size:.64rem;padding:3rpx 16rpx}.product-card-small .product-card-close{font-size:1rem;padding:0 10rpx}.product-card-small .buy-icon{display:none}
|
|
@@ -50,6 +50,7 @@ Component({
|
|
|
50
50
|
this.unsub = this.properties.sdkInstance.store.get({
|
|
51
51
|
productList: (val) => {
|
|
52
52
|
if (val) {
|
|
53
|
+
this.properties.sdkInstance.get('logReportServer').report('116999', { stage: 'productListUpdate', logData: val });
|
|
53
54
|
this.setData({ productList: val });
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { reloadCurrentPage } from '../../shared/mpUtils.js'
|
|
1
2
|
const errorMap = {
|
|
2
3
|
512002: {
|
|
3
4
|
msg: '活动不存在或已删除'
|
|
@@ -121,26 +122,7 @@ Component({
|
|
|
121
122
|
methods: {
|
|
122
123
|
onTap() {
|
|
123
124
|
if (this.data.code === 900004 && this.data.secondText > 0) return;
|
|
124
|
-
|
|
125
|
-
const pageStack = getCurrentPages();
|
|
126
|
-
const currentPage = pageStack[pageStack.length - 1];
|
|
127
|
-
const route = currentPage.route;
|
|
128
|
-
const options = currentPage.options;
|
|
129
|
-
|
|
130
|
-
// 拼接路由参数
|
|
131
|
-
let queryStr = '';
|
|
132
|
-
const params = [];
|
|
133
|
-
for (const key in options) {
|
|
134
|
-
params.push(`${key}=${encodeURIComponent(options[key])}`);
|
|
135
|
-
}
|
|
136
|
-
if (params.length) {
|
|
137
|
-
queryStr = '?' + params.join('&');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// redirectTo:关闭当前页面,重新打开同页面,页面栈层级不变
|
|
141
|
-
wx.redirectTo({
|
|
142
|
-
url: `/${route}${queryStr}`
|
|
143
|
-
});
|
|
125
|
+
reloadCurrentPage();
|
|
144
126
|
},
|
|
145
127
|
},
|
|
146
128
|
});
|
package/lib/sdk/config/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";const envConfig={production:{BASE_URL:"https://open-api.vhall.com",VHALLYUN_API_BASE:"https://api.vhallyun.com",LOG_REPORT_BASE_URL:"https://dc.e.vhall.com/login",PUBLIC_KEY:"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0eUJFtW3vryA2NXx4M4f\n1w7dg3PHwOCA6Kx7JVfD/9eBGfqLhqsp+pg4AXG4PhuQx8EsV+sncQIiQO5J2//T\n3pO8LftDtCQztLnxnhq+BjhbFeswgfez2CwV2YKLTX2zyZ69T1Vu/M4H4gWSLeiV\n1FcH6xycA2+jG+EvOxSSItCKYT9EkB9BZSKf5RU7gM+qPtzdPtJP5vlsMCa0WnpY\nI6Qrmu/w9CZkL0397gUek9nBpPHkyPYg7ZijF3Gj8EqCMCVVTYpX96k4dd/Rz1em\ns4OSPF5jDsYZi58p+LmTcc3g7W9bD3QWWxzn47ie/Dh9LbnWfCqpGjUaHd3d42vR\ncQIDAQAB\n-----END PUBLIC KEY-----"},test:{BASE_URL:"https://test01-open-api.vhou.tv",VHALLYUN_API_BASE:"https://test01-api.vhallyun.com",LOG_REPORT_BASE_URL:"https://t-dc.e.vhall.com/login",PUBLIC_KEY:"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxWGCgHz2NLdVNa91CsNX\nFfCsxfgkTx738t3yMpuPYLL/5wwuWRrX7hBfNsfC+R5BW5b13ISzD001NNt+BWGK\np3V5fdWO18j9M/AhaTV2Ao/IpdP5huvVoNFVWPUQvX70FHu0sPVTev8ycAZHUpKx\n+mm83wxOpWBN5vAMJYx75pRCQfidb73XbOm6JXLJlxN91TUTrTiblxBhRwH0AQyr\ns9dUr+IJUZ1ea2uU3fkB4uYh7V/cHuNDMsJowfLtEU2+9IqEuJY4OwqX0qdfPF72\nsGMjCgghgL0z/7kv7Qe1+tOkJTBQTzODXBheGTVbF7hH2+5XuZsK2TfgBIew0I4k\n1wIDAQAB\n-----END PUBLIC KEY-----"}};exports._PLATFORM=19,exports.envConfig=envConfig;
|