|
@@ -1,8 +1,8 @@
|
|
|
<template>
|
|
|
<view class="container">
|
|
|
- <u-image src="@/static/logo.png"></u-image>
|
|
|
+ <u-image src="@/static/logo.png" mode="widthFix"></u-image>
|
|
|
<view class="login-btn-wrap">
|
|
|
- <u-button shape="circle" type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信用户一键登录</u-button>
|
|
|
+ <u-button shape="circle" type="primary" :loading="loading" @tap="login">微信用户一键登录</u-button>
|
|
|
<u-button shape="circle" :customStyle="{ 'margin-top': '20rpx' }" @tap="$Router.push('/pages/login/phoneLogin')">手机号登录/注册</u-button>
|
|
|
</view>
|
|
|
<view>
|
|
@@ -14,43 +14,37 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getWxLoginCode, getOpenId } from '@/api/system.js';
|
|
|
-import { request } from '@/service';
|
|
|
+import { getWxLoginCode } from '@/api/login.js';
|
|
|
+
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- appid: 'wx962bee9cb47b1696',
|
|
|
- secret: '366ebb364f2180d59de5c42e25a453ea',
|
|
|
+ loading: false,
|
|
|
form: {
|
|
|
client_id: 'chelvc_client',
|
|
|
client_secret: 'qWBe6jD%GCuPPTkP',
|
|
|
grant_type: 'wechat',
|
|
|
token: '',
|
|
|
- mobile: '',
|
|
|
},
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
- async getPhoneNumber(e) {
|
|
|
- console.log(e);
|
|
|
- // TODO: update appid and secret
|
|
|
- if (e.detail.errMsg != 'getPhoneNumber:ok') return uni.$u.toast('请授权使用您的手机号');
|
|
|
- this.form.mobile = e.detail.encryptedData;
|
|
|
+ async login() {
|
|
|
+ this.loading = true;
|
|
|
this.form.token = await getWxLoginCode();
|
|
|
- uni.getSystemInfoAsync({
|
|
|
- success: res => {
|
|
|
- console.log(res);
|
|
|
- },
|
|
|
- });
|
|
|
- request({
|
|
|
- url: '/uc/login',
|
|
|
- method: 'post',
|
|
|
- data: this.form,
|
|
|
- header: {
|
|
|
- 'Content-type': 'application/form-data',
|
|
|
- },
|
|
|
- loadingText: '登录中...',
|
|
|
- });
|
|
|
+ this.$store
|
|
|
+ .dispatch('LoginByWxCode', this.form)
|
|
|
+ .then(() => {
|
|
|
+ this.loading = false;
|
|
|
+ uni.$u.toast('登录成功');
|
|
|
+ setTimeout(() => {
|
|
|
+ this.$Router.pushTab('/pages/home/index');
|
|
|
+ }, 1500);
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.loading = false;
|
|
|
+ uni.$u.toast('登录失败');
|
|
|
+ });
|
|
|
},
|
|
|
},
|
|
|
};
|
|
@@ -58,7 +52,10 @@ export default {
|
|
|
|
|
|
<style scoped>
|
|
|
.container {
|
|
|
+ padding: 0 20rpx;
|
|
|
+ box-sizing: border-box;
|
|
|
}
|
|
|
.login-btn-wrap {
|
|
|
+ margin-top: 40rpx;
|
|
|
}
|
|
|
</style>
|