1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <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) {
- let _this = this
- uni.showLoading({
- mask: true,
- title: '加载中'
- });
- console.log(e.target.encryptedData,'eeeeeee')
- if (e.target.errMsg === 'getPhoneNumber:ok') {
- uni.login({
- provider: 'weixin',
- success(res) {
- login({
- code: res.code,
- encryptedData: e.target.encryptedData,
- iv: e.target.iv
- }).then(res => {
- uni.hideLoading();
- console.log(res, 'login data')
- if (res.status == '200') {
- console.log(res.data, 'login data')
- getApp().globalData.token = res.data
- _this.$u.vuex('vuex_token',res.data)
- 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>
|