vhall-mini-sdk 0.2.0 → 0.3.0

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.
Files changed (31) hide show
  1. package/README.md +106 -11
  2. package/lib/components/announcement/announ-banner/index.js +40 -0
  3. package/lib/components/announcement/announ-banner/index.json +4 -0
  4. package/lib/components/announcement/announ-banner/index.wxml +13 -0
  5. package/lib/components/announcement/announ-banner/index.wxss +1 -0
  6. package/lib/components/announcement/announ-icon/index.js +69 -0
  7. package/lib/components/announcement/announ-icon/index.json +3 -0
  8. package/lib/components/announcement/announ-icon/index.wxml +10 -0
  9. package/lib/components/announcement/announ-icon/index.wxss +1 -0
  10. package/lib/components/announcement/announ-popup/index.js +44 -0
  11. package/lib/components/announcement/announ-popup/index.json +7 -0
  12. package/lib/components/announcement/announ-popup/index.wxml +39 -0
  13. package/lib/components/announcement/announ-popup/index.wxss +1 -0
  14. package/lib/components/announcement/index.js +228 -0
  15. package/lib/components/announcement/index.json +9 -0
  16. package/lib/components/announcement/index.wxml +6 -0
  17. package/lib/components/announcement/index.wxss +0 -0
  18. package/lib/components/chat/chat-item/chat-item.js +5 -5
  19. package/lib/components/live-landscape/live-landscape.js +7 -1
  20. package/lib/components/live-landscape/live-landscape.json +2 -0
  21. package/lib/components/live-landscape/live-landscape.wxml +7 -4
  22. package/lib/components/live-portrait/live-portrait.js +10 -2
  23. package/lib/components/live-portrait/live-portrait.json +3 -1
  24. package/lib/components/live-portrait/live-portrait.wxml +8 -4
  25. package/lib/components/mall-reward/index.js +47 -29
  26. package/lib/components/product/product-card/product-card.js +5 -6
  27. package/lib/components/product/product-detail/product-detail.js +6 -6
  28. package/lib/components/product/product-list/product-list.js +2 -3
  29. package/lib/sdk/main/index.js +2 -2
  30. package/lib/sdk/plugins/MallRewardServer.js +1 -1
  31. package/package.json +6 -10
@@ -104,7 +104,7 @@ Component({
104
104
  memberLevel: {
105
105
  type: Object,
106
106
  value: null,
107
- },
107
+ },
108
108
  },
