login-action-sheet.vue 2.8 KB
Newer Older
芊里 已提交
1 2 3 4 5 6 7 8 9 10 11 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
<template>
	<uni-popup ref="actionSheet" type="bottom">
		<view class="flex w-750 action-sheet-box bg-white">
			<view class="flex flex-row flex-nowrap align-center justify-center auth-item" @click="clickItem(item)"
				hover-class="hover" v-for="(item, index) in providerList" :key="index">
				<image :src="item.image" class="login-logo"></image>
				<text class="px-1 font-28">{{providerName[item.value]}}</text>
			</view>
			<view class="cancel-line"></view>
			<view class="flex flex-row flex-nowrap align-center justify-center cancel-item" @click="clickItem(item)">
				<text class="font-28">取消</text>
			</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>

<style>
	@import url("../../common/myStyle.css");

	.action-sheet-box {
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
	}

	.login-logo {
		width: 42rpx;
		height: 42rpx;
	}

	.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;
	}
</style>