<template>
	<view class="main">
		<view :style="{height:iSMT+'px'}"></view>
		<view class="top">
			<view class="top-list">
				<text>标准</text>
				<radio value="0" class="radio-btn" activeBackgroundColor="red" :checked="selectedIndex === 0"
					@click="selectFont(0)" />
			</view>
			<view class="top-list">
				<text>中号</text>
				<radio value="1" class="radio-btn" activeBackgroundColor="red" :checked="selectedIndex === 1"
					@click="selectFont(1)" />
			</view>
			<view class="top-list">
				<text>大号</text>
				<radio value="2" class="radio-btn" activeBackgroundColor="red" :checked="selectedIndex === 2"
					@click="selectFont(2)" />
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue'
	import {
		getSetting
	} from "@/api/setting/general"
	const iSMT = ref(0)
	const selectedIndex = ref(0)

	const getFont = async () => {
		try {
			const res = await getSetting()
			if (res.code === 200) {
				const fontSize = res.data.fontSize
				const sizeMap = {
					small: 0,
					medium: 1,
					large: 2
				}
				console.log('看看字体', res.data.fontSize)
				selectedIndex.value = sizeMap[fontSize] ?? 0;
			}
		} catch (err) {
			console.error("获取字体设置失败：", err);
		}
	}

	const selectFont = (index) => {
		selectedIndex.value = index
		console.log('看看选中状态', selectedIndex.value)
	}
	onMounted(() => {
		// 状态栏高度
		iSMT.value = uni.getSystemInfoSync().statusBarHeight;
		console.log('看看高度', iSMT.value)
		getFont()
	})
</script>

<style>
	.top {
		margin-top: 1.5vh;
		height: 21vh;
		background-color: white;
	}

	.top-list {
		width: 630rpx;
		height: 7vh;
		display: flex;
		align-items: center;
		margin: 0 40rpx;
		padding: 0 10rpx;
		border-bottom: 1rpx solid #eee;
	}

	.top-list:last-child {
		border-bottom: none;
	}

	.radio-btn {
		margin-left: auto;
		transform: scale(0.6);
	}
</style>