123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <template>
- <view>
- <u-popup :show="authShow" mode="bottom">
- <view class="auth-wrap">
- <view class="tip">为了正常使用功能,请授权用户信息。</view>
- <!-- #ifdef MP-ALIPAY -->
- <button :loading="authIng" @click="getInfoAli()" type="default">授权</button>
- <view style="height: 100rpx;"></view>
- <!-- #endif -->
- <!-- #ifndef MP-ALIPAY -->
- <button :loading="authIng" @click="getInfo()" type="default">授权</button>
- <!-- #endif -->
- </view>
- </u-popup>
- </view>
- </template>
- <script>
- import $http from '../../utils/request.js'
- import appId from '@/config/appId.js'
- export default {
- name: "auth",
- props: {
- authShow: {
- type: Boolean,
- default: true
- },
- authToken: {
- type: String,
- default: ''
- },
- authMobile: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- authIng: false
- };
- },
- methods: {
- getInfo() {
- let _this = this
- if (this.authIng) {
- return
- }
- _this.authIng = true
- uni.getUserProfile({
- desc: '用于填充用户默认信息',
- success(info) {
- uni.login({
- success(res) {
- $http.post('/api/v1/mp/user/wxauth', {
- ...{
- identity: 1,
- code: res.code
- },
- ...info.userInfo,
- appSource: appId
- }).then(res => {
- _this.authIng = false
- if (res.code === 0) {
- uni.$u.toast('授权成功');
- _this.authIng = false
- _this.$emit('close')
- }
- }).catch(() => {
- _this.authIng = false
- })
- }
- })
- },
- fail() {
- _this.authIng = false
- }
- })
- },
- getInfoAli() {
- let _this = this
- if (this.authIng) {
- return
- }
- _this.authIng = true
- my.getAuthCode({
- scopes: ['auth_user'],
- success: (res) => {
- $http.post('/api/v1/mp/user/aliAuth', {
- code: res.authCode
- }).then(res => {
- _this.authIng = false
- if (res.code === 0) {
- uni.$u.toast('授权成功');
- _this.authIng = false
- _this.$emit('close')
- }
- }).catch(() => {
- _this.authIng = false
- })
- },
- fail: (res) => {
- uni.$u.toast('授权失败');
- uni.removeStorageSync('token')
- _this.authIng = false
- _this.$emit('fail')
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .auth-wrap {
- /* #ifndef MP-ALIPAY */
- padding: 32rpx 32rpx 50rpx;
- /* #endif */
- /* #ifdef MP-ALIPAY */
- padding: 32rpx 32rpx 0;
- /* #endif */
- ::v-deep button {
- line-height: 76rpx;
- font-size: 28rpx;
- height: 76rpx;
- color: #fff;
- background-color: $uni-bg-color;
- border: none;
- border-radius: 100rpx;
- }
- }
- .tip {
- padding: 50rpx 16rpx;
- font-size: 26rpx;
- color: #333;
- }
- </style>
|