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

默认首页

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