<template>
	<view>
		北京诚祥 登录页面
		<view>
			<!-- <button type="primary" @click="setLocalData">设置缓存</button>
			<button type="primary" @click="setPinia">设置状态</button>
			<button type="primary" @click="goAdminShouye">去管理首页</button>
			<button type="warn" @click="goJiaZhengShouye">去家政首页</button> -->
			<input type="text" v-model="userName" placeholder="请输入用户名">
			<input type="text" v-model="password" @blur="handleUpdateLLiPassword" placeholder="请输入密码">
			<button type="warn" @click="handleLogin">登录</button>
		</view>
		已加密的:{{lliPassword}}

    <!--  隐藏的同步加密密码组件 非可见  -->
		<passwordLli ref="passLLiRef" :password="password" @lli-password="onLliPassword" />
	</view>
</template>

<script setup>
	import cacheManager from '@/utils/cacheManager.js'
	import * as httpApi from "@/api/login.js"
	import passwordLli from "@/components/password-lli/password-lli.vue";
	import {
		ref
	} from "vue"
	const userName = ref('18604088413') // 用户名
	const password = ref('1') // 密码
	const lliPassword = ref('') // 加密后的密码
	const passLLiRef = ref(null)

	function goAdminShouye() {
		uni.navigateTo({
			url: "/pages/ShouYe/shouyeOne"
		})
	}

	function goJiaZhengShouye() {
		uni.navigateTo({
			url: "/pages/ShouYe/shouyeTwo"
		})
	}

	function handleUpdateLLiPassword() {
		passLLiRef.value.lliPassword();
	}

	function onLliPassword(password) {
		lliPassword.value = password;
	}

	function handleLogin() {
		httpApi.login({
			userName: userName.value,
			password: lliPassword.value
		}).then(res => {
			cacheManager.set('auth', res.data)
			console.log('登录成功')

			// 目前默认跳转管理端首页
			// uni.navigateTo({
			// 	url: `/pages/admin/ShouYe/shouye`
			// })

			// 目前默认管理端考试页面
			uni.navigateTo({
				url: `/pages/admin/Jiazheng/index`
			})
		})
	}
</script>
