123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <template>
- <view class="content">
- <u-button type="success" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信一键登录</u-button>
- </view>
- </template>
- <script>
- import {
- login
- } from "@/api/login.js"
- export default {
- components: {},
- data() {
- return {
- path: '/pages/index/index',
- lanuch: true
- }
- },
- onShow() {},
- mounted() {},
- onLoad(option) {
- console.log(option)
- const {
- path,
- lanuch
- } = option;
- this.lanuch = (lanuch + '') === 'true';
- if (path) {
- this.path = decodeURIComponent(path);
- }
- },
- methods: {
- 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 {
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- </style>
|