<template>
	<view class="titles">切换环境</view>
	<view class="mabxose">
		<view class="titl">请输入需要设置的IP环境</view>
		<view class="titl">例：http://192.168.10.12:1086/</view>
		<view class="inps">
			<input placeholder="请输入ip环境" v-model="iptis" />
		</view>
		<view class="buts" @click="submitip">确认</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from "vue";

	import {
		onPullDownRefresh
	} from '@dcloudio/uni-app'

	// 下拉刷新
	onPullDownRefresh(() => {
		const timer = setTimeout(() => {
			iptis.value = ('http://192.168.10.75:8777/')
			// 关闭刷新动画
			uni.stopPullDownRefresh()
			clearTimeout(timer)
		}, 500)
	})

	let iptis = ref<string>('http://192.168.10.12:1086/')
	if (uni.getStorageSync('setip')) {
		iptis.value = uni.getStorageSync('setip')
	}
	function submitip() {
		if (iptis.value) {
			uni.setStorageSync('setip', iptis.value)
			uni.showToast({
				title: '设置成功',
				icon: 'success'
			})
		} else {
			uni.showToast({
				title: '请输入ip',
				icon: 'none'
			})
		}
	}
</script>
<style lang="scss">
	.titles {
		position: absolute;
		left: 50%;
		top: 70upx;
		transform: translate(-50%);
		font-size: 36upx;
		font-weight: 400;
		color: #D3832A;
		z-index: 5;
	}

	.mabxose {
		margin: auto;
		margin-top: 150upx;
		width: 560upx;
		padding: 20upx;
		background-color: #f0e6dc;
		border-radius: 10upx;

		.titl {
			color: #D3832A;

		}

		.inps {
			width: 500upx;
			height: 60upx;
			border: 1upx solid #cfcfcf;
			display: flex;
			align-items: center;
			justify-content: flex-start;
			margin-top: 20upx;

			>input {
				flex: 1;
			}
		}

		.buts {
			background-color: #D3832A;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 240upx;
			height: 80upx;
			border-radius: 10upx;
			margin: auto;
			margin-top: 20upx;
		}
	}
</style>