|
@@ -0,0 +1,99 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script>
|
|
|
|
|
+ export default {
|
|
|
|
|
+ data() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ onLoad(option) {
|
|
|
|
|
+ uni.showLoading({
|
|
|
|
|
+ title: 'loading'
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ // 授权调用
|
|
|
|
|
+ if(typeof(option.code) != 'undefined' && option.code){
|
|
|
|
|
+ this.userAuth(option.code);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ sessionStorage.setItem('redirceUrl', option.reback_url)
|
|
|
|
|
+ this.getAuthUrl();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ },
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ // 获取授权地址
|
|
|
|
|
+ getAuthUrl() {
|
|
|
|
|
+ this.$request.api('/api/auth/url', {url: document.location.protocol+'://'+document.domain+'/page/entry/auth'}).then(res => {
|
|
|
|
|
+ uni.hideLoading()
|
|
|
|
|
+ if(res.success == true){
|
|
|
|
|
+ location.href = res.data
|
|
|
|
|
+ }else{
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: res.msg,
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(parmas => {
|
|
|
|
|
+ console.log(params)
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ // 用户授权登录
|
|
|
|
|
+ userAuth(code) {
|
|
|
|
|
+ let _uni = this
|
|
|
|
|
+ let redirceUrl = sessionStorage.getItem('redirceUrl')
|
|
|
|
|
+ redirceUrl = typeof(redirceUrl)!= 'undefined'? redirceUrl : location.domain+'/pages/index/index';
|
|
|
|
|
+ this.$request.api('/api/auth', {code: code}).then(res => {
|
|
|
|
|
+ console.log(res)
|
|
|
|
|
+ uni.hideLoading()
|
|
|
|
|
+ let accessToken = typeof(res.access_token)!= 'undefined'? res.access_token : ''
|
|
|
|
|
+ if(res.success == true && accessToken){
|
|
|
|
|
+ _uni.$store.commit('setToken', res);
|
|
|
|
|
+ location.href = redirceUrl
|
|
|
|
|
+ }else{
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '错误提示',
|
|
|
|
|
+ content: accessToken? '授权失败,点击确定重试或者取消返回': res.msg+',点击确定重试或者取消返回',
|
|
|
|
|
+ success: function (res) {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ uni.navigateTo({
|
|
|
|
|
+ url: '/pages/entry/auth'
|
|
|
|
|
+ })
|
|
|
|
|
+ } else if (res.cancel) {
|
|
|
|
|
+ location.href = redirceUrl
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(parmas => {
|
|
|
|
|
+ console.log(parmas)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style>
|
|
|
|
|
+ .nav-bar {
|
|
|
|
|
+ padding-top: 50rpx;
|
|
|
|
|
+ padding-bottom: 10rpx;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ justify-content: space-between;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ background: linear-gradient(rgb(255, 152, 101), rgb(255, 122, 85));
|
|
|
|
|
+ height: 125rpx;
|
|
|
|
|
+ }
|
|
|
|
|
+ .btn {
|
|
|
|
|
+ width: 50%;
|
|
|
|
|
+ height: 80rpx;
|
|
|
|
|
+ line-height: 80rpx;
|
|
|
|
|
+ margin: 0 auto;
|
|
|
|
|
+ background-color: #18B566;
|
|
|
|
|
+ color: #fff;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ margin-top: 50%;
|
|
|
|
|
+ border-radius: 6rpx;
|
|
|
|
|
+ }
|
|
|
|
|
+</style>
|