109
109
  data: {
110
110
  roleName: {
@@ -152,11 +152,11 @@ Component({
152
152
  const item = (memberLevel.custom_list || []).find((item) => item.level == level);
153
153
  icon = item?.icon || '';
154
154
  } else {
155
- icon = `https://t-alistatic01.e.vhall.com/common-static/images/mp/vip/vip${level}.png`;
155
+ icon = `https://cnstatic01.e.vhall.com/common-static/images/mp/vip/vip${level}.png`;
156
156
  }
157
157
 
158
158
  this.setData({ memberLevelIcon: icon });
159
- },
159
+ },
160
160
  preview(event) {
161
161
  const index = event.currentTarget.dataset.index;
162
162
  const imgList = this.data.chatItem.data.image_urls;
@@ -186,8 +186,8 @@ Component({
186
186
  // 构建正则表达式来匹配 @ 昵称和表情
187
187
  const atPattern =
188
188
  atNames.length > 0 ?
189
- atNames.map((name) => this._escapeRegExp(name)).join('|') :
190
- '';
189
+ atNames.map((name) => this._escapeRegExp(name)).join('|') :
190
+ '';
191
191
  const facePattern = Object.keys(faceArr)
192
192
  .map(this._escapeRegExp)
193
193
  .join('|');
@@ -1,3 +1,5 @@
1
+ import { reloadCurrentPage } from '../../shared/mpUtils.js';
2
+
1
3
  Component({
2
4
  properties: {
3
5
  sdkInstance: {
@@ -9,6 +11,7 @@ Component({
9
11
  tabList: [],
10
12
  activeTab: 0,
11
13
  liveInfo: null,
14
+ isReady: false, // SDK 是否已初始化完成
12
15
  showStartDialog: false, // 是否显示开始直播弹窗
13
16
 
14
17
  showRecordWatchExpireDialog: false, // 是否显示回放视频已过观看有效期提示框
@@ -31,6 +34,9 @@ Component({
31
34
  liveInfo: val,
32
35
  });
33
36
  },
37
+ isReady: (val) => {
38
+ this.setData({ isReady: !!val });
39
+ },
34
40
  webinarStatus: (val) => {
35
41
  this.setData({
36
42
  webinarStatus: val,
@@ -124,7 +130,7 @@ Component({
124
130
  this.setData({
125
131
  showStartDialog: false,
126
132
  });
127
- this.sdkInstance.init();
133
+ reloadCurrentPage();
128
134
  },
129
135
  handleExprie() {
130
136
  this.sdkInstance._handleBizErrorCode(512912)
@@ -13,6 +13,7 @@
13
13
  "vhall-product-order": "../product/product-order/product-order",
14
14
  "vhall-lottery": "../lottery/lottery",
15
15
  "vhall-mall-reward":"../mall-reward/index",
16
+ "vhall-announcement":"../announcement/index",
16
17
  "start-countdown": "../../pubComponents/countdown/countdown",
17
18
  "signin-dialog": "../signin/signin-dialog",
18
19
  "my-invite-detail": "../invite-rank/my-invite-detail",
@@ -31,6 +32,7 @@
31
32
  "vhall-gift-sender": "view",
32
33
  "vhall-lottery": "view",
33
34
  "vhall-mall-reward":"view",
35
+ "vhall-announcement":"view",
34
36
  "vhall-invite-rank": "view"
35
37
  },
36
38
  "permissiion": {
@@ -1,4 +1,5 @@
1
- <view class="live_landscape" wx:if="{{!errorResp || !errorResp.code}}">
1
+ <error-page wx:if="{{errorResp && errorResp.code}}" errorResp="{{errorResp}}"></error-page>
2
+ <view class="live_landscape" wx:elif="{{isReady}}">
2
3
  <view class="live_landscape_player">
3
4
  <vhall-player sdkInstance="{{sdkInstance}}"></vhall-player>
4
5
  </view>
@@ -66,8 +67,10 @@
66
67
  <vh-popup visible="{{showOrder}}" mode="bottom" maskClosable="true" bind:close="closeOrder">
67
68
  <vhall-product-order show="{{showOrder}}" product="{{selectedProduct}}" sdkInstance="{{sdkInstance}}" bind:close="closeOrder" bind:paySuccess="onPaySuccess" />
68
69
  </vh-popup>
69
- <vhall-lottery sdkInstance="{{sdkInstance}}" />
70
+ <!-- 抽奖组件 -->
71
+ <vhall-lottery wx:if="{{webinarStatus==1}}" sdkInstance="{{sdkInstance}}" />
70
72
  <!-- 商城奖励 -->
71
- <vhall-mall-reward sdkInstance="{{sdkInstance}}" />
73
+ <vhall-mall-reward wx:if="{{webinarStatus==1||webinarStatus==5}}" sdkInstance="{{sdkInstance}}" />
74
+ <!-- 公告组件 -->
75
+ <vhall-announcement wx:if="{{webinarStatus==1||webinarStatus==5}}" sdkInstance="{{sdkInstance}}" mode="{{1}}" />
72
76
  </view>
73
- <error-page wx:else errorResp="{{errorResp}}"></error-page>
@@ -1,3 +1,5 @@
1
+ import { reloadCurrentPage } from '../../shared/mpUtils.js';
2
+
1
3
  Component({
2
4
  properties: {
3
5
  sdkInstance: {
@@ -9,6 +11,7 @@ Component({
9
11
  tabList: [],
10
12
  activeTab: 0,
11
13
  liveInfo: null,
14
+ isReady: false, // SDK 是否已初始化完成
12
15
  showStartDialog: false, // 是否显示开始直播弹窗
13
16
 
14
17
  showRecordWatchExpireDialog: false, // 是否显示回放视频已过观看有效期提示框
@@ -42,6 +45,9 @@ Component({
42
45
  liveInfo: val,
43
46
  });
44
47
  },
48
+ isReady: (val) => {
49
+ this.setData({ isReady: !!val });
50
+ },
45
51
  webinarStatus: (val) => {
46
52
  this.setData({
47
53
  webinarStatus: val,
@@ -148,7 +154,8 @@ Component({
148
154
  this.setData({
149
155
  showStartDialog: false,
150
156
  });
151
- this.sdkInstance.init();
157
+ reloadCurrentPage();
158
+
152
159
  },
153
160
  handleExprie() {
154
161
  this.sdkInstance._handleBizErrorCode(512912)
@@ -279,4 +286,5 @@ Component({
279
286
  // 支付成功后的处理
280
287
  },
281
288
  },
282
- });
289
+ });
290
+
@@ -13,6 +13,7 @@
13
13
  "vhall-product-order": "../product/product-order/product-order",
14
14
  "vhall-lottery": "../lottery/lottery",
15
15
  "vhall-mall-reward": "../mall-reward/index",
16
+ "vhall-announcement": "../announcement/index",
16
17
  "product-detail": "../product/product-detail/product-detail",
17
18
  "start-countdown": "../../pubComponents/countdown/countdown",
18
19
  "signin-dialog": "../signin/signin-dialog",
@@ -33,6 +34,7 @@
33
34
  "signin-dialog": "view",
34
35
  "vhall-gift-sender": "view",
35
36
  "vhall-lottery": "view",
36
- "vhall-invite-rank": "view"
37
+ "vhall-invite-rank": "view",
38
+ "vhall-announcement": "view"
37
39
  }
38
40
  }
@@ -1,4 +1,5 @@
1
- <view class="live_portrait" wx:if="{{!errorResp || !errorResp.code}}">
1
+ <error-page wx:if="{{errorResp && errorResp.code}}" errorResp="{{errorResp}}"></error-page>
2
+ <view class="live_portrait" wx:elif="{{isReady}}">
2
3
  <view class="live_portrait_player">
3
4
  <vhall-player sdkInstance="{{sdkInstance}}" objectFit="{{playerObjectFit}}"></vhall-player>
4
5
  </view>
@@ -99,8 +100,11 @@
99
100
  </scroll-view>
100
101
  </view>
101
102
  </vh-popup>
102
- <vhall-lottery sdkInstance="{{sdkInstance}}" />
103
+ <!-- 抽奖组件 -->
104
+ <vhall-lottery wx:if="{{webinarStatus==1}}" sdkInstance="{{sdkInstance}}" />
103
105
  <!-- 商城奖励 -->
104
- <vhall-mall-reward sdkInstance="{{sdkInstance}}" />
106
+ <vhall-mall-reward wx:if="{{webinarStatus==1||webinarStatus==5}}" sdkInstance="{{sdkInstance}}" />
107
+ <!-- 公告组件 -->
108
+ <vhall-announcement wx:if="{{webinarStatus==1||webinarStatus==5}}" sdkInstance="{{sdkInstance}}" mode="{{0}}" />
105
109
  </view>
106
- <error-page wx:else errorResp="{{errorResp}}"></error-page>
110
+
@@ -35,12 +35,11 @@ Component({
35
35
  if (!_sdkInstance) return;
36
36
  log.info('mall-reward sdkInstance');
37
37
  this.sdkInstance = _sdkInstance;
38
- this.setData({
39
- initTime: Date.now(),
40
- });
41
38
  this.initEventListener();
42
-
43
- this.checkAndFetchMallRewardInfo('refresh');
39
+ if (this.sdkInstance.isReady()) {
40
+ // 已经 ready 了,立刻刷新(事件已发过,不等)
41
+ this.onSdkReady();
42
+ }
44
43
  },
45
44
  },
46
45
  lifetimes: {
@@ -58,6 +57,11 @@ Component({
58
57
  this.unlistener?.();
59
58
  const obj = {};
60
59
 
60
+ // 直接调用 sdkInstance.init()触发
61
+ obj[this.sdkInstance.EVENT.SDK_READY] = () => {
62
+ this.onSdkReady();
63
+ };
64
+
61
65
  // 推送商城奖励
62
66
  obj[this.sdkInstance.EVENT.MALL_REWARD_PUSH] = (msg) => {
63
67
  log.info('mallReward open msg:', JSON.stringify(msg));
@@ -66,6 +70,7 @@ Component({
66
70
  if (!this.webinarType != 1) {
67
71
  return;
68
72
  }
73
+ this.sdkInstance.BRSAgent?.customLog('checkAndFetchMallRewardInfo from=push');
69
74
  this.checkAndFetchMallRewardInfo('push', { reward_id: msg.data?.id });
70
75
  // 消息推送
71
76
  // const data = {
@@ -109,41 +114,54 @@ Component({
109
114
  });
110
115
  };
111
116
 
112
- // 上线消息
113
- obj[this.sdkInstance.EVENT.JOIN_MSG] = (msg) => {
114
- log.info('mallReward ------handleMsgJoin-msg:', msg);
115
- // 监听上线消息,刷新商城奖励数据条件:
116
- //(1)上线的人是自己;( 支持多端上线)
117
- //(2)间隔初始化请求时间超过3s(否则每次刷新调用两次请求;是否可以仅使用JOIN消息请求?不行,因为join消息不可靠,有时候收不到)
117
+ // 连接状态变化(以 socket connected/disconnect 为准,比 JOIN_MSG 广播更可靠)
118
+ obj[this.sdkInstance.EVENT.ONLINE_STATE_CHANGE] = (data) => {
119
+ log.info('mallReward ------handleOnlineStateChange data:', data);
118
120
  if (!this.sdkInstance) return;
119
- const watchInitData = this.sdkInstance.store.get('watchInitData');
120
- const thirdPartyUserId = watchInitData?.join_info?.third_party_user_id;
121
- /* prettier-ignore */
122
- if (thirdPartyUserId && msg.sender_id == thirdPartyUserId && Date.now() - this.data.initTime > 3000) {
123
- this.checkAndFetchMallRewardInfo('refresh');
121
+ if (data?.online) {
122
+ // 上线(连接建立成功):刷新商城奖励数据(与 FOREGROUND_REFRESH 共用防抖,避免重复请求)
123
+ if (this._shouldRefreshByEvent()) {
124
+ this.sdkInstance.BRSAgent?.customLog('checkAndFetchMallRewardInfo from=refresh, online_state_change');
125
+ this.checkAndFetchMallRewardInfo('refresh');
126
+ }
127
+ } else {
128
+ // 下线(连接断开):暂停计时器
129
+ log.info('mallReward ------onlineStateChange offline, 倒计时暂停');
130
+ this.destroyTimer();
124
131
  }
125
132
  };
126
133
 
127
- // 下线消息
128
- obj[this.sdkInstance.EVENT.LEAVE_MSG] = (msg) => {
129
- log.info('mallReward ------handleMsgLeave-msg:', msg);
134
+ // 切回前台刷新(JOIN_MSG 有限频不可靠,以此事件兜底刷新商城奖励数据)
135
+ obj[this.sdkInstance.EVENT.FOREGROUND_REFRESH] = (data) => {
136
+ log.info('mallReward ------handleForegroundRefresh data:', data);
130
137
  if (!this.sdkInstance) return;
131
- const watchInitData = this.sdkInstance.store.get('watchInitData');
132
- const localKickMark = this.sdkInstance.store.get('kickMark');
133
- const localKickID = watchInitData?.sso?.kick_id;
134
- const msgContex = safeJsonParse(msg?.context);
135
- /* prettier-ignore */ // 自己下线了,计时器暂停
136
- if (localKickMark && localKickID && msgContex.kick_id === localKickID && msgContex.kick_mark === localKickMark) {
137
- console.log('mallReward 倒计时暂停');
138
- this.destroyTimer();
138
+ this.sdkInstance.BRSAgent?.customLog('checkAndFetchMallRewardInfo from=refresh, foreground_refresh');
139
+ if (this._shouldRefreshByEvent()) {
140
+ this.checkAndFetchMallRewardInfo('refresh');
139
141
  }
140
142
  };
141
143
 
142
144
  this.unlistener = this.sdkInstance.on(obj);
143
145
  },
146
+ onSdkReady() {
147
+ log.info('mall-reward onSdkReady');
148
+ this.setData({ initTime: Date.now() });
149
+ this.sdkInstance.BRSAgent?.customLog('checkAndFetchMallRewardInfo from=refresh, onSdkReady');
150
+ this.checkAndFetchMallRewardInfo('refresh');
151
+ },
152
+ // 事件触发的刷新防抖:JOIN_MSG / FOREGROUND_REFRESH 等共用冷却,避免接口重复触发
153
+ _shouldRefreshByEvent() {
154
+ const now = Date.now();
155
+ // 距离上次事件刷新(或 onSdkReady 初始化刷新)不足 3s 时跳过,避免接口重复请求
156
+ const last = this._lastRefreshTime || this.data.initTime || 0;
157
+ if (last && now - last < 2000) {
158
+ return false;
159
+ }
160
+ this._lastRefreshTime = now;
161
+ return true;
162
+ },
144
163
  async checkAndFetchMallRewardInfo(from, extra) {
145
- this.sdkInstance.BRSAgent?.customLog(`checkAndFetchMallRewardInfo from=${from}`, JSON.stringify(extra));
146
- log.info('mall-reward checkAndFetchMallRewardInfo start');
164
+ log.info('mall-reward checkAndFetchMallRewardInfo call')
147
165
  const mallRewardServer = this.sdkInstance.get('mallRewardServer');
148
166
  if (!mallRewardServer) return;
149
167
 
@@ -6,7 +6,7 @@ Component({
6
6
  sdkInstance: {
7
7
  type: Object,
8
8
  value: null,
9
- observer: function(newVal) {
9
+ observer: function (newVal) {
10
10
  if (newVal) {
11
11
  this.initStoreListener();
12
12
  // 初始加载商品数据
@@ -38,7 +38,7 @@ Component({
38
38
  if (this.unsub) {
39
39
  this.unsub();
40
40
  }
41
-
41
+
42
42
  this.unsub = this.properties.sdkInstance.store.get({
43
43
  productList: (val) => {
44
44
  if (val) {
@@ -46,7 +46,6 @@ 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 });
50
49
  this.setData({
51
50
  products: products
52
51
  });
@@ -70,12 +69,12 @@ Component({
70
69
  console.error('商品数据不存在');
71
70
  return;
72
71
  }
73
-
72
+
74
73
  // 检查是否已抢光或待开价
75
74
  if (product.sale_status === 0 || product.covered_status === 1) {
76
75
  return;
77
76
  }
78
-
77
+
79
78
  // 检查 buy_type
80
79
  if (product.buy_type === 4 && product?.mini_program_config?.mini_program_path) {
81
80
  // 跳转到小程序路径
@@ -99,7 +98,7 @@ Component({
99
98
  // 点击关闭按钮(通过改变本地数据关闭卡片)
100
99
  onCloseCard(e) {
101
100
  const productId = e.currentTarget.dataset.productId;
102
-
101
+
103
102
  // 从本地数据中移除该商品
104
103
  const updatedProducts = this.data.products.filter(product => product.goods_id !== productId);
105
104
  this.setData({
@@ -15,7 +15,7 @@ Component({
15
15
  sdkInstance: {
16
16
  type: Object,
17
17
  value: null,
18
- observer: function(newVal) {
18
+ observer: function (newVal) {
19
19
  if (newVal) {
20
20
  this.initStoreListener();
21
21
  }
@@ -42,7 +42,7 @@ Component({
42
42
  },
43
43
  observers: {
44
44
  // 监听显示状态变化
45
- show: function(show) {
45
+ show: function (show) {
46
46
  if (show) {
47
47
  // 重置数据
48
48
  this.setData({
@@ -57,7 +57,7 @@ Component({
57
57
  if (this.unsub) {
58
58
  this.unsub();
59
59
  }
60
-
60
+
61
61
  this.unsub = this.properties.sdkInstance.store.get({
62
62
  productList: (val) => {
63
63
  if (val && this.properties.product && this.properties.product.goods_id) {
@@ -83,17 +83,17 @@ Component({
83
83
  // 购买商品
84
84
  buyProduct() {
85
85
  const product = this.data.product;
86
-
86
+
87
87
  if (!product) {
88
88
  console.error('商品数据不存在');
89
89
  return;
90
90
  }
91
-
91
+
92
92
  // 检查是否已抢光或待开价
93
93
  if (product.sale_status === 0 || product.covered_status === 1) {
94
94
  return;
95
95
  }
96
-
96
+
97
97
  // 检查 buy_type
98
98
  if (product.buy_type === 4 && product?.mini_program_config?.mini_program_path) {
99
99
  // 跳转到小程序路径
@@ -3,7 +3,7 @@ Component({
3
3
  sdkInstance: {
4
4
  type: Object,
5
5
  value: null,
6
- observer: function(newVal) {
6
+ observer: function (newVal) {
7
7
  if (newVal) {
8
8
  this.initStoreListener();
9
9
  }
@@ -46,11 +46,10 @@ Component({
46
46
  if (this.unsub) {
47
47
  this.unsub();
48
48
  }
49
-
49
+
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 });
54
53
  this.setData({ productList: val });
55
54
  }
56
55
  }