123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <template>
- <view class="content">
- <view>
- <view>
- <view class="logo">
- <u-image src="/static/logo.png" width="140" height="140" ></u-image>
- </view>
- <view class="login-btns">
- <u-button
- shape="circle"
- :custom-style="wxButton"
- class="login-btn"
- type="success"
- :hair-line="false"
- :open-type="tyYd?'getPhoneNumber':''"
- @click="getCheckYd"
- @getphonenumber="getPhoneNumber">
- 手机号快捷登录
- </u-button>
- <u-gap height="30"></u-gap>
- <u-button shape="circle" :custom-style="phoneButton" class="login-btn" @click="phoneLogin" type="primary">
- 手机验证码登录
- </u-button>
- </view>
- </view>
- <view class="nologin">
- <u-button shape="circle" size="mini" plain lass="login-btn" @click="cansel" type="info">
- 暂不登录
- </u-button>
- </view>
- </view>
- <view class="xieyi" style="display: flex;align-items: center;padding:50upx 0;justify-content: center;font-size: 24rpx;">
- <u-checkbox v-model="tyYd" :label-size="24">登录代表您已同意</u-checkbox>
- <text style="margin-left: -20rpx;" @click="toYs()">隐私政策、服务条款</text>
- </view>
- </view>
- </template>
- <script>
- import {
- login
- } from "@/api/login"
- export default {
- components: {},
- data() {
- return {
- path: '/pages/index/index',
- lanuch: false,
- tyYd: false,
- code: '',
- url:'', // 二维码参数
- wxButton: {
- background: '#07c160'
- },
- phoneButton: {
- background: '#00aaff'
- }
- }
- },
- mounted() {},
- onLoad(option) {
- if(option.q !=undefined){
- this.url=decodeURIComponent(option.q)
- }
- // 开启分享
- uni.showShareMenu({
- withShareTicket: true,
- menus: ['shareAppMessage', 'shareTimeline']
- })
- // 为解决首次登录异常问题 进入页面先调微信登录获取code
- this.wxLogin()
- const {
- path,
- lanuch
- } = option;
- this.lanuch = (lanuch + '') === 'true';
- if (path) {
- this.path = decodeURIComponent(path);
- }
- },
- methods: {
- cansel(){
- this.$store.state.vuex_noLogin = true
- uni.reLaunch({
- url: '/pages/index/index'
- })
- },
- toYs(){
- uni.navigateTo({
- url: '/pages/agreement/agreement'
- })
- },
- getCheckYd(){
- if(!this.tyYd){
- uni.showToast({
- title: "请阅读并同意隐私政策、服务条款",
- icon: "none"
- })
- return
- }
- },
- 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,
- }
- if(_this.url){
- params.encode=_this.url
- }
- login(params).then(res => {
- uni.hideLoading();
- _this.code = ''
- console.log(res,_this.path, 'login data')
- if (res.status == '200') {
- getApp().globalData.token = res.data
- _this.$u.vuex('vuex_token',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
- });
- }
- },
- // 调微信登录 获取code
- wxLogin () {
- let _this = this
- uni.login({
- provider: 'weixin',
- success(res) {
- console.log(res.code)
- _this.code = res.code
- }
- })
- },
- // 手机号登录
- phoneLogin () {
- if(this.url){
- wx.navigateTo({
- url: '/pages/login/phoneLogin?path='+this.path+'&lanuch='+this.lanuch+'&encode='+this.url
- })
- }else{
- wx.navigateTo({
- url: '/pages/login/phoneLogin?path='+this.path+'&lanuch='+this.lanuch
- })
- }
-
- }
- }
- }
- </script>
- <style lang="scss">
- .content {
- width: 100%;
- height: 100%;
- padding: 40upx;
- display: flex;
- flex-direction: column;
- > view{
- text-align: center;
- &:first-child{
- flex-grow: 1;
- height: 80vh;
- padding: 20% 10%;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
- &:last-child{
- font-size: 24upx;
- text{
- color: #07c160;
- }
- }
- .logo{
- text-align: center;
- display: flex;
- justify-content: center;
- }
- .login-btns{
- padding: 60upx 0;
- .login-btn{
- margin: 30upx 0;
- }
- }
- }
- }
- </style>
|