Authored by huzhiming

feat(活动模版):活动模版闲鱼分享功能接入 reviewed by tao.huang

@@ -134,7 +134,7 @@ @@ -134,7 +134,7 @@
134 "whatwg-fetch": "^2.0.4", 134 "whatwg-fetch": "^2.0.4",
135 "workbox-sw": "^2.1.2", 135 "workbox-sw": "^2.1.2",
136 "workbox-webpack-plugin": "^3.4.1", 136 "workbox-webpack-plugin": "^3.4.1",
137 - "yo-cli": "^2.1.10", 137 + "yo-cli": "^2.1.13",
138 "yoho-activity-sdk": "^1.1.5", 138 "yoho-activity-sdk": "^1.1.5",
139 "yoho-cookie": "^1.2.0", 139 "yoho-cookie": "^1.2.0",
140 "yoho-fastclick": "^1.0.6", 140 "yoho-fastclick": "^1.0.6",
@@ -12,6 +12,7 @@ const shopTmpl = require('hbs/activity/feature/shop-group.hbs'); @@ -12,6 +12,7 @@ const shopTmpl = require('hbs/activity/feature/shop-group.hbs');
12 const seckillTabTpl = require('hbs/activity/feature/seckill-tab.hbs'); 12 const seckillTabTpl = require('hbs/activity/feature/seckill-tab.hbs');
13 const seckillProductTpl = require('hbs/activity/feature/seckill-product.hbs'); 13 const seckillProductTpl = require('hbs/activity/feature/seckill-product.hbs');
14 const yo_sdk = require('./feature/yo-sdk'); 14 const yo_sdk = require('./feature/yo-sdk');
  15 +const { XianyuJSBridge } = require('./xianyu');
15 16
16 require('scss/feature.scss'); 17 require('scss/feature.scss');
17 18
@@ -1601,3 +1602,31 @@ $(function() { @@ -1601,3 +1602,31 @@ $(function() {
1601 couponSendFinished(); 1602 couponSendFinished();
1602 } 1603 }
1603 }); 1604 });
  1605 +
  1606 +// 1、判断闲鱼环境,加载相关jssdk资源(layout.hbs 已做)
  1607 +// 2、打开闲鱼导航栏右侧···按钮,并配置分享参数
  1608 +// 3、绑定相关触发函数
  1609 +// /* eslint-disable */
  1610 +$(function() {
  1611 + // var VConsole = require('vconsole');
  1612 + // var vConsole = new VConsole();
  1613 + const webShareData = {
  1614 + title: $('#shareTitle').val(),
  1615 + desc: $('#shareImg').val(),
  1616 + imgUrl: $('#shareDesc').val(),
  1617 + link: $('#shareLink').val()
  1618 + };
  1619 + const parames = {
  1620 + shareType: 'activity', // 类型,默认activity
  1621 + image: webShareData.imgUrl,
  1622 + url: `${webShareData.link}?isNeedRefresh=false`, // 分享链接
  1623 + link: `${webShareData.link}?isNeedRefresh=false`, // 和url保持
  1624 + title: `淘口令#${webShareData.title}`, // 分享标题
  1625 + text: '' // 分享描述
  1626 + };
  1627 +
  1628 + // parames.image = $('.feature-page .floor').eq(1).children('img').eq(0).attr('src');
  1629 + // console.log(parames);
  1630 +
  1631 + XianyuJSBridge.hideLoadingBox().setNavRightItem(parames);
  1632 +});
  1 +
1 import $ from 'yoho-jquery'; 2 import $ from 'yoho-jquery';
2 3
3 function XianyuLinkHandle() { 4 function XianyuLinkHandle() {
@@ -38,3 +39,86 @@ function XianyuLinkHandle() { @@ -38,3 +39,86 @@ function XianyuLinkHandle() {
38 } 39 }
39 40
40 export default new XianyuLinkHandle(); 41 export default new XianyuLinkHandle();
  42 +
  43 +/* eslint-disable */
  44 +/*
  45 + * @ description: js调用闲鱼相关API方法封装
  46 + * @ author: huzhiming
  47 + * @ date: 2019-12-03 09:45:05
  48 + * @ version: v1.0.0
  49 + *
  50 +*/
  51 +export const XianyuJSBridge = {
  52 + // 判断是否在闲鱼环境内
  53 + get isAliApp () {
  54 + return /AliApp/i.test(navigator.userAgent || '');
  55 + },
  56 + /*
  57 + * @ description: 导航栏右侧自定义按钮 设为关闭
  58 + * @ author: huzhiming
  59 + * @ date: 2019-11-14 16:15:07
  60 + * @ version: v1.0.0
  61 + */
  62 + closeNavRightItem () {
  63 + if (this.isAliApp && window.WindVane) {
  64 + window.WindVane.call('WVIdleFishApi', 'setHideNavigatorRightItem', {}, () => { }, () => { })
  65 + }
  66 + return this;
  67 + },
  68 +
  69 + // 导航栏右侧自定义按钮 设为可见
  70 + setNavRightItem (shareParam = null) {
  71 + window._xianyuShare = () => {
  72 + this.setXianyuShare(shareParam);
  73 + }
  74 + if (this.isAliApp && window.WindVane) {
  75 + window.WindVane.call('WVIdleFishApi', 'setNavigatorRightItem', {
  76 + title: '∙∙∙', // 按钮名称
  77 + func: '_xianyuShare' // func: 'test' //点击调用函数 注意调用的函数必须挂载在window上
  78 + }, function(data) {
  79 + console.log('setNavigatorRightItem success:', data);
  80 + }, function(e) {
  81 + console.log('setNavigatorRightItem error:', e);
  82 + });
  83 + }
  84 + return this;
  85 + },
  86 +
  87 + /*
  88 + * @ description: 配置分享参数进行分享操作
  89 + * @ author: huzhiming
  90 + * @ date: 2019-11-05 10:38:24
  91 + * @ version: v1.0.0
  92 + */
  93 + setXianyuShare (param = {
  94 + shareType: 'activity', // 类型,默认activity
  95 + image: '//img11.static.yhbimg.com/goodsimg/2018/12/24/17/01070adae9791c70ed02593550437cf30e.jpg?imageMogr2/thumbnail/600x600/background/d2hpdGU=/position/center/quality/80',
  96 + url: '//xianyu.yohobuy.com/xianyu/index/channel?wxIsAvailable', // 分享链接
  97 + link: '//xianyu.yohobuy.com/xianyu/index/channel?wxIsAvailable', // 和url保持
  98 + title: '闲鱼潮品首页', // 分享标题
  99 + text: '' // 分享描述
  100 + }) {
  101 + if (this.isAliApp && window.WindVane) {
  102 + window.WindVane.call('WVIdleFishApi', 'showShareMenu', param, (data) => {
  103 + console.log('success:', JSON.stringify(data), typeof data.isCancel);
  104 + // if (data.isCancel === 'false') {}
  105 + }, function(e) {
  106 + console.log('fail:', JSON.stringify(e));
  107 + });
  108 + }
  109 + return this;
  110 + },
  111 +
  112 + // 隐藏 webview loadingBox
  113 + hideLoadingBox () {
  114 + if (this.isAliApp && window.WindVane) {
  115 + window.WindVane.call('WVUI', 'hideLoadingBox', {}, function(e) {
  116 + console.log('success: ' + JSON.stringify(e));
  117 + }, function(e) {
  118 + console.log('failure: ' + JSON.stringify(e));
  119 + });
  120 + }
  121 + return this;
  122 + }
  123 +};
  124 +