Commit c4c77657 by mamingqun

添加分享

parent 103970e5
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> <link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>testnihao</title> <title>testnihao</title>
<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
</head> </head>
<body> <body>
<noscript> <noscript>
......
...@@ -7,19 +7,27 @@ ...@@ -7,19 +7,27 @@
<router-link to="/loading">loading</router-link>| <router-link to="/loading">loading</router-link>|
<router-link to="/user">user</router-link> <router-link to="/user">user</router-link>
</div> </div>
<keep-alive>
<router-view /> <router-view />
</keep-alive>
</div> </div>
</template> </template>
<script> <script>
import config from '@/config/config.js' import config from '@/config/config.js'
import { requestWxInit } from "@/utils/wxShare"
export default { export default {
mounted() { mounted() {
console.log('NODE_ENV')
console.log(process.env.NODE_ENV)
console.log('VUE_APP_BUILD_TYPE')
console.log(process.env.VUE_APP_BUILD_TYPE)
console.log('config') console.log('config')
console.log(config) console.log(config)
console.log('accessToken'); console.log('accessToken')
console.log(localStorage.getItem('accessToken')) console.log(localStorage.getItem('accessToken'))
requestWxInit('测试标题', '描述啊描述', config.shareIcon, config.shareLink)
} }
} }
</script> </script>
......
...@@ -2,7 +2,7 @@ import Vue from 'vue' ...@@ -2,7 +2,7 @@ import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import store from './store' import store from './store'
import './utils/request' import './utils/axiosConfig'
import wxAuth from './utils/wxAuth' import wxAuth from './utils/wxAuth'
import config from './config/config'; import config from './config/config';
...@@ -21,13 +21,13 @@ window.$ = jquery ...@@ -21,13 +21,13 @@ window.$ = jquery
import axios from 'axios' import axios from 'axios'
window.$axios = axios window.$axios = axios
// 微信授权 // 微信授权
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development' && !process.env.VUE_APP_BUILD_TYPE) {
// 调试开发,替换这里token // 调试开发,替换这里token
let testToken = 'OJBwh2ZvViYyQ1phNZEghwf9D8dyAImCD5twnjl0' let testToken = 'OJBwh2ZvViYyQ1phNZEghwf9D8dyAImCD5twnjl0'
axios.defaults.headers.common['sysType'] = config.sysType axios.defaults.headers.common['sysType'] = config.sysType
axios.defaults.headers.common['accessToken'] = testToken axios.defaults.headers.common['accessToken'] = testToken
localStorage.setItem('accessToken', testToken) localStorage.setItem('accessToken', testToken)
}else{ } else {
wxAuth.initWX() wxAuth.initWX()
} }
......
import axios from 'axios' import axios from 'axios'
import wxAuth from './wxAuth' import wxAuth from './wxAuth'
import config from '@/config/config.js' import configCommon from '@/config/config.js'
var wxinfoApi = config.BASEURL + '/weixin/info' var wxinfoApi = configCommon.BASEURL + '/weixin/info'
// import { getToken } from '@/utils/auth'
// 创建axios实例 // 创建axios实例
// const service = axios.create({ // const service = axios.create({
// // baseURL: process.env.BASE_API, // api的base_url // // baseURL: process.env.BASE_API, // api的base_url
// timeout: 10000 // 请求超时时间 // timeout: 10000 // 请求超时时间
// }) // })
// console.log(service)
axios.defaults.baseURL = configCommon.BASEURL
// request拦截器 // request拦截器
axios.interceptors.request.use( axios.interceptors.request.use(
config => { config => {
// Do something before request is sent // Do something before request is sent
// console.log(config.url, store.state.token, 'accessToken')
if (localStorage.getItem('accessToken')) { if (localStorage.getItem('accessToken')) {
config.headers['accessToken'] = localStorage.getItem('accessToken') // 让每个请求携带token--['ticket']为自定义key 请根据实际情况自行修改 config.headers['accessToken'] = localStorage.getItem('accessToken') // 让每个请求携带token--['ticket']为自定义key 请根据实际情况自行修改
config.headers['sysType'] = configCommon.sysType
} }
// if (store.state.type) {
// config.headers['type'] = store.state.type // 让每个请求携带token--['ticket']为自定义key 请根据实际情况自行修改
// }
if (!config.headers['Content-Type']) { if (!config.headers['Content-Type']) {
if (config.url != '/upload') { if (config.url != '/upload') {
config.headers['Content-Type'] = 'application/json' config.headers['Content-Type'] = 'application/json'
} }
} }
// config.headers['Content-Type'] = 'application/json'
// config.headers['platform'] = 'front'
return config return config
}, },
error => { error => {
// Do something with request error // Do something with request error
// eslint-disable-next-line no-console
console.log(error) // for debug console.log(error) // for debug
Promise.reject(error) Promise.reject(error)
} }
...@@ -55,7 +54,7 @@ axios.interceptors.response.use( ...@@ -55,7 +54,7 @@ axios.interceptors.response.use(
// }) // })
if (response.data.code == 100100 || response.data.code == 100101) { if (response.data.code == 100100 || response.data.code == 100101) {
// store.dispatch('getAuth') // store.dispatch('getAuth')
wxAuth.init(config.sysType, wxinfoApi) wxAuth.init(configCommon.sysType, wxinfoApi)
} }
return Promise.reject(new Error({ return Promise.reject(new Error({
response response
...@@ -70,7 +69,7 @@ axios.interceptors.response.use( ...@@ -70,7 +69,7 @@ axios.interceptors.response.use(
err => { err => {
if (err && err.response) { if (err && err.response) {
if (err.response.data.code == 100100 || err.response.data.code == 100101) { if (err.response.data.code == 100100 || err.response.data.code == 100101) {
wxAuth.init(config.sysType, wxinfoApi) wxAuth.init(configCommon.sysType, wxinfoApi)
} }
switch (err.response.status) { switch (err.response.status) {
case 400: case 400:
...@@ -129,7 +128,8 @@ axios.interceptors.response.use( ...@@ -129,7 +128,8 @@ axios.interceptors.response.use(
// }) // })
// Toast.fail(err.message) // Toast.fail(err.message)
console.log('❎❎', err.message) // eslint-disable-next-line no-console
console.log('❎❎', err)
return Promise.reject(err) return Promise.reject(err)
} }
) )
\ No newline at end of file
...@@ -86,7 +86,7 @@ function getAccessTokenByCode(sysType, getAccessTokenByCodeApi, getwxinfoApi) { ...@@ -86,7 +86,7 @@ function getAccessTokenByCode(sysType, getAccessTokenByCodeApi, getwxinfoApi) {
success: function (data) { success: function (data) {
res = data res = data
}, },
error: function (data) { error: function () {
init(config.sysType, getwxinfoApi) init(config.sysType, getwxinfoApi)
} }
}) })
......
import axios from 'axios'
export const requestWxInit = (title, desc, imgUrl, link) => {
let url = window.encodeURIComponent(window.location.href.split("#")[0]);
axios
.post('/wechat/info', {
url: url,
type: '2'
}).then(res => {
let respoens = res.data.data;
// console.log('http的微信信息的res');
// console.log(res);
window.wx.config({
debug: false,
appId: respoens.appId,
timestamp: respoens.timestamp,
nonceStr: respoens.nonceStr,
signature: respoens.signature,
jsApiList: [
"chooseImage",
"uploadImage",
"getLocalImgData",
"downloadImage",
"onMenuShareTimeline",
"onMenuShareAppMessage"
]
});
window.wx.ready(function () {
// 获取“分享到朋友圈”按钮点击状态及自定义分享内容接口(即将废弃)
var data1 = {
title: title, // 分享标题(原标题为:直通2019篮球世界杯•万达牵手小球童全国招募,20190626更改)
// link: api.wrapHref, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
link: link,
imgUrl: imgUrl, // 分享图标
success: function () {}
}
// window.wx.onMenuShareTimeline(tar.shapeShareTimeline(data1));
window.wx.onMenuShareTimeline(data1);
// 获取“分享给朋友”按钮点击状态及自定义分享内容接口(即将废弃)
var data2 = {
title: title, // 分享标题
desc: desc, // 分享描述
// link: api.wrapHref, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
link: link,
imgUrl: imgUrl, // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户点击了分享后执行的回调函数
}
}
// window.wx.onMenuShareAppMessage(tar.shapeShareAppMessage(data2));
window.wx.onMenuShareAppMessage(data2);
})
window.wx.error(() => {
// eslint-disable-next-line no-console
console.log('error')
})
window.wx.checkJsApi({
jsApiList: ['onMenuShareTimeline', "onMenuShareAppMessage"], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function (res) {
// eslint-disable-next-line no-console
console.log(res);
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
});
// console.log('respones', respoens)
})
}
\ No newline at end of file
...@@ -21,7 +21,7 @@ export default { ...@@ -21,7 +21,7 @@ export default {
mounted() { mounted() {
this.msg = process.env.NODE_ENV this.msg = process.env.NODE_ENV
console.log(process.env.NODE_ENV)
}, },
methods: { methods: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment