<script setup>
	/**
	 * name：
	 * user：sa0ChunLuyu
	 * date：2024年8月7日 20:05:05
	 */
	import {
		ref
	} from 'vue'
	import {
		$api,
		$response,
	} from '@/api'
	import {
		onShow,
		onHide
	} from '@dcloudio/uni-app'

	import {
		useStore
	} from '@/store'
	const $store = useStore()

	const setConfigStore = () => {
		const config_str = uni.getStorageSync('CONFIG_CONFIG')
		const config = JSON.parse(config_str)
		$store.config = config
		if (!config.color) {
			document.body.classList.toggle('grayscale');
		}
		const openid_str = uni.getStorageSync('OPENID')
		let url = window.location.href
		if (!openid_str) {
			if (url.indexOf('/pages/main/login/login') === -1) {
				uni.redirectTo({
					url: '/pages/main/login/login'
				})
			}
		}
		const save_info_str = uni.getStorageSync('SAVE_INFO')
		if (!!save_info_str) {
			$store.save_info = JSON.parse(save_info_str)
		} else {
			$store.resetSaveInfo()
		}
	}

	const getConfigConfig = async () => {
		const response = await $api('ConfigConfig')
		$response(response, () => {
			uni.setStorageSync('CONFIG_CONFIG', JSON.stringify(response.data.config))
			setConfigStore()
		})
	}

	const getConfigVersion = async () => {
		const response = await $api('ConfigVersion')
		$response(response, () => {
			const config_version = uni.getStorageSync('CONFIG_VERSION')
			let get_config = false
			if (!config_version) {
				get_config = true
			} else {
				if (config_version !== response.data.version) {
					get_config = true
				}
			}
			uni.setStorageSync('CONFIG_VERSION', response.data.version)
			if (!!get_config) {
				getConfigConfig()
			} else {
				setConfigStore()
			}
		})
	}

	onShow(() => {
		console.log(`\n %c 鹿和 %c https://sa0.online/ \n\n`, 'color: #ffffff; background: #fd6b60; padding:5px 0;',
			'color: #fd6b60;background: #ffffff; padding:5px 0;')
		getConfigVersion()
	})
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';

	/* #endif */
	.grayscale {
		filter: grayscale(100%);
	}

	// 设置整个项目的背景色
	page {
		background-color: #f5f5f5;
	}

	.bottom_blank_wrapper {
		height: calc(20rpx + var(--safe-area-inset-bottom));
	}

	.botm_blank_wrapper {
		width: 100%;
		height: 20rpx;
	}

	.top_blank_wrapper::after {
		content: ".";
	}

	.top_blank_wrapper {
		height: 0;
		width: 100%;
		opacity: 0;
	}

	.navbar_blank_wrapper {
		height: calc(100rpx + var(--safe-area-inset-top));
	}

	.input_line_wrapper {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.input_line_tag_wrapper {
		width: 200rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		background: #f9f9f9;
		font-size: 26rpx;
		font-weight: bold;
		border-radius: 6rpx;
	}

	.input_line_input_wrapper {
		width: 500rpx;
	}
</style>