<template>
	<view class="main">
		<view class="one">
			<image class="logo" :src="logoUrl||'/static/logo.png'"></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				logoUrl: ''
			};
		},
		onShow: async function() {
			const that = this;
			await that.searchConfig();
			await that.search();
		},
		methods: {
			// 查询基本设置
			async searchConfig() {
				const that = this;
				const arr = await that.$api(`/design`, 'GET', {});
				if (arr.errcode == '0') {
					that.$set(that, `logoUrl`, arr.data[0].logoUrl[0]?.url);
					uni.setStorage({
						key: 'config',
						data: arr.data[0],
					})
				}
			},
			search() {
				const that = this;
				uni.getStorage({
					key: 'openid',
					success: function(res) {
						uni.reLaunch({
							url: `/pages/home/index`
						})
					},
					fail: function(err) {
						uni.login({
							success: async function(res) {
								if (res.code) {
									const aee = await that.$app('/wechat/api/login/app', 'GET', {
										js_code: res.code,
										config: that.$config.wx_projectkey
									})
									if (aee.errcode == '0') {
										uni.setStorage({
											key: "openid",
											data: aee.data.openid
										})
										uni.reLaunch({
											url: `/pages/home/index`
										})
									} else {
										uni.showToast({
											title: aee.errmsg,
											icon: 'none'
										})
									}
								} else {
									uni.showToast({
										title: res.errMsg,
										icon: 'none'
									})
								}
							}
						});
					}
				})
			}
		},
	}
</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>