login-withoutpwd.vue 5.9 KB
Newer Older
DCloud_JSON's avatar
1.0.0  
DCloud_JSON 已提交
1
<!-- 免密登录页 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
2 3
<template>
	<view class="uni-content">
JiaRongPing's avatar
JiaRongPing 已提交
4 5 6
		<view class="login-logo">
			<image :src="logo"></image>
		</view>
DCloud_JSON's avatar
DCloud_JSON 已提交
7 8 9
		<!-- 顶部文字 -->
		<text class="title">请选择登录方式</text>
		<!-- 快捷登录框 当url带参数时有效 -->
C
chenruilong 已提交
10
		<template v-if="['apple','weixin', 'weixinMobile'].includes(type)">
DCloud_JSON's avatar
DCloud_JSON 已提交
11 12
			<text class="tip">将根据第三方账号服务平台的授权范围获取你的信息</text>
			<view class="quickLogin">
C
chenruilong 已提交
13 14 15
				<image v-if="type !== 'weixinMobile'" @click="quickLogin" :src="imgSrc" mode="widthFix" class="quickLoginBtn"></image>
        <button v-else type="primary" open-type="getPhoneNumber" @getphonenumber="quickLogin">微信授权手机号登录</button>
        <uni-id-pages-agreements scope="register" ref="agreements"></uni-id-pages-agreements>
DCloud_JSON's avatar
DCloud_JSON 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
			</view>
		</template>
		<template v-else>
			<text class="tip">未注册的账号验证通过后将自动注册</text>
			<view class="phone-box">
				<view @click="chooseArea" class="area">+86</view>
				<uni-easyinput :focus="focusPhone" @blur="focusPhone = false" class="input-box" type="number" :inputBorder="false"
					v-model="phone" maxlength="11" placeholder="请输入手机号" />
			</view>
			<uni-id-pages-agreements scope="register" ref="agreements"></uni-id-pages-agreements>
			<button class="uni-btn" type="primary" @click="toSmsPage">获取验证码</button>
		</template>
		<!-- 固定定位的快捷登录按钮 -->
		<uni-id-pages-fab-login ref="uniFabLogin"></uni-id-pages-fab-login>
	</view>
</template>

