| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <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>
|