<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<button @click="cb"> {{data.user_name}}

		</button>
		<view v-for="(v,k,i) in obj" key="k">
			<text> {{v}}{{i}}</text>
		</view>
	
		<alertDialog v-if="isOpenDialog" :titleName="titleName" contentText="你好呀!" @dialogConfirm ="onDialogConfirm" @dialogClose = "onDialogClose" />
		<button @click="isOpenDialog=true">显示对话框</button>
		
		<button @click="isOpenMessage=true">显示消息提示</button>
		<MessageVue v-if="isOpenMessage" :messageText="tip_message" @onFinish="isOpenMessage=false"> </MessageVue>
	</view>
</template>

<script setup lang="ts">
	import { ref,reactive ,onMounted,onUnmounted,watch} from 'vue';
	import { UserData } from '../../stores/userDataManager';
	import { user_data } from '../../data/data';
	import {storeToRefs} from 'pinia';
	import { util } from '../../framework/util';
	import MessageVue from '../../components/public/Message.vue';
	import alertDialog from '../../components/public/alertDialog.vue';
	import { log } from '../../framework/log';
	import { http } from '../../framework/http';
	import { config } from '../../config/config';

	let udata = new user_data()
	udata.token = "123"
	udata.user_id = 1
	udata.user_name = "大靓仔"
	
	let tip_message = ref("")
	UserData().updateUserData(udata)
	const {data} =  storeToRefs(UserData())
	let title = ref("123")
	let obj = reactive({a:"12",b:"123"});
	let cb = function(){
		util.alert("你有点呆呆的！")
		title.value = "fuck!"
		obj.a = "world";
	}
		
	// Dialog 使用用例 给组件传递参数和回调 start
	let isOpenDialog = ref(false)
	let titleName = ref("fuck u!")
	function onDialogClose(){
		log.Debug("onDialogClose!")
		isOpenDialog.value = false
	}
	
		
	function onDialogConfirm(){
		log.Debug("onDialogConfirm!")
		isOpenDialog.value = false
		http.StaticRequest("https://static.hainanmlwl.com/test_books/book_list.json",(err,data)=>{
			if(err){
				tip_message = err
				isOpenMessage.value = true
				return
			}
			
			log.Debug("data.code", typeof config.url_confg.StatesCode.SUCCESS)
			if(data.code==config.url_confg.StatesCode.SUCCESS){
				log.Debug("book_list",data)
			}else{
				tip_message = data.message
				isOpenMessage.value = true
			}
			
		})
	}
	//end
	
	
	//消息
	let isOpenMessage = ref(false)
	//end
	onMounted(()=>{
		
	})
	onUnmounted(()=>{
	})
	
	watch(obj,async (new_v,old_v)=>{
		console.log(new_v,old_v)
	})
	
	
</script>

<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