<script>
	let currentWebview; //当前窗口对象
	import config from '@/uni_modules/uni-id-pages/config.js'
	import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
	export default {
		mixins: [mixin],
		data() {
			return {
				type: "", //快捷登录方式
				phone: "", //手机号码
JiaRongPing's avatar
JiaRongPing 已提交
43 44
				focusPhone:false,
				logo: "/static/logo.png"
DCloud_JSON's avatar
DCloud_JSON 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
			}
		},
		computed: {
			async loginTypes() { //读取配置的登录优先级
				return config.loginTypes
			},
			isPhone() { //手机号码校验正则
				return /^1\d{10}$/.test(this.phone);
			},
			imgSrc() { //大快捷登录按钮图
				return '/uni_modules/uni-id-pages/static/login/' + this.type + '.png'
			}
		},
		async onLoad(e) {
			console.log(e);
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
60 61
			//获取通过url传递的参数type设置当前登录方式,如果没传递直接默认以配置的登录
			let type = e.type || config.loginTypes[0]
DCloud_JSON's avatar
DCloud_JSON 已提交
62 63 64 65 66 67 68
			this.type = type
			if(type != 'univerify'){
				this.focusPhone = true
			}
			this.$nextTick(() => {
				//关闭重复显示的登录快捷方式
				if (['weixin', 'apple'].includes(type)) {
DCloud_JSON's avatar
1.0.20  
DCloud_JSON 已提交
69
					this.$refs.uniFabLogin.servicesList = this.$refs.uniFabLogin.servicesList.filter(item =>item.id != type)
DCloud_JSON's avatar
DCloud_JSON 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
				}
			})
			uni.$on('uni-id-pages-set-login-type', type => {
				this.type = type
			})
		},
		onShow() {
			// #ifdef H5
			document.onkeydown = event => {
				var e = event || window.event;
				if (e && e.keyCode == 13) { //回车键的键值为13
					this.toSmsPage()
				}
			};
			// #endif
		},
		onUnload() {
			uni.$off('uni-id-pages-set-login-type')
		},
		onReady() {
			//是否优先启动一键登录。即:页面一加载就启动一键登录
			//#ifdef APP-PLUS
			if (this.type == "univerify") {
				this.type == this.loginTypes[1]
				// console.log('开始一键登录');
				setTimeout(() => {
					this.$refs.uniFabLogin.login_before('univerify')
				}, 100)
			}
			//#endif
		},
		methods: {
C
chenruilong 已提交
102 103 104 105 106 107
			quickLogin(e) {
        let options = {}

        if (e.detail?.code) {
          options.phoneNumberCode = e.detail.code
        }
108 109 110

        if (this.type === 'weixinMobile' && !e.detail?.code) return

C
chenruilong 已提交
111
				this.$refs.uniFabLogin.login_before(this.type, true, options)
DCloud_JSON's avatar
DCloud_JSON 已提交
112 113 114 115 116 117 118
			},
			toSmsPage() {
				console.log('toSmsPage',this.agree);
				if (!this.isPhone) {
					this.focusPhone = true
					return uni.showToast({
						title: "手机号码格式不正确",
119 120
						icon: 'none',
						duration: 3000
DCloud_JSON's avatar
DCloud_JSON 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
					});
				}
				if (this.needAgreements && !this.agree) {
					return this.$refs.agreements.popup(this.toSmsPage)
				}
				// 发送验证吗
				uni.navigateTo({
					url: '/uni_modules/uni-id-pages/pages/login/login-smscode?phoneNumber=' + this.phone
				});
			},
			//去密码登录页
			toPwdLogin() {
				uni.navigateTo({
					url: '../login/password'
				})
			},
			chooseArea() {
				uni.showToast({
					title: '暂不支持其他国家',
140 141
					icon: 'none',
					duration: 3000
DCloud_JSON's avatar
DCloud_JSON 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/uni_modules/uni-id-pages/common/login-page.scss";

	.uni-content,
	.quickLogin {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
	}

	.phone-box {
		position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
	}

	.area {
		position: absolute;
		left: 10px;
		z-index: 9;
		top: 12px;
		font-size: 14px;
	}

	.area::after {
		content: "";
		border: 3px solid transparent;
		border-top-color: #000;
		top: 12px;
		left: 3px;
		position: relative;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
182 183 184 185 186
	
	/* #ifdef MP */
	// 解决小程序端开启虚拟节点virtualHost引起的 class = input-box丢失的问题 [详情参考](https://uniapp.dcloud.net.cn/matter.html#%E5%90%84%E5%AE%B6%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AE%9E%E7%8E%B0%E6%9C%BA%E5%88%B6%E4%B8%8D%E5%90%8C-%E5%8F%AF%E8%83%BD%E5%AD%98%E5%9C%A8%E7%9A%84%E5%B9%B3%E5%8F%B0%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98)
	.phone-box ::v-deep .uni-easyinput__content,
	/* #endif */
DCloud_JSON's avatar
DCloud_JSON 已提交
187 188 189 190 191 192 193 194 195 196 197
	.input-box {
		/* #ifndef APP-NVUE */
		box-sizing: border-box;
		/* #endif */
		flex: 1;
		padding-left: 45px;
		margin-bottom: 10px;
		border-radius: 0;
	}

	.quickLogin {
DCloud_JSON's avatar
DCloud_JSON 已提交
198
		// width: 650rpx;
DCloud_JSON's avatar
DCloud_JSON 已提交
199 200 201 202 203 204 205 206
		height: 350px;
		align-items: center;
		justify-content: center;
	}

	.quickLoginBtn {
		margin: 20px 0;
		width: 450rpx;
DCloud_JSON's avatar
DCloud_JSON 已提交
207 208 209
		/* #ifndef APP-NVUE */
		max-width: 230px;
		/* #endif */
DCloud_JSON's avatar
DCloud_JSON 已提交
210 211 212 213 214 215 216
		height: 82rpx;
	}

	.tip {
		margin-top: -15px;
		margin-bottom: 20px;
	}
C
chenruilong 已提交
217

JiaRongPing's avatar
JiaRongPing 已提交
218 219 220 221 222
	@media screen and (min-width: 690px) {
		.quickLogin{
			height: auto;
		}
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
223
</style>