<script setup>
	import {
		useNavbarStore
	} from '@/stores/navbarStore';
	import {
		APIgeocodelocation
	} from "@/common/api/api.js"
	import {
		onLaunch
	} from '@dcloudio/uni-app';
	import {
		getCurrentInstance
	} from 'vue';
	import {
		Storelogin
	} from '@/stores/user.js';
	const {
		proxy
	} = getCurrentInstance()
	// 小程序启动时执行
	onLaunch(async () => {
		// 标记应用启动完成
		const store = useNavbarStore();
		await store.initNavbarHeight();
		// #ifndef H5
		try {
			const storelogin = Storelogin();
			await storelogin.actionslogin()
		} catch (error) {
			console.log(error)
		}
		// #endif
		try {
			uni.getLocation({
				type: 'wgs84',
				success: async (res) => {
					let successres = await APIgeocodelocation({
						lng: res.longitude,
						lat: res.latitude,
					})
					if (successres) {
						let datastorage = {
							country: successres.addressComponent.country, // "中国"
							province: successres.addressComponent
								.province, //province: "陕西省"
							address: successres.addressComponent.city, //district: "西安市"
							district: successres.addressComponent.district, //district: "未央区"
							lng: res.longitude,
							lat: res.latitude,
						}
						uni.cache.set('getLocationstorage', datastorage);
						// 登录
						proxy.$isResolve()
					}
				},

			});
		} catch (error) {
			try {
				let successres = await APIgeocodelocation({
					lng: '',
					lat: '',
				})
				if (successres) {
					let datastorage = {
						country: successres.addressComponent.country, // "中国"
						province: successres.addressComponent
							.province, //province: "陕西省"
						address: successres.addressComponent.city, //district: "西安市"
						district: successres.addressComponent.district, //district: "未央区"
						lng: res.longitude,
						lat: res.latitude,
					}
					uni.cache.set('getLocationstorage', datastorage);
					proxy.$isResolve()
				}
			} catch (error) {
				proxy.$isResolve()
			}
		}
	});

	// export default {
	// 	onLaunch: async function() {


	// 	},
	// 	onShow: function() {},
	// 	onHide: function() {}
	// }
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-plus/index.scss";
	@import '@/common/css/flex.css';
	@import "@/common/css/common.css";
</style>