123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <template>
- <view class="content">
- <view class="content-body">
- <view class="login-logo">
- <u-image src="/static/logo.png" width="160" height="160" class="logo"></u-image>
- </view>
- <view class="login-btns">
- <u-button shape="circle" :custom-style="wxButton" class="login-btn" type="success" :hair-line="false" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
- 微信一键登录
- </u-button>
- <u-button shape="circle" :custom-style="phoneButton" class="login-btn phoneBtn" @click="phoneLogin" :hoverClass='none'>
- 手机号登录/注册
- </u-button>
- </view>
- </view>
- <view class="xieyi" @click="gotoXieyi()">
- 首次登录会自动创建账号且代表同意 <text>《用户协议》</text>及<text>《隐私政策》</text>
- </view>
- </view>
-
- </template>
- <script>
- import service from '../../service.js';
- import {wxlogin} from '../../api/login.js'
- import {
- mapState,
- mapMutations
- } from 'vuex'
-
- export default {
- components: {
- },
- data() {
- return {
- path: '/pages/index/index',
- lanuch: false,
- mobile: '',
- code: '',
- codeText: '获取验证码',
- getCodeing: false,
- totalTime: 60,
- positionTop: 0,
- hasFocus: false,
- hasFocus1: false,
- wxButton:{
- background: '#1283d4'
- },
- phoneButton:{
- background: '#ffffff'
- }
- }
- },
- computed: mapState(['forcedLogin']),
- mounted() {
-
-
- this.$store.dispatch('wxLogin','weixin')
-
- },
- onLoad(option) {
-
- this.wxLogin()
- const {
- path,
- lanuch,
- q
- } = option;
- this.lanuch = (lanuch + '') === 'true';
- if (path) {
- this.path = decodeURIComponent(path+"?q="+q);
- }
- },
- methods: {
- ...mapMutations(['login']),
-
- getPhoneNumber(e) {
- let _this = this
- uni.showLoading({
- mask: true,
- title: '加载中'
- });
- if (!this.code) {
- this.wxLogin()
- }
- console.log(this.code, e)
- if (e.target.errMsg === 'getPhoneNumber:ok') {
- setTimeout(()=>{
- const params={
- code: _this.code,
- encryptedData: e.target.encryptedData,
- iv: e.target.iv,
- }
- wxlogin(params).then(res => {
- uni.hideLoading();
- _this.code = ''
- console.log(res,_this.path, 'login data')
- if (res.status == '200') {
- this.toMain(res.data)
-
- uni.$emit("getUserInfo")
- if (_this.path === '/pages/index/index' || _this.lanuch) {
- uni.reLaunch({
- url: _this.path
- });
- } else {
- uni.redirectTo({
- url: _this.path
- });
- }
- } else {
- uni.showToast({
- title: res.message,
- icon: 'none',
- duration: 2500
- });
- }
- });
- },300)
- } else {
- uni.showToast({
- title: '授权失败',
- icon: 'none',
- duration: 2500
- });
- }
- },
-
- wxLogin () {
- let _this = this
- uni.login({
- provider: 'weixin',
- success(res) {
- console.log(res.code)
- _this.code = res.code
- }
- })
- },
- toMain(data) {
- this.login({token:data});
- uni.reLaunch({
- url: '/pages/index/index',
- });
- },
-
- phoneLogin(){
- wx.navigateTo({
- url: '/pages/login/phoneLogin'
- })
- },
- initPosition() {
-
- this.positionTop = uni.getSystemInfoSync().windowHeight - 100;
- },
- gotoXieyi(url){
- uni.navigateTo({
- url: '/pagesMe/xieyi/index?id=0'
- })
- }
- },
- onReady() {
- this.initPosition();
- }
- }
- </script>
- <style lang="less">
- .content{
- width: 100%;
- height: 100vh;
- padding:0 125upx;
- display: flex;
- flex-direction: column;
- text-align: center;
- .content-body{
- flex: 1;
- .logo{
- display: inline-block;
- margin:250upx 0 120upx;
- }
- .phoneBtn{
- display: block;
- margin: 30rpx 0 350upx;
- }
- }
- .xieyi{
- font-size: 24upx;
- padding-bottom: 60upx;
- text{
- color:#1283d4
- }
- }
- }
- </style>
|