Commit c9dd295e authored by 小耗子's avatar 小耗子

默认首页

parent b7959b9a
<template> <template>
<view class="screen-container"> <view class="screen-container">
<image class="bg" src="../../static/img/screen/screen-bg.png" mode="scaleToFill"/> <image class="bg" src="../../static/img/screen/screen-bg.png" mode="scaleToFill" />
<button v-if="unregistered" @click="changeTabBar" class="btn" > <button v-if="unregistered" @click="changeTabBar" class="btn">
马上进入 马上进入
</button> </button>
<button v-else class="btn" open-type="getPhoneNumber" @getphonenumber="getInfoPhoneNumber"> <button v-else class="btn" open-type="getPhoneNumber" @getphonenumber="getInfoPhoneNumber">
授权绑定 授权绑定
</button> </button>
</view> </view>
...@@ -19,48 +19,115 @@ ...@@ -19,48 +19,115 @@
export default { export default {
data() { data() {
return { return {
unregistered:false unregistered: false
} }
}, },
computed: { computed: {
...mapGetters(['userInfo','todayNum']) ...mapGetters(['userInfo', 'todayNum'])
}, },
methods: { methods: {
...mapActions(['getPhoneNumber','registerInfoFn','getWeRunDataFn','authCheck','getUserInfo']), ...mapActions(['getPhoneNumber', 'registerInfoFn', 'getWeRunDataFn', 'authCheck', 'getUserInfo']),
// 切换底部tab; // 切换底部tab;
changeTabBar(){ changeTabBar() {
if(this.unregistered){ if (this.unregistered) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/h5/index', url: '/pages/h5/index',
}) })
} }
}, },
// 获取手机号 // 获取手机号
async getInfoPhoneNumber (e) { async getInfoPhoneNumber(e) {
let number = await this.getPhoneNumber(e); let number = await this.getPhoneNumber(e);
let register = await this.registerInfoFn(); let register = await this.registerInfoFn();
if(register){ //注册成功 if (register) { //注册成功
this.unregistered = true; this.unregistered = true;
} }
}, },
async getAuth(){ async authAndWeRun() {
let auth = await this.authCheck();
if (auth == 0) {
this.unregistered = true;
} else if (auth == 2001) {
this.getUserInfo();
this.unregistered = false;
}
},
async loginSession() {
let token = uni.getStorageSync('token'); let token = uni.getStorageSync('token');
// 如果有缓存信息 let that = this;
if (token) { /**
let auth = await this.authCheck(); * session有效{
if(auth == 0) { 用户注册:token有/无/失效 homepaeg- authcheck(2001)- code-wxRun
this.unregistered = true; 用户未注册:token有/无 authcheck(1001)-homepage-code-手机号-注册-wxRun(点击授权登录)
}
}else if(auth == 2001){ * session无效{
this.unregistered = false; 用户注册:token有/无/失效 login-更新session -homepage -authcheck - wxrun
} 用户未注册:token无/失效 login-更新session -homepage -authcheck (点击授权登录)
} else { }
let getUserInfo = await this.getUserInfo();
* *
*/
if (this.checkSessionStatus && token) {
let token = uni.getStorageSync('token');
this.authAndWeRun();
} else {
// session 不存在,调用login。userInfo 。更新session
uni.login({
success: function(info) { //调用code
console.log("code000000000000000000000000==========", info.code)
that.$store.commit('wxCode', info.code); //按钮切换全选。
let userInfo = that.getUserInfo();
userInfo.then(res => {
that.authCheck().then(checkCode => {
if (checkCode == 0) {
that.unregistered = true;
}else if(checkCode == 2001) {
that.unregistered = false;
}
})
})
}
})
} }
},
async getAuth() {
let that = this;
uni.checkSession({ //校验session
success(res) { //有效
console.log("有效session")
if (res.errMsg === "checkSession:ok") {
that.checkSessionStatus = true;
// 如果有缓存信息
that.loginSession()
}
},
fail(err) { //无效
console.log("无效session")
that.checkSessionStatus = false;
that.loginSession()
}
})
} }
// async getAuth(){
// let token = uni.getStorageSync('token');
// // 如果有缓存信息
// if (token) {
// let auth = await this.authCheck();
// if(auth == 0) {
// this.unregistered = true;
// }else if(auth == 2001){
// this.unregistered = false;
// }
// } else {
// let getUserInfo = await this.getUserInfo();
// }
// }
}, },
onHide(){ onHide() {},
},
onShow() { onShow() {
// uni.hideTabBar(); // uni.hideTabBar();
}, },
...@@ -71,29 +138,31 @@ ...@@ -71,29 +138,31 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.screen-container{ .screen-container {
// position: fixed; // position: fixed;
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 100%; height: 100%;
top:0; top: 0;
left: 0; left: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
.bg{
.bg {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.btn{
.btn {
position: absolute; position: absolute;
transform: translateX(-50%); transform: translateX(-50%);
left:50%; left: 50%;
bottom: 100rpx; bottom: 100rpx;
width: 640rpx; width: 640rpx;
height: 100rpx; height: 100rpx;
line-height: 100rpx; line-height: 100rpx;
background-color: #fff; background-color: #fff;
color:red; color: red;
border-radius: 30rpx; border-radius: 30rpx;
font-size: 50rpx; font-size: 50rpx;
font-weight: 400; font-weight: 400;
...@@ -101,5 +170,4 @@ ...@@ -101,5 +170,4 @@
box-shadow: 0 10px 15px 0 rgba(255, 255, 255, 0.2); box-shadow: 0 10px 15px 0 rgba(255, 255, 255, 0.2);
} }
} }
</style> </style>
...@@ -11,64 +11,50 @@ const state = { ...@@ -11,64 +11,50 @@ const state = {
empcardno: '', //封闭式传 empcardno: '', //封闭式传
registerType: 'register' //注册时的类型为普通注册 registerType: 'register' //注册时的类型为普通注册
}, },
wxCode:'',
// weRunData:{//今日步数 // weRunData:{//今日步数
// todayNum: 0, // todayNum: 0,
// totalNum: 0, // totalNum: 0,
// updateDate: "", // updateDate: "",
// yesterdayNum: 0 // yesterdayNum: 0
// }, // },
todayNum:0 todayNum:0,
sessionStatus:false
} }
const getters = { const getters = {
token: state => state.token, token: state => state.token,
userInfo: state => state.userInfo, userInfo: state => state.userInfo,
todayNum: state => state.todayNum todayNum: state => state.todayNum,
wxCode: state=> state.wxCode,
sessionStatus: state=> state.sessionStatus
} }
const actions = { const actions = {
/***获取用户信息 /***获取用户信息
无token 走获取用户信息接口。 无token 走获取用户信息接口。
有token 走校验authcheck信息 有token 走校验authcheck信息
*/ */
async getUserInfo({ async getUserInfo({
dispatch, dispatch,
commit, commit,
state state
}, code) { }, code) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let sessionStatus = false; let mallId = '106975910000477'
uni.checkSession({ //校验session uni.setStorageSync("mallId", mallId)
success(res) { let code = state.wxCode;
if (res.errMsg === "checkSession:ok") sessionStatus = true; http('user.getHomePage', {
code: code,
}, mallId: mallId
complete() { }).then(res => {
let mallId = '106975910000477'; if (!res.code) {
uni.setStorageSync("mallId", mallId) let { sessionKey } = res.data;
if (uni.getStorageSync("sessionKey") && sessionStatus) { uni.setStorageSync("sessionKey", sessionKey)
resolve(uni.getStorageSync("sessionKey")); commit('userInfo', res.data);
} else { let token = encodeURI(JSON.stringify(res.data))
uni.login({ uni.setStorageSync("token", token)
success: function(info) { resolve(1);
let code = info.code;
http('user.getHomePage', {
code: code,
mallId: mallId
}).then(res => {
if (!res.code) {
let { sessionkey } = res.data
uni.setStorageSync("sessionKey", sessionkey)
commit('userInfo', res.data);
let token = encodeURI(JSON.stringify(res.data))
uni.setStorageSync("token", token)
dispatch('authCheck')
resolve(res)
}
})
}
})
}
} }
}) })
}) })
...@@ -93,7 +79,6 @@ const actions = { ...@@ -93,7 +79,6 @@ const actions = {
if (res.code === 0) { if (res.code === 0) {
resolve(res.code) resolve(res.code)
} else if (res.code == 1001) { } else if (res.code == 1001) {
dispatch('getUserInfo');
reject(res.code) reject(res.code)
} else { } else {
reject(res.code) reject(res.code)
...@@ -156,10 +141,10 @@ const actions = { ...@@ -156,10 +141,10 @@ const actions = {
getWeRunDataFn({state}){ getWeRunDataFn({state}){
return new Promise((resolve,reject) => { return new Promise((resolve,reject) => {
let wRunEncryptedData = {} let wRunEncryptedData = {}
uni.getWeRunData({ wx.getWeRunData({
success: function(res) { success: function(res) {
wRunEncryptedData.encryptedData = res.encryptedData; wRunEncryptedData.encryptedData = encodeURIComponent(res.encryptedData);
wRunEncryptedData.iv = res.iv; wRunEncryptedData.iv = encodeURIComponent(res.iv);
http('user.wxRun', wRunEncryptedData).then(res => { http('user.wxRun', wRunEncryptedData).then(res => {
if (!res.code && res.data) { if (!res.code && res.data) {
state.todayNum = res.data.todayNum; state.todayNum = res.data.todayNum;
...@@ -174,7 +159,16 @@ const actions = { ...@@ -174,7 +159,16 @@ const actions = {
reject(res.data); reject(res.data);
} }
}) })
},
fail:function(err){
console.log(err)
uni.showToast({
title: "您未开通微信运动,请关注微信运动公众号后重试",
duration: 2000,
icon:'none'
});
} }
}) })
}) })
} }
...@@ -185,8 +179,10 @@ const mutations = { ...@@ -185,8 +179,10 @@ const mutations = {
token(state, payload) { token(state, payload) {
state.token = payload; state.token = payload;
uni.setStorageSync("token", payload); uni.setStorageSync("token", payload);
},
wxCode(state,code) {
state.wxCode = code;
} }
} }
export default { export default {
state, state,
......
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 to comment