<template>
	<view class="container">
		
		<view>
			<label>服务器IP:</label>
			<input v-model="serverIP" placeholder="请输入服务器IP" />
		</view>
		
		<view>
			<label>服务器端口:</label>
			<input v-model="serverPort" placeholder="请输入服务器端口" />
		</view>
		
		<button @click="saveConfigs">保存配置</button>
	</view>
</template>

<script>
	import {
		saveConfig
	} from '@/config.js';
	import {
		getConfig
	} from '@/config.js';

	export default {
		data() {
			return {
				serverIP: '',
				serverPort: ''
			};
		},
		onLoad:function() {
			this.serverIP = getConfig('serverIP', '192.168.18.200');
			this.serverPort = getConfig('serverPort', '8888');
		},
		methods: {
			saveConfigs() {
				saveConfig('serverIP', this.serverIP);
				saveConfig('serverPort', this.serverPort);
				uni.showToast({
					title: '配置保存成功',
					icon: 'success'
				});
			}
		}
	};
</script>

<style>
	.container {
		padding: 20px;
	}

	label {
		display: block;
		margin-bottom: 10px;
	}

	input {
		width: 100%;
		padding: 10px;
		margin-bottom: 20px;
	}

	button {
		padding: 10px 20px;
		background-color: #1aad19;
		color: white;
		border: none;
		border-radius: 5px;
	}
</style>