Browse Source

fix: 微信分享自定义不显示

old
wangqing 5 years ago
parent
commit
83c30ed315
  1. 2
      src/utils/loadWxSdk.js
  2. 55
      src/views/form/write.vue

2
src/utils/loadWxSdk.js

@ -17,7 +17,7 @@ export default function loadWXJs(cb) {
background: 'rgba(255, 255, 255, 0.5)'
})
loadScript('http://res.wx.qq.com/open/js/jweixin-1.6.0.js', () => {
loadScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js', () => {
loading.close()
// eslint-disable-next-line no-undef
wxObj = wx

55
src/views/form/write.vue

@ -43,7 +43,6 @@ const uaParser = require('ua-parser-js')
const ua = uaParser(navigator.userAgent)
require('@/utils/ut')
let wx
export default {
name: 'WriteView',
props: {},
@ -86,10 +85,11 @@ export default {
this.queryProjectSettingStatus()
this.queryProjectSetting()
//
this.$api.get('/wx/jsapi/signature', {params: {url: getCurrentDomain()}}).then(res => {
this.$api.get('/wx/jsapi/signature', {params: {url: window.location.href}}).then(res => {
this.wxSignature = res.data
this.setWxConfig()
})
console.log(ua)
},
mounted() {
this.viewProjectHandle()
@ -98,7 +98,7 @@ export default {
ProjectForm
}, methods: {
viewProjectHandle() {
//
//
this.$api.post(`/user/project/result/view/${this.projectConfig.projectKey}`, {params: {projectKey: this.projectConfig.projectKey}}).then(res => {
})
@ -136,9 +136,9 @@ export default {
})
},
setWxConfig() {
let that = this
let signature = this.wxSignature
loadWXJs(val => {
wx = val
loadWXJs(wx => {
wx.config({
debug: false, // ,apialertpclogpc
appId: signature.appId, //
@ -148,22 +148,26 @@ export default {
jsApiList: [
'updateAppMessageShareData',
'updateTimelineShareData',
'onMenuShareAppMessage',
'onMenuShareTimeline',
'showMenuItems',
'hideMenuItems',
'chooseWXPay'
] // 使JS
})
this.setWxProjectShare()
//sdk
wx.ready(function() {
//
console.log('ready')
that.setWxProjectShare(wx)
})
})
},
/**
* 微信分享
*/
setWxProjectShare() {
setWxProjectShare(wx) {
let {shareImg, shareTitle, shareDesc} = this.userProjectSetting
console.log(wx)
wx.ready(function() { //
console.log('ready')
wx.updateAppMessageShareData({
title: shareTitle ? shareTitle : defaultValue.projectShareTitle, //
desc: shareDesc ? shareDesc : defaultValue.projectShareDesc, //
@ -190,6 +194,25 @@ export default {
console.log('fail')
}
})
wx.onMenuShareTimeline({
title: shareTitle ? shareTitle : defaultValue.projectShareTitle, //
desc: shareDesc ? shareDesc : defaultValue.projectShareDesc, //
link: window.location.href, // JS
imgUrl: shareImg ? shareImg : defaultValue.projectShareImg, //
success: function() {
//
console.log('succcess')
}
})
wx.onMenuShareAppMessage({
title: shareTitle ? shareTitle : defaultValue.projectShareTitle, //
desc: shareDesc ? shareDesc : defaultValue.projectShareDesc, //
link: window.location.href, // JS
imgUrl: shareImg ? shareImg : defaultValue.projectShareImg, //
success: function() {
//
console.log('succcess')
}
})
},
queryProjectSetting() {
@ -200,9 +223,9 @@ export default {
if (res.data && res.data.wxWrite) {
//
if (res.data.recordWxUser && !this.wxAuthorizationCode) {
console.log(this.wxAuthorizationUrl)
location.href = this.wxAuthorizationUrl
} else {
//
this.onlyWxOpenHandle()
}
}
@ -229,17 +252,7 @@ export default {
'originalData': data.formModel,
'processData': data.labelFormModel
}).then(res => {
//
let submitJumpUrl = this.userProjectSetting.submitJumpUrl
if (submitJumpUrl) {
//httpshttp
if (!submitJumpUrl.startsWith('http') || !submitJumpUrl.startsWith('http')) {
submitJumpUrl = 'http://' + submitJumpUrl
}
window.location.href = submitJumpUrl
}
this.writeStatus = 2
})
}
}

Loading…
Cancel
Save