|
@@ -1,62 +1,90 @@
|
|
|
<template>
|
|
|
<view class="content">
|
|
|
- <u-button type="success" open-type="getUserInfo" @click="loginIn">微信一键登录</u-button>
|
|
|
+ <u-button type="success" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信一键登录</u-button>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import {code2Session} from "@/api/login.js"
|
|
|
+ import {
|
|
|
+ login
|
|
|
+ } from "@/api/login.js"
|
|
|
export default {
|
|
|
- components: {
|
|
|
- },
|
|
|
+ components: {},
|
|
|
data() {
|
|
|
return {
|
|
|
-
|
|
|
+ path: '/pages/index/index',
|
|
|
+ lanuch: true
|
|
|
}
|
|
|
},
|
|
|
- onShow () {
|
|
|
-
|
|
|
- },
|
|
|
+ onShow() {},
|
|
|
+ mounted() {},
|
|
|
onLoad(option) {
|
|
|
-
|
|
|
+ console.log(option)
|
|
|
+ const {
|
|
|
+ path,
|
|
|
+ lanuch
|
|
|
+ } = option;
|
|
|
+ this.lanuch = (lanuch + '') === 'true';
|
|
|
+ if (path) {
|
|
|
+ this.path = decodeURIComponent(path);
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
- loginIn () {
|
|
|
- let _this = this
|
|
|
- // uni.login({
|
|
|
- // provider: provider,
|
|
|
- // success(result) {
|
|
|
- // console.log(result)
|
|
|
- // if (result.code) {
|
|
|
- // code2Session({
|
|
|
- // code: result.code
|
|
|
- // }).then(res => {
|
|
|
- // if (res.status === '200') {
|
|
|
- // _this.$u.vuex('vuex_openid',res.data)
|
|
|
- // uni.navigateTo({
|
|
|
- // url: '/pages/index/index'
|
|
|
- // })
|
|
|
- // };
|
|
|
- // });
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- uni.login({
|
|
|
- provider: 'weixin',
|
|
|
- success: function (loginRes) {
|
|
|
- console.log(loginRes); // 返回code
|
|
|
- uni.navigateTo({
|
|
|
- url: '/pages/index/index'
|
|
|
+ getPhoneNumber(e) {
|
|
|
+ uni.showLoading({
|
|
|
+ mask: true,
|
|
|
+ title: '加载中'
|
|
|
+ });
|
|
|
+ if (e.target.errMsg === 'getPhoneNumber:ok') {
|
|
|
+ uni.login({
|
|
|
+ success(result) {
|
|
|
+ if (result.code) {
|
|
|
+ login({
|
|
|
+ code: result.code,
|
|
|
+ encryptedData: e.target.encryptedData,
|
|
|
+ iv: e.target.iv
|
|
|
+ }).then(res => {
|
|
|
+ uni.hideLoading();
|
|
|
+ if (res.status === '200') {
|
|
|
+ console.log(res.data, 'login data')
|
|
|
+ uni.setStorageSync('token', res.data.token);
|
|
|
+ uni.setStorageSync('phone', res.data.phone);
|
|
|
+ uni.setStorageSync('userId', res.data.userId);
|
|
|
+ if (this.path === '/pages/index/main' || this.lanuch) {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: this.path
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.redirectTo({
|
|
|
+ url: this.path
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.message,
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2500
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
})
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
+
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: '授权失败',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2500
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style>
|
|
|
- .content{
|
|
|
+ .content {
|
|
|
padding: 0;
|
|
|
display: flex;
|
|
|
align-items: center;
|