index.vue 4.0 KB
Newer Older
芊里 已提交
1
<template>
DCloud_JSON's avatar
DCloud_JSON 已提交
2
	<view class="content">
3
		<!-- 顶部文字 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
4
		<text class="title">登录后即可展示自己</text>
5 6
		<uni-agreements @setAgree="agree = $event"></uni-agreements>
		<!-- 登录框 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
7 8
		<input type="number" class="input-box" :inputBorder="false" v-model="phone" maxlength="11"
			placeholder="请输入手机号" />
9 10
		<button class="get-code" :class="{isPhone}" :disabled="!isPhone" :type="isPhone?'primary':'default'"
			@click="sendShortMsg">获取短信验证码</button>
DCloud_JSON's avatar
DCloud_JSON 已提交
11
		<text class="tip">未注册的手机号验证通过后将自动注册</text>
L
linju 已提交
12
		<!-- 登录按钮弹窗 -->
DCloud_JSON's avatar
DCloud_JSON 已提交
13
		<uni-quick-login :univerifyStyle="univerifyStyle" :agree="agree" ref="uniQuickLogin"></uni-quick-login>
芊里 已提交
14 15 16
	</view>
</template>

17
<script>
DCloud_JSON's avatar
DCloud_JSON 已提交
18
	var univerify_first, currentWebview; //是否一键登录优先
L
123  
linju 已提交
19
	export default {
芊里 已提交
20
		data() {
21
			return {
DCloud_JSON's avatar
DCloud_JSON 已提交
22 23
				phone: "",
				agree: false,
24 25
				univerifyStyle: {
					"fullScreen": true, // 是否全屏显示,true表示全屏模式,false表示非全屏模式,默认值为false。
DCloud_JSON's avatar
DCloud_JSON 已提交
26 27 28
					"backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff
					"buttons": { // 自定义登陆按钮
						"iconWidth": "45px", // 图标宽度(高度等比例缩放) 默认值:45px
29 30 31 32 33 34 35 36 37
						"list": []
					},
					"privacyTerms": {
						"defaultCheckBoxState": "true", // 条款勾选框初始状态 默认值: true   
						"textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB  
						"termsColor": "#5496E3", //  协议文字颜色 默认值: #5496E3  
						"prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”  
						"suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”  
						"privacyItems": []
DCloud_JSON's avatar
DCloud_JSON 已提交
38 39
					}
				}
L
linju 已提交
40
			}
L
23  
linju 已提交
41
		},
42
		computed: {
DCloud_JSON's avatar
DCloud_JSON 已提交
43
			isPhone() {
44
				return /^1\d{10}$/.test(this.phone);
45 46 47
			},
			agreements() {
				return getApp().globalData.config.about.agreements || []
48 49
			}
		},
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
		onLoad(e) {
			uni.getProvider({
				service: 'oauth',
				success: res => {
					if (~res.provider.indexOf('weixin')&&plus.runtime.isApplicationExist({
							pname: 'com.tencent.mm',
							action: 'weixin://'
						})) {
						this.univerifyStyle.buttons.list.push({
							"iconPath": "/static/uni-quick-login/wechat.png"
						})
					}
					if (~res.provider.indexOf('apple')) {
						this.univerifyStyle.buttons.list.push({
							"iconPath": "/static/uni-quick-login/apple.png"
						})
					}
				}
			});


DCloud_JSON's avatar
DCloud_JSON 已提交
71
			//是否优先启动一键登录。即:页面一加载就启动一键登录
L
23  
linju 已提交
72 73
			univerify_first = e.univerify_first
			//#ifdef APP-PLUS
DCloud_JSON's avatar
DCloud_JSON 已提交
74
			if (univerify_first) {
75
				this.univerifyStyle.privacyTerms.privacyItems = this.agreements
L
23  
linju 已提交
76 77 78
				const pages = getCurrentPages();
				currentWebview = pages[pages.length - 1].$getAppWebview();
				currentWebview.setStyle({
DCloud_JSON's avatar
DCloud_JSON 已提交
79
					"top": "2000px" //隐藏当前页面窗体
L
23  
linju 已提交
80
				})
L
21  
linju 已提交
81
			}
L
23  
linju 已提交
82 83 84 85
			//#endif
		},
		onReady() {
			//#ifdef APP-PLUS
DCloud_JSON's avatar
DCloud_JSON 已提交
86
			if (univerify_first) {
87
				// console.log('开始一键登录');
88
				this.agree = true
DCloud_JSON's avatar
DCloud_JSON 已提交
89
				setTimeout(() => {
90
					this.$refs.uniQuickLogin.login_before('univerify')
DCloud_JSON's avatar
DCloud_JSON 已提交
91
				}, 100)
L
23  
linju 已提交
92 93
				setTimeout(() => {
					currentWebview.setStyle({
DCloud_JSON's avatar
DCloud_JSON 已提交
94 95 96
						titleNView: {
							autoBackButton: true,
							backgroundColor: "#FFFFFF"
L
23  
linju 已提交
97 98 99
						}
					})
					currentWebview.setStyle({
DCloud_JSON's avatar
DCloud_JSON 已提交
100
						"top": "0"
L
23  
linju 已提交
101 102 103 104 105
					})
				}, 1500);
			}
			//#endif
		},
L
linju 已提交
106
		methods: {
107
			sendShortMsg() {
DCloud_JSON's avatar
DCloud_JSON 已提交
108
				if (!this.agree) {
109 110 111 112 113
					return uni.showToast({
						title: '你未同意隐私政策协议',
						icon: 'none'
					});
				}
DCloud_JSON's avatar
DCloud_JSON 已提交
114
				// 发送验证吗
L
123  
linju 已提交
115
				uni.showLoading();
L
123  
linju 已提交
116
				uni.navigateTo({
DCloud_JSON's avatar
DCloud_JSON 已提交
117
					url: '/pages/ucenter/login-page/phone-code/phone-code?phoneNumber=' + this.phone,
118 119
					complete: () => {
						uni.hideLoading();
DCloud_JSON's avatar
DCloud_JSON 已提交
120
					}
L
123  
linju 已提交
121
				});
L
linju 已提交
122
			},
DCloud_JSON's avatar
DCloud_JSON 已提交
123
			//去密码登录页
L
linju 已提交
124 125
			toPwdLogin() {
				uni.navigateTo({
L
23  
linju 已提交
126
					url: '../pwd-login/pwd-login'
L
linju 已提交
127
				})
芊里 已提交
128 129 130 131 132
			}
		}
	}
</script>

133
<style lang="scss">
DCloud_JSON's avatar
DCloud_JSON 已提交
134
	@import url("../common/login-page.css");
DCloud_JSON's avatar
DCloud_JSON 已提交
135
</style>