<script setup lang="ts">
	import { onLaunch } from '@dcloudio/uni-app'
	import { useAppStore } from './stores/app'
	import { getLangPag } from '@/api/lang'
	const appStore = useAppStore()

	onLaunch(async () => {
		await appStore.getConfig()

		const pag = await getLangPag({ 'lang': uni.getStorageSync('lang') })
		await pag.forEach((item : any) => {
			//先销毁再重新赋值
			uni.removeStorageSync(item.type + '.' + item.name);
			uni.setStorageSync(item.type + '.' + item.name, item.value);
		});
		if (!uni.getStorageSync('langPag')) {
			uni.setStorageSync('langPag', 1);

			const current = getCurrentPages();
			let pageRoute = "/pages/index/index";
			if (current) {
				let pageNow = current[current.length - 1]
				pageRoute = "/" + pageNow.route;
				
				let params = pageNow.$page.options
				let keys = Object.keys(params); //获取对象的key 返回对象key的数组
				let query = '';
				if (keys.length > 0) {
					query = keys.reduce((pre, cur) => {
						return pre + cur + '=' + params[cur] + '&';
					}, '?').slice(0, -1);
				}
				pageRoute += query
			}
			uni.reLaunch({
				url: pageRoute
			});
		}
	})
</script>
<style lang="scss">
	.uni-simple-toast__text {
		word-break: break-word !important;
	}
</style>