提交 1c366fa3 authored 作者: lihuihui's avatar lihuihui

添加微信分享

上级 0f1ab992
...@@ -7,5 +7,8 @@ module.exports = { ...@@ -7,5 +7,8 @@ module.exports = {
'vue/no-mutating-props': 'off', // 暂时关闭 'vue/no-mutating-props': 'off', // 暂时关闭
'vue/comment-directive': 'off', 'vue/comment-directive': 'off',
'space-before-function-paren': 'off' 'space-before-function-paren': 'off'
},
globals: {
wx: true
} }
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<link rel="icon" href="https://zws-imgs-pub.ezijing.com/pc/base/favicon.ico" /> <link rel="icon" href="https://zws-imgs-pub.ezijing.com/pc/base/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title> <title></title>
<script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
......
...@@ -4,6 +4,7 @@ import router from './router' ...@@ -4,6 +4,7 @@ import router from './router'
import store from '@/store' import store from '@/store'
import modules from './modules' import modules from './modules'
import beforeEnter from '@/utils/beforeEnter' import beforeEnter from '@/utils/beforeEnter'
import useWXShare from '@/utils/wx'
// 公共css // 公共css
import '@/assets/css/base.css' import '@/assets/css/base.css'
...@@ -30,6 +31,8 @@ router.beforeEach(beforeEnter) ...@@ -30,6 +31,8 @@ router.beforeEach(beforeEnter)
// return originalPush.call(this, location).catch(err => err) // return originalPush.call(this, location).catch(err => err)
// } // }
useWXShare()
new Vue({ new Vue({
store, store,
router, router,
......
...@@ -2,7 +2,7 @@ import axios from 'axios' ...@@ -2,7 +2,7 @@ import axios from 'axios'
// import queryString from 'query-string' // import queryString from 'query-string'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import router from '../router' import router from '../router'
import store from '../store' // import store from '../store'
import qs from 'qs' import qs from 'qs'
const httpRequest = axios.create({ const httpRequest = axios.create({
...@@ -14,21 +14,6 @@ const httpRequest = axios.create({ ...@@ -14,21 +14,6 @@ const httpRequest = axios.create({
// 请求拦截 // 请求拦截
httpRequest.interceptors.request.use( httpRequest.interceptors.request.use(
function (config) { function (config) {
// 设置项目
config.headers.tenant = store.state.activeProject?.tag
config.params = Object.assign({ project_prefix: store.state.activeProject?.tag }, config.params)
config.data = Object.assign({ project_prefix: store.state.activeProject?.tag }, config.data)
// 默认参数
const defaultHeaders = {
timestamp: parseInt(Date.now() / 1000),
nonce: Math.random().toString(36).slice(-8),
'secret-id': 'ezijing_20200410',
'secret-key': 'THIxz9hfbMDD5pil',
signature: 'UG7wBenexQhiuD2wpCwuxkU0jqcj006d'
}
config.headers = Object.assign(config.headers, defaultHeaders)
if (config.headers['Content-Type'] === 'application/x-www-form-urlencoded') { if (config.headers['Content-Type'] === 'application/x-www-form-urlencoded') {
config.data = qs.stringify(config.data) config.data = qs.stringify(config.data)
} }
......
import httpRequest from './axios'
export default function useWXShare() {
httpRequest
.post('https://node-server.ezijing.com/share/getsignature', {
appId: 'wxa41d0081d4889921',
url: location.href.split('#').pop()
})
.then(result => {
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wxa41d0081d4889921', // 必填,公众号的唯一标识
timestamp: result.timestamp, // 必填,生成签名的时间戳
nonceStr: result.noncestr, // 必填,生成签名的随机串
signature: result.token, // 必填,签名
jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] // 必填,需要使用的JS接口列表
})
wx.ready(() => {
wx.updateAppMessageShareData({
title: '中国公路建设行业协会', // 分享标题
desc: '中国公路建设行业协会', // 分享描述
link: location.href,
imgUrl: 'https://webapp-pub.ezijing.com/highway/h5/banner-0420.png'
})
wx.updateTimelineShareData({
title: '中国公路建设行业协会', // 分享标题
link: location.href,
imgUrl: 'https://webapp-pub.ezijing.com/highway/h5/banner-0420.png'
})
})
})
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论