<template>
	<view class="content">
		<image class="logo" :src="config?.logo[0]?.url||'/static/logo.png'"></image>
	</view>
</template>

<script setup lang="ts">
	import { getCurrentInstance, ref } from 'vue';
	//该依赖已内置不需要单独安装
	import { onLoad } from "@dcloudio/uni-app";
	// 请求接口
	const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
	const $app = getCurrentInstance()?.appContext.config.globalProperties.$app;
	const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
	// 基本信息
	const config = ref({ logo: [] });
	onLoad(async () => {
		await searchConfig();
		await search();
	})
	// config信息
	const searchConfig = async () => {
		let res = await $api(`config`, 'GET', {});
		if (res.errcode == 0) {
			config.value = res.data
			uni.setStorage({
				key: 'config',
				data: res.data,
			})
		}
	};
	// 查询
	const search = async () => {
		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) {
							uni.reLaunch({
								url: `/pages/home/index`
							})
							const aee = await $app('/wechat/api/login/app', 'GET', {
								js_code: res.code,
								config: $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>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 100vw;
		height: 100vh;

		.logo {
			width: 50vw;
			height: 50vw;
			border-radius: 90px;
			box-shadow: 0 0 5px #f1f1f1;
		}
	}
</style>