Commit 28f61820a717026dd51b5b75318704ca2a08421d
1 parent
fa9cc451
购好物,“好物推荐”商品,“+”功能对接App加入购物车~
Showing
2 changed files
with
45 additions
and
2 deletions
src/pages/common/common.vue
| @@ -639,6 +639,34 @@ | @@ -639,6 +639,34 @@ | ||
| 639 | } | 639 | } |
| 640 | }, | 640 | }, |
| 641 | 641 | ||
| 642 | + /** | ||
| 643 | + * 加入购物车 | ||
| 644 | + * @param {Object} item [商品信息对象] | ||
| 645 | + */ | ||
| 646 | + addToShoppingCart(item) { | ||
| 647 | + | ||
| 648 | + if (this.isCNLive.value) { | ||
| 649 | + | ||
| 650 | + // 获取商品id | ||
| 651 | + let {id} = item; | ||
| 652 | + | ||
| 653 | + // 判断必要参数,是否有商品id | ||
| 654 | + if (id) { | ||
| 655 | + | ||
| 656 | + // 请求App接口,加入购物车 | ||
| 657 | + if(window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.addToShoppingCart) { | ||
| 658 | + | ||
| 659 | + // 请求App接口,加入购物车 | ||
| 660 | + window.webkit.messageHandlers.addToShoppingCart.postMessage({body: {id: id}}); | ||
| 661 | + } else if(window.obj && window.obj.addToShoppingCart) { | ||
| 662 | + | ||
| 663 | + // 请求App接口,加入购物车 | ||
| 664 | + window.obj.addToShoppingCart(id); | ||
| 665 | + } | ||
| 666 | + } | ||
| 667 | + } | ||
| 668 | + }, | ||
| 669 | + | ||
| 642 | /* 获取并设置唤起App参数 开始 */ | 670 | /* 获取并设置唤起App参数 开始 */ |
| 643 | 671 | ||
| 644 | /** | 672 | /** |
src/pages/optimization2/optimization2.vue
| @@ -1075,8 +1075,23 @@ | @@ -1075,8 +1075,23 @@ | ||
| 1075 | */ | 1075 | */ |
| 1076 | primary(item) { | 1076 | primary(item) { |
| 1077 | 1077 | ||
| 1078 | - // 跳转详情页面 | ||
| 1079 | - this.toDetail(item); | 1078 | + // 判断是否在App内 |
| 1079 | + if (this.isCNLive.value) { | ||
| 1080 | + | ||
| 1081 | + // 判断加入购物车函数是否存在 | ||
| 1082 | + if (typeof this.$parent.addToShoppingCart === 'function') { | ||
| 1083 | + | ||
| 1084 | + // 加入购物车 | ||
| 1085 | + this.$parent.addToShoppingCart(item); | ||
| 1086 | + | ||
| 1087 | + // 提示加入购物车 | ||
| 1088 | + Toast('已加入购物车'); | ||
| 1089 | + } | ||
| 1090 | + } else { | ||
| 1091 | + | ||
| 1092 | + // 跳转详情页面 | ||
| 1093 | + this.toDetail(item); | ||
| 1094 | + } | ||
| 1080 | }, | 1095 | }, |
| 1081 | 1096 | ||
| 1082 | /** | 1097 | /** |