<template>
	<mobile-frame>
		<view class="main">
			<view class="one">
				<image class="logo" :src="logoUrl" mode=""></image>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				logoUrl: '',
			};
		},
		onLoad: async function() {
			const that = this;
			await that.searchConfig();
			await that.watchlogin();
		},
		methods: {
			watchlogin() {
				const that = this;
				if (that.$store.state.socketTask == null) {
					uni.getStorage({
						key: 'token',
						success: function(res) {
							let user = that.$jwt(res.data);
							if (user._id) {
								//当websocket收到后端发送的消息时，触发
								let config = that.$config.wsUrl;
								// 开启websocket
								that.$store.dispatch('websocketInit', config + `/${user._id}`);
							}
						}
					})
				}
			},
			// 查询基本设置
			async searchConfig() {
				const that = this;
				let res = await that.$api(`/config`, 'GET', {});
				if (res.errcode == '0') {
					uni.getStorage({
						key: 'token',
						success: async (res) => {
							let arr = await that.$api(`/user/cct`, 'POST');
							if (arr.errcode == '0') {
								uni.setStorage({
									key: 'token',
									data: arr.data,
									success: function() {}
								});
							}
						}
					})
					let config = res.data;
					that.$set(that, `logoUrl`, config.config.logo[0].url);
					uni.setStorage({
						key: 'config',
						data: config,
						success: function(res) {
							// 赋值默认值
							that.$config.share = {
								title: config.title,
								path: '/pages/index/index',
								imageUrl: config.config.share[0].url
							}
							let url = `/pages/home/index`; ///pagesHome/order/detail   /pages/home/index
							uni.redirectTo({
								url
							})
						},
						fail: function(err) {
							console.log(err);
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.one {
			text-align: center;
			margin: 40vw 0 0 0;

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