123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <template>
- <div></div>
- </template>
- <script>
- import wx from 'weixin-js-sdk'
- import * as API_WeiXin from '@/apis/weixin'
- export default {
- name: 'Share',
- props: {
-
- },
- data() {
- return {
- id:'',
- title:'',
- url:'',
- isLoading: false,
- nowItem: {
- shareTitle: '',
- shareImg: '',
- shareDescription: ''
- }
- }
- },
- created() {},
- methods: {
- addPoint(){
- API_WeiXin.addPoint({
- id:this.id,
- pointCode:"70007"
- }).then(response => {
-
- })
- },
-
- //获取微信jssdk配置信息
- get_wx_config() {
-
- this.isLoading = true;
- API_WeiXin.getConfig(window.location.href.split("#")[0]).then(response => {
- this.isLoading = false;
- var wxconfig = response.wxConfig;
- console.log(wxconfig.nonceStr)
- this.wxConfig = wxconfig;
- wx.config({
- debug: true, // 开启调试模式,
- appId: wxconfig.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
- timestamp: wxconfig.timestamp, // 必填,生成签名的时间戳
- nonceStr: wxconfig.nonceStr, // 必填,生成签名的随机串
- signature: wxconfig.signature, // 必填,签名,见附录1
- jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage',
- 'onMenuShareQQ', 'onMenuShareQZone','updateAppMessageShareData','updateTimelineShareData'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
- wx.error(function(res){
- console.log(res)
- console.log("error")
- // config信息验证失败会执行 error 函数,如签名过期导致验证失败,具体错误信息可以打开 config 的debug模式查看,也可以在返回的 res 参数中查看,对于 SPA 可以在这里更新签名。
- });
-
- //this.wxShare()
- }).catch(error => {
- this.isLoading = false;
-
- })
- },
- setUrl(url){
- this.url=process.car.IMG_URL+"railroad-phone/#"+url;
- },
- setTitle(text,id){
- this.title=text;
- this.id=id;
- this.wxShare()
-
- },
- //微信分享自定义
- wxShare() {
- var userInfo=this.carhelp.getPersonInfo()
- //var img=require("@/assets/img/logo.png")
- var img=""
- var title="[微官网]"+this.title
- // var desc=
- let joinUrl = this.url;
- console.log(img);
- console.log(title);
- console.log(joinUrl);
- var _this = this;
-
- wx.ready(function() {
- wx.checkJsApi({
- jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage',
- 'onMenuShareQQ', 'onMenuShareQZone','updateAppMessageShareData','updateTimelineShareData'], // 需要检测的 JS 接口列表,所有 JS 接口列表见附录2,
- success: function(res) {
- console.log(res)
- console.log("1111")
- }
- });
-
- wx.updateTimelineShareData({
- title: title,
- // desc:desc ,
- link: joinUrl,
- imgUrl: img,
- success: function() {
- if(userInfo){
- //_this.addPoint()
- }
- // 设置成功
- _this.$emit("wxShare",null);
- }
- })
- wx.updateAppMessageShareData({
- title: title,
- // desc:desc ,
- link: joinUrl,
- imgUrl: img,
- success: function() {
- if(userInfo){
- //_this.addPoint()
- }
- // 设置成功
- _this.$emit("wxShare",null);
- }
- })
- wx.onMenuShareAppMessage({
- title: title,
- // desc:desc ,
- link: joinUrl,
- imgUrl: img,
- success: function() {
- if(userInfo){
- //_this.addPoint()
- }
- // 设置成功
- _this.$emit("wxShare",null);
- }
- })
- wx.onMenuShareTimeline({
- title: title,
- //desc:desc ,
- link: joinUrl,
- imgUrl: img,
- success: function() {
- // 设置成功
- _this.$emit("wxShare",null);
- }
- })
- });
- }
- },
- mounted() {
- this.url=window.location.href;
- this.get_wx_config();
- },
- }
- </script>
- <style>
- </style>
|