<template>
	<view class="main">
		<view class="one">
			<image class="logo" :src="logoUrl"></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				logoUrl: ''
			};
		},
		onLoad: async function() {
			const that = this;
			await that.searchConfig();
			await that.searchOpenid();
		},
		methods: {
			// 查询基本设置
			async searchConfig() {
				const that = this;
				let res = await that.$api(`/config`, 'GET', {});
				if (res.errcode == '0') {
					that.$set(that, `logoUrl`, res.data.logo_url[0].url);
					uni.setStorage({
						key: 'config',
						data: res.data,
						success: function(res) {},
						fail: function(err) {
							console.log(err);
						}
					})
				}
			},
			async searchOpenid() {
				const that = this;
				try {
					const res = uni.getStorageSync('openid');
					const aee = await that.$api(`/login/app/${res}`, 'POST', {})
					if (aee.errcode == '0') {
						uni.reLaunch({
							url: `/pages/home/index`
						})
					} else {
						uni.showToast({
							title: aee.errmsg,
							icon: 'none'
						})
					}
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
				uni.reLaunch({
					url: `/pages/home/index`
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.main {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100vw;
		height: 100vh;

		.one {
			.logo {
				width: 50vw;
				height: 50vw;
				border-radius: 90px;
				box-shadow: 0 0 5px var(--f1Color);
			}
		}
	}
</style>