13 changed files with 509 additions and 382 deletions
@ -1,52 +0,0 @@ |
|||||||
// import router from "../router";
|
|
||||||
import store from "../store"; |
|
||||||
import cookie from "@/utils/store/cookie"; |
|
||||||
import { |
|
||||||
isWeixin, |
|
||||||
login, |
|
||||||
replaceLogin, |
|
||||||
getCurrentPageUrl, |
|
||||||
getCurrentPageUrlWithArgs, |
|
||||||
parseQuery, |
|
||||||
replace, |
|
||||||
handleQrCode |
|
||||||
} from "@/utils"; |
|
||||||
|
|
||||||
export default function toLogin(push, backUrl) { |
|
||||||
console.log('token失效,需要重新登录') |
|
||||||
store.commit("LOGOUT"); |
|
||||||
// 如果没有授权,走登录的接口重新授权
|
|
||||||
// 授权获取失败会跳转到授权的接口
|
|
||||||
console.log(store.getters.isAuthorization, '是否有登陆权限') |
|
||||||
if (store.getters.isAuthorization) { |
|
||||||
login() |
|
||||||
return |
|
||||||
} |
|
||||||
console.log(store.getters.isAuthorizationPage, '判断是不是登录页面或者授权页面') |
|
||||||
// 判断当前是不是已经在登录页面或者授权页,防止二次跳转
|
|
||||||
if (store.getters.isAuthorizationPage || getCurrentPageUrl() == '/pages/user/Login/index') { |
|
||||||
console.log('已经是登录页面或者授权页面,跳出方法') |
|
||||||
return |
|
||||||
} |
|
||||||
|
|
||||||
// 判断是不是扫描的砍价海报进来的
|
|
||||||
if (getCurrentPageUrl() == 'pages/activity/DargainDetails/index' && handleQrCode()) { |
|
||||||
console.log('是扫描的砍价海报进来的') |
|
||||||
let url = handleQrCode(); |
|
||||||
if (url) { |
|
||||||
replaceLogin({ |
|
||||||
redirect: `/${getCurrentPageUrl()}`, |
|
||||||
id: url.bargainId, |
|
||||||
partake: url.uid |
|
||||||
}) |
|
||||||
} else { |
|
||||||
console.log('是扫描的砍价海报进来的,但是没有获取到参数') |
|
||||||
replaceLogin() |
|
||||||
} |
|
||||||
} else { |
|
||||||
console.log('无特殊情况,重新登录') |
|
||||||
replaceLogin() |
|
||||||
} |
|
||||||
store.commit("UPDATE_AUTHORIZATION", false); |
|
||||||
store.commit("UPDATE_AUTHORIZATIONPAGE", true); |
|
||||||
} |
|
@ -1,211 +1,255 @@ |
|||||||
<template> |
<template> |
||||||
<view class="container"> |
<view class="container"> |
||||||
<view v-if="!token"> |
<view v-if="!token"> |
||||||
<!-- 小程序 --> |
<!-- 小程序 --> |
||||||
<view v-if="$deviceType == 'routine'"> |
<view v-if="$deviceType == 'routine'&&authorize"> |
||||||
<view class="getUserInfo"> |
<view class="getUserInfo"> |
||||||
<text>您还未允许微信登录授权,请点击下方按钮允许微信授权登录。</text> |
<text>您还未允许微信登录授权,请点击下方按钮允许微信授权登录。</text> |
||||||
<button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">允许微信登录授权</button> |
<button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">允许微信登录授权</button> |
||||||
<view style="height:20rpx"></view> |
<view style="height:20rpx"></view> |
||||||
<button @click="back">取消微信登录授权</button> |
<button @click="back">取消微信登录授权</button> |
||||||
</view> |
</view> |
||||||
</view> |
</view> |
||||||
<!-- app --> |
<!-- app --> |
||||||
<view v-if="$deviceType == 'app'"> |
<view v-if="$deviceType == 'app'&&authorize"> |
||||||
<view class="getUserInfo"> |
<view class="getUserInfo"> |
||||||
<text>请先登录</text> |
<text>请先登录</text> |
||||||
<button type="primary" @click="this.toLogin">去登录</button> |
<button type="primary" @click="this.toLogin">去登录</button> |
||||||
</view> |
</view> |
||||||
</view> |
</view> |
||||||
</view> |
<view v-if="!authorize"> |
||||||
</view> |
<view class="getUserInfo"> |
||||||
|
<text>登录中</text> |
||||||
|
</view> |
||||||
|
</view> |
||||||
|
</view> |
||||||
|
</view> |
||||||
</template> |
</template> |
||||||
|
|
||||||
<script> |
<script> |
||||||
import { mapState, mapMutations, mapActions } from 'vuex'; |
import { mapState, mapMutations, mapActions } from "vuex"; |
||||||
// 组件 |
// 组件 |
||||||
// import request from "@//api/request"; |
// import request from "@//api/request"; |
||||||
import { wxappAuth, getUser } from '@/api/user'; |
import { wxappAuth, getUser } from "@/api/user"; |
||||||
import dayjs from 'dayjs'; |
import dayjs from "dayjs"; |
||||||
import cookie from '@/utils/store/cookie'; |
import cookie from "@/utils/store/cookie"; |
||||||
import { login } from '@/utils'; |
import { login, authorize } from "@/utils"; |
||||||
|
|
||||||
export default { |
export default { |
||||||
data() { |
data() { |
||||||
return { |
return { |
||||||
}; |
authorize: false |
||||||
}, |
}; |
||||||
computed: { |
}, |
||||||
...mapState(['isAuthorization','$deviceType','token']) |
computed: { |
||||||
}, |
...mapState(["isAuthorization", "$deviceType", "token"]) |
||||||
onShow() { |
}, |
||||||
this.UPDATE_AUTHORIZATIONPAGE(true); |
onShow() { |
||||||
}, |
this.UPDATE_AUTHORIZATIONPAGE(true); |
||||||
onHide() { |
// // 先校验用户是否授权,如果没有授权,显示授权按钮 |
||||||
this.UPDATE_AUTHORIZATIONPAGE(false); |
console.log("先校验用户是否授权,如果没有授权,显示授权按钮"); |
||||||
this.changeAuthorization(false); |
authorize("userInfo") |
||||||
}, |
.then(res => { |
||||||
onUnload() { |
console.log(res); |
||||||
this.UPDATE_AUTHORIZATIONPAGE(false); |
}) |
||||||
this.changeAuthorization(false); |
.catch(error => { |
||||||
}, |
console.log(error); |
||||||
methods: { |
// 用户未授权,显示授权按钮 |
||||||
...mapActions(['changeAuthorization', 'setUserInfo']), |
this.authorize = true; |
||||||
...mapMutations(['UPDATE_AUTHORIZATIONPAGE', 'CHANGE_TABTAR']), |
}); |
||||||
back() { |
}, |
||||||
this.$yrouter.switchTab({ |
onHide() { |
||||||
path: '/pages/home/index', |
console.log("离开授权页面,11111"); |
||||||
query: {} |
this.UPDATE_AUTHORIZATIONPAGE(false); |
||||||
}); |
this.changeAuthorization(false); |
||||||
}, |
}, |
||||||
getUserInfo(data) { |
onUnload() { |
||||||
if (data.detail.errMsg == 'getUserInfo:fail auth deny') { |
console.log("离开授权页面,11111"); |
||||||
uni.showToast({ |
this.UPDATE_AUTHORIZATIONPAGE(false); |
||||||
title: '取消授权', |
this.changeAuthorization(false); |
||||||
icon: 'none', |
}, |
||||||
duration: 2000 |
methods: { |
||||||
}); |
...mapActions(["changeAuthorization", "setUserInfo"]), |
||||||
return; |
...mapMutations(["UPDATE_AUTHORIZATIONPAGE", "CHANGE_TABTAR"]), |
||||||
} |
back() { |
||||||
uni.showLoading({ |
this.$yrouter.switchTab({ |
||||||
title: '登录中' |
path: "/pages/home/index", |
||||||
}); |
query: {} |
||||||
login({ |
}); |
||||||
success: () => {} |
}, |
||||||
}); |
getUserInfo(data) { |
||||||
}, |
if (data.detail.errMsg == "getUserInfo:fail auth deny") { |
||||||
toLogin() { |
uni.showToast({ |
||||||
this.$yrouter.push({ |
title: "取消授权", |
||||||
path: '/pages/user/Login/index', |
icon: "none", |
||||||
query: {} |
duration: 2000 |
||||||
}); |
}); |
||||||
} |
return; |
||||||
}, |
} |
||||||
onUnload() {}, |
uni.showLoading({ |
||||||
mounted() { |
title: "登录中" |
||||||
} |
}); |
||||||
|
login() |
||||||
|
.then(res => { |
||||||
|
this.$yrouter.replace({ path: cookie.get("redirect") }); |
||||||
|
}) |
||||||
|
.catch(error => { |
||||||
|
console.log(error); |
||||||
|
uni.showToast({ |
||||||
|
title: error, |
||||||
|
icon: "none", |
||||||
|
duration: 2000 |
||||||
|
}); |
||||||
|
}); |
||||||
|
}, |
||||||
|
toLogin() { |
||||||
|
this.$yrouter.push({ |
||||||
|
path: "/pages/user/Login/index", |
||||||
|
query: {} |
||||||
|
}); |
||||||
|
} |
||||||
|
}, |
||||||
|
onUnload() { |
||||||
|
console.log("离开授权页面,11111"); |
||||||
|
this.UPDATE_AUTHORIZATIONPAGE(false); |
||||||
|
this.changeAuthorization(false); |
||||||
|
}, |
||||||
|
mounted() { |
||||||
|
this.UPDATE_AUTHORIZATIONPAGE(true); |
||||||
|
// // 先校验用户是否授权,如果没有授权,显示授权按钮 |
||||||
|
console.log("先校验用户是否授权,如果没有授权,显示授权按钮"); |
||||||
|
authorize("userInfo") |
||||||
|
.then(res => { |
||||||
|
console.log(res); |
||||||
|
}) |
||||||
|
.catch(error => { |
||||||
|
console.log(error); |
||||||
|
// 用户未授权,显示授权按钮 |
||||||
|
this.authorize = true; |
||||||
|
}); |
||||||
|
} |
||||||
}; |
}; |
||||||
</script> |
</script> |
||||||
|
|
||||||
<style lang="less"> |
<style lang="less"> |
||||||
.sp-cell { |
.sp-cell { |
||||||
height: 20rpx; |
height: 20rpx; |
||||||
} |
} |
||||||
|
|
||||||
.getUserInfo { |
.getUserInfo { |
||||||
display: flex; |
display: flex; |
||||||
align-items: center; |
align-items: center; |
||||||
flex-direction: column; |
flex-direction: column; |
||||||
padding: 30px; |
padding: 30px; |
||||||
|
|
||||||
text { |
text { |
||||||
font-size: 30rpx; |
font-size: 30rpx; |
||||||
text-align: center; |
text-align: center; |
||||||
margin-bottom: 20px; |
margin-bottom: 20px; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
.container { |
.container { |
||||||
flex: 1; |
flex: 1; |
||||||
display: flex; |
display: flex; |
||||||
flex-direction: column; |
flex-direction: column; |
||||||
justify-content: flex-start; |
justify-content: flex-start; |
||||||
position: relative; |
position: relative; |
||||||
} |
} |
||||||
|
|
||||||
.tab-bar { |
.tab-bar { |
||||||
font-size: 0; |
font-size: 0; |
||||||
display: flex; |
display: flex; |
||||||
align-items: center; |
align-items: center; |
||||||
background: rgba(255, 255, 255, 0.9); |
background: rgba(255, 255, 255, 0.9); |
||||||
position: fixed; |
position: fixed; |
||||||
bottom: 0; |
bottom: 0; |
||||||
left: 0; |
left: 0; |
||||||
right: 0; |
right: 0; |
||||||
z-index: 99; |
z-index: 99; |
||||||
border-top: 1px solid rgba(248, 248, 248, 1); |
border-top: 1px solid rgba(248, 248, 248, 1); |
||||||
|
|
||||||
.tab-bar-item { |
.tab-bar-item { |
||||||
flex: 1; |
flex: 1; |
||||||
height: 49px; |
height: 49px; |
||||||
display: flex; |
display: flex; |
||||||
justify-content: center; |
justify-content: center; |
||||||
align-items: center; |
align-items: center; |
||||||
flex-direction: column; |
flex-direction: column; |
||||||
|
|
||||||
&.active { |
&.active { |
||||||
text { |
text { |
||||||
color: #ee7559; |
color: #ee7559; |
||||||
} |
} |
||||||
|
|
||||||
.tab-bar-pic { |
.tab-bar-pic { |
||||||
display: none; |
display: none; |
||||||
background: #f9f9f9; |
background: #f9f9f9; |
||||||
|
|
||||||
&.active { |
&.active { |
||||||
display: block; |
display: block; |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
.tab-bar-pic { |
.tab-bar-pic { |
||||||
display: block; |
display: block; |
||||||
background: #f9f9f9; |
background: #f9f9f9; |
||||||
|
|
||||||
&.active { |
&.active { |
||||||
display: none; |
display: none; |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
.tab-bar-pic { |
.tab-bar-pic { |
||||||
width: 25px; |
width: 25px; |
||||||
height: 25px; |
height: 25px; |
||||||
background: #f9f9f9; |
background: #f9f9f9; |
||||||
|
|
||||||
image { |
image { |
||||||
width: 25px; |
width: 25px; |
||||||
height: 25px; |
height: 25px; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
.tab-bar-pic-active { |
.tab-bar-pic-active { |
||||||
} |
} |
||||||
|
|
||||||
text { |
text { |
||||||
font-size: 10px; |
font-size: 10px; |
||||||
color: rgb(160, 160, 160); |
color: rgb(160, 160, 160); |
||||||
line-height: 10px; |
line-height: 10px; |
||||||
margin-top: 5px; |
margin-top: 5px; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
.tab-bar-bg { |
.tab-bar-bg { |
||||||
padding-top: 46px; |
padding-top: 46px; |
||||||
width: 100%; |
width: 100%; |
||||||
} |
} |
||||||
|
|
||||||
.view-item { |
.view-item { |
||||||
display: none; |
display: none; |
||||||
width: 100%; |
width: 100%; |
||||||
} |
} |
||||||
|
|
||||||
.view-item-active { |
.view-item-active { |
||||||
display: block; |
display: block; |
||||||
} |
} |
||||||
|
|
||||||
.getUserInfo { |
.getUserInfo { |
||||||
display: flex; |
display: flex; |
||||||
align-items: center; |
align-items: center; |
||||||
flex-direction: column; |
flex-direction: column; |
||||||
padding: 30px; |
padding: 30px; |
||||||
|
|
||||||
p { |
p { |
||||||
margin-bottom: 20px; |
margin-bottom: 20px; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
._van-dialog { |
._van-dialog { |
||||||
z-index: 99999999999; |
z-index: 99999999999; |
||||||
} |
} |
||||||
</style> |
</style> |
||||||
|
Loading…
Reference in new issue