123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <template>
- </template>
- <script>
- import * as API_Common from '$project/apis/common'
- import wx from 'weixin-js-sdk'
- import * as WxJsApi from '$project/utils/wxJsApi'
- export default {
- name: 'Share',
- props: {
- id: {
- require: true,
- default: '0',
- },
- serverList: {
- require: true,
- type: Array,
- default: () => {
- return [];
- }
- }
- },
- data() {
- return {
- shareName:null,
- isLoading: false,
- nowItem: {
- shareTitle: '',
- shareImg: '',
- shareDescription: ''
- }
- }
- },
- created() {
- },
- methods: {
- //父组件调用子组件的方法在获取相应的数据后调用
- init() {
- for (var i = 0; i < this.serverList.length; i++) {
- if (this.serverList[i]['dictionaryId'] == this.id) {
- this.nowItem = this.serverList[i];
- break;
- }
- }
- //定义微信分享
- this.wxShare();
- },
- get_wx_config() {
- // this.isLoading = true;
- var sz=['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareQZone']
- WxJsApi.getWxConfig(sz)
- },
- //第二种方法,直接通过调用该方法来处理
- setShare() {
- this.isLoading = true;
- API_Common.getSchoolServeList().then(response => {
- this.isLoading = false;
- for (var i = 0; i < response.length; i++) {
- if (response[i]['dictionaryId'] == this.id) {
- this.nowItem = response[i];
- break;
- }
- }
- //定义微信分享
- this.wxShare();
- }).catch(error => {
- this.isLoading = false;
- //this.mui.toast(error);
- })
- },
- setName(name) {
- this.shareName=name;
- },
- //获取微信jssdk配置信息
- //微信分享自定义
- wxShare() {
- console.log(this.nowItem);
- if(this.shareName){
- this.nowItem.shareTitle=this.shareName;
- }
- let joinUrl = window.location.href
- if(joinUrl.indexOf("&share=1")>0){
- joinUrl= joinUrl.replace("&share=1","")
- }
- var _this = this;
- wx.ready(function() {
- wx.onMenuShareAppMessage({
- title: '【小鹏管家】'+_this.nowItem.shareTitle,
- desc: _this.nowItem.shareDescription,
- link: joinUrl,
- imgUrl: _this.nowItem.shareImg,
- success: function() {
- // 设置成功
- }
- })
- wx.onMenuShareTimeline({
- title: _this.nowItem.shareTitle,
- desc: _this.nowItem.shareDescription,
- link: joinUrl,
- imgUrl: _this.nowItem.shareImg,
- success: function() {
- // 设置成功
- }
- })
- });
- }
- },
- mounted() {
- this.get_wx_config();
- },
- }
- </script>
- <style>
- </style>
|