tool.js页面
import {
login,
weixinshare
} from './goods'
import store from '../../store/index'
export default {
tologins(codes) {
// window.localStorage.setItem('phone', this.logindata.phone);
// alert('345'+JSON.stringify(this.logindata))
login({
code: codes
}).then(res => {
if (res.code == 200) {
// this.userid = res.result.id
window.sessionStorage.setItem('id', JSON.stringify(res.result.id))
window.sessionStorage.setItem('state', JSON.stringify(true))
window.sessionStorage.setItem('token', res.result.token)
window.sessionStorage.setItem('userName', res.result.username)
window.localStorage.setItem('userName', res.result.username)
window.localStorage.setItem('id', JSON.stringify(res.result.id))
window.localStorage.setItem('state', JSON.stringify(true))
window.localStorage.setItem('gateId_self', res.result.gateId)
store.commit('setloginshow', false)
if (!res.result.openidgzh) {
// 此处是二次公众号授权接口。二Openid入库。需要提交本次的unionid。
}
// next()
// this.initWebpack();
// this.reload();
// this.$toast('欢迎来到值悦商城')
// if($route.path=='/login')
// this.$router.push('/index');
} else {
// netxt()
// this.$toast(res.message)
console.log("啧啧:",res)
}
}).catch(
(err)=>{
console.log("报错啦,想啥呢:",err);
}
)
},
// 获取code
getcodes(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
//alert(window.location.search.substr(1))
var r = window.location.search.substr(1).match(reg)
if (r != null) {
return unescape(r[2])
}
return null
},
getcodes2(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
var r = window.location.href.substr(1).match(reg)
if (r != null) {
return unescape(r[2])
}
return null
},
iszfb()
{
if (/AlipayClient/.test(window.navigator.userAgent)) {
// alert('支付宝客户端');
// window.location.href = "Payment.html";
return true;
}
else
return false;
},
// 判断是否为微信浏览器
typed() {
var ua = window.navigator.userAgent.toLowerCase()
// mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
return true
} else {
return false
}
},
// // 微信浏览器自动登录
// tologin() {
// login(this.logindata).then(res => {
// if (res.code == 200) {
// this.userid = res.result.id;
// window.sessionStorage.setItem('id', this.userid);
// window.sessionStorage.setItem('token', res.result.token);
// window.localStorage.setItem('id', this.userid);
// window.localStorage.setItem('token', res.result.token);
// this.initWebpack();
// this.reload();
// this.$toast('欢迎来到值悦商城');
// } else {
// this.$toast(res.message);
// }
// });
// },
// 获取code
togetpower() {
// var domain = this.$store.state.domain
var redirecturl = window.location.href
window.location.href =
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0c81f7d38006a1e4&redirect_uri=' +
encodeURIComponent(redirecturl) +
'&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect'
},
togetpowerzfb() {
// var domain = this.$store.state.domain
//var redirecturl = "http://test.sodataint.com"
var redirecturl = window.location.href
window.location.href =
'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2017122000998941&scope=auth_base&state=STATE&redirect_uri=' +
encodeURIComponent(redirecturl)
},
togetpoweroftz() {
// var domain = this.$store.state.domain
var redirecturl = window.location.href
// if (this.$route.path == '/')
// redirecturl = domain + '/#/index'
if (this.$route.query != {}) {
window.location.href =
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0c81f7d38006a1e4&redirect_uri=' +
encodeURIComponent(redirecturl) +
'&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect'
} else {
window.location.href =
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0c81f7d38006a1e4&redirect_uri=' +
encodeURIComponent(redirecturl) +
'?response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect'
}
},
getcode(name) {
// alert(window.location.href)
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
var r = window.location.search.substr(1).match(reg)
if (r != null) {
return unescape(r[2])
}
return null
},
// 微信自动登录逻辑
autologin() {
if (!window.sessionStorage.getItem('token')) {
// alert('code:'+this.getcode('code'))
if (this.getcodes('code')) {
// this.logindata.code = this.getcodes('code')
this.tologins(this.getcodes('code'))
} else {
this.togetpower()
}
}
},
navtype(){
var typ='';
var u = navigator.userAgent;
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
typ='a';
} else if (u.indexOf('iPhone') > -1) {//苹果手机
typ='i';
} else if (u.indexOf('Windows Phone') > -1) {//winphone手机
typ='w';
}
return typ;
},
// 全局注册分享函数
wxShare(title, desc, link, imgUrl) {
// 获取签名
var signurl=location.href;
if(this.navtype()=='i')
{
signurl=sessionStorage.getItem("initLink");
}
console.log("now signurl:"+signurl)
weixinshare({
itemid: 19890724,
token: window.sessionStorage.getItem("token"),
jsapi_ticket_url: signurl
// appname:'XINYI'
}).then((res) => {
if (res.code === 200) {
wx.config({
debug: false,
appId: res.result.appId, // 必填,公众号的唯一标识
timestamp: res.result.timeStamp, // 必填,生成签名的时间戳
nonceStr: res.result.nonceStr, // 必填,生成签名的随机串
signature: res.result.signature, // 必填,签名,见附录1
jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
} else if (res.code === CODE_ERR) {
console.log("获取accessToken失败");
}
}).catch((res) => {
console.log(res)
window.alert('网络异常,登录请求失败');
});
wx.ready(function () {
var copy_content = window.location.href;
//store.state.domain+"/#/";
var title='有没有一款专属手机壳,不辜负你的热爱? 千名艺术设计师同堂竞技'
var desc='馨艺“热情萌物”手机壳艺术大赛,千名艺术设计师正版灵感,邀请你来评选心中最萌手机壳!'
wx.onMenuShareAppMessage({
title: title, // 分享标题
desc: desc, // 分享描述
link: copy_content, // 分享链接
imgUrl: "http://tests.sodataint.com/image/default/0EFC5AE1665345708F38CB62B2B42D56-6-2.png", // 分享图标
type: "", // 分享类型,music、video或link,不填默认为link
dataUrl: "", // 如果type是music或video,则要提供数据链接,默认为空
success: function() {
// _this.state.showShare2 = false;
},
cancel: function() {
// _this.state.showShare2 = false;
},
fail: function() {
// alert("cuowu");
}
});
wx.onMenuShareTimeline({
title:title, // 分享标题
desc: desc, // 分享描述
link: copy_content, // 分享链接
imgUrl: "http://tests.sodataint.com/image/default/0EFC5AE1665345708F38CB62B2B42D56-6-2.png", // 分享图标
type: "", // 分享类型,music、video或link,不填默认为link
dataUrl: "", // 如果type是music或video,则要提供数据链接,默认为空
success: function() {
// _this.state.showShare2 = false;
},
cancel: function() {
// _this.state.showShare2 = false;
},
fail: function() {
// alert("cuowu");
}
});
});
}
}
goods.js页面
import http from './base'
// 用户登录
const login = (params) => {
return http.dataPost('/api/member/login', params)
}
// app用户登录
const applogin = (params) => {
return http.dataPost('/api/member/applogin', params)
}
// 验证码发送接口
const code = (params) => {
return http.dataPost('/api/member/validate', params)
}
// 获取上传token
const gettoken = (params) => {
return http.dataGet('/api/getvideotoken', params)
}
export {
gettoken,
applogin,
login,
code,
}
index.js
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
login1show: false,
login2show: false,
signshow: false,
islist: false,
playvideo: -1,
toapplogin: false,
to_app_login: false,
downtag: true,
domain: 'http://activity.sodataint.com',
appid: 'wx0c81f7d38006a1e4',
isLoading: false,
direction: '',
gzhurl:'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg3MjAxMjMxNQ==#wechat_redirect',
// tabbar的状态管理
selected:0,
// vip状态管理
vipJurisdiction:false
},
mutations: mutations
})