提交 9301c992 编写于 作者: guangjun.yang's avatar guangjun.yang

分享问题

上级 f613710b
此差异已折叠。
......@@ -23,7 +23,7 @@
"vue-router": "^2.1.1",
"vuex": "^2.0.0",
"web-buried-point": "^2.1.0",
"weixin-js-sdk": "^1.4.0-test",
"weixin-js-sdk": "^1.6.0",
"pica-call-app": "^1.0.43"
},
"devDependencies": {
......
/* eslint-disable */
import Vue from 'vue'
import request from '@/utils/fetch';
import wx from 'weixin-js-sdk'
import { getWxType } from "@/utils/index";
/** 注入配置信息 */
export const wxConfig = () => {
// const params = { resetURI: true, url: encodeURIComponent(location.href) };
// 上线前是需要把域名改为线上的sc
let type = '&type=' + getWxType(); // type不同,对应的appid不一样,15为线上
request({ url: `https://sc.yunqueyi.com/wechats/signs?url=${encodeURIComponent(location.href)}${type}` }).then(res => {
let configs = res.data.signMap;
wx.config({
debug: false,
appId: configs.appId,
nonceStr: configs.nonceStr,
timestamp: configs.timestamp,
signature: configs.signature,
jsApiList: [
'hideMenuItems',
'previewImage',
'checkJsApi',
'chooseWXPay',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'onMenuShareQZone',
'getLocation',
'openLocation',
'translateVoice'
]
});
});;
};
/**
* wxShare 分享
* @param option
*/
export const wxShare = (option = {}, successCB = () => {}) => {
wx.ready(() => {
WeixinJSBridge.call('showOptionMenu');
wx.showAllNonBaseMenuItem();
// 分享给朋友
wx.onMenuShareAppMessage({
title: option.title,
desc: option.desc,
link: option.link,
imgUrl: option.imgUrl,
success: function(res) {
// 用户确认分享后执行的回调函数
successCB(res);
},
cancel: function() {
// 用户取消分享后执行的回调函数
}
});
// 分享到朋友圈
wx.onMenuShareTimeline({
title: option.friendtitle || option.title, // 标题
desc: option.desc,
link: option.link, // 链接
imgUrl: option.imgUrl, // 分享图标
success: function(res) {
successCB(res);
},
cancel: function() {
// 用户取消分享后执行的回调函数
}
});
});
};
function wxHideMenu() {
wx.ready(() => {
WeixinJSBridge.call('hideOptionMenu');
wx.hideAllNonBaseMenuItem();
});
}
export const wxDisabledShare = () => {
wx.ready(() => {
wx.hideMenuItems({
menuList: [
'menuItem:share:appMessage',
'menuItem:share:timeline',
'menuItem:share:qq',
'menuItem:share:weiboApp',
'menuItem:share:QZone',
'menuItem:copyUrl',
'menuItem:openWithQQBrowser',
'menuItem:openWithSafari',
],
openTagList: ['wx-open-launch-app', 'wx-open-launch-weapp'],
});
});
};
/**
*
* @param source
* @param option
*/
export const wechatShare = (option = {}, successCB = () => {}, hideMenu) => {
const shareOption = {
link: location.href,
title: `云鹊医!`,
friendtitle: `讨论进行中,速来围观!`,
desc: '参与讨论,一起畅谈医学那些事!快来看看吧~',
imgUrl: 'https://file.yunqueyi.com/logo.png',
...option
};
wxConfig();
if (hideMenu) {
wxHideMenu()
} else {
wxShare(shareOption, successCB);
}
};
export function chooseWXPay(params) {
wx.ready(() => {
wx.chooseWXPay(params);
})
}
Vue.prototype.wechatShare = wechatShare;
Vue.prototype.wxDisabledShare = wxDisabledShare;
/* eslint-disable */
import Vue from 'vue'
import request from '@/utils/fetch';
import wx from 'weixin-js-sdk'
import wx from 'weixin-js-sdk';
import { getWxType } from "@/utils/index";
/** 注入配置信息 */
export const wxConfig = () => {
// const params = { resetURI: true, url: encodeURIComponent(location.href) };
// 上线前是需要把域名改为线上的sc
/**
* 各个环境目前获取签名使用: type[dev: 1, test1: 15, uat: 30, prod: 5]
* 微信类型 1、云鹊医联 5、云鹊健康 10、基层大众版 15、云鹊医 20、基层医生版 25、云鹊慧测试账号 30云鹊医导流公众号
*/
let type = '&type=' + getWxType(); // type不同,对应的appid不一样,15为线上
request({ url: `https://sc.yunqueyi.com/wechats/signs?url=${encodeURIComponent(location.href)}${type}` }).then(res => {
let configs = res.data.signMap;
......@@ -28,10 +31,12 @@ export const wxConfig = () => {
'onMenuShareQZone',
'getLocation',
'openLocation',
'translateVoice'
]
'translateVoice',
'onMenuShareAppMessage'
],
openTagList: ['wx-open-launch-app', 'wx-open-launch-weapp'],
});
});;
});
};
......@@ -41,8 +46,6 @@ export const wxConfig = () => {
*/
export const wxShare = (option = {}, successCB = () => {}) => {
wx.ready(() => {
WeixinJSBridge.call('showOptionMenu');
wx.showAllNonBaseMenuItem();
// 分享给朋友
wx.onMenuShareAppMessage({
title: option.title,
......@@ -55,6 +58,9 @@ export const wxShare = (option = {}, successCB = () => {}) => {
},
cancel: function() {
// 用户取消分享后执行的回调函数
},
fail: function (res) {
console.log('分享失败',JSON.stringify(res));
}
});
......@@ -72,15 +78,11 @@ export const wxShare = (option = {}, successCB = () => {}) => {
}
});
});
wx.error((res) => {
console.log('wx.error res => ', res);
})
};
function wxHideMenu() {
wx.ready(() => {
WeixinJSBridge.call('hideOptionMenu');
wx.hideAllNonBaseMenuItem();
});
}
export const wxDisabledShare = () => {
wx.ready(() => {
wx.hideMenuItems({
......@@ -89,12 +91,8 @@ export const wxDisabledShare = () => {
'menuItem:share:timeline',
'menuItem:share:qq',
'menuItem:share:weiboApp',
'menuItem:share:QZone',
'menuItem:copyUrl',
'menuItem:openWithQQBrowser',
'menuItem:openWithSafari',
],
openTagList: ['wx-open-launch-app', 'wx-open-launch-weapp'],
'menuItem:share:QZone'
]
});
});
};
......@@ -104,7 +102,7 @@ export const wxDisabledShare = () => {
* @param source
* @param option
*/
export const wechatShare = (option = {}, successCB = () => {}, hideMenu) => {
export const wechatShare = async (option = {}, successCB = () => {}) => {
const shareOption = {
link: location.href,
title: `云鹊医!`,
......@@ -115,21 +113,9 @@ export const wechatShare = (option = {}, successCB = () => {}, hideMenu) => {
...option
};
wxConfig();
if (hideMenu) {
wxHideMenu()
} else {
wxShare(shareOption, successCB);
}
wxShare(shareOption, successCB);
};
export function chooseWXPay(params) {
wx.ready(() => {
wx.chooseWXPay(params);
})
}
Vue.prototype.wechatShare = wechatShare;
Vue.prototype.wxDisabledShare = wxDisabledShare;
Vue.prototype.wechatShare = wechatShare
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册