You've already forked guangan-mp
1.0.0
This commit is contained in:
101
pages/user/login.vue
Normal file
101
pages/user/login.vue
Normal file
@ -0,0 +1,101 @@
|
||||
<template>
|
||||
<view class="login">
|
||||
|
||||
<view class="login-head flex-y">
|
||||
<text class="login-head-h1">登录</text>
|
||||
</view>
|
||||
|
||||
<view class="login-body flex-y">
|
||||
|
||||
<view class="flex-center">
|
||||
<text class="login-body-name">微信授权</text>
|
||||
</view>
|
||||
|
||||
<view style="margin-top:80rpx;" class="flex-center">
|
||||
<button type="success" size="large" @click="doLogin" customStyle="width:600rpx;height:100rpx">登
|
||||
录</button>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<!--
|
||||
<view class="login-foot">
|
||||
<view class='login-foot-agent flex-center'>
|
||||
<checkbox label="1" v-model="agent.value">同意协议</checkbox>
|
||||
<text @click="agent.show = true">《用户隐私协议》</text>
|
||||
</view>
|
||||
</view> -->
|
||||
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { TaAjax } from '@/common/ajax';
|
||||
import { TaCache } from '@/common/cache';
|
||||
import { TaToast } from '@/common/toast';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 用户协议
|
||||
agent: {
|
||||
show: false,
|
||||
value: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
created() {
|
||||
const userInfo = TaCache.get('auth.user')
|
||||
if (userInfo) {
|
||||
uni.navigateBack()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 执行注册登录
|
||||
doLogin() {
|
||||
TaToast.loading("登录中")
|
||||
this.login().then((data) => {
|
||||
TaCache.set('auth.user', data)
|
||||
}).finally(() => {
|
||||
TaToast.loadhide()
|
||||
})
|
||||
},
|
||||
login() {
|
||||
return new Promise((resolve, reject) => uni.login({
|
||||
provider: 'weixin',
|
||||
success(loginRes) {
|
||||
// 换取会话密钥
|
||||
let data = {
|
||||
code: loginRes.code,
|
||||
iv: '',
|
||||
encrypted: ''
|
||||
}
|
||||
TaAjax.post('/plugin-account/api.wxapp/session', data).then((ret) => {
|
||||
console.log('SessionDone: ', ret)
|
||||
TaCache.set('auth.token', ret.data.token)
|
||||
// 获取用户信息
|
||||
uni.getUserInfo({
|
||||
provider: 'weixin',
|
||||
success: (infoRes) => {
|
||||
console.log('UserInfo: ', infoRes)
|
||||
data.iv = infoRes.iv, data.encrypted = infoRes
|
||||
.encryptedData
|
||||
TaAjax.post('/plugin-account/api.wxapp/decode', data)
|
||||
.then((ret) => {
|
||||
console.log('UserDone: ', ret.data)
|
||||
resolve(ret.data)
|
||||
}).catch((ret) => {
|
||||
console.log('UserFail: ', ret.data)
|
||||
reject(ret)
|
||||
})
|
||||
}
|
||||
})
|
||||
}).catch((ret) => {
|
||||
console.log('SessionFail: ', ret)
|
||||
reject(ret);
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
Reference in New Issue
Block a user