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)' 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() loading.close()
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
wxObj = wx wxObj = wx

55
src/views/form/write.vue

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

Loading…
Cancel
Save