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

			});
		} catch (error) {
			let successres = await APIgeocodelocation({
				lng: '',
				lat: '',
			})
			if (successres.code == 0) {
				let datastorage = {
					country: successres.data.addressComponent.country, // "中国"
					province: successres.data.addressComponent
						.province, //province: "陕西省"
					address: successres.data.addressComponent.city, //district: "西安市"
					district: successres.data.addressComponent
						.district, //district: "未央区"
					lng: res.longitude,
					lat: res.latitude,
				}
				uni.cache.set('getLocationstorage', datastorage);
				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>