<script setup name="prepare">
import excelCop from '@/components/excel.vue'
import treeCop from '@/components/tree.vue'
import tableCop from './components/table.vue'
import { ElMessage } from 'element-plus';
import { onMounted, ref, onActivated } from 'vue'
import request from '@/api/axios.js'
import config from '@api/config.js'
/**配置参数 */
const treeHeight = ref(window.innerHeight - 260 + 'px') //tree高度
const excelHeight = ref(window.innerHeight - 260 + 'px') //excel高度
const tableHeight = ref(window.innerHeight - 260 + 'px')

let stop1=ref(Boolean)
let stop2=ref(Boolean)
let stop3=ref(Boolean)


const sjklist=async(urlKey)=>{
	const requestUrl=config[urlKey];
	const res = await request.get(`${requestUrl}/taos/create/database`)
	console.log(res);
		// webSocket.onerror = () => setTimeout(() => { funWebSocket() }, 2000)
         ElMessage.success(res.msg)
}
 const cjblist=async(urlKey)=>{
	const requestUrl=config[urlKey];
	 const res = await request.get(`${requestUrl}/taos/create/supertable`)
	// webSocket.onerror = () => setTimeout(() => { funWebSocket() }, 2000)
         ElMessage.success(res.msg)
 }

const redislist=async(urlKey)=>{
	const requestUrl=config[urlKey];
	 const res = await request.get(`${requestUrl}/taos/create/table`)
	console.log(res);
	// webSocket.onerror = () => setTimeout(() => { funWebSocket() }, 2000)
         ElMessage.success(res.msg)
 }

 

	const funSubmit1 = async(urlKey)=>{
		const requestUrl=config[urlKey];
		const res=await request.get(`${requestUrl}/redis/read/start`)
		// console.log(res);
		// webSocket.onerror = () => setTimeout(() => { funWebSocket() }, 2000)
		 ElMessage.success(res.msg)
		
	}
	const funSubmit2 = async(urlKey)=>{
		const requestUrl=config[urlKey];
		const res=await request.get(`${requestUrl}/taos/create/table`)
		// console.log(res);	
		// webSocket.onerror = () => setTimeout(() => { funWebSocket() }, 2000)
		 ElMessage.success(res.msg)
	}
	const funSubmit3 = async(urlKey)=>{
		const requestUrl=config[urlKey];
		const res=await request.get(`${requestUrl}/redis/read/stop`)
		// console.log(res);
		// webSocket.onerror = () => setTimeout(() => { funWebSocket() }, 2000)
		 ElMessage.success(res.msg)	
	}


onMounted(() => {
	tableHeight.value = window.innerHeight - 260 + 'px'
	excelHeight.value = window.innerHeight - 260 + 'px'
	treeHeight.value = window.innerHeight - 260 + 'px'
	window.addEventListener('resize', () => {
		tableHeight.value = window.innerHeight - 260 + 'px'
		excelHeight.value = window.innerHeight - 260 + 'px'
		treeHeight.value = window.innerHeight - 260 + 'px'
	})
	console.log(111111111111111,config);
	const requestUrl=config.taosURL;
	const res=request.get(`${requestUrl}/redis/read/status`)
	console.log(666666,res);
	if(res==true){
		stop1.value=false
		stop2.value=false
		stop3.value=true
	}	else{
		stop1.value=true
		stop2.value=true
		stop3.value=false
	}
	
})

    
onActivated(() => {
	// funGetTree()
})
</script>
<template>
	<div class="bg-white py-[10px] px-[10px] relative">
	<div class="pl-[20px] flex items-center h-[80px] relative mb-[20px] shadow rounded-[6px] shadow-blue-500">
		
	
			<el-form-item class="!mb-0 ml-5">
				<el-button @click="sjklist('redisURL')" type="primary" :disabled="disable">建数据库</el-button>
			</el-form-item>
			<el-form-item class="!mb-0 ml-5">
				<el-button @click="cjblist('redisURL')" type="primary">建超级表</el-button>
			</el-form-item>
			<el-form-item class="!mb-0 ml-5">
				<el-button @click="redislist('redisURL')" type="primary">按采集Redis建点</el-button>
			</el-form-item>
			<el-form-item class="!mb-0 ml-5">
				<el-button @click="funSubmit1('taosURL')" type="primary" :disabled="stop1">启动读redis写taos</el-button>
			</el-form-item>
			<el-form-item class="!mb-0 ml-5">
				<el-button @click="funSubmit2('redisURL')" type="primary" :disabled="stop2">redis新增建点</el-button>
			</el-form-item>
			<el-form-item class="!mb-0 ml-5">
				<el-button @click="funSubmit3('taosURL')" type="primary" :disabled="stop3">停止读redis写taos</el-button>
			</el-form-item>
		
	</div>
		<div class="relative shadow rounded-[6px] shadow-blue-500 px-[10px] pt-[20px] pb-[10px]">
		
			<el-row :gutter="10">
				<el-col :span="5">
					<!-- <tree-cop :data="treeData" :height="treeHeight" @currentChange="funCurrentChange" @refresh="funGetTree">
					</tree-cop> -->
				</el-col>
				<el-col :span="3">
					<!-- <excel-cop :data="excelList" :height="excelHeight" @excelChange="funExcelChange"></excel-cop> -->
				</el-col>
				<el-col :span="16">
					<!-- <div>
						<table-cop class="" :data="tableData" :column="tableColumn" :loading="tableLoading"
							:height="tableHeight" :tableId="tableShowId" :tableName="tableName" @export="funExport"></table-cop>
					</div> -->


				</el-col>
			</el-row>
		</div>

		<el-progress :percentage="progress" v-if="progress" class="!absolute top-0 right-0 left-0" :indeterminate="false"
			color="rgb(19,206,102)" :stroke-width="4" :show-text="false" />
	</div>
</template>