login-action-sheet.vue 2.9 KB
Newer Older
芊里 已提交
1 2
<template>
	<uni-popup ref="actionSheet" type="bottom">
芊里 已提交
3 4
		<view class="action-sheet-box">
			<view class="auth-wrap auth-item" @click="clickItem(item)"
芊里 已提交
5 6
				hover-class="hover" v-for="(item, index) in providerList" :key="index">
				<image :src="item.image" class="login-logo"></image>
芊里 已提交
7
				<text class="auth-text">{{providerName[item.value]}}</text>
芊里 已提交
8 9
			</view>
			<view class="cancel-line"></view>
芊里 已提交
10 11
			<view class="auth-wrap cancel-item" @click="clickItem(item)">
				<text class="auth-text">取消</text>
芊里 已提交
12 13 14 15 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
			</view>
		</view>
	</uni-popup>
</template>

<script>
	export default {
		name: "login-action-sheet",
		data() {
			return {
				providerList: [],
				providerName: {
					apple: '苹果登录',
					weixin: '微信登录',
					qq: 'QQ登录',
					sinaweibo: '微博登录'
				}
			};
		},
		created() {
			this.initProvider();
			this.testInit();
		},
		methods: {
			/**
			 * 测试方法
			 */
			testInit() {
				const filters = ['apple', 'weixin', 'qq', 'sinaweibo'];
				this.providerList = [];
				filters.forEach(curProvider => {
					this.providerList.push({
						value: curProvider,
						image: '../../static/login/img/' + curProvider + '.png'
					});
				})

			},
			/**
			 * 初始化第三方登录
			 */
			initProvider() {
				return
				const filters = ['apple', 'weixin', 'qq', 'sinaweibo'];
				uni.getProvider({
					service: 'oauth',
					success: (res) => {
						if (res.provider && res.provider.length) {
							if (res.provider.indexOf('apple') !== -1) {
								this.hasAppleLogin = true;
							}
							for (let i = 0; i < res.provider.length; i++) {
								const curProvider = res.provider[i];
								if (~filters.indexOf(curProvider)) {
									this.providerList.push({
										value: curProvider,
										image: '/components/auth-btn/img/' + curProvider + '.png'
									});
								}
							}
							this.hasProvider = true;
						}
					},
					fail: (err) => {
						console.error('获取服务供应商失败:' + JSON.stringify(err));
					}
				});
			},
			clickItem(item) {
				this.$refs.actionSheet.close();
				if (item) this.$emit('login', item);
			},
			open() {
				this.$refs.actionSheet.open();
			}
		}
	}
</script>

芊里 已提交
91
<style scoped>
芊里 已提交
92 93
	.action-sheet-box {
		border-top-left-radius: 20rpx;
芊里 已提交
94 95 96 97 98 99
		border-top-right-radius: 20rpx;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 750rpx;
		background-color: #fff;
芊里 已提交
100 101 102 103 104 105
	}

	.login-logo {
		width: 42rpx;
		height: 42rpx;
	}
芊里 已提交
106 107 108 109 110 111 112 113 114 115 116
	
	.auth-wrap{
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: nowrap;
		align-items: center;
		justify-content: center;
	}
	
芊里 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130
	.auth-item {
		border-bottom-width: 1px;
		border-bottom-color: #F1F1F1;
		height: 125rpx;
	}

	.cancel-item {
		height: 125rpx;
	}

	.cancel-line {
		width: 750rpx;
		height: 10rpx;
		background-color: #F1F1F1;
芊里 已提交
131 132 133 134
	}
	.auth-text{
		padding: 0 10rpx;
		font-size: 28rpx;
芊里 已提交
135 136
	}
</style